Overview
Get Started
Components
- Accordion
- Alert Dialog
- Alert
- Autocomplete
- Avatar
- Badge
- Button Group
- Button
- Calendar
- Checkbox Group
- Checkbox
- Collapsible
- Combobox
- Command
- Dialog
- Field
- Form
- Input Group
- Input
- Kbd
- Label
- Menu
- Meter
- Navigation Menu
- Number Field
- Number InputNew
- OTP Field
- Pagination
- Popover
- Radio Group
- Scroll Area
- Select
- Sheet
- Sidebar
- Slider
- Spinner
- Switch
- Table
- Tabs
- Textarea
- Tooltip
import { NumberField } from "@/components/ui/number-field";
export function NumberFieldDemo() {
return (
<div>
<label htmlFor="number-field" className="mb-2 inline-block font-medium">
Number Field
</label>
<NumberField id="number-field" placeholder="Enter a number" />
</div>
);
}Installation
pnpm dlx @zbmui/cli@latest add number-field
Usage
import { NumberField } from "@/components/ui/number-field";<NumberField />Example
Sizes
Pass the size prop to set the size of the NumberField. Available sizes are xs, sm, default, lg, and xl.
import { NumberField } from "@/components/ui/number-field";
export function NumberFieldDemo() {
return (
<div className="flex flex-col gap-4">
<NumberField placeholder="Enter a number" size="xs" />
<NumberField placeholder="Enter a number" size="sm" />
<NumberField placeholder="Enter a number" size="default" />
<NumberField placeholder="Enter a number" size="lg" />
<NumberField placeholder="Enter a number" size="xl" />
</div>
);
}Controlled
Your quantity: null
"use client";
import { useState } from "react";
import { NumberField } from "@/components/ui/number-field";
export function NumberFieldDemo() {
const [quantity, setQuantity] = useState<number | null>(null);
return (
<div>
<label htmlFor="quantity" className="mb-2 inline-block font-medium">
Quantity
</label>
<NumberField
id="quantity"
inputProps={{ className: "w-[calc(4ch+20px)]" }}
min={1}
max={100}
value={quantity}
onValueChange={setQuantity}
/>
<p className="mt-2 text-muted-foreground text-sm">Your quantity: {quantity ?? "null"}</p>
</div>
);
}Minimum and maximum value
Pass the min prop or max prop to set an upper and lower limit for the input. By default, the input will restrict the value to stay within the specified range.
function NumberFieldDemo() {
return <NumberField min={0} max={10} />;
}API Reference
NumberField Props
Component type props
Prop
Type
Default
Expand prop details
The size of the input component.
Type
'xs' | 'sm' | 'default' | 'lg' | 'xl'Default
'default'The placeholder text to display when the input is empty.
Type
string