Progress
Displays the status of a task that takes a long time.
Loading
"use client";
import { useState, useEffect } from "react";
import {
Progress,
ProgressLabel,
ProgressTrack,
ProgressIndicator,
ProgressValue,
} from "@/components/ui/progress/progress";
import styles from "./progress-demo.module.css";
export default function ProgressDemo() {
const [progress, setProgress] = useState(0);
useEffect(() => {
const interval = setInterval(() => {
setProgress((current) => {
if (current >= 100) {
clearInterval(interval);
return 100;
}
return Math.min(100, Math.round(current + Math.random() * 25));
});
}, 1000);
return () => clearInterval(interval);
}, []);
return (
<Progress value={progress} className={styles.progress}>
<div className={styles.progressHeader}>
<ProgressLabel>Loading</ProgressLabel>
<ProgressValue />
</div>
<ProgressTrack>
<ProgressIndicator />
</ProgressTrack>
</Progress>
);
}
Installation
npx shadcn@latest add https://roiui.com/r/progress.json
Anatomy
anatomy
import {
Progress,
ProgressLabel,
ProgressTrack,
ProgressIndicator,
ProgressValue,
} from '../ui/progress'
<Progress value={50}>
<ProgressLabel>Loading</ProgressLabel>
<ProgressValue />
<ProgressTrack>
<ProgressIndicator />
</ProgressTrack>
</Progress>