import CwElement from '../../internal/cw-element.js'; import CwIcon from '../icon/icon.component.js'; import CwOption from '../option/option.component.js'; import CwPopup from '../popup/popup.component.js'; import type { CSSResultGroup } from 'lit'; import type { CwFormControl } from '../../internal/cw-element.js'; type TimeGranularity = 'hour' | 'minute' | 'second'; type HourFormat = 'auto' | '12' | '24'; /** * @summary Time pickers let users select a time from a set of predefined hour, minute, second, and meridiem columns. * @documentation https://cw-elements-b0c7e5.gitlab.io/components/time-picker * @status experimental * @since 1.1 * * @dependency cw-icon * @dependency cw-option * @dependency cw-popup * * @slot label - The input's label. Alternatively, you can use the `label` attribute. * @slot prefix - Used to prepend a presentational icon or similar element to the combobox. * @slot suffix - Used to append a presentational icon or similar element to the combobox. * @slot clear-icon - An icon to use in lieu of the default clear icon. * @slot expand-icon - The icon to show when the control is expanded and collapsed. * @slot help-text - Text that describes how to use the input. Alternatively, you can use the `help-text` attribute. * * @event cw-change - Emitted when the control's value changes. * @event cw-clear - Emitted when the control's value is cleared. * @event cw-input - Emitted when the control receives input. * @event cw-focus - Emitted when the control gains focus. * @event cw-blur - Emitted when the control loses focus. * @event cw-show - Emitted when the time picker's listbox opens. * @event cw-after-show - Emitted after the time picker's listbox opens and all animations are complete. * @event cw-hide - Emitted when the time picker's listbox closes. * @event cw-after-hide - Emitted after the time picker's listbox closes and all animations are complete. * @event cw-invalid - Emitted when the form control has been checked for validity and its constraints aren't satisfied. * * @csspart form-control - The form control that wraps the label, input, and help text. * @csspart form-control-label - The label's wrapper. * @csspart form-control-input - The time picker's wrapper. * @csspart form-control-help-text - The help text's wrapper. * @csspart combobox - The container the wraps the prefix, suffix, display input, clear icon, and expand icon. * @csspart prefix - The container that wraps the prefix slot. * @csspart suffix - The container that wraps the suffix slot. * @csspart display-input - The element that displays the selected time, an `` element. * @csspart listbox - The listbox container where the hour/minute/second/meridiem columns are rendered. * @csspart column - One of the listbox's columns. * @csspart option - An individual option within a column. * @csspart clear-button - The clear button. * @csspart expand-icon - The container that wraps the expand icon. */ export default class CwTimePicker extends CwElement implements CwFormControl { static styles: CSSResultGroup; static dependencies: { 'cw-icon': typeof CwIcon; 'cw-option': typeof CwOption; 'cw-popup': typeof CwPopup; }; private readonly formControlController; private readonly hasSlotController; private readonly localize; private closeWatcher; popup: CwPopup; combobox: HTMLElement; displayInput: HTMLInputElement; valueInput: HTMLInputElement; listbox: HTMLElement; columnElements: NodeListOf; private hasFocus; private activeColumn; private valueHasChanged; /** The name of the time picker, submitted as a name/value pair with form data. */ name: string; private _value; get value(): string; /** * The current value of the time picker, submitted as a name/value pair with form data. The value is a 24-hour, * zero-padded string whose precision matches `granularity` (e.g. `"14"`, `"14:08"`, or `"14:08:32"`). */ set value(val: string); /** The default value of the form control. Primarily used for resetting the form control. */ defaultValue: string; /** The smallest unit of time the picker allows the user to set. */ granularity: TimeGranularity; /** * The hour format to use. When `auto`, the format is determined by the page's locale. When `12`, hours are shown from * 1-12 alongside an AM/PM column. When `24`, hours are shown from 00-23. */ hourFormat: HourFormat; /** The time picker's size. */ size: 'small' | 'medium' | 'large'; /** Placeholder text to show as a hint when the time picker is empty. */ placeholder: string; /** Disables the time picker. */ disabled: boolean; /** Adds a clear button when the time picker is not empty. */ clearable: boolean; /** * Indicates whether or not the time picker is open. You can toggle this attribute to show and hide the listbox, or you * can use the `show()` and `hide()` methods and this attribute will reflect the time picker's open state. */ open: boolean; /** * Enable this option to prevent the listbox from being clipped when the component is placed inside a container with * `overflow: auto|scroll`. Hoisting uses a fixed positioning strategy that works in many, but not all, scenarios. */ hoist: boolean; /** Draws a filled time picker. */ filled: boolean; /** Draws a pill-style time picker with rounded edges. */ pill: boolean; /** The time picker's label. If you need to display HTML, use the `label` slot instead. */ label: string; /** * The preferred placement of the time picker's listbox. Note that the actual placement may vary as needed to keep the * listbox inside of the viewport. */ placement: 'top' | 'bottom'; /** The time picker's help text. If you need to display HTML, use the `help-text` slot instead. */ helpText: string; /** * By default, form controls are associated with the nearest containing `
` element. This attribute allows you * to place the form control outside of a form and associate it with the form that has this `id`. The form must be in * the same document or shadow root for this to work. */ form: string; /** The time picker's required attribute. */ required: boolean; /** Gets the validity state object */ get validity(): ValidityState; /** Gets the validation message */ get validationMessage(): string; private get parsedValue(); connectedCallback(): void; private addOpenListeners; private removeOpenListeners; private handleFocus; private handleBlur; private handleLabelClick; private handleDocumentFocusIn; private handleDocumentMouseDown; private handleDocumentKeyDown; private handleComboboxMouseDown; private handleComboboxKeyDown; private handleClearClick; private handleClearMouseDown; private handleListboxMouseDown; private handleOptionClick; private handleInvalid; private getHourCycle; private is12Hour; private getPeriodLabel; private getColumns; private getColumnValue; private applyColumnValue; private setTimeValue; private scrollActiveOptionsIntoView; private get displayLabel(); private getColumnLabel; private getColumnOptionLabel; private renderColumn; handleDisabledChange(): void; attributeChangedCallback(name: string, oldVal: string | null, newVal: string | null): void; handleValueChange(): void; handleGranularityOrHourFormatChange(): void; handleOpenChange(): Promise; /** Shows the listbox. */ show(): Promise; /** Hides the listbox. */ hide(): Promise; /** Checks for validity but does not show a validation message. Returns `true` when valid and `false` when invalid. */ checkValidity(): boolean; /** Gets the associated form, if one exists. */ getForm(): HTMLFormElement | null; /** Checks for validity and shows the browser's validation message if the control is invalid. */ reportValidity(): boolean; /** Sets a custom validation message. Pass an empty string to restore validity. */ setCustomValidity(message: string): void; /** Sets focus on the control. */ focus(options?: FocusOptions): void; /** Removes focus from the control. */ blur(): void; render(): import("lit-html").TemplateResult<1>; } export {};