import * as React from "react"; import "./DurationControl.css"; import { DurationUnitType } from "./DurationControlUnitInput"; type DurationControlUnit = { type: DurationUnitType; characters: number | undefined; step: number; max: number; value: number | null; }; type DurationControlElement = DurationControlUnit | string; /** * The DurationControl component props. */ export type DurationControlProps = { /** The class to apply to the control. */ className?: string | undefined; /** The pattern. */ pattern: string; /** The value in milliseconds. */ value: number; /** The change handler that is called whenever the control value changes. */ onChange: (milliseconds: number) => void; /** The change handler that is called whenever a control unit gets the focus. */ onUnitFocus?: (unit: DurationUnitType) => void; /** The change handler that is called whenever a control unit gets blurred. */ onUnitBlur?: (unit: DurationUnitType) => void; /** The control label. */ label?: string; /** A flag indicating whether the control is disabled. */ disabled?: boolean; /** A flag indicating whether to hide the control spinner. */ hideSpinner?: boolean; /** * If enable, it allows unit values (e.g., minutes, hours) to roll over to the next higher unit. * For example: * - Typing 59 into the minutes field and incrementing by 1 will reset the minutes to 0 and increment the hours by 1. * - Typing 65 into the minutes field will reset the minutes to 5 and increment the hours by 1. */ rollover?: boolean; /** * A flag indicating whether to render the control in a touch-friendly mode by making touch target areas larger. */ touchFriendly?: boolean; /** The maximum value for the day unit. Defaults to Number.MAX_SAFE_INTEGER */ dMax?: number; /** The amount to increment/decrement the day unit value by when an up/down arrow key or spinner button is pressed. Defaults to 1. */ dStep?: number; /** The maximum value for the hour unit. Defaults to Number.MAX_SAFE_INTEGER */ hMax?: number; /** The amount to increment/decrement the hour unit value by when an up/down arrow key or spinner button is pressed. Defaults to 1. */ hStep?: number; /** The maximum value for the minute unit. Defaults to Number.MAX_SAFE_INTEGER */ mMax?: number; /** The amount to increment/decrement the minute unit value by when an up/down arrow key or spinner button is pressed. Defaults to 1. */ mStep?: number; /** The maximum value for the second unit. Defaults to Number.MAX_SAFE_INTEGER */ sMax?: number; /** The amount to increment/decrement the second unit value by when an up/down arrow key or spinner button is pressed. Defaults to 1. */ sStep?: number; /** The maximum value for the millisecond unit. Defaults to Number.MAX_SAFE_INTEGER */ fMax?: number; /** The amount to increment/decrement the millisecond unit value by when an up/down arrow key or spinner button is pressed. Defaults to 1. */ fStep?: number; }; /** * The DurationControl component state. */ export type DurationControlState = { /** The pattern. */ pattern: string; /** The duration control elements. */ elements: DurationControlElement[]; /** The current value in milliseconds. */ milliseconds: number; /** The last unit input to have focus. */ lastFocusedInputUnitType: DurationUnitType | null; /** A flag indicating whether the control has focus. */ focused: boolean; }; /** * The DurationControl component. */ export declare class DurationControl extends React.Component { /** The mapping of time units to millisecond multipliers. */ private static UNIT_MILLISECOND_MULTIPLIERS; /** The default component props. */ static defaultProps: { dMax: number; dStep: number; hMax: number; hStep: number; mMax: number; mStep: number; sMax: number; sStep: number; fMax: number; fStep: number; }; /** * Creates the DurationControl element. * @param props The control properties. */ constructor(props: DurationControlProps); /** Gets the control class name. */ private get _controlClassName(); /** * Gets the state derived from the given props. * @param nextProps The next props. * @param prevState The previous state. * @returns The state derived from the given props. */ static getDerivedStateFromProps(nextProps: DurationControlProps, prevState: DurationControlState): { pattern: string; elements: DurationControlElement[]; milliseconds: number; lastFocusedInputUnitType: DurationUnitType | null; } | null; /** * Renders the component. */ render(): React.ReactNode; /** * Updates the value for the specified unit duration type. * @param unitType The unit input type. * @param value The new value. */ private _updateUnitValue; /** * Handles a unit input element getting focus. * @param type The focused unit input type. */ private _onUnitInputFocus; /** * Handles a unit input element getting blur. * * @param type The blurred unit input type. */ private _onUnitInputBlur; /** * Increments or decrements the current value for the specified unit. * @param isIncrement Whether the the value should be incremented rather than decremeneted. */ private _incrementOrDecrementUnitValue; /** * Gets the max and step prop values for the given unit type. * @param unitType The unit type. * @param props The component props. * @returns The max and step prop values for the given unit type. */ private static _getUnitPropValues; /** * Takes a time value in milliseconds and spreads the value across all available unit elements. * @param millis The milliseconds value to spread across the unit elements. * @param elements The control elements. */ private static _spreadMillisAcrossUnitElements; /** * Gets the type of the smallest unit element present in the specified elements array. * @param elements The control elements array. * @returns The type of the smallest unit element present in the specified elements array. */ private static _getSmallestUnitElementType; /** * Parse an array of duration control elements, either strings or unit input definitions, from the given props. * @param props The component props. * @returns An array of duration control elements, either strings or unit input definitions. */ private static _parseElementsFromProps; } export {};