Theme v2: import icon packs (install screen, packs in the theme choice)
Appearance > Icons gets Import icon pack: a *.icons.json file is parsed by the runtime sanitizer and shown on an install screen (name, author, licence, source, credits, every glyph, size, data only) before it joins the persisted theme choice (packs, at most 8, validated natively for shape and size) and the Icons picker. Imported packs can be removed again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
d902d3f65a
commit
a8710dfe02
7 changed files with 156 additions and 10 deletions
|
|
@ -17,6 +17,8 @@ import { shell, type WebParams } from '../frame/state.ts';
|
|||
import { assign } from '../frame/themeScopes.ts';
|
||||
import { tabProfile } from '../profileModel.ts';
|
||||
import { Button, ColorField, Row, Section, Segmented, Select, Slider, Toggle, useSettingsQuery, type Option } from './controls.tsx';
|
||||
import { IconPackImport, IconPackReview } from './IconPackInstall.tsx';
|
||||
import type { IconPack } from '../../../runtime/src/themeIcons.ts';
|
||||
import { bytesLabel, defaultWeights, loadCatalog, weightsLabel } from './fonts/catalog.ts';
|
||||
import { FontRoles } from './fonts/FontRoles.tsx';
|
||||
import { CustomCssEditor } from './Plugins.tsx';
|
||||
|
|
@ -88,6 +90,7 @@ export function Appearance({ notify }: { notify: Notify }) {
|
|||
const { ready, choice, scopes } = useThemeState();
|
||||
const [importing, setImporting] = useState(false);
|
||||
const [asking, setAsking] = useState<{ theme: ThemeSpec; families: string[] } | null>(null);
|
||||
const [packReview, setPackReview] = useState<{ pack: IconPack; warnings: string[]; bytes: number } | null>(null);
|
||||
const query = useSettingsQuery();
|
||||
|
||||
if (!ready) return null;
|
||||
|
|
@ -206,10 +209,16 @@ export function Appearance({ notify }: { notify: Notify }) {
|
|||
<Row label={t('wb.appearance.accent')} hint={t('wb.appearance.accentHint')} keywords="color colour highlight link" wide>
|
||||
<ColorField label={t('wb.appearance.accentColor')} value={choice.accent} swatches={[...themes.accents]} autoLabel={t('wb.appearance.theme')} onChange={accent => void update({ ...choice, accent })}/>
|
||||
</Row>
|
||||
{themes.iconPacks?.length ? <Row label={t('wb.appearance.icons')} hint={t('wb.appearance.iconsHint')} keywords="icon pack glyphs symbols pixel">
|
||||
<Select label={t('wb.appearance.icons')} value={choice.icons ?? 'theme'} width={220}
|
||||
onChange={icons => void update({ ...choice, icons: icons === 'theme' ? undefined : icons })}
|
||||
options={[{ value: 'theme', label: t('wb.appearance.icons.theme') }, { value: 'site', label: t('wb.appearance.icons.site') }, ...themes.iconPacks.map(pack => ({ value: pack.id, label: pack.name }))]}/>
|
||||
{themes.iconPacks?.length ? <Row label={t('wb.appearance.icons')} hint={t('wb.appearance.iconsHint')} keywords="icon pack glyphs symbols pixel import" wide>
|
||||
<div className="bt-inline">
|
||||
<Select label={t('wb.appearance.icons')} value={choice.icons ?? 'theme'} width={220}
|
||||
onChange={icons => void update({ ...choice, icons: icons === 'theme' ? undefined : icons })}
|
||||
options={[{ value: 'theme', label: t('wb.appearance.icons.theme') }, { value: 'site', label: t('wb.appearance.icons.site') }, ...themes.iconPacks.filter(pack => !choice.packs?.some(item => item.id === pack.id)).map(pack => ({ value: pack.id, label: pack.name })), ...(choice.packs ?? []).map(pack => ({ value: pack.id, label: pack.name }))]}/>
|
||||
<IconPackImport onError={message => notify(message, true)} onParsed={(pack, warnings, bytes) => setPackReview({ pack, warnings, bytes })}/>
|
||||
</div>
|
||||
{choice.packs?.length ? <div className="bt-inline wb-pack-list" aria-label={t('wb.appearance.icons.imported')}>{choice.packs.map(pack => <Button key={pack.id} size="sm" tone="ghost" onClick={() => void update({ ...choice, packs: choice.packs!.filter(item => item.id !== pack.id), ...(choice.icons === pack.id ? { icons: undefined } : {}) }).then(() => notify(t('wb.appearance.icons.removed', { name: pack.name })))}>{t('wb.appearance.icons.remove', { name: pack.name })}</Button>)}</div> : null}
|
||||
{packReview && <IconPackReview {...packReview} replaces={!!choice.packs?.some(item => item.id === packReview.pack.id)} onCancel={() => setPackReview(null)}
|
||||
onInstall={() => { const { pack } = packReview; setPackReview(null); void update({ ...choice, packs: [...(choice.packs ?? []).filter(item => item.id !== pack.id), pack], icons: pack.id }).then(() => notify(t('wb.appearance.icons.installed', { name: pack.name }))); }}/>}
|
||||
</Row> : null}
|
||||
<Row label={t('wb.appearance.fonts')} hint={t('wb.appearance.fontsHint')}
|
||||
keywords="typeface typography family font google fonts post text heading numbers code interface window dialogs" wide>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue