An open source design system that's fully customizable and agent ready
TypeScript
feat(DateTimeInput): expose toggle-icon and clock-icon theme targets (#5148)
freddymeta640a05bbe2e1
diff --git a/.changeset/datetime-input-icon-targets.md b/.changeset/datetime-input-icon-targets.mdnew file mode 100644index 0000000000..7987d3ff94--- /dev/null+++ b/.changeset/datetime-input-icon-targets.md@@ -0,0 +1,7 @@+---+'@astryxdesign/core': patch+---++[feat] DateTimeInput: expose `date-time-input-toggle-icon` (calendar glyph, with open/closed `state`) and `date-time-input-clock-icon` (leading time glyph) theme targets, so a theme can size and color the leading icons — matching the `date-input-toggle-icon` seam DateInput already offers.++@freddymetadiff --git a/packages/core/src/DateTimeInput/DateTimeInput.doc.mjs b/packages/core/src/DateTimeInput/DateTimeInput.doc.mjsindex fcfbcca18f..ca14148de2 100644--- a/packages/core/src/DateTimeInput/DateTimeInput.doc.mjs+++ b/packages/core/src/DateTimeInput/DateTimeInput.doc.mjs@@ -204,6 +204,8 @@ export const docs = {className: 'astryx-date-time-input-time-segment',visualProps: ['size', 'status'],},+ {className: 'astryx-date-time-input-toggle-icon', states: ['state']},+ {className: 'astryx-date-time-input-clock-icon'},],},usage: {@@ -508,6 +510,8 @@ export const docsZh = {className: 'astryx-date-time-input-time-segment',visualProps: ['size', 'status'],},+ {className: 'astryx-date-time-input-toggle-icon', states: ['state']},+ {className: 'astryx-date-time-input-clock-icon'},],},};diff --git a/packages/core/src/DateTimeInput/DateTimeInput.test.tsx b/packages/core/src/DateTimeInput/DateTimeInput.test.tsxindex e157a76158..513681c5fb 100644--- a/packages/core/src/DateTimeInput/DateTimeInput.test.tsx+++ b/packages/core/src/DateTimeInput/DateTimeInput.test.tsx@@ -15,6 +15,7 @@ import userEvent from '@testing-library/user-event';import {getButton, queryButton} from '../__tests__/fastRoleQueries';import {DateTimeInput} from './DateTimeInput';import type {ISODateTimeString} from './DateTimeInput';+import {Icon} from '../Icon';import {defineTheme} from '../theme/defineTheme';import {generateThemeCSS} from '../theme/generateThemeRules';import {InternationalizationProvider} from '../i18n';@@ -1063,6 +1064,100 @@ describe('DateTimeInput', () => {expect(css).toContain('block-size: var(--size-element-lg)');expect(css).toContain('padding-inline: var(--spacing-4)');});++ it('renders the toggle-icon target on the calendar glyph with open/closed state', async () => {+ const {container} = render(+ <DateTimeInput label="Meeting" onChange={() => {}} />,+ );+ // The stable target lands on the icon element itself (not the button),+ // so a theme can restyle just this glyph — mirroring+ // `date-input-toggle-icon`.+ const icon = container.querySelector(+ '.astryx-date-time-input-toggle-icon',+ );+ expect(icon).not.toBeNull();+ expect(icon).toHaveClass('astryx-icon');+ expect(icon).toHaveAttribute('data-state', 'collapsed');++ fireEvent.click(getButton('Open calendar'));+ await waitFor(() => {+ expect(+ container.querySelector('.astryx-date-time-input-toggle-icon'),+ ).toHaveAttribute('data-state', 'expanded');+ });+ });++ it('renders the clock-icon target on the leading time glyph', () => {+ const {container} = render(+ <DateTimeInput label="Meeting" onChange={() => {}} />,+ );+ const icon = container.querySelector(+ '.astryx-date-time-input-clock-icon',+ );+ expect(icon).not.toBeNull();+ expect(icon).toHaveClass('astryx-icon');+ });++ it('leaves both leading glyphs byte-identical to a plain secondary/sm icon by default', () => {+ // The targets are purely additive: the stable target class and its+ // reflected state add nothing to the render until a theme targets them.+ // Guard that by diffing each glyph's StyleX classes against a standalone+ // secondary/sm icon, excluding only the additive target/state classes.+ const {container} = render(+ <DateTimeInput label="Meeting" onChange={() => {}} />,+ );+ const calendarIcon = container.querySelector(+ '.astryx-date-time-input-toggle-icon',+ ) as HTMLElement;+ const clockIcon = container.querySelector(+ '.astryx-date-time-input-clock-icon',+ ) as HTMLElement;++ const {container: refContainer} = render(+ <Icon icon="calendar" size="sm" color="secondary" />,+ );+ const refIcon = refContainer.querySelector('.astryx-icon') as HTMLElement;++ const themeTargetClasses = new Set([+ 'astryx-date-time-input-toggle-icon',+ 'astryx-date-time-input-clock-icon',+ 'collapsed',+ 'expanded',+ ]);+ const styleClasses = (el: HTMLElement) =>+ el.className+ .split(' ')+ .filter(c => !themeTargetClasses.has(c))+ .sort();++ expect(styleClasses(calendarIcon)).toEqual(styleClasses(refIcon));+ expect(styleClasses(clockIcon)).toEqual(styleClasses(refIcon));+ });++ it('exposes the icon targets so a theme reaches their size and per-state color', () => {+ // jsdom cannot resolve the @layer cascade, so the generated CSS is what+ // proves a same-element theme rule can reach these glyphs and win over+ // the icon's own base size/color.+ const theme = defineTheme({+ name: 'date-time-input-icon-targets-test',+ components: {+ 'date-time-input-toggle-icon': {+ base: {width: '14px', height: '14px', fontSize: '14px'},+ 'state:expanded': {color: 'var(--color-icon-primary)'},+ },+ 'date-time-input-clock-icon': {+ base: {width: '14px', height: '14px', fontSize: '14px'},+ },+ },+ });+ const css = generateThemeTestCSS(theme);++ expect(css).toContain('.astryx-date-time-input-toggle-icon {');+ expect(css).toContain('.astryx-date-time-input-toggle-icon.expanded');+ expect(css).toContain('.astryx-date-time-input-clock-icon {');+ expect(css).toContain('width: 14px');+ expect(css).toContain('color: var(--color-icon-primary)');+ });});});diff --git a/packages/core/src/DateTimeInput/DateTimeInput.tsx b/packages/core/src/DateTimeInput/DateTimeInput.tsxindex ce5a0366eb..34eea3faf7 100644--- a/packages/core/src/DateTimeInput/DateTimeInput.tsx+++ b/packages/core/src/DateTimeInput/DateTimeInput.tsx@@ -960,7 +960,20 @@ export function DateTimeInput({styles.iconButton,isEffectivelyDisabled && styles.iconButtonDisabled,)}>- <Icon icon="calendar" size="sm" color="secondary" />+ <Icon+ icon="calendar"+ size="sm"+ color="secondary"+ // Stable theme target on the calendar toggle glyph, so a theme+ // can restyle just this icon (color, size, hover) — and each+ // open/closed state — via `defineTheme`, mirroring+ // `date-input-toggle-icon`. Same-element rules in+ // @layer astryx-theme win over the icon's own base color/size,+ // which a segment-level target could not reach.+ {...themeProps('date-time-input-toggle-icon', {+ state: popover.isOpen ? 'expanded' : 'collapsed',+ })}+ /></button><inputref={mergeRefs(ref, dateInputRef)}@@ -1039,7 +1052,16 @@ export function DateTimeInput({),)}><div {...stylex.props(styles.icon)}>- <Icon icon="clock" size="sm" color="secondary" />+ <Icon+ icon="clock"+ size="sm"+ color="secondary"+ // Stable theme target on the leading clock glyph, so a theme can+ // restyle just this icon (color, size) via `defineTheme`. The+ // time segment has no toggle button — the clock is a static+ // leading affordance — so this carries no interactive state.+ {...themeProps('date-time-input-clock-icon')}+ /></div><inputref={timeInputRef}