An open source design system that's fully customizable and agent ready
TypeScript
feat(DateRangeInput): expose preset theme targets (#6223)
freddymeta071a98191da5
diff --git a/.changeset/expose-daterangeinput-preset-theming-targets-m3p8.md b/.changeset/expose-daterangeinput-preset-theming-targets-m3p8.mdnew file mode 100644index 0000000000..f2d75e5b0c--- /dev/null+++ b/.changeset/expose-daterangeinput-preset-theming-targets-m3p8.md@@ -0,0 +1,6 @@+---+'@astryxdesign/core': patch+---++[feat] Expose DateRangeInput preset theming targets+@freddymetadiff --git a/apps/storybook/stories/DateRangeInput.stories.tsx b/apps/storybook/stories/DateRangeInput.stories.tsxindex 8a4e7d3b93..1bdbe5669f 100644--- a/apps/storybook/stories/DateRangeInput.stories.tsx+++ b/apps/storybook/stories/DateRangeInput.stories.tsx@@ -125,6 +125,24 @@ export const WithPresetsAndValue: Story = {},};+export const WithDisabledPresets: Story = {+ render: args => {+ const [value, setValue] = useState<DateRange | null>(null);+ return <DateRangeInput {...args} value={value} onChange={setValue} />;+ },+ args: {+ label: 'Constrained analytics period',+ presets: defaultPresets,+ maxRangeSpan: 1,+ },+ play: async ({canvasElement}) => {+ const trigger = canvasElement.querySelector('button');+ if (trigger instanceof HTMLElement) {+ trigger.click();+ }+ },+};+export const WithDescription: Story = {render: args => {const [value, setValue] = useState<DateRange | null>(null);diff --git a/packages/core/src/DateRangeInput/DateRangeInput.doc.mjs b/packages/core/src/DateRangeInput/DateRangeInput.doc.mjsindex b7c27fe043..cf93d11c45 100644--- a/packages/core/src/DateRangeInput/DateRangeInput.doc.mjs+++ b/packages/core/src/DateRangeInput/DateRangeInput.doc.mjs@@ -114,7 +114,7 @@ export const docs = {name: 'presets',type: 'Array<DateRangePreset>',description:- 'Preset ranges shown as quick-select options beside the calendar.',+ 'Preset ranges shown as quick-select options beside the calendar. A preset is disabled when either endpoint violates min, max, or dateConstraints, or when its span violates minRangeSpan or maxRangeSpan.',},{name: 'hasClear',@@ -178,9 +178,21 @@ export const docs = {],theming: {targets: [- {className: 'astryx-date-range-input', visualProps: ['size', 'status'], states: ['disabled']},+ {+ className: 'astryx-date-range-input',+ visualProps: ['size', 'status'],+ states: ['disabled'],+ },{className: 'astryx-date-range-input-toggle-icon', states: ['state']},- {className: 'astryx-date-range-input-clear-icon', deprecatedFor: 'input-clear-icon'},+ {+ className: 'astryx-date-range-input-clear-icon',+ deprecatedFor: 'input-clear-icon',+ },+ {className: 'astryx-date-range-input-presets'},+ {+ className: 'astryx-date-range-input-preset',+ states: ['selected', 'disabled'],+ },],},usage: {@@ -230,6 +242,12 @@ export const docs = {description:'Text above the trigger describing what date range is expected.',},+ {+ name: 'Field surface',+ required: true,+ description:+ 'Bordered control containing the calendar toggle, range trigger, and end affordances.',+ },{name: 'Trigger button',required: true,@@ -252,6 +270,12 @@ export const docs = {required: false,description: 'A list of preset range options beside the calendar.',},+ {+ name: 'Preset button',+ required: false,+ description:+ 'A quick-select action for one preset range, reflecting current and disabled states.',+ },{name: 'Clear button',required: false,@@ -320,7 +344,8 @@ export const docsDense = {isDisabled: 'disable trigger+picker',disabledMessage:'reason shown in a tooltip on hover/focus when disabled; keeps trigger focusable via aria-disabled',- value: 'selected range {start, end} or null; import DateRange type from @astryxdesign/core/DateRangeInput (do not redeclare)',+ value:+ 'selected range {start, end} or null; import DateRange type from @astryxdesign/core/DateRangeInput (do not redeclare)',onChange: 'callback on range change; null on clear',min: 'min selectable date: ISODateString template literal type (YYYY-MM-DD); use string literal or cast `as ISODateString`',max: 'max selectable date: ISODateString template literal type (YYYY-MM-DD); use string literal or cast `as ISODateString`',@@ -329,15 +354,18 @@ export const docsDense = {'max days a range may span, both endpoints counted (7 = a 7-day window); caps the window from the picked start. Selection-only; does not rewrite an over-wide value',minRangeSpan:'min days a range must span, both endpoints counted (2 forbids a single-day range); repeated start click commits one day when allowed, otherwise cancels; default 1',- presets: 'preset ranges as quick-select options',+ presets:+ 'preset ranges as quick-select options; disabled when an endpoint or span violates the corresponding constraints',hasClear: 'clear button when range is set (default true)',placeholder: 'placeholder when empty',size: 'trigger size',status: 'error/warning/success status',- statusVariant: 'How status message is placed: attached overlaps below input; detached floats below w/ spacing; tooltip hides the box and shows it on the status icon.',+ statusVariant:+ 'How status message is placed: attached overlaps below input; detached floats below w/ spacing; tooltip hides the box and shows it on the status icon.',labelTooltip: 'tooltip via info icon at label end',numberOfMonths: 'months in calendar (default 2)',- weekStartsOn: 'first day of week in calendar (0=Sunday, or name e.g. "mon")',+ weekStartsOn:+ 'first day of week in calendar (0=Sunday, or name e.g. "mon")',changeAction:'async action fired after onChange; drives optimistic UI updates via useTransition',isLoading: 'loading state; disables interaction + shows a spinner',diff --git a/packages/core/src/DateRangeInput/DateRangeInput.spec.md b/packages/core/src/DateRangeInput/DateRangeInput.spec.mdnew file mode 100644index 0000000000..02917874eb--- /dev/null+++ b/packages/core/src/DateRangeInput/DateRangeInput.spec.md@@ -0,0 +1,203 @@+---+schema_version: 3+template_version: 4+kind: component+id: component:DateRangeInput+authority: current+archive_reason: null+superseded_by: null+approved_by: cixzhang+approved_at: 2026-09-14+owners: [cixzhang]+review_triggers: [theming]+verified_by:+ [+ packages/core/src/DateRangeInput/DateRangeInput.test.tsx,+ packages/core/src/theme/themingTargets.test.ts,+ scripts/check-knowledge.mjs,+ ]+modules: []+families: [family:input-fields, family:overlay-dismissal]+design_specs: []+architecture: [architecture:component-theming-surface]+contributing: []+system_specs: []+---++# DateRangeInput component contract++## Intent++DateRangeInput presents one controlled date range through a labeled field surface.+Its trigger opens a Calendar-backed Popover and may include a list of quick-select+presets beside that calendar.++## Compatibility and migration++- Released default preserved: `yes`+- Compatibility class: additive theme targets plus corrected preset constraint+ enforcement; default appearance, DOM semantics, and public props remain unchanged+- Controlled/uncontrolled behavior: unchanged; DateRangeInput remains controlled+- Migration decision: none++Consumer migration instructions belong in consumer docs and release notes.++## Ownership boundary++**Owns**++- The composite date-range field surface and its range-display trigger.+- The optional preset list, each preset action, and reflection of a preset's current+ and disabled states.+- Converting a selected Calendar range or preset into `onChange` and+ `changeAction` output.++**Does not own / non-goals**++- Label, description, and status presentation — owned by `component:Field` and+ `component:FieldStatus`.+- Calendar-grid rendering and date-cell interaction — owned by+ `component:Calendar`.+- Layer hosting and dismissal — owned by `component:Popover` and+ `family:overlay-dismissal`.+- Shared clear-button presentation — owned by `component:Field`.++## Public concepts++No public prop or value domain is added. This contract records the existing+preset-list anatomy and its additive theming surface.++## Behavioral and layout contract++| ID | Candidate invariant | Basis | Review state |+| --- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------- | -------------------------- |+| FR1 | DateRangeInput MUST present the controlled `value` and emit range changes without maintaining a competing selected range. | Current source, docs, and focused tests | Verified current behavior |+| FR2 | When presets are present, each preset remains an independent button in one labeled group; the applied preset reflects current state and a preset whose endpoint violates `min`, `max`, or `dateConstraints`, or whose range violates `minRangeSpan` or `maxRangeSpan`, reflects disabled state. | Current source, accessibility comments, and focused tests | Verified current behavior |+| FR3 | The preset group and each preset button expose stable theme targets; selected and disabled are states of the preset-button target rather than separate targets. | `architecture:component-theming-surface`; #5417 demand | Approved additive contract |+| FR4 | Adding theme targets MUST NOT change the Popover, Calendar, button, focus, or selection semantics those elements already own. | Composition boundary and compatibility goal | Approved additive contract |++### Allowed variation++- **AV1 — Preset content.** A caller may omit presets or provide any number of+ labeled ranges.+- **AV2 — Calendar layout.** Calendar month count, date constraints, and range+ bounds may vary without changing preset target identity.+- **AV3 — Theme output.** Themes may restyle the preset group and buttons while+ the component's button semantics and state remain unchanged.++### Representative states++| State | Required invariant | Allowed variation |+| ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------- |+| No presets | No preset group or preset-button target renders. | Calendar configuration |+| Presets, no match | Every button carries the preset target with no selected state. | Preset count and labels |+| Applied preset | The matching button carries `aria-current="true"` and the target's selected state. | Selected range |+| Disabled preset | A preset that violates an endpoint date constraint or a range-span constraint is natively disabled and carries the target's disabled state. | Constraint source |++### Transformation and precedence order++- **ORD1 — Preset state.** Resolve each preset's range once, compare it with the+ controlled value, evaluate `min`, `max`, and `dateConstraints` against both+ endpoints, evaluate `minRangeSpan` and `maxRangeSpan` against the full range,+ then reflect selected and disabled state on the same preset-button target.+- **ORD2 — Preset activation.** An enabled preset emits the already-resolved range;+ activation does not resolve the preset again.++Endpoint constraints match Calendar selection: they apply to the preset's start+and end, not every date between them.++### Performance and resources++No new performance or resource constraint is introduced.++## Accessibility contract++- **AR1 — Preset semantics.** Presets remain native buttons in one labeled group,+ navigated independently by Tab.+- **AR2 — Current state.** The applied preset remains exposed with+ `aria-current="true"`; theme state reflection is additive.+- **AR3 — Disabled state.** A preset that violates an endpoint date constraint or+ a range-span constraint remains natively disabled; theme state reflection does+ not replace that behavior.++## Design relationships++| Anatomy or state | Design requirement | Representation authority | Hierarchy role | Component contract |+| ---------------- | --------------------------------------------------------------- | ------------------------------------- | -------------- | ------------------ |+| Field surface | Presents one coherent input boundary. | Current source and input-field family | Prominent | FR1 |+| Calendar popover | Provides range selection without changing field ownership. | Popover and Calendar components | Prominent | FR1, FR4 |+| Preset sidebar | Groups optional shortcuts beside the calendar. | Current source and public docs | Supporting | FR2, FR3 |+| Preset button | Presents one quick-select range and its current/disabled state. | Current source and public docs | Supporting | FR2–FR4, AR1–AR3 |++### Theming anatomy++<!-- anatomy-theming:v1 -->++```json+{+ "Label": {+ "delegatesTo": {"owner": "component:Field", "target": "field-label"}+ },+ "Field surface": {"target": "date-range-input"},+ "Trigger button": {+ "none": {+ "reason": "unsettled: The composite field surface has a target, but the inner range-display button has no separate current target."+ }+ },+ "Calendar icon": {"target": "date-range-input-toggle-icon"},+ "Calendar popover": {+ "delegatesTo": {"owner": "component:Popover", "target": "popover"}+ },+ "Preset sidebar": {"target": "date-range-input-presets"},+ "Preset button": {"target": "date-range-input-preset"},+ "Clear button": {+ "delegatesTo": {"owner": "component:Field", "target": "input-clear-button"}+ },+ "Status message": {+ "delegatesTo": {"owner": "component:FieldStatus", "target": "field-status"}+ }+}+```++The deprecated `date-range-input-clear-icon` alias remains compatibility metadata;+the shared `input-clear-icon` target owns the current glyph contract.++## Family and system relationships++- `family:input-fields` owns field sizing, status placement, loading, disabled+ reasons, and end-control geometry.+- `family:overlay-dismissal` owns the Popover dismissal stack.+- `architecture:component-theming-surface` owns target admission, state+ reflection, and anatomy mapping.++## Verification map++| Contract | Verification | Representative states | Mutation or failure expectation | Audit section |+| ------------------- | -------------------------------------------------------------------------- | ---------------------------------------------------------------------- | --------------------------------------------------------------------------- | ------------------------------ |+| FR1, FR2, AR1–AR3 | `DateRangeInput.test.tsx` | no match, applied preset, endpoint-invalid preset, span-invalid preset | Semantics or state attributes disappear | `audit:DateRangeInput/presets` |+| FR3, FR4 | `DateRangeInput.test.tsx`, `themingTargets.test.ts`, generated probe theme | group target, selected button, disabled button | Target class/state is missing, undocumented, or placed on the wrong element | `audit:DateRangeInput/theming` |+| Theming anatomy map | `scripts/check-knowledge.mjs` | all documented anatomy | Target ownership or anatomy names drift | `audit:DateRangeInput/theming` |++## Decision log++### DEC-1 — Preset group and buttons are public theme anatomy++**Reference:** `component:DateRangeInput/DEC-1`+**Decider:** cixzhang, 2026-09-14++The optional preset sidebar and each quick-select button are stable,+consumer-recognizable parts. `date-range-input-presets` belongs on the group+that owns sidebar presentation; `date-range-input-preset` belongs on each+button, with selected and disabled reflected as states rather than separate+targets. The target additions preserve default visuals and button semantics;+preset constraint enforcement follows FR2 and ORD1–ORD2.++## Open questions++- **OQ1 — Should the inner range-display trigger receive its own target, or remain+ represented only by the composite field surface?** (`human-api`)++## Content boundary++This file does not duplicate the consumer prop table, usage examples, Calendar or+Popover contracts, current audit results, or downstream theme implementation.diff --git a/packages/core/src/DateRangeInput/DateRangeInput.test.tsx b/packages/core/src/DateRangeInput/DateRangeInput.test.tsxindex b7e6db8e40..0d2817c235 100644--- a/packages/core/src/DateRangeInput/DateRangeInput.test.tsx+++ b/packages/core/src/DateRangeInput/DateRangeInput.test.tsx@@ -370,10 +370,15 @@ describe('DateRangeInput', () => {expect(screen.queryByRole('listbox', {hidden: true}),).not.toBeInTheDocument();- expect(- screen.getByRole('group', {name: 'Preset date ranges', hidden: true}),- ).toBeInTheDocument();- expect(getButton('Last 7 days')).toBeInTheDocument();+ const group = screen.getByRole('group', {+ name: 'Preset date ranges',+ hidden: true,+ });+ expect(group).toBeInTheDocument();+ expect(group).toHaveClass('astryx-date-range-input-presets');+ expect(getButton('Last 7 days')).toHaveClass(+ 'astryx-date-range-input-preset',+ );});it('marks the applied preset with aria-current, not aria-selected', () => {@@ -386,11 +391,99 @@ describe('DateRangeInput', () => {/>,);const active = getButton('Last 7 days');+ expect(active).toHaveClass('astryx-date-range-input-preset');+ expect(active).toHaveAttribute('data-selected', 'selected');expect(active).toHaveAttribute('aria-current', 'true');expect(active).not.toHaveAttribute('aria-selected');const inactive = getButton('This month');+ expect(inactive).toHaveClass('astryx-date-range-input-preset');+ expect(inactive).not.toHaveAttribute('data-selected');+ expect(inactive).not.toHaveAttribute('data-disabled');expect(inactive).not.toHaveAttribute('aria-current');});++ it('disables a preset when its start is before min', () => {+ const handleChange = vi.fn();+ render(+ <DateRangeInput+ label="Range"+ value={null}+ onChange={handleChange}+ min="2026-03-02"+ presets={[presets[0]]}+ />,+ );++ const preset = getButton('Last 7 days');+ expect(preset).toBeDisabled();+ fireEvent.click(preset);+ expect(handleChange).not.toHaveBeenCalled();+ });++ it('disables a preset when its end is after max', () => {+ const handleChange = vi.fn();+ render(+ <DateRangeInput+ label="Range"+ value={null}+ onChange={handleChange}+ max="2026-03-06"+ presets={[presets[0]]}+ />,+ );++ const preset = getButton('Last 7 days');+ expect(preset).toBeDisabled();+ fireEvent.click(preset);+ expect(handleChange).not.toHaveBeenCalled();+ });++ it('disables a preset when either endpoint fails dateConstraints', () => {+ const handleChange = vi.fn();+ render(+ <DateRangeInput+ label="Range"+ value={null}+ onChange={handleChange}+ dateConstraints={[date => date.getDate() !== 7]}+ presets={[presets[0]]}+ />,+ );++ const preset = getButton('Last 7 days');+ expect(preset).toBeDisabled();+ fireEvent.click(preset);+ expect(handleChange).not.toHaveBeenCalled();+ });++ it('commits an enabled preset using its already-resolved range', () => {+ const range = {start: '2026-03-01', end: '2026-03-07'} as const;+ const getRange = vi.fn(() => range);+ let getRangeCallsAtChange = 0;+ const handleChange = vi.fn(() => {+ getRangeCallsAtChange = getRange.mock.calls.length;+ });+ render(+ <DateRangeInput+ label="Range"+ value={null}+ onChange={handleChange}+ min="2026-03-01"+ max="2026-03-31"+ dateConstraints={[date => date.getDate() !== 13]}+ minRangeSpan={2}+ maxRangeSpan={7}+ presets={[{label: 'Allowed range', getRange}]}+ />,+ );++ const getRangeCallsBeforeClick = getRange.mock.calls.length;+ const preset = getButton('Allowed range');+ expect(preset).not.toBeDisabled();+ fireEvent.click(preset);+ expect(handleChange).toHaveBeenCalledWith(range);+ expect(getRangeCallsAtChange).toBe(getRangeCallsBeforeClick);+ });});describe('disabledMessage', () => {// jsdom does not implement the Popover API used by the tooltip, so mock@@ -831,7 +924,10 @@ describe('DateRangeInput range-span forwarding', () => {const withinCap = getButton('Last 3 days');const overCap = getButton('Last 30 days');expect(withinCap).not.toBeDisabled();+ expect(withinCap).not.toHaveAttribute('data-disabled');expect(overCap).toBeDisabled();+ expect(overCap).toHaveClass('astryx-date-range-input-preset');+ expect(overCap).toHaveAttribute('data-disabled', 'disabled');fireEvent.click(overCap);expect(handleChange).not.toHaveBeenCalled();diff --git a/packages/core/src/DateRangeInput/DateRangeInput.tsx b/packages/core/src/DateRangeInput/DateRangeInput.tsxindex 13a9b34a7a..37707097fa 100644--- a/packages/core/src/DateRangeInput/DateRangeInput.tsx+++ b/packages/core/src/DateRangeInput/DateRangeInput.tsx@@ -54,6 +54,7 @@ import {type DayOfWeek,type DayOfWeekName,} from '../Calendar';+import {useCalendarConstraints} from '../Calendar/hooks';import {usePopover} from '../Popover';import {useTooltip} from '../Tooltip';import {mergeProps} from '../utils';@@ -376,6 +377,9 @@ export interface DateRangeInputProps extends Omit</*** Preset date ranges shown as quick-select options beside the calendar.+ * A preset is disabled when either endpoint violates `min`, `max`, or+ * `dateConstraints`, or when its span violates `minRangeSpan` or+ * `maxRangeSpan`.*/presets?: ReadonlyArray<DateRangePreset>;@@ -542,6 +546,11 @@ export function DateRangeInput({dialogLabel: t('@astryx.dateRangeInput.dialogLabel'),closeButtonLabel: t('@astryx.dateInput.closeCalendar'),});+ const {isDateDisabled} = useCalendarConstraints({+ min,+ max,+ dateConstraints,+ });const fireChange = useCallback((newValue: DateRange | null) => {@@ -577,14 +586,6 @@ export function DateRangeInput({[fireChange, popover],);- const handlePresetClick = useCallback(- (preset: DateRangePreset) => {- fireChange(preset.getRange());- popover.hide();- },- [fireChange, popover],- );-const handleClear = useCallback((e: React.MouseEvent) => {e.stopPropagation();@@ -713,15 +714,17 @@ export function DateRangeInput({<divrole="group"aria-label={t('@astryx.dateRangeInput.presetDateRanges')}- {...stylex.props(styles.presetSidebar)}>+ {...mergeProps(+ themeProps('date-range-input-presets'),+ stylex.props(styles.presetSidebar),+ )}>{presets.map(preset => {const presetRange = preset.getRange();const isActive = isRangeEqual(value, presetRange);- const isPresetDisabled = !isRangeWithinSpan(- presetRange,- maxRangeSpan,- minRangeSpan,- );+ const isPresetDisabled =+ !isRangeWithinSpan(presetRange, maxRangeSpan, minRangeSpan) ||+ isDateDisabled(plainDateFromISO(presetRange.start)) ||+ isDateDisabled(plainDateFromISO(presetRange.end));return (<buttonkey={preset.label}@@ -733,12 +736,18 @@ export function DateRangeInput({// concept that contradicted the Tab interaction) (forms-5).aria-current={isActive ? 'true' : undefined}disabled={isPresetDisabled}- onClick={() => handlePresetClick(preset)}- {...stylex.props(- focusOutlineStyles.focusVisible,- styles.presetButton,- isActive && styles.presetButtonActive,- isPresetDisabled && styles.presetButtonDisabled,+ onClick={() => handleRangeSelect(presetRange)}+ {...mergeProps(+ themeProps('date-range-input-preset', {+ selected: isActive ? 'selected' : null,+ disabled: isPresetDisabled ? 'disabled' : null,+ }),+ stylex.props(+ focusOutlineStyles.focusVisible,+ styles.presetButton,+ isActive && styles.presetButtonActive,+ isPresetDisabled && styles.presetButtonDisabled,+ ),)}>{preset.label}</button>diff --git a/packages/themes/probe/src/probeTheme.ts b/packages/themes/probe/src/probeTheme.tsindex 8f88b9d7d2..1fb9f2cdf6 100644--- a/packages/themes/probe/src/probeTheme.ts+++ b/packages/themes/probe/src/probeTheme.ts@@ -6,7 +6,7 @@// test fixture. Regenerate with: pnpm visual:probe-theme//// defineTheme takes six things and this covers all six:-// components 282 targets, 913 selectors (generated from the docs)+// components 284 targets, 917 selectors (generated from the docs)// tokens custom properties, read back off the themed element// icons every registry entry swapped for a marked glyph// indicators check / radio / checkbox swapped — the swap that reaches furthest@@ -1842,6 +1842,34 @@ export const probeTheme = defineTheme({outlineColor: 'hsl(139.1 73% 25%)',},},+ 'date-range-input-preset': {+ base: {+ backgroundColor: 'hsl(47.5 89% 45%)',+ color: 'hsl(70.3 75% 12%)',+ borderColor: 'hsl(169.6 85% 25%)',+ outlineColor: 'hsl(321.0 85% 25%)',+ },+ selected: {+ backgroundColor: 'hsl(125.5 76% 49%)',+ color: 'hsl(111.5 90% 12%)',+ borderColor: 'hsl(52.9 90% 25%)',+ outlineColor: 'hsl(215.4 89% 25%)',+ },+ disabled: {+ backgroundColor: 'hsl(198.6 92% 57%)',+ color: 'hsl(334.4 80% 12%)',+ borderColor: 'hsl(146.0 80% 25%)',+ outlineColor: 'hsl(39.7 84% 25%)',+ },+ },+ 'date-range-input-presets': {+ base: {+ backgroundColor: 'hsl(21.0 84% 45%)',+ color: 'hsl(301.8 74% 12%)',+ borderColor: 'hsl(226.5 82% 25%)',+ outlineColor: 'hsl(24.9 89% 25%)',+ },+ },'date-range-input-toggle-icon': {base: {backgroundColor: 'hsl(17.5 87% 54%)',