teachable-design-system 0.1.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/README.md +69 -0
- package/dist/index.cjs.js +3515 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.esm.js +3494 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/src/assets/index.d.ts +2 -0
- package/dist/src/assets/index.d.ts.map +1 -0
- package/dist/src/components/Button/Button.d.ts +4 -0
- package/dist/src/components/Button/Button.d.ts.map +1 -0
- package/dist/src/components/Button/index.d.ts +2 -0
- package/dist/src/components/Button/index.d.ts.map +1 -0
- package/dist/src/components/Button/style.d.ts +13 -0
- package/dist/src/components/Button/style.d.ts.map +1 -0
- package/dist/src/components/CheckBox/CheckBox.d.ts +4 -0
- package/dist/src/components/CheckBox/CheckBox.d.ts.map +1 -0
- package/dist/src/components/CheckBox/index.d.ts +2 -0
- package/dist/src/components/CheckBox/index.d.ts.map +1 -0
- package/dist/src/components/CheckBox/style.d.ts +22 -0
- package/dist/src/components/CheckBox/style.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Dropdown.d.ts +3 -0
- package/dist/src/components/Dropdown/Dropdown.d.ts.map +1 -0
- package/dist/src/components/Dropdown/index.d.ts +2 -0
- package/dist/src/components/Dropdown/index.d.ts.map +1 -0
- package/dist/src/components/Dropdown/style.d.ts +35 -0
- package/dist/src/components/Dropdown/style.d.ts.map +1 -0
- package/dist/src/components/Input/Input.d.ts +4 -0
- package/dist/src/components/Input/Input.d.ts.map +1 -0
- package/dist/src/components/Input/index.d.ts +2 -0
- package/dist/src/components/Input/index.d.ts.map +1 -0
- package/dist/src/components/Input/style.d.ts +5 -0
- package/dist/src/components/Input/style.d.ts.map +1 -0
- package/dist/src/components/Sidebar/Sidebar.d.ts +3 -0
- package/dist/src/components/Sidebar/Sidebar.d.ts.map +1 -0
- package/dist/src/components/Sidebar/index.d.ts +2 -0
- package/dist/src/components/Sidebar/index.d.ts.map +1 -0
- package/dist/src/components/Sidebar/style.d.ts +37 -0
- package/dist/src/components/Sidebar/style.d.ts.map +1 -0
- package/dist/src/components/TabBar/TabBar.d.ts +13 -0
- package/dist/src/components/TabBar/TabBar.d.ts.map +1 -0
- package/dist/src/components/TabBar/index.d.ts +2 -0
- package/dist/src/components/TabBar/index.d.ts.map +1 -0
- package/dist/src/components/TabBar/style.d.ts +21 -0
- package/dist/src/components/TabBar/style.d.ts.map +1 -0
- package/dist/src/components/index.d.ts +7 -0
- package/dist/src/components/index.d.ts.map +1 -0
- package/dist/src/foundation/index.d.ts +2 -0
- package/dist/src/foundation/index.d.ts.map +1 -0
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/style/index.d.ts +2 -0
- package/dist/src/style/index.d.ts.map +1 -0
- package/dist/src/style/theme/colors.d.ts +474 -0
- package/dist/src/style/theme/colors.d.ts.map +1 -0
- package/dist/src/style/theme/index.d.ts +3 -0
- package/dist/src/style/theme/index.d.ts.map +1 -0
- package/dist/src/style/theme/typography.d.ts +181 -0
- package/dist/src/style/theme/typography.d.ts.map +1 -0
- package/dist/src/type/Dropdown.types.d.ts +8 -0
- package/dist/src/type/Dropdown.types.d.ts.map +1 -0
- package/dist/src/type/Sidebar.types.d.ts +6 -0
- package/dist/src/type/Sidebar.types.d.ts.map +1 -0
- package/dist/src/types/button.types.d.ts +12 -0
- package/dist/src/types/button.types.d.ts.map +1 -0
- package/dist/src/types/checkBox.types.d.ts +7 -0
- package/dist/src/types/checkBox.types.d.ts.map +1 -0
- package/dist/src/types/input.types.d.ts +11 -0
- package/dist/src/types/input.types.d.ts.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/package.json +60 -0
- package/src/assets/icons/arrow-down.png +0 -0
- package/src/assets/icons/checked.png +0 -0
- package/src/assets/icons/icon_size.png +0 -0
- package/src/assets/images/.gitkeep +0 -0
- package/src/assets/index.ts +1 -0
- package/src/components/Button/Button.stories.tsx +145 -0
- package/src/components/Button/Button.tsx +27 -0
- package/src/components/Button/index.ts +1 -0
- package/src/components/Button/style.ts +132 -0
- package/src/components/CheckBox/CheckBox.stories.tsx +203 -0
- package/src/components/CheckBox/CheckBox.tsx +34 -0
- package/src/components/CheckBox/index.ts +1 -0
- package/src/components/CheckBox/style.ts +76 -0
- package/src/components/Dropdown/Dropdown.stories.tsx +91 -0
- package/src/components/Dropdown/Dropdown.tsx +56 -0
- package/src/components/Dropdown/index.ts +1 -0
- package/src/components/Dropdown/style.ts +213 -0
- package/src/components/Input/Input.stories.tsx +152 -0
- package/src/components/Input/Input.tsx +33 -0
- package/src/components/Input/index.ts +1 -0
- package/src/components/Input/style.ts +88 -0
- package/src/components/Sidebar/Sidebar.stories.tsx +60 -0
- package/src/components/Sidebar/Sidebar.tsx +67 -0
- package/src/components/Sidebar/index.ts +1 -0
- package/src/components/Sidebar/index.tsx +1 -0
- package/src/components/Sidebar/style.ts +109 -0
- package/src/components/TabBar/TabBar.stories.tsx +116 -0
- package/src/components/TabBar/TabBar.tsx +47 -0
- package/src/components/TabBar/index.ts +1 -0
- package/src/components/TabBar/style.ts +53 -0
- package/src/components/index.ts +6 -0
- package/src/foundation/index.ts +1 -0
- package/src/index.ts +2 -0
- package/src/style/index.ts +1 -0
- package/src/style/theme/colors.ts +504 -0
- package/src/style/theme/index.ts +2 -0
- package/src/style/theme/typography.ts +194 -0
- package/src/type/Dropdown.types.ts +7 -0
- package/src/type/Sidebar.types.ts +5 -0
- package/src/types/ krds-uiux.d.ts +12 -0
- package/src/types/button.types.ts +12 -0
- package/src/types/checkBox.types.ts +6 -0
- package/src/types/input.types.ts +11 -0
- package/src/vite-env.d.ts +1 -0
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { Meta, StoryObj } from "@storybook/react";
|
|
2
|
+
import CheckBox from "./CheckBox";
|
|
3
|
+
import React, { useState } from "react";
|
|
4
|
+
|
|
5
|
+
const meta = {
|
|
6
|
+
title: "Components/CheckBox",
|
|
7
|
+
component: CheckBox,
|
|
8
|
+
parameters: {
|
|
9
|
+
layout: "centered",
|
|
10
|
+
},
|
|
11
|
+
tags: ["autodocs"],
|
|
12
|
+
argTypes: {
|
|
13
|
+
size: {
|
|
14
|
+
control: "select",
|
|
15
|
+
options: ["medium", "large"],
|
|
16
|
+
description: "체크박스 크기",
|
|
17
|
+
},
|
|
18
|
+
select: {
|
|
19
|
+
control: "select",
|
|
20
|
+
options: ["off", "on", "indeterminate"],
|
|
21
|
+
description: "체크박스 선택 상태",
|
|
22
|
+
},
|
|
23
|
+
state: {
|
|
24
|
+
control: "select",
|
|
25
|
+
options: ["default", "disabled"],
|
|
26
|
+
description: "체크박스 활성화 상태",
|
|
27
|
+
},
|
|
28
|
+
onClick: {
|
|
29
|
+
action: "clicked",
|
|
30
|
+
description: "클릭 이벤트 핸들러",
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
} satisfies Meta<typeof CheckBox>;
|
|
34
|
+
|
|
35
|
+
export default meta;
|
|
36
|
+
type Story = StoryObj<typeof meta>;
|
|
37
|
+
|
|
38
|
+
// 기본 체크박스 (Off 상태)
|
|
39
|
+
export const Default: Story = {
|
|
40
|
+
args: {
|
|
41
|
+
size: "large",
|
|
42
|
+
select: "off",
|
|
43
|
+
state: "default",
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// 체크된 상태
|
|
48
|
+
export const Checked: Story = {
|
|
49
|
+
args: {
|
|
50
|
+
size: "large",
|
|
51
|
+
select: "on",
|
|
52
|
+
state: "default",
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
// 중간 상태 (Indeterminate)
|
|
57
|
+
export const Indeterminate: Story = {
|
|
58
|
+
args: {
|
|
59
|
+
size: "large",
|
|
60
|
+
select: "indeterminate",
|
|
61
|
+
state: "default",
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// Medium 크기
|
|
66
|
+
export const MediumSize: Story = {
|
|
67
|
+
args: {
|
|
68
|
+
size: "medium",
|
|
69
|
+
select: "on",
|
|
70
|
+
state: "default",
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
// Large 크기
|
|
75
|
+
export const LargeSize: Story = {
|
|
76
|
+
args: {
|
|
77
|
+
size: "large",
|
|
78
|
+
select: "on",
|
|
79
|
+
state: "default",
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
// 비활성화 상태 (Off)
|
|
84
|
+
export const DisabledOff: Story = {
|
|
85
|
+
args: {
|
|
86
|
+
size: "large",
|
|
87
|
+
select: "off",
|
|
88
|
+
state: "disabled",
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
// 비활성화 상태 (Checked)
|
|
93
|
+
export const DisabledChecked: Story = {
|
|
94
|
+
args: {
|
|
95
|
+
size: "large",
|
|
96
|
+
select: "on",
|
|
97
|
+
state: "disabled",
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
// 비활성화 상태 (Indeterminate)
|
|
102
|
+
export const DisabledIndeterminate: Story = {
|
|
103
|
+
args: {
|
|
104
|
+
size: "large",
|
|
105
|
+
select: "indeterminate",
|
|
106
|
+
state: "disabled",
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
// 인터랙티브 예제
|
|
111
|
+
export const Interactive = {
|
|
112
|
+
args: {
|
|
113
|
+
size: "large" as const,
|
|
114
|
+
state: "default" as const,
|
|
115
|
+
},
|
|
116
|
+
render: () => {
|
|
117
|
+
const [select, setSelect] = useState<"off" | "on" | "indeterminate">("off");
|
|
118
|
+
|
|
119
|
+
const handleClick = () => {
|
|
120
|
+
setSelect((prev) => {
|
|
121
|
+
if (prev === "off") return "on";
|
|
122
|
+
if (prev === "on") return "indeterminate";
|
|
123
|
+
return "off";
|
|
124
|
+
});
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
return (
|
|
128
|
+
<div
|
|
129
|
+
style={{
|
|
130
|
+
display: "flex",
|
|
131
|
+
flexDirection: "column",
|
|
132
|
+
gap: "16px",
|
|
133
|
+
alignItems: "center",
|
|
134
|
+
}}
|
|
135
|
+
>
|
|
136
|
+
<CheckBox
|
|
137
|
+
size="large"
|
|
138
|
+
select={select}
|
|
139
|
+
state="default"
|
|
140
|
+
onClick={handleClick}
|
|
141
|
+
/>
|
|
142
|
+
<p style={{ margin: 0, fontSize: "14px", color: "#666" }}>
|
|
143
|
+
클릭하여 상태 변경: {select}
|
|
144
|
+
</p>
|
|
145
|
+
</div>
|
|
146
|
+
);
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
// 모든 상태 비교
|
|
151
|
+
export const AllStates = {
|
|
152
|
+
args: {
|
|
153
|
+
size: "large" as const,
|
|
154
|
+
state: "default" as const,
|
|
155
|
+
},
|
|
156
|
+
render: () => (
|
|
157
|
+
<div style={{ display: "flex", gap: "32px", flexWrap: "wrap" }}>
|
|
158
|
+
<div
|
|
159
|
+
style={{
|
|
160
|
+
display: "flex",
|
|
161
|
+
flexDirection: "column",
|
|
162
|
+
gap: "16px",
|
|
163
|
+
alignItems: "center",
|
|
164
|
+
}}
|
|
165
|
+
>
|
|
166
|
+
<h4 style={{ margin: 0, fontSize: "14px", fontWeight: 600 }}>
|
|
167
|
+
Default
|
|
168
|
+
</h4>
|
|
169
|
+
<CheckBox size="large" select="off" state="default" />
|
|
170
|
+
<CheckBox size="large" select="on" state="default" />
|
|
171
|
+
<CheckBox size="large" select="indeterminate" state="default" />
|
|
172
|
+
</div>
|
|
173
|
+
<div
|
|
174
|
+
style={{
|
|
175
|
+
display: "flex",
|
|
176
|
+
flexDirection: "column",
|
|
177
|
+
gap: "16px",
|
|
178
|
+
alignItems: "center",
|
|
179
|
+
}}
|
|
180
|
+
>
|
|
181
|
+
<h4 style={{ margin: 0, fontSize: "14px", fontWeight: 600 }}>
|
|
182
|
+
Disabled
|
|
183
|
+
</h4>
|
|
184
|
+
<CheckBox size="large" select="off" state="disabled" />
|
|
185
|
+
<CheckBox size="large" select="on" state="disabled" />
|
|
186
|
+
<CheckBox size="large" select="indeterminate" state="disabled" />
|
|
187
|
+
</div>
|
|
188
|
+
<div
|
|
189
|
+
style={{
|
|
190
|
+
display: "flex",
|
|
191
|
+
flexDirection: "column",
|
|
192
|
+
gap: "16px",
|
|
193
|
+
alignItems: "center",
|
|
194
|
+
}}
|
|
195
|
+
>
|
|
196
|
+
<h4 style={{ margin: 0, fontSize: "14px", fontWeight: 600 }}>Medium</h4>
|
|
197
|
+
<CheckBox size="medium" select="off" state="default" />
|
|
198
|
+
<CheckBox size="medium" select="on" state="default" />
|
|
199
|
+
<CheckBox size="medium" select="indeterminate" state="default" />
|
|
200
|
+
</div>
|
|
201
|
+
</div>
|
|
202
|
+
),
|
|
203
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import * as S from "./style";
|
|
3
|
+
import { CheckBoxProps } from "@/types/checkBox.types";
|
|
4
|
+
|
|
5
|
+
const CheckBox = ({ size, select, state, onClick }: CheckBoxProps) => {
|
|
6
|
+
const handleClick = () => {
|
|
7
|
+
if (state !== "disabled" && onClick) {
|
|
8
|
+
onClick();
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
return (
|
|
13
|
+
<S.Wrapper size={size} select={select} state={state} onClick={handleClick}>
|
|
14
|
+
{select === "on" && (
|
|
15
|
+
<S.CheckIcon
|
|
16
|
+
viewBox="0 0 24 24"
|
|
17
|
+
fill="none"
|
|
18
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
19
|
+
>
|
|
20
|
+
<path
|
|
21
|
+
d="M20 6L9 17L4 12"
|
|
22
|
+
stroke="white"
|
|
23
|
+
strokeWidth="2.5"
|
|
24
|
+
strokeLinecap="round"
|
|
25
|
+
strokeLinejoin="round"
|
|
26
|
+
/>
|
|
27
|
+
</S.CheckIcon>
|
|
28
|
+
)}
|
|
29
|
+
{select === "indeterminate" && <S.DashIcon state={state} />}
|
|
30
|
+
</S.Wrapper>
|
|
31
|
+
);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export default CheckBox;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./CheckBox";
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import styled from "@emotion/styled";
|
|
2
|
+
import { css } from "@emotion/react";
|
|
3
|
+
import { colors } from "@/style/theme";
|
|
4
|
+
|
|
5
|
+
interface WrapperProps {
|
|
6
|
+
size: "medium" | "large";
|
|
7
|
+
select: "off" | "on" | "indeterminate";
|
|
8
|
+
state: "default" | "disabled";
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const Wrapper = styled.div<WrapperProps>`
|
|
12
|
+
${({ size, select, state }) => {
|
|
13
|
+
const dimensions = size === "large" ? "24px" : "20px";
|
|
14
|
+
const borderRadius = size === "large" ? "8px" : "6px";
|
|
15
|
+
|
|
16
|
+
return css`
|
|
17
|
+
width: ${dimensions};
|
|
18
|
+
height: ${dimensions};
|
|
19
|
+
display: flex;
|
|
20
|
+
align-items: center;
|
|
21
|
+
justify-content: center;
|
|
22
|
+
border-radius: ${borderRadius};
|
|
23
|
+
cursor: ${state === "disabled" ? "not-allowed" : "pointer"};
|
|
24
|
+
transition: all 0.2s ease;
|
|
25
|
+
|
|
26
|
+
${state === "disabled" &&
|
|
27
|
+
css`
|
|
28
|
+
background-color: ${colors.surface.disabled};
|
|
29
|
+
border: 1px solid ${colors.border.disabled};
|
|
30
|
+
`}
|
|
31
|
+
|
|
32
|
+
${state === "default" &&
|
|
33
|
+
select === "off" &&
|
|
34
|
+
css`
|
|
35
|
+
background-color: ${colors.surface.white};
|
|
36
|
+
border: 1px solid ${colors.border["gray-dark"]};
|
|
37
|
+
|
|
38
|
+
&:hover {
|
|
39
|
+
border-color: ${colors.border.primary};
|
|
40
|
+
}
|
|
41
|
+
`}
|
|
42
|
+
|
|
43
|
+
${state === "default" &&
|
|
44
|
+
(select === "on" || select === "indeterminate") &&
|
|
45
|
+
css`
|
|
46
|
+
background-color: ${colors.element.primary};
|
|
47
|
+
border: 1px solid ${colors.element.primary};
|
|
48
|
+
|
|
49
|
+
&:hover {
|
|
50
|
+
background-color: ${colors.light.primary["60"]};
|
|
51
|
+
border-color: ${colors.light.primary["60"]};
|
|
52
|
+
}
|
|
53
|
+
`}
|
|
54
|
+
`;
|
|
55
|
+
}}
|
|
56
|
+
`;
|
|
57
|
+
|
|
58
|
+
export const CheckIcon = styled.svg`
|
|
59
|
+
width: 100%;
|
|
60
|
+
height: 100%;
|
|
61
|
+
padding: 2px;
|
|
62
|
+
`;
|
|
63
|
+
|
|
64
|
+
interface DashIconProps {
|
|
65
|
+
state: "default" | "disabled";
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export const DashIcon = styled.div<DashIconProps>`
|
|
69
|
+
width: 60%;
|
|
70
|
+
height: 2.5px;
|
|
71
|
+
background-color: ${({ state }) =>
|
|
72
|
+
state === "disabled"
|
|
73
|
+
? colors.element["disabled-dark"]
|
|
74
|
+
: colors.element.inverse};
|
|
75
|
+
border-radius: 2px;
|
|
76
|
+
`;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { Dropdown } from './Dropdown';
|
|
3
|
+
|
|
4
|
+
const meta = {
|
|
5
|
+
title: 'Components/Dropdown',
|
|
6
|
+
component: Dropdown,
|
|
7
|
+
parameters: {
|
|
8
|
+
layout: 'centered',
|
|
9
|
+
},
|
|
10
|
+
tags: ['autodocs'],
|
|
11
|
+
argTypes: {
|
|
12
|
+
placeholder: {
|
|
13
|
+
control: 'text',
|
|
14
|
+
description: '기본',
|
|
15
|
+
},
|
|
16
|
+
size: {
|
|
17
|
+
control: 'text',
|
|
18
|
+
description: '트리거 버튼 높이',
|
|
19
|
+
},
|
|
20
|
+
label: {
|
|
21
|
+
control: 'text',
|
|
22
|
+
description: '상단 라벨 텍스트',
|
|
23
|
+
},
|
|
24
|
+
options: {
|
|
25
|
+
control: 'object',
|
|
26
|
+
description: '표시할 옵션 문자열 배열',
|
|
27
|
+
},
|
|
28
|
+
onSelect: {
|
|
29
|
+
action: 'selected',
|
|
30
|
+
description: '옵션 선택 시 호출되는 핸들러',
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
} satisfies Meta<typeof Dropdown>;
|
|
34
|
+
|
|
35
|
+
export default meta;
|
|
36
|
+
type Story = StoryObj<typeof meta>;
|
|
37
|
+
|
|
38
|
+
export const Default: Story = {
|
|
39
|
+
args: {
|
|
40
|
+
label: '과목 선택',
|
|
41
|
+
placeholder: '가상학급수',
|
|
42
|
+
options: ['국어', '영어', '수학', '사회', '과학'],
|
|
43
|
+
size: 'medium'
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export const WithCustomSize: Story = {
|
|
48
|
+
args: {
|
|
49
|
+
label: '강의 분류',
|
|
50
|
+
placeholder: '가상학급수',
|
|
51
|
+
size: 'large',
|
|
52
|
+
options: ['정규 과정', '특강', '워크숍'],
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export const MiniSize: Story = {
|
|
57
|
+
args: {
|
|
58
|
+
label: '강의 분류',
|
|
59
|
+
placeholder: '가상학급수',
|
|
60
|
+
size: 'small',
|
|
61
|
+
options: ['정규 과정', '특강', '워크숍'],
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export const WithoutLabel: Story = {
|
|
66
|
+
args: {
|
|
67
|
+
placeholder: '가상학급수',
|
|
68
|
+
options: ['옵션 1', '옵션 2', '옵션 3'],
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export const ManyOptions: Story = {
|
|
73
|
+
args: {
|
|
74
|
+
placeholder: '가상학급수',
|
|
75
|
+
options: ['옵션 1', '옵션 2', '옵션 3', '옵션 1', '옵션 2', '옵션 3','옵션 1', '옵션 2', '옵션 3'],
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
export const ManyOptionsWithSmallSize: Story = {
|
|
79
|
+
args: {
|
|
80
|
+
placeholder: '가상학급수',
|
|
81
|
+
options: ['옵션 1', '옵션 2', '옵션 3', '옵션 1', '옵션 2', '옵션 3','옵션 1', '옵션 2', '옵션 3'],
|
|
82
|
+
size: 'small'
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
export const ManyOptionsWithLargeSize: Story = {
|
|
86
|
+
args: {
|
|
87
|
+
placeholder: '가상학급수',
|
|
88
|
+
options: ['옵션 1', '옵션 2', '옵션 3', '옵션 1', '옵션 2', '옵션 3','옵션 1', '옵션 2', '옵션 3'],
|
|
89
|
+
size: 'large'
|
|
90
|
+
},
|
|
91
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import {DropdownProps} from "../../type/Dropdown.types";
|
|
3
|
+
import {StyledBox, StyledDropDown, StyledText, StyledLabel, StyledIcon, StyledOptions, StyledOption} from "./style";
|
|
4
|
+
import arrowDownIcon from '../../assets/icons/arrow-down.png';
|
|
5
|
+
|
|
6
|
+
export function Dropdown({size, options, onSelect, label, placeholder}: DropdownProps) {
|
|
7
|
+
const [open, setOpen] = React.useState(false);
|
|
8
|
+
const [selected, setSelected] = React.useState<string | null>(null);
|
|
9
|
+
const ref = React.useRef<HTMLDivElement>(null);
|
|
10
|
+
|
|
11
|
+
React.useEffect(() => {
|
|
12
|
+
const handleClickOutside = (e: MouseEvent) => {
|
|
13
|
+
if (ref.current && !ref.current.contains(e.target as Node)) {
|
|
14
|
+
setOpen(false);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
18
|
+
return () => document.removeEventListener("mousedown", handleClickOutside);
|
|
19
|
+
}, []);
|
|
20
|
+
|
|
21
|
+
const handleSelect = (option: string) => {
|
|
22
|
+
setSelected(option);
|
|
23
|
+
onSelect?.(option);
|
|
24
|
+
setOpen(false);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<div style={{position: 'relative'}}>
|
|
30
|
+
<StyledLabel>{label}</StyledLabel>
|
|
31
|
+
<StyledDropDown onClick={() => setOpen((prev) => !prev)}
|
|
32
|
+
size={size}
|
|
33
|
+
isOpen={open}
|
|
34
|
+
>
|
|
35
|
+
<StyledBox>
|
|
36
|
+
<StyledText
|
|
37
|
+
size={size}
|
|
38
|
+
isOpen={open}
|
|
39
|
+
>{selected ?? placeholder}</StyledText>
|
|
40
|
+
<StyledIcon size={size}>
|
|
41
|
+
<img src={arrowDownIcon} alt="dropdown icon" style={{width:'100%', height:'100%'}}/>
|
|
42
|
+
</StyledIcon>
|
|
43
|
+
</StyledBox>
|
|
44
|
+
</StyledDropDown>
|
|
45
|
+
{open && (
|
|
46
|
+
<StyledOptions ref={ref} size={size}>
|
|
47
|
+
{options?.map((option) => (
|
|
48
|
+
<StyledOption key={option} onClick={() => handleSelect(option)} size={size} isSelected={option === selected}>
|
|
49
|
+
{option}
|
|
50
|
+
</StyledOption>
|
|
51
|
+
))}
|
|
52
|
+
</StyledOptions>
|
|
53
|
+
)}
|
|
54
|
+
</div>
|
|
55
|
+
)
|
|
56
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Dropdown';
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import styled from '@emotion/styled';
|
|
2
|
+
import { css } from '@emotion/react';
|
|
3
|
+
import { colors } from '../../style';
|
|
4
|
+
import { typography } from '../../style';
|
|
5
|
+
import element from '../../assets/icons/checked.png';
|
|
6
|
+
|
|
7
|
+
export interface StyledDropdownProps {
|
|
8
|
+
size?: 'small' | 'medium' | 'large';
|
|
9
|
+
onSelect?: (option: string) => void;
|
|
10
|
+
isOpen?: boolean;
|
|
11
|
+
isSelected?: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const getButtonSize = (size?: 'small' | 'medium' | 'large') => {
|
|
15
|
+
switch (size) {
|
|
16
|
+
case 'small':
|
|
17
|
+
return css`
|
|
18
|
+
height: 40px;
|
|
19
|
+
`
|
|
20
|
+
case 'medium':
|
|
21
|
+
return css`
|
|
22
|
+
height: 48px;
|
|
23
|
+
`
|
|
24
|
+
case 'large':
|
|
25
|
+
return css`
|
|
26
|
+
height: 56px;
|
|
27
|
+
`
|
|
28
|
+
default:
|
|
29
|
+
return css`
|
|
30
|
+
height: 48px;
|
|
31
|
+
`
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const getFontSize = (size?: 'small' | 'medium' | 'large') => {
|
|
35
|
+
switch (size) {
|
|
36
|
+
case 'small':
|
|
37
|
+
return css`
|
|
38
|
+
font-size: ${typography.label.small.fontSize};
|
|
39
|
+
line-height: ${typography.label.small.lineHeight};
|
|
40
|
+
font-weight: ${typography.label.small.fontWeight};
|
|
41
|
+
`
|
|
42
|
+
case 'medium':
|
|
43
|
+
return css`
|
|
44
|
+
font-size: ${typography.label.medium.fontSize};
|
|
45
|
+
line-height: ${typography.label.medium.lineHeight};
|
|
46
|
+
font-weight: ${typography.label.medium.fontWeight};
|
|
47
|
+
`
|
|
48
|
+
case 'large':
|
|
49
|
+
return css`
|
|
50
|
+
font-size: ${typography.label.large.fontSize};
|
|
51
|
+
line-height: ${typography.label.large.lineHeight};
|
|
52
|
+
font-weight: ${typography.label.large.fontWeight};
|
|
53
|
+
`
|
|
54
|
+
default:
|
|
55
|
+
return css`
|
|
56
|
+
font-size: ${typography.label.medium.fontSize};
|
|
57
|
+
line-height: ${typography.label.medium.lineHeight};
|
|
58
|
+
font-weight: ${typography.label.medium.fontWeight};
|
|
59
|
+
`
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const getIconSize = (size?: 'small' | 'medium' | 'large') => {
|
|
63
|
+
switch (size) {
|
|
64
|
+
case 'small':
|
|
65
|
+
return css`
|
|
66
|
+
width: 16px;
|
|
67
|
+
height: 16px;
|
|
68
|
+
`
|
|
69
|
+
case 'medium':
|
|
70
|
+
return css`
|
|
71
|
+
width: 20px;
|
|
72
|
+
height: 20px;
|
|
73
|
+
`
|
|
74
|
+
case 'large':
|
|
75
|
+
return css`
|
|
76
|
+
width: 24px;
|
|
77
|
+
height: 24px;
|
|
78
|
+
`
|
|
79
|
+
default:
|
|
80
|
+
return css`
|
|
81
|
+
width: 20px;
|
|
82
|
+
height: 20px;
|
|
83
|
+
`
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const getOptionSize = (size?: 'small' | 'medium' | 'large') => {
|
|
87
|
+
switch (size) {
|
|
88
|
+
case 'small':
|
|
89
|
+
return css`
|
|
90
|
+
height: 23px;
|
|
91
|
+
`
|
|
92
|
+
case 'medium':
|
|
93
|
+
return css`
|
|
94
|
+
height: 26px;
|
|
95
|
+
`
|
|
96
|
+
case 'large':
|
|
97
|
+
return css`
|
|
98
|
+
height: 29px;
|
|
99
|
+
`
|
|
100
|
+
default:
|
|
101
|
+
return css`
|
|
102
|
+
height: 26px;
|
|
103
|
+
`
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export const StyledDropDown = styled.button<StyledDropdownProps>`
|
|
108
|
+
font-family: ${typography.fontFamily.primary};
|
|
109
|
+
background: ${colors.input.surface};
|
|
110
|
+
border-radius: 8px;
|
|
111
|
+
display: flex;
|
|
112
|
+
flex-direction: column;
|
|
113
|
+
align-items: flex-start;
|
|
114
|
+
gap: 8px;
|
|
115
|
+
width: 320px;
|
|
116
|
+
|
|
117
|
+
border: ${({ isOpen }) =>
|
|
118
|
+
isOpen ? `2px solid ${colors.input['border-active']}` : `1px solid ${colors.input.border}`};
|
|
119
|
+
${props => getButtonSize(props.size)}
|
|
120
|
+
|
|
121
|
+
`;
|
|
122
|
+
|
|
123
|
+
export const StyledBox = styled.div`
|
|
124
|
+
display: flex;
|
|
125
|
+
height: 100%;
|
|
126
|
+
padding: 0 16px;
|
|
127
|
+
align-items: center;
|
|
128
|
+
gap: 8px;
|
|
129
|
+
align-self: stretch;
|
|
130
|
+
`
|
|
131
|
+
|
|
132
|
+
export const StyledText = styled.p<StyledDropdownProps>`
|
|
133
|
+
font-family: ${typography.fontFamily.primary};
|
|
134
|
+
font-style: normal;
|
|
135
|
+
letter-spacing: 0;
|
|
136
|
+
width: 246px;
|
|
137
|
+
flex: 1 0 0;
|
|
138
|
+
text-align: left;
|
|
139
|
+
${props => getFontSize(props.size)}
|
|
140
|
+
color: ${({ isOpen }) => isOpen ? colors.text.static : colors.text.disabled};
|
|
141
|
+
`
|
|
142
|
+
|
|
143
|
+
export const StyledLabel = styled.p`
|
|
144
|
+
font-family: ${typography.fontFamily.primary};
|
|
145
|
+
color: ${colors.text.static};
|
|
146
|
+
`
|
|
147
|
+
|
|
148
|
+
export const StyledIcon = styled.div<StyledDropdownProps>`
|
|
149
|
+
${props => getIconSize(props.size)}
|
|
150
|
+
`
|
|
151
|
+
|
|
152
|
+
export const StyledOptions = styled.div<StyledDropdownProps>`
|
|
153
|
+
border: 1px solid ${colors.border["gray-light"]};
|
|
154
|
+
border-radius: 8px;
|
|
155
|
+
|
|
156
|
+
display: flex;
|
|
157
|
+
padding: 12px 8px;
|
|
158
|
+
flex-direction: column;
|
|
159
|
+
align-items: flex-start;
|
|
160
|
+
gap: 8px;
|
|
161
|
+
max-height: ${({ size }) =>
|
|
162
|
+
size === 'small' ? '220px' :
|
|
163
|
+
size === 'large' ? '260px' :
|
|
164
|
+
'240px'};
|
|
165
|
+
overflow-y: auto;
|
|
166
|
+
overflow-x: hidden;
|
|
167
|
+
`
|
|
168
|
+
|
|
169
|
+
export const StyledOption = styled.div<StyledDropdownProps>`
|
|
170
|
+
display: flex;
|
|
171
|
+
padding: 8px 12px;
|
|
172
|
+
flex-direction: column;
|
|
173
|
+
align-items: flex-start;
|
|
174
|
+
gap: 10px;
|
|
175
|
+
align-self: stretch;
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
border-radius: 8px;
|
|
179
|
+
|
|
180
|
+
color: ${colors.text.subtle};
|
|
181
|
+
position: relative;
|
|
182
|
+
|
|
183
|
+
${props => getFontSize(props.size)}
|
|
184
|
+
${props => getOptionSize(props.size)}
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
${({ isSelected }) => isSelected && css`
|
|
188
|
+
background: ${colors.action["secondary-selected"]};
|
|
189
|
+
color: ${colors.text.secondary};
|
|
190
|
+
|
|
191
|
+
padding-left: 36px;
|
|
192
|
+
|
|
193
|
+
&::after {
|
|
194
|
+
content: '';
|
|
195
|
+
width: 16px;
|
|
196
|
+
height: 16px;
|
|
197
|
+
background-image: url(${element});
|
|
198
|
+
background-size: cover;
|
|
199
|
+
background-repeat: no-repeat;
|
|
200
|
+
position: absolute;
|
|
201
|
+
left: 12px;
|
|
202
|
+
top: 50%;
|
|
203
|
+
transform: translateY(-50%);
|
|
204
|
+
}
|
|
205
|
+
`}
|
|
206
|
+
|
|
207
|
+
&:hover {
|
|
208
|
+
background: ${colors.action["secondary-hover"]};
|
|
209
|
+
}
|
|
210
|
+
&:active {
|
|
211
|
+
background: ${colors.action["secondary-pressed"]};
|
|
212
|
+
}
|
|
213
|
+
`
|