update cloudflare context
This commit is contained in:
27
packages/ui/src/components/currency.tsx
Normal file
27
packages/ui/src/components/currency.tsx
Normal file
@@ -0,0 +1,27 @@
|
||||
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)
|
||||
}
|
||||
33
packages/ui/src/components/datetime.tsx
Normal file
33
packages/ui/src/components/datetime.tsx
Normal file
@@ -0,0 +1,33 @@
|
||||
import type { ComponentPropsWithoutRef } from 'react'
|
||||
|
||||
type DateTimeProps = {
|
||||
children: string
|
||||
options?: Intl.DateTimeFormatOptions
|
||||
locale?: string
|
||||
} & ComponentPropsWithoutRef<'time'>
|
||||
|
||||
export function DateTime({
|
||||
children,
|
||||
options,
|
||||
locale = 'pt-BR',
|
||||
...props
|
||||
}: DateTimeProps) {
|
||||
const optionsInit: Intl.DateTimeFormatOptions = {
|
||||
day: '2-digit',
|
||||
month: '2-digit',
|
||||
year: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit'
|
||||
}
|
||||
|
||||
const datetime = new Intl.DateTimeFormat(locale, {
|
||||
...optionsInit,
|
||||
...options
|
||||
})
|
||||
|
||||
return (
|
||||
<time dateTime={children} {...props}>
|
||||
{datetime.format(new Date(children))}
|
||||
</time>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user