Progress
Displays an indicator showing the completion progress of a task.
Installation
bash npx @moe/cli add progress Install the following dependency:
npx expo install @rn-primitives/progressCopy/paste the following code to @/components/ui/progress.tsx
import * as ProgressPrimitive from "@rn-primitives/progress";
import * as React from "react";
import { View } from "react-native";
import { cn } from "@/lib/utils";
const Progress = React.forwardRef<
React.ElementRef<typeof ProgressPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof ProgressPrimitive.Root>
>(({ className, value, ...props }, ref) => (
<ProgressPrimitive.Root
ref={ref}
className={cn(
"relative h-4 w-full overflow-hidden rounded-full bg-secondary",
className,
)}
{...props}
>
<ProgressPrimitive.Indicator
className="h-full w-full flex-1 bg-primary web:transition-all"
style={{ transform: [{ translateX: `-${100 - (value || 0)}%` }] }}
/>
</ProgressPrimitive.Root>
));
Progress.displayName = ProgressPrimitive.Root.displayName;
export { Progress };Usage
import { Progress } from "@moe/registry/ui/progress";
import * as React from "react";
import { View } from "react-native";
export function ProgressDemo() {
const [progress, setProgress] = React.useState(13);
React.useEffect(() => {
const timer = setTimeout(() => setProgress(66), 500);
return () => clearTimeout(timer);
}, []);
return (
<View className="w-full max-w-sm">
<Progress value={progress} />
</View>
);
}Props
| Prop | Type | Default | Description |
|---|---|---|---|
value | number | 0 | The progress value (0-100) |
max | number | 100 | The maximum value |