Number Field

A Number Field component is a UI element that allows users to enter and adjust numeric values using increment and decrement buttons or direct input. It supports features like min/max constraints, step values, and number formatting.

Demo

Rendered live, with the same build of the library you install.

Basic:

Currency:

Usage

NumberField.tsx
import { useState } from 'react';
import { NNumberField } from '@nayan-ui/react';
const NumberField = () => {
const [quantity, setQuantity] = useState(1);
const [price, setPrice] = useState(9.99);
return (
<div>
<div className="space-y-4 max-w-sm">
<h3 className="text-foreground mb-2 mt-4 text-sm font-semibold">Basic:</h3>
<NNumberField value={quantity} onChange={setQuantity} minValue={0} maxValue={100} aria-label="Quantity" />
<h3 className="text-foreground mb-2 mt-4 text-sm font-semibold">Currency:</h3>
<NNumberField
value={price}
onChange={setPrice}
minValue={0}
step={0.01}
formatOptions={{ style: 'currency', currency: 'USD' }}
aria-label="Price"
/>
</div>
</div>
);
};
export default NumberField;

Attributes

13 props
NameTypeDefaultDetails
valuenumberOptionalControlled value.
defaultValuenumberOptionalDefault value.
onChange(value: number) => voidOptionalCallback when value changes.
minValuenumberOptionalMinimum value.
maxValuenumberOptionalMaximum value.
stepnumber1Step increment.
disabledbooleanfalseDisables the field.
isInvalidbooleanfalseMarks as invalid.
variant'primary' | 'secondary''primary'Visual variant.
fullWidthbooleanfalseFull width mode.
formatOptionsIntl.NumberFormatOptionsOptionalNumber format options (currency, percent, etc).
classNamestring' 'Additional CSS classes.
labelstringOptionalLabel text for the number field.

Tags

Other components solving nearby problems.