forked from FlowwStar/FlowStar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogress-bar.tsx
More file actions
60 lines (57 loc) · 1.57 KB
/
Copy pathprogress-bar.tsx
File metadata and controls
60 lines (57 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { cn } from '@/lib/utils'
interface ProgressBarProps {
/** 0–1 */
value: number
className?: string
/** Optional secondary marker (0–1), e.g. withdrawn portion. */
marker?: number
indeterminateShimmer?: boolean
/** Height variant. @default 'default' */
size?: 'sm' | 'default' | 'lg'
}
/** Shows the % of a stream that has unlocked, with an optional withdrawn marker. */
export function ProgressBar({
value,
className,
marker,
indeterminateShimmer,
size = 'default',
}: ProgressBarProps) {
const sizeClasses = {
sm: 'h-1',
default: 'h-2',
lg: 'h-3',
}
const pct = Math.min(Math.max(value, 0), 1) * 100
const markerPct =
marker != null ? Math.min(Math.max(marker, 0), 1) * 100 : null
return (
<div
role="progressbar"
aria-valuenow={Math.round(pct)}
aria-valuemin={0}
aria-valuemax={100}
className={cn(
'relative w-full overflow-hidden rounded-full bg-secondary',
sizeClasses[size],
className,
)}
>
<div
className="absolute inset-y-0 left-0 rounded-full bg-primary transition-[width] duration-700 ease-out"
style={{ width: `${pct}%` }}
>
{indeterminateShimmer && pct > 0 && pct < 100 && (
<div className="absolute inset-0 animate-pulse rounded-full bg-primary/40" />
)}
</div>
{markerPct != null && markerPct > 0 && (
<div
className="absolute inset-y-0 w-0.5 bg-foreground/70"
style={{ left: `calc(${markerPct}% - 1px)` }}
aria-hidden
/>
)}
</div>
)
}