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

Progress 문서

원문 보기 위키 갱신

Progress는 작업이 얼마나 진행됐는지 완료 상태를 보여 주는 컴포넌트예요. 파일 업로드나 설치 상태처럼 점진적으로 채워지는 진행률을 표현할 때 딱 맞아요.

출처: 문서

본문

아래 예시에서는 파일 업로드 진행률을 Progress 바로 보여 줘요. 값이 시간에 따라 증가하면서 막대가 차오르는 모습을 확인할 수 있어요.

<script lang="ts">
  import { Progress } from "bits-ui";
  import { onMount } from "svelte";
  import { cubicInOut } from "svelte/easing";
  import { Tween } from "svelte/motion";
  const tween = new Tween(13, { duration: 1000, easing: cubicInOut });
  const labelId = $props.id();
  onMount(() => {
    const timer = setTimeout(() => tween.set(66), 500);
    return () => {
      clearTimeout(timer);
    };
  });
</script>
<div class="flex w-[60%] flex-col gap-2">
  <div class="flex items-center justify-between text-sm font-medium">
    <span id={labelId}> Uploading file... </span>
    <span>{Math.round(tween.current)}%</span>
  </div>
  <Progress.Root
    aria-labelledby={labelId}
    value={Math.round(tween.current)}
    max={100}
    class="bg-dark-10 shadow-mini-inset relative h-[15px] w-full overflow-hidden rounded-full"
  >
    <div
      class="bg-foreground shadow-mini-inset h-full w-full flex-1 rounded-full"
      style={`transform: translateX(-${100 - (100 * (tween.current ?? 0)) / 100}%)`}
    ></div>
  </Progress.Root>
</div>

겉모습은 비슷할 때가 많지만, Progress 바와 Meter는 서로 목적이 달라요.

Progress:

  • 작업의 완료 상태를 보여 줘요
  • 작업이 진행될수록 값만 커져요
  • 예시: 파일 업로드, 설치 상태, 폼 작성
  • 완료를 향한 진행 상황을 추적할 때 사용해요

Meter:

  • 정해진 범위(0-100) 안의 정적인 측정값을 보여 줘요
  • 실시간 측정에 따라 값이 위아래로 변할 수 있어요
  • 예시: CPU 사용량, 배터리 잔량, 음량
  • 현재 상태를 용량 대비로 보여 줄 때 사용해요

만약 요구 사항에 Meter가 더 어울린다면 Meter 컴포넌트를 확인해 보세요.

구조 (Structure)

Progress의 기본 구조는 Progress.Root 하나로 시작해요.

<script lang="ts">
  import { Progress } from "bits-ui";
</script>
<Progress.Root />

재사용 컴포넌트 (Reusable Components)

Progress 프리미티브로 애플리케이션 곳곳에서 쓸 수 있는 나만의 Progress 컴포넌트를 만드는 걸 권장해요. 아래 예시는 Progress 프리미티브로 더 풍성한 Progress 컴포넌트를 만든 모습이에요.

<script lang="ts">
  import { Progress, useId } from "bits-ui";
  import type { ComponentProps } from "svelte";
  let {
    max = 100,
    value = 0,
    min = 0,
    label,
    valueLabel,
  }: ComponentProps<typeof Progress.Root> & {
    label: string;
    valueLabel: string;
  } = $props();
  const labelId = useId();
</script>
<div>
  <span id={labelId}> {label} </span>
  <span>{valueLabel}</span>
</div>
<Progress.Root
  aria-labelledby={labelId}
  aria-valuetext={valueLabel}
  {value}
  {min}
  {max}
/>

그리고 만든 MyProgress 컴포넌트는 애플리케이션에서 이렇게 사용하면 돼요.

+page.svelte

<script lang="ts">
  import MyProgress from "$lib/components/MyProgress.svelte";
  let value = $state(50);
</script>
<MyProgress label="Loading images..." valueLabel="{value}%" {value} />

물론 실제로는 MyProgress 컴포넌트에 애플리케이션 디자인에 맞는 스타일과 커스터마이징을 더하고 싶을 거예요.

접근성 (Accessibility)

시각적인 라벨을 사용한다면 라벨 요소의 ID를 aria-labelledby prop으로 Progress.Root에 전달해야 해요. 시각적 라벨이 없다면 aria-label prop으로 프로그레스 바를 설명하는 텍스트를 넣어 줘야 해요.

API Reference

Progress.Root

The progress bar component.

Property Type Description Details
max number The maximum value of the progress bar.Default: 100
min number The minimum value of the progress bar.Default: 0
value number | null The current value of the progress bar. If set to null the progress bar will be indeterminate.Default: 0
ref $bindable HTMLDivElement The underlying DOM element being rendered. You can bind to this to get a reference to the element.Default: null
children Snippet The children content to render.Default: —— undefined
child Snippet - type SnippetProps = { props: Record<string, unknown>; }; Use render delegation to render your own element. See Child Snippet docs for more information.Default: —— undefined
Data Attribute Value Description Details
data-value '' The current value of the progress bar.
data-state enum - 'indeterminate' | 'determinate' The current state of the progress bar.
data-min '' The minimum value of the progress bar.
data-max '' The maximum value of the progress bar.
data-indeterminate '' Present when the value is null.
data-progress-root '' Present on the root element.

더 알아보기 (Learn more)

Progress는 작업의 완료 진행을 나타내는 용도라서, 현재 상태를 범위 안에서 보여 주는 Meter와는 쓰임새가 달라요. 어떤 컴포넌트를 쓸지는 상황에 따라 달라지므로, 둘 다 알아 두면 UI 요구 사항에 맞게 골라 쓸 수 있어요.