From b7c3c77b640964ad2e0b3b58e098b715c318596b Mon Sep 17 00:00:00 2001 From: aidataba Date: Thu, 15 Oct 2026 10:38:47 +0200 Subject: [PATCH 1/5] feat(core): add generic date variants to date picker --- .../catalyst/src/lib/directives/proxies.ts | 11 ++++-- core/src/components.d.ts | 28 +++++++++++++++ .../cat-date-inline/cat-date-inline.scss | 9 +++++ .../cat-date-inline/cat-date-inline.spec.tsx | 28 +++++++++++++++ .../cat-date-inline/cat-date-inline.tsx | 36 ++++++++++++++++++- .../cat-date-inline/cat-date-view-change.ts | 4 +++ core/src/components/cat-date-inline/readme.md | 8 +++-- core/src/components/cat-date/cat-date.tsx | 16 +++++++++ core/src/components/cat-date/readme.md | 12 ++++--- core/src/index.ts | 1 + 10 files changed, 142 insertions(+), 11 deletions(-) create mode 100644 core/src/components/cat-date-inline/cat-date-view-change.ts diff --git a/angular/projects/catalyst/src/lib/directives/proxies.ts b/angular/projects/catalyst/src/lib/directives/proxies.ts index 33bd5ff03..e08998183 100644 --- a/angular/projects/catalyst/src/lib/directives/proxies.ts +++ b/angular/projects/catalyst/src/lib/directives/proxies.ts @@ -13,6 +13,7 @@ import { import { ProxyCmp } from './angular-component-lib/utils'; import { Components } from '@haiilo/catalyst'; +import type { CatDateViewChange } from '@haiilo/catalyst'; @ProxyCmp({ inputs: ['color', 'icon', 'noIcon'] @@ -318,6 +319,7 @@ export declare interface CatCheckbox extends Components.CatCheckbox { inputs: [ 'autoComplete', 'clearable', + 'dayVariants', 'disabled', 'errorUpdate', 'errors', @@ -376,12 +378,13 @@ export declare interface CatCheckbox extends Components.CatCheckbox { 'textSuffix', 'value' ], - outputs: ['catChange', 'catFocus', 'catBlur'], + outputs: ['catChange', 'catViewChange', 'catFocus', 'catBlur'], standalone: false }) export class CatDate { protected el: HTMLCatDateElement; @Output() catChange = new EventEmitter>(); + @Output() catViewChange = new EventEmitter>(); @Output() catFocus = new EventEmitter>(); @Output() catBlur = new EventEmitter>(); constructor( @@ -399,6 +402,7 @@ export declare interface CatDate extends Components.CatDate { * Emitted when the value is changed. */ catChange: EventEmitter>; + catViewChange: EventEmitter>; /** * Emitted when the input received focus. */ @@ -412,6 +416,7 @@ export declare interface CatDate extends Components.CatDate { @ProxyCmp({ inputs: [ 'a11yLabel', + 'dayVariants', 'hint', 'identifier', 'label', @@ -449,12 +454,13 @@ export declare interface CatDate extends Components.CatDate { 'value', 'weeks' ], - outputs: ['catChange'], + outputs: ['catChange', 'catViewChange'], standalone: false }) export class CatDateInline { protected el: HTMLCatDateInlineElement; @Output() catChange = new EventEmitter>(); + @Output() catViewChange = new EventEmitter>(); constructor( c: ChangeDetectorRef, r: ElementRef, @@ -470,6 +476,7 @@ export declare interface CatDateInline extends Components.CatDateInline { * Emitted when the value is changed. */ catChange: EventEmitter>; + catViewChange: EventEmitter>; } @ProxyCmp({ diff --git a/core/src/components.d.ts b/core/src/components.d.ts index 4f498ea9c..eec11f98b 100644 --- a/core/src/components.d.ts +++ b/core/src/components.d.ts @@ -8,6 +8,7 @@ import { HTMLStencilElement, JSXBase } from "@stencil/core/internal"; import { Breakpoint } from "./utils/breakpoints"; import { ErrorMap } from "./components/cat-form-hint/cat-form-hint"; import { Placement } from "@floating-ui/dom"; +import { CatDateViewChange } from "./components/cat-date-inline/cat-date-view-change"; import { CatDatepickerMode } from "./components/cat-datepicker/cat-datepicker.mode"; import { BaseOptions } from "flatpickr/dist/types/options"; import { InputType } from "./components/cat-input/input-type"; @@ -19,6 +20,7 @@ import { TooltipPlacement } from "./components/cat-tooltip/cat-tooltip"; export { Breakpoint } from "./utils/breakpoints"; export { ErrorMap } from "./components/cat-form-hint/cat-form-hint"; export { Placement } from "@floating-ui/dom"; +export { CatDateViewChange } from "./components/cat-date-inline/cat-date-view-change"; export { CatDatepickerMode } from "./components/cat-datepicker/cat-datepicker.mode"; export { BaseOptions } from "flatpickr/dist/types/options"; export { InputType } from "./components/cat-input/input-type"; @@ -382,6 +384,10 @@ export namespace Components { * @default false */ "clearable": boolean; + /** + * Optional semantic visual variant for individual dates, keyed by local ISO date. + */ + "dayVariants"?: Record; /** * Whether the input is disabled. * @default false @@ -509,6 +515,10 @@ export namespace Components { * Clear the picker. */ "clear": () => Promise; + /** + * Optional semantic visual variant for individual dates, keyed by local ISO date. + */ + "dayVariants"?: Record; /** * Programmatically move focus to the inline datepicker, i,e, the first focusable date. * @param options An optional object providing options to control aspects of the focusing process. @@ -2479,6 +2489,7 @@ declare global { }; interface HTMLCatDateElementEventMap { "catChange": string; + "catViewChange": CatDateViewChange; "catFocus": FocusEvent; "catBlur": FocusEvent; } @@ -2501,6 +2512,7 @@ declare global { }; interface HTMLCatDateInlineElementEventMap { "catChange": string; + "catViewChange": CatDateViewChange; } /** * An inline date picker component to select a date. @@ -3393,6 +3405,10 @@ declare namespace LocalJSX { * @default false */ "clearable"?: boolean; + /** + * Optional semantic visual variant for individual dates, keyed by local ISO date. + */ + "dayVariants"?: Record; /** * Whether the input is disabled. * @default false @@ -3470,6 +3486,10 @@ declare namespace LocalJSX { * Emitted when the input received focus. */ "onCatFocus"?: (event: CatDateCustomEvent) => void; + /** + * Emitted when the visible inclusive calendar range changes. + */ + "onCatViewChange"?: (event: CatDateCustomEvent) => void; /** * The placeholder text to display within the input. */ @@ -3519,6 +3539,10 @@ declare namespace LocalJSX { * Adds accessible label for the datepicker. The label will be read by assistive technology upon focusing the datepicker. */ "a11yLabel"?: string; + /** + * Optional semantic visual variant for individual dates, keyed by local ISO date. + */ + "dayVariants"?: Record; /** * Shows an arrow keys navigation hint. * @default false @@ -3560,6 +3584,10 @@ declare namespace LocalJSX { * Emitted when the value is changed. */ "onCatChange"?: (event: CatDateInlineCustomEvent) => void; + /** + * Emitted when the visible inclusive calendar range changes. + */ + "onCatViewChange"?: (event: CatDateInlineCustomEvent) => void; /** * Allow the selection of a range of dates, i.e. start and end date. * @default false diff --git a/core/src/components/cat-date-inline/cat-date-inline.scss b/core/src/components/cat-date-inline/cat-date-inline.scss index 04b1bb06a..7b60ca663 100644 --- a/core/src/components/cat-date-inline/cat-date-inline.scss +++ b/core/src/components/cat-date-inline/cat-date-inline.scss @@ -119,6 +119,15 @@ opacity: 0.25; } +.date-variant-warning:not(.date-selected):not(.date-today)::part(button), +.date-variant-danger:not(.date-selected):not(.date-today)::part(button) { + background-color: var(--cat-date-day-warning-background, #{cat-token('color.theme.warning.bg', 0.5)}) !important; +} + +.date-variant-danger:not(.date-selected):not(.date-today)::part(button) { + background-color: var(--cat-date-day-danger-background, #{cat-token('color.theme.danger.bg', 0.5)}) !important; +} + .picker-foot { display: flex; align-items: center; diff --git a/core/src/components/cat-date-inline/cat-date-inline.spec.tsx b/core/src/components/cat-date-inline/cat-date-inline.spec.tsx index 59a19d30b..debbde257 100644 --- a/core/src/components/cat-date-inline/cat-date-inline.spec.tsx +++ b/core/src/components/cat-date-inline/cat-date-inline.spec.tsx @@ -19,4 +19,32 @@ describe('cat-date-inline', () => { `); }); + + it('renders day states for local ISO dates', async () => { + const today = new Date(); + const date = [today.getFullYear(), today.getMonth() + 1, today.getDate()] + .map((part, index) => (index === 0 ? String(part) : String(part).padStart(2, '0'))) + .join('-'); + const { root } = await render(); + + expect(root.shadowRoot?.querySelector(`[data-date="${date}"]`)).toHaveClass('date-variant-danger'); + }); + + it('emits the visible inclusive range when navigating', async () => { + const { root } = await render(); + const viewChange = vi.fn(); + root.addEventListener('catViewChange', viewChange); + + (root.shadowRoot?.querySelectorAll('cat-button')[2] as HTMLElement).click(); + await new Promise(resolve => setTimeout(resolve)); + + expect(viewChange).toHaveBeenCalledWith( + expect.objectContaining({ + detail: { + from: expect.any(String), + to: expect.any(String) + } + }) + ); + }); }); diff --git a/core/src/components/cat-date-inline/cat-date-inline.tsx b/core/src/components/cat-date-inline/cat-date-inline.tsx index 556db3a9e..8792fa313 100644 --- a/core/src/components/cat-date-inline/cat-date-inline.tsx +++ b/core/src/components/cat-date-inline/cat-date-inline.tsx @@ -2,6 +2,7 @@ import { Component, Element, Event, EventEmitter, Host, Listen, Method, Prop, St import { catI18nRegistry as i18n } from '../cat-i18n/cat-i18n-registry'; import { getLocale } from './cat-date-locale'; import { addDays, addMonth, clampDate, isSameDay, isSameMonth, isSameYear } from './cat-date-math'; +import type { CatDateViewChange } from './cat-date-view-change'; import firstTabbable from '../../utils/first-tabbable'; let nextUniqueId = 0; @@ -107,11 +108,21 @@ export class CatDateInline { */ @Prop({ mutable: true }) value?: string; + /** + * Optional semantic visual variant for individual dates, keyed by local ISO date. + */ + @Prop() dayVariants?: Record; + /** * Emitted when the value is changed. */ @Event() catChange!: EventEmitter; + /** + * Emitted when the visible inclusive calendar range changes. + */ + @Event() catViewChange!: EventEmitter; + private get focusedDate() { const [all, year, month, day] = this.hostElement.shadowRoot @@ -145,6 +156,10 @@ export class CatDateInline { } } + componentDidLoad() { + this.emitViewChange(); + } + @Listen('keydown') onKeyDown(e: KeyboardEvent) { if (!['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown'].includes(e.key)) { @@ -221,6 +236,7 @@ export class CatDateInline { const [minDate, maxDate] = this.getMinMaxDate(); const [dateStart] = this.getValue(); this.viewDate = dateStart ?? clampDate(minDate, this.locale.now(), maxDate); + this.emitViewChange(); } /** @@ -325,6 +341,8 @@ export class CatDateInline { )}
{dateGrid.map(day => { + const date = this.locale.toLocalISO(day); + const variant = this.dayVariants?.[date]; const isStartDate = isSameDay(dateStart, day); const isEndDate = isSameDay(dateEnd, day); const isRange = !!dateStart && !!dateEnd && day > dateStart && day < dateEnd; @@ -340,6 +358,9 @@ export class CatDateInline { 'date-start': this.range && isStartDate, 'date-range': this.range && isRange, 'date-end': this.range && isEndDate, + 'date-selected': isStartDate || isEndDate, + 'date-variant-warning': variant === 'warning', + 'date-variant-danger': variant === 'danger', 'date-focusable': this.canFocus(day), 'date-disabled': !this.canClick(day) }} @@ -350,7 +371,7 @@ export class CatDateInline { color={isStartDate || isEndDate || isToday ? 'primary' : 'secondary'} disabled={!this.canClick(day)} onClick={() => this.select(day)} - data-date={this.locale.toLocalISO(day)} + data-date={date} > {day.getDate()} @@ -380,7 +401,11 @@ export class CatDateInline { private focus(date: Date, focus = true) { const [minDate, maxDate] = this.getMinMaxDate(); const focusDate = clampDate(minDate, date, maxDate); + const previousViewDate = this.viewDate; this.viewDate = new Date(focusDate.getFullYear(), focusDate.getMonth()); + if (!isSameMonth(previousViewDate, this.viewDate)) { + this.emitViewChange(); + } if (focus) { this.focusDate = focusDate; this.hostElement.shadowRoot @@ -403,6 +428,15 @@ export class CatDateInline { const maxDate = new Date(targetYear, targetMonth, maxDay); this.viewDate = clampDate(minDate, date, maxDate); this.setAriaLive(this.getHeadline()); + this.emitViewChange(); + } + + private emitViewChange() { + const dateGrid = this.dateGrid(this.viewDate.getFullYear(), this.viewDate.getMonth()); + this.catViewChange.emit({ + from: this.locale.toLocalISO(dateGrid[0]), + to: this.locale.toLocalISO(dateGrid[dateGrid.length - 1]) + }); } private setAriaLive(text?: string) { diff --git a/core/src/components/cat-date-inline/cat-date-view-change.ts b/core/src/components/cat-date-inline/cat-date-view-change.ts new file mode 100644 index 000000000..2fae4943c --- /dev/null +++ b/core/src/components/cat-date-inline/cat-date-view-change.ts @@ -0,0 +1,4 @@ +export interface CatDateViewChange { + from: string; + to: string; +} diff --git a/core/src/components/cat-date-inline/readme.md b/core/src/components/cat-date-inline/readme.md index 9252d1238..ce7e0ac42 100644 --- a/core/src/components/cat-date-inline/readme.md +++ b/core/src/components/cat-date-inline/readme.md @@ -14,6 +14,7 @@ An inline date picker component to select a date. | Property | Attribute | Description | Type | Default | | ---------------- | ----------------- | ---------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------ | ------------ | | `a11yLabel` | `a11y-label` | Adds accessible label for the datepicker. The label will be read by assistive technology upon focusing the datepicker. | `string \| undefined` | `undefined` | +| `dayVariants` | -- | Optional semantic visual variant for individual dates, keyed by local ISO date. | `"danger" \| "warning" \| string \| undefined` | `undefined` | | `hint` | `hint` | Shows an arrow keys navigation hint. | `boolean` | `false` | | `identifier` | `identifier` | A unique identifier for the input. | `string \| undefined` | `undefined` | | `label` | `label` | The label for the input. | `string` | `''` | @@ -31,9 +32,10 @@ An inline date picker component to select a date. ## Events -| Event | Description | Type | -| ----------- | ---------------------------------- | --------------------- | -| `catChange` | Emitted when the value is changed. | `CustomEvent` | +| Event | Description | Type | +| --------------- | ---------------------------------------------------------- | -------------------------------- | +| `catChange` | Emitted when the value is changed. | `CustomEvent` | +| `catViewChange` | Emitted when the visible inclusive calendar range changes. | `CustomEvent` | ## Methods diff --git a/core/src/components/cat-date/cat-date.tsx b/core/src/components/cat-date/cat-date.tsx index 5b1518ef0..677e097f4 100644 --- a/core/src/components/cat-date/cat-date.tsx +++ b/core/src/components/cat-date/cat-date.tsx @@ -2,6 +2,7 @@ import { Placement } from '@floating-ui/dom'; import { Component, Element, Event, EventEmitter, Host, Method, Prop, Watch, h, State } from '@stencil/core'; import { getLocale } from '../cat-date-inline/cat-date-locale'; import { clampDate } from '../cat-date-inline/cat-date-math'; +import type { CatDateViewChange } from '../cat-date-inline/cat-date-view-change'; import { ErrorMap } from '../cat-form-hint/cat-form-hint'; import { catI18nRegistry as i18n } from '../cat-i18n/cat-i18n-registry'; import { DateUnit, FormatDateOptions } from 'cleave-zen'; @@ -133,6 +134,11 @@ export class CatDate { */ @Prop({ mutable: true }) value?: string; + /** + * Optional semantic visual variant for individual dates, keyed by local ISO date. + */ + @Prop() dayVariants?: Record; + /** * The validation errors for this input. Will render a hint under the input * with the translated error message(s) `error.${key}`. If an object is @@ -186,6 +192,11 @@ export class CatDate { */ @Event() catChange!: EventEmitter; + /** + * Emitted when the visible inclusive calendar range changes. + */ + @Event() catViewChange!: EventEmitter; + /** * Emitted when the input received focus. */ @@ -310,10 +321,15 @@ export class CatDate { min={this.min} max={this.max} value={this.value} + dayVariants={this.dayVariants} hint weeks noClear onCatChange={this.onDateChange.bind(this)} + onCatViewChange={(e: CustomEvent) => { + e.stopPropagation(); + this.catViewChange.emit(e.detail); + }} >
diff --git a/core/src/components/cat-date/readme.md b/core/src/components/cat-date/readme.md index 10ca5ef04..09235bc1e 100644 --- a/core/src/components/cat-date/readme.md +++ b/core/src/components/cat-date/readme.md @@ -15,6 +15,7 @@ A date input component to select a date from a calendar in a dropdown. | ------------------ | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------- | | `autoComplete` | `auto-complete` | Hint for form autofill feature. | `string` | `'off'` | | `clearable` | `clearable` | Whether the input should show a clear button. | `boolean` | `false` | +| `dayVariants` | -- | Optional semantic visual variant for individual dates, keyed by local ISO date. | `"danger" \| "warning" \| string \| undefined` | `undefined` | | `disabled` | `disabled` | Whether the input is disabled. | `boolean` | `false` | | `errorUpdate` | `error-update` | Fine-grained control over when the errors are shown. Can be `false` to never show errors, `true` to show errors on blur, or a number to show errors change with the given delay in milliseconds or immediately on blur. | `boolean \| number` | `0` | | `errors` | `errors` | The validation errors for this input. Will render a hint under the input with the translated error message(s) `error.${key}`. If an object is passed, the keys will be used as error keys and the values translation parameters. If the value is `true`, the input will be marked as invalid without any hints under the input. | `boolean \| string[] \| undefined \| { [key: string]: any; }` | `undefined` | @@ -42,11 +43,12 @@ A date input component to select a date from a calendar in a dropdown. ## Events -| Event | Description | Type | -| ----------- | -------------------------------------- | ------------------------- | -| `catBlur` | Emitted when the input loses focus. | `CustomEvent` | -| `catChange` | Emitted when the value is changed. | `CustomEvent` | -| `catFocus` | Emitted when the input received focus. | `CustomEvent` | +| Event | Description | Type | +| --------------- | ---------------------------------------------------------- | -------------------------------- | +| `catBlur` | Emitted when the input loses focus. | `CustomEvent` | +| `catChange` | Emitted when the value is changed. | `CustomEvent` | +| `catFocus` | Emitted when the input received focus. | `CustomEvent` | +| `catViewChange` | Emitted when the visible inclusive calendar range changes. | `CustomEvent` | ## Methods diff --git a/core/src/index.ts b/core/src/index.ts index 6b73e5526..24359cb66 100644 --- a/core/src/index.ts +++ b/core/src/index.ts @@ -19,3 +19,4 @@ export { objectArrayConnector, stringArrayConnector, stringMapConnector } from ' export { TooltipPlacement } from './components/cat-tooltip/cat-tooltip'; export { FormatTimeMaskOptions, FormatDateMaskOptions } from './components/cat-input/cat-input'; export { DropdownPlacement } from './components/cat-dropdown/cat-dropdown'; +export type { CatDateViewChange } from './components/cat-date-inline/cat-date-view-change'; From 891afe3063dd263848713937c8571393246c522b Mon Sep 17 00:00:00 2001 From: aidataba Date: Thu, 15 Oct 2026 14:38:47 +0200 Subject: [PATCH 2/5] feat(core): add generic date variants to date picker --- .../catalyst/src/lib/directives/proxies.ts | 25 ++++++--- core/src/components.d.ts | 38 +++++++------- .../cat-date-inline/cat-date-day-variant.ts | 2 + .../cat-date-inline/cat-date-inline.scss | 26 ++++++++-- .../cat-date-inline/cat-date-inline.spec.tsx | 51 +++++++++++-------- .../cat-date-inline/cat-date-inline.tsx | 38 ++++++++------ .../cat-date-inline/cat-date-view-change.ts | 4 -- .../cat-date-inline/cat-date-view-range.ts | 7 +++ core/src/components/cat-date-inline/readme.md | 17 ++++++- core/src/components/cat-date/cat-date.scss | 9 ++++ .../src/components/cat-date/cat-date.spec.tsx | 25 +++++++++ core/src/components/cat-date/cat-date.tsx | 15 +++--- core/src/components/cat-date/readme.md | 17 ++++++- core/src/index.ts | 3 +- 14 files changed, 196 insertions(+), 81 deletions(-) create mode 100644 core/src/components/cat-date-inline/cat-date-day-variant.ts delete mode 100644 core/src/components/cat-date-inline/cat-date-view-change.ts create mode 100644 core/src/components/cat-date-inline/cat-date-view-range.ts diff --git a/angular/projects/catalyst/src/lib/directives/proxies.ts b/angular/projects/catalyst/src/lib/directives/proxies.ts index e08998183..36b9ad2dd 100644 --- a/angular/projects/catalyst/src/lib/directives/proxies.ts +++ b/angular/projects/catalyst/src/lib/directives/proxies.ts @@ -13,7 +13,6 @@ import { import { ProxyCmp } from './angular-component-lib/utils'; import { Components } from '@haiilo/catalyst'; -import type { CatDateViewChange } from '@haiilo/catalyst'; @ProxyCmp({ inputs: ['color', 'icon', 'noIcon'] @@ -354,6 +353,7 @@ export declare interface CatCheckbox extends Components.CatCheckbox { inputs: [ 'autoComplete', 'clearable', + 'dayVariants', 'disabled', 'errorUpdate', 'errors', @@ -378,13 +378,13 @@ export declare interface CatCheckbox extends Components.CatCheckbox { 'textSuffix', 'value' ], - outputs: ['catChange', 'catViewChange', 'catFocus', 'catBlur'], + outputs: ['catChange', 'catDateViewChange', 'catFocus', 'catBlur'], standalone: false }) export class CatDate { protected el: HTMLCatDateElement; @Output() catChange = new EventEmitter>(); - @Output() catViewChange = new EventEmitter>(); + @Output() catDateViewChange = new EventEmitter>(); @Output() catFocus = new EventEmitter>(); @Output() catBlur = new EventEmitter>(); constructor( @@ -397,12 +397,17 @@ export class CatDate { } } +import type { CatDateViewRange as ICatDateCatDateViewRange } from '@haiilo/catalyst'; + export declare interface CatDate extends Components.CatDate { /** * Emitted when the value is changed. */ catChange: EventEmitter>; - catViewChange: EventEmitter>; + /** + * Emitted with the visible inclusive calendar range and whenever that range changes. + */ + catDateViewChange: EventEmitter>; /** * Emitted when the input received focus. */ @@ -440,6 +445,7 @@ export declare interface CatDate extends Components.CatDate { // eslint-disable-next-line @angular-eslint/no-inputs-metadata-property inputs: [ 'a11yLabel', + 'dayVariants', 'hint', 'identifier', 'label', @@ -454,13 +460,13 @@ export declare interface CatDate extends Components.CatDate { 'value', 'weeks' ], - outputs: ['catChange', 'catViewChange'], + outputs: ['catChange', 'catDateViewChange'], standalone: false }) export class CatDateInline { protected el: HTMLCatDateInlineElement; @Output() catChange = new EventEmitter>(); - @Output() catViewChange = new EventEmitter>(); + @Output() catDateViewChange = new EventEmitter>(); constructor( c: ChangeDetectorRef, r: ElementRef, @@ -471,12 +477,17 @@ export class CatDateInline { } } +import type { CatDateViewRange as ICatDateInlineCatDateViewRange } from '@haiilo/catalyst'; + export declare interface CatDateInline extends Components.CatDateInline { /** * Emitted when the value is changed. */ catChange: EventEmitter>; - catViewChange: EventEmitter>; + /** + * Emitted with the visible inclusive calendar range and whenever that range changes. + */ + catDateViewChange: EventEmitter>; } @ProxyCmp({ diff --git a/core/src/components.d.ts b/core/src/components.d.ts index eec11f98b..574abb176 100644 --- a/core/src/components.d.ts +++ b/core/src/components.d.ts @@ -6,9 +6,10 @@ */ import { HTMLStencilElement, JSXBase } from "@stencil/core/internal"; import { Breakpoint } from "./utils/breakpoints"; +import { CatDateDayVariant } from "./components/cat-date-inline/cat-date-day-variant"; import { ErrorMap } from "./components/cat-form-hint/cat-form-hint"; import { Placement } from "@floating-ui/dom"; -import { CatDateViewChange } from "./components/cat-date-inline/cat-date-view-change"; +import { CatDateViewRange } from "./components/cat-date-inline/cat-date-view-range"; import { CatDatepickerMode } from "./components/cat-datepicker/cat-datepicker.mode"; import { BaseOptions } from "flatpickr/dist/types/options"; import { InputType } from "./components/cat-input/input-type"; @@ -18,9 +19,10 @@ import { CatSelectConnector, CatSelectValue, Item } from "./components/cat-selec import { Observable } from "rxjs"; import { TooltipPlacement } from "./components/cat-tooltip/cat-tooltip"; export { Breakpoint } from "./utils/breakpoints"; +export { CatDateDayVariant } from "./components/cat-date-inline/cat-date-day-variant"; export { ErrorMap } from "./components/cat-form-hint/cat-form-hint"; export { Placement } from "@floating-ui/dom"; -export { CatDateViewChange } from "./components/cat-date-inline/cat-date-view-change"; +export { CatDateViewRange } from "./components/cat-date-inline/cat-date-view-range"; export { CatDatepickerMode } from "./components/cat-datepicker/cat-datepicker.mode"; export { BaseOptions } from "flatpickr/dist/types/options"; export { InputType } from "./components/cat-input/input-type"; @@ -385,9 +387,9 @@ export namespace Components { */ "clearable": boolean; /** - * Optional semantic visual variant for individual dates, keyed by local ISO date. + * Applies a semantic theme variant to each matching local ISO date. */ - "dayVariants"?: Record; + "dayVariants"?: Record; /** * Whether the input is disabled. * @default false @@ -516,9 +518,9 @@ export namespace Components { */ "clear": () => Promise; /** - * Optional semantic visual variant for individual dates, keyed by local ISO date. + * Applies a semantic theme variant to each matching local ISO date. */ - "dayVariants"?: Record; + "dayVariants"?: Record; /** * Programmatically move focus to the inline datepicker, i,e, the first focusable date. * @param options An optional object providing options to control aspects of the focusing process. @@ -2489,7 +2491,7 @@ declare global { }; interface HTMLCatDateElementEventMap { "catChange": string; - "catViewChange": CatDateViewChange; + "catDateViewChange": CatDateViewRange; "catFocus": FocusEvent; "catBlur": FocusEvent; } @@ -2512,7 +2514,7 @@ declare global { }; interface HTMLCatDateInlineElementEventMap { "catChange": string; - "catViewChange": CatDateViewChange; + "catDateViewChange": CatDateViewRange; } /** * An inline date picker component to select a date. @@ -3406,9 +3408,9 @@ declare namespace LocalJSX { */ "clearable"?: boolean; /** - * Optional semantic visual variant for individual dates, keyed by local ISO date. + * Applies a semantic theme variant to each matching local ISO date. */ - "dayVariants"?: Record; + "dayVariants"?: Record; /** * Whether the input is disabled. * @default false @@ -3483,13 +3485,13 @@ declare namespace LocalJSX { */ "onCatChange"?: (event: CatDateCustomEvent) => void; /** - * Emitted when the input received focus. + * Emitted with the visible inclusive calendar range and whenever that range changes. */ - "onCatFocus"?: (event: CatDateCustomEvent) => void; + "onCatDateViewChange"?: (event: CatDateCustomEvent) => void; /** - * Emitted when the visible inclusive calendar range changes. + * Emitted when the input received focus. */ - "onCatViewChange"?: (event: CatDateCustomEvent) => void; + "onCatFocus"?: (event: CatDateCustomEvent) => void; /** * The placeholder text to display within the input. */ @@ -3540,9 +3542,9 @@ declare namespace LocalJSX { */ "a11yLabel"?: string; /** - * Optional semantic visual variant for individual dates, keyed by local ISO date. + * Applies a semantic theme variant to each matching local ISO date. */ - "dayVariants"?: Record; + "dayVariants"?: Record; /** * Shows an arrow keys navigation hint. * @default false @@ -3585,9 +3587,9 @@ declare namespace LocalJSX { */ "onCatChange"?: (event: CatDateInlineCustomEvent) => void; /** - * Emitted when the visible inclusive calendar range changes. + * Emitted with the visible inclusive calendar range and whenever that range changes. */ - "onCatViewChange"?: (event: CatDateInlineCustomEvent) => void; + "onCatDateViewChange"?: (event: CatDateInlineCustomEvent) => void; /** * Allow the selection of a range of dates, i.e. start and end date. * @default false diff --git a/core/src/components/cat-date-inline/cat-date-day-variant.ts b/core/src/components/cat-date-inline/cat-date-day-variant.ts new file mode 100644 index 000000000..94ae8bff3 --- /dev/null +++ b/core/src/components/cat-date-inline/cat-date-day-variant.ts @@ -0,0 +1,2 @@ +/** Semantic theme variants available for individual date cells. */ +export type CatDateDayVariant = 'primary' | 'secondary' | 'info' | 'success' | 'warning' | 'danger'; diff --git a/core/src/components/cat-date-inline/cat-date-inline.scss b/core/src/components/cat-date-inline/cat-date-inline.scss index 7b60ca663..326131bce 100644 --- a/core/src/components/cat-date-inline/cat-date-inline.scss +++ b/core/src/components/cat-date-inline/cat-date-inline.scss @@ -3,6 +3,15 @@ @use '_snippets/form-label'; :host { + /** + * @prop --cat-date-day-primary-background: Background color for primary date variants. + * @prop --cat-date-day-secondary-background: Background color for secondary date variants. + * @prop --cat-date-day-info-background: Background color for info date variants. + * @prop --cat-date-day-success-background: Background color for success date variants. + * @prop --cat-date-day-warning-background: Background color for warning date variants. + * @prop --cat-date-day-danger-background: Background color for danger date variants. + * @prop --cat-date-day-danger-border-color: Border color for danger date variants. + */ display: flex; flex-direction: column; gap: 0.5rem; @@ -119,13 +128,22 @@ opacity: 0.25; } -.date-variant-warning:not(.date-selected):not(.date-today)::part(button), -.date-variant-danger:not(.date-selected):not(.date-today)::part(button) { - background-color: var(--cat-date-day-warning-background, #{cat-token('color.theme.warning.bg', 0.5)}) !important; +@mixin date-variant($variant) { + .date-variant-#{$variant}:not(.date-selected):not(.date-today) { + background-color: var(--cat-date-day-#{$variant}-background, #{cat-token('color.theme.#{$variant}.bg', 0.5)}); + border-radius: cat-border-radius('m'); + } } +@include date-variant('primary'); +@include date-variant('secondary'); +@include date-variant('info'); +@include date-variant('success'); +@include date-variant('warning'); +@include date-variant('danger'); + .date-variant-danger:not(.date-selected):not(.date-today)::part(button) { - background-color: var(--cat-date-day-danger-background, #{cat-token('color.theme.danger.bg', 0.5)}) !important; + box-shadow: inset 0 0 0 1.5px var(--cat-date-day-danger-border-color, transparent); } .picker-foot { diff --git a/core/src/components/cat-date-inline/cat-date-inline.spec.tsx b/core/src/components/cat-date-inline/cat-date-inline.spec.tsx index debbde257..0cfcd3e49 100644 --- a/core/src/components/cat-date-inline/cat-date-inline.spec.tsx +++ b/core/src/components/cat-date-inline/cat-date-inline.spec.tsx @@ -20,31 +20,42 @@ describe('cat-date-inline', () => { `); }); - it('renders day states for local ISO dates', async () => { - const today = new Date(); - const date = [today.getFullYear(), today.getMonth() + 1, today.getDate()] - .map((part, index) => (index === 0 ? String(part) : String(part).padStart(2, '0'))) - .join('-'); - const { root } = await render(); - - expect(root.shadowRoot?.querySelector(`[data-date="${date}"]`)).toHaveClass('date-variant-danger'); + it('renders each semantic variant for local ISO dates', async () => { + const variants = ['primary', 'secondary', 'info', 'success', 'warning', 'danger'] as const; + const now = new Date(); + const dateKeys = variants.map((_, index) => { + const date = new Date(now.getFullYear(), now.getMonth(), index + 1); + return [date.getFullYear(), date.getMonth() + 1, date.getDate()] + .map((part, partIndex) => (partIndex === 0 ? String(part) : String(part).padStart(2, '0'))) + .join('-'); + }); + const dayVariants = Object.fromEntries(dateKeys.map((date, index) => [date, variants[index]])); + const { root } = await render(); + + dateKeys.forEach((date, index) => { + expect(root.shadowRoot?.querySelector(`[data-date="${date}"]`)).toHaveClass(`date-variant-${variants[index]}`); + }); }); it('emits the visible inclusive range when navigating', async () => { - const { root } = await render(); + const { root, waitForChanges } = await render(); const viewChange = vi.fn(); - root.addEventListener('catViewChange', viewChange); + root.addEventListener('catDateViewChange', viewChange); (root.shadowRoot?.querySelectorAll('cat-button')[2] as HTMLElement).click(); - await new Promise(resolve => setTimeout(resolve)); - - expect(viewChange).toHaveBeenCalledWith( - expect.objectContaining({ - detail: { - from: expect.any(String), - to: expect.any(String) - } - }) - ); + await waitForChanges(); + + const inline = root as HTMLCatDateInlineElement; + await inline.resetView(); + await waitForChanges(); + await inline.resetView(); + + expect(viewChange).toHaveBeenCalledTimes(2); + const emittedRanges = viewChange.mock.calls.map(([event]) => event.detail); + emittedRanges.forEach(range => { + expect(range.from).toMatch(/^\d{4}-\d{2}-\d{2}$/); + expect(range.to).toMatch(/^\d{4}-\d{2}-\d{2}$/); + }); + expect(emittedRanges[0]).not.toEqual(emittedRanges[1]); }); }); diff --git a/core/src/components/cat-date-inline/cat-date-inline.tsx b/core/src/components/cat-date-inline/cat-date-inline.tsx index 8792fa313..badf57153 100644 --- a/core/src/components/cat-date-inline/cat-date-inline.tsx +++ b/core/src/components/cat-date-inline/cat-date-inline.tsx @@ -1,8 +1,9 @@ import { Component, Element, Event, EventEmitter, Host, Listen, Method, Prop, State, h } from '@stencil/core'; import { catI18nRegistry as i18n } from '../cat-i18n/cat-i18n-registry'; +import type { CatDateDayVariant } from './cat-date-day-variant'; import { getLocale } from './cat-date-locale'; import { addDays, addMonth, clampDate, isSameDay, isSameMonth, isSameYear } from './cat-date-math'; -import type { CatDateViewChange } from './cat-date-view-change'; +import type { CatDateViewRange } from './cat-date-view-range'; import firstTabbable from '../../utils/first-tabbable'; let nextUniqueId = 0; @@ -27,8 +28,9 @@ export class CatDateInline { private readonly language = i18n.getLocale(); private readonly locale = getLocale(this.language); - // additonally store the focus date to ensure correct focus after potential re-render + // Preserve the focused date so it can be restored after a re-render. private focusDate: Date | null = null; + private lastEmittedViewRange?: CatDateViewRange; @Element() hostElement!: HTMLElement; @@ -109,9 +111,9 @@ export class CatDateInline { @Prop({ mutable: true }) value?: string; /** - * Optional semantic visual variant for individual dates, keyed by local ISO date. + * Applies a semantic theme variant to each matching local ISO date. */ - @Prop() dayVariants?: Record; + @Prop() dayVariants?: Record; /** * Emitted when the value is changed. @@ -119,9 +121,9 @@ export class CatDateInline { @Event() catChange!: EventEmitter; /** - * Emitted when the visible inclusive calendar range changes. + * Emitted with the visible inclusive calendar range and whenever that range changes. */ - @Event() catViewChange!: EventEmitter; + @Event() catDateViewChange!: EventEmitter; private get focusedDate() { const [all, year, month, day] = @@ -148,7 +150,7 @@ export class CatDateInline { componentDidRender() { if (this.focusDate) { - // re-focus the previously focused date after re-render + // Restore focus to the previously focused date after re-render. this.hostElement.shadowRoot ?.querySelector(`[data-date="${this.locale.toLocalISO(this.focusDate)}"]`) ?.doFocus(); @@ -157,7 +159,7 @@ export class CatDateInline { } componentDidLoad() { - this.emitViewChange(); + this.emitDateViewChange(); } @Listen('keydown') @@ -236,7 +238,7 @@ export class CatDateInline { const [minDate, maxDate] = this.getMinMaxDate(); const [dateStart] = this.getValue(); this.viewDate = dateStart ?? clampDate(minDate, this.locale.now(), maxDate); - this.emitViewChange(); + this.emitDateViewChange(); } /** @@ -359,8 +361,7 @@ export class CatDateInline { 'date-range': this.range && isRange, 'date-end': this.range && isEndDate, 'date-selected': isStartDate || isEndDate, - 'date-variant-warning': variant === 'warning', - 'date-variant-danger': variant === 'danger', + [`date-variant-${variant}`]: !!variant, 'date-focusable': this.canFocus(day), 'date-disabled': !this.canClick(day) }} @@ -404,7 +405,7 @@ export class CatDateInline { const previousViewDate = this.viewDate; this.viewDate = new Date(focusDate.getFullYear(), focusDate.getMonth()); if (!isSameMonth(previousViewDate, this.viewDate)) { - this.emitViewChange(); + this.emitDateViewChange(); } if (focus) { this.focusDate = focusDate; @@ -428,15 +429,20 @@ export class CatDateInline { const maxDate = new Date(targetYear, targetMonth, maxDay); this.viewDate = clampDate(minDate, date, maxDate); this.setAriaLive(this.getHeadline()); - this.emitViewChange(); + this.emitDateViewChange(); } - private emitViewChange() { + private emitDateViewChange() { const dateGrid = this.dateGrid(this.viewDate.getFullYear(), this.viewDate.getMonth()); - this.catViewChange.emit({ + const visibleRange = { from: this.locale.toLocalISO(dateGrid[0]), to: this.locale.toLocalISO(dateGrid[dateGrid.length - 1]) - }); + }; + if (this.lastEmittedViewRange?.from === visibleRange.from && this.lastEmittedViewRange.to === visibleRange.to) { + return; + } + this.lastEmittedViewRange = visibleRange; + this.catDateViewChange.emit(visibleRange); } private setAriaLive(text?: string) { diff --git a/core/src/components/cat-date-inline/cat-date-view-change.ts b/core/src/components/cat-date-inline/cat-date-view-change.ts deleted file mode 100644 index 2fae4943c..000000000 --- a/core/src/components/cat-date-inline/cat-date-view-change.ts +++ /dev/null @@ -1,4 +0,0 @@ -export interface CatDateViewChange { - from: string; - to: string; -} diff --git a/core/src/components/cat-date-inline/cat-date-view-range.ts b/core/src/components/cat-date-inline/cat-date-view-range.ts new file mode 100644 index 000000000..83317e498 --- /dev/null +++ b/core/src/components/cat-date-inline/cat-date-view-range.ts @@ -0,0 +1,7 @@ +/** The inclusive local-date range currently displayed by the date picker. */ +export interface CatDateViewRange { + /** First visible local date, in YYYY-MM-DD format. */ + from: string; + /** Last visible local date, in YYYY-MM-DD format. */ + to: string; +} diff --git a/core/src/components/cat-date-inline/readme.md b/core/src/components/cat-date-inline/readme.md index ce7e0ac42..1496df103 100644 --- a/core/src/components/cat-date-inline/readme.md +++ b/core/src/components/cat-date-inline/readme.md @@ -14,7 +14,7 @@ An inline date picker component to select a date. | Property | Attribute | Description | Type | Default | | ---------------- | ----------------- | ---------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------ | ------------ | | `a11yLabel` | `a11y-label` | Adds accessible label for the datepicker. The label will be read by assistive technology upon focusing the datepicker. | `string \| undefined` | `undefined` | -| `dayVariants` | -- | Optional semantic visual variant for individual dates, keyed by local ISO date. | `"danger" \| "warning" \| string \| undefined` | `undefined` | +| `dayVariants` | -- | Applies a semantic theme variant to each matching local ISO date. | `"danger" \| "info" \| "primary" \| "secondary" \| "success" \| "warning" \| string \| undefined` | `undefined` | | `hint` | `hint` | Shows an arrow keys navigation hint. | `boolean` | `false` | | `identifier` | `identifier` | A unique identifier for the input. | `string \| undefined` | `undefined` | | `label` | `label` | The label for the input. | `string` | `''` | @@ -35,7 +35,7 @@ An inline date picker component to select a date. | Event | Description | Type | | --------------- | ---------------------------------------------------------- | -------------------------------- | | `catChange` | Emitted when the value is changed. | `CustomEvent` | -| `catViewChange` | Emitted when the visible inclusive calendar range changes. | `CustomEvent` | +| `catDateViewChange` | Emitted with the visible inclusive calendar range and whenever that range changes. | `CustomEvent` | ## Methods @@ -101,6 +101,19 @@ Type: `Promise` | `"label"` | The native label element. | +## CSS Custom Properties + +| Name | Description | +| ------------------------------------- | --------------------------------------------- | +| `--cat-date-day-danger-background` | Background color for danger date variants. | +| `--cat-date-day-danger-border-color` | Border color for danger date variants. | +| `--cat-date-day-info-background` | Background color for info date variants. | +| `--cat-date-day-primary-background` | Background color for primary date variants. | +| `--cat-date-day-secondary-background` | Background color for secondary date variants. | +| `--cat-date-day-success-background` | Background color for success date variants. | +| `--cat-date-day-warning-background` | Background color for warning date variants. | + + ## Dependencies ### Used by diff --git a/core/src/components/cat-date/cat-date.scss b/core/src/components/cat-date/cat-date.scss index 390d89fcf..c00a19c2c 100644 --- a/core/src/components/cat-date/cat-date.scss +++ b/core/src/components/cat-date/cat-date.scss @@ -2,6 +2,15 @@ @use 'mixins' as *; :host { + /** + * @prop --cat-date-day-primary-background: Background color for primary date variants. + * @prop --cat-date-day-secondary-background: Background color for secondary date variants. + * @prop --cat-date-day-info-background: Background color for info date variants. + * @prop --cat-date-day-success-background: Background color for success date variants. + * @prop --cat-date-day-warning-background: Background color for warning date variants. + * @prop --cat-date-day-danger-background: Background color for danger date variants. + * @prop --cat-date-day-danger-border-color: Border color for danger date variants. + */ display: block; } diff --git a/core/src/components/cat-date/cat-date.spec.tsx b/core/src/components/cat-date/cat-date.spec.tsx index ca0b4e4ea..5967d3b09 100644 --- a/core/src/components/cat-date/cat-date.spec.tsx +++ b/core/src/components/cat-date/cat-date.spec.tsx @@ -15,4 +15,29 @@ describe('cat-date', () => { `); }); + + it('forwards day variants to the inline date picker', async () => { + const dayVariants = { '2026-10-20': 'danger' as const }; + const { root } = await render(); + + expect(root.shadowRoot?.querySelector('cat-date-inline')?.dayVariants).toEqual(dayVariants); + }); + + it('forwards the visible date range from cat-date-inline', async () => { + const { root } = await render(); + const viewChange = vi.fn(); + root.addEventListener('catDateViewChange', viewChange); + const detail = { from: '2026-10-12', to: '2026-11-22' }; + + root.shadowRoot?.querySelector('cat-date-inline')?.dispatchEvent( + new CustomEvent('catDateViewChange', { + detail, + bubbles: true, + composed: true + }) + ); + + expect(viewChange).toHaveBeenCalledTimes(1); + expect(viewChange).toHaveBeenCalledWith(expect.objectContaining({ detail })); + }); }); diff --git a/core/src/components/cat-date/cat-date.tsx b/core/src/components/cat-date/cat-date.tsx index 677e097f4..84596d84d 100644 --- a/core/src/components/cat-date/cat-date.tsx +++ b/core/src/components/cat-date/cat-date.tsx @@ -2,7 +2,8 @@ import { Placement } from '@floating-ui/dom'; import { Component, Element, Event, EventEmitter, Host, Method, Prop, Watch, h, State } from '@stencil/core'; import { getLocale } from '../cat-date-inline/cat-date-locale'; import { clampDate } from '../cat-date-inline/cat-date-math'; -import type { CatDateViewChange } from '../cat-date-inline/cat-date-view-change'; +import type { CatDateDayVariant } from '../cat-date-inline/cat-date-day-variant'; +import type { CatDateViewRange } from '../cat-date-inline/cat-date-view-range'; import { ErrorMap } from '../cat-form-hint/cat-form-hint'; import { catI18nRegistry as i18n } from '../cat-i18n/cat-i18n-registry'; import { DateUnit, FormatDateOptions } from 'cleave-zen'; @@ -135,9 +136,9 @@ export class CatDate { @Prop({ mutable: true }) value?: string; /** - * Optional semantic visual variant for individual dates, keyed by local ISO date. + * Applies a semantic theme variant to each matching local ISO date. */ - @Prop() dayVariants?: Record; + @Prop() dayVariants?: Record; /** * The validation errors for this input. Will render a hint under the input @@ -193,9 +194,9 @@ export class CatDate { @Event() catChange!: EventEmitter; /** - * Emitted when the visible inclusive calendar range changes. + * Emitted with the visible inclusive calendar range and whenever that range changes. */ - @Event() catViewChange!: EventEmitter; + @Event() catDateViewChange!: EventEmitter; /** * Emitted when the input received focus. @@ -326,9 +327,9 @@ export class CatDate { weeks noClear onCatChange={this.onDateChange.bind(this)} - onCatViewChange={(e: CustomEvent) => { + onCatDateViewChange={(e: CustomEvent) => { e.stopPropagation(); - this.catViewChange.emit(e.detail); + this.catDateViewChange.emit(e.detail); }} > diff --git a/core/src/components/cat-date/readme.md b/core/src/components/cat-date/readme.md index 09235bc1e..b146f6a20 100644 --- a/core/src/components/cat-date/readme.md +++ b/core/src/components/cat-date/readme.md @@ -15,7 +15,7 @@ A date input component to select a date from a calendar in a dropdown. | ------------------ | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------- | | `autoComplete` | `auto-complete` | Hint for form autofill feature. | `string` | `'off'` | | `clearable` | `clearable` | Whether the input should show a clear button. | `boolean` | `false` | -| `dayVariants` | -- | Optional semantic visual variant for individual dates, keyed by local ISO date. | `"danger" \| "warning" \| string \| undefined` | `undefined` | +| `dayVariants` | -- | Applies a semantic theme variant to each matching local ISO date. | `"danger" \| "info" \| "primary" \| "secondary" \| "success" \| "warning" \| string \| undefined` | `undefined` | | `disabled` | `disabled` | Whether the input is disabled. | `boolean` | `false` | | `errorUpdate` | `error-update` | Fine-grained control over when the errors are shown. Can be `false` to never show errors, `true` to show errors on blur, or a number to show errors change with the given delay in milliseconds or immediately on blur. | `boolean \| number` | `0` | | `errors` | `errors` | The validation errors for this input. Will render a hint under the input with the translated error message(s) `error.${key}`. If an object is passed, the keys will be used as error keys and the values translation parameters. If the value is `true`, the input will be marked as invalid without any hints under the input. | `boolean \| string[] \| undefined \| { [key: string]: any; }` | `undefined` | @@ -47,8 +47,8 @@ A date input component to select a date from a calendar in a dropdown. | --------------- | ---------------------------------------------------------- | -------------------------------- | | `catBlur` | Emitted when the input loses focus. | `CustomEvent` | | `catChange` | Emitted when the value is changed. | `CustomEvent` | +| `catDateViewChange` | Emitted with the visible inclusive calendar range and whenever that range changes. | `CustomEvent` | | `catFocus` | Emitted when the input received focus. | `CustomEvent` | -| `catViewChange` | Emitted when the visible inclusive calendar range changes. | `CustomEvent` | ## Methods @@ -92,6 +92,19 @@ Type: `Promise` +## CSS Custom Properties + +| Name | Description | +| ------------------------------------- | --------------------------------------------- | +| `--cat-date-day-danger-background` | Background color for danger date variants. | +| `--cat-date-day-danger-border-color` | Border color for danger date variants. | +| `--cat-date-day-info-background` | Background color for info date variants. | +| `--cat-date-day-primary-background` | Background color for primary date variants. | +| `--cat-date-day-secondary-background` | Background color for secondary date variants. | +| `--cat-date-day-success-background` | Background color for success date variants. | +| `--cat-date-day-warning-background` | Background color for warning date variants. | + + ## Dependencies ### Depends on diff --git a/core/src/index.ts b/core/src/index.ts index 24359cb66..e90f39e8c 100644 --- a/core/src/index.ts +++ b/core/src/index.ts @@ -19,4 +19,5 @@ export { objectArrayConnector, stringArrayConnector, stringMapConnector } from ' export { TooltipPlacement } from './components/cat-tooltip/cat-tooltip'; export { FormatTimeMaskOptions, FormatDateMaskOptions } from './components/cat-input/cat-input'; export { DropdownPlacement } from './components/cat-dropdown/cat-dropdown'; -export type { CatDateViewChange } from './components/cat-date-inline/cat-date-view-change'; +export type { CatDateDayVariant } from './components/cat-date-inline/cat-date-day-variant'; +export type { CatDateViewRange } from './components/cat-date-inline/cat-date-view-range'; From b2f5293b6bc70c683c2f8e679cab5f16dbabc0b5 Mon Sep 17 00:00:00 2001 From: aidataba Date: Tue, 20 Oct 2026 10:40:57 +0200 Subject: [PATCH 3/5] feat(core): add generic date variants to date picker --- .../cat-date-inline/cat-date-inline.spec.tsx | 23 +++++++++++++++++++ .../cat-date-inline/cat-date-inline.tsx | 9 -------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/core/src/components/cat-date-inline/cat-date-inline.spec.tsx b/core/src/components/cat-date-inline/cat-date-inline.spec.tsx index 0cfcd3e49..d650610ff 100644 --- a/core/src/components/cat-date-inline/cat-date-inline.spec.tsx +++ b/core/src/components/cat-date-inline/cat-date-inline.spec.tsx @@ -37,6 +37,28 @@ describe('cat-date-inline', () => { }); }); + it('emits the rendered inclusive range on initial load', async () => { + const viewChange = vi.fn(); + const { root } = await render(); + + const dates = root.shadowRoot?.querySelectorAll('[data-date]'); + expect(viewChange).toHaveBeenCalledTimes(1); + expect(viewChange).toHaveBeenCalledWith( + expect.objectContaining({ detail: { from: dates?.[0].dataset.date, to: dates?.[dates.length - 1].dataset.date } }) + ); + }); + + it('does not emit a range change when day variants trigger a render', async () => { + const { root, waitForChanges } = await render(); + const viewChange = vi.fn(); + root.addEventListener('catDateViewChange', viewChange); + + (root as HTMLCatDateInlineElement).dayVariants = { '2026-10-20': 'warning' }; + await waitForChanges(); + + expect(viewChange).not.toHaveBeenCalled(); + }); + it('emits the visible inclusive range when navigating', async () => { const { root, waitForChanges } = await render(); const viewChange = vi.fn(); @@ -49,6 +71,7 @@ describe('cat-date-inline', () => { await inline.resetView(); await waitForChanges(); await inline.resetView(); + await waitForChanges(); expect(viewChange).toHaveBeenCalledTimes(2); const emittedRanges = viewChange.mock.calls.map(([event]) => event.detail); diff --git a/core/src/components/cat-date-inline/cat-date-inline.tsx b/core/src/components/cat-date-inline/cat-date-inline.tsx index badf57153..12478406c 100644 --- a/core/src/components/cat-date-inline/cat-date-inline.tsx +++ b/core/src/components/cat-date-inline/cat-date-inline.tsx @@ -156,9 +156,6 @@ export class CatDateInline { ?.doFocus(); this.focusDate = null; } - } - - componentDidLoad() { this.emitDateViewChange(); } @@ -238,7 +235,6 @@ export class CatDateInline { const [minDate, maxDate] = this.getMinMaxDate(); const [dateStart] = this.getValue(); this.viewDate = dateStart ?? clampDate(minDate, this.locale.now(), maxDate); - this.emitDateViewChange(); } /** @@ -402,11 +398,7 @@ export class CatDateInline { private focus(date: Date, focus = true) { const [minDate, maxDate] = this.getMinMaxDate(); const focusDate = clampDate(minDate, date, maxDate); - const previousViewDate = this.viewDate; this.viewDate = new Date(focusDate.getFullYear(), focusDate.getMonth()); - if (!isSameMonth(previousViewDate, this.viewDate)) { - this.emitDateViewChange(); - } if (focus) { this.focusDate = focusDate; this.hostElement.shadowRoot @@ -429,7 +421,6 @@ export class CatDateInline { const maxDate = new Date(targetYear, targetMonth, maxDay); this.viewDate = clampDate(minDate, date, maxDate); this.setAriaLive(this.getHeadline()); - this.emitDateViewChange(); } private emitDateViewChange() { From c16768c402c038716c0d2ea965fdc3af4f194a23 Mon Sep 17 00:00:00 2001 From: aidataba Date: Tue, 20 Oct 2026 13:16:28 +0200 Subject: [PATCH 4/5] feat(core): add generic date variants to date picker --- core/src/components/cat-date-inline/cat-date-inline.scss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/components/cat-date-inline/cat-date-inline.scss b/core/src/components/cat-date-inline/cat-date-inline.scss index 326131bce..e7f3a735b 100644 --- a/core/src/components/cat-date-inline/cat-date-inline.scss +++ b/core/src/components/cat-date-inline/cat-date-inline.scss @@ -143,7 +143,7 @@ @include date-variant('danger'); .date-variant-danger:not(.date-selected):not(.date-today)::part(button) { - box-shadow: inset 0 0 0 1.5px var(--cat-date-day-danger-border-color, transparent); + box-shadow: inset 0 0 0 1px var(--cat-date-day-danger-border-color, transparent); } .picker-foot { From 2162fc77045ec6f492b22ad47bcd0c3826f23041 Mon Sep 17 00:00:00 2001 From: aidataba Date: Tue, 20 Oct 2026 15:05:59 +0200 Subject: [PATCH 5/5] feat(core): copilot --- core/src/components.d.ts | 16 +++++----- .../cat-date-inline/cat-date-inline.tsx | 4 +-- core/src/components/cat-date-inline/readme.md | 28 +++++++++++++--- core/src/components/cat-date/cat-date.tsx | 4 +-- core/src/components/cat-date/readme.md | 32 +++++++++++++++---- 5 files changed, 62 insertions(+), 22 deletions(-) diff --git a/core/src/components.d.ts b/core/src/components.d.ts index 574abb176..a6182a4ce 100644 --- a/core/src/components.d.ts +++ b/core/src/components.d.ts @@ -387,9 +387,9 @@ export namespace Components { */ "clearable": boolean; /** - * Applies a semantic theme variant to each matching local ISO date. + * Maps local ISO dates (YYYY-MM-DD) to semantic theme variants, e.g. `{ '2026-10-20': 'danger' }`. */ - "dayVariants"?: Record; + "dayVariants"?: { [date: string]: CatDateDayVariant }; /** * Whether the input is disabled. * @default false @@ -518,9 +518,9 @@ export namespace Components { */ "clear": () => Promise; /** - * Applies a semantic theme variant to each matching local ISO date. + * Maps local ISO dates (YYYY-MM-DD) to semantic theme variants, e.g. `{ '2026-10-20': 'danger' }`. */ - "dayVariants"?: Record; + "dayVariants"?: { [date: string]: CatDateDayVariant }; /** * Programmatically move focus to the inline datepicker, i,e, the first focusable date. * @param options An optional object providing options to control aspects of the focusing process. @@ -3408,9 +3408,9 @@ declare namespace LocalJSX { */ "clearable"?: boolean; /** - * Applies a semantic theme variant to each matching local ISO date. + * Maps local ISO dates (YYYY-MM-DD) to semantic theme variants, e.g. `{ '2026-10-20': 'danger' }`. */ - "dayVariants"?: Record; + "dayVariants"?: { [date: string]: CatDateDayVariant }; /** * Whether the input is disabled. * @default false @@ -3542,9 +3542,9 @@ declare namespace LocalJSX { */ "a11yLabel"?: string; /** - * Applies a semantic theme variant to each matching local ISO date. + * Maps local ISO dates (YYYY-MM-DD) to semantic theme variants, e.g. `{ '2026-10-20': 'danger' }`. */ - "dayVariants"?: Record; + "dayVariants"?: { [date: string]: CatDateDayVariant }; /** * Shows an arrow keys navigation hint. * @default false diff --git a/core/src/components/cat-date-inline/cat-date-inline.tsx b/core/src/components/cat-date-inline/cat-date-inline.tsx index 12478406c..ea3c1d7a7 100644 --- a/core/src/components/cat-date-inline/cat-date-inline.tsx +++ b/core/src/components/cat-date-inline/cat-date-inline.tsx @@ -111,9 +111,9 @@ export class CatDateInline { @Prop({ mutable: true }) value?: string; /** - * Applies a semantic theme variant to each matching local ISO date. + * Maps local ISO dates (YYYY-MM-DD) to semantic theme variants, e.g. `{ '2026-10-20': 'danger' }`. */ - @Prop() dayVariants?: Record; + @Prop() dayVariants?: { [date: string]: CatDateDayVariant }; /** * Emitted when the value is changed. diff --git a/core/src/components/cat-date-inline/readme.md b/core/src/components/cat-date-inline/readme.md index 1496df103..d000dcaf8 100644 --- a/core/src/components/cat-date-inline/readme.md +++ b/core/src/components/cat-date-inline/readme.md @@ -1,6 +1,26 @@ # cat-date-inline +## Per-day variants +`dayVariants` maps local `YYYY-MM-DD` dates to `CatDateDayVariant`: `primary`, +`secondary`, `info`, `success`, `warning`, or `danger`. Pass an object, not a +single variant string or an HTML attribute. Selected dates and today keep their +usual styling; disabled dates remain disabled. + +```ts +const picker = document.querySelector('cat-date-inline'); +picker.dayVariants = { '2026-10-20': 'warning', '2026-10-21': 'danger' }; +``` + +In Angular, pass the object through a property binding: + +```html + +``` + +`catDateViewChange` reports `{ from, to }` as inclusive local ISO dates for the +visible grid, including days from adjacent months. Consumers decide what to +fetch and which variants to assign. @@ -14,7 +34,7 @@ An inline date picker component to select a date. | Property | Attribute | Description | Type | Default | | ---------------- | ----------------- | ---------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------ | ------------ | | `a11yLabel` | `a11y-label` | Adds accessible label for the datepicker. The label will be read by assistive technology upon focusing the datepicker. | `string \| undefined` | `undefined` | -| `dayVariants` | -- | Applies a semantic theme variant to each matching local ISO date. | `"danger" \| "info" \| "primary" \| "secondary" \| "success" \| "warning" \| string \| undefined` | `undefined` | +| `dayVariants` | -- | Maps local ISO dates (YYYY-MM-DD) to semantic theme variants, e.g. `{ '2026-10-20': 'danger' }`. | `undefined \| { [date: string]: CatDateDayVariant; }` | `undefined` | | `hint` | `hint` | Shows an arrow keys navigation hint. | `boolean` | `false` | | `identifier` | `identifier` | A unique identifier for the input. | `string \| undefined` | `undefined` | | `label` | `label` | The label for the input. | `string` | `''` | @@ -32,9 +52,9 @@ An inline date picker component to select a date. ## Events -| Event | Description | Type | -| --------------- | ---------------------------------------------------------- | -------------------------------- | -| `catChange` | Emitted when the value is changed. | `CustomEvent` | +| Event | Description | Type | +| ------------------- | ---------------------------------------------------------------------------------- | ------------------------------- | +| `catChange` | Emitted when the value is changed. | `CustomEvent` | | `catDateViewChange` | Emitted with the visible inclusive calendar range and whenever that range changes. | `CustomEvent` | diff --git a/core/src/components/cat-date/cat-date.tsx b/core/src/components/cat-date/cat-date.tsx index 84596d84d..a521e01e5 100644 --- a/core/src/components/cat-date/cat-date.tsx +++ b/core/src/components/cat-date/cat-date.tsx @@ -136,9 +136,9 @@ export class CatDate { @Prop({ mutable: true }) value?: string; /** - * Applies a semantic theme variant to each matching local ISO date. + * Maps local ISO dates (YYYY-MM-DD) to semantic theme variants, e.g. `{ '2026-10-20': 'danger' }`. */ - @Prop() dayVariants?: Record; + @Prop() dayVariants?: { [date: string]: CatDateDayVariant }; /** * The validation errors for this input. Will render a hint under the input diff --git a/core/src/components/cat-date/readme.md b/core/src/components/cat-date/readme.md index b146f6a20..63e6afc1d 100644 --- a/core/src/components/cat-date/readme.md +++ b/core/src/components/cat-date/readme.md @@ -1,6 +1,26 @@ # cat-date +## Per-day variants +`dayVariants` maps local `YYYY-MM-DD` dates to `CatDateDayVariant`: `primary`, +`secondary`, `info`, `success`, `warning`, or `danger`. Pass an object, not a +single variant string or an HTML attribute. Selected dates and today keep their +usual styling; disabled dates remain disabled. + +```ts +const picker = document.querySelector('cat-date'); +picker.dayVariants = { '2026-10-20': 'warning', '2026-10-21': 'danger' }; +``` + +In Angular, pass the object through a property binding: + +```html + +``` + +`catDateViewChange` reports `{ from, to }` as inclusive local ISO dates for the +visible grid, including days from adjacent months. Consumers decide what to +fetch and which variants to assign. @@ -15,7 +35,7 @@ A date input component to select a date from a calendar in a dropdown. | ------------------ | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------- | | `autoComplete` | `auto-complete` | Hint for form autofill feature. | `string` | `'off'` | | `clearable` | `clearable` | Whether the input should show a clear button. | `boolean` | `false` | -| `dayVariants` | -- | Applies a semantic theme variant to each matching local ISO date. | `"danger" \| "info" \| "primary" \| "secondary" \| "success" \| "warning" \| string \| undefined` | `undefined` | +| `dayVariants` | -- | Maps local ISO dates (YYYY-MM-DD) to semantic theme variants, e.g. `{ '2026-10-20': 'danger' }`. | `undefined \| { [date: string]: CatDateDayVariant; }` | `undefined` | | `disabled` | `disabled` | Whether the input is disabled. | `boolean` | `false` | | `errorUpdate` | `error-update` | Fine-grained control over when the errors are shown. Can be `false` to never show errors, `true` to show errors on blur, or a number to show errors change with the given delay in milliseconds or immediately on blur. | `boolean \| number` | `0` | | `errors` | `errors` | The validation errors for this input. Will render a hint under the input with the translated error message(s) `error.${key}`. If an object is passed, the keys will be used as error keys and the values translation parameters. If the value is `true`, the input will be marked as invalid without any hints under the input. | `boolean \| string[] \| undefined \| { [key: string]: any; }` | `undefined` | @@ -43,12 +63,12 @@ A date input component to select a date from a calendar in a dropdown. ## Events -| Event | Description | Type | -| --------------- | ---------------------------------------------------------- | -------------------------------- | -| `catBlur` | Emitted when the input loses focus. | `CustomEvent` | -| `catChange` | Emitted when the value is changed. | `CustomEvent` | +| Event | Description | Type | +| ------------------- | ---------------------------------------------------------------------------------- | ------------------------------- | +| `catBlur` | Emitted when the input loses focus. | `CustomEvent` | +| `catChange` | Emitted when the value is changed. | `CustomEvent` | | `catDateViewChange` | Emitted with the visible inclusive calendar range and whenever that range changes. | `CustomEvent` | -| `catFocus` | Emitted when the input received focus. | `CustomEvent` | +| `catFocus` | Emitted when the input received focus. | `CustomEvent` | ## Methods