Repository navigation
feat(theme): a theme lists its icon variant names once - #8756
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
There was a problem hiding this comment.
Changes requested: the runtime iconVariants list and its typing match AST-087, but astryx theme build does not yet handle the new field consistently.
- Built themes drop
iconVariants, so a built theme and any theme extending it read no list; write it frominheritableFieldsinpackages/cli/api/theme/build/build.mjsand add a build test that a built theme and its child keep the list. - Declaring
IconVariantMapmakes the build treat acomponents.icon['variant:<name>']styling rule as an enrolled value (it now writes anIconVariantMapaugmentation, and fails the build when the rule sits only under an adaptation); exclude artwork-request maps from component-value enrollment and cover that with a build test.
[Automated review]
| * The icon variant names this theme supports: its own `iconVariants`, or | ||
| * the list it inherited. Absent when no theme in its lineage lists any. | ||
| */ | ||
| iconVariants?: ReadonlyArray<string>; |
There was a problem hiding this comment.
astryx theme build does not serialize this new DefinedTheme field: inheritableFields in packages/cli/api/theme/build/build.mjs (lines 2131–2154, whose comment asks to stay in sync with DefinedTheme) writes no iconVariants. A built defineTheme({name: 'probe', iconVariants: ['outline', 'filled']}) reads iconVariants as undefined, and a theme extending the built module inherits no list. architecture:theme-compilation (System model, item 7) requires built JavaScript to carry the list; please write it there and add a build test for the built theme and a child of it.
There was a problem hiding this comment.
Declining this in this PR: it is built output, not this PR's scope. This PR implements spec:AST-087 FR2, the FR3 types, and the iconVariants part of FR18 for defineTheme themes. Serializing the list into built JavaScript belongs to FR19 and architecture:theme-compilation (System model item 7, INV15). That is the separate theme-build change, which FR3 also gives the job of writing the IconVariantMap augmentation from a built theme's list. Built output carrying function entries, the per-entry defining lists that <Icon variant> uses, and the list is one coherent change; serializing only the list here would ship half of it. This PR changes no build output for existing themes (the enrollment fix above keeps it that way), and the PR description lists built output under "Not in this PR". I have flagged the gap to the owner.
There was a problem hiding this comment.
Added in e920fdb, for parity between built and runtime themes, following the owner's standing rule that every new theme setting also works in built themes. iconVariants is now an inheritable field of the built module, an explicit [] included. The new build.icon-variants.test.mjs builds themes and imports the generated modules. It checks that a built theme reads the same list as its runtime theme, that a theme extending the built one inherits the list or replaces it exactly as it would extending the runtime theme, that [] is kept and inherited, and that a list-less theme writes no field. Three of the four cases fail without the serialization. Nothing else in theme build changes: carrying function entries and the per-entry defining lists, and the INV15 enumeration, stay with the later theme-build change.
| * ``` | ||
| */ | ||
| // eslint-disable-next-line @typescript-eslint/no-empty-object-type -- augmentation point | ||
| export interface IconVariantMap {} |
There was a problem hiding this comment.
Declaring this interface makes astryx theme build treat components.icon['variant:<name>'] as an enrolled custom value: classifyComponentValue (packages/cli/api/theme/build/build.mjs:1403) accepts any <Prefix><Prop>Map declared in @astryxdesign/core/<Component>. With this change, a theme with components: {icon: {'variant:filled': {…}}} gets a generated IconVariantMap augmentation for 'filled', and the same rule placed only under an adaptation fails the build; on the base neither happens. Icon.variant has no component styling map (architecture:component-theming-surface INV14), so the build should exclude this map from component-value enrollment.
There was a problem hiding this comment.
Fixed in be6f60f. classifyComponentValue and the augmentation lookup in generateVariantDeclarationsAsync now skip an explicit artwork-request list (IconVariantMap), so a components.icon['variant:<name>'] key stays unresolved pass-through, as it was before the map existed. It writes no augmentation, and an adaptation-only rule builds. build.adaptation-enrollment.test.mjs adds the paired root/rule case; it fails without the fix once the core declarations include IconVariantMap.
c41a9a7 to
e59ac65
Compare
PR Analysis Report📚 Storybook Preview🧪 Sandbox PreviewModified ComponentsIcon (@astryxdesign/core) · View in Storybook
Component Size
Sizes are gzip. Import counts the JavaScript the import loads eagerly; CSS counts the package stylesheet rules referenced by the modules it can load from its own package, lazily loaded ones included. Bundle Size SummaryGzip figures measure each package's entry file, not the code an import pulls in.
Accessibility AuditStatus: No accessibility violations detected. Visual Regression57 of 504 shot(s) changed. A change here is a question, not a failure: check whether the after is the
and 37 more. Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
e59ac65 to
5ddebb1
Compare
There was a problem hiding this comment.
Changes requested: the iconVariants list and its typing match AST-087 at runtime, but two fixes are needed before this can land.
astryx theme buildstill dropsiconVariants, so a built theme and any theme that extends it have no list (architecture:theme-compilationSystem model item 7); please write it frominheritableFieldsinpackages/cli/api/theme/build/build.mjsand add a build test for a built theme and a theme extending it.- A
defineTheme()call with no list now returnsResolvedDefinedTheme<never>, solet active = defineTheme({name: 'app'}); active = defineTheme(shared);withshared: DefineThemeInputstops compiling, which a patch release must not do (AST-017 FR25); keeping list-less results assignable fromResolvedDefinedTheme, for example with a method-shaped__iconVariantmarker, plus a type test for that reassignment, would fix it.
[Automated review]
| * one types its icon entries by the list it inherits. Never set. | ||
| * @internal | ||
| */ | ||
| readonly __iconVariant?: IconVariant; |
There was a problem hiding this comment.
readonly __iconVariant?: IconVariant makes defineTheme() return ResolvedDefinedTheme<never> for a theme with no list, so a variable inferred from such a call no longer accepts a ResolvedDefinedTheme value:
const shared: DefineThemeInput = {name: 'base'};
let active = defineTheme({name: 'app'});
active = defineTheme(shared); // TS2322 here; compiles on mainA useState(defineTheme({name: 'app'})) setter fails the same way. Declaring the marker as a method, __iconVariant?(variant: IconVariant): void, and reading it in BaseThemeIconVariant with __iconVariant?(variant: infer Variant): void, keeps these compiling while this PR's type tests still pass; a type test for the reassignment would lock it in.
There was a problem hiding this comment.
Fixed in 1323957. __iconVariant is now method-shaped (__iconVariant?(variant: IconVariant): void), and BaseThemeIconVariant infers from its parameter, so resolved themes with and without lists are mutually assignable again while extends still infers the exact names. The new type test in defineTheme.test.ts covers your reassignment (defineTheme(shared) into a list-less result), a listed result into a list-less one, a list-less result into a listed one, and either into ResolvedDefinedTheme. It fails with the property-shaped marker.
There was a problem hiding this comment.
Changes requested: the iconVariants list, its typing, and the assignability of defineTheme() results now match AST-087 and AST-017, but astryx theme build still drops the list. A built theme and any theme that extends it have no iconVariants (architecture:theme-compilation System model item 7, architecture:theme-authoring-contract INV1), so please write the field from inheritableFields in packages/cli/api/theme/build/build.mjs, keeping an explicit [], and add a build test for a built theme and a theme extending it. At this revision the list is the only icon data that built and runtime themes need to share, so this fix does not wait on the later function-entry and variant-gating work.
[Automated review]
There was a problem hiding this comment.
No further changes requested: the iconVariants list, its typing and the assignability of defineTheme() results match AST-087 and AST-017, and astryx theme build now keeps the list, with build.icon-variants.test.mjs showing that built and runtime themes, and themes extending them, read the same list. As an optional follow-up with the theme-build change that writes the IconVariantMap augmentation, consider typing a built theme's declaration by its list: a theme that extends a built theme currently sees variant as string, so a misspelled name compiles there.
[Automated review]
DefineThemeInput.iconVariants lists the variant names the whole theme supports, and DefinedTheme['iconVariants'] reads the list back. A child theme that sets the list replaces the inherited one; one that omits it inherits it. Inside defineTheme, icon entry functions receive variant typed as the theme's listed names (or the inherited list). @astryxdesign/core/Icon declares the augmentable IconVariantMap and its IconVariant names, which type variant for process-wide registerIcons entries. No variant source exists yet, so entries still receive variant: undefined. Implements spec:AST-087 FR2, FR3 (types) and the iconVariants part of FR18.
Declaring IconVariantMap in @astryxdesign/core/Icon made theme build's <Component><Prop>Map convention treat a components.icon['variant:<name>'] styling key as an enrolled value: the root wrote an IconVariantMap augmentation and an adaptation-only rule failed the build. Icon.variant selects artwork and has no component styling map (architecture:component-theming-surface INV14), so the build excludes artwork-request maps from component-value enrollment; such a key stays unresolved pass-through, as before the map existed.
…assignable
The type-only __iconVariant marker on ResolvedDefinedTheme was a
property, so a list-less defineTheme() result (ResolvedDefinedTheme<never>)
no longer accepted a ResolvedDefinedTheme value:
let active = defineTheme({name}); active = defineTheme(shared) stopped
compiling. The marker is now method-shaped, which keeps resolved themes
mutually assignable as before while extends still infers the exact names.
theme build wrote no iconVariants into the built module, so a built theme and any theme extending it read no list while the runtime theme did. The list is now an inheritable field of the built module, an explicit [] included, so built and runtime themes agree (architecture:theme-compilation System model item 7; spec:AST-087 FR2, FR18).
5597a3f to
e3d59ec
Compare
There was a problem hiding this comment.
No changes requested: the iconVariants list, its typing and the built-theme copy match AST-087, existing defineTheme() callers still compile, and the new build tests guard both theme-build fixes. Two optional follow-ups for the later theme-build work: a theme that extends a built theme still sees variant as string because the built declaration is plain DefinedTheme, and two defineTheme() results whose lists differ are not assignable to each other (for example useState(brandA) followed by setTheme(brandB)), so theme-switching state needs a DefinedTheme annotation.
[Automated review]
| * other, as they were before the list existed. | ||
| * @internal | ||
| */ | ||
| __iconVariant?(variant: IconVariant): void; |
There was a problem hiding this comment.
Optional, non-blocking: because this marker carries the exact names, two defineTheme() results whose lists differ are not assignable to each other. With brandA listing ['outline', 'filled'], const [theme, setTheme] = useState(brandA); setTheme(brandB); fails (TS2345) for a brandB listing ['bold'], and the message points at __iconVariant. Code that compiles on main is unaffected and a DefinedTheme annotation on the state works; if this trade-off is intended, a line in the icons docs or a type test would make it explicit.
Follows #8753 (function icon entries), which is merged; this PR is now based on
main.User need
A theme whose icon library draws several variants of one glyph (outline and filled, for example) needs one place to say which variant names it supports, and its icon entries need those names typed, so a misspelled
'filed'fails to compile instead of silently drawing the normal artwork.Without a theme-level list, every entry would branch on a bare
stringwith no type help. Tooling would also have no finite set of names to enumerate, and an application would have no public type for the names it may request. Anextendschild also needs a predictable rule for whether it keeps its base's names.Problem and solution fit
iconVariants(primary).DefineThemeInput.iconVariantslists the variant names the whole theme supports. A child that sets it replaces the inherited list; a child that omits it inherits it.DefinedTheme['iconVariants']reads the theme's list back.Typed entries (supporting). Inside
defineTheme, an entry function receivesvarianttyped as the theme's listed names: its own list, else the list it inherits. Comparing with an unlisted name is a type error.IconVariantMap/IconVariant(supporting). The public, augmentableIconVariantMapis declared in@astryxdesign/core/Icon, andIconVariantis its names. They typevariantfor process-wideregisterIcons()entries, and the next PR's<Icon variant>prop.Theme build keeps the artwork axis out of styling enrollment (supporting).
astryx theme buildfinds augmentable maps by the<Component><Prop>Mapnaming convention, so declaringIconVariantMapmade acomponents.icon['variant:<name>']styling key count as an enrolled value: the root wrote anIconVariantMapaugmentation, and an adaptation-only rule failed the build.Icon.varianthas no component styling map (component-theming-surfaceINV14), so the build now skips an explicit artwork-request list and such a key stays unresolved pass-through, as before.Built themes keep the list (supporting, built/runtime parity).
astryx theme buildwritesiconVariants, an explicit[]included, into the built module's inheritable fields. A built theme, and a theme thatextendsit, read the same list as the runtime theme. No other theme-build output changes.CLI goldens (supporting). The new Icon Variants docs section changes the
iconstopic tree and the search counts captured inpackages/cli/test/__golden__/no-icon-set/*. They are regenerated.Nothing passes a variant yet: entries still receive
variant: undefined. Thevariantrequest, and the rule that only active-theme-listed names reach an entry, come in the next stacked PR.Current specification
spec:AST-087(current): FR2 (a theme lists its variant names once; a child that sets the list replaces it, one that omits it inherits it), FR3 (types only: entry functions insidedefineThemereceivevarianttyped as the listed names;IconVariantis the names in the public, augmentableIconVariantMap), FR18 (DefinedTheme['iconVariants']is the theme's list), and theiconVariantspart of FR19 (a built theme carries the list, so built and runtime themes, and themes extending them, read the same list). DEC-9.architecture:theme-compilation→ System model item 7 (a built theme carries itsiconVariantslist in its JavaScript): the list part only.architecture:theme-authoring-contract→ System model (an expliciticonVariantslist replaces the inherited list; an omitted list is inherited; entry functions receivevarianttyped as the theme's listed names), INV3, INV14 (the list is theme-level and never combined with another theme's list).architecture:icon-resolution-and-component-slots→ Owning code (the public@astryxdesign/core/Iconsubpath declares the interface consumers augment).architecture:component-theming-surface→ INV14 (Icon.variantis an artwork axis whose names live inIconVariantMap).Not in this PR:
<Icon variant>and variant gating (next PR); the rest of theme build output (carrying function entries and per-entry defining lists, augmentingIconVariantMapfrom a built theme, INV15 enumeration);componentIconsslots; and FR8 enumeration.Public delta and caller burden
New
defineThemefield:New public types in
@astryxdesign/core/Icon(and the package root):Changed types:
IconRequest<Variant extends string = IconVariant>andIconEntry<Variant extends string = IconVariant>gain a type parameter. With an empty map,IconVariantisnever, sovariantstaysundefined-only, as in feat(Icon): a theme icon entry can be a function of the requested size #8753.DefinedTheme['iconVariants']:ReadonlyArray<string> | undefined(new optional field).defineThemeinfersiconVariants(as aconstlist) and theextendsbase. It returnsResolvedDefinedTheme<Names>, where the new type parameter defaults tostring, so existingResolvedDefinedThemeannotations keep compiling.DefineThemeInputgains two type parameters with defaults. An annotatedconst input: DefineThemeInput = {…}keeps working; its entries receivevariant: string | undefined.DefinedThemegives a child's entriesvariant: string | undefined, because its names are not known statically. A base fromdefineThemegives its exact names.Caller decisions: none for existing callers. A theme author who adopts variants chooses the names once per theme. An application that wants typed names augments
IconVariantMap.Compatibility: additive. A theme without
iconVariantshas no list (the field is absent) and behaves exactly as before. Assignability and comparison between theme types are unchanged: the exact names travel on a type-only, method-shaped optional marker ofResolvedDefinedTheme, never onDefinedThemeitself. Solet active = defineTheme({name: 'app'}); active = defineTheme(shared);still compiles, as do assertions betweenDefinedThemeand resolved themes.Theming and accessibility: no runtime rendering change.
Design and alternatives
defineTheme<const IconVariants, Base>infers the names fromiconVariantsand fromextendsonly, never from an entry function's parameter annotation (a deferred indexed access blocks that inference withoutNoInfer, so older TypeScript versions read the declarations). A child's names are its own list when set, otherwise the base's.stringwith no list, merging a child's list with its base's, and Astryx deriving one variant type from several themes' lists. Also rejected here: makingDefinedThemegeneric over the names. A list-less theme would then typeiconVariantsasReadonlyArray<never>, and existing type assertions betweenDefinedThemeand a resolved theme would stop compiling.IconVariantMapis declared literally inIcon/index.ts, the module consumers augment, as the record requires. No*Propsfield usesIconVariantyet, so the extensible-axis guard is unaffected until the next PR.Evidence
defineTheme.test.ts(iconVariantssuite): resolved themes with and without lists stay assignable to each other and toResolvedDefinedTheme(this fails with a property-shaped marker); the list is kept as the theme's own copy; no list in the lineage → no field; a child inherits; a child replaces (including with[]) without changing the base; type assertions for own, inherited, replaced, absent, and plain-DefinedThemebase names, plus@ts-expect-errorfor unlisted names ('bold'in a theme that listsoutline/filled, and'filled'after a child replaced the list with['bold']); entries still receive no variant.globalIconRegistry.test.tsx(variant namessuite): an augmentation ofIconVariantMaptypesIconVariantandregisterIcons()entries, and an unaugmented name is a type error; listed themes still passvariant: undefined.build.adaptation-enrollment.test.mjs:icon+variant:filledis accepted on the root without generating an augmentation, and is accepted rule-only. It fails without the build fix once the core declarations includeIconVariantMap.build.test.mjs,build.icon-lineage,build.heading-core-compat,build.adaptation-core-compat: 74 passed.build.icon-variants.test.mjsbuilds themes and imports the generated modules: a built theme reads the same list as its runtime theme; a theme extending the built one inherits the list or replaces it, matching the same child of the runtime theme;[]is kept and inherited; a list-less theme writes no field. Three of the four cases fail without the serialization. Allpackages/cli/api/theme/buildsuites pass.packages/cli/test/experimental-isolation.test.mjs: 34/34 with regenerated goldens.scripts/check-theme-template.test.mjs: the template documentsiconVariants. The guard's interface regex now accepts the genericDefineThemeInput<…>declaration (supporting change, one line).Scope
Testing
pnpm vitest run packages/core/src/Icon packages/core/src/theme scripts/check-theme-template.test.mjs: 1692 passed.pnpm vitest run packages/core/src/IconButton packages/core/src/utils/touchPresentation.test.ts packages/core/src/theme packages/cli/api/theme/build/build.icon-lineage.test.mjs: 1606 passed.pnpm vitest run packages/cli/api/docs scripts/check-theme-template.test.mjs: 176 passed.build.test.mjs -t "theme template"(the shipped template builds with no warnings): passed.pnpm vitest run packages/core/src: 14455 passed. Of the failures,postinstall.test.mjsand theMarkdown.fr23.perf.test.tstiming tests also fail on cleanmainhere. The rest (DateTimeInputTouch, aMultiSelectorbottom-sheet test, and theTable.perfbudgets) fail only under the parallel full-suite load: 241 + 12 tests pass when those files run on their own.pnpm -F @astryxdesign/core typecheck(includingtypecheck:docs): clean.eslinton changed files: 0 errors, 0 warnings.prettier --checkon changed TS/MD files: clean.pnpm check:repo(pre-commit hook): passes.node scripts/check-changesets.mjs: passes.