shadcn.io is not affiliated with official shadcn/ui
Shadcn Format for React and Tailwind
Format numbers, bytes, and time with Intl API.
File size120 kB
Installation
bunx --bun shadcn@latest add https://kit.dev/r/format.jsonpnpm dlx shadcn@latest add https://kit.dev/r/format.jsonnpx shadcn@latest add https://kit.dev/r/format.jsonyarn shadcn@latest add https://kit.dev/r/format.jsonInstall the following dependencies:
bun add @ark-ui/reactpnpm add @ark-ui/reactnpm install @ark-ui/reactyarn add @ark-ui/reactCopy and paste the following code into your project.
"use client";
import { Format as ArkFormat } from "@ark-ui/react/format";
export const FormatByte = (
props: React.ComponentProps<typeof ArkFormat.Byte>
) => <ArkFormat.Byte data-slot="format-byte" {...props} />;
export const FormatNumber = (
props: React.ComponentProps<typeof ArkFormat.Number>
) => <ArkFormat.Number data-slot="format-number" {...props} />;
export const FormatRelativeTime = (
props: React.ComponentProps<typeof ArkFormat.RelativeTime>
) => <ArkFormat.RelativeTime data-slot="format-relative-time" {...props} />;Update the import paths to match your project setup.
Usage
import {
FormatByte,
FormatNumber,
FormatRelativeTime
} from "@/registry/react/components/format";<FormatByte value={120_000} />
<FormatNumber value={1234567} />
<FormatRelativeTime value={new Date("2025-05-05")} />Examples
Format Byte
Format byte values as file sizes.
Unit display
Use the unitDisplay prop to control how the unit is displayed.
Unit system
Use unitSystem to choose between decimal (1000 bytes) or binary (1024 bytes).
Format Relative Time
Format dates as relative time.
Style
Use the style prop for long, short, or narrow format.
Format Number
Format numbers with locale-aware options.
Currency
Use style="currency" with the currency prop for currency formatting.
Percentage
Use style="percent" to format numbers as percentages.
Compact notation
Use notation="compact" for compact display.
API Reference
FormatByte
| Prop | Type | Default |
|---|---|---|
value | number | - |
unit | "byte" | "bit" | "byte" |
unitDisplay | "long" | "short" | "narrow" | - |
unitSystem | "decimal" | "binary" | - |
locale | string | - |
FormatRelativeTime
| Prop | Type | Default |
|---|---|---|
value | Date | number | - |
numeric | "always" | "auto" | - |
style | "long" | "short" | "narrow" | - |
locale | string | - |
FormatNumber
| Prop | Type | Default |
|---|---|---|
value | number | - |
locale | string | - |
style | "decimal" | "percent" | "currency" | "unit" | "decimal" |
currency | string | - |
unit | string | - |
notation | "standard" | "compact" | "scientific" | "engineering" | "standard" |
minimumFractionDigits | number | - |
maximumFractionDigits | number | - |
For a complete list of props, see the Ark UI documentation.