Progress Bar
Progress bars are used to provide feedback to users about the duration and progression of a process.
import {QProgressBar} from "@qui/react"
Overview
- Progress bars can help to reduce user anxiety by providing a visual indication of how long a user will be waiting.
- Progress bars can also be used to provide a sense of accomplishment by showing users how much progress they have made towards completing a task.
Accessibility
- When the value is supplied, we provide the corresponding aria-value* attributes to the element.
- According to ARIA guidelines, the progress bar must have an accessible name. When you supply the label prop, we automatically associate it with the progress bar element. If you omit the label, you should provide an accessible name using the
aria-label
attribute.
<QProgressBar aria-label="Loading Profile" />
Examples
Determinate
A determinate progress bar displays the exact percentage of completion of the operation. Pass a value between 0 and 100 to the value property to indicate an operation's progress.
import {ReactNode, useEffect, useState} from "react"import {QProgressBar} from "@qui/react"export default function Determinate(): ReactNode {const [value, setValue] = useState<number>(0)useEffect(() => {const interval = setInterval(() => {setValue((currentValue) => (currentValue >= 100 ? 0 : currentValue + 5))}, 1000)return () => clearInterval(interval)}, [])return (<div className="grid justify-center p-4"><div className="flex w-[300px] p-4"><QProgressBararia-label="Loading Indicator"label="Loading..."showValueLabelvalue={value}/></div></div>)}
Indeterminate
If no value is specified, the progress bar will not display any percentage of completion, and will instead render as indeterminate. This is indicated by a bar that is constantly moving.
import {ReactNode} from "react"import {QProgressBar} from "@qui/react"export default function Indeterminate(): ReactNode {return (<div className="grid justify-center"><div className="flex w-[300px] p-4"><QProgressBar label="Processing..." /></div></div>)}
Label
Add a descriptor for the progress bar by passing a label property. The label will render above the progress bar by default. Change this by setting the labelPosition property to side
. To show the value label, set the showValueLabel property to true
.
No Label (default)Top LabelSide Label
import {ReactNode, useEffect, useState} from "react"import {QProgressBar} from "@qui/react"export default function Label(): ReactNode {const [value, setValue] = useState<number>(0)useEffect(() => {const interval = setInterval(() => {setValue((currentValue) => (currentValue >= 100 ? 0 : currentValue + 5))}, 1000)return () => clearInterval(interval)}, [])return (<div className="grid justify-center gap-8 p-4"><div className="flex w-[300px] flex-col gap-8 p-4"><span className="text-primary q-font-heading-xs">No Label (default)</span><QProgressBar label="Processing..." value={value} /><QProgressBar aria-label="Loading" /><span className="mt-4 text-primary q-font-heading-xs">Top Label</span><QProgressBar label="Loading..." showValueLabel value={value} /><QProgressBar label="Loading..." value={value} /><span className="mt-4 text-primary q-font-heading-xs">Side Label</span><QProgressBar label="Loading..." labelPosition="side" value={value} /><QProgressBararia-label="Loading"labelPosition="side"showValueLabelvalue={value}/><QProgressBarlabel="Loading..."labelPosition="side"showValueLabelvalue={value}/></div></div>)}
Sizes
Two sizes are available: m
(default) and l
Medium (m)Large (l)
import {ReactNode, useEffect, useState} from "react"import {QProgressBar} from "@qui/react"export default function Size(): ReactNode {const [value, setValue] = useState<number>(0)useEffect(() => {const interval = setInterval(() => {setValue((currentValue) => (currentValue >= 100 ? 0 : currentValue + 5))}, 1000)return () => clearInterval(interval)}, [])return (<div className="grid justify-center"><div className="flex w-[300px] flex-col gap-8 p-4"><span className="text-primary q-font-heading-xs">Medium (m)</span><QProgressBar aria-label="Loading" value={value} /><QProgressBar aria-label="Loading" /><span className="text-primary q-font-heading-xs">Large (l)</span><QProgressBar aria-label="Loading" size="l" value={value} /><QProgressBar aria-label="Loading" size="l" /></div></div>)}
API
Props
Name & Description | Option(s) | Default |
---|---|---|
The component used for the root node. It can be a React component or
element. |
| 'div' |
The className property of the Element
interface gets and sets the value of the
class attribute
of the specified element. |
| |
The color of filled segment of the progress bar. |
| 'var(--q-brand-600)' |
Label for the progress bar. | ReactNode | |
Position of the label. |
| 'top' |
If true and the value input is supplied, the current progress percentage
will be indicated by a label. |
| false |
Size of the progress bsr. |
| 'm' |
The style global attribute
contains CSS styling
declarations to be applied to the element. | CSSProperties | |
Value of the progress bar. If this value is omitted, the progress bar will be
rendered as indeterminate. |
|
Type
| ElementType| ComponentType
Default
'div'
Description
The component used for the root node. It can be a React component or
element.
Type
string
Description
The className property of the Element
interface gets and sets the value of the
class attribute
of the specified element.
Type
string
Default
'var(--q-brand-600)'
Description
The color of filled segment of the progress bar.
Type
'top' | 'side'
Default
'top'
Description
Position of the label.
Type
boolean
Default
false
Description
If true and the value input is supplied, the current progress percentage
will be indicated by a label.
Type
'm' | 'l'
Default
'm'
Description
Size of the progress bsr.
Type
CSSProperties
Description
The style global attribute
contains CSS styling
declarations to be applied to the element.
Type
number
Description
Value of the progress bar. If this value is omitted, the progress bar will be
rendered as indeterminate.