-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgress.tsx
More file actions
57 lines (52 loc) · 1.45 KB
/
Progress.tsx
File metadata and controls
57 lines (52 loc) · 1.45 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
import * as ProgressPrimitive from '@radix-ui/react-progress';
import { cva, type VariantProps } from 'class-variance-authority';
import * as React from 'react';
import { cn } from '../../lib/utils';
const track = cva('relative w-full overflow-hidden rounded-full', {
variants: {
variant: {
profile: 'h-[0.4rem] bg-gray100',
tree: 'h-[1.2rem] bg-gray100',
},
},
defaultVariants: { variant: 'profile' },
});
const indicator = cva(
'h-full rounded-full transition-[width] duration-300 ease-out',
{
variants: {
variant: {
profile: 'bg-main400',
tree: 'bg-gradient-to-r from-gradient-start to-gradient-end',
},
},
defaultVariants: { variant: 'profile' },
}
);
export interface ProgressProps
extends Omit<
React.ComponentProps<typeof ProgressPrimitive.Root>,
'value' | 'max'
>,
VariantProps<typeof track> {
value: number;
}
function Progress({ className, variant, value, ...props }: ProgressProps) {
const progressPercent = Math.max(0, Math.min(100, value));
return (
<ProgressPrimitive.Root
data-slot="progress"
className={cn(track({ variant }), className)}
value={progressPercent}
max={100}
{...props}
>
<ProgressPrimitive.Indicator
data-slot="progress-indicator"
className={indicator({ variant })}
style={{ width: `${progressPercent}%` }}
/>
</ProgressPrimitive.Root>
);
}
export default Progress;