-
-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui): update Progress to use Ark UI and add Progress Circular
- Loading branch information
1 parent
0205113
commit a18660a
Showing
7 changed files
with
225 additions
and
18 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@tszhong0411/ui': patch | ||
--- | ||
|
||
Update Progress to use Ark UI and add Progress Circular |
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
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
'use client' | ||
|
||
import { | ||
Progress, | ||
ProgressCircle, | ||
ProgressCircleRange, | ||
ProgressCircleTrack, | ||
ProgressLabel, | ||
ProgressValueText | ||
} from '@tszhong0411/ui' | ||
import { useEffect, useState } from 'react' | ||
|
||
const ProgressCircularDemo = () => { | ||
const [progress, setProgress] = useState(13) | ||
|
||
useEffect(() => { | ||
const timer = setTimeout(() => { | ||
setProgress(66) | ||
}, 500) | ||
|
||
return () => { | ||
clearTimeout(timer) | ||
} | ||
}, []) | ||
return ( | ||
<Progress value={progress}> | ||
<ProgressLabel>Label</ProgressLabel> | ||
<ProgressCircle> | ||
<ProgressCircleTrack /> | ||
<ProgressCircleRange /> | ||
</ProgressCircle> | ||
<ProgressValueText /> | ||
</Progress> | ||
) | ||
} | ||
|
||
export default ProgressCircularDemo |
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,22 +1,32 @@ | ||
'use client' | ||
|
||
import { Progress } from '@tszhong0411/ui' | ||
import { Progress, ProgressRange, ProgressTrack, ProgressValueText } from '@tszhong0411/ui' | ||
import { useEffect, useState } from 'react' | ||
|
||
const ProgressDemo = () => { | ||
const [progress, setProgress] = useState(13) | ||
const [progress, setProgress] = useState(0) | ||
|
||
useEffect(() => { | ||
const timer = setTimeout(() => { | ||
setProgress(66) | ||
}, 500) | ||
const interval = setInterval(() => { | ||
setProgress((value) => (value === 100 ? 0 : value + 1)) | ||
// eslint-disable-next-line sonarjs/pseudo-random -- it's safe | ||
}, Math.random() * 500) | ||
|
||
return () => { | ||
clearTimeout(timer) | ||
clearInterval(interval) | ||
} | ||
}, []) | ||
|
||
return <Progress aria-label='Loading...' value={progress} className='max-w-md' /> | ||
return ( | ||
<Progress value={progress} min={0} max={100} className='w-3/5 max-w-md'> | ||
<ProgressTrack> | ||
<ProgressRange /> | ||
</ProgressTrack> | ||
<div className='w-full text-center'> | ||
<ProgressValueText /> | ||
</div> | ||
</Progress> | ||
) | ||
} | ||
|
||
export default ProgressDemo |
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use client' | ||
|
||
import { Progress, ProgressLabel, ProgressRange, ProgressTrack } from '@tszhong0411/ui' | ||
import { useEffect, useState } from 'react' | ||
|
||
const ProgressWithLabelDemo = () => { | ||
const [progress, setProgress] = useState(13) | ||
|
||
useEffect(() => { | ||
const timer = setTimeout(() => { | ||
setProgress(66) | ||
}, 500) | ||
|
||
return () => { | ||
clearTimeout(timer) | ||
} | ||
}, []) | ||
|
||
return ( | ||
<Progress value={progress} className='w-3/5 max-w-md'> | ||
<ProgressLabel>Label</ProgressLabel> | ||
<ProgressTrack> | ||
<ProgressRange /> | ||
</ProgressTrack> | ||
</Progress> | ||
) | ||
} | ||
|
||
export default ProgressWithLabelDemo |
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use client' | ||
|
||
import { Progress, ProgressRange, ProgressTrack, ProgressValueText } from '@tszhong0411/ui' | ||
import { useEffect, useState } from 'react' | ||
|
||
const ProgressWithValueDemo = () => { | ||
const [progress, setProgress] = useState(13) | ||
|
||
useEffect(() => { | ||
const timer = setTimeout(() => { | ||
setProgress(66) | ||
}, 500) | ||
|
||
return () => { | ||
clearTimeout(timer) | ||
} | ||
}, []) | ||
|
||
return ( | ||
<Progress value={progress} className='w-3/5 max-w-md'> | ||
<ProgressTrack> | ||
<ProgressRange /> | ||
</ProgressTrack> | ||
<ProgressValueText /> | ||
</Progress> | ||
) | ||
} | ||
|
||
export default ProgressWithValueDemo |
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,24 +1,103 @@ | ||
'use client' | ||
|
||
import * as ProgressPrimitive from '@radix-ui/react-progress' | ||
import { Progress as ProgressPrimitive } from '@ark-ui/react' | ||
import { cn } from '@tszhong0411/utils' | ||
|
||
type ProgressProps = React.ComponentProps<typeof ProgressPrimitive.Root> | ||
|
||
const Progress = (props: ProgressProps) => { | ||
const { className, value, ...rest } = props | ||
const { className, ...rest } = props | ||
|
||
return ( | ||
<ProgressPrimitive.Root | ||
className={cn('[--size:96px] [--thickness:12px]', className)} | ||
{...rest} | ||
/> | ||
) | ||
} | ||
|
||
type ProgressLabelProps = React.ComponentProps<typeof ProgressPrimitive.Label> | ||
|
||
const ProgressLabel = (props: ProgressLabelProps) => { | ||
const { className, ...rest } = props | ||
|
||
return ( | ||
<ProgressPrimitive.Label | ||
className={cn('text-sm font-medium leading-none', className)} | ||
{...rest} | ||
/> | ||
) | ||
} | ||
|
||
type ProgressTrackProps = React.ComponentProps<typeof ProgressPrimitive.Track> | ||
|
||
const ProgressTrack = (props: ProgressTrackProps) => { | ||
const { className, ...rest } = props | ||
|
||
return ( | ||
<ProgressPrimitive.Track | ||
className={cn('bg-secondary relative h-3 w-full overflow-hidden rounded-full', className)} | ||
{...rest} | ||
> | ||
<ProgressPrimitive.Indicator | ||
className='bg-primary size-full flex-1 transition-all' | ||
style={{ transform: `translateX(-${100 - (value ?? 0)}%)` }} | ||
/> | ||
</ProgressPrimitive.Root> | ||
/> | ||
) | ||
} | ||
|
||
type ProgressRangeProps = React.ComponentProps<typeof ProgressPrimitive.Range> | ||
|
||
const ProgressRange = (props: ProgressRangeProps) => { | ||
const { className, ...rest } = props | ||
|
||
return ( | ||
<ProgressPrimitive.Range | ||
className={cn('bg-primary size-full flex-1 transition-all', className)} | ||
{...rest} | ||
/> | ||
) | ||
} | ||
|
||
export { Progress } | ||
type ProgressValueTextProps = React.ComponentProps<typeof ProgressPrimitive.ValueText> | ||
|
||
const ProgressValueText = (props: ProgressValueTextProps) => { | ||
const { className, ...rest } = props | ||
|
||
return ( | ||
<ProgressPrimitive.ValueText | ||
className={cn('text-muted-foreground text-sm', className)} | ||
{...rest} | ||
/> | ||
) | ||
} | ||
|
||
const ProgressCircle = ProgressPrimitive.Circle | ||
|
||
type ProgressCircleTrackProps = React.ComponentProps<typeof ProgressPrimitive.CircleTrack> | ||
|
||
const ProgressCircleTrack = (props: ProgressCircleTrackProps) => { | ||
const { className, ...rest } = props | ||
|
||
return <ProgressPrimitive.CircleTrack className={cn('stroke-secondary', className)} {...rest} /> | ||
} | ||
|
||
type ProgressCircleRangeProps = React.ComponentProps<typeof ProgressPrimitive.CircleRange> | ||
|
||
const ProgressCircleRange = (props: ProgressCircleRangeProps) => { | ||
const { className, ...rest } = props | ||
|
||
return ( | ||
<ProgressPrimitive.CircleRange | ||
className={cn('stroke-primary transition-all', className)} | ||
{...rest} | ||
/> | ||
) | ||
} | ||
|
||
export { | ||
Progress, | ||
ProgressCircle, | ||
ProgressCircleRange, | ||
ProgressCircleTrack, | ||
ProgressLabel, | ||
ProgressRange, | ||
ProgressTrack, | ||
ProgressValueText | ||
} |