An open source design system that's fully customizable and agent ready
TypeScript
feat(date-range-input): add clear + calendar-toggle icon theme targets (+ Icon styling-prop handling) (#4456)
freddymeta53c21e7119c6
diff --git a/.changeset/date-range-input-icon-theme-targets.md b/.changeset/date-range-input-icon-theme-targets.mdnew file mode 100644index 0000000000..09a754812b--- /dev/null+++ b/.changeset/date-range-input-icon-theme-targets.md@@ -0,0 +1,7 @@+---+'@astryxdesign/core': patch+---++[feat] DateRangeInput: add `astryx-date-range-input-clear-icon` and `astryx-date-range-input-toggle-icon` theme targets on the clear and calendar-toggle glyphs, so consumers can recolor, hover-morph, and resize them via `defineTheme` instead of a fragile descendant selector or raw CSS. The toggle icon reflects its open/closed state as a `data-state` attribute. `Icon` now fully handles its styling props (`className`, `style`, `xstyle`) so they compose with its base styles instead of being dropped. Default rendering is unchanged.++@freddymetadiff --git a/apps/storybook/stories/DateRangeInput.stories.tsx b/apps/storybook/stories/DateRangeInput.stories.tsxindex d01fd5032d..dab2bc9d08 100644--- a/apps/storybook/stories/DateRangeInput.stories.tsx+++ b/apps/storybook/stories/DateRangeInput.stories.tsx@@ -5,6 +5,7 @@ import type {Meta, StoryObj} from '@storybook/react';import {DateRangeInput} from '@astryxdesign/core/DateRangeInput';import type {DateRange} from '@astryxdesign/core/DateRangeInput';import type {ISODateString} from '@astryxdesign/core/Calendar';+import {Theme, defineTheme} from '@astryxdesign/core/theme';function daysAgo(n: number): ISODateString {const d = new Date();@@ -339,7 +340,8 @@ export const StatusVariantComparison: Story = {const [a, setA] = useState<DateRange | null>(null);const [b, setB] = useState<DateRange | null>(null);return (- <div style={{display: 'flex', flexDirection: 'column', gap: 24, width: 320}}>+ <div+ style={{display: 'flex', flexDirection: 'column', gap: 24, width: 320}}><DateRangeInputlabel="Attached (default)"value={a}@@ -357,3 +359,56 @@ export const StatusVariantComparison: Story = {);},};++/**+ * Theme the clear and calendar-toggle glyphs precisely via `defineTheme`.+ * `components['date-range-input-clear-icon'].base` and+ * `components['date-range-input-toggle-icon'].base` scope overrides to the+ * icons themselves (via the `astryx-date-range-input-*-icon` targets), so a+ * theme can recolor, hover-morph, and resize them — without a fragile+ * descendant selector or raw CSS. Same-element rules in `@layer astryx-theme`+ * win over each icon's own base color/size.+ */+const iconTheme = defineTheme({+ name: 'date-range-input-icon-demo',+ components: {+ 'date-range-input-clear-icon': {+ base: {+ width: '12px',+ height: '12px',+ fontSize: '12px',+ color: 'var(--color-icon-secondary)',+ ':hover': {color: 'var(--color-accent)'},+ },+ },+ 'date-range-input-toggle-icon': {+ base: {+ width: '14px',+ height: '14px',+ fontSize: '14px',+ color: 'var(--color-accent)',+ },+ },+ },+});++export const ThemedIcons: Story = {+ render: () => {+ const [value, setValue] = useState<DateRange | null>({+ start: daysAgo(7),+ end: today(),+ });+ return (+ <Theme theme={iconTheme} mode="light">+ <div style={{width: 320}}>+ <DateRangeInput+ label="Icons themed (12px clear w/ hover, 14px accent toggle)"+ value={value}+ onChange={setValue}+ hasClear+ />+ </div>+ </Theme>+ );+ },+};diff --git a/packages/core/src/DateRangeInput/DateRangeInput.doc.mjs b/packages/core/src/DateRangeInput/DateRangeInput.doc.mjsindex 60ebefc41f..4feb09fcff 100644--- a/packages/core/src/DateRangeInput/DateRangeInput.doc.mjs+++ b/packages/core/src/DateRangeInput/DateRangeInput.doc.mjs@@ -154,6 +154,8 @@ export const docs = {theming: {targets: [{className: 'astryx-date-range-input', visualProps: ['size', 'status']},+ {className: 'astryx-date-range-input-toggle-icon', states: ['state']},+ {className: 'astryx-date-range-input-clear-icon'},],},usage: {diff --git a/packages/core/src/DateRangeInput/DateRangeInput.test.tsx b/packages/core/src/DateRangeInput/DateRangeInput.test.tsxindex f798ce4133..e6baa64d1d 100644--- a/packages/core/src/DateRangeInput/DateRangeInput.test.tsx+++ b/packages/core/src/DateRangeInput/DateRangeInput.test.tsx@@ -19,6 +19,9 @@ import userEvent from '@testing-library/user-event';import {getButton, queryButton} from '../__tests__/fastRoleQueries';import {DateRangeInput} from './DateRangeInput';import type {DateRange} from './DateRangeInput';+import {Icon} from '../Icon';+import {defineTheme} from '../theme/defineTheme';+import {generateThemeCSSFlat} from '../theme/generateThemeRules';describe('DateRangeInput', () => {it('renders with label', () => {@@ -472,11 +475,15 @@ describe('DateRangeInput', () => {});});-describe('DateRangeInput statusVariant forwarding', () => {it('defaults to attached (status renders with data-variant="attached")', () => {const {container} = render(- <DateRangeInput label="Range" value={null} onChange={() => {}} status={{type: 'error', message: 'Required'}} />,+ <DateRangeInput+ label="Range"+ value={null}+ onChange={() => {}}+ status={{type: 'error', message: 'Required'}}+ />,);expect(container.querySelector('.astryx-field-status')).toHaveAttribute('data-variant',@@ -486,7 +493,13 @@ describe('DateRangeInput statusVariant forwarding', () => {it('forwards statusVariant="detached" to the underlying Field status', () => {const {container} = render(- <DateRangeInput label="Range" value={null} onChange={() => {}} status={{type: 'error', message: 'Required'}} statusVariant="detached" />,+ <DateRangeInput+ label="Range"+ value={null}+ onChange={() => {}}+ status={{type: 'error', message: 'Required'}}+ statusVariant="detached"+ />,);expect(container.querySelector('.astryx-field-status')).toHaveAttribute('data-variant',@@ -494,3 +507,107 @@ describe('DateRangeInput statusVariant forwarding', () => {);});});++describe('DateRangeInput icon theme targets', () => {+ const RANGE: DateRange = {start: '2026-03-15', end: '2026-03-22'};++ // Resolve a glyph span (the astryx-icon element) inside a given button,+ // independent of the theme target class.+ const iconIn = (button: HTMLElement): HTMLElement => {+ const icon = button.querySelector('.astryx-icon');+ if (icon == null) {+ throw new Error('icon not found');+ }+ return icon as HTMLElement;+ };++ it('renders astryx-date-range-input-clear-icon on the clear glyph', () => {+ render(+ <DateRangeInput+ label="Range"+ value={RANGE}+ onChange={() => {}}+ hasClear+ />,+ );+ // The stable target lands on the icon element itself (not the button), so a+ // theme can restyle just this glyph (color, size, hover) via defineTheme —+ // a button-level target could not reach the icon's own color/size.+ const icon = iconIn(getButton('Clear Range'));+ expect(icon).toHaveClass('astryx-date-range-input-clear-icon');+ expect(icon).toHaveClass('astryx-icon');+ });++ it('renders astryx-date-range-input-toggle-icon on the calendar-toggle glyph, reflecting state', () => {+ render(<DateRangeInput label="Range" value={null} onChange={() => {}} />);+ const icon = iconIn(getButton('Open calendar'));+ expect(icon).toHaveClass('astryx-date-range-input-toggle-icon');+ expect(icon).toHaveClass('astryx-icon');+ // Closed by default → data-state="collapsed".+ expect(icon).toHaveAttribute('data-state', 'collapsed');+ });++ it('renders the default icons (secondary color, sm size) byte-identically', () => {+ // Pixel-identical default guard: the glyphs must carry the exact same+ // StyleX color/size classes as a standalone secondary/sm icon. The added+ // target class is purely additive — it changes nothing until a theme+ // targets it.+ render(+ <DateRangeInput+ label="Range"+ value={RANGE}+ onChange={() => {}}+ hasClear+ />,+ );+ const clearIcon = iconIn(getButton('Clear Range'));++ const {container: refContainer} = render(+ <Icon icon="close" size="sm" color="secondary" />,+ );+ const refIcon = refContainer.querySelector('.astryx-icon') as HTMLElement;++ const styleClasses = (el: HTMLElement) =>+ el.className+ .split(' ')+ .filter(+ c =>+ c !== 'astryx-date-range-input-clear-icon' &&+ c !== 'astryx-date-range-input-toggle-icon',+ )+ .sort();++ expect(styleClasses(clearIcon)).toEqual(styleClasses(refIcon));+ });++ it('exposes the icon targets so a theme reaches icon color, size, and hover', () => {+ // jsdom cannot resolve the @layer cascade, so the DOM-class assertions+ // above (targets land on the icon elements) plus this generation assertion+ // (the theme emits same-element icon rules in @layer astryx-theme) together+ // prove the seam: a same-element theme rule wins over the icon's own+ // base-layer color/size.+ const theme = defineTheme({+ name: 'date-range-input-icon-test',+ components: {+ 'date-range-input-clear-icon': {+ base: {+ width: '12px',+ height: '12px',+ fontSize: '12px',+ color: 'var(--color-icon-secondary)',+ ':hover': {color: 'var(--color-icon-primary)'},+ },+ },+ 'date-range-input-toggle-icon': {+ base: {width: '14px', height: '14px', fontSize: '14px'},+ },+ },+ });+ const css = generateThemeCSSFlat(theme);+ expect(css).toContain('.astryx-date-range-input-clear-icon');+ expect(css).toContain('.astryx-date-range-input-toggle-icon');+ expect(css).toContain(':hover');+ expect(css).toContain('12px');+ expect(css).toContain('14px');+ });+});diff --git a/packages/core/src/DateRangeInput/DateRangeInput.tsx b/packages/core/src/DateRangeInput/DateRangeInput.tsxindex d93c71b0a2..cd140cb64a 100644--- a/packages/core/src/DateRangeInput/DateRangeInput.tsx+++ b/packages/core/src/DateRangeInput/DateRangeInput.tsx@@ -577,7 +577,14 @@ export function DateRangeInput({styles.iconButton,isEffectivelyDisabled && styles.iconButtonDisabled,)}>- <Icon icon="calendar" size="sm" color="secondary" />+ <Icon+ icon="calendar"+ size="sm"+ color="secondary"+ {...themeProps('date-range-input-toggle-icon', {+ state: popover.isOpen ? 'expanded' : 'collapsed',+ })}+ /></button><buttonref={ref}@@ -610,7 +617,12 @@ export function DateRangeInput({onClick={handleClear}aria-label={t('@astryx.dateInput.clear', {label})}{...stylex.props(styles.iconButton)}>- <Icon icon="close" size="sm" color="secondary" />+ <Icon+ icon="close"+ size="sm"+ color="secondary"+ {...themeProps('date-range-input-clear-icon')}+ /></button>)}{isBusy && <Spinner size="sm" />}