-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d3270b2
commit 5f262c3
Showing
1 changed file
with
21 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,41 @@ | ||
import * as ProgressPrimitive from '@radix-ui/react-progress' | ||
import { cva, VariantProps } from 'class-variance-authority' | ||
|
||
import { Atoms } from '~/css' | ||
const progressIndicatorVariants = cva('h-full rounded-full', { | ||
variants: { | ||
color: { | ||
positive: 'bg-positive', | ||
info: 'bg-info', | ||
warning: 'bg-warning', | ||
negative: 'bg-negative', | ||
}, | ||
}, | ||
defaultVariants: { | ||
color: 'positive', | ||
}, | ||
}) | ||
|
||
import { Box } from '../Box' | ||
|
||
interface ProgressProps { | ||
interface ProgressProps extends VariantProps<typeof progressIndicatorVariants> { | ||
value: number // Ratio between 0 and 1 | ||
color?: Atoms['color'] | ||
} | ||
|
||
export const Progress = (props: ProgressProps) => { | ||
const { value, color = 'positive' } = props | ||
const { value, color } = props | ||
const percent = Math.min(value * 100, 100) | ||
|
||
return ( | ||
<Box | ||
as={ProgressPrimitive.Root} | ||
<ProgressPrimitive.Root | ||
value={percent} | ||
borderRadius="circle" | ||
background="backgroundPrimary" | ||
width="full" | ||
height="1" | ||
overflow="hidden" | ||
position="relative" | ||
className="h-1 w-full rounded-full bg-background-primary overflow-hidden relative" | ||
> | ||
<Box | ||
as={ProgressPrimitive.ProgressIndicator} | ||
<ProgressPrimitive.ProgressIndicator | ||
className={progressIndicatorVariants({ color })} | ||
style={{ | ||
width: `${percent}%`, | ||
transition: 'width 660ms cubic-bezier(0.65, 0, 0.35, 1)', | ||
backgroundSize: '300% 100%', | ||
}} | ||
height="full" | ||
borderRadius="circle" | ||
background={color} | ||
/> | ||
</Box> | ||
</ProgressPrimitive.Root> | ||
) | ||
} |