Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(Radial Progress): added size and thickness props and stories #92

Merged
merged 1 commit into from Apr 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 24 additions & 1 deletion src/RadialProgress/RadialProgress.stories.tsx
Expand Up @@ -8,10 +8,33 @@ export default {
component: RadialProgress,
} as Meta

export const Default: Story<RadialProgressProps> = (args) => {
const Template: Story<RadialProgressProps> = (args) => {
return <RadialProgress {...args}>{args.value}%</RadialProgress>
}

export const Default = Template.bind({})
Default.args = {
value: 75,
}

export const CustomColor = Template.bind({})
CustomColor.args = {
value: 75,
color: 'primary'
}

export const BackgroundColor = Template.bind({})
BackgroundColor.args = {
value: 75,
className: 'bg-primary text-primary-content border-4 border-primary'
}

export const CustomSizeAndThickness: Story<RadialProgressProps> = (args) => {
return (
<div className='flex items-center gap-4'>
<RadialProgress value={70} size='12rem' thickness='2px'>70%</RadialProgress>
<RadialProgress value={80} size='12rem' thickness='2rem'>80%</RadialProgress>
</div>
)
}
CustomSizeAndThickness.args = {}
31 changes: 27 additions & 4 deletions src/RadialProgress/RadialProgress.tsx
@@ -1,19 +1,42 @@
import React, { forwardRef } from 'react'
import clsx from 'clsx'
import { twMerge } from 'tailwind-merge'

import { IComponentBaseProps } from '../types'
import { ComponentColor, IComponentBaseProps } from '../types'

export type RadialProgressProps = React.HTMLAttributes<HTMLDivElement> &
IComponentBaseProps & {
value: number
size?: string
thickness?: string
color?: ComponentColor
}

const RadialProgress = forwardRef<HTMLDivElement, RadialProgressProps>(
({ value, dataTheme, className, children, ...props }, ref): JSX.Element => {
const classes = twMerge('radial-progress', className)
({
value,
size = '4rem',
thickness = '4px',
color,
dataTheme,
className,
children,
...props
}, ref): JSX.Element => {
const classes = twMerge(
'radial-progress',
className,
clsx({
[`text-${color}`]: color,
})
)

const displayedValue = Math.min(100, Math.max(0, value))
const progressStyle: Record<string, number> = { '--value': displayedValue }
const progressStyle: Record<string, string | number> = {
'--value': displayedValue,
'--size': size,
'--thickness': thickness,
}

return (
<div
Expand Down