Directory
- Welcome
Progress Component
The Progress component provides visual feedback for ongoing processes in your application. With smooth animations and state management, it helps users understand the completion status of tasks.
Key Features
-
Multiple Sizes: Small, medium, and large variants
-
State Management: Success and error states
-
Smooth Animations: Built-in transitions
-
Accessible: Semantic HTML with ARIA support
Basic Usage
<Progress value={0.5} max={1} label="Basic Progress" />
Variants
Size Options
<Progress value={75} max={100} size="sm" label="Small Progress" /><Progress value={75} max={100} size="md" label="Medium Progress" /><Progress value={75} max={100} size="lg" label="Large Progress" />
State Variants
<Progress value={100} max={100} data-state="success" label="Success State" /><Progress value={30} max={100} data-state="error" label="Error State" />
Props API
Prop | Type | Default | Description |
---|---|---|---|
label | string | Label text for the progress bar | |
size | 'sm' | 'md' | 'lg' | md | Size variant of the progress bar |
Progress Functions API
The Progress component exposes methods for programmatic control:
// Get progress instanceconst progress = document.querySelector('progress-wrapper');
// Update progressprogress.setProgress(0.75); // Set to 75%
// Reset progressprogress.resetProgress();
// Set stateprogress.setState('success');progress.setState('error');
Animated Progress Example
Here’s how to create an animated progress bar:
import { ready } from '@/components/NST-components/base';import type { ProgressElement } from '@/components/NST-components/UI/progress/data';
const progressBars = await ready( document.querySelector<ProgressElement>('progress-wrapper'));
function animateProgress() { let currentValue = 0; const interval = setInterval(() => { currentValue += 0.005; // Increment by 0.005 every 20ms if (progressBars) { progressBars.progress = currentValue; }
if (currentValue >= 1) { clearInterval(interval); // Wait 2 seconds then reset and start again setTimeout(() => { if (progressBars) { progressBars.reset(); } setTimeout(() => { animateProgress(); }, 100); }, 2000); } }, 20);}
// Start the animationanimateProgress();
Limited Time Launch Sale
Add professional progress indicators to your website with our AstroJS starter template. Get started now!
GET 60% OFF!