|
1
|
import { useState } from "react" |
|
2
|
import { CurrencyInput } from "@medusajs/ui" |
|
3
|
|
|
4
|
export default function CurrencyInputError() { |
|
5
|
const [value, setValue] = useState<string | undefined>("0") |
|
6
|
const [touched, setTouched] = useState(false) |
|
7
|
const isError = touched && (!value || parseFloat(value) <= 0) |
|
8
|
return ( |
|
9
|
<div className="max-w-[250px]"> |
|
10
|
<CurrencyInput |
|
11
|
symbol="$" |
|
12
|
code="usd" |
|
13
|
value={value} |
|
14
|
onValueChange={(val) => setValue(val)} |
|
15
|
aria-label="Amount" |
|
16
|
aria-invalid={isError} |
|
17
|
onBlur={() => setTouched(true)} |
|
18
|
min={0.01} |
|
19
|
/> |
|
20
|
{isError && ( |
|
21
|
<div className="mt-2 text-xs text-ui-fg-error"> |
|
22
|
Amount must be greater than 0 |
|
23
|
</div> |
|
24
|
)} |
|
25
|
</div> |
|
26
|
) |
|
27
|
} |