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

프로그레스

원문 보기 위키 갱신

프로그레스 (Progress)

오래 걸리는 작업의 상태를 표시하는 고품질의 비스타일 React 프로그레스 바 컴포넌트예요. 불확정(indeterminate) 상태와 접근 가능한 텍스트 표시까지 지원해요.

출처: Base UI 프로그레스

본문

오래 걸리는 작업의 상태를 표시하는 고품질의 비스타일 React 프로그레스 바 컴포넌트예요.

데모

Tailwind

이 예시는 Tailwind CSS로 컴포넌트를 구현하는 방법을 보여줘요.

/* index.tsx */
'use client';
import * as React from 'react';
import { Progress } from '@base-ui/react/progress';

export default function ExampleProgress() {
  const [value, setValue] = React.useState(20);

  // Simulate changes
  React.useEffect(() => {
    const interval = setInterval(() => {
      setValue((current) => Math.min(100, Math.round(current + Math.random() * 25)));
    }, 1000);
    return () => clearInterval(interval);
  }, []);

  return (
    <Progress.Root className="grid max-w-full w-60 grid-cols-2 gap-y-2" value={value}>
      <Progress.Label className="text-sm font-normal text-neutral-950 dark:text-white">
        Export data
      </Progress.Label>
      <Progress.Value className="text-right text-sm text-neutral-950 dark:text-white" />
      <Progress.Track className="col-span-2 h-1 overflow-hidden bg-neutral-200 dark:bg-neutral-800">
        <Progress.Indicator className="bg-neutral-950 transition-[width] duration-500 dark:bg-white" />
      </Progress.Track>
    </Progress.Root>
  );
}

CSS Modules

이 예시는 CSS Modules로 컴포넌트를 구현하는 방법을 보여줘요.

/* index.module.css */
.Progress {
  display: grid;
  grid-template-columns: 1fr 1fr;
  row-gap: 0.5rem;
  width: 15rem;
  max-width: 100%;
}

.Label {
  font-size: 0.875rem;
  line-height: 1.25rem;
  font-weight: 400;
  color: oklch(14.5% 0 0deg);

  @media (prefers-color-scheme: dark) {
    color: white;
  }
}

.Value {
  font-size: 0.875rem;
  line-height: 1.25rem;
  color: oklch(14.5% 0 0deg);
  text-align: right;

  @media (prefers-color-scheme: dark) {
    color: white;
  }
}

.Track {
  grid-column: 1 / 3;
  overflow: hidden;
  height: 0.25rem;
  background-color: oklch(92.2% 0 0deg);

  @media (prefers-color-scheme: dark) {
    background-color: oklch(26.9% 0 0deg);
  }
}

.Indicator {
  background-color: oklch(14.5% 0 0deg);
  transition: width 500ms;

  @media (prefers-color-scheme: dark) {
    background-color: white;
  }
}
/* index.tsx */
'use client';
import * as React from 'react';
import { Progress } from '@base-ui/react/progress';
import styles from './index.module.css';

export default function ExampleProgress() {
  const [value, setValue] = React.useState(20);

  // Simulate changes
  React.useEffect(() => {
    const interval = setInterval(() => {
      setValue((current) => Math.min(100, Math.round(current + Math.random() * 25)));
    }, 1000);
    return () => clearInterval(interval);
  }, []);

  return (
    <Progress.Root className={styles.Progress} value={value}>
      <Progress.Label className={styles.Label}>Export data</Progress.Label>
      <Progress.Value className={styles.Value} />
      <Progress.Track className={styles.Track}>
        <Progress.Indicator className={styles.Indicator} />
      </Progress.Track>
    </Progress.Root>
  );
}

구조 (Anatomy)

컴포넌트를 임포트하고 파트를 조립해요.

import { Progress } from '@base-ui/react/progress';

<Progress.Root>
  <Progress.Label />
  <Progress.Track>
    <Progress.Indicator />
  </Progress.Track>
  <Progress.Value />
</Progress.Root>;

API 레퍼런스

Root

프로그레스 바의 모든 파트를 묶고 작업 완료 상태를 스크린 리더에 제공해요. <div> 요소를 렌더링해요.

Root Props:

Prop Type Default Description
value* number | null - 현재 값. value가 null이면 컴포넌트는 불확정(indeterminate) 상태가 돼요.
aria-valuetext string - 프로그레스 바의 현재 값인 aria-valuenow에 사용자 친화적인 이름을 제공하는 문자열 값.
getAriaValueText ((formattedValue: string, value: number | null) => string) - 프로그레스 바의 현재 값에 대한 사람이 읽을 수 있는 텍스트 대안을 반환하는 함수를 받아요.
locale Intl.LocalesArgument - 값 형식화 시 Intl.NumberFormat이 사용하는 로케일. 기본값은 사용자 런타임 로케일이에요.
min number 0 최소값.
max number 100 최대값.
format Intl.NumberFormatOptions - 값을 형식화할 옵션.
className string | ((state: Progress.Root.State) => string | undefined) - 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태에 따라 클래스를 반환하는 함수.
style React.CSSProperties | ((state: Progress.Root.State) => React.CSSProperties | undefined) - 요소에 적용되는 스타일, 또는 컴포넌트 상태에 따라 스타일 객체를 반환하는 함수.
render ReactElement | ((props: HTMLProps, state: Progress.Root.State) => ReactElement) - 컴포넌트의 HTML 요소를 다른 태그로 대체하거나 다른 컴포넌트와 합성할 수 있게 해줘요. ReactElement 또는 렌더링할 요소를 반환하는 함수를 받아요.

Root Data Attributes:

Attribute Type Description
data-complete - 진행이 완료되었을 때 존재해요.
data-indeterminate - 진행이 불확정 상태일 때 존재해요.
data-progressing - 진행 중일 때 존재해요.

Root.Props

Root props의 재내보내기예요.

Root.State

type ProgressRootState = {
  /** The current status. */
  status: Progress.Status;
};

Value

현재 값을 표시하는 텍스트 요소예요. <span> 요소를 렌더링해요.

Value Props:

Prop Type Default Description
children ((formattedValue: string | null, value: number | null) => React.ReactNode) | null - -
className string | ((state: Progress.Value.State) => string | undefined) - 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태에 따라 클래스를 반환하는 함수.
style React.CSSProperties | ((state: Progress.Value.State) => React.CSSProperties | undefined) - 요소에 적용되는 스타일, 또는 컴포넌트 상태에 따라 스타일 객체를 반환하는 함수.
render ReactElement | ((props: HTMLProps, state: Progress.Value.State) => ReactElement) - 컴포넌트의 HTML 요소를 다른 태그로 대체하거나 다른 컴포넌트와 합성할 수 있게 해줘요. ReactElement 또는 렌더링할 요소를 반환하는 함수를 받아요.

Value Data Attributes:

Attribute Type Description
data-complete - 진행이 완료되었을 때 존재해요.
data-indeterminate - 진행이 불확정 상태일 때 존재해요.
data-progressing - 진행 중일 때 존재해요.

Value.Props

Value props의 재내보내기예요.

Value.State

type ProgressValueState = {
  /** The current status. */
  status: Progress.Status;
};

Indicator

작업의 완료 상태를 시각화해요. <div> 요소를 렌더링해요.

Indicator Props:

Prop Type Default Description
className string | ((state: Progress.Indicator.State) => string | undefined) - 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태에 따라 클래스를 반환하는 함수.
style React.CSSProperties | ((state: Progress.Indicator.State) => React.CSSProperties | undefined) - 요소에 적용되는 스타일, 또는 컴포넌트 상태에 따라 스타일 객체를 반환하는 함수.
render ReactElement | ((props: HTMLProps, state: Progress.Indicator.State) => ReactElement) - 컴포넌트의 HTML 요소를 다른 태그로 대체하거나 다른 컴포넌트와 합성할 수 있게 해줘요. ReactElement 또는 렌더링할 요소를 반환하는 함수를 받아요.

Indicator Data Attributes:

Attribute Type Description
data-complete - 진행이 완료되었을 때 존재해요.
data-indeterminate - 진행이 불확정 상태일 때 존재해요.
data-progressing - 진행 중일 때 존재해요.

Indicator.Props

Indicator props의 재내보내기예요.

Indicator.State

type ProgressIndicatorState = {
  /** The current status. */
  status: Progress.Status;
};

Track

프로그레스 바 인디케이터를 담아요. <div> 요소를 렌더링해요.

Track Props:

Prop Type Default Description
className string | ((state: Progress.Track.State) => string | undefined) - 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태에 따라 클래스를 반환하는 함수.
style React.CSSProperties | ((state: Progress.Track.State) => React.CSSProperties | undefined) - 요소에 적용되는 스타일, 또는 컴포넌트 상태에 따라 스타일 객체를 반환하는 함수.
render ReactElement | ((props: HTMLProps, state: Progress.Track.State) => ReactElement) - 컴포넌트의 HTML 요소를 다른 태그로 대체하거나 다른 컴포넌트와 합성할 수 있게 해줘요. ReactElement 또는 렌더링할 요소를 반환하는 함수를 받아요.

Track Data Attributes:

Attribute Type Description
data-complete - 진행이 완료되었을 때 존재해요.
data-indeterminate - 진행이 불확정 상태일 때 존재해요.
data-progressing - 진행 중일 때 존재해요.

Track.Props

Track props의 재내보내기예요.

Track.State

type ProgressTrackState = {
  /** The current status. */
  status: Progress.Status;
};

Label

프로그레스 바를 위한 접근 가능한 레이블이에요. <span> 요소를 렌더링해요.

Label Props:

Prop Type Default Description
className string | ((state: Progress.Label.State) => string | undefined) - 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태에 따라 클래스를 반환하는 함수.
style React.CSSProperties | ((state: Progress.Label.State) => React.CSSProperties | undefined) - 요소에 적용되는 스타일, 또는 컴포넌트 상태에 따라 스타일 객체를 반환하는 함수.
render ReactElement | ((props: HTMLProps, state: Progress.Label.State) => ReactElement) - 컴포넌트의 HTML 요소를 다른 태그로 대체하거나 다른 컴포넌트와 합성할 수 있게 해줘요. ReactElement 또는 렌더링할 요소를 반환하는 함수를 받아요.

Label Data Attributes:

Attribute Type Description
data-complete - 진행이 완료되었을 때 존재해요.
data-indeterminate - 진행이 불확정 상태일 때 존재해요.
data-progressing - 진행 중일 때 존재해요.

Label.Props

Label props의 재내보내기예요.

Label.State

type ProgressLabelState = {
  /** The current status. */
  status: Progress.Status;
};

추가 타입 (Additional Types)

Progress.Status

type ProgressStatus = 'indeterminate' | 'progressing' | 'complete';

내보내기 그룹 (Export Groups)

  • Progress.Root: Progress.Root, Progress.Root.State, Progress.Root.Props
  • Progress.Track: Progress.Track, Progress.Track.State, Progress.Track.Props
  • Progress.Indicator: Progress.Indicator, Progress.Indicator.State, Progress.Indicator.Props
  • Progress.Value: Progress.Value, Progress.Value.State, Progress.Value.Props
  • Progress.Label: Progress.Label, Progress.Label.State, Progress.Label.Props
  • Default: Progress.Status, ProgressStatus, ProgressRootState, ProgressRootProps, ProgressIndicatorState, ProgressIndicatorProps, ProgressLabelState, ProgressLabelProps, ProgressTrackState, ProgressTrackProps, ProgressValueState, ProgressValueProps

Canonical Types

Canonical: Alias 매핑 — Canonical의 네임스페이스가 이미 임포트되어 있으면 Canonical을, 아니면 Alias를 사용하세요.

  • Progress.Root.State: ProgressRootState
  • Progress.Root.Props: ProgressRootProps
  • Progress.Track.State: ProgressTrackState
  • Progress.Track.Props: ProgressTrackProps
  • Progress.Indicator.State: ProgressIndicatorState
  • Progress.Indicator.Props: ProgressIndicatorProps
  • Progress.Value.State: ProgressValueState
  • Progress.Value.Props: ProgressValueProps
  • Progress.Label.State: ProgressLabelState
  • Progress.Label.Props: ProgressLabelProps
  • Progress.Status: ProgressStatus

더 알아보기 (Learn more)