@reitwagen/design-components 0.4.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/Button/Button.stories.d.ts +1 -0
- package/dist/components/Button/Button.stories.d.ts.map +1 -1
- package/dist/components/Button/Button.stories.js +4 -0
- package/dist/components/Checkbox/Checkbox.stories.d.ts +1 -0
- package/dist/components/Checkbox/Checkbox.stories.d.ts.map +1 -1
- package/dist/components/Checkbox/Checkbox.stories.js +4 -0
- package/dist/components/Chip/Chip.stories.d.ts +1 -0
- package/dist/components/Chip/Chip.stories.d.ts.map +1 -1
- package/dist/components/Chip/Chip.stories.js +2 -0
- package/dist/components/Chip/index.d.ts.map +1 -1
- package/dist/components/FormControl/FormControl.d.ts +55 -0
- package/dist/components/FormControl/FormControl.d.ts.map +1 -0
- package/dist/components/FormControl/FormControl.js +79 -0
- package/dist/components/FormControl/FormControl.stories.d.ts +19 -0
- package/dist/components/FormControl/FormControl.stories.d.ts.map +1 -0
- package/dist/components/FormControl/FormControl.stories.js +75 -0
- package/dist/components/FormControl/FormControlLabel.d.ts +20 -0
- package/dist/components/FormControl/FormControlLabel.d.ts.map +1 -0
- package/dist/components/FormControl/FormControlLabel.js +32 -0
- package/dist/components/FormControl/FormControlValidation.d.ts +13 -0
- package/dist/components/FormControl/FormControlValidation.d.ts.map +1 -0
- package/dist/components/FormControl/FormControlValidation.js +22 -0
- package/dist/components/FormControl/index.d.ts +2 -0
- package/dist/components/FormControl/index.d.ts.map +1 -0
- package/dist/components/FormControl/index.js +5 -0
- package/dist/components/Icons/IconPlaceLine.js +1 -1
- package/dist/components/Input/Input.d.ts +28 -0
- package/dist/components/Input/Input.d.ts.map +1 -0
- package/dist/components/Input/Input.js +30 -0
- package/dist/components/Input/Input.stories.d.ts +34 -0
- package/dist/components/Input/Input.stories.d.ts.map +1 -0
- package/dist/components/Input/Input.stories.js +81 -0
- package/dist/components/Input/Input.styles.d.ts +5 -0
- package/dist/components/Input/Input.styles.d.ts.map +1 -0
- package/dist/components/Input/Input.styles.js +20 -0
- package/dist/components/Input/index.d.ts +2 -0
- package/dist/components/Input/index.d.ts.map +1 -0
- package/dist/components/Input/index.js +5 -0
- package/dist/components/Radio/Radio.d.ts +6 -6
- package/dist/components/Radio/Radio.d.ts.map +1 -1
- package/dist/components/Radio/Radio.js +27 -9
- package/dist/components/Radio/Radio.stories.d.ts +1 -0
- package/dist/components/Radio/Radio.stories.d.ts.map +1 -1
- package/dist/components/Radio/Radio.stories.js +6 -2
- package/dist/components/Radio/index.d.ts.map +1 -1
- package/dist/components/RadioGroup/RadioGroup.d.ts +55 -0
- package/dist/components/RadioGroup/RadioGroup.d.ts.map +1 -0
- package/dist/components/RadioGroup/RadioGroup.js +45 -0
- package/dist/components/RadioGroup/RadioGroup.stories.d.ts +40 -0
- package/dist/components/RadioGroup/RadioGroup.stories.d.ts.map +1 -0
- package/dist/components/RadioGroup/RadioGroup.stories.js +103 -0
- package/dist/components/RadioGroup/index.d.ts +2 -0
- package/dist/components/RadioGroup/index.d.ts.map +1 -0
- package/dist/components/RadioGroup/index.js +5 -0
- package/dist/components/Toggle/index.d.ts.map +1 -1
- package/dist/index.css +70 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/types/props.d.ts +2 -2
- package/dist/types/props.d.ts.map +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Error = exports.Default = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const Input_1 = require("./Input");
|
|
6
|
+
const meta = {
|
|
7
|
+
title: "Components/Input",
|
|
8
|
+
component: Input_1.Input,
|
|
9
|
+
tags: ["autodocs"],
|
|
10
|
+
parameters: {
|
|
11
|
+
layout: "centered",
|
|
12
|
+
docs: {
|
|
13
|
+
description: {
|
|
14
|
+
component: `
|
|
15
|
+
Input은 한 줄의 텍스트 값을 설정하는데 사용됩니다.
|
|
16
|
+
|
|
17
|
+
## <b>Input guide</b>
|
|
18
|
+
|
|
19
|
+
입력 필드는 텍스트의 길이를 고려하여 적절한 크기로 제공하며, 플레이스홀더를 레이블이나 도움말의 대체 수단으로 사용하지 않도록 합니다.
|
|
20
|
+
`,
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
argTypes: {
|
|
25
|
+
variant: {
|
|
26
|
+
control: { type: "radio" },
|
|
27
|
+
options: ["default"],
|
|
28
|
+
},
|
|
29
|
+
disabled: {
|
|
30
|
+
control: { type: "boolean" },
|
|
31
|
+
options: ["true", "false"],
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
exports.default = meta;
|
|
36
|
+
exports.Default = {
|
|
37
|
+
parameters: {
|
|
38
|
+
layout: "centered",
|
|
39
|
+
docs: {
|
|
40
|
+
description: {
|
|
41
|
+
story: `
|
|
42
|
+
|
|
43
|
+
`,
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
render: (props) => ((0, jsx_runtime_1.jsxs)("div", { className: "ui:flex ui:gap-2", children: [(0, jsx_runtime_1.jsx)(Input_1.Input, { ...props }), props.children] })),
|
|
48
|
+
args: {
|
|
49
|
+
placeholder: "placeholder",
|
|
50
|
+
variant: "default",
|
|
51
|
+
},
|
|
52
|
+
argTypes: {
|
|
53
|
+
disabled: {
|
|
54
|
+
control: { type: "boolean" },
|
|
55
|
+
options: ["true", "false"],
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
exports.Error = {
|
|
60
|
+
parameters: {
|
|
61
|
+
layout: "centered",
|
|
62
|
+
docs: {
|
|
63
|
+
description: {
|
|
64
|
+
story: `
|
|
65
|
+
|
|
66
|
+
`,
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
render: (props) => ((0, jsx_runtime_1.jsxs)("div", { className: "ui:flex ui:gap-2", children: [(0, jsx_runtime_1.jsx)(Input_1.Input, { ...props, variant: "error" }), props.children] })),
|
|
71
|
+
args: {
|
|
72
|
+
placeholder: "placeholder",
|
|
73
|
+
variant: "error",
|
|
74
|
+
},
|
|
75
|
+
argTypes: {
|
|
76
|
+
disabled: {
|
|
77
|
+
control: { type: "boolean" },
|
|
78
|
+
options: ["true", "false"],
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Input.styles.d.ts","sourceRoot":"","sources":["../../../src/components/Input/Input.styles.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,aAAa;;;8EAmBzB,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.inputVariants = void 0;
|
|
4
|
+
const class_variance_authority_1 = require("class-variance-authority");
|
|
5
|
+
exports.inputVariants = (0, class_variance_authority_1.cva)("ui:h-[50px] ui:bg-white ui:px-4 ui:rounded-[16px] ui:w-full ui:border ui:text-body4 ui:transition-colors ui:outline-none", {
|
|
6
|
+
variants: {
|
|
7
|
+
variant: {
|
|
8
|
+
default: "ui:border-gray-100 ui:text-gray-800 ui:placeholder:text-body4 ui:placeholder:text-gray-500 ui:focus:bg-gray-50 ui:focus:border-gray-200",
|
|
9
|
+
error: "ui:border-red-200 ui:bg-red-50",
|
|
10
|
+
},
|
|
11
|
+
disabled: {
|
|
12
|
+
true: "ui:cursor-not-allowed ui:bg-gray-50 ui:border-gray-100 ui:text-gray-500 ui:placeholder:text-300",
|
|
13
|
+
false: "",
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
defaultVariants: {
|
|
17
|
+
variant: "default",
|
|
18
|
+
disabled: false,
|
|
19
|
+
},
|
|
20
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/Input/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC"}
|
|
@@ -9,25 +9,25 @@ export type RadioProps = ComponentPropsWithRef<"input"> & ChildrenProps & Varian
|
|
|
9
9
|
onCheckedChange?: (checked: boolean) => void;
|
|
10
10
|
};
|
|
11
11
|
/**
|
|
12
|
-
* `Radio`: 그룹 내 단일 선택만 가능한 요소로, 상호 배타적 옵션을 나타냅니다.
|
|
12
|
+
* `Radio`: 그룹 내 단일 선택만 가능한 요소로, 상호 배타적 옵션을 나타냅니다. 그룹과 함께 사용하려면, `RadioGroup`을 사용하세요.
|
|
13
13
|
* @see [RDS Storybook: Radio](https://main--691ac7d6da1eb0c0acb5f3e2.chromatic.com/?path=/docs/components-radio--docs)
|
|
14
|
+
* @see [RDS Storybook: RadioGroup](https://main--691ac7d6da1eb0c0acb5f3e2.chromatic.com/?path=/docs/components-radiogroup--docs)
|
|
14
15
|
* @example
|
|
15
16
|
* ```tsx
|
|
16
|
-
* const [
|
|
17
|
+
* const [checked, setChecked] = useState(false)
|
|
17
18
|
*
|
|
18
19
|
* // Controlled
|
|
19
20
|
* <Radio
|
|
20
|
-
* checked={
|
|
21
|
-
* onCheckedChange={
|
|
21
|
+
* checked={checked}
|
|
22
|
+
* onCheckedChange={() => setChecked(!checked)}
|
|
22
23
|
* >
|
|
23
24
|
* Option
|
|
24
25
|
* </Radio>
|
|
25
|
-
*
|
|
26
26
|
* // Uncontrolled
|
|
27
27
|
* <Radio defaultChecked>Option</Radio>
|
|
28
28
|
* ```
|
|
29
29
|
*/
|
|
30
|
-
export declare function Radio({ id: idProp, checked: controlledChecked, defaultChecked, disabled, className, onCheckedChange, children, ...props }: RadioProps): import("react/jsx-runtime").JSX.Element;
|
|
30
|
+
export declare function Radio({ id: idProp, checked: controlledChecked, defaultChecked, disabled, className, onCheckedChange, children, value, ...props }: RadioProps): import("react/jsx-runtime").JSX.Element;
|
|
31
31
|
export declare namespace Radio {
|
|
32
32
|
var displayName: string;
|
|
33
33
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Radio.d.ts","sourceRoot":"","sources":["../../../src/components/Radio/Radio.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAmB,MAAM,OAAO,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAExD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAoB,aAAa,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"Radio.d.ts","sourceRoot":"","sources":["../../../src/components/Radio/Radio.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAmB,MAAM,OAAO,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAExD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAoB,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAGjE,MAAM,MAAM,UAAU,GAAG,qBAAqB,CAAC,OAAO,CAAC,GACrD,aAAa,GACb,YAAY,CAAC,OAAO,aAAa,CAAC,GAAG;IACnC;;OAEG;IACH,eAAe,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;CAC9C,CAAC;AAEJ;;;;;;;;;;;;;;;;;;GAkBG;AAEH,wBAAgB,KAAK,CAAC,EACpB,EAAE,EAAE,MAAM,EACV,OAAO,EAAE,iBAAiB,EAC1B,cAAc,EACd,QAAQ,EACR,SAAS,EACT,eAAe,EACf,QAAQ,EACR,KAAK,EACL,GAAG,KAAK,EACT,EAAE,UAAU,2CA8EZ;yBAxFe,KAAK"}
|
|
@@ -6,39 +6,57 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
6
6
|
const react_1 = require("react");
|
|
7
7
|
const style_1 = require("../../utils/style");
|
|
8
8
|
const Radio_styles_1 = require("./Radio.styles");
|
|
9
|
+
const RadioGroup_1 = require("../RadioGroup/RadioGroup");
|
|
9
10
|
/**
|
|
10
|
-
* `Radio`: 그룹 내 단일 선택만 가능한 요소로, 상호 배타적 옵션을 나타냅니다.
|
|
11
|
+
* `Radio`: 그룹 내 단일 선택만 가능한 요소로, 상호 배타적 옵션을 나타냅니다. 그룹과 함께 사용하려면, `RadioGroup`을 사용하세요.
|
|
11
12
|
* @see [RDS Storybook: Radio](https://main--691ac7d6da1eb0c0acb5f3e2.chromatic.com/?path=/docs/components-radio--docs)
|
|
13
|
+
* @see [RDS Storybook: RadioGroup](https://main--691ac7d6da1eb0c0acb5f3e2.chromatic.com/?path=/docs/components-radiogroup--docs)
|
|
12
14
|
* @example
|
|
13
15
|
* ```tsx
|
|
14
|
-
* const [
|
|
16
|
+
* const [checked, setChecked] = useState(false)
|
|
15
17
|
*
|
|
16
18
|
* // Controlled
|
|
17
19
|
* <Radio
|
|
18
|
-
* checked={
|
|
19
|
-
* onCheckedChange={
|
|
20
|
+
* checked={checked}
|
|
21
|
+
* onCheckedChange={() => setChecked(!checked)}
|
|
20
22
|
* >
|
|
21
23
|
* Option
|
|
22
24
|
* </Radio>
|
|
23
|
-
*
|
|
24
25
|
* // Uncontrolled
|
|
25
26
|
* <Radio defaultChecked>Option</Radio>
|
|
26
27
|
* ```
|
|
27
28
|
*/
|
|
28
|
-
function Radio({ id: idProp, checked: controlledChecked, defaultChecked, disabled, className, onCheckedChange, children, ...props }) {
|
|
29
|
+
function Radio({ id: idProp, checked: controlledChecked, defaultChecked, disabled, className, onCheckedChange, children, value, ...props }) {
|
|
29
30
|
const [uncontrolledChecked, setUncontrolledChecked] = (0, react_1.useState)(defaultChecked);
|
|
31
|
+
const group = (0, RadioGroup_1.useRadioGroup)();
|
|
30
32
|
const uniqId = (0, react_1.useId)();
|
|
31
33
|
const id = idProp || uniqId;
|
|
32
|
-
const
|
|
34
|
+
const isInGroup = !!group;
|
|
35
|
+
const isDisabled = group?.disabled || disabled;
|
|
36
|
+
const isChecked = isInGroup
|
|
37
|
+
? group.value === value
|
|
38
|
+
: (controlledChecked ?? uncontrolledChecked);
|
|
33
39
|
const handleChange = () => {
|
|
34
|
-
if (disabled)
|
|
40
|
+
if (disabled) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (isInGroup) {
|
|
44
|
+
group.setValue(value);
|
|
35
45
|
return;
|
|
46
|
+
}
|
|
36
47
|
if (controlledChecked === undefined) {
|
|
37
48
|
setUncontrolledChecked(true);
|
|
38
49
|
}
|
|
39
50
|
onCheckedChange?.(true);
|
|
40
51
|
};
|
|
41
|
-
return ((0, jsx_runtime_1.jsxs)("label", { htmlFor: id, className: (0, style_1.cn)("ui:flex ui:items-center ui:gap-2 ui:cursor-pointer
|
|
52
|
+
return ((0, jsx_runtime_1.jsxs)("label", { htmlFor: id, className: (0, style_1.cn)("ui:flex ui:items-center ui:gap-2 ui:cursor-pointer", isDisabled && "ui:cursor-default ui:pointer-events-none"), children: [(0, jsx_runtime_1.jsx)("input", { id: id, type: "radio", name: group?.name, value: value, checked: isChecked, defaultChecked: defaultChecked, disabled: isDisabled, onChange: handleChange, className: "ui:sr-only", ...props }), (0, jsx_runtime_1.jsx)("div", { className: (0, Radio_styles_1.radioVariants)({
|
|
53
|
+
checked: isChecked,
|
|
54
|
+
disabled: isDisabled,
|
|
55
|
+
className,
|
|
56
|
+
}), children: (0, jsx_runtime_1.jsx)("div", { className: (0, Radio_styles_1.radioDotVariants)({
|
|
57
|
+
checked: isChecked,
|
|
58
|
+
disabled: isDisabled,
|
|
59
|
+
}) }) }), children && ((0, jsx_runtime_1.jsx)("span", { className: (0, style_1.cn)("ui:text-body5", isDisabled
|
|
42
60
|
? "ui:text-gray-400 ui:pointer-events-none"
|
|
43
61
|
: "ui:cursor-pointer"), children: children }))] }));
|
|
44
62
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Radio.stories.d.ts","sourceRoot":"","sources":["../../../src/components/Radio/Radio.stories.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAQ,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"Radio.stories.d.ts","sourceRoot":"","sources":["../../../src/components/Radio/Radio.stories.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAQ,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,QAAA,MAAM,IAAI;;;;;;;;;;;;;;;;;;;;;;;;CAsBoB,CAAC;AAE/B,eAAe,IAAI,CAAC;AACpB,KAAK,KAAK,GAAG,QAAQ,CAAC,OAAO,IAAI,CAAC,CAAC;AAEnC,eAAO,MAAM,UAAU,EAAE,KAgCxB,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,KA4BjC,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,KAoB1B,CAAC;AAEF,eAAO,MAAM,qBAAqB,EAAE,KASnC,CAAC"}
|
|
@@ -8,10 +8,11 @@ const meta = {
|
|
|
8
8
|
component: Radio_1.Radio,
|
|
9
9
|
tags: ["autodocs"],
|
|
10
10
|
parameters: {
|
|
11
|
+
layout: "centered",
|
|
11
12
|
docs: {
|
|
12
13
|
description: {
|
|
13
14
|
component: `
|
|
14
|
-
그룹 내 단일 선택만 가능한 요소로, 상호 배타적 옵션을 나타냅니다. 라벨과 함께 사용하거나 단독으로 사용할 수 있습니다.
|
|
15
|
+
그룹 내 단일 선택만 가능한 요소로, 상호 배타적 옵션을 나타냅니다. 라벨과 함께 사용하거나 단독으로 사용할 수 있습니다. 둘 이상의 Radio를 활용할 때는, \`<RadioGroup>\` 컴포넌트를 활용하는 것을 권장합니다.
|
|
15
16
|
`,
|
|
16
17
|
},
|
|
17
18
|
},
|
|
@@ -28,6 +29,7 @@ const meta = {
|
|
|
28
29
|
exports.default = meta;
|
|
29
30
|
exports.Controlled = {
|
|
30
31
|
parameters: {
|
|
32
|
+
layout: "centered",
|
|
31
33
|
docs: {
|
|
32
34
|
description: {
|
|
33
35
|
story: `
|
|
@@ -60,6 +62,7 @@ function Controlled() {
|
|
|
60
62
|
};
|
|
61
63
|
exports.ControlledWithLabel = {
|
|
62
64
|
parameters: {
|
|
65
|
+
layout: "centered",
|
|
63
66
|
docs: {
|
|
64
67
|
source: {
|
|
65
68
|
code: `
|
|
@@ -88,12 +91,13 @@ function ControlledWithLabel() {
|
|
|
88
91
|
};
|
|
89
92
|
exports.UnControlled = {
|
|
90
93
|
parameters: {
|
|
94
|
+
layout: "centered",
|
|
91
95
|
docs: {
|
|
92
96
|
description: {
|
|
93
97
|
story: `
|
|
94
98
|
### 상태를 내부에서 관리하는 방식
|
|
95
99
|
|
|
96
|
-
Radio상태를 내부에서 자동으로 관리하려면 <code>defaultChecked</code> 속성을 사용하세요. 이 속성은 Checkbox이 처음 화면에 표시될 때 선택 상태를 정해주고, 그 후에는 컴포넌트가 스스로 상태를 관리해요. 상태 변화를 추적하지 않아도 될 때 유용해요.
|
|
100
|
+
Radio의 상태를 내부에서 자동으로 관리하려면 <code>defaultChecked</code> 속성을 사용하세요. 이 속성은 Checkbox이 처음 화면에 표시될 때 선택 상태를 정해주고, 그 후에는 컴포넌트가 스스로 상태를 관리해요. 상태 변화를 추적하지 않아도 될 때 유용해요.
|
|
97
101
|
`,
|
|
98
102
|
},
|
|
99
103
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/Radio/index.
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/Radio/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { ComponentPropsWithoutRef } from "react";
|
|
2
|
+
interface RadioGroupContextValue {
|
|
3
|
+
name: string;
|
|
4
|
+
disabled?: boolean;
|
|
5
|
+
value?: string;
|
|
6
|
+
setValue: (value: string) => void;
|
|
7
|
+
}
|
|
8
|
+
export declare const useRadioGroup: () => RadioGroupContextValue | null;
|
|
9
|
+
export interface RadioGroupProps extends ComponentPropsWithoutRef<"div"> {
|
|
10
|
+
/**
|
|
11
|
+
* `Radio` 컴포넌트 목록
|
|
12
|
+
*/
|
|
13
|
+
children: React.ReactNode;
|
|
14
|
+
/**
|
|
15
|
+
* 선택된 value (Controlled)
|
|
16
|
+
*/
|
|
17
|
+
value?: string;
|
|
18
|
+
/**
|
|
19
|
+
* 초기 선택 값 (Uncontrolled)
|
|
20
|
+
*/
|
|
21
|
+
defaultValue?: string;
|
|
22
|
+
/**
|
|
23
|
+
* 선택 값이 변경될 때 호출되는 이벤트 핸들러
|
|
24
|
+
*/
|
|
25
|
+
onValueChange?: (value: string) => void;
|
|
26
|
+
/**
|
|
27
|
+
* 그룹 전체 비활성화 여부
|
|
28
|
+
*/
|
|
29
|
+
disabled?: boolean;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* `RadioGroup`: 하나의 값을 선택할 수 있는 라디오 옵션 그룹입니다.
|
|
33
|
+
* 내부의 `Radio` 컴포넌트는 자동으로 그룹 상태를 공유하며, 그룹 단위로 value 제어 및 disabled 상태를 관리할 수 있습니다.
|
|
34
|
+
*
|
|
35
|
+
* @see [RDS Storybook: RadioGroup](https://main--691ac7d6da1eb0c0acb5f3e2.chromatic.com/?path=/docs/components-radiogroup--docs)
|
|
36
|
+
* @example
|
|
37
|
+
* ```tsx
|
|
38
|
+
* // Controlled
|
|
39
|
+
* const [value, setValue] = useState("a");
|
|
40
|
+
*
|
|
41
|
+
* <RadioGroup value={value} onValueChange={setValue}>
|
|
42
|
+
* <Radio value="a">Option A</Radio>
|
|
43
|
+
* <Radio value="b">Option B</Radio>
|
|
44
|
+
* </RadioGroup>
|
|
45
|
+
*
|
|
46
|
+
* // Uncontrolled
|
|
47
|
+
* <RadioGroup defaultValue="b">
|
|
48
|
+
* <Radio value="a">Option A</Radio>
|
|
49
|
+
* <Radio value="b">Option B</Radio>
|
|
50
|
+
* </RadioGroup>
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export declare function RadioGroup({ children, value: controlledValue, defaultValue, onValueChange, disabled, className, ...props }: RadioGroupProps): import("react/jsx-runtime").JSX.Element;
|
|
54
|
+
export {};
|
|
55
|
+
//# sourceMappingURL=RadioGroup.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RadioGroup.d.ts","sourceRoot":"","sources":["../../../src/components/RadioGroup/RadioGroup.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EAKzB,MAAM,OAAO,CAAC;AAGf,UAAU,sBAAsB;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACnC;AAID,eAAO,MAAM,aAAa,qCAA+B,CAAC;AAE1D,MAAM,WAAW,eAAgB,SAAQ,wBAAwB,CAAC,KAAK,CAAC;IACtE;;OAEG;IACH,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAExC;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,UAAU,CAAC,EACzB,QAAQ,EACR,KAAK,EAAE,eAAe,EACtB,YAAY,EACZ,aAAa,EACb,QAAQ,EACR,SAAS,EACT,GAAG,KAAK,EACT,EAAE,eAAe,2CAwBjB"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useRadioGroup = void 0;
|
|
4
|
+
exports.RadioGroup = RadioGroup;
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
const style_1 = require("../../utils/style");
|
|
8
|
+
const RadioGroupContext = (0, react_1.createContext)(null);
|
|
9
|
+
const useRadioGroup = () => (0, react_1.use)(RadioGroupContext);
|
|
10
|
+
exports.useRadioGroup = useRadioGroup;
|
|
11
|
+
/**
|
|
12
|
+
* `RadioGroup`: 하나의 값을 선택할 수 있는 라디오 옵션 그룹입니다.
|
|
13
|
+
* 내부의 `Radio` 컴포넌트는 자동으로 그룹 상태를 공유하며, 그룹 단위로 value 제어 및 disabled 상태를 관리할 수 있습니다.
|
|
14
|
+
*
|
|
15
|
+
* @see [RDS Storybook: RadioGroup](https://main--691ac7d6da1eb0c0acb5f3e2.chromatic.com/?path=/docs/components-radiogroup--docs)
|
|
16
|
+
* @example
|
|
17
|
+
* ```tsx
|
|
18
|
+
* // Controlled
|
|
19
|
+
* const [value, setValue] = useState("a");
|
|
20
|
+
*
|
|
21
|
+
* <RadioGroup value={value} onValueChange={setValue}>
|
|
22
|
+
* <Radio value="a">Option A</Radio>
|
|
23
|
+
* <Radio value="b">Option B</Radio>
|
|
24
|
+
* </RadioGroup>
|
|
25
|
+
*
|
|
26
|
+
* // Uncontrolled
|
|
27
|
+
* <RadioGroup defaultValue="b">
|
|
28
|
+
* <Radio value="a">Option A</Radio>
|
|
29
|
+
* <Radio value="b">Option B</Radio>
|
|
30
|
+
* </RadioGroup>
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
function RadioGroup({ children, value: controlledValue, defaultValue, onValueChange, disabled, className, ...props }) {
|
|
34
|
+
const [uncontrolledValue, setUncontrolledValue] = (0, react_1.useState)(defaultValue);
|
|
35
|
+
const name = (0, react_1.useId)();
|
|
36
|
+
const isControlled = controlledValue !== undefined;
|
|
37
|
+
const currentValue = isControlled ? controlledValue : uncontrolledValue;
|
|
38
|
+
const setValue = (newValue) => {
|
|
39
|
+
if (!isControlled) {
|
|
40
|
+
setUncontrolledValue(newValue);
|
|
41
|
+
}
|
|
42
|
+
onValueChange?.(newValue);
|
|
43
|
+
};
|
|
44
|
+
return ((0, jsx_runtime_1.jsx)(RadioGroupContext, { value: { name, value: currentValue, disabled, setValue }, children: (0, jsx_runtime_1.jsx)("div", { className: (0, style_1.cn)("ui:flex ui:flex-col", className), ...props, children: children }) }));
|
|
45
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { StoryObj } from "@storybook/react";
|
|
2
|
+
import { RadioGroup } from "./RadioGroup";
|
|
3
|
+
declare const meta: {
|
|
4
|
+
title: string;
|
|
5
|
+
component: typeof RadioGroup;
|
|
6
|
+
tags: string[];
|
|
7
|
+
parameters: {
|
|
8
|
+
layout: string;
|
|
9
|
+
docs: {
|
|
10
|
+
description: {
|
|
11
|
+
component: string;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
argTypes: {
|
|
16
|
+
value: {
|
|
17
|
+
control: "text";
|
|
18
|
+
};
|
|
19
|
+
defaultValue: {
|
|
20
|
+
control: "text";
|
|
21
|
+
};
|
|
22
|
+
disabled: {
|
|
23
|
+
control: "boolean";
|
|
24
|
+
};
|
|
25
|
+
className: {
|
|
26
|
+
control: "text";
|
|
27
|
+
description: string;
|
|
28
|
+
};
|
|
29
|
+
children: {
|
|
30
|
+
table: {
|
|
31
|
+
disable: true;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
export default meta;
|
|
37
|
+
type Story = StoryObj<typeof meta>;
|
|
38
|
+
export declare const Controlled: Story;
|
|
39
|
+
export declare const Uncontrolled: Story;
|
|
40
|
+
//# sourceMappingURL=RadioGroup.stories.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RadioGroup.stories.d.ts","sourceRoot":"","sources":["../../../src/components/RadioGroup/RadioGroup.stories.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAQ,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEvD,OAAO,EAAE,UAAU,EAAmB,MAAM,cAAc,CAAC;AAG3D,QAAA,MAAM,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiCyB,CAAC;AAEpC,eAAe,IAAI,CAAC;AACpB,KAAK,KAAK,GAAG,QAAQ,CAAC,OAAO,IAAI,CAAC,CAAC;AAcnC,eAAO,MAAM,UAAU,EAAE,KAmCxB,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,KA0B1B,CAAC"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Uncontrolled = exports.Controlled = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const RadioGroup_1 = require("./RadioGroup");
|
|
7
|
+
const Radio_1 = require("../Radio/Radio");
|
|
8
|
+
const meta = {
|
|
9
|
+
title: "Components/RadioGroup",
|
|
10
|
+
component: RadioGroup_1.RadioGroup,
|
|
11
|
+
tags: ["autodocs"],
|
|
12
|
+
parameters: {
|
|
13
|
+
layout: "centered",
|
|
14
|
+
docs: {
|
|
15
|
+
description: {
|
|
16
|
+
component: `
|
|
17
|
+
여러 개의 Radio를 묶어 단일 선택을 강제하는 컴포넌트입니다.
|
|
18
|
+
\`value\`를 넘기면 제어 모드로, \`defaultValue\`만 넘기면 비제어 모드로 동작합니다.
|
|
19
|
+
`,
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
argTypes: {
|
|
24
|
+
value: {
|
|
25
|
+
control: "text",
|
|
26
|
+
},
|
|
27
|
+
defaultValue: {
|
|
28
|
+
control: "text",
|
|
29
|
+
},
|
|
30
|
+
disabled: { control: "boolean" },
|
|
31
|
+
className: {
|
|
32
|
+
control: "text",
|
|
33
|
+
description: "ui:gap-3",
|
|
34
|
+
},
|
|
35
|
+
children: {
|
|
36
|
+
table: {
|
|
37
|
+
disable: true,
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
exports.default = meta;
|
|
43
|
+
function ControlledRadioGroup(props) {
|
|
44
|
+
const [value, setValue] = (0, react_1.useState)("b");
|
|
45
|
+
return ((0, jsx_runtime_1.jsxs)(RadioGroup_1.RadioGroup, { ...props, value: value, onValueChange: setValue, children: [(0, jsx_runtime_1.jsx)(Radio_1.Radio, { value: "a", children: "A" }), (0, jsx_runtime_1.jsx)(Radio_1.Radio, { value: "b", children: "B" }), (0, jsx_runtime_1.jsx)(Radio_1.Radio, { value: "c", children: "C" })] }));
|
|
46
|
+
}
|
|
47
|
+
exports.Controlled = {
|
|
48
|
+
parameters: {
|
|
49
|
+
layout: "centered",
|
|
50
|
+
docs: {
|
|
51
|
+
description: {
|
|
52
|
+
story: `
|
|
53
|
+
### 상태를 외부에서 관리하는 방식
|
|
54
|
+
|
|
55
|
+
RadioGroup의 상태를 외부에서 관리하려면 \`value\`와 \`onValueChange\` 속성을 함께 사용하세요.
|
|
56
|
+
`,
|
|
57
|
+
},
|
|
58
|
+
source: {
|
|
59
|
+
code: `
|
|
60
|
+
function Controlled() {
|
|
61
|
+
const [value, setValue] = useState("b");
|
|
62
|
+
|
|
63
|
+
return (
|
|
64
|
+
<RadioGroup value={value} onValueChange={setValue} className="gap-3">
|
|
65
|
+
<Radio value="a">A</Radio>
|
|
66
|
+
<Radio value="b">B</Radio>
|
|
67
|
+
<Radio value="c">C</Radio>
|
|
68
|
+
</RadioGroup>
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
`.trim(),
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
render: (props) => (0, jsx_runtime_1.jsx)(ControlledRadioGroup, { ...props }),
|
|
76
|
+
args: {
|
|
77
|
+
value: "b",
|
|
78
|
+
children: (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {}),
|
|
79
|
+
disabled: false,
|
|
80
|
+
className: "ui:gap-3",
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
exports.Uncontrolled = {
|
|
84
|
+
parameters: {
|
|
85
|
+
layout: "centered",
|
|
86
|
+
docs: {
|
|
87
|
+
description: {
|
|
88
|
+
story: `
|
|
89
|
+
### 상태를 내부에서 관리하는 방식
|
|
90
|
+
|
|
91
|
+
RadioGroup의 상태를 내부에서 자동으로 관리하려면 \`defaultValue\` 속성을 사용하세요.
|
|
92
|
+
`,
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
render: (props) => ((0, jsx_runtime_1.jsxs)(RadioGroup_1.RadioGroup, { ...props, defaultValue: "b", children: [(0, jsx_runtime_1.jsx)(Radio_1.Radio, { value: "a", children: "A" }), (0, jsx_runtime_1.jsx)(Radio_1.Radio, { value: "b", children: "B" }), (0, jsx_runtime_1.jsx)(Radio_1.Radio, { value: "c", children: "C" })] })),
|
|
97
|
+
args: {
|
|
98
|
+
defaultValue: "b",
|
|
99
|
+
children: (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {}),
|
|
100
|
+
disabled: false,
|
|
101
|
+
className: "ui:gap-3",
|
|
102
|
+
},
|
|
103
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/RadioGroup/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RadioGroup = void 0;
|
|
4
|
+
var RadioGroup_1 = require("./RadioGroup");
|
|
5
|
+
Object.defineProperty(exports, "RadioGroup", { enumerable: true, get: function () { return RadioGroup_1.RadioGroup; } });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/Toggle/index.
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/Toggle/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC"}
|