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

프로그레스 바 (Progress Bar)

원문 보기 위키 갱신

진행 중인 작업의 상태를 보여주는 가로형 진행 표시 컴포넌트예요. 업로드 진행률 같은 정해진(determinate) 작업의 진행도를 표현할 때 써요. _ | SlProgressBar, Shoelace 2.0부터 제공되고 있으며 stable 상태예요.

출처: 문서

본문

| SlProgressBar — Since 2.0, stable

프로그레스 바(Progress Bar)는 진행 중인 작업의 상태를 보여주는 데 쓰여요.

<sl-progress-bar value="50"></sl-progress-bar>
import SlProgressBar from '@shoelace-style/shoelace/dist/react/progress-bar';
const App = () => <SlProgressBar value={50} />;

Examples

Labels

label 속성으로 프로그레스 바에 레이블을 달고, 보조 기기가 어떻게 알려줄지 지정할 수 있어요.

<sl-progress-bar value="50" label="Upload progress"></sl-progress-bar>
import SlProgressBar from '@shoelace-style/shoelace/dist/react/progress-bar';
const App = () => <SlProgressBar value="50" label="Upload progress" />;

Custom Height

--height 커스텀 프로퍼티로 프로그레스 바의 높이를 정할 수 있어요.

<sl-progress-bar value="50" style="--height: 6px;"></sl-progress-bar>
import SlProgressBar from '@shoelace-style/shoelace/dist/react/progress-bar';
const App = () => <SlProgressBar value={50} style={{ '--height': '6px' }} />;

Showing Values

기본 슬롯으로 값을 표시할 수 있어요.

<sl-progress-bar value="50" class="progress-bar-values">50%</sl-progress-bar>
<br />
<sl-button circle><sl-icon name="dash" label="Decrease"></sl-icon></sl-button>
<sl-button circle><sl-icon name="plus" label="Increase"></sl-icon></sl-button>
<script>
  const progressBar = document.querySelector('.progress-bar-values');
  const subtractButton = progressBar.nextElementSibling.nextElementSibling;
  const addButton = subtractButton.nextElementSibling;
  addButton.addEventListener('click', () => {
    const value = Math.min(100, progressBar.value + 10);
    progressBar.value = value;
    progressBar.textContent = `${value}%`;
  });
  subtractButton.addEventListener('click', () => {
    const value = Math.max(0, progressBar.value - 10);
    progressBar.value = value;
    progressBar.textContent = `${value}%`;
  });
</script>
import { useState } from 'react';
import SlButton from '@shoelace-style/shoelace/dist/react/button';
import SlIcon from '@shoelace-style/shoelace/dist/react/icon';
import SlProgressBar from '@shoelace-style/shoelace/dist/react/progress-bar';
const App = () => {
  const [value, setValue] = useState(50);
  function adjustValue(amount) {
    let newValue = value + amount;
    if (newValue < 0) newValue = 0;
    if (newValue > 100) newValue = 100;
    setValue(newValue);
  }
  return (
    <>
      <SlProgressBar value={value}>{value}%</SlProgressBar>
      <br />
      <SlButton circle onClick={() => adjustValue(-10)}>
        <SlIcon name="dash" label="Decrease" />
      </SlButton>
      <SlButton circle onClick={() => adjustValue(10)}>
        <SlIcon name="plus" label="Increase" />
      </SlButton>
    </>
  );
};

Indeterminate

indeterminate 속성은 작업이 진행 중이지만 현재 상태를 정할 수 없을 때 사용자에게 알려주는 데 쓰여요. 이 상태에서는 value가 무시되고, 레이블이 있으면 표시되지 않아요.

<sl-progress-bar indeterminate></sl-progress-bar>
import SlProgressBar from '@shoelace-style/shoelace/dist/react/progress-bar';
const App = () => <SlProgressBar indeterminate />;

Importing

autoloader나 전통적인 loader를 사용하고 있다면 이 부분은 건너뛰어도 돼요. 그 외에는 아래 스니펫 중 원하는 걸 골라 이 컴포넌트만 골라 가져올 수 있어요.

Script / Import / Bundler / React 방식이 준비되어 있어요.

CDN에서 <script> 태그로 이 컴포넌트를 가져오려면:

<script type="module" src="https://cdn.jsdelivr.net/npm/@shoelace-style/shoelace@2.20.1/cdn/components/progress-bar/progress-bar.js"></script>

CDN에서 JavaScript import로 가져오려면:

import 'https://cdn.jsdelivr.net/npm/@shoelace-style/shoelace@2.20.1/cdn/components/progress-bar/progress-bar.js';

Bundler를 사용해 가져오려면:

import '@shoelace-style/shoelace/dist/components/progress-bar/progress-bar.js';

React 컴포넌트로 가져오려면:

import SlProgressBar from '@shoelace-style/shoelace/dist/react/progress-bar';

Slots

Name Description
(default) A label to show inside the progress indicator.

슬롯 사용법에 대해 더 알아보세요.

Properties

Name Description Reflects Type Default
value The current progress as a percentage, 0 to 100. number 0
indeterminate When true, percentage is ignored, the label is hidden, and the progress bar is drawn in an
indeterminate state. boolean false
label A custom label for assistive devices. string ''
updateComplete A read-only promise that resolves when the component has
finished updating.

속성과 프로퍼티에 대해 더 알아보세요.

Custom Properties

Name Description Default
--height The progress bar’s height.
--track-color The color of the track.
--indicator-color The color of the indicator.
--label-color The color of the label.

CSS 커스텀 프로퍼티 커스터마이징에 대해 더 알아보세요.

Parts

Name Description
base The component’s base wrapper.
indicator The progress bar’s indicator.
label The progress bar’s label.

CSS 파트 커스터마이징에 대해 더 알아보세요.

더 알아보기 (Learn more)