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

Import

MyComponent.tsx
1import { CircularProgress } from '@/crossbuildui/circular-progress';

CircularProgress Component

Basic Usage

Provide a value between minValue (default 0) and maxValue (default 100).

MyComponent.tsx
1<CircularProgress value={50} />

With Label

Display a descriptive label inside or below the progress circle.

MyComponent.tsx
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.

MyComponent.tsx
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.

MyComponent.tsx
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.

MyComponent.tsx
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.

MyComponent.tsx
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.

MyComponent.tsx
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.

MyComponent.tsx
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.

MyComponent.tsx
1<CircularProgress value={70} isDisabled label="Disabled" showValueLabel />

Disable Animation

Set disableAnimation to true to prevent animations on value changes or for indeterminate state.

MyComponent.tsx
1<CircularProgress value={60} disableAnimation showValueLabel label="No Animation" />

Props Overview

PROPTYPEDEFAULTDESCRIPTION
labelReactNode-Content for the main label.
size'sm' | 'md' | 'lg' | number'md'Size of the progress indicator. Number sets custom diameter.
valuenumber-Current progress value (0-100 by default). Overridden by isIndeterminate.
valueLabelReactNode-Custom content for the value label.
minValuenumber0Minimum progress value.
maxValuenumber100Maximum progress value.
formatOptionsIntl.NumberFormatOptions-Formatting options for the displayed value.
showValueLabelbooleantrue if value is provided & not isIndeterminate, else falseWhether to display the value label.
strokeWidthnumberVaries by size (e.g., 4 for 'md'); dynamic for numeric sizeWidth of the progress stroke.
colorCircularProgressColor'primary'Thematic color of the indicator.
indicatorColorstring-Custom color for the progress indicator circle. Overrides theme/color prop.
trackColorstring-Custom color for the track circle. Overrides theme/color prop.
labelColorstring-Custom color for the label text. Overrides theme.
valueLabelColorstring-Custom color for the value label text. Overrides theme or indicator color.
isDisabledbooleanfalseIf true, visually mutes the component.
disableAnimationbooleanfalseIf true, disables all animations.
isIndeterminatebooleanfalseIf true, shows an indeterminate loading animation.
stylesCircularProgressSlotsStyles-Custom styles for internal slots.
styleStyleProp<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 wrapper View.
  • svg: The View container for the SVG element.
  • track: The background circle (Circle component from react-native-svg). You can pass SVG props like stroke, strokeOpacity etc.
  • indicator: The progress indicator circle (AnimatedCircle). You can pass SVG props.
  • label: The label Text component.
  • valueLabel: The value label Text component.
MyComponent.tsx
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 has accessibilityRole="progressbar".
  • Accessibility properties accessibilityValue.min, accessibilityValue.max, and accessibilityValue.now are set based on the minValue, maxValue, and value 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.