Progress Ring
<p-progress-ring> | PProgressRing
Progress rings are used to show the progress of a determinate operation in a circular fashion.
<p-progress-ring value="25"></p-progress-ring>
import PProgressRing from 'pure-uikit/dist/react/progress-ring'; const App = () => <PProgressRing value="25" />;
Examples
Size
Use the --size
custom property to set the diameter of the progress ring.
<p-progress-ring value="50" style="--size: 200px;"></p-progress-ring>
import PProgressRing from 'pure-uikit/dist/react/progress-ring'; const App = () => <PProgressRing value="50" style={{ '--size': '200px' }} />;
Track and Indicator Width
Use the --track-width
and --indicator-width
custom properties to set the width of
the progress ring’s track and indicator.
<p-progress-ring value="50" style="--track-width: 6px; --indicator-width: 12px;"></p-progress-ring>
import PProgressRing from 'pure-uikit/dist/react/progress-ring'; const App = () => <PProgressRing value="50" style={{ '--track-width': '6px', '--indicator-width': '12px' }} />;
Colors
To change the color, use the --track-color
and --indicator-color
custom
properties.
<p-progress-ring value="50" style=" --track-color: pink; --indicator-color: deeppink; " ></p-progress-ring>
import PProgressRing from 'pure-uikit/dist/react/progress-ring'; const App = () => ( <PProgressRing value="50" style={{ '--track-color': 'pink', '--indicator-color': 'deeppink' }} /> );
Labels
Use the label
attribute to label the progress ring and tell assistive devices how to announce
it.
<p-progress-ring value="50" label="Upload progress"></p-progress-ring>
import PProgressRing from 'pure-uikit/dist/react/progress-ring'; const App = () => <PProgressRing value="50" label="Upload progress" />;
Showing Values
Use the default slot to show a label inside the progress ring.
<p-progress-ring value="50" class="progress-ring-values" style="margin-bottom: .5rem;">50%</p-progress-ring> <br /> <p-button circle><p-icon name="dash" label="Decrease"></p-icon></p-button> <p-button circle><p-icon name="plus" label="Increase"></p-icon></p-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 PButton from 'pure-uikit/dist/react/button'; import PIcon from 'pure-uikit/dist/react/icon'; import PProgressRing from 'pure-uikit/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 ( <> <PProgressRing value={value} style={{ marginBottom: '.5rem' }}> {value}% </PProgressRing> <br /> <PButton circle onClick={() => adjustValue(-10)}> <PIcon name="dash" label="Decrease" /> </PButton> <PButton circle onClick={() => adjustValue(10)}> <PIcon name="plus" label="Increase" /> </PButton> </> ); };
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/pure-uikit@1.3.13/cdn/components/progress-ring/progress-ring.js"></script>
To import this component from the CDN using a JavaScript import:
import 'https://cdn.jsdelivr.net/npm/pure-uikit@1.3.13/cdn/components/progress-ring/progress-ring.js';
To import this component using a bundler:
import 'pure-uikit/dist/components/progress-ring/progress-ring.js';
To import this component as a React component:
import PProgressRing from 'pure-uikit/dist/react/progress-ring';
Slots
Name | Description |
---|---|
(default) | A label to show inside the ring. |
Learn more about using slots.
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. |
Learn more about attributes and properties.
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. |
Learn more about customizing CSS custom properties.
Parts
Name | Description |
---|---|
base |
The component’s base wrapper. |
label |
The progress ring label. |
Learn more about customizing CSS parts.