diff --git a/angular/projects/catalyst/src/lib/directives/proxies.ts b/angular/projects/catalyst/src/lib/directives/proxies.ts index 33bd5ff0..36b9ad2d 100644 --- a/angular/projects/catalyst/src/lib/directives/proxies.ts +++ b/angular/projects/catalyst/src/lib/directives/proxies.ts @@ -318,6 +318,7 @@ export declare interface CatCheckbox extends Components.CatCheckbox { inputs: [ 'autoComplete', 'clearable', + 'dayVariants', 'disabled', 'errorUpdate', 'errors', @@ -352,6 +353,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', 'catDateViewChange', 'catFocus', 'catBlur'], standalone: false }) export class CatDate { protected el: HTMLCatDateElement; @Output() catChange = new EventEmitter>(); + @Output() catDateViewChange = new EventEmitter>(); @Output() catFocus = new EventEmitter>(); @Output() catBlur = new EventEmitter>(); constructor( @@ -394,11 +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>; + /** + * Emitted with the visible inclusive calendar range and whenever that range changes. + */ + catDateViewChange: EventEmitter>; /** * Emitted when the input received focus. */ @@ -412,6 +421,7 @@ export declare interface CatDate extends Components.CatDate { @ProxyCmp({ inputs: [ 'a11yLabel', + 'dayVariants', 'hint', 'identifier', 'label', @@ -435,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', @@ -449,12 +460,13 @@ export declare interface CatDate extends Components.CatDate { 'value', 'weeks' ], - outputs: ['catChange'], + outputs: ['catChange', 'catDateViewChange'], standalone: false }) export class CatDateInline { protected el: HTMLCatDateInlineElement; @Output() catChange = new EventEmitter>(); + @Output() catDateViewChange = new EventEmitter>(); constructor( c: ChangeDetectorRef, r: ElementRef, @@ -465,11 +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>; + /** + * 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 4f498ea9..a6182a4c 100644 --- a/core/src/components.d.ts +++ b/core/src/components.d.ts @@ -6,8 +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 { 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"; @@ -17,8 +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 { 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"; @@ -382,6 +386,10 @@ export namespace Components { * @default false */ "clearable": boolean; + /** + * Maps local ISO dates (YYYY-MM-DD) to semantic theme variants, e.g. `{ '2026-10-20': 'danger' }`. + */ + "dayVariants"?: { [date: string]: CatDateDayVariant }; /** * Whether the input is disabled. * @default false @@ -509,6 +517,10 @@ export namespace Components { * Clear the picker. */ "clear": () => Promise; + /** + * Maps local ISO dates (YYYY-MM-DD) to semantic theme variants, e.g. `{ '2026-10-20': 'danger' }`. + */ + "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. @@ -2479,6 +2491,7 @@ declare global { }; interface HTMLCatDateElementEventMap { "catChange": string; + "catDateViewChange": CatDateViewRange; "catFocus": FocusEvent; "catBlur": FocusEvent; } @@ -2501,6 +2514,7 @@ declare global { }; interface HTMLCatDateInlineElementEventMap { "catChange": string; + "catDateViewChange": CatDateViewRange; } /** * An inline date picker component to select a date. @@ -3393,6 +3407,10 @@ declare namespace LocalJSX { * @default false */ "clearable"?: boolean; + /** + * Maps local ISO dates (YYYY-MM-DD) to semantic theme variants, e.g. `{ '2026-10-20': 'danger' }`. + */ + "dayVariants"?: { [date: string]: CatDateDayVariant }; /** * Whether the input is disabled. * @default false @@ -3466,6 +3484,10 @@ declare namespace LocalJSX { * Emitted when the value is changed. */ "onCatChange"?: (event: CatDateCustomEvent) => void; + /** + * Emitted with the visible inclusive calendar range and whenever that range changes. + */ + "onCatDateViewChange"?: (event: CatDateCustomEvent) => void; /** * Emitted when the input received focus. */ @@ -3519,6 +3541,10 @@ declare namespace LocalJSX { * Adds accessible label for the datepicker. The label will be read by assistive technology upon focusing the datepicker. */ "a11yLabel"?: string; + /** + * Maps local ISO dates (YYYY-MM-DD) to semantic theme variants, e.g. `{ '2026-10-20': 'danger' }`. + */ + "dayVariants"?: { [date: string]: CatDateDayVariant }; /** * Shows an arrow keys navigation hint. * @default false @@ -3560,6 +3586,10 @@ declare namespace LocalJSX { * Emitted when the value is changed. */ "onCatChange"?: (event: CatDateInlineCustomEvent) => void; + /** + * Emitted with the visible inclusive calendar range and whenever that range changes. + */ + "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 00000000..94ae8bff --- /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 04b1bb06..e7f3a735 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,6 +128,24 @@ opacity: 0.25; } +@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) { + box-shadow: inset 0 0 0 1px var(--cat-date-day-danger-border-color, transparent); +} + .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 59a19d30..d650610f 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,66 @@ describe('cat-date-inline', () => { `); }); + + 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 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(); + root.addEventListener('catDateViewChange', viewChange); + + (root.shadowRoot?.querySelectorAll('cat-button')[2] as HTMLElement).click(); + await waitForChanges(); + + const inline = root as HTMLCatDateInlineElement; + await inline.resetView(); + await waitForChanges(); + await inline.resetView(); + await waitForChanges(); + + 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 556db3a9..ea3c1d7a 100644 --- a/core/src/components/cat-date-inline/cat-date-inline.tsx +++ b/core/src/components/cat-date-inline/cat-date-inline.tsx @@ -1,7 +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 { CatDateViewRange } from './cat-date-view-range'; import firstTabbable from '../../utils/first-tabbable'; let nextUniqueId = 0; @@ -26,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; @@ -107,11 +110,21 @@ export class CatDateInline { */ @Prop({ mutable: true }) value?: string; + /** + * Maps local ISO dates (YYYY-MM-DD) to semantic theme variants, e.g. `{ '2026-10-20': 'danger' }`. + */ + @Prop() dayVariants?: { [date: string]: CatDateDayVariant }; + /** * Emitted when the value is changed. */ @Event() catChange!: EventEmitter; + /** + * Emitted with the visible inclusive calendar range and whenever that range changes. + */ + @Event() catDateViewChange!: EventEmitter; + private get focusedDate() { const [all, year, month, day] = this.hostElement.shadowRoot @@ -137,12 +150,13 @@ 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(); this.focusDate = null; } + this.emitDateViewChange(); } @Listen('keydown') @@ -325,6 +339,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 +356,8 @@ export class CatDateInline { 'date-start': this.range && isStartDate, 'date-range': this.range && isRange, 'date-end': this.range && isEndDate, + 'date-selected': isStartDate || isEndDate, + [`date-variant-${variant}`]: !!variant, 'date-focusable': this.canFocus(day), 'date-disabled': !this.canClick(day) }} @@ -350,7 +368,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()} @@ -405,6 +423,19 @@ export class CatDateInline { this.setAriaLive(this.getHeadline()); } + private emitDateViewChange() { + const dateGrid = this.dateGrid(this.viewDate.getFullYear(), this.viewDate.getMonth()); + 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) { const node = this.hostElement.shadowRoot?.querySelector('.cursor-aria'); if (node && text) { 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 00000000..83317e49 --- /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 9252d123..d000dcaf 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,6 +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` | -- | 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` | `''` | @@ -31,9 +52,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` | +| `catDateViewChange` | Emitted with the visible inclusive calendar range and whenever that range changes. | `CustomEvent` | ## Methods @@ -99,6 +121,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 390d89fc..c00a19c2 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 ca0b4e4e..5967d3b0 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 5b1518ef..a521e01e 100644 --- a/core/src/components/cat-date/cat-date.tsx +++ b/core/src/components/cat-date/cat-date.tsx @@ -2,6 +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 { 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'; @@ -133,6 +135,11 @@ export class CatDate { */ @Prop({ mutable: true }) value?: string; + /** + * Maps local ISO dates (YYYY-MM-DD) to semantic theme variants, e.g. `{ '2026-10-20': 'danger' }`. + */ + @Prop() dayVariants?: { [date: string]: CatDateDayVariant }; + /** * 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 +193,11 @@ export class CatDate { */ @Event() catChange!: EventEmitter; + /** + * Emitted with the visible inclusive calendar range and whenever that range changes. + */ + @Event() catDateViewChange!: EventEmitter; + /** * Emitted when the input received focus. */ @@ -310,10 +322,15 @@ export class CatDate { min={this.min} max={this.max} value={this.value} + dayVariants={this.dayVariants} hint weeks noClear onCatChange={this.onDateChange.bind(this)} + onCatDateViewChange={(e: CustomEvent) => { + e.stopPropagation(); + this.catDateViewChange.emit(e.detail); + }} >
diff --git a/core/src/components/cat-date/readme.md b/core/src/components/cat-date/readme.md index 10ca5ef0..63e6afc1 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,6 +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` | -- | 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` | @@ -42,11 +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` | -| `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` | +| `catDateViewChange` | Emitted with the visible inclusive calendar range and whenever that range changes. | `CustomEvent` | +| `catFocus` | Emitted when the input received focus. | `CustomEvent` | ## Methods @@ -90,6 +112,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 6b73e552..e90f39e8 100644 --- a/core/src/index.ts +++ b/core/src/index.ts @@ -19,3 +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 { CatDateDayVariant } from './components/cat-date-inline/cat-date-day-variant'; +export type { CatDateViewRange } from './components/cat-date-inline/cat-date-view-range';