An open source design system that's fully customizable and agent ready
TypeScript
fix(banner): move the 'banner-icon' theme target onto the status Icon so 'status:X' overrides reach the glyph (#4166) (#4201)
Jiun Shind6d345c5bdf3
diff --git a/.changeset/banner-info-icon-themeable.md b/.changeset/banner-info-icon-themeable.mdnew file mode 100644index 0000000000..8185452f0c--- /dev/null+++ b/.changeset/banner-info-icon-themeable.md@@ -0,0 +1,7 @@+---+'@astryxdesign/core': patch+---++[fix] Banner: the 'banner-icon' theme target now rides on the default status Icon itself instead of its layout wrapper, so theme component overrides ('banner-icon' + 'status:X') that set color actually reach the glyph. The Icon keeps its existing color variant (info still renders accent) and same-element rules in @layer astryx-theme win over it, so default rendering is unchanged. Contract note: '.astryx-banner-icon' now matches the icon element rather than the wrapper when the default icon renders; a theme that used the target for wrapper layout (margin, alignment) now styles the glyph instead. With a custom `icon` node the target stays on the layout-only wrapper, since core never injects props into consumer elements (#4166)++@jiunshinndiff --git a/packages/core/src/Banner/Banner.test.tsx b/packages/core/src/Banner/Banner.test.tsxindex b4bbc5eee4..9fd7309786 100644--- a/packages/core/src/Banner/Banner.test.tsx+++ b/packages/core/src/Banner/Banner.test.tsx@@ -3,7 +3,8 @@/*** @file Banner.test.tsx* @input Uses vitest, @testing-library/react, Banner component- * @output Unit tests for Banner component behavior+ * @output Unit tests for Banner component behavior, including the+ * 'banner-icon' theme target riding on the status icon glyph (#4166)* @position Testing; validates Banner.tsx implementation** SYNC: When modified, update this header@@ -337,6 +338,62 @@ describe('Banner', () => {expect(ref.current).toBeInstanceOf(HTMLDivElement);});+ // =========================================================================+ // Status icon color theming (#4166)+ // =========================================================================++ it("carries the 'banner-icon' theme target on the default status icon glyph", () => {+ // Theme overrides for 'banner-icon' + 'status:X' compile to+ // '.astryx-banner-icon.<status>' (parseStyleKey). The target must sit on+ // the <Icon> span itself so those same-element rules in+ // @layer astryx-theme beat the Icon's own color variant.+ const statuses = ['info', 'warning', 'error', 'success'] as const;+ for (const status of statuses) {+ const {container, unmount} = render(+ <Banner status={status} title={`${status} banner`} />,+ );+ const glyph = container.querySelector(+ `.astryx-icon.astryx-banner-icon.${status}`,+ );+ expect(glyph).not.toBeNull();+ expect(glyph).toHaveAttribute('data-status', status);+ // Exactly one element carries the target — the layout wrapper no+ // longer does.+ expect(container.querySelectorAll('.astryx-banner-icon')).toHaveLength(1);+ unmount();+ }+ });++ it('keeps the color variant on the theme-target element (regression pin for #4166)', () => {+ // Pre-fix, '.astryx-banner-icon.info' matched the layout wrapper while+ // the color variant (data-color="accent") sat on an inner span that a+ // theme override could never reach. Target and paint now share one+ // element.+ const {container} = render(<Banner status="info" title="Info" />);+ const target = container.querySelector('.astryx-banner-icon.info');+ expect(target).toHaveAttribute('data-color', 'accent');+ });++ it("keeps the 'banner-icon' target on the wrapper for a custom icon node", () => {+ // Core never injects props into consumer elements, so with a custom+ // `icon` the target stays on the (layout-only) wrapper and overrides+ // reach the node via inheritance. The node itself is untouched.+ const {container} = render(+ <Banner+ status="info"+ title="Custom icon"+ icon={<span data-testid="custom-glyph">i</span>}+ />,+ );+ const targets = container.querySelectorAll('.astryx-banner-icon');+ expect(targets).toHaveLength(1);+ expect(targets[0]?.tagName).toBe('DIV');+ expect(targets[0]).toHaveAttribute('aria-hidden', 'true');+ const custom = container.querySelector('[data-testid="custom-glyph"]');+ expect(custom).not.toBeNull();+ expect(custom?.className).toBe('');+ });+// =========================================================================// Icon registry integration// =========================================================================diff --git a/packages/core/src/Banner/Banner.tsx b/packages/core/src/Banner/Banner.tsxindex efa0ec67dc..768b800c4a 100644--- a/packages/core/src/Banner/Banner.tsx+++ b/packages/core/src/Banner/Banner.tsx@@ -12,6 +12,9 @@* - Root container: layout-only wrapper (flex column), no visual styling, no theme target* - Header area (themeProps 'banner'): colored status background with icon, title, description, actions, dismiss* - Content area (themeProps 'banner-content'): collapsible card background for additional content (children)+ * - Status icon (themeProps 'banner-icon'): the target rides on the default+ * <Icon> itself — the element that paints — so 'status:X' overrides reach+ * the glyph (#4166); for a custom `icon` node it stays on the layout wrapper* - No left border accent — color is expressed through the full header background* - Each visual area owns its own border-radius (no overflow:clip on the container)* - When children are provided, a collapse/expand toggle button appears in the end area@@ -445,16 +448,32 @@ export function Banner({: styles.headerCardStandalone),),)}>+ {/* The 'banner-icon' target rides on the element that paints: the+ default <Icon> below, or this wrapper when a custom `icon` node+ is passed (core never injects props into consumer elements, so+ overrides reach it via inheritance). The wrapper itself stays+ layout-only. */}<div- {...mergeProps(- themeProps('banner-icon', {status}),- stylex.props(styles.iconWrapper),- )}+ {...(icon != null+ ? mergeProps(+ themeProps('banner-icon', {status}),+ stylex.props(styles.iconWrapper),+ )+ : stylex.props(styles.iconWrapper))}aria-hidden="true">{icon != null ? (icon) : (- <Icon icon={defaultIconName} size="md" color={iconColor} />+ // Applied to the status <Icon> itself rather than the wrapper, so+ // the element that paints the glyph is the element a theme+ // targets — a 'banner-icon' 'status:X' color override beats the+ // Icon's own variant from @layer astryx-theme (#4166).+ <Icon+ icon={defaultIconName}+ size="md"+ color={iconColor}+ {...themeProps('banner-icon', {status})}+ />)}</div><div {...stylex.props(styles.headerContent)}>