프로그레스(Progress)
시간에 따른 작업의 진행률을 결정적(determinate) 또는 비결정적(indeterminate) 형태로 보여주는 컴포넌트예요.
출처: 문서
본문
Import
import { Progress } from "@kobalte/core/progress";
// or
import { Root, Label, ... } from "@kobalte/core/progress";
// or (deprecated)
import { Progress } from "@kobalte/core";
Features
- ARIA를 통해 보조 기술에 프로그레스 바로 노출돼요.
- 접근성을 위한 라벨링을 지원해요.
- 백분율 또는 값으로 다국어 숫자 포맷팅을 지원해요.
- 결정적(determinate) 및 비결정적(indeterminate) 진행률을 모두 지원해요.
Anatomy
프로그레스는 다음 요소들로 구성돼요:
- Progress: 프로그레스 바의 루트 컨테이너예요.
- Progress.Label: 진행 상황에 대한 정보를 사용자에게 주는 접근 가능한 라벨이에요.
- Progress.ValueLabel: 현재 값을 사람이 읽을 수 있는 형식으로 나타내는 접근 가능한 라벨 텍스트예요.
- Progress.Track: 프로그레스 트랙을 시각적으로 나타내는 컴포넌트예요.
- Progress.Fill: 프로그레스 값을 시각적으로 나타내는 컴포넌트예요.
<Progress>
<Progress.Label />
<Progress.ValueLabel />
<Progress.Track>
<Progress.Fill />
</Progress.Track>
</Progress>
Example
Usage
Custom value scale
기본적으로 value prop은 현재 진행률의 백분율을 나타내며, 최소·최대 값은 각각 0과 100으로 기본 설정돼요. 대신 minValue와 maxValue prop을 설정해 다른 스케일을 사용할 수도 있어요.
<Progress value={100} minValue={50} maxValue={150} class="progress">
<div class="progress__label-container">
<Progress.Label class="progress__label">Loading...</Progress.Label>
<Progress.ValueLabel class="progress__value-label" />
</div>
<Progress.Track class="progress__track">
<Progress.Fill class="progress__fill" />
</Progress.Track>
</Progress>
Custom value label
getValueLabel prop을 사용하면 Progress.ValueLabel과 ARIA에서 사용되는 포맷된 값을 커스텀 문자열로 바꿀 수 있어요. 현재 값, min, max 값을 파라미터로 받아요.
<Progress
value={3}
minValue={0}
maxValue={10}
getValueLabel={({ value, max }) => `${value} of ${max} tasks completed`}
class="progress"
>
<div class="progress__label-container">
<Progress.Label class="progress__label">Processing...</Progress.Label>
<Progress.ValueLabel class="progress__value-label" />
</div>
<Progress.Track class="progress__track">
<Progress.Fill class="progress__fill" />
</Progress.Track>
</Progress>
Progress bar fill width
진행률 백분율에 해당하는 CSS 커스텀 프로퍼티 --kb-progress-fill-width를 노출해요(ex: 80%). 선형(linear) 프로그레스 바를 만들 때 CSS에서 이 값을 사용해 Progress.Fill 컴포넌트의 너비를 설정할 수 있어요.
API Reference
Progress
Progress는 @kobalte/core/progress의 Root import와 동일해요(그리고 폐기(deprecated)된 Progress.Root).
| Prop | Description |
|---|---|
| value | number The progress value. |
| minValue | number The minimum progress value. |
| maxValue | number The maximum progress value. |
| indeterminate | boolean Whether the progress is in an indeterminate state. |
| getValueLabel | (params: { value: number; min: number; max: number }) => string A function to get the accessible label text representing the current value in a human-readable format. If not provided, the value label will be read as a percentage of the max value. |
| Data attribute | Description |
|---|---|
| data-progress='loading' | Present when the progress is not complete (value < maxValue). |
| data-progress='complete' | Present when the progress is complete (value === maxValue). |
| data-indeterminate | Present when the progress is in an indeterminate state. |
Progress.Label, Progress.ValueLabel, Progress.Track and Progress.Fill shares the same data-attributes.
Rendered elements
| Component | Default rendered element |
|---|---|
Progress |
div |
Progress.Label |
span |
Progress.ValueLabel |
div |
Progress.Track |
div |
Progress.Fill |
div |