Progress Bar
<mf-progress-bar> | MfProgressBar
Progress bars are used to show the status of an ongoing operation.
<mf-progress-bar value="50"></mf-progress-bar>
import MfProgressBar from 'maf-ui-kit/dist/react/progress-bar'; const App = () => <MfProgressBar value={50} />;
Examples
Labels
Use the label attribute to label the progress bar and tell assistive devices how to announce
it.
<mf-progress-bar value="50" label="Upload progress"></mf-progress-bar>
import MfProgressBar from 'maf-ui-kit/dist/react/progress-bar'; const App = () => <MfProgressBar value="50" label="Upload progress" />;
Custom Height
Use the --height custom property to set the progress bar’s height.
<mf-progress-bar value="50" style="--height: 6px;"></mf-progress-bar>
import MfProgressBar from 'maf-ui-kit/dist/react/progress-bar'; const App = () => <MfProgressBar value={50} style={{ '--height': '6px' }} />;
Showing Values
Use the default slot to show a value.
<mf-progress-bar value="50" class="progress-bar-values">50%</mf-progress-bar> <br /> <mf-button circle><mf-icon name="dash" label="Decrease"></mf-icon></mf-button> <mf-button circle><mf-icon name="plus" label="Increase"></mf-icon></mf-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 MfButton from 'maf-ui-kit/dist/react/button'; import MfIcon from 'maf-ui-kit/dist/react/icon'; import MfProgressBar from 'maf-ui-kit/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 ( <> <MfProgressBar value={value}>{value}%</MfProgressBar> <br /> <MfButton circle onClick={() => adjustValue(-10)}> <MfIcon name="dash" label="Decrease" /> </MfButton> <MfButton circle onClick={() => adjustValue(10)}> <MfIcon name="plus" label="Increase" /> </MfButton> </> ); };
Indeterminate
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.
<mf-progress-bar indeterminate></mf-progress-bar>
import MfProgressBar from 'maf-ui-kit/dist/react/progress-bar'; const App = () => <MfProgressBar indeterminate />;
Importing
If you’re using the autoloader or the traditional loader, you can ignore this section. Otherwise, feel free to use any of the following snippets to cherry pick this component.
To import this component from the CDN using a script tag:
<script type="module" src="https://cdn.jsdelivr.net/npm/maf-ui-kit@0.0.1/cdn/components/progress-bar/progress-bar.js"></script>
To import this component from the CDN using a JavaScript import:
import 'https://cdn.jsdelivr.net/npm/maf-ui-kit@0.0.1/cdn/components/progress-bar/progress-bar.js';
To import this component using a bundler:
import 'maf-ui-kit/dist/components/progress-bar/progress-bar.js';
To import this component as a React component:
import MfProgressBar from 'maf-ui-kit/dist/react/progress-bar';
slots
| Name | Description |
|---|---|
| (default) | A label to show inside the progress indicator. |
Learn more about using slots.
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. |
Learn more about attributes and properties.
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. |
Learn more about customizing CSS custom properties.
Parts
| Name | Description |
|---|---|
base |
The component’s base wrapper. |
indicator |
The progress bar’s indicator. |
label |
The progress bar’s label. |
Learn more about customizing CSS parts.