2020-07-15 21:30:37 +00:00
|
|
|
# Progress Ring
|
|
|
|
|
|
|
|
[component-header:sl-progress-ring]
|
|
|
|
|
|
|
|
Progress rings are used to show the progress of a determinate operation in a circular fashion.
|
|
|
|
|
|
|
|
```html preview
|
2021-09-30 13:02:28 +00:00
|
|
|
<sl-progress-ring value="25"></sl-progress-ring>
|
2020-07-15 21:30:37 +00:00
|
|
|
```
|
|
|
|
|
2021-11-04 22:12:47 +00:00
|
|
|
```jsx react
|
|
|
|
import { SlProgressRing } from '@shoelace-style/shoelace/dist/react';
|
|
|
|
|
|
|
|
const App = () => (
|
|
|
|
<SlProgressRing value="25" />
|
|
|
|
);
|
|
|
|
```
|
|
|
|
|
2020-07-15 21:30:37 +00:00
|
|
|
## Examples
|
|
|
|
|
|
|
|
### Size
|
|
|
|
|
2021-09-30 12:40:21 +00:00
|
|
|
Use the `--size` custom property to set the diameter of the progress ring.
|
2020-07-15 21:30:37 +00:00
|
|
|
|
|
|
|
```html preview
|
2021-09-30 13:02:28 +00:00
|
|
|
<sl-progress-ring value="50" style="--size: 200px;"></sl-progress-ring>
|
2020-07-15 21:30:37 +00:00
|
|
|
```
|
|
|
|
|
2021-11-04 22:12:47 +00:00
|
|
|
```jsx react
|
|
|
|
import { SlProgressRing } from '@shoelace-style/shoelace/dist/react';
|
|
|
|
|
|
|
|
const App = () => (
|
|
|
|
<SlProgressRing
|
|
|
|
value="50"
|
|
|
|
style={{ '--size': '200px' }}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
```
|
|
|
|
|
2021-09-17 22:15:13 +00:00
|
|
|
### Track Width
|
2020-07-15 21:30:37 +00:00
|
|
|
|
2021-10-10 02:00:41 +00:00
|
|
|
Use the `--track-width` custom property to set the width of the progress ring's track.
|
2020-07-15 21:30:37 +00:00
|
|
|
|
|
|
|
```html preview
|
2021-10-10 02:00:41 +00:00
|
|
|
<sl-progress-ring value="50" style="--track-width: 10px;"></sl-progress-ring>
|
2020-07-15 21:30:37 +00:00
|
|
|
```
|
|
|
|
|
2021-11-04 22:12:47 +00:00
|
|
|
```jsx react
|
|
|
|
import { SlProgressRing } from '@shoelace-style/shoelace/dist/react';
|
|
|
|
|
|
|
|
const App = () => (
|
|
|
|
<SlProgressRing
|
|
|
|
value="50"
|
|
|
|
style={{ '--track-width': '10px' }}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
```
|
|
|
|
|
2020-07-15 21:30:37 +00:00
|
|
|
### Colors
|
|
|
|
|
|
|
|
To change the color, use the `--track-color` and `--indicator-color` custom properties.
|
|
|
|
|
|
|
|
```html preview
|
|
|
|
<sl-progress-ring
|
2021-09-30 13:02:28 +00:00
|
|
|
value="50"
|
2021-08-18 12:55:59 +00:00
|
|
|
style="
|
2021-09-17 22:15:13 +00:00
|
|
|
--track-color: pink;
|
|
|
|
--indicator-color: deeppink;
|
2021-08-18 12:55:59 +00:00
|
|
|
"
|
2020-07-15 21:30:37 +00:00
|
|
|
></sl-progress-ring>
|
|
|
|
```
|
|
|
|
|
2021-11-04 22:12:47 +00:00
|
|
|
```jsx react
|
|
|
|
import { SlProgressRing } from '@shoelace-style/shoelace/dist/react';
|
|
|
|
|
|
|
|
const App = () => (
|
|
|
|
<SlProgressRing
|
|
|
|
value="50"
|
|
|
|
style={{
|
|
|
|
'--track-color': 'pink',
|
|
|
|
'--indicator-color': 'deeppink'
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
```
|
|
|
|
|
2020-07-15 21:30:37 +00:00
|
|
|
### Labels
|
|
|
|
|
2021-10-14 12:34:54 +00:00
|
|
|
Use the `label` attribute to label the progress ring and tell assistive devices how to announce it.
|
|
|
|
|
|
|
|
```html preview
|
|
|
|
<sl-progress-ring value="50" label="Upload progress"></sl-progress-ring>
|
|
|
|
```
|
|
|
|
|
2021-11-04 22:12:47 +00:00
|
|
|
```jsx react
|
|
|
|
import { SlProgressRing } from '@shoelace-style/shoelace/dist/react';
|
|
|
|
|
|
|
|
const App = () => (
|
|
|
|
<SlProgressRing
|
|
|
|
value="50"
|
|
|
|
label="Upload progress"
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
```
|
|
|
|
|
2021-10-14 12:34:54 +00:00
|
|
|
### Showing Values
|
|
|
|
|
2021-11-04 22:12:47 +00:00
|
|
|
Use the default slot to show a label inside the progress ring.
|
2020-07-15 21:30:37 +00:00
|
|
|
|
|
|
|
```html preview
|
2021-10-14 12:34:54 +00:00
|
|
|
<sl-progress-ring value="50" class="progress-ring-values" style="margin-bottom: .5rem;">50%</sl-progress-ring>
|
2020-07-15 21:30:37 +00:00
|
|
|
|
|
|
|
<br>
|
|
|
|
|
|
|
|
<sl-button circle><sl-icon name="dash"></sl-icon></sl-button>
|
|
|
|
<sl-button circle><sl-icon name="plus"></sl-icon></sl-button>
|
|
|
|
|
|
|
|
<script>
|
2021-10-14 12:34:54 +00:00
|
|
|
const progressRing = document.querySelector('.progress-ring-values');
|
2020-07-15 21:30:37 +00:00
|
|
|
const subtractButton = progressRing.nextElementSibling.nextElementSibling;
|
|
|
|
const addButton = subtractButton.nextElementSibling;
|
|
|
|
|
|
|
|
addButton.addEventListener('click', () => {
|
2021-09-30 13:02:28 +00:00
|
|
|
const value = Math.min(100, progressRing.value + 10);
|
|
|
|
progressRing.value = value;
|
|
|
|
progressRing.textContent = `${value}%`;
|
2020-07-15 21:30:37 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
subtractButton.addEventListener('click', () => {
|
2021-09-30 13:02:28 +00:00
|
|
|
const value = Math.max(0, progressRing.value - 10)
|
|
|
|
progressRing.value = value;
|
|
|
|
progressRing.textContent = `${value}%`;
|
2020-07-15 21:30:37 +00:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
```
|
|
|
|
|
2021-11-04 22:12:47 +00:00
|
|
|
```jsx react
|
|
|
|
import { useState } from 'react';
|
|
|
|
import {
|
|
|
|
SlButton,
|
|
|
|
SlIcon,
|
|
|
|
SlProgressRing
|
|
|
|
} from '@shoelace-style/shoelace/dist/react';
|
|
|
|
|
|
|
|
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" />
|
|
|
|
</SlButton>
|
|
|
|
|
|
|
|
<SlButton circle onClick={() => adjustValue(10)}>
|
|
|
|
<SlIcon name="plus" />
|
|
|
|
</SlButton>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
```
|
|
|
|
|
2020-07-15 21:30:37 +00:00
|
|
|
[component-metadata:sl-progress-ring]
|