import { type FormEvent, type KeyboardEvent as ReactKeyboardEvent, type RefObject } from 'react'; import type { AriaLabelingProps, DataTestId, StylingProps } from '@dynatrace/strato-components/core'; import type { FormControlProps } from '../../../core/types/form-control-props.js'; import type { SpinButtonTextSelection } from '../types.js'; /** @internal */ export type TextSpinButtonProps = FormControlProps void> & StylingProps & DataTestId & AriaLabelingProps & { /** List of options of the current text spin button. */ options: string[]; /** * Callback transformer to modify the value index on ArrowUp. * @param index - Current index of the selected value. * @param e - Details about the keyboard event. * @returns New index. * @defaultValue `(i) => i-1` */ onArrowUp?: (index: number, e: FormEvent) => number; /** * Callback transformer to modify the value index on ArrowDown. * @param index - Current index of the selected value. * @param e - Details about the keyboard event. * @returns New index. * @defaultValue `(i) => i+1` */ onArrowDown?: (index: number, e: FormEvent) => number; /** * Callback transformer to modify the value index on PageUp. * @param index - Current index of the selected value. * @param e - Details about the keyboard event. * @returns New index. * @defaultValue `(i) => i-5` */ onPageUp?: (index: number, e: FormEvent) => number; /** * Callback transformer to modify the value index on PageDown. * @param index - Current index of the selected value. * @param e - Details about the keyboard event. * @returns New index. * @defaultValue `(i) => i+5` */ onPageDown?: (index: number, e: FormEvent) => number; /** * Callback transformer to modify the value index on Home. * @param index - Current index of the selected value. * @param e - Details about the keyboard event. * @returns New index. * @defaultValue `(i) => 0` */ onHome?: (index: number, e: FormEvent) => number; /** * Callback transformer to modify the value index on End. * @param index - Current index of the selected value. * @param e - Details about the keyboard event. * @returns New index. * @defaultValue `(i) => options.lenght-1` */ onEnd?: (index: number, e: FormEvent) => number; /** * Placeholder to show if no value is selected. * @defaultValue '' */ placeholder?: string; /** * Whether the spinbutton is in readonly mode. * @defaultValue false */ readOnly?: boolean; /** * Whether the spinbutton is disabled. * @defaultValue false */ disabled?: boolean; /** * Whether a spinbutton value is required. * @defaultValue false */ required?: boolean; /** * Determine if the spinbutton is in error state or not. * @defaultValue false */ hasError?: boolean; /** * Callback transformer to modify the value on key press. */ onKeyDownHandler?: (e: ReactKeyboardEvent) => void; }; /** * Imperative handler to give access to the root span element of the spinbutton. * It provides additional methods to interact with the spinbutton. * @internal */ export interface TextSpinButtonRef { /** Type of the spinbutton. */ type: 'text'; /** A ref to the root span element of the spinbutton. */ readonly element: RefObject; /** Set cursor selection within the spinbutton. */ setSelection: (selection: SpinButtonTextSelection) => void; /** Get current cursor selection if the spinbutton has focus. Returns `undefined` otherwise. */ getSelection: () => SpinButtonTextSelection | undefined; /** Select all text content within the spinbutton. */ selectAll: () => void; /** Deselect any text selecton. */ deselectAll: () => void; /** Case insensitive value lookup. First value starting with `firstChar` is selected. Ignored if no value can be found.*/ searchValue: (firstChar: string, fireOnChange?: boolean) => void; /** Clear the text content of the spinbutton. */ clearValue: (fireOnChange?: boolean) => void; /** Calls the onChange. */ onChange: ((value: string | null) => void) | undefined; }