Progress
The Progress component displays a linear progress bar, ideal for showing task completion, loading states, or any quantifiable progression.
Installation
$ cbui-cli install progresscbui-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 labelsisGlass feature for the progress track uses expo-blur. Ensure this library is installed and linked if you plan to use this feature.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-gradient1<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>Glass Track Effect
Apply a frosted glass effect to the progress bar's track (background) using isGlass. Customize it with glassIntensity (0-100) and glassTint ('light', 'dark', 'default'). When isGlass is true, the track's direct background color becomes transparent, and a BlurView provides the visual effect. Label and value label colors default to the theme's foreground color for better contrast on the blurred background. For dark glass tints, you might need to manually set label colors via the styles prop. The indicator renders on top of this glass track.
1<View style={{ gap: 16, width: '80%', padding: 10, backgroundColor: 'rgba(0,0,0,0.1)' /* Example background */ }}>
2 <Progress
3 value={70}
4 isGlass
5 glassIntensity={80}
6 glassTint="light"
7 label="Light Glass Track"
8 valueLabel="70%"
9 />
10 <Progress
11 value={50}
12 isGlass
13 glassIntensity={50}
14 glassTint="dark"
15 label="Dark Glass Track"
16 valueLabel="50%"
17 styles={{ label: { color: 'white' }, valueLabel: { color: 'white' } }} // Example: manual text color for dark glass
18 />
19</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. |
isGlass | boolean | false | Apply glassmorphism effect to the track background. |
glassTint | 'default' | 'light' | 'dark' | Theme-derived | Tint for the glass effect on the track. |
glassIntensity | number | 30 | Intensity (0-100) for the glass effect on the track. |
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: TheViewcontaining thelabelandvalueLabel.label: The labelTextcomponent.valueLabel: The value labelTextcomponent.track: The backgroundViewof the progress bar.indicator: The foregroundAnimated.Viewshowing the progress.- When
isGlassis true, aBlurViewis rendered as the background for thetrack. Thetrackstyle'sbackgroundColorwill be set to transparent.
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
ViewhasaccessibilityRole="progressbar". - Accessibility properties
accessibilityValue.min,accessibilityValue.max, andaccessibilityValue.noware automatically set based on theminValue,maxValue, andvalueprops respectively. - If a
labelis provided, it serves as the primary accessibility label for the progress bar. Ensure it is descriptive. - The
valueLabelcan provide additional context to screen reader users if it's a string.