FormatDuration

Data Display

ISO-8601 duration을 로케일에 맞춰 표시하는 Format 컴포넌트.

Usage

ISO-8601 기간 값을 시간·분 같은 읽기 쉬운 로케일 문자열로 표시할 때 사용한다.

import

import

import { FormatDuration } from '@mildang/design-system/Format';

API Reference

FormatDuration Props

Prop

Type

Default

fallback

string

지정 안 함

locale

string

지정 안 함

style

"narrow" | "short" | "long" | "digital"

지정 안 함

value

string

지정 안 함

같은 패밀리

@mildang/design-system/Format 에서 같이 내보내는 컴포넌트다.

예제

Default

import type { ComponentProps } from 'react';
import { FormatDuration } from '@mildang/design-system/Format';

const STORY_DEFAULT_ARGS = { ...({}), ...({
    value: 'PT50M',
    style: 'short',
    locale: 'ko-KR',
  }) } as ComponentProps<typeof FormatDuration>;

const FormatDurationDefaultExampleRender = (args: ComponentProps<typeof FormatDuration>) => <FormatDuration {...args} />;

export default function FormatDurationDefaultExample(props: Partial<ComponentProps<typeof FormatDuration>>) {
  const mergedProps = { ...STORY_DEFAULT_ARGS, ...props } as ComponentProps<typeof FormatDuration>;
  return FormatDurationDefaultExampleRender(mergedProps);
}

HourAndMinute

import type { ComponentProps } from 'react';
import { FormatDuration } from '@mildang/design-system/Format';

const STORY_DEFAULT_ARGS = { ...({}), ...({
    value: 'PT1H20M',
    style: 'short',
    locale: 'ko-KR',
  }) } as ComponentProps<typeof FormatDuration>;

const FormatDurationHourAndMinuteExampleRender = (args: ComponentProps<typeof FormatDuration>) => <FormatDuration {...args} />;

export default function FormatDurationHourAndMinuteExample(props: Partial<ComponentProps<typeof FormatDuration>>) {
  const mergedProps = { ...STORY_DEFAULT_ARGS, ...props } as ComponentProps<typeof FormatDuration>;
  return FormatDurationHourAndMinuteExampleRender(mergedProps);
}

EnglishLocale

import type { ComponentProps } from 'react';
import { FormatDuration } from '@mildang/design-system/Format';

const STORY_DEFAULT_ARGS = { ...({}), ...({
    value: 'PT1H20M',
    style: 'short',
    locale: 'en-US',
  }) } as ComponentProps<typeof FormatDuration>;

const FormatDurationEnglishLocaleExampleRender = (args: ComponentProps<typeof FormatDuration>) => <FormatDuration {...args} />;

export default function FormatDurationEnglishLocaleExample(props: Partial<ComponentProps<typeof FormatDuration>>) {
  const mergedProps = { ...STORY_DEFAULT_ARGS, ...props } as ComponentProps<typeof FormatDuration>;
  return FormatDurationEnglishLocaleExampleRender(mergedProps);
}

InvalidValue

import type { ComponentProps } from 'react';
import { FormatDuration } from '@mildang/design-system/Format';

const STORY_DEFAULT_ARGS = { ...({}), ...({
    value: 'invalid-duration',
    fallback: '-',
  }) } as ComponentProps<typeof FormatDuration>;

const FormatDurationInvalidValueExampleRender = (args: ComponentProps<typeof FormatDuration>) => <FormatDuration {...args} />;

export default function FormatDurationInvalidValueExample(props: Partial<ComponentProps<typeof FormatDuration>>) {
  const mergedProps = { ...STORY_DEFAULT_ARGS, ...props } as ComponentProps<typeof FormatDuration>;
  return FormatDurationInvalidValueExampleRender(mergedProps);
}