-
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.
feat(components): Progress and Radio Group components
- Loading branch information
Showing
6 changed files
with
237 additions
and
0 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
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,57 @@ | ||
import { Meta, StoryObj } from "@storybook/react"; | ||
|
||
import { Progress, ProgressProps } from "@/components/ui/progress"; | ||
|
||
const meta: Meta<ProgressProps> = { | ||
component: Progress, | ||
title: "Progress", | ||
args: { | ||
value: 20, | ||
className: "", | ||
}, | ||
argTypes: { | ||
value: { | ||
type: "string", | ||
control: "number", | ||
}, | ||
className: { | ||
type: "string", | ||
control: "text", | ||
}, | ||
}, | ||
}; | ||
type Story = StoryObj<ProgressProps>; | ||
|
||
const Render = (args: ProgressProps) => <Progress {...args} />; | ||
|
||
export const LightMode: Story = { | ||
args: { | ||
value: 20, | ||
className: "", | ||
}, | ||
parameters: { | ||
backgrounds: { | ||
default: "light", | ||
}, | ||
}, | ||
render: Render, | ||
}; | ||
|
||
export const DarkMode: Story = { | ||
args: { | ||
value: 20, | ||
className: "", | ||
}, | ||
parameters: { | ||
backgrounds: { | ||
default: "dark", | ||
}, | ||
}, | ||
render: (args) => ( | ||
<div className="dark"> | ||
<Render {...args} /> | ||
</div> | ||
), | ||
}; | ||
|
||
export default meta; |
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,26 @@ | ||
"use client"; | ||
|
||
import { Indicator, Root } from "@radix-ui/react-progress"; | ||
import React from "react"; | ||
|
||
import { cn } from "@/lib/utils"; | ||
|
||
export type ProgressProps = React.ComponentPropsWithoutRef<typeof Root>; | ||
|
||
const Progress = React.forwardRef<React.ElementRef<typeof Root>, ProgressProps>( | ||
({ className, value, ...props }, ref) => ( | ||
<Root | ||
ref={ref} | ||
className={cn("relative h-2 w-full overflow-hidden rounded-full bg-primary/20", className)} | ||
{...props} | ||
> | ||
<Indicator | ||
className="h-full w-full flex-1 bg-primary transition-all" | ||
style={{ transform: `translateX(-${100 - (value || 0)}%)` }} | ||
/> | ||
</Root> | ||
), | ||
); | ||
Progress.displayName = Root.displayName; | ||
|
||
export { Progress }; |
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,66 @@ | ||
import { Meta, StoryObj } from "@storybook/react"; | ||
|
||
import { Label } from "@/components/ui/label"; | ||
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"; | ||
|
||
const meta: Meta = { | ||
component: RadioGroup, | ||
title: "Radio Group", | ||
args: { | ||
className: "", | ||
}, | ||
argTypes: { | ||
className: { | ||
type: "string", | ||
control: "text", | ||
}, | ||
}, | ||
}; | ||
type Story = StoryObj; | ||
|
||
const Render = (args: object) => ( | ||
<RadioGroup defaultValue="option-one" {...args}> | ||
<div className="flex items-center space-x-2"> | ||
<RadioGroupItem value="option-one" id="option-one" /> | ||
<Label htmlFor="option-one">Option One</Label> | ||
</div> | ||
<div className="flex items-center space-x-2"> | ||
<RadioGroupItem value="option-two" id="option-two" /> | ||
<Label htmlFor="option-two">Option Two</Label> | ||
</div> | ||
<div className="flex items-center space-x-2"> | ||
<RadioGroupItem value="option-three" id="option-three" /> | ||
<Label htmlFor="option-three">Option Three</Label> | ||
</div> | ||
</RadioGroup> | ||
); | ||
|
||
export const LightMode: Story = { | ||
args: { | ||
className: "", | ||
}, | ||
parameters: { | ||
backgrounds: { | ||
default: "light", | ||
}, | ||
}, | ||
render: Render, | ||
}; | ||
|
||
export const DarkMode: Story = { | ||
args: { | ||
className: "", | ||
}, | ||
parameters: { | ||
backgrounds: { | ||
default: "dark", | ||
}, | ||
}, | ||
render: (args) => ( | ||
<div className="dark"> | ||
<Render {...args} /> | ||
</div> | ||
), | ||
}; | ||
|
||
export default meta; |
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,36 @@ | ||
"use client"; | ||
|
||
import { CheckIcon } from "@radix-ui/react-icons"; | ||
import { Indicator, Item, Root } from "@radix-ui/react-radio-group"; | ||
import React from "react"; | ||
|
||
import { cn } from "@/lib/utils"; | ||
|
||
const RadioGroup = React.forwardRef<React.ElementRef<typeof Root>, React.ComponentPropsWithoutRef<typeof Root>>( | ||
({ className, ...props }, ref) => { | ||
return <Root className={cn("grid gap-2", className)} {...props} ref={ref} />; | ||
}, | ||
); | ||
RadioGroup.displayName = Root.displayName; | ||
|
||
const RadioGroupItem = React.forwardRef<React.ElementRef<typeof Item>, React.ComponentPropsWithoutRef<typeof Item>>( | ||
({ className, ...props }, ref) => { | ||
return ( | ||
<Item | ||
ref={ref} | ||
className={cn( | ||
"aspect-square h-4 w-4 rounded-full border border-primary text-primary shadow focus:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50", | ||
className, | ||
)} | ||
{...props} | ||
> | ||
<Indicator className="flex items-center justify-center"> | ||
<CheckIcon className="h-3.5 w-3.5 fill-primary" /> | ||
</Indicator> | ||
</Item> | ||
); | ||
}, | ||
); | ||
RadioGroupItem.displayName = Item.displayName; | ||
|
||
export { RadioGroup, RadioGroupItem }; |
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