CurrencyInput component is a specialized input field for monetary values that applies automatic formatting based on the currency's locale. It supports over 20 different currencies and offers real-time formatting as the user types.tsx
import { CurrencyInput } from "@arkyn/components";
name and locale property.tsx
<CurrencyInput name="price" locale="USD" />
locale property, which is mandatory. The value formatting will be applied automatically as the user types, following the standards of the specified currency. You can also set a maximum value using the max property.locale property is mandatory and defines the currency locale for formatting. Common examples include USD (US Dollar), EUR (Euro), and BRL (Brazilian Real).tsx
<CurrencyInputname="price-brl"locale="BRL"placeholder="Enter the value"leftIcon={TrendingUp}/>
max property allows you to set a maximum value that the user can enter. If the entered value exceeds this limit, it will not be reflected in the input.tsx
<CurrencyInputname="price-max"locale="USD"max={5000}label="Maximum: $5,000.00"leftIcon={Building}/>
md and lg, following the same pattern as the other input components.tsx
<CurrencyInputname="price-md"locale="USD"placeholder="Enter the amount"size="md"/><CurrencyInputname="price-lg"locale="USD"placeholder="Enter the amount"size="lg"/>
solid, outline, and underline, providing different visual styles.tsx
<CurrencyInputname="amount-solid"locale="BRL"placeholder="R$ 0.00"variant="solid"/><CurrencyInputname="amount-outline"locale="BRL"placeholder="R$ 0.00"variant="outline"/><CurrencyInputname="amount-underline"locale="BRL"placeholder="R$ 0.00"variant="underline"/>
R$
tsx
<CurrencyInputname="monthly-cost"label="Custo Mensal"locale="BRL"prefix="R$"placeholder="0,00"leftIcon={Calculator}/>
$
USD
tsx
<CurrencyInputname="annual-fee"label="Taxa Anual"locale="USD"prefix="$"suffix="USD"placeholder="0.00"leftIcon={Receipt}/>
tsx
<CurrencyInputname="disabled-with-value"label="Disabled amount"locale="USD"value={1000}disabledleftIcon={Banknote}/>
tsx
<CurrencyInputname="readonly-total"label="Calculated total"locale="BRL"value={15750.8}readOnlyleftIcon={Calculator}/>
rightIcon.tsx
<CurrencyInputname="loading-right"label="Processing payment..."locale="USD"placeholder="$0.00"rightIcon={CreditCard}isLoading/>
errorMessage property, it will take precedence over messages from the form provider.tsx
<CurrencyInputname="invalid-salary"label="Wage"locale="BRL"placeholder="R$ 0,00"errorMessage="Valor deve ser maior que R$ 1.000,00"leftIcon={DollarSign}showAsterisk/>
onChange callback differs from HTML's onChange; it provides three parameters for maximum flexibility:tsx
function handleCurrencyChange(event: ChangeEvent<HTMLInputElement>,originalValue: string,maskedValue: string) {// event - original event// originalValue - unformatted numeric value// maskedValue - formatted value with currency maskconsole.log("Original value:", originalValue); // "1500.50"console.log("Formatted value:", maskedValue); // "R$ 1,500.50"// Use originalValue for calculationsconst numericValue = Number(originalValue);// Use maskedValue for displaysetDisplayValue(maskedValue);}
name - string (required)
Name of the field for form manipulationlocale - Locale (required)
Currency locale for formatting (e.g., "USD", "EUR", "BRL", etc.)label - string
Label text to display above the inputerrorMessage - string
Error message to display below the inputisLoading - boolean (default: false)
Controls the loading state with a spinnersize - "md" | "lg" (default: "md")
Input sizevariant - "solid" | "outline" | "underline" (default:"solid"`)
Visual variant of the inputprefix - string | LucideIcon
Text or icon to display at the beginning of the inputsuffix - string | LucideIcon
Text or icon to display at the end of the inputshowAsterisk - boolean
Whether to display an asterisk in the label for required fieldsleftIcon - LucideIcon
Optional icon to display on the left siderightIcon - LucideIcon
Optional icon to display on the right sidemax - number
Maximum value allowed for the inputvalue - number
Controlled value (number) for the inputdefaultValue - number | null
Default value (number) for uncontrolled useonChange - (event, originalValue, maskedValue) => void
Callback function called when the value changes, receives the event, original value, and formatted value<input> are also supported, except type, max, defaultValue, value, and onChange, which are controlled by the component.type type is not supported because it is controlled by the mask.isLoading is true, input is automatically disabled.