Progress
tetra-ui/progressFreeComponent
Displays an indicator showing the completion progress of a task.
Live preview
live · rendered by the registry
Rendered by tetra-ui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://tetra-ui.com/r/progress.jsonSource
1import { cva, type VariantProps } from "class-variance-authority";2import { createContext, useContext, useEffect, useMemo } from "react";3import { View } from "react-native";4import Animated, {5 Easing,6 useAnimatedStyle,7 useSharedValue,8 withTiming,9} from "react-native-reanimated";10import { cn } from "@/lib/utils";11import { Text } from "./text";1213// Constants14const ANIMATION_DURATION = 320;15const ANIMATION_EASING = Easing.out(Easing.cubic);1617// Types18type ProgressContextValue = VariantProps<typeof progressVariants> & {19 value: number;20 max: number;21};2223type ProgressProps = React.ComponentProps<typeof View> &24 VariantProps<typeof progressVariants> & {25 value?: number | null;26 max?: number;27 };2829// Context30const ProgressContext = createContext<ProgressContextValue | null>(null);3132const useProgress = () => {33 const context = useContext(ProgressContext);34 if (!context) {35 throw new Error("Progress components must be used within Progress");36 }37 return context;38};3940export function Progress({41 className,42 children,43 value,44 max = 100,45 variant = "linear",46 ...props47}: ProgressProps) {48 const normalizedValue = value ?? 0;4950 const ctx = useMemo(51 () => ({52 max,53 value: normalizedValue,54 variant,55 }),56 [max, normalizedValue, variant]57 );5859 return (60 <ProgressContext.Provider value={ctx}>61 <View62 accessibilityRole="progressbar"63 accessibilityValue={{64 max,65 min: 0,66 now: normalizedValue,67 }}68 className={cn("flex w-full flex-wrap gap-3", className)}69 data-slot="progress"70 {...props}71 >72 {children}73 {variant === "steps" ? (74 <ProgressSteps />75 ) : (76 <ProgressTrack>77 <ProgressIndicator />78 </ProgressTrack>79 )}80 </View>81 </ProgressContext.Provider>82 );83}8485function ProgressTrack({86 className,87 ...props88}: React.ComponentProps<typeof View>) {89 return (90 <View91 className={cn(92 progressVariants({ variant: "linear" }),93 "relative w-full overflow-hidden rounded-full bg-muted",94 className95 )}96 data-slot="progress-track"97 style={{ borderCurve: "continuous" }}98 {...props}99 />100 );101}102103function ProgressIndicator({104 className,105 ...props106}: React.ComponentProps<typeof Animated.View>) {107 const { max, value } = useProgress();108 const targetProgress = max > 0 ? value / max : 0;109// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from tetra-ui
All 41 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | tetra-ui | Components | Free | 1 dep | |
| Action Inputaction-input | tetra-ui | Components | Free | no deps | |
| Alertalert | tetra-ui | Components | Free | no deps | |
| Avataravatar | tetra-ui | Components | Free | no deps | |
| Badgebadge | tetra-ui | Components | Free | no deps | |
| Bottom Sheetbottom-sheet | tetra-ui | Components | Free | 4 deps · 7 files | |
| Buttonbutton | tetra-ui | Components | Free | no deps | |
| Cardcard | tetra-ui | Components | Free | no deps |
