-
Notifications
You must be signed in to change notification settings - Fork 0
[Feat/#58] feat(web): migrate Radio #69
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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} />, | ||
| }; |
| 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} | ||
| 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. μ€λ³΅ id μν: useIdλ‘ id μμ ν μ¬λ¬ Radio μ»΄ν¬λνΈκ° λμΌ valueλ₯Ό κ°μ§ κ²½μ° id={ - 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 |
||
| <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> | ||
| ); | ||
| } | ||
| 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; | ||
| }; | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.