Skip to content

feat: add shadcn radio-group component #17264

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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 4, 2025
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"@radix-ui/react-dropdown-menu": "2.1.4",
"@radix-ui/react-label": "2.1.0",
"@radix-ui/react-popover": "1.1.5",
"@radix-ui/react-radio-group": "1.2.3",
"@radix-ui/react-scroll-area": "1.2.3",
"@radix-ui/react-select": "2.1.4",
"@radix-ui/react-slider": "1.2.2",
Expand Down
89 changes: 89 additions & 0 deletions site/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 55 additions & 0 deletions site/src/components/RadioGroup/RadioGroup.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import type { Meta, StoryObj } from "@storybook/react";
import { RadioGroup, RadioGroupItem } from "./RadioGroup";

const meta: Meta<typeof RadioGroup> = {
title: "components/RadioGroup",
component: RadioGroup,
args: {},
};

export default meta;
type Story = StoryObj<typeof RadioGroup>;

export const Default: Story = {
render: () => (
<RadioGroup defaultValue="option-1">
<div className="flex items-center space-x-2">
<RadioGroupItem value="option-1" id="option-1" tabIndex={0} />
<label htmlFor="option-1" className="text-content-primary text-sm">
Option 1
</label>
</div>
<div className="flex items-center space-x-2">
<RadioGroupItem value="option-2" id="option-2" tabIndex={0} />
<label htmlFor="option-2" className="text-content-primary text-sm">
Option 2
</label>
</div>
<div className="flex items-center space-x-2">
<RadioGroupItem value="option-3" id="option-3" tabIndex={0} />
<label htmlFor="option-3" className="text-content-primary text-sm">
Option 3
</label>
</div>
</RadioGroup>
),
};

export const WithDisabledOptions: Story = {
render: () => (
<RadioGroup defaultValue="option-1">
<div className="flex items-center space-x-2">
<RadioGroupItem value="option-1" id="disabled-1" disabled />
<label htmlFor="disabled-1" className="text-content-disabled text-sm">
Disabled Selected Option
</label>
</div>
<div className="flex items-center space-x-2">
<RadioGroupItem value="option-2" id="disabled-2" disabled />
<label htmlFor="disabled-2" className="text-content-disabled text-sm">
Disabled Not Selected Option
</label>
</div>
</RadioGroup>
),
};
47 changes: 47 additions & 0 deletions site/src/components/RadioGroup/RadioGroup.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* Copied from shadc/ui on 04/04/2025
* @see {@link https://ui.shadcn.com/docs/components/radio-group}
*/
import * as RadioGroupPrimitive from "@radix-ui/react-radio-group";
import { Circle } from "lucide-react";
import * as React from "react";

import { cn } from "utils/cn";

export const RadioGroup = React.forwardRef<
React.ElementRef<typeof RadioGroupPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof RadioGroupPrimitive.Root>
>(({ className, ...props }, ref) => {
return (
<RadioGroupPrimitive.Root
className={cn("grid gap-2", className)}
{...props}
ref={ref}
/>
);
});
RadioGroup.displayName = RadioGroupPrimitive.Root.displayName;

export const RadioGroupItem = React.forwardRef<
React.ElementRef<typeof RadioGroupPrimitive.Item>,
React.ComponentPropsWithoutRef<typeof RadioGroupPrimitive.Item>
>(({ className, ...props }, ref) => {
return (
<RadioGroupPrimitive.Item
ref={ref}
className={cn(
`aspect-square h-4 w-4 rounded-full border border-solid border-border text-content-primary bg-surface-primary
focus:outline-none focus-visible:ring-2 focus-visible:ring-content-link
focus-visible:ring-offset-4 focus-visible:ring-offset-surface-primary
disabled:cursor-not-allowed disabled:opacity-25 disabled:border-surface-invert-primary
hover:border-border-hover`,
className,
)}
{...props}
>
<RadioGroupPrimitive.Indicator className="flex items-center justify-center">
<Circle className="absolute h-2.5 w-2.5 fill-surface-invert-primary" />
</RadioGroupPrimitive.Indicator>
</RadioGroupPrimitive.Item>
);
});
Loading