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

프로그레스 링 (Progress Ring)

원문 보기 위키 갱신

정해진(determinate) 작업의 진행도를 원형으로 보여주는 컴포넌트예요. 원형 게이지처럼 한눈에 진행률을 파악할 때 유용해요. _ | SlProgressRing, Shoelace 2.0부터 제공되고 있으며 stable 상태예요.

출처: 문서

본문

| SlProgressRing — Since 2.0, stable

프로그레스 링(Progress Ring)은 정해진 작업의 진행도를 원형으로 보여주는 데 쓰여요.

<sl-progress-ring value="25"></sl-progress-ring>
import SlProgressRing from '@shoelace-style/shoelace/dist/react/progress-ring';
const App = () => <SlProgressRing value="25" />;

Examples

Size

--size 커스텀 프로퍼티로 프로그레스 링의 지름을 정할 수 있어요.

<sl-progress-ring value="50" style="--size: 200px;"></sl-progress-ring>
import SlProgressRing from '@shoelace-style/shoelace/dist/react/progress-ring';
const App = () => <SlProgressRing value="50" style={{ '--size': '200px' }} />;

Track and Indicator Width

--track-width와 --indicator-width 커스텀 프로퍼티로 프로그레스 링의 트랙과 인디케이터의 너비를 정할 수 있어요.

<sl-progress-ring value="50" style="--track-width: 6px; --indicator-width: 12px;"></sl-progress-ring>
import SlProgressRing from '@shoelace-style/shoelace/dist/react/progress-ring';
const App = () => <SlProgressRing value="50" style={{ '--track-width': '6px', '--indicator-width': '12px' }} />;

Colors

색을 바꾸려면 --track-color와 --indicator-color 커스텀 프로퍼티를 쓰면 돼요.

<sl-progress-ring
  value="50"
  style="
    --track-color: pink;
    --indicator-color: deeppink;
  "
></sl-progress-ring>
import SlProgressRing from '@shoelace-style/shoelace/dist/react/progress-ring';
const App = () => (
  <SlProgressRing
    value="50"
    style={{
      '--track-color': 'pink',
      '--indicator-color': 'deeppink'
    }}
  />
);

Labels

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

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

Showing Values

기본 슬롯을 사용해 프로그레스 링 안에 레이블을 표시할 수 있어요.

<sl-progress-ring value="50" class="progress-ring-values" style="margin-bottom: .5rem;">50%</sl-progress-ring>
<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 progressRing = document.querySelector('.progress-ring-values');
  const subtractButton = progressRing.nextElementSibling.nextElementSibling;
  const addButton = subtractButton.nextElementSibling;
  addButton.addEventListener('click', () => {
    const value = Math.min(100, progressRing.value + 10);
    progressRing.value = value;
    progressRing.textContent = `${value}%`;
  });
  subtractButton.addEventListener('click', () => {
    const value = Math.max(0, progressRing.value - 10);
    progressRing.value = value;
    progressRing.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 SlProgressRing from '@shoelace-style/shoelace/dist/react/progress-ring';
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 (
    <>
      <SlProgressRing value={value} style={{ marginBottom: '.5rem' }}>
        {value}%
      </SlProgressRing>
      <br />
      <SlButton circle onClick={() => adjustValue(-10)}>
        <SlIcon name="dash" label="Decrease" />
      </SlButton>
      <SlButton circle onClick={() => adjustValue(10)}>
        <SlIcon name="plus" label="Increase" />
      </SlButton>
    </>
  );
};

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-ring/progress-ring.js"></script>

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

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

Bundler를 사용해 가져오려면:

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

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

import SlProgressRing from '@shoelace-style/shoelace/dist/react/progress-ring';

Slots

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

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

Properties

Name Description Reflects Type Default
value The current progress as a percentage, 0 to 100. number 0
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
--size The diameter of the progress ring (cannot be a percentage).
--track-width The width of the track.
--track-color The color of the track.
--indicator-width The width of the indicator. Defaults to the track width.
--indicator-color The color of the indicator.
--indicator-transition-duration The duration of the indicator’s transition when the value changes.

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

Parts

Name Description
base The component’s base wrapper.
label The progress ring label.

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

더 알아보기 (Learn more)