import { NumberField } from '@base-ui/react/number-field' import { Minus, Plus } from 'lucide-react' import type { ReactNode } from 'react' import { cn } from '../lib/cn' import { controlBox, controlHeight, controlPaddingX, iconSize, type Size } from '../lib/styles' import { Field } from './Field' import { FIELD_BOX_DISABLED_INPUT, FIELD_BOX_RING_INPUT } from './featuredinput.tokens' import { NUMBER_ADDON, NUMBER_STEPPER, NUMBER_STEPPER_WIDTH } from './numberinput.tokens' export type NumberInputProps = { /** Visible label, linked to the input. */ label?: ReactNode /** Help text under the input. */ description?: ReactNode /** Error message; marks the input invalid and replaces `description`. */ error?: ReactNode /** Shows the required mark and requires a value. */ required?: boolean disabled?: boolean /** Shows the value but blocks changes. */ readOnly?: boolean size?: Size /** Lowest allowed value. Stepping clamps to it. */ min?: number /** Highest allowed value. Stepping clamps to it. */ max?: number /** Amount the buttons and arrow keys change the value by. Shift steps by 10×. */ step?: number value?: number | null defaultValue?: number | null /** Fires with the new number, or `null` when the input is cleared. */ onValueChange?: (value: number | null) => void /** How the value is displayed, e.g. `{ style: 'currency', currency: 'USD' }`. */ format?: Intl.NumberFormatOptions /** Locale for formatting and parsing. Defaults to the user's. */ locale?: Intl.LocalesArgument /** Text or element attached before the input, such as `$`. */ startAddon?: ReactNode /** Text or element attached after the input, such as `kg`. */ endAddon?: ReactNode /** Identifies the field in a form. */ name?: string /** Classes for the outer field wrapper. */ className?: string /** Classes for the input itself. */ inputClassName?: string } /** * A number field on Base UI NumberField: typing is parsed and formatted, * arrow keys and the − / + buttons step the value, and min / max clamp it. */ export function NumberInput({ label, description, error, required, disabled, readOnly, size = 'md', min, max, step = 1, value, defaultValue, onValueChange, format, locale, startAddon, endAddon, name, className, inputClassName, }: NumberInputProps) { return ( onValueChange(next) : undefined} min={min} max={max} step={step} format={format} locale={locale} required={required} disabled={disabled} readOnly={readOnly} className="w-full" > {startAddon != null && {startAddon}} {endAddon != null && {endAddon}} ) }