File size: 1.45 kB
import { FormatByte, Text } from "@chakra-ui/react"
export const FormatByteBasic = () => {
  return (
    <Text textStyle="lg">
      File size: <FormatByte value={1450.45} />
    </Text>
  )
}
import { FormatByte } from "@chakra-ui/react"<FormatByte value={1000} />The format functions works for any size of bytes.
50 byte
5 kB
5 MB
5 GB
import { FormatByte, Stack, Text } from "@chakra-ui/react"
export const FormatByteSizes = () => {
  return (
    <Stack>
      <Text textStyle="lg">
        <FormatByte value={50} />
      </Text>
      <Text textStyle="lg">
        <FormatByte value={5000} />
      </Text>
      <Text textStyle="lg">
        <FormatByte value={5000000} />
      </Text>
      <Text textStyle="lg">
        <FormatByte value={5000000000} />
      </Text>
    </Stack>
  )
}
Use the unit prop to change the byte format to bits.
File size: 1.45 kb
import { FormatByte, Text } from "@chakra-ui/react"
export const FormatByteWithUnit = () => {
  return (
    <Text textStyle="lg">
      File size: <FormatByte value={1450.45} unit="bit" />
    </Text>
  )
}
Wrap the FormatByte component within the LocaleProvider to change the
locale.
de-DE
1,45 kBzh-CN
1.45 kBimport { FormatByte, HStack, LocaleProvider, Text } from "@chakra-ui/react"
export const FormatByteWithLocale = () => {
  return (
    <Text textStyle="lg">
      <HStack>
        <Text fontWeight="medium">de-DE</Text>
        <LocaleProvider locale="de-DE">
          <FormatByte value={1450.45} />
        </LocaleProvider>
      </HStack>
      <HStack>
        <Text fontWeight="medium">zh-CN</Text>
        <LocaleProvider locale="zh-CN">
          <FormatByte value={1450.45} />
        </LocaleProvider>
      </HStack>
    </Text>
  )
}
Use the unitDisplay prop to change the byte format to compact notation.
50.3kB
50.3 kB
50.3 kilobytes
import { FormatByte, Stack, Text } from "@chakra-ui/react"
export const FormatByteWithUnitDisplay = () => {
  return (
    <Stack>
      <Text textStyle="lg">
        <FormatByte value={50345.53} unitDisplay="narrow" />
      </Text>
      <Text textStyle="lg">
        <FormatByte value={50345.53} unitDisplay="short" />
      </Text>
      <Text textStyle="lg">
        <FormatByte value={50345.53} unitDisplay="long" />
      </Text>
    </Stack>
  )
}
| Prop | Default | Type | 
|---|---|---|
| value * | numberThe byte size to format | |
| unit  | 'bit' | 'byte'The unit granularity to display | |
| unitDisplay  | 'long' | 'short' | 'narrow'The unit display |