Atoms / Number input

Number input

A number with minus and plus buttons, read and written in the locale.

import { NumberInput } from "@forgeron/ui";
/01 → Stepper
import { NumberInput } from "@forgeron/ui";
import { useState } from "react";

export default function Stepper() {
  const [seats, setSeats] = useState<number | null>(5);
  return <NumberInput label="Seats" value={seats} onChange={setSeats} min={1} max={500} />;
}
/02 → Locale
kg
kg
import { NumberInput } from "@forgeron/ui";

export default function Locale() {
  return (
    <div style={{ display: "grid", gap: 8 }}>
      <NumberInput
        label="Weight, French"
        locale="fr-FR"
        suffix="kg"
        step={0.5}
        defaultValue={1234.5}
      />
      <NumberInput
        label="Weight, English"
        locale="en-US"
        suffix="kg"
        step={0.5}
        defaultValue={1234.5}
      />
      <NumberInput
        label="Discount"
        format={{ style: "percent" }}
        step={0.05}
        min={0}
        max={1}
        defaultValue={0.15}
      />
    </div>
  );
}
API → Props
PropTypeDefaultDescription
labelstring—Names the field for assistive technology.
value / defaultValuenumber | null—Controlled or not.
onChange(value: number | null) => void—On blur, Enter and every step.
min / maxnumber—Clamped on commit and on steps.
step / largeStepnumber1 / 10 × stepArrows and buttons; Page keys and Shift.
localestringthe device's`fr-FR` reads 1 234,5.
formatIntl.NumberFormatOptions—{ style: "percent" }, { maximumFractionDigits: 2 }.
prefix / suffixReactNode—A unit or a symbol inside the field.
buttonsbooleantrueThe minus and plus buttons.
readOnlyboolean—Shown, not editable.
disabledboolean—Not editable.
id / aria-describedby / aria-invalidstring / string / boolean—From `Field`'s function form: the label, hint and error stay tied.
classNamestring—Extra classes.