Progress Bar
dashboardblocks/progress-barFreeComponent
A progress bar component.
Live preview
live · rendered by the registry
Rendered by dashboardblocks on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://dashboardblocks.com/r/progress-bar.jsonSource
1'use client'23import { useInView } from '@/registry/hooks/use-in-view'4import { useEffect, useState } from 'react'56import { cn } from '@/lib/utils'78export interface ProgressBarProps {9 className?: string10 fillClassName?: string11 percentage: number12}1314export const ProgressBar = ({15 className,16 percentage,17 fillClassName,18}: ProgressBarProps) => {19 const [width, setWidth] = useState(0)20 const { isInView, ref } = useInView()2122 const safePercentage = Number.isFinite(percentage) ? percentage : 023 const normalized = Math.min(100, Math.max(0, safePercentage))2425 useEffect(() => {26 if (isInView) {27 // Small delay to ensure the initial render happens at 028 const timer = requestAnimationFrame(() => {29 setWidth(normalized)30 })31 return () => cancelAnimationFrame(timer)32 }33 }, [isInView, normalized])3435 return (36 <div37 ref={ref as React.RefObject<HTMLDivElement>}38 className={cn('h-2 w-full rounded-full bg-muted', className)}39 >40 <div41 className={cn(42 'h-full rounded-full bg-primary transition-width! duration-1000 ease-out-expo',43 fillClassName,44 )}45 style={{ width: `${width}%` }}46 />47 </div>48 )49}5051export interface SegmentedProgressBarProps {52 className?: string53 segments: Array<{54 color?: string55 label?: string56 value: number57 }>58 total: number59}6061export const SegmentedProgressBar = ({62 className,63 segments,64 total,65}: SegmentedProgressBarProps) => {66 const [animatedMultiplier, setAnimatedMultiplier] = useState(0)67 const { isInView, ref } = useInView()68 const safeTotal = total > 0 ? total : 16970 useEffect(() => {71 if (isInView) {72 // Small delay to ensure the initial render happens at 073 const timer = requestAnimationFrame(() => {74 setAnimatedMultiplier(1)75 })76 return () => cancelAnimationFrame(timer)77 }78 }, [isInView])7980 return (81 <div82 ref={ref as React.RefObject<HTMLDivElement>}83 className={cn('flex h-2 w-full overflow-hidden rounded-full bg-muted', className)}84 >85 {segments.map((segment, index) => {86 const percentage = (segment.value / safeTotal) * 10087 const animatedWidth = Math.max(0, percentage) * animatedMultiplier88 return (89 <div90 key={segment.label || index}91 className='h-full transition-width! duration-1000 ease-out-expo first:rounded-l-full last:rounded-r-full'92 style={{93// … truncated
What it pulls in
Other registry items
Files it writes
More from dashboardblocks
All 36 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Activity Feedactivity-feed | dashboardblocks | Components | Free | 1 dep | |
| activity-feed-01activity-feed-01 | dashboardblocks | Components | Free | 1 dep | |
| activity-feed-02activity-feed-02 | dashboardblocks | Components | Free | 1 dep | |
| activity-feed-03activity-feed-03 | dashboardblocks | Components | Free | 1 dep | |
| activity-feed-04activity-feed-04 | dashboardblocks | Components | Free | 1 dep | |
| activity-feed-05activity-feed-05 | dashboardblocks | Components | Free | 1 dep | |
| Animated Numberanimated-number | dashboardblocks | Components | Free | no deps | |
| Animated Waveanimated-wave | dashboardblocks | Components | Free | no deps |
