-
Notifications
You must be signed in to change notification settings - Fork 439
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:
RadioGroup
component & story (#1478)
* feat: `RadioGroup` component & story * fix(RadioGroup): set text color only once
- Loading branch information
1 parent
14f0f25
commit 0913140
Showing
5 changed files
with
119 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 @@ | ||
import { Meta, StoryObj } from "@storybook/react" | ||
import { Label } from "./Label" | ||
import { RadioGroup, RadioGroupItem, RadioGroupProps } from "./RadioGroup" | ||
|
||
const RadioGroupExample = (props: RadioGroupProps) => ( | ||
<RadioGroup {...props} defaultValue="option-one"> | ||
<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> | ||
</RadioGroup> | ||
) | ||
|
||
const meta: Meta<typeof RadioGroupExample> = { | ||
title: "Design system/RadioGroup", | ||
component: RadioGroupExample, | ||
} | ||
|
||
export default meta | ||
|
||
type Story = StoryObj<typeof RadioGroupExample> | ||
|
||
export const Default: Story = { | ||
args: { | ||
disabled: false, | ||
}, | ||
argTypes: { | ||
disabled: { | ||
type: "boolean", | ||
control: "boolean", | ||
}, | ||
}, | ||
} |
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,47 @@ | ||
"use client" | ||
|
||
import { cn } from "@/lib/utils" | ||
import { Check } from "@phosphor-icons/react/dist/ssr" | ||
import * as RadioGroupPrimitive from "@radix-ui/react-radio-group" | ||
import { ComponentPropsWithoutRef, ElementRef, forwardRef } from "react" | ||
|
||
export type RadioGroupProps = ComponentPropsWithoutRef< | ||
typeof RadioGroupPrimitive.Root | ||
> | ||
|
||
const RadioGroup = forwardRef< | ||
ElementRef<typeof RadioGroupPrimitive.Root>, | ||
RadioGroupProps | ||
>(({ className, ...props }, ref) => { | ||
return ( | ||
<RadioGroupPrimitive.Root | ||
className={cn("grid gap-2", className)} | ||
{...props} | ||
ref={ref} | ||
/> | ||
) | ||
}) | ||
RadioGroup.displayName = RadioGroupPrimitive.Root.displayName | ||
|
||
const RadioGroupItem = forwardRef< | ||
ElementRef<typeof RadioGroupPrimitive.Item>, | ||
ComponentPropsWithoutRef<typeof RadioGroupPrimitive.Item> | ||
>(({ className, ...props }, ref) => { | ||
return ( | ||
<RadioGroupPrimitive.Item | ||
ref={ref} | ||
className={cn( | ||
"relative size-4 cursor-pointer rounded-full border-2 border-border text-white focus:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:border-0 data-[state=checked]:bg-primary [&~label]:cursor-pointer [&~label]:disabled:opacity-50", | ||
className | ||
)} | ||
{...props} | ||
> | ||
<RadioGroupPrimitive.Indicator className="absolute inset-0 flex items-center justify-center rounded-full bg-primary"> | ||
<Check className="size-3" weight="bold" /> | ||
</RadioGroupPrimitive.Indicator> | ||
</RadioGroupPrimitive.Item> | ||
) | ||
}) | ||
RadioGroupItem.displayName = RadioGroupPrimitive.Item.displayName | ||
|
||
export { RadioGroup, RadioGroupItem } |