UNPKG

@payfit/unity-components

Version:

74 lines (73 loc) • 3.01 kB
import { ReactNode } from 'react'; import { LabelProps } from '../../../../core/components/label/Label.js'; import { NumberInputProps } from '../number-input/NumberInput.js'; /** * Base props shared by the NumberField, including label and field adornments. * Inherits `isRequired` and `requiredVariant` from {@link LabelProps} to control * the required indicator in the label. */ export interface FieldProps extends Pick<LabelProps, 'isRequired' | 'requiredVariant'> { /** The plain-text label associated with the number input (required for a11y). */ label: string; /** Optional helper text displayed above the control to guide the user. */ helperText?: ReactNode; /** Optional contextual link rendered below the control for additional info. */ contextualLink?: ReactNode; } /** * Props for {@link NumberField}. * * Combines field chrome (label, helper/contextual link, feedback) with the * input behavior from {@link NumberInput}. All value/validation aspects * are handled by the Form field context, so you should not pass `name`, * `value`, `defaultValue`, or `isInvalid` here. */ export type NumberFieldProps = FieldProps & NumberInputProps; /** * NumberField renders a complete number field for forms: * label, helper text, the numeric input itself, feedback message, and an * optional contextual link. * * Behavior * - Integrates with the Form field via `<form.AppField name="…">`. * - Uses {@link NumberInput} for the numeric control and forwards visual * props such as `withControls`, `minValue`, `maxValue`, `step`, `formatOptions`, * `prefix`, `suffix`, and state props (`isReadOnly`, `isDisabled`, `isLoading`). * - Invalid state is derived from the field meta (touched + !isValid) and is * displayed through the underlying input and feedback area. * * Accessibility * - The surrounding {@link FormField} provides `aria-labelledby`, * `aria-describedby` (helper/feedback), and `aria-details` wiring so the input * is fully accessible out of the box. * * Example * ```tsx * import { useUnityForm } from "../../hooks/use-form.js" * import { NumberField } from "@/components/number-field/NumberField" * * const form = useUnityForm<{ amount: number }>({ validators: {} }) * * <form.AppForm> * <form.Form> * <form.AppField name="amount"> * {() => ( * <NumberField * label="Amount" * withControls * minValue={0} * step={5} * helperText="Enter a positive amount" * /> * )} * </form.AppField> * </form.Form> * </form.AppForm> * ``` * @see NumberInput for the underlying numeric control * @see FormField for the a11y and layout context * @see useUnityForm to create a form and field context * @returns A composite field bound to the current form field */ declare const NumberField: import('react').ForwardRefExoticComponent<FieldProps & NumberInputProps & import('react').RefAttributes<HTMLInputElement>>; export { NumberField };