Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions angular/projects/catalyst/src/lib/directives/proxies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ export declare interface CatCheckbox extends Components.CatCheckbox {
inputs: [
'autoComplete',
'clearable',
'dayVariants',
'disabled',
'errorUpdate',
'errors',
Expand Down Expand Up @@ -352,6 +353,7 @@ export declare interface CatCheckbox extends Components.CatCheckbox {
inputs: [
'autoComplete',
'clearable',
'dayVariants',
'disabled',
'errorUpdate',
'errors',
Expand All @@ -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<CustomEvent<string>>();
@Output() catDateViewChange = new EventEmitter<CustomEvent<ICatDateCatDateViewRange>>();
Comment thread
ddoe8 marked this conversation as resolved.
Resolved
@Output() catFocus = new EventEmitter<CustomEvent<FocusEvent>>();
@Output() catBlur = new EventEmitter<CustomEvent<FocusEvent>>();
constructor(
Expand All @@ -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<CustomEvent<string>>;
/**
* Emitted with the visible inclusive calendar range and whenever that range changes.
*/
catDateViewChange: EventEmitter<CustomEvent<ICatDateCatDateViewRange>>;
/**
* Emitted when the input received focus.
*/
Expand All @@ -412,6 +421,7 @@ export declare interface CatDate extends Components.CatDate {
@ProxyCmp({
inputs: [
'a11yLabel',
'dayVariants',
'hint',
'identifier',
'label',
Expand All @@ -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',
Expand All @@ -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<CustomEvent<string>>();
@Output() catDateViewChange = new EventEmitter<CustomEvent<ICatDateInlineCatDateViewRange>>();
constructor(
c: ChangeDetectorRef,
r: ElementRef,
Expand All @@ -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<CustomEvent<string>>;
/**
* Emitted with the visible inclusive calendar range and whenever that range changes.
*/
catDateViewChange: EventEmitter<CustomEvent<ICatDateInlineCatDateViewRange>>;
}

@ProxyCmp({
Expand Down
30 changes: 30 additions & 0 deletions core/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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";
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -509,6 +517,10 @@ export namespace Components {
* Clear the picker.
*/
"clear": () => Promise<void>;
/**
* 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.
Expand Down Expand Up @@ -2479,6 +2491,7 @@ declare global {
};
interface HTMLCatDateElementEventMap {
"catChange": string;
"catDateViewChange": CatDateViewRange;
"catFocus": FocusEvent;
"catBlur": FocusEvent;
}
Expand All @@ -2501,6 +2514,7 @@ declare global {
};
interface HTMLCatDateInlineElementEventMap {
"catChange": string;
"catDateViewChange": CatDateViewRange;
}
/**
* An inline date picker component to select a date.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -3466,6 +3484,10 @@ declare namespace LocalJSX {
* Emitted when the value is changed.
*/
"onCatChange"?: (event: CatDateCustomEvent<string>) => void;
/**
* Emitted with the visible inclusive calendar range and whenever that range changes.
*/
"onCatDateViewChange"?: (event: CatDateCustomEvent<CatDateViewRange>) => void;
/**
* Emitted when the input received focus.
*/
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -3560,6 +3586,10 @@ declare namespace LocalJSX {
* Emitted when the value is changed.
*/
"onCatChange"?: (event: CatDateInlineCustomEvent<string>) => void;
/**
* Emitted with the visible inclusive calendar range and whenever that range changes.
*/
"onCatDateViewChange"?: (event: CatDateInlineCustomEvent<CatDateViewRange>) => void;
/**
* Allow the selection of a range of dates, i.e. start and end date.
* @default false
Expand Down
2 changes: 2 additions & 0 deletions core/src/components/cat-date-inline/cat-date-day-variant.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/** Semantic theme variants available for individual date cells. */
export type CatDateDayVariant = 'primary' | 'secondary' | 'info' | 'success' | 'warning' | 'danger';
27 changes: 27 additions & 0 deletions core/src/components/cat-date-inline/cat-date-inline.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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');
Comment thread
ddoe8 marked this conversation as resolved.
Resolved
}
}

@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;
Expand Down
62 changes: 62 additions & 0 deletions core/src/components/cat-date-inline/cat-date-inline.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,66 @@ describe('cat-date-inline', () => {
<cat-date-inline tabindex="0" class="hydrated"></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(<cat-date-inline dayVariants={dayVariants} />);

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(<cat-date-inline value="2026-12-15" onCatDateViewChange={viewChange} />);

const dates = root.shadowRoot?.querySelectorAll<HTMLElement>('[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(<cat-date-inline />);
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(<cat-date-inline />);
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]);
});
});
Loading
Loading