본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

Format Byte

원문 보기 위키 갱신

Format Byte (바이트 포맷)

바이트 값을 다양한 옵션과 단위로 포맷하는 데 사용하는 컴포넌트예요. 자동 단위 변환과 표시 옵션을 포함해 바이트 특화된 포맷팅을 지원해 줘요.

출처: 문서

본문

사용법 (Usage)

바이트 포맷 컴포넌트는 숫자 포맷 기능을 확장해 자동 단위 변환과 표시 옵션을 포함한 바이트 특화 포맷팅을 처리해 줘요.

import { Format } from '@ark-ui/react'

예제 (Examples)

기본 (Basic)

Format.Byte 컴포넌트를 사용해 기본 옵션으로 바이트 값을 포맷해 보세요.

import { Format } from '@ark-ui/react/format'
import styles from 'styles/format.module.css'

export const ByteBasic = () => {
  return (
    <div className={styles.Root}>
      <span className={styles.Label}>File size</span>
      <span className={styles.Value}>
        <Format.Byte value={120000} />
      </span>
    </div>
  )
}

크기 (Sizes)

sizes prop을 사용해 포맷에 사용할 커스텀 바이트 크기를 지정할 수 있어요.

import { Format } from '@ark-ui/react/format'
import styles from 'styles/format.module.css'

export const ByteSizes = () => {
  const byteSizes = [50, 5000, 5000000, 5000000000]

  return (
    <div className={styles.List}>
      {byteSizes.map((size) => (
        <div key={size} className={styles.ListItem}>
          <span className={styles.Value}>
            <Format.Byte value={size} />
          </span>
        </div>
      ))}
    </div>
  )
}

로케일 (Locale)

locale prop을 사용해 바이트 값을 특정 로케일에 맞게 포맷할 수 있어요.

import { Format } from '@ark-ui/react/format'
import { LocaleProvider } from '@ark-ui/react/locale'
import styles from 'styles/format.module.css'

export const ByteWithLocale = () => {
  const locales = ['de-DE', 'zh-CN']

  return (
    <div className={styles.List}>
      {locales.map((locale) => (
        <LocaleProvider key={locale} locale={locale}>
          <div className={styles.ListItem}>
            <span className={styles.InlineLabel}>{locale}:</span>
            <span className={styles.Value}>
              <Format.Byte value={1450.45} />
            </span>
          </div>
        </LocaleProvider>
      ))}
    </div>
  )
}

단위 (Unit)

unit prop을 사용해 바이트 값의 단위를 지정할 수 있어요.

import { Format } from '@ark-ui/react/format'
import styles from 'styles/format.module.css'

export const ByteWithUnit = () => {
  return (
    <div className={styles.Inline}>
      <span className={styles.InlineLabel}>File size:</span>
      <span className={styles.InlineValue}>
        <Format.Byte value={1450.45} unit="bit" />
      </span>
    </div>
  )
}

단위 표시 (Unit Display)

unitDisplay prop을 사용해 단위의 표시 방식을 지정할 수 있어요.

import { Format } from '@ark-ui/react/format'
import styles from 'styles/format.module.css'

export const ByteWithUnitDisplay = () => {
  const unitDisplays = ['narrow', 'short', 'long'] as const

  return (
    <div className={styles.List}>
      {unitDisplays.map((unitDisplay) => (
        <div key={unitDisplay} className={styles.ListItem}>
          <span className={styles.InlineLabel}>{unitDisplay}:</span>
          <span className={styles.Value}>
            <Format.Byte value={50345.53} unitDisplay={unitDisplay} />
          </span>
        </div>
      ))}
    </div>
  )
}

단위 체계 (Unit System)

unitSystem prop을 사용해 십진(1000바이트) 또는 이진(1024바이트) 단위 체계 중 무엇을 사용할지 지정할 수 있어요.

import { Format } from '@ark-ui/react/format'
import styles from 'styles/format.module.css'

export const ByteWithUnitSystem = () => {
  return (
    <div className={styles.List}>
      <div className={styles.ListItem}>
        <span className={styles.InlineLabel}>Decimal (1000 bytes):</span>
        <span className={styles.InlineValue}>
          <Format.Byte value={1024} unitSystem="decimal" />
        </span>
      </div>
      <div className={styles.ListItem}>
        <span className={styles.InlineLabel}>Binary (1024 bytes):</span>
        <span className={styles.InlineValue}>
          <Format.Byte value={1024} unitSystem="binary" />
        </span>
      </div>
    </div>
  )
}

더 알아보기 (Learn more)