Raw
1 import { useState } from "react"
2 import { CurrencyInput } from "@medusajs/ui"
3
4 export default function CurrencyInputControlled() {
5 const [value, setValue] = useState<string | undefined>("")
6 const formatValue = (val: string | undefined) => {
7 if (!val) {
8 return ""
9 }
10 return new Intl.NumberFormat("en-US", {
11 style: "currency",
12 currency: "USD",
13 }).format(parseFloat(val))
14 }
15 return (
16 <div className="max-w-[250px]">
17 <CurrencyInput
18 symbol="$"
19 code="usd"
20 value={value}
21 onValueChange={setValue}
22 aria-label="Amount"
23 />
24 <div className="mt-2 text-xs text-ui-fg-muted">
25 Value: {formatValue(value)}
26 </div>
27 </div>
28 )
29 }