Number input
Number input component with plus and minus buttons, arrow keys, min and max, steps, decimals, prefix and suffix.
How to use it
Run npx @blossomui/react add number-input, or copy src/components/UI/NumberInput/NumberInput.tsx into your React project and import it.
import { NumberInput } from './components/ui/NumberInput'Props
NumberInputLabels
| Prop | Type | Description |
|---|---|---|
| decrease (required) | string | Accessible name of the button that lowers the number. |
| increase (required) | string | Accessible name of the button that raises the number. |
NumberInputProps
| Prop | Type | Description |
|---|---|---|
| labels | Partial<NumberInputLabels> | Texts of the component. Pass only the ones you want to change, for example to translate it. |
| required | boolean | Marks the field as required: an asterisk is shown next to the label. |
| color | string | Accent color of this component: any CSS color. Without it the component uses `--blossom-accent`, which is pink by default. |
| label | string | |
| hint | string | Helper text shown under the field. |
| error | string | Error message. Turns the field red. |
| success | string | Success message. Turns the field green. |
| value | number | null | Controlled value, `null` when the field is empty. Use together with `onChange`. |
| defaultValue | number | null | Initial value when the field is not controlled. |
| onChange | (value: number | null) => void | Called with the number, or `null` when the field is emptied. |
| min | number | |
| max | number | |
| step | number | How much the buttons and the arrow keys add or remove. Shift + arrow moves ten steps. |
| precision | number | Decimals to show. By default they follow the decimals of `step`. |
| prefix | string | Text shown before the number, such as "$". |
| suffix | string | Text shown after the number, such as "kg". |
| locale | string | Format the number with the thousands separator of this locale when the field loses focus. |
| placeholder | string | |
| name | string | Adds a name to the input so the number is sent with native forms. |
| disabled | boolean | |
| readOnly | boolean |