UNPKG

@instawork/design-system

Version:

The design system for Instawork's web apps

68 lines (67 loc) 2.89 kB
import { DateTime } from 'luxon'; import { AttributeInvalidError, AttributeRequiredError } from '../common'; import { NestedInputComponent } from '../nested-input'; export interface TemporalInputElement extends HTMLElement { } export declare enum SyncValueAttribute { none = 1, host = 2, value = 4, hostAndValue = 6 } export declare abstract class TemporalComponent<TElement extends TemporalInputElement = TemporalInputElement> extends NestedInputComponent<TElement, DateTime> { /** * Used to optionally set the base date used when constructing a new date/time value from the selected time. */ get baseDate(): string; get timeZone(): string; get isValid(): boolean; /** * Returns the Luxon {@link DateTime} object representation of the input's value. */ get luxonValue(): DateTime; get luxonOriginalValue(): DateTime; get isModified(): boolean; get value(): string; set value(value: string); /** * Determines which elements get their "value" attribute updated when the value changes */ protected get syncValueAttr(): SyncValueAttribute; protected constructor($el: JQuery<TElement>); /** * Returns a {@link DateTime} parsed from the provided input. Returns `undefined` if the input is a `null`, * `undefined`, or empty string value. * * @param input - A string representation of a date/time */ parseValue(input: string): DateTime; /** * Attempts to parse the specified input into a {@link DateTime} value and set it as the value for the component. */ importValue(input: string): DateTime; /** * Convenience method for handling all logic around value updates: storing the parsed {@link DateTime} value, setting * DOM attribute and value properties, emitting change events, validation */ syncValue(value?: DateTime): DateTime; /** * Stores the {@link DateTime} representation of the value for access by {@link luxonValue} */ protected setLuxonValue(value: DateTime): void; /** * Stores the {@link DateTime} representation of the original value for access by {@link luxonOriginalValue} */ protected setLuxonOriginalValue(value: DateTime): void; protected initValue(): void; protected getBaseDate(): DateTime; protected isValueChanged(prev: DateTime, next: DateTime): boolean; protected setComponentValue(value: DateTime): void; protected formatValue(value: DateTime): string; protected updateValidityState(value: DateTime): DateTime; /** * Handles UI side effects of value updates, such as validation display and change events */ protected onValue(value: DateTime, isChanged: boolean, isValid: boolean): void; protected invalidDateTimeAttributeError(attrName: string, value: DateTime): AttributeInvalidError | AttributeRequiredError; }