import React from 'react'; import { NumberInput as CoreNumberInput } from '@shoptet/ui-core-web'; import { NumberInputDecrementButton } from './NumberInputDecrementButton'; import { NumberInputIncrementButton } from './NumberInputIncrementButton'; import { NumberInputInput } from './NumberInputInput'; import type { NumberInputProps } from './types'; export type { NumberInputProps, NumberInputInputProps, NumberInputIncrementButtonProps, NumberInputDecrementButtonProps, } from './types'; function toNumber(value: number | string | undefined): number | undefined { const parsedNumber = parseFloat(value?.toString() ?? ''); return value === undefined || isNaN(parsedNumber) ? undefined : parsedNumber; } /** * A locale-aware number input. * * Standalone it renders a single styled field: ``. * * To build a stepper, provide children and compose the sub-components — each auto-wires to the * value through context (see `CounterInput`): * * ```tsx * * * * * * ``` */ export const NumberInput = Object.assign( ({ value, defaultValue, min, max, step, disabled, onChange, onBlur, onFocus, children, ref, ...fieldProps }: NumberInputProps) => ( {typeof children === 'function' ? children : () => children ?? } ), { displayName: 'NumberInput', Input: NumberInputInput, IncrementButton: NumberInputIncrementButton, DecrementButton: NumberInputDecrementButton, } );