Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
jaaydenh merged 1 commit intomainfromjaaydenh/radio-group-component
Apr 4, 2025
Merged
Show file tree
Hide file tree
Changes fromall 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 deletionssite/package.json
View file
Open in desktop
Original file line numberDiff line numberDiff 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 deletionssite/pnpm-lock.yaml
View file
Open in desktop

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

55 changes: 55 additions & 0 deletionssite/src/components/RadioGroup/RadioGroup.stories.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff 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 deletionssite/src/components/RadioGroup/RadioGroup.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff 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

[8]ページ先頭

©2009-2025 Movatter.jp