import { html } from 'lit' import { customElement, property } from 'lit/decorators.js' import { classMap } from 'lit/directives/class-map.js' import { ifDefined } from 'lit/directives/if-defined.js' import { ref } from 'lit/directives/ref.js' import { PktDatepickerBase } from './datepicker-base' import { keyboardUtils, formUtils } from './datepicker-utils' import { IDatepickerStrings, defaultSingleStrings } from './datepicker-types' import { isIOS } from 'shared-utils/device-utils' export class PktDatepickerSingle extends PktDatepickerBase { @property({ type: String }) value: string = '' @property({ type: Object }) strings: IDatepickerStrings = defaultSingleStrings private dispatchManageValidity(input: HTMLInputElement) { this.dispatchEvent( new CustomEvent('manage-validity', { detail: input, bubbles: true, composed: true, }), ) } render() { return html`
{ e.preventDefault() this.dispatchToggleCalendar(e) }} @touchend=${(e: TouchEvent) => { e.preventDefault() this.dispatchToggleCalendar(e) }} ?disabled=${this.disabled} @keydown=${(e: KeyboardEvent) => keyboardUtils.handleInputKeydown( e, (event) => this.dispatchToggleCalendar(event), () => formUtils.submitFormOrFallback(this.internals, () => this.inputRef.value?.blur()), undefined, () => this.inputRef.value?.blur(), )} @input=${(e: Event) => { this.dispatchInput(e) e.stopImmediatePropagation() }} @focus=${() => { this.dispatchFocus() if (isIOS()) { this.dispatchToggleCalendar(new Event('focus')) } }} @blur=${(e: FocusEvent) => { this.dispatchBlur(e) this.dispatchManageValidity(e.target as HTMLInputElement) this.dispatchEvent( new CustomEvent('value-change', { detail: (e.target as HTMLInputElement).value, bubbles: true, composed: true, }), ) }} @change=${(e: Event) => { this.dispatchChange(e) e.stopImmediatePropagation() }} ${ref(this.inputRef)} /> ${this.renderCalendarButton()}
` } } try { customElement('pkt-datepicker-single')(PktDatepickerSingle) } catch (e) { console.warn('Forsøker å definere , men den er allerede definert') }