import {classMap} from "lit/directives/class-map.js"; import {type CSSResultGroup, html, type PropertyValues, unsafeCSS} from 'lit'; import {defaultValue} from "../../internal/default-value"; import {FormControlController} from "../../internal/form"; import {HasSlotController} from "../../internal/slot"; import {ifDefined} from "lit/directives/if-defined.js"; import {live} from "lit/directives/live.js"; import {property, query, state} from 'lit/decorators.js'; import {watch} from "../../internal/watch"; import AirDatepicker, {type AirDatepickerLocale, type AirDatepickerOptions} from "air-datepicker"; import ZincElement from '../../internal/zinc-element'; import ZnIcon from "../icon"; import ZnTooltip from "../tooltip"; import type {ZincFormControl} from '../../internal/zinc-element'; import styles from './datepicker.scss'; /** * @summary A date picker component with calendar popup and input validation. * @documentation https://zinc.style/components/datepicker * @status experimental * @since 1.0 * * @dependency zn-icon * @dependency zn-tooltip * * @event zn-change - Emitted when the date value changes. * @event zn-input - Emitted when the input value changes. * @event zn-blur - Emitted when the input loses focus. * @event zn-focus - Emitted when the input gains focus. * * @slot label - The datepicker's label. Alternatively, you can use the `label` attribute. * @slot label-tooltip - Tooltip content for the label. Alternatively, you can use the `label-tooltip` attribute. * @slot context-note - Additional context text displayed above the input. Alternatively, you can use the `context-note` attribute. * @slot help-text - Help text displayed below the input. Alternatively, you can use the `help-text` attribute. * @slot prefix - Content to display before the input (in addition to the default calendar icon). * @slot suffix - Content to display after the input. * * @csspart base - The component's base wrapper. * @csspart form-control - The form control wrapper. * @csspart form-control-label - The label element. * @csspart form-control-input - The input wrapper. * @csspart form-control-help-text - The help text element. * * @property format - Date format using AirDatepicker tokens. Default: 'dd/MM/yyyy' * Supported formats: * - dd/MM/yyyy (31/12/2024) - Default * - MM/dd/yyyy (12/31/2024) * - yyyy-MM-dd (2024-12-31) * - dd-MM-yyyy (31-12-2024) * - yyyy/MM/dd (2024/12/31) * * @cssproperty --zn-input-* - Inherited input component CSS custom properties. */ export default class ZnDatepicker extends ZincElement implements ZincFormControl { static styles: CSSResultGroup = unsafeCSS(styles); static dependencies = { 'zn-icon': ZnIcon, 'zn-tooltip': ZnTooltip } private readonly formControlController = new FormControlController(this, { assumeInteractionOn: ['zn-blur', 'zn-input'] }); private readonly hasSlotController = new HasSlotController(this, 'help-text', 'label', 'label-tooltip'); @query('.input__control') input: HTMLInputElement; @state() private hasFocus = false; @property() title = "" // make reactive pass through /** The name of the input, submitted as a name/value pair with form data. */ @property() name: string = ""; /** The current value of the input, submitted as a name/value pair with form data. */ @property() value: any = ''; /** The default value of the form control. Primarily used for resetting the form control. */ @defaultValue() defaultValue: string = ''; /** The inputs size **/ @property({reflect: true}) size: 'small' | 'medium' | 'large' = 'medium'; /** The inputs label. If you need to display HTML, use the `label` slot. **/ @property() label: string = ''; /** Text that appears in a tooltip next to the label. If you need to display HTML in the tooltip, use the * `label-tooltip` slot. * **/ @property({attribute: 'label-tooltip'}) labelTooltip: string = ''; /** * Text that appears above the input, on the right, to add additional context. If you need to display HTML * in this text, use the `context-note` slot instead */ @property({attribute: 'context-note'}) contextNote: string = ''; /** The input's help text. If you need to display HTML, use the `help-text` slot instead. **/ @property({attribute: 'help-text'}) helpText: string = ''; /** Disables the input **/ @property({type: Boolean, reflect: true}) disabled: boolean = false; /** Placeholder text to show as a hint when the input is empty. */ @property() placeholder: string = ''; /** Makes the input read-only **/ @property({type: Boolean, reflect: true}) readonly: boolean = false; /** * By default, form-controls are associated with the nearest containing `