스피너 (Spinner)
SlSpinner는 완료 시점이 정해지지 않은(indeterminate) 작업의 진행 상태를 보여줄 때 사용하는 요소예요. 로딩 중임을 시각적으로 알려줄 때 딱 맞는 컴포넌트입니다.
출처: 문서
본문
<sl-spinner></sl-spinner>
React에서는 이렇게 사용할 수 있어요.
import SlSpinner from '@shoelace-style/shoelace/dist/react/spinner';
const App = () => <SlSpinner />;
예시 (Examples)
크기 (Size)
스피너의 크기는 현재 font-size 값을 기준으로 정해져요. 크기를 바꾸려면 아래처럼 스피너 자신이나 부모 요소에 font-size 프로퍼티를 설정하면 됩니다.
<sl-spinner></sl-spinner>
<sl-spinner style="font-size: 2rem;"></sl-spinner>
<sl-spinner style="font-size: 3rem;"></sl-spinner>
import SlSpinner from '@shoelace-style/shoelace/dist/react/spinner';
const App = () => (
<>
<SlSpinner />
<SlSpinner style={{ fontSize: '2rem' }} />
<SlSpinner style={{ fontSize: '3rem' }} />
</>
);
트랙 두께 (Track Width)
스피너 트랙(track)의 두께는 --track-width 커스텀 프로퍼티로 바꿀 수 있어요.
<sl-spinner style="font-size: 50px; --track-width: 10px;"></sl-spinner>
import SlSpinner from '@shoelace-style/shoelace/dist/react/spinner';
const App = () => (
<SlSpinner
style={{
fontSize: '3rem',
'--track-width': '6px'
}}
/>
);
색상 (Color)
스피너의 색은 --indicator-color와 --track-color 커스텀 프로퍼티로 바꿀 수 있어요.
<sl-spinner style="font-size: 3rem; --indicator-color: deeppink; --track-color: pink;"></sl-spinner>
import SlSpinner from '@shoelace-style/shoelace/dist/react/spinner';
const App = () => (
<SlSpinner
style={{
fontSize: '3rem',
'--indicator-color': 'deeppink',
'--track-color': 'pink'
}}
/>
);
불러오기 (Importing)
autoloader나 전통적인 loader를 사용 중이라면 이 부분은 무시해도 돼요. 그게 아니라면 아래 스니펫 중 원하는 방식으로 이 컴포넌트만 골라서 불러올 수 있어요.
Script 태그로 CDN에서 이 컴포넌트를 불러오려면:
<script type="module" src="https://cdn.jsdelivr.net/npm/@shoelace-style/shoelace@2.20.1/cdn/components/spinner/spinner.js"></script>
JavaScript import 구문으로 CDN에서 불러오려면:
import 'https://cdn.jsdelivr.net/npm/@shoelace-style/shoelace@2.20.1/cdn/components/spinner/spinner.js';
번들러(bundler)를 사용해 불러오려면:
import '@shoelace-style/shoelace/dist/components/spinner/spinner.js';
React 컴포넌트로 불러오려면:
import SlSpinner from '@shoelace-style/shoelace/dist/react/spinner';
커스텀 프로퍼티 (Custom Properties)
| Name | Description | Default |
|---|---|---|
--track-width |
The width of the track. | |
--track-color |
The color of the track. | |
--indicator-color |
The color of the spinner’s indicator. | |
--speed |
The time it takes for the spinner to complete one animation cycle. |
CSS 커스텀 프로퍼티 커스터마이징에 대해 더 알아보기.
파트 (Parts)
| Name | Description |
|---|---|
base |
The component’s base wrapper. |
CSS 파트 커스터마이징에 대해 더 알아보기.