Circular Progress
The CircularProgress component displays progress indication in a circular format, suitable for showing loading states or completion percentages.
Installation
$ cbui-cli install @crossbuildui/circular-progress
cbui-cli
globally and authenticated your account. This will ensure you can access all the necessary features.Import
1import { CircularProgress } from '@/crossbuildui/circular-progress';
CircularProgress Component
Basic Usage
Provide a value
between minValue
(default 0) and maxValue
(default 100).
1<CircularProgress value={50} />
With Label
Display a descriptive label
inside or below the progress circle.
1<CircularProgress value={75} label="Loading..." />
Sizes
The component comes in three predefined sizes: sm
, md
(default), and lg
. You can also provide a number
for a custom diameter.
1<View style={{ flexDirection: 'row', alignItems: 'center', gap: 24 }}>
2 <CircularProgress size="sm" value={30} showValueLabel />
3 <CircularProgress size="md" value={60} showValueLabel />
4 <CircularProgress size="lg" value={90} showValueLabel />
5 <CircularProgress size={80} value={70} showValueLabel label="Custom Size (80)" />
6</View>
Colors
Set the base thematic color using the color
prop. Supported values include primary
(default), secondary
, success
, warning
, danger
, and default
. This base color influences the indicator and track colors by default.
1<View style={{ flexDirection: 'row', alignItems: 'center', gap: 16 }}>
2 <CircularProgress value={25} color="primary" showValueLabel />
3 <CircularProgress value={50} color="secondary" showValueLabel />
4 <CircularProgress value={75} color="success" showValueLabel />
5 <CircularProgress value={60} color="warning" showValueLabel />
6 <CircularProgress value={40} color="danger" showValueLabel />
7 <CircularProgress value={80} color="default" showValueLabel />
8</View>
Custom Individual Colors
For more granular control, you can use specific color props:indicatorColor
, trackColor
, labelColor
, and valueLabelColor
. These props override any colors derived from the theme or the base color
prop.
1<View style={{ flexDirection: 'row', alignItems: 'center', gap: 16 }}>
2 <CircularProgress
3 value={65}
4 label="Custom Colors"
5 indicatorColor="purple"
6 trackColor="lightpink"
7 labelColor="darkmagenta"
8 valueLabelColor="indigo"
9 showValueLabel
10 />
11</View>
Value Label
Use showValueLabel
to display the current value, formatted by default or using formatOptions
. You can also provide a custom valueLabel
.
1<View style={{ flexDirection: 'row', alignItems: 'center', gap: 24 }}>
2 <CircularProgress value={66} showValueLabel />
3 <CircularProgress value={33} valueLabel="1/3 Done" showValueLabel />
4 <CircularProgress value={88} showValueLabel formatOptions={{ style: 'percent', minimumFractionDigits: 1 }} />
5</View>
Indeterminate
Set isIndeterminate
to true for an animated loading state when the progress value is unknown. This overrides the value
prop.
1<View style={{ flexDirection: 'row', alignItems: 'center', gap: 24 }}>
2 <CircularProgress isIndeterminate label="Processing..." />
3 <CircularProgress isIndeterminate color="success" size="sm" />
4</View>
Custom Stroke Width
Customize the thickness of the progress circle using the strokeWidth
prop.
1<View style={{ flexDirection: 'row', alignItems: 'center', gap: 24 }}>
2 <CircularProgress value={50} strokeWidth={2} size="md" showValueLabel />
3 <CircularProgress value={75} strokeWidth={8} size="lg" showValueLabel label="Thick Stroke" />
4</View>
Disabled State
Set isDisabled
to true to visually mute the progress indicator.
1<CircularProgress value={70} isDisabled label="Disabled" showValueLabel />
Disable Animation
Set disableAnimation
to true to prevent animations on value changes or for indeterminate state.
1<CircularProgress value={60} disableAnimation showValueLabel label="No Animation" />
Props Overview
PROP | TYPE | DEFAULT | DESCRIPTION |
---|---|---|---|
label | ReactNode | - | Content for the main label. |
size | 'sm' | 'md' | 'lg' | number | 'md' | Size of the progress indicator. Number sets custom diameter. |
value | number | - | Current progress value (0-100 by default). Overridden by isIndeterminate . |
valueLabel | ReactNode | - | Custom content for the value label. |
minValue | number | 0 | Minimum progress value. |
maxValue | number | 100 | Maximum progress value. |
formatOptions | Intl.NumberFormatOptions | - | Formatting options for the displayed value. |
showValueLabel | boolean | true if value is provided & not isIndeterminate , else false | Whether to display the value label. |
strokeWidth | number | Varies by size (e.g., 4 for 'md'); dynamic for numeric size | Width of the progress stroke. |
color | CircularProgressColor | 'primary' | Thematic color of the indicator. |
indicatorColor | string | - | Custom color for the progress indicator circle. Overrides theme/color prop. |
trackColor | string | - | Custom color for the track circle. Overrides theme/color prop. |
labelColor | string | - | Custom color for the label text. Overrides theme. |
valueLabelColor | string | - | Custom color for the value label text. Overrides theme or indicator color. |
isDisabled | boolean | false | If true, visually mutes the component. |
disableAnimation | boolean | false | If true, disables all animations. |
isIndeterminate | boolean | false | If true, shows an indeterminate loading animation. |
styles | CircularProgressSlotsStyles | - | Custom styles for internal slots. |
style | StyleProp<ViewStyle> | - | Style for the main wrapper View. |
Styling
Customize the CircularProgress appearance using several methods:
- Direct color props:
indicatorColor
,trackColor
,labelColor
,valueLabelColor
for specific parts. - The
style
prop for the main container. - The
styles
prop for more granular control over internal elements (slots). Styles applied here can override the direct color props.
The styles
prop accepts an object where keys correspond to different parts of the component:
base
: The main wrapperView
.svg
: TheView
container for the SVG element.track
: The background circle (Circle
component fromreact-native-svg
). You can pass SVG props likestroke
,strokeOpacity
etc.indicator
: The progress indicator circle (AnimatedCircle
). You can pass SVG props.label
: The labelText
component.valueLabel
: The value labelText
component.
track
and indicator
slots, you are passing props directly to SVG Circle
components. For example, to change the track color via the styles
prop, you would use { track: { stroke: 'yourColor' } }
. This is different from typical ViewStyle
or TextStyle
props.1<CircularProgress
2 value={80}
3 label="Custom Style"
4 showValueLabel
5 color="primary"
6 size="lg"
7 strokeWidth={6}
8 style={{ transform: [{ scale: 1.1 }] }} // Styles the outermost 'base' container
9 styles={{
10 base: { opacity: 0.9 },
11 svg: { transform: [{ rotate: '10deg' }] }, // Example: slightly rotate the SVG
12 track: { stroke: 'lightgray', strokeOpacity: 0.5 },
13 indicator: { strokeLinecap: 'butt' }, // Change from default 'round'
14 label: { color: 'blue', fontSize: 16, fontWeight: 'bold' },
15 valueLabel: { color: 'darkblue', fontStyle: 'italic' }
16 }}
17/>
Accessibility
The CircularProgress component includes accessibility features:
- The root
View
hasaccessibilityRole="progressbar"
. - Accessibility properties
accessibilityValue.min
,accessibilityValue.max
, andaccessibilityValue.now
are set based on theminValue
,maxValue
, andvalue
props respectively. - If a
label
is provided, it helps describe the progress indicator. Ensure the label is meaningful. - When
isIndeterminate
is true, the component signifies an ongoing process without a specific completion percentage. Screen readers should announce this appropriately.