import clsx from "clsx"; import { forwardRef, ReactNode, Ref, RefObject, useId, useImperativeHandle, useRef } from "react"; import { useTranslation } from "react-i18next"; import HintTooltip from "~/components/ui/tooltips/HintTooltip"; import { NumberInput } from "~/ui/components/NumberInput"; export interface RefInputNumber { input: RefObject; } // type WithoutValue = {}; type WithDefaultValue = { defaultValue: number | undefined }; type WithValueAndSetValue = { value: number | undefined; setValue: React.Dispatch> }; type Props = (WithDefaultValue | WithValueAndSetValue) & { name?: string; title?: string; withLabel?: boolean; className?: string; help?: string; min?: number; max?: number; disabled?: boolean; readOnly?: boolean; required?: boolean; hint?: ReactNode; step?: string; placeholder?: string; icon?: string; borderless?: boolean; autoFocus?: boolean; canUnset?: boolean; }; const InputNumber = (props: Props, ref: Ref) => { const { t } = useTranslation(); const { name, title, withLabel = true, className, hint, help, disabled = false, readOnly = false, required = false, min = 0, max, step, placeholder, // icon — Subframe NumberInput has no left-icon slot; see note below. borderless, autoFocus, canUnset, } = props; const value = "value" in props ? props.value : undefined; const setValue = "setValue" in props ? props.setValue : undefined; const defaultValue = "defaultValue" in props ? props.defaultValue : undefined; useImperativeHandle(ref, () => ({ input })); const input = useRef(null); // Fall back to a generated id so the visible