import type { RequireAtLeastOne } from 'type-fest'; import { type DataTestId, type MaskingProps, type StylingProps, type AriaDisabledProps } from '@dynatrace/strato-components/core'; import type { FormControlProps } from '../../core/types/form-control-props.js'; import type { TimeValue, TimeframeV2 } from '../../core/types/time.js'; import type { DateTimePickerPrecision, DateTimePickerType } from '../date-time-picker/types.js'; import type { FormControlRef, TimeRangePickerRef } from '../shared-types.js'; import type { SpinButtonHandler } from '../spin-buttons/spin-button-group/types.js'; /** * Possible DateTimeInput error states * @internal */ export type DateTimeRangeError = DateTimeError | 'invalidOrder'; /** @internal */ export type ValidationError = { error: DateTimeRangeError; source: 'both' | 'from' | 'to'; }; /** * Props for the controlled and uncontrolled version for the DateTimeRangePicker component. * @internal */ export type DateTimeRangePickerProps = FormControlProps | RequireAtLeastOne | null, (value: TimeframeV2 | null) => void> & StylingProps & DataTestId & MaskingProps & { /** * The ISODatetime string of the earliest datetime that can be configured. * @defaultValue '1677-09-21T00:12:43.145224192Z' */ min?: string; /** * The ISODatetime string of the latest datetime that can be configured. * @defaultValue '2262-04-11T23:47:16.854775807Z' */ max?: string; /** * Determines the level of precision of the time component. * @defaultValue 'minutes' */ precision?: DateTimePickerPrecision; /** * The placeholder that's shown in the respective input fields if the content is empty. */ placeholder?: { from?: string; to?: string; }; }; /** * Imperative handler to give access to the DOM elements of the DateTimeRangePicker. * It provides additional methods to interact with the DateTimeRangePicker. * @internal */ export type DateTimeRangePickerRef = Omit & Pick & { /** Open calendar widget.*/ readonly open: () => void; /** Close calendar widget.*/ readonly close: () => void; }; /** * Possible DateTimeInput error states * @internal */ export type DateTimeError = 'valueMissing' | 'invalid' | 'outsideRange' | null; /** * Common props for the controlled and uncontrolled version for the DateTimeInput component. * @internal */ export type DateTimeInputProps = FormControlProps void> & StylingProps & DataTestId & { /** * ISODatetime string of the earliest datetime that can be configured. */ min?: string; /** * ISODatetime string of the latest datetime that can be configured. */ max?: string; /** * Determines the level of precision of the time component. */ precision?: DateTimePickerPrecision; /** * Determines which spin buttons will be shown when not in expression mode. */ type?: DateTimePickerType; /** * The placeholder that's shown in the respective input fields if the content is empty. */ placeholder?: string; /** Callback triggered when the element has an error. */ onError?: (error: DateTimeError) => void; controlId?: string; }; /** * Imperative handler to give access to the DOM elements of the DateTimeInput. * @internal */ export type DateTimeInputRef = Omit, 'inputRef'> & { readonly inputRef?: HTMLInputElement | null; readonly expressionInputRef?: HTMLSpanElement | null; readonly spinButtonHandlers: Map; }; /** * Props of the DateRangeSelector value. * @internal */ export type DateRangeSelectorValueType = { from: TimeValue | null; to: TimeValue | null; } | null; /** * Props of the DateRangeSelector component. * @internal */ export interface DateRangeSelectorProps extends StylingProps, DataTestId, MaskingProps, AriaDisabledProps { /** ISO string to initialize the calendar widget when opened. */ value: DateRangeSelectorValueType; /** Returns the selected ISO datetime selected in the calendar widget. */ onChange: (value: DateRangeSelectorValueType) => void; /** Determine if the trigger is disabled or not. */ disabled?: boolean; /** Determines whether the input is in read-only mode. */ readOnly?: boolean; /** Determine if the trigger is in error state or not. */ error: boolean; /** ISODatetime string of the earliest datetime that can be configured. */ min?: string; /** ISODatetime string of the latest datetime that can be configured. */ max?: string; /** Determine if the ValueFrom is in error state or not. */ errorFrom?: DateTimeRangeError; /** Determine if the ValueTo is in error state or not. */ errorTo?: DateTimeRangeError; /** Determines the level of precision of the time component. */ precision?: 'minutes' | 'seconds' | 'milliseconds'; } /** * Imperative handle to provide methods to interact with the calendar widget. * @internal */ export interface DateRangeSelectorRef { /** Open the calendar widget. */ open(): void; /** Close the calendar widget. */ close(): void; }