Circular Progress
The CircularProgress component displays progress indication in a circular format, suitable for showing loading states or completion percentages.
Installation
$ cbui-cli install circular-progresscbui-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" />Glass Effect
Apply a frosted glass effect to the background area of the progress circle using isGlass. Customize it with glassIntensity (0-100) and glassTint ('light', 'dark', 'default'). The track color automatically adapts for visibility on the blurred background. Label and value label colors default to the theme's foreground. For dark glass tints or if the default foreground color lacks contrast, you may need to manually set labelColor, valueLabelColor, or use the styles prop to ensure readability.
1<View style={{ flexDirection: 'row', alignItems: 'center', gap: 24, padding: 16, backgroundColor: 'darkslategray' }}>
2 <CircularProgress
3 value={70}
4 isGlass
5 glassIntensity={80}
6 glassTint="light"
7 label="Light Glass"
8 showValueLabel
9 />
10 <CircularProgress
11 value={50}
12 isGlass
13 glassIntensity={50}
14 glassTint="dark"
15 label="Dark Glass"
16 showValueLabel
17 styles={{ label: { color: 'white' }, valueLabel: { color: 'white' } }} // Example: manual text color for dark glass
18 />
19 <CircularProgress isIndeterminate isGlass glassIntensity={60} label="Indeterminate" styles={{ label: { color: 'lightgray' } }}/>
20</View>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-derived color and the default track color used with `isGlass`. |
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. |
isGlass | boolean | false | Apply glassmorphism effect to the background area where the track is drawn. |
glassTint | 'default' | 'light' | 'dark' | Theme-derived | Tint for the glass effect. If 'default', it's derived from the current theme mode. |
glassIntensity | number | 30 | Intensity (0-100) for the glass effect. |
Styling
Customize the CircularProgress appearance using several methods:
- Direct color props:
indicatorColor,trackColor,labelColor,valueLabelColorfor specific parts. - The
styleprop for the main container. - The
stylesprop 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: TheViewcontainer for the SVG element.track: The background circle (Circlecomponent fromreact-native-svg). You can pass SVG props likestroke,strokeOpacityetc.indicator: The progress indicator circle (AnimatedCircle). You can pass SVG props.label: The labelTextcomponent.valueLabel: The value labelTextcomponent.- When
isGlassis true, aBlurViewis rendered as the background. Thestyleprop (orstyles.base) applies to the container that holds thisBlurView, SVG, and labels. ThetrackColorprop can still override the default glass track color.
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
ViewhasaccessibilityRole="progressbar". - Accessibility properties
accessibilityValue.min,accessibilityValue.max, andaccessibilityValue.noware set based on theminValue,maxValue, andvalueprops respectively. - If a
labelis provided, it helps describe the progress indicator. Ensure the label is meaningful. - When
isIndeterminateis true, the component signifies an ongoing process without a specific completion percentage. Screen readers should announce this appropriately.