Repository navigation
feat(buttons): apply theme-owned icon styling to the Button family - #7221
rubyycheung wants to merge 2 commits into
Conversation
Work in progress, not review-ready. Declares the button-leading role (disabled, pressed, loading) and routes a direct Astryx Icon in Button's icon position through the shared role helper with one effective state and a wrapper box resolved from the same inputs as the glyph. Consumer type fixtures, stories, docs and changeset are still pending.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
Button, IconButton and ToggleButton render a direct Astryx Icon in the `button-leading` role. The role reports one effective state (disabled, pressed or loading) that changes appearance only, and the Button wrapper and glyph share one final theme dimension. With no theme icon policy the markup and pixels match the released Button; other icon content keeps the released box and implicit size context. Completes the Button-family example started in the previous checkpoint: public consumer type programs now account for Core's role, the icon engine story uses a real nonparticipating control, new stories carry before/after and computed-box hooks, and builder docs and a changeset describe the role.
PR Analysis Report
|
There was a problem hiding this comment.
Approval waits on a maintainer to provide or identify the governing spec for making the Button family's leading icon a theme-stylable button-leading role: current spec fixes the owned-slot default size and treats component icon slots as source mappings only, so that spec needs to settle theme role sizes, state appearances (including what loading should do, since its artwork is mostly visible only during the spinner delay), whether the icon box may follow an explicit child Icon size, and what componentIcons['button-leading'] means when callers always supply the icon. Unsized Icons with no theme policy keep their released markup and boxes, and under a role theme the box and glyph agree, but these fixes are needed whatever that decision is:
- A ToggleButton whose
iconandpressedIconhave different explicit sizes now grows on press (104px to 108px in Chromium), which the family rule that pressed state and icon replacement must not change outer dimensions forbids; reserve one box across both icons. - The re-rendered Icon loses the caller element's React
key, so changing the key no longer remounts it; carryicon.keythrough and add a test. - The
ThemeSwitchingstory's play function fails in a browser (the nestedpolicyregion measures 28px, not 18px) because a nested theme inherits the outer role size; clear it with'button-leading': nullor change the expectation, and cover that nesting in the unit suite. - The changeset says Buttons with no theme policy look exactly as before, but an explicitly sized Icon now sets the box (an
mdButton with asize="md"Icon is 4px wider); describe that change and how to keep the old look.
[Automated review]
| theme: DefinedTheme | undefined, | ||
| ): ReactNode { | ||
| if (isValidElement<IconProps>(icon) && icon.type === Icon) { | ||
| const {icon: source, ...iconProps} = icon.props; |
There was a problem hiding this comment.
Re-rendering the caller's Icon element from its props drops that element's React key: key is not part of icon.props, and neither this destructuring nor the slot helper it calls reads or forwards icon.key, so a caller who changes key on the element to force a remount (for example, to restart a stateful supplied-artwork component) no longer gets one, where the released render preserved it. The neighboring forwarding of label, ref, class, style, and data attributes is already covered by the new suite; please also carry the original element's key through the re-render — or, if dropping it is genuinely intended, document and test that expectation so the behavior is a decision rather than a side effect.
AST-054 PR 4 — Apply theme-owned icon styling to the Button family
Draft. Blocked on authority approval (#6891, #7116) and on #7219, which this change completes as its first real component example. Not landable. Real-browser screenshots, Node 24 and full CI remain explicitly pending.
User need
Theme authors want the icon inside a Button to follow their icon system — its size, its appearance when the button is disabled, pressed or loading, and the weight that goes with its size — without product code passing new props, and without Buttons changing shape. This is the first end-to-end component example: theme size, appearance, weight and state flow into a real Button, the button's icon space and the icon itself always agree, and default pixels and accessibility stay exactly as they are.
Problem and solution fit
button-leading, for the Button family's owned icon position. It reports at most one ofdisabled,pressedorloading, highest first. No universal state list and no new caller props.family:buttonsgives Button one owned icon slot (AV2: a leading icon;endContentis arbitrary trailing content, not an icon position) and says IconButton and ToggleButton reuse Button's surface. Both already render their icon through Button'sicon, so they share the role. No trailing role, no IconButton- or ToggleButton-specific role, and no other component family.disabledcomes from explicit or group disabled — not loading-induced inactivity, keeping FR4's distinction between pending and disabled.pressedis the renderedaria-pressed, so ToggleButton (and any caller-rendered pressed button) reports exactly the value it exposes (FR10).loadingis loading or a pending action.<Icon>in Button'siconis re-rendered through the shared private role helper from feat(core): add component icon role and state infrastructure #7219. The Button wrapper box comes from the same resolver inputs as the glyph — explicit Icon size, then theme role-size override, then the control-size default (sm/md→sm,lg→md, FR7) — so the wrapper and glyph paint one theme-resolved dimension, including when an explicit child size wins.pressedIconstays the caller's source override; state changes appearance only and never weight; explicit Icon appearance/weight still win; control height, padding, gap, label, focus, keyboard, disabled, loading,aria-busy, tooltip and link behavior are unchanged.Current specification and dependencies
Code base: #7219 at exactly
a0b54a8a606c62f4765cb4a1f6f0d0f39b9bc58f, itself on #7214 (724d3f3df635503d15e1902dbf4766f4172fa172). #7219 stays stacked with this change; it is not independently release-ready.Approval dependencies, not code bases: AST-054 proposal #6891 and owner-authority proposal #7116. Linking them does not imply approval or make a draft record current. AST-054 remains draft. No specification, architecture, design, family or authority record is edited here, and no accepted-but-unshipped owner note is changed; that projection stays with #7116.
Current owners read for the exact delta:
family:buttons(current) — FR1–FR4 and FR6 (names, native semantics, disabled, pending, pressed state), FR7 (shared size:sm/mdcontrols default an owned-slot Icon tosm,lgtomd; explicit Icon size wins; label weight, pressed state, loading and icon replacement do not change outer control dimensions), FR10 (public, rendered and theming states agree), AV1–AV3.component:Icon(current) — FR5 (explicit size wins, then the owning component's default, thenmd) and the accessibility rules AR1–AR3.architecture:icon-resolution-and-component-slots(current) — routed below.The proposed FR13 in #7116 (metadata-bearing Button role; wrapper and glyph from one final resolution, including when an explicit child size wins;
pressedIconstays a source override; family policy never chooses appearance or weight) is the draft direction this implements. It is pending, not current.Public delta and caller burden
Theme authors can now write:
ComponentIconSlotName,ComponentIconStateNameandParticipatingComponentIconSlotNameincludebutton-leadingand its three states, andComponentIconMapis keyed bybutton-leadingrather than beingRecord<string, never>. The feat(core): add component icon role and state infrastructure #7219 consumer programs are updated to assert exactly that.sm); explicit Icon size and theme role-size overrides still win, and public Icon props still cannot set role, state or default size.Design and alternatives
:has()rule, so the shared box is deterministic in SSR and testable without layout.pressedreadsaria-pressedinstead of a new private ToggleButton channel, so the reported state always equals the rendered semantics.disabled → pressed → loading: explicit non-operability is the persistent condition; pressed is a retained value that should show during an optimistic pending action; loading is transient and its content is hidden once the spinner shows.Evidence
Button/buttonIconRole.test.tsx, 54 jsdom cases — role metadata and immutability; precedence for every condition mix; public types (finite Button states, no Button role/state props,byStatecannot choose weight or invent a state); byte-identical default markup forsm/md/lgwith and without a policy-free theme, plus IconButton, ToggleButton, grouped, loading and disabled; control and label classes unchanged under a role theme; wrapper and glyph share 19px/23px theme dimensions per control size, a 43px role-size override with final-size weight for every control size, null clearing back to the control default, explicit child size with the wrapper following, sparse artwork keeping the final box, nonparticipating content keeping the released box and context, theme switching and nested themes; state appearance for rest/disabled/loading/disabled-over-loading/aria-pressed, unchanged final-size weight in every state, disabled ButtonGroup, explicit appearance/weight winning, a real ToggleButton press changing appearance only with a stable box,pressedIconsource override, ToggleButtonGroup selection; public prop spoofing filtered; the shared button pattern (7 rows) and toggle-button pattern (3 rows) from the existing accessibility contracts rendered with participating themed icons; decorative glyph and label-only name; Icon label/ref/class/style/data forwarding; keyboard activation and disabled blocking; loading busy/hidden content with a stable box; SSR markup with the shared box and hydration without mismatch.Core/Button/Icon Rolestories —DefaultPixels(released vs participating pairs for every size, Button and IconButton),RoleSize(no policy / theme dimensions / role size / null-cleared, plus icon-only, toggle, explicit size, sparse artwork and a nonparticipating control),StateAppearance(every state plus a real toggle press),ThemeSwitching(including nested themes) andRootFontScaling(canonical rem vs theme px at a 20px root). Each row is a[data-button-role-case]with a live readout of the control, wrapper and glyph boxes and the selected artwork; the play functions assert wrapper = glyph boxes, unchanged control height/width/offsets, icon-only squareness, final-size weight, appearance-only state and focusability. The existingIconEnginestory's Button case now uses a real nonparticipating control (an Icon nested in other content) and adds a participating case.Open for review
size="md"in anmdButton) is now wider by the size difference instead of letting the glyph overflow its 16px box. Icon-only buttons keep their square outer box at control height; a browser check of the centered glyph position is still pending. Explicit sizes equal to the family default are unchanged.iconandpressedIcon. Under (1), a text ToggleButton whose two caller icons carry different explicit sizes would change width on press, which current FR7 forbids. Same-size icons (the documented outline/filled swap) keep a stable box, and that case is tested. Options: accept as caller-authored, or reserve the larger box in ToggleButton. This needs an owner ruling; no change is made here.componentIcons['button-leading']type-checks but has no effect. Button never reads the source map because callers always supply the source. The shared map type includes every declared slot.Scope
pressedIconsource override and state-never-changes-weight preserved and tested.Testing
Local execution used Node 22.14.0 and pnpm 11.10.0. Dependency-status auto-install was disabled (
pnpm_config_verify_deps_before_run=false); checks and hooks themselves were not disabled.Core build and types (exact head)
The Core
buildscript sequence was replayed with the installed tool binaries (clean, i18n runtime, pseudo-locale, Babel,tsc --project tsconfig.build.json, CSS, no-dev-JSX, fully-specified). Passed: 701 emitted JavaScript files with declarations, 786 reachable CSS source files / 7,495 rules, no development JSX, every relative specifier fully specified.All passed. The unchanged Neutral theme was built locally with its package build sequence to supply the templates'
theme-neutral/builtprerequisite; nothing tracked changed. Both new/changed stories also type-check against the Storybook project configuration.Focused UI and accessibility
Passed 577/577 across 16 files at the exact head, including the 54 new cases and the existing Button (23) and ToggleButton (16) accessibility-contract suites. jsdom prints its existing "Could not parse CSS stylesheet" notices for injected modern selectors; they are not new failures.
Public consumer programs
Passed: role/state source 5/5 and emitted 5/5 (now asserting Core's
button-leadingvocabulary exactly, no Button role/state props or exports, and no public subpath for the private role module); capability source 5/5 and emitted 6/6.CLI theme build
All 23 CLI theme-build suites passed (447/447) against the fresh Core build with the same root-relative runner used for #7219. The first run's family suite failed only because its fixture shells out to
pnpm exec tscand pnpm was not onPATH; rerun with pnpm available it passed 9/9. No CLI source is changed here.Supporting checks
astryx component Button|IconButton|ToggleButton|Iconandastryx docs icons component-role-state.doc-loadsdynamic-execution inventory for the CLI theme build modules, reproduces unchanged at the basea0b54a8a6; this change touches neither module.pnpm check:repopassed standalone and in the commit hook (existing localization notes are informational).ASTRYX_STRICT_LINT=1,--max-warnings=0): zero errors and warnings. The Node 22 "typeless package" advisory foreslint.config.jsis unchanged baseline output.Button.doc.mjs,IconButton.doc.mjsandToggleButton.doc.mjs, which were already unformatted at the base and are outside lint-staged's patterns; only their prop descriptions changed, to avoid unrelated churn.git diff --checkis clean.pnpm exec lint-stagedandpnpm check:reponormally. The earlier WIP checkpoint commit was created before the worktree's hook directory was installed, so its hooks did not run; its files are covered by the explicit lint, format and repository checks above.Writing rubric results
No knowledge record is edited, so R1–R6 do not apply to this change. Builder-facing
.doc.mjs, docs and template text describe current behavior in plain present tense.Local review receipt
Commits:
8761dc33e4f435fe0e1cfdb4eb6ac1524c406d46(WIP checkpoint, parenta0b54a8a606c62f4765cb4a1f6f0d0f39b9bc58f) and4ef91dcf5820cd037614e9fa68bf70047c97eea5(head). They can be squashed at publication. No push, publication or land.Semantic triggers derived from the delta: accessibility, behavior, compatibility, component-slots, interaction, layout, public-api, react-runtime, styling, testing, theming, visual. The direct owners
family:buttonsandcomponent:Iconwere resolved first (above).review-global-baselines.mjsran with the review head'sorigin/mainmerge basebbeffca1a6f031eec14c4041fc6be17fa597b6abas the authority commit and4ef91dcf5820cd037614e9fa68bf70047c97eea5as the review head: 265 matched claims across 24 records and 35 grouped record/trigger rows.visualmatched no claim. A route contributes only its listed claim.For every grouped row, the router's exact reason template is:
Requested trigger "<trigger>" matched review-applicability:v1 claim "<record>/<claim>".Matched-claim counts by trigger: accessibility 33, behavior 18, compatibility 59, component-slots 6, interaction 6, layout 24, public-api 58, react-runtime 7, styling 10, testing 11, theming 33.
accessibilityspec:AST-009: FR1, FR10, FR11, FR12, FR13, FR14, FR15, FR16, FR2, FR3, FR4, FR5, FR6, FR7, FR9.spec:AST-020: FR1, FR2, FR6.spec:AST-055: AR1, AR2, AR3, AR4.spec:AST-056: AR1, AR2.spec:AST-057: AR1, AR2, AR3.spec:AST-058: AR1, AR2, AR3, AR4, DEC-2, DEC-3.behaviorspec:AST-057: DEC-2, DEC-5, FR4, FR5, FR6, FR7, FR8.spec:AST-058: FR3, FR4, FR5, FR6, FR7, FR8.spec:AST-059: FR2, FR4, FR5, FR7, FR8.compatibilityspec:AST-017: DEC-1, DEC-10, DEC-11, DEC-12, DEC-13, DEC-14, DEC-15, DEC-16, DEC-5, DEC-6, DEC-7, DEC-8, DEC-9, FR12, FR14, FR15, FR16, FR17, FR18, FR19, FR20, FR21, FR22, FR23, FR24, FR25, FR26, FR27, FR28, FR29, FR29a, FR29b, FR29c, FR29d, FR3, FR30, FR31, FR32, FR33, FR34, FR35, FR36, FR37, FR38, FR39, FR4, FR40, FR41, FR42, FR43, FR44, FR45, FR46, FR47, FR48, FR49, FR5, FR50.spec:AST-056: FR7.component-slotsarchitecture:icon-resolution-and-component-slots: INV1, INV10, INV2, INV3, INV6, INV7.interactionarchitecture:interaction-modality: INV1, INV2, INV3, INV4, INV7, INV8.layoutarchitecture:component-size-cascade: INV1, INV2, INV3, INV4, INV5, INV9.architecture:container-padding: INV1, INV10, INV11, INV3, INV6, INV8, INV9.architecture:layer-runtime: INV11, INV12, INV3.spec:AST-059: DEC-2, FR1, FR2, FR3, FR4, FR5, FR6, FR8.public-apiarchitecture:container-padding: INV10, INV11, INV3, INV7, INV9.architecture:public-component-api: INV1, INV12, INV2, INV3, INV4, INV5, INV6, INV7, INV8, INV9.spec:AST-002: DEC-1, DEC-2, DEC-3, DEC-6, DEC-7, DEC-8, FR15, FR4.spec:AST-055: DEC-1, DEC-4, FR1, FR2, FR3, FR7, FR8.spec:AST-056: DEC-1, DEC-2, DEC-3, DEC-4, FR1, FR2, FR3, FR4, FR5, FR6, FR7.spec:AST-057: DEC-1, DEC-3, DEC-4, DEC-6, FR1, FR2, FR3, FR9.spec:AST-058: DEC-1, DEC-4, DEC-5, FR1, FR2, FR9.spec:AST-059: DEC-4, DEC-5, FR6.react-runtimearchitecture:react-component-runtime: INV1, INV2, INV3, INV4, INV5, INV6, INV8.stylingarchitecture:component-style-authoring: INV1, INV2, INV3, INV4, INV5.spec:AST-055: DEC-2, DEC-3, FR4, FR5, FR6.testingarchitecture:component-test-sufficiency: INV1, INV10, INV11, INV2, INV3, INV4, INV5, INV6, INV7.spec:AST-030: FR11, FR7.themingarchitecture:component-theming-surface: INV10, INV12, INV14, INV15, INV3, INV4, INV5, INV6, INV7, INV8, INV9.architecture:theme-application: INV1, INV2, INV3, INV7, INV8, INV9.architecture:theme-authoring-contract: INV1, INV11, INV12, INV3, INV8, INV9.architecture:theme-compilation: INV10, INV2, INV3, INV4, INV6, INV9.spec:AST-012: FR4, FR5, FR6, FR7.