Amount Field

Web/Mobile

A labeled amount field with currency unit, description, and error. Values always display as Persian digits with thousand separators.

تومان
مبلغ را به تومان وارد کنید. ارقام به‌صورت خودکار گروه‌بندی می‌شوند.

Installation

pnpm dlx cubix-ui@latest add amount-field --base aria

Usage

Import
import {
  AmountField,
  AmountFieldControl,
  AmountFieldCurrency,
  AmountFieldDescription,
  AmountFieldInput,
  AmountFieldLabel,
} from "@/components/cubix/amount-field"
Example
<AmountField className="w-full max-w-sm">
  <AmountFieldLabel>مبلغ</AmountFieldLabel>
  <AmountFieldControl>
    <Icon data-icon="inline-start" />
    <AmountFieldInput defaultValue="۱۲۵۰۰۰۰" placeholder="۰" />
    <AmountFieldCurrency unit="تومان" />
  </AmountFieldControl>
  <AmountFieldDescription>
    مبلغ را به تومان وارد کنید. ارقام به‌صورت خودکار گروه‌بندی می‌شوند.
  </AmountFieldDescription>
</AmountField>

Composition

Same composition as Text Field, with AmountFieldCurrency for the unit.AmountFieldInput uses inputMode="numeric" with type="text", converts Latin digits, and inserts thousand separators as you type. Use parseAmountFieldValue when you need the numeric amount from the formatted string.

Structure
AmountField
├── AmountFieldLabel
├── AmountFieldControl
│   ├── Icon data-icon="inline-start" | "inline-end"
│   ├── AmountFieldInput
│   └── AmountFieldCurrency
├── AmountFieldDescription
└── AmountFieldError

Accessibility

Letters are blocked on insert and paste so the field stays numeric. AmountFieldDescription and AmountFieldError are announced through aria-describedby, and invalid sets aria-invalid on the input. When amountInWords is on, the spoken amount updates as the value changes.

Examples

Description

Add helper text below the input for format hints or guidance.

فقط عدد وارد کنید. جداکننده هزارگان به‌صورت خودکار اضافه می‌شود.

Amount in words

Set amountInWords on AmountFieldDescription to spell the amount in Persian. With تومان, words use ریال (×10); with ریال, words use تومان (÷10).

تومان
ریال

Currency

Place AmountFieldCurrency in the control with unit set to تومان or ریال.

تومان
ریال

Invalid

Set invalid on the root to apply destructive styles and show AmountFieldError.

تومان
یک مبلغ معتبر وارد کنید.

Disabled

Disable the field to block the input. The control uses a muted fill; label and description stay readable.

تومان
این فیلد فعلاً قابل ویرایش نیست.

Sizes

Two heights ship by default: default (40px) and lg (48px). Use className for any other size.

تومان
ارتفاع ۴۰ پیکسل
تومان
ارتفاع ۴۸ پیکسل

Icons

Place icons inside AmountFieldControl with data-icon like Button so spacing follows the reading direction.

تومان

In a form

Set name on the root so the value is submitted with the form, and pair the field with Cubix Button.

پرداخت

مبلغ قابل پرداخت را وارد کنید.

تومان
یک مبلغ معتبر به تومان وارد کنید.

Custom styling

Every part accepts a className merged with the shipped cn helper. Here the field uses a filled surface instead of the default outline.

با className می‌توانید ظاهر را سفارشی کنید.

API Reference

Note: Parts render data-slot attributes (amount-field, amount-field-label, amount-field-control, amount-field-input, amount-field-currency, amount-field-description, amount-field-error) for targeting in tests and parent selectors. Use the same props on Base UI, React Aria, and Radix.

AmountField

PropTypeDefaultDescription
size"default" | "lg""default"Height for the input: default 40px, lg 48px. Inherited by AmountFieldInput and AmountFieldControl unless overridden. Use className for other heights.
disabledbooleanfalseDisables the field and prevents interaction. Forwarded to the control on every base.
invalidbooleanfalseMarks the field as invalid and shows AmountFieldError when present.
namestring-Identifies the field when a form is submitted. Forwarded to the input on every base.
classNamestring-Additional Tailwind classes merged with the root styles (last one wins).

AmountFieldControl

PropTypeDefaultDescription
size"default" | "lg"-Overrides the size from AmountField. Icon inset and height match the default and lg sizes.
childrenReact.ReactNode-Wrap AmountFieldInput with icons marked data-icon="inline-start" or "inline-end" (same as Button), and optionally AmountFieldCurrency.
classNamestring-Additional Tailwind classes merged with the control styles (last one wins).

AmountFieldInput

PropTypeDefaultDescription
type"text""text"Always displays Persian digits (۰-۹) with thousand separators (٬). Latin digits typed or pasted are converted. Letters are blocked. inputMode is always numeric and spellCheck is always false.
size"default" | "lg"-Overrides the size from AmountField. Default 40px, lg 48px. Use className for other heights.
inputMode"numeric""numeric"Locked to numeric so mobile keyboards show a number pad.
placeholderstring-Hint text shown when the input is empty.
classNamestring-Additional Tailwind classes merged with the input styles (last one wins).
...propsOmit<React.ComponentProps<'input'>, 'type' | 'inputMode' | 'spellCheck'>-Native input attributes (value, onChange, name, required, ...) are forwarded. type, inputMode, and spellCheck stay locked for amount entry. Use parseAmountFieldValue to read a numeric amount from the formatted string.

AmountFieldCurrency

PropTypeDefaultDescription
unit"تومان" | "ریال"-Currency label beside the amount. Only تومان or ریال.
classNamestring-Additional Tailwind classes merged with the currency styles (last one wins).

AmountFieldLabel / Description / Error

PropTypeDefaultDescription
amountInWordsbooleanfalseOn AmountFieldDescription only. When true, spells the entered amount in Persian words. If the currency is تومان, words use ریال (×10); if ریال, words use تومان (÷10). When the input is empty, children are shown instead (or the description hides if there are none). Leave false for a normal static help text.
classNamestring-Additional Tailwind classes merged with the part styles (last one wins).
...propsHTML attributes-Native attributes for the rendered element are forwarded.