28 lines
502 B
TypeScript
28 lines
502 B
TypeScript
import type { ReactNode } from 'react'
|
|
|
|
type CurrencyProps = {
|
|
children: number
|
|
options?: Intl.NumberFormatOptions
|
|
locale?: string
|
|
currency?: string
|
|
}
|
|
|
|
export function Currency({
|
|
children,
|
|
options,
|
|
locale = 'pt-BR',
|
|
currency = 'BRL'
|
|
}: CurrencyProps): ReactNode {
|
|
const optionsInit: Intl.NumberFormatOptions = {
|
|
style: 'currency',
|
|
currency
|
|
}
|
|
|
|
const formatter = new Intl.NumberFormat(locale, {
|
|
...optionsInit,
|
|
...options
|
|
})
|
|
|
|
return formatter.format(children)
|
|
}
|