Skip to content

Commit ccc043b

Browse files
feat: Add Radio Group (#90)
1 parent 4f91343 commit ccc043b

File tree

7 files changed

+213
-0
lines changed

7 files changed

+213
-0
lines changed

.changeset/happy-goats-itch.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@zenml-io/react-component-library": minor
3+
---
4+
5+
add radio group

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
"@radix-ui/react-dropdown-menu": "^2.0.6",
6262
"@radix-ui/react-hover-card": "^1.1.1",
6363
"@radix-ui/react-progress": "^1.0.3",
64+
"@radix-ui/react-radio-group": "^1.2.0",
6465
"@radix-ui/react-scroll-area": "^1.1.0",
6566
"@radix-ui/react-select": "^2.0.0",
6667
"@radix-ui/react-slot": "^1.0.2",

pnpm-lock.yaml

+120
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { Meta } from "@storybook/react";
2+
import React from "react";
3+
import { RadioGroup, RadioGroupItem } from "./index";
4+
import { StoryObj } from "@storybook/react";
5+
6+
const meta = {
7+
title: "Elements/Radio Group",
8+
component: RadioGroup,
9+
decorators: [
10+
(Story) => (
11+
<div className="w-[400px] flex items-center justify-center bg-theme-surface-primary h-[200px]">
12+
<Story />
13+
</div>
14+
)
15+
],
16+
parameters: {
17+
layout: "centered"
18+
},
19+
20+
tags: ["autodocs"]
21+
} satisfies Meta<typeof RadioGroup>;
22+
23+
export default meta;
24+
25+
type Story = StoryObj<typeof meta>;
26+
27+
export const DefaultVariant: Story = {
28+
name: "Default",
29+
render: () => (
30+
<RadioGroup defaultValue="option-one">
31+
<div className="flex items-center space-x-2">
32+
<RadioGroupItem value="option-one" id="option-one" />
33+
<label htmlFor="option-one">Option One</label>
34+
</div>
35+
<div className="flex items-center space-x-2">
36+
<RadioGroupItem value="option-two" id="option-two" />
37+
<label htmlFor="option-two">Option Two</label>
38+
</div>
39+
<div className="flex items-center space-x-2">
40+
<RadioGroupItem disabled value="option-three" id="option-three" />
41+
<label htmlFor="option-three">Option disabled</label>
42+
</div>
43+
</RadioGroup>
44+
)
45+
};
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import * as React from "react";
2+
import * as RadioGroupPrimitive from "@radix-ui/react-radio-group";
3+
import { cn } from "../../utilities";
4+
5+
const RadioGroup = React.forwardRef<
6+
React.ElementRef<typeof RadioGroupPrimitive.Root>,
7+
React.ComponentPropsWithoutRef<typeof RadioGroupPrimitive.Root>
8+
>(({ className, ...props }, ref) => {
9+
return <RadioGroupPrimitive.Root className={cn("grid gap-2", className)} {...props} ref={ref} />;
10+
});
11+
RadioGroup.displayName = RadioGroupPrimitive.Root.displayName;
12+
13+
const RadioGroupItem = React.forwardRef<
14+
React.ElementRef<typeof RadioGroupPrimitive.Item>,
15+
React.ComponentPropsWithoutRef<typeof RadioGroupPrimitive.Item>
16+
>(({ className, ...props }, ref) => {
17+
return (
18+
<RadioGroupPrimitive.Item
19+
ref={ref}
20+
className={cn(
21+
"aspect-square h-3 w-3 bg-theme-surface-primary rounded-rounded border border-theme-border-bold text-primary ring-offset-background focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:data-[state=unchecked]:opacity-30 disabled:data-[state=checked]:bg-neutral-300",
22+
className
23+
)}
24+
{...props}
25+
>
26+
<RadioGroupPrimitive.Indicator className="flex text-theme-surface-strong items-center justify-center data-[state=checked]:data-[disabled]:text-theme-surface-primary">
27+
<svg
28+
className="h-[10px] w-[10px] fill-current text-current"
29+
viewBox="0 0 100 100"
30+
xmlns="http://www.w3.org/2000/svg"
31+
>
32+
<circle cx="50" cy="50" r="50" />
33+
</svg>
34+
</RadioGroupPrimitive.Indicator>
35+
</RadioGroupPrimitive.Item>
36+
);
37+
});
38+
RadioGroupItem.displayName = RadioGroupPrimitive.Item.displayName;
39+
40+
export { RadioGroup, RadioGroupItem };

src/components/RadioGroup/index.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./RadioGroup";

src/components/client.ts

+1
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ export * from "./Switch";
1616
export * from "./AlertDialog";
1717
export * from "./ScrollArea";
1818
export * from "./HoverCard";
19+
export * from "./RadioGroup";

0 commit comments

Comments
 (0)