21 lines
416 B
TypeScript
21 lines
416 B
TypeScript
|
import { JSX } from 'preact/jsx-runtime'
|
||
|
|
||
|
export const currencyFormat = new Intl.NumberFormat('en-US', {
|
||
|
style: 'currency',
|
||
|
currency: 'USD',
|
||
|
maximumFractionDigits: 2,
|
||
|
minimumFractionDigits: 2,
|
||
|
})
|
||
|
|
||
|
export function Currency(
|
||
|
{ amount, ...props }:
|
||
|
& { amount: number }
|
||
|
& JSX.HTMLAttributes<HTMLSpanElement>,
|
||
|
) {
|
||
|
return (
|
||
|
<span class='font-mono' {...props}>
|
||
|
{currencyFormat.format(amount)}
|
||
|
</span>
|
||
|
)
|
||
|
}
|