Progress
The Progress component displays a linear progress bar, ideal for showing task completion, loading states, or any quantifiable progression.
Installation
$ cbui-cli install @crossbuildui/progress
cbui-cli
globally and authenticated your account. This will ensure you can access all the necessary features.Import
1import { Progress } from '@/crossbuildui/progress';
2import type { ProgressColor, ProgressRadius, ProgressSize } from '@/crossbuildui/progress'; // Optional: for type safety
3import { View, Text } from 'react-native'; // For layout and labels
Progress Component
Basic Usage
Provide a value
between minValue
(default 0) and maxValue
(default 100).
1<Progress value={50} />
With Labels
Display a descriptive label
and/or a valueLabel
above the progress bar. The valueLabel
should be a string or ReactNode representing the current value (e.g., "50%", "Step 2 of 5").
1<View style={{ gap: 16 }}>
2 <Progress value={75} label="Task Completion" />
3 <Progress value={30} valueLabel="30%" />
4 <Progress value={60} label="Upload Progress" valueLabel="60/100MB" />
5</View>
Sizes
The component comes in three predefined sizes affecting its height: sm
, md
(default), and lg
.
1<View style={{ gap: 16, width: '80%' }}>
2 <Progress size="sm" value={30} label="Small (sm)" valueLabel="30%" />
3 <Progress size="md" value={60} label="Medium (md)" valueLabel="60%" />
4 <Progress size="lg" value={90} label="Large (lg)" valueLabel="90%" />
5</View>
Colors
Set the thematic color of the indicator using the color
prop. Supported colors: primary
(default), secondary
, success
, warning
, danger
, and default
.
1<View style={{ gap: 16, width: '80%' }}>
2 <Progress value={25} color="primary" label="Primary" />
3 <Progress value={40} color="secondary" label="Secondary" />
4 <Progress value={55} color="success" label="Success" />
5 <Progress value={70} color="warning" label="Warning" />
6 <Progress value={85} color="danger" label="Danger" />
7 <Progress value={50} color="default" label="Default" />
8</View>
Radius
Adjust the border radius of the track and indicator using the radius
prop. Options: none
, sm
, md
(default), lg
, full
(pill shape).
1<View style={{ gap: 16, width: '80%' }}>
2 <Progress value={50} radius="none" label="No Radius (none)" />
3 <Progress value={50} radius="sm" label="Small Radius (sm)" />
4 <Progress value={50} radius="md" label="Medium Radius (md)" />
5 <Progress value={50} radius="lg" label="Large Radius (lg)" />
6 <Progress value={50} radius="full" label="Full Radius (pill)" />
7</View>
Striped
Set isStriped
to true for a striped visual effect on the indicator. This uses expo-linear-gradient
.
isStriped
feature requires expo-linear-gradient
to be installed in your project.npm install expo-linear-gradient
or yarn add expo-linear-gradient
1<View style={{ gap: 16, width: '80%' }}>
2 <Progress value={70} isStriped label="Striped Primary" />
3 <Progress value={60} color="success" isStriped label="Striped Success" />
4</View>
Animation Control
Control the progress animation with disableAnimation
(boolean) and animationDuration
(number, in milliseconds).
1<View style={{ gap: 16, width: '80%' }}>
2 <Progress value={80} disableAnimation label="Animation Disabled" />
3 <Progress value={65} animationDuration={1000} label="Slow Animation (1s)" />
4 <Progress value={50} animationDuration={100} label="Fast Animation (0.1s)" />
5</View>
Props Overview
PROP | TYPE | DEFAULT | DESCRIPTION |
---|---|---|---|
label | ReactNode | - | Main label for the progress bar. |
size | ProgressSize | 'md' | Size (height) of the progress bar. |
color | ProgressColor | 'primary' | Thematic color of the indicator. |
radius | ProgressRadius | 'md' | Border radius of track and indicator. |
value | number | - | Current progress value. |
valueLabel | ReactNode | - | Label for the current value (e.g., "50%"). |
minValue | number | 0 | Minimum progress value. |
maxValue | number | 100 | Maximum progress value. |
isStriped | boolean | false | If true, indicator has a striped appearance. |
disableAnimation | boolean | false | If true, disables animation on value change. |
styles | ProgressSlotsStyles | - | Custom styles for internal slots. |
style | StyleProp<ViewStyle> | - | Style for the outermost container. |
animationDuration | number | 300 | Duration of animation in milliseconds. |
Styling
Customize the Progress component's appearance using the style
prop for the main container or the styles
prop for more granular control over internal elements (slots).
The styles
prop accepts an object where keys correspond to different parts of the component:
base
: The main wrapperView
.labelWrapper
: TheView
containing thelabel
andvalueLabel
.label
: The labelText
component.valueLabel
: The value labelText
component.track
: The backgroundView
of the progress bar.indicator
: The foregroundAnimated.View
showing the progress.
color
prop primarily determines the indicator's background color (or base colors for isStriped
). If you provide styles.indicator.backgroundColor
for a non-striped progress, it will override the color derived from the color
prop. For a striped progress, styles.indicator
applies to the container of the LinearGradient
, not the gradient colors themselves.1<Progress
2 value={75}
3 label="Custom Styled Progress"
4 valueLabel="75 Points"
5 color="warning" // Base color for indicator
6 size="lg"
7 radius="sm"
8 style={{ opacity: 0.9, marginVertical: 10 }} // Styles the outermost 'base' container
9 styles={{
10 base: { borderWidth: 1, borderColor: 'gray' },
11 labelWrapper: { marginBottom: 8 },
12 label: { color: 'purple', fontSize: 16, fontWeight: 'bold' },
13 valueLabel: { color: 'darkorange', fontStyle: 'italic' },
14 track: { backgroundColor: '#e0e0e0', height: 15 }, // Custom track
15 indicator: { borderWidth: 2, borderColor: 'black' } // Custom indicator styles (backgroundColor will be from 'color' prop)
16 }}
17/>
Accessibility
The Progress component includes accessibility features:
- The root
View
hasaccessibilityRole="progressbar"
. - Accessibility properties
accessibilityValue.min
,accessibilityValue.max
, andaccessibilityValue.now
are automatically set based on theminValue
,maxValue
, andvalue
props respectively. - If a
label
is provided, it serves as the primary accessibility label for the progress bar. Ensure it is descriptive. - The
valueLabel
can provide additional context to screen reader users if it's a string.