import { LitElement, html, PropertyValues } from 'lit'; import { customElement, property, state, query } from 'lit/decorators.js'; import { ifDefined } from 'lit/directives/if-defined.js'; import { classMap } from 'lit/directives/class-map.js'; import { DATE_PICKER_TYPES } from './defs'; import DatePickerScss from './datepicker.scss'; /** * Datepicker. * @fires on-input - Captures the input event and emits the selected value and original event details. * @prop {string} minDate - Mimimum date in YYYY-MM-DD or YYYY-MM-DDThh:mm format. If the value isn't a possible date string in the format, then the element has no minimum date value. * @prop {string} maxDate - Maximum date in YYYY-MM-DD or YYYY-MM-DDThh:mm format. If the value isn't a possible date string in the format, then the element has no maximum date value * @slot unnamed - Slot for label text. */ @customElement('kyn-date-picker') export class DatePicker extends LitElement { static override styles = DatePickerScss; /** @ignore */ static override shadowRootOptions = { ...LitElement.shadowRootOptions, delegatesFocus: true, }; /** * Associate the component with forms. * @ignore */ static formAssociated = true; /** * Attached internals for form association. * @ignore */ @state() internals = this.attachInternals(); /** Datepicker size. "sm", "md", or "lg". */ @property({ type: String }) size = 'md'; /** Optional text beneath the input. */ @property({ type: String }) caption = ''; /** Datepicker value in YYYY-MM-DD or YYYY-MM-DDThh:mm format. */ @property({ type: String }) value = ''; /** Datepicker name. */ @property({ type: String }) name = ''; /** Makes the date required. */ @property({ type: Boolean }) required = false; /** Date disabled state. */ @property({ type: Boolean }) disabled = false; /** Date invalid text. */ @property({ type: String }) invalidText = ''; /** Date warning text */ @property({ type: String }) warnText = ''; /** Maximum date in YYYY-MM-DD or YYYY-MM-DDThh:mm format. * If the value isn't a possible date string in the format, then the element has no maximum date value */ @property({ type: String }) maxDate!: string; /** Minimum date in YYYY-MM-DD or YYYY-MM-DDThh:mm format, * If the value isn't a possible date string in the format, then the element has no minimum date value. */ @property({ type: String }) minDate!: string; /** Specifies the granularity that the value must adhere to, or the special value any, * For date inputs, the value of step is given in days; and is treated as a number of milliseconds equal to 86,400,000 times the step value. * The default value of step is 1, indicating 1 day.*/ @property({ type: String }) step!: string; /** Date picker types. Default 'single' */ @property({ type: String }) datePickerType: DATE_PICKER_TYPES = DATE_PICKER_TYPES.SINGLE; /** * Queries the DOM element. * @ignore */ @query('input') inputEl!: HTMLInputElement; /** * Internal validation message. * @ignore */ @state() internalValidationMsg = ''; /** * isInvalid when internalValidationMsg or invalidText is non-empty. * @ignore */ @state() isInvalid = false; override render() { return html`