From 0913140dc30e66a174c72b4487716b87a0225295 Mon Sep 17 00:00:00 2001 From: BrickheadJohnny <92519134+BrickheadJohnny@users.noreply.github.com> Date: Thu, 12 Sep 2024 10:45:52 +0200 Subject: [PATCH] feat: `RadioGroup` component & story (#1478) * feat: `RadioGroup` component & story * fix(RadioGroup): set text color only once --- package-lock.json | 33 +++++++++++++++ package.json | 1 + src/v2/components/ui/Label.tsx | 2 +- src/v2/components/ui/RadioGroup.stories.tsx | 37 ++++++++++++++++ src/v2/components/ui/RadioGroup.tsx | 47 +++++++++++++++++++++ 5 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 src/v2/components/ui/RadioGroup.stories.tsx create mode 100644 src/v2/components/ui/RadioGroup.tsx diff --git a/package-lock.json b/package-lock.json index 6c3d4fb856..78864fc6e8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -41,6 +41,7 @@ "@radix-ui/react-focus-scope": "^1.1.0", "@radix-ui/react-label": "^2.1.0", "@radix-ui/react-popover": "^1.1.1", + "@radix-ui/react-radio-group": "^1.2.0", "@radix-ui/react-select": "^2.1.1", "@radix-ui/react-separator": "^1.1.0", "@radix-ui/react-slot": "^1.1.0", @@ -8093,6 +8094,38 @@ } } }, + "node_modules/@radix-ui/react-radio-group": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@radix-ui/react-radio-group/-/react-radio-group-1.2.0.tgz", + "integrity": "sha512-yv+oiLaicYMBpqgfpSPw6q+RyXlLdIpQWDHZbUKURxe+nEh53hFXPPlfhfQQtYkS5MMK/5IWIa76SksleQZSzw==", + "license": "MIT", + "dependencies": { + "@radix-ui/primitive": "1.1.0", + "@radix-ui/react-compose-refs": "1.1.0", + "@radix-ui/react-context": "1.1.0", + "@radix-ui/react-direction": "1.1.0", + "@radix-ui/react-presence": "1.1.0", + "@radix-ui/react-primitive": "2.0.0", + "@radix-ui/react-roving-focus": "1.1.0", + "@radix-ui/react-use-controllable-state": "1.1.0", + "@radix-ui/react-use-previous": "1.1.0", + "@radix-ui/react-use-size": "1.1.0" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", + "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, "node_modules/@radix-ui/react-roving-focus": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@radix-ui/react-roving-focus/-/react-roving-focus-1.1.0.tgz", diff --git a/package.json b/package.json index 9c7589e6b8..9c26118329 100644 --- a/package.json +++ b/package.json @@ -53,6 +53,7 @@ "@radix-ui/react-focus-scope": "^1.1.0", "@radix-ui/react-label": "^2.1.0", "@radix-ui/react-popover": "^1.1.1", + "@radix-ui/react-radio-group": "^1.2.0", "@radix-ui/react-select": "^2.1.1", "@radix-ui/react-separator": "^1.1.0", "@radix-ui/react-slot": "^1.1.0", diff --git a/src/v2/components/ui/Label.tsx b/src/v2/components/ui/Label.tsx index c93cb53819..657b017555 100644 --- a/src/v2/components/ui/Label.tsx +++ b/src/v2/components/ui/Label.tsx @@ -7,7 +7,7 @@ import { cn } from "@/lib/utils" import { ComponentPropsWithoutRef, ElementRef, forwardRef } from "react" const labelVariants = cva( - "text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70" + "font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70" ) const Label = forwardRef< diff --git a/src/v2/components/ui/RadioGroup.stories.tsx b/src/v2/components/ui/RadioGroup.stories.tsx new file mode 100644 index 0000000000..02419165d1 --- /dev/null +++ b/src/v2/components/ui/RadioGroup.stories.tsx @@ -0,0 +1,37 @@ +import { Meta, StoryObj } from "@storybook/react" +import { Label } from "./Label" +import { RadioGroup, RadioGroupItem, RadioGroupProps } from "./RadioGroup" + +const RadioGroupExample = (props: RadioGroupProps) => ( + +
+ + +
+
+ + +
+
+) + +const meta: Meta = { + title: "Design system/RadioGroup", + component: RadioGroupExample, +} + +export default meta + +type Story = StoryObj + +export const Default: Story = { + args: { + disabled: false, + }, + argTypes: { + disabled: { + type: "boolean", + control: "boolean", + }, + }, +} diff --git a/src/v2/components/ui/RadioGroup.tsx b/src/v2/components/ui/RadioGroup.tsx new file mode 100644 index 0000000000..aaf749093a --- /dev/null +++ b/src/v2/components/ui/RadioGroup.tsx @@ -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, + RadioGroupProps +>(({ className, ...props }, ref) => { + return ( + + ) +}) +RadioGroup.displayName = RadioGroupPrimitive.Root.displayName + +const RadioGroupItem = forwardRef< + ElementRef, + ComponentPropsWithoutRef +>(({ className, ...props }, ref) => { + return ( + + + + + + ) +}) +RadioGroupItem.displayName = RadioGroupPrimitive.Item.displayName + +export { RadioGroup, RadioGroupItem }