2020-07-15 21:30:37 +00:00
# Progress Bar
[component-header:sl-progress-bar]
2020-11-25 21:20:15 +00:00
Progress bars are used to show the status of an ongoing operation.
2020-07-15 21:30:37 +00:00
```html preview
2021-09-30 13:02:28 +00:00
< sl-progress-bar value = "50" > < / sl-progress-bar >
2020-07-15 21:30:37 +00:00
```
2021-11-04 22:12:47 +00:00
```jsx react
import { SlProgressBar } from '@shoelace-style/shoelace/dist/react';
2022-03-02 15:10:41 +00:00
const App = () => < SlProgressBar value = {50} / > ;
2021-11-04 22:12:47 +00:00
```
2020-07-15 21:30:37 +00:00
## Examples
### Custom Height
Use the `--height` custom property to set the progress bar's height.
```html preview
2021-09-30 13:02:28 +00:00
< sl-progress-bar value = "50" style = "--height: 6px;" > < / sl-progress-bar >
2020-07-15 21:30:37 +00:00
```
2021-11-04 22:12:47 +00:00
```jsx react
import { SlProgressBar } from '@shoelace-style/shoelace/dist/react';
2022-03-02 15:10:41 +00:00
const App = () => < SlProgressBar value = {50} style = {{ ' --height ' : ' 6px ' } } / > ;
2021-11-04 22:12:47 +00:00
```
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 bar and tell assistive devices how to announce it.
2020-07-15 21:30:37 +00:00
```html preview
2021-10-14 12:34:54 +00:00
< sl-progress-bar value = "50" label = "Upload progress" > < / sl-progress-bar >
```
2021-11-04 22:12:47 +00:00
```jsx react
import { SlProgressBar } from '@shoelace-style/shoelace/dist/react';
2022-03-02 15:10:41 +00:00
const App = () => < SlProgressBar value = "50" label = "Upload progress" / > ;
2021-11-04 22:12:47 +00:00
```
2021-10-14 12:34:54 +00:00
### Showing Values
Use the default slot to show a value.
```html preview
< sl-progress-bar value = "50" class = "progress-bar-values" > 50%< / sl-progress-bar >
2020-07-15 21:30:37 +00:00
2022-03-02 15:10:41 +00:00
< br / >
2020-07-15 21:30:37 +00:00
< 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 progressBar = document.querySelector('.progress-bar-values');
2020-07-15 21:30:37 +00:00
const subtractButton = progressBar.nextElementSibling.nextElementSibling;
const addButton = subtractButton.nextElementSibling;
addButton.addEventListener('click', () => {
2021-09-30 13:02:28 +00:00
const value = Math.min(100, progressBar.value + 10);
progressBar.value = value;
progressBar.textContent = `${value}%` ;
2020-07-15 21:30:37 +00:00
});
subtractButton.addEventListener('click', () => {
2022-03-02 15:10:41 +00:00
const value = Math.max(0, progressBar.value - 10);
2021-09-30 13:02:28 +00:00
progressBar.value = value;
progressBar.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';
2022-03-02 15:10:41 +00:00
import { SlButton, SlIcon, SlProgressBar } from '@shoelace-style/shoelace/dist/react';
2021-11-04 22:12:47 +00:00
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 (
< >
2022-03-02 15:10:41 +00:00
< SlProgressBar value = {value} > {value}%< / SlProgressBar >
2021-11-04 22:12:47 +00:00
< br / >
< SlButton circle onClick = {() = > adjustValue(-10)}>
< SlIcon name = "dash" / >
< / SlButton >
< SlButton circle onClick = {() = > adjustValue(10)}>
< SlIcon name = "plus" / >
< / SlButton >
< />
);
};
```
2020-11-25 21:20:15 +00:00
### Indeterminate
2021-09-30 13:02:28 +00:00
The `indeterminate` attribute can be used to inform the user that the operation is pending, but its status cannot currently be determined. In this state, `value` is ignored and the label, if present, will not be shown.
2020-11-25 21:20:15 +00:00
```html preview
< sl-progress-bar indeterminate > < / sl-progress-bar >
```
2021-11-04 22:12:47 +00:00
```jsx react
import { SlProgressBar } from '@shoelace-style/shoelace/dist/react';
2022-03-02 15:10:41 +00:00
const App = () => < SlProgressBar indeterminate / > ;
2021-11-04 22:12:47 +00:00
```
2020-07-15 21:30:37 +00:00
[component-metadata:sl-progress-bar]