Skip to content
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 apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"dependencies": {
"@radix-ui/react-switch": "^1.2.6",
"@radix-ui/react-tabs": "^1.1.13",
"@radix-ui/react-radio-group": "^1.3.8",
"@tanstack/react-query": "^5.80.7",
"@tanstack/react-query-devtools": "^5.80.7",
"date-fns": "^4.1.0",
Expand Down
61 changes: 61 additions & 0 deletions apps/web/src/shared/components/Radio/Radio.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import type { Meta, StoryObj } from "@storybook/nextjs-vite";
import { Radio } from "./Radio";
import type { RadioProps } from "./Radio.type";

const meta = {
title: "v2/Components/Radio",
component: Radio,
parameters: {
layout: "centered",
},
tags: ["autodocs"],
argTypes: {
options: {
control: "select",
options: [
[
{ label: "ν”„λ‘œμ νŠΈ1", value: "ν”„λ‘œμ νŠΈ1" },
{ label: "ν”„λ‘œμ νŠΈ2", value: "ν”„λ‘œμ νŠΈ2" },
{ label: "ν”„λ‘œμ νŠΈ3", value: "ν”„λ‘œμ νŠΈ3" },
],
],
description: "radio의 μ˜΅μ…˜μ„ μ§€μ •",
},
disabled: {
control: "boolean",
description: "radio의 λΉ„ν™œμ„±ν™” μƒνƒœλ₯Ό μ§€μ •",
},
defaultValue: {
control: "select",
options: ["ν”„λ‘œμ νŠΈ1", "ν”„λ‘œμ νŠΈ2", "ν”„λ‘œμ νŠΈ3"],
description: "radio의 κΈ°λ³Έ 값을 μ§€μ •",
},
},
} satisfies Meta<typeof Radio>;

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

export const Base: Story = {
args: {
defaultValue: "ν”„λ‘œμ νŠΈ1",
options: [
{ label: "ν”„λ‘œμ νŠΈ1", value: "ν”„λ‘œμ νŠΈ1" },
{ label: "ν”„λ‘œμ νŠΈ2", value: "ν”„λ‘œμ νŠΈ2" },
{ label: "ν”„λ‘œμ νŠΈ3", value: "ν”„λ‘œμ νŠΈ3" },
],
},
render: args => <Radio {...args} />,
};

export const Disabled: Story = {
args: {
options: [
{ label: "ν”„λ‘œμ νŠΈ1", value: "ν”„λ‘œμ νŠΈ1" },
{ label: "ν”„λ‘œμ νŠΈ2", value: "ν”„λ‘œμ νŠΈ2" },
{ label: "ν”„λ‘œμ νŠΈ3", value: "ν”„λ‘œμ νŠΈ3" },
],
disabled: true,
},
render: (args: RadioProps) => <Radio {...args} />,
};
77 changes: 77 additions & 0 deletions apps/web/src/shared/components/Radio/Radio.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import * as RadioGroupBase from "@radix-ui/react-radio-group";
import { css } from "../../../../styled-system/css";
import type { RadioProps } from "./Radio.type";

export function Radio({ options, defaultValue, onChange, disabled = false }: RadioProps) {
return (
<RadioGroupBase.Root
defaultValue={defaultValue}
onValueChange={onChange}
disabled={disabled}
Comment thread
seungdeok marked this conversation as resolved.
className={css({
display: "flex",
alignItems: "center",
flexDirection: "column",
gap: "8px",
})}
>
{options.map(option => (
<div
className={css({
display: "flex",
flexDirection: "row",
alignItems: "center",
})}
key={option.value}
>
<RadioGroupBase.Item
className={css({
margin: "11px",
width: "20px",
height: "20px",
borderRadius: "50%",
border: "1px solid #B7C2D0",
cursor: "pointer",
position: "relative",
flexShrink: 0,
_hover: { borderColor: "#3A8DFF" },
'&[data-state="checked"]': { borderColor: "#3A8DFF" },
"&[data-disabled]": { borderColor: "#B7C2D0", cursor: "not-allowed" },
})}
value={option.value}
id={`radio-${option.value}`}
>
Comment on lines +41 to +43

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

쀑볡 id μœ„ν—˜: useId둜 id μ•ˆμ •ν™”

μ—¬λŸ¬ Radio μ»΄ν¬λ„ŒνŠΈκ°€ 동일 valueλ₯Ό κ°€μ§ˆ 경우 id={radio-${value}}κ°€ νŽ˜μ΄μ§€ μ „μ—­μ—μ„œ 쀑볡될 수 μžˆμ–΄ 라벨 연결이 깨질 수 μžˆμŠ΅λ‹ˆλ‹€. React useId둜 고유 prefixλ₯Ό λΆ€μ—¬ν•˜μ„Έμš”.

-            id={`radio-${option.value}`}
+            id={`${baseId}-${option.value}`}
-            htmlFor={`radio-${option.value}`}
+            htmlFor={`${baseId}-${option.value}`}

μ»΄ν¬λ„ŒνŠΈ 내뢀에 baseId μ„ μ–Έ 및 import μΆ”κ°€(파일 μ™Έ λ³€κ²½):

import { useId } from "react";

export function Radio(props: RadioProps) {
  const baseId = useId();
  // ...
}

Also applies to: 69-69

πŸ€– Prompt for AI Agents
In apps/web/src/shared/components/Radio/Radio.tsx around lines 41-43 (and also
at line 69), the component currently builds IDs as `radio-${option.value}` which
can collide across multiple Radio instances; import React's useId, create a
baseId inside the component (e.g. const baseId = useId()), and prefix the
generated id with it (for example `${baseId}-radio-${option.value}`) so each
Radio instance has a unique id; update both the input id and the corresponding
label htmlFor to use the new prefixed id and add the useId import at the top of
the file.

<div
className={css({
width: "10px",
height: "10px",
borderRadius: "50%",
position: "absolute",
top: "50%",
left: "50%",
transform: "translate(-50%, -50%)",
backgroundColor: "transparent",
"[data-state=checked] &": { backgroundColor: "#3A8DFF" },
"[data-disabled] &": { backgroundColor: "#B7C2D0" },
})}
/>
<RadioGroupBase.Indicator />
</RadioGroupBase.Item>
<label
className={css({
display: "flex",
alignItems: "center",
cursor: "pointer",
userSelect: "none",
'&[aria-disabled="true"]': { opacity: 0.5, cursor: "not-allowed" },
})}
aria-disabled={disabled}
htmlFor={`radio-${option.value}`}
>
<div className={css({ flex: 1 })}>{option.label}</div>
</label>
</div>
))}
</RadioGroupBase.Root>
);
}
11 changes: 11 additions & 0 deletions apps/web/src/shared/components/Radio/Radio.type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { ReactNode } from "react";

export type RadioProps = {
options: {
label: ReactNode;
value: string;
}[];
defaultValue?: string;
onChange?: (value: string) => void;
disabled?: boolean;
};
Comment thread
coderabbitai[bot] marked this conversation as resolved.
34 changes: 34 additions & 0 deletions pnpm-lock.yaml

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