GitHub

Currency Input

Input field for currency values with formatting.

Loading
Loading...
"use client";
 
import { useState } from "react";
 
import { CurrencyInput } from "@/components/ui/currency-input";
import { Label } from "@/components/ui/label";
 
export function CurrencyInputDemo() {
  const [monthlyPrice, setMonthlyPrice] = useState<string | undefined>("29.00");
  const [credit, setCredit] = useState<string | undefined>("100.00");
 
  return (
    <div className="grid w-full max-w-md gap-6">
      <div className="space-y-1">
        <p className="font-medium text-sm">Billing settings</p>
        <p className="text-muted-foreground text-sm">
          Configure workspace pricing and account credits.
        </p>
      </div>
 
      <div className="space-y-2">
        <Label htmlFor="monthly-price">Monthly price</Label>
        <CurrencyInput
          decimalSeparator="."
          decimalsLimit={2}
          groupSeparator=","
          id="monthly-price"
          name="monthlyPrice"
          onValueChange={(value) => setMonthlyPrice(value)}
          placeholder="Enter monthly price"
          prefix="$"
          value={monthlyPrice}
        />
        <p className="text-muted-foreground text-sm">
          Charged once per workspace each month.
        </p>
      </div>
    </div>
  );
}

Installation

npx shadcn@latest add "https://ui.blode.co/r/styles/default/currency-input"

Usage

import { CurrencyInput } from "@/components/ui/currency-input";
<CurrencyInput
  placeholder="Enter an amount"
  prefix="$"
  groupSeparator=","
  decimalSeparator="."
  decimalsLimit={2}
/>

Props

Currency Input extends react-currency-input-field with additional styling and clear/addon controls.

PropTypeDefaultDescription
classNamestring-Class name applied to the input.
clearClassNamestring-Class name applied to the clear button.
hasErrorbooleanfalseShows error state with a destructive border.
clearablebooleanfalseEnables a clear button when value is present.
onClear() => void-Callback fired when the clear button is clicked.
leftAddonReact.ReactNode-Content displayed before the input field.
rightAddonReact.ReactNode-Content displayed after the input field.
leftControlReact.ReactNode-Absolute-positioned control on the left.
rightControlReact.ReactNode-Absolute-positioned control on the right.
prefixstring-Prefix rendered before the numeric value.
suffixstring-Suffix rendered after the numeric value.
decimalsLimitnumber-Maximum number of decimal places allowed.
decimalSeparatorstring.Character used as the decimal separator.
groupSeparatorstring,Character used to group thousands.
valuestring | undefined-Controlled value.
defaultValuestring | undefined-Initial uncontrolled value.
onValueChange(value: string | undefined, name?: string) => void-Callback fired when value changes.