@weing-dev/ui-kit-primitive 0.0.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.
Files changed (328) hide show
  1. package/README.md +50 -0
  2. package/eslint.config.js +29 -0
  3. package/index.html +13 -0
  4. package/package.json +75 -0
  5. package/public/static/icon/Add.svg +1 -0
  6. package/public/static/icon/ApprovalInactive.svg +1 -0
  7. package/public/static/icon/ArrowRight.svg +5 -0
  8. package/public/static/icon/Cancle Filled.svg +1 -0
  9. package/public/static/icon/Cancle.svg +1 -0
  10. package/public/static/icon/Cart Filled.svg +1 -0
  11. package/public/static/icon/Cart.svg +1 -0
  12. package/public/static/icon/Check.svg +1 -0
  13. package/public/static/icon/CheckBoxRound.svg +3 -0
  14. package/public/static/icon/Company.svg +1 -0
  15. package/public/static/icon/DragHandle.svg +1 -0
  16. package/public/static/icon/Eco.svg +1 -0
  17. package/public/static/icon/EditSquare.svg +1 -0
  18. package/public/static/icon/Error Filled.svg +1 -0
  19. package/public/static/icon/Error.svg +1 -0
  20. package/public/static/icon/File Upload.svg +1 -0
  21. package/public/static/icon/FilecheckInactive.svg +1 -0
  22. package/public/static/icon/Go Before.svg +1 -0
  23. package/public/static/icon/Go Next.svg +1 -0
  24. package/public/static/icon/Hamburger Menu.svg +1 -0
  25. package/public/static/icon/ImagecheckPlay.svg +4 -0
  26. package/public/static/icon/Kakao Talk.svg +1 -0
  27. package/public/static/icon/Minus.svg +1 -0
  28. package/public/static/icon/Naver Blog.svg +1 -0
  29. package/public/static/icon/Naver.svg +1 -0
  30. package/public/static/icon/OrderApprove.svg +1 -0
  31. package/public/static/icon/OrderInactive.svg +1 -0
  32. package/public/static/icon/OrderPlay.svg +1 -0
  33. package/public/static/icon/PayApprove.svg +1 -0
  34. package/public/static/icon/PayInactive.svg +1 -0
  35. package/public/static/icon/PrintInactive.svg +1 -0
  36. package/public/static/icon/PrintPlay.svg +1 -0
  37. package/public/static/icon/Search.svg +1 -0
  38. package/public/static/icon/ShippingDone.svg +1 -0
  39. package/public/static/icon/Support Agent.svg +1 -0
  40. package/public/static/icon/Task.svg +1 -0
  41. package/public/static/icon/User.svg +1 -0
  42. package/public/static/icon/Warning Filled.svg +1 -0
  43. package/public/static/icon/Warning.svg +1 -0
  44. package/public/static/icon/add_a_photo.svg +3 -0
  45. package/public/static/icon/attach_file.svg +1 -0
  46. package/public/static/icon/check_circle.svg +1 -0
  47. package/public/static/icon/close.svg +1 -0
  48. package/public/static/icon/download.svg +1 -0
  49. package/public/static/icon/expand all.svg +1 -0
  50. package/public/static/icon/expand_less.svg +1 -0
  51. package/public/static/icon/expand_more.svg +1 -0
  52. package/public/static/icon/factory.svg +1 -0
  53. package/public/static/icon/inventory.svg +1 -0
  54. package/public/static/icon/listAll.svg +1 -0
  55. package/public/static/icon/local_shipping.svg +1 -0
  56. package/public/static/icon/logout.svg +1 -0
  57. package/public/static/icon/menu.svg +1 -0
  58. package/public/static/icon/mode_edit.svg +4 -0
  59. package/public/static/icon/more.svg +1 -0
  60. package/public/static/icon/outward.svg +1 -0
  61. package/public/static/icon/personcard.svg +1 -0
  62. package/public/static/icon/product.svg +1 -0
  63. package/public/static/icon/settings.svg +1 -0
  64. package/public/static/icon/swap_vert.svg +3 -0
  65. package/public/static/icon/upload.svg +1 -0
  66. package/public/static/icon/warning_amber.svg +3 -0
  67. package/public/static/image/Thumbnail.png +0 -0
  68. package/public/vite.svg +1 -0
  69. package/public/weing_logo_final.png +0 -0
  70. package/scripts/icons/setIcon.cjs +151 -0
  71. package/scripts/icons/svg-template.cjs +18 -0
  72. package/scripts/icons/svgo-config.json +9 -0
  73. package/scripts/icons/svgr-config.json +16 -0
  74. package/src/@types/color.d.ts +51 -0
  75. package/src/@types/common.d.ts +6 -0
  76. package/src/@types/extends/react.extends.d.ts +7 -0
  77. package/src/@types/quill-image-resize-module-react/index.d.ts +1 -0
  78. package/src/App.css +0 -0
  79. package/src/App.tsx +84 -0
  80. package/src/assets/react.svg +1 -0
  81. package/src/components/Accordion/Accordion.context.tsx +62 -0
  82. package/src/components/Accordion/Accordion.module.scss +163 -0
  83. package/src/components/Accordion/Accordion.tsx +242 -0
  84. package/src/components/Accordion/README.md +408 -0
  85. package/src/components/Accordion/images/as_trigger.gif +0 -0
  86. package/src/components/Accordion/images/closed.png +0 -0
  87. package/src/components/Accordion/images/open.png +0 -0
  88. package/src/components/Accordion/images/thumbnail1.png +0 -0
  89. package/src/components/Accordion/images/thumbnail2.png +0 -0
  90. package/src/components/Accordion/images/thumbnail3.png +0 -0
  91. package/src/components/Avatar/Avatar.module.scss +47 -0
  92. package/src/components/Avatar/Avatar.tsx +230 -0
  93. package/src/components/Avatar/README.md +333 -0
  94. package/src/components/Badge/Badge.module.scss +49 -0
  95. package/src/components/Badge/Badge.tsx +87 -0
  96. package/src/components/Badge/README.md +223 -0
  97. package/src/components/BarCode/BarCode.module.scss +0 -0
  98. package/src/components/BarCode/BarCode.tsx +153 -0
  99. package/src/components/Breadcrumb/Breadcrumb.module.scss +36 -0
  100. package/src/components/Breadcrumb/Breadcrumb.tsx +114 -0
  101. package/src/components/Breadcrumb/README.md +339 -0
  102. package/src/components/Button/Button.colors.tsx +322 -0
  103. package/src/components/Button/Button.context.tsx +47 -0
  104. package/src/components/Button/Button.module.scss +156 -0
  105. package/src/components/Button/Button.tsx +190 -0
  106. package/src/components/Button/Button.type.ts +11 -0
  107. package/src/components/Calendar/Calendar.context.tsx +138 -0
  108. package/src/components/Calendar/Calendar.module.scss +116 -0
  109. package/src/components/Calendar/Calendar.tsx +440 -0
  110. package/src/components/Calendar/dayjs.util.ts +312 -0
  111. package/src/components/Cascader/Cacader.data.ts +1185 -0
  112. package/src/components/Cascader/Cascader.context.tsx +61 -0
  113. package/src/components/Cascader/Cascader.hook.ts +502 -0
  114. package/src/components/Cascader/Cascader.module.scss +143 -0
  115. package/src/components/Cascader/Cascader.tsx +281 -0
  116. package/src/components/Cascader/README.md +735 -0
  117. package/src/components/Chart/Chart.module.scss +0 -0
  118. package/src/components/Chart/Chart.tsx +230 -0
  119. package/src/components/Chart/README.md +85 -0
  120. package/src/components/Chart/images/barChart.png +0 -0
  121. package/src/components/Chips/Chips.colors.tsx +185 -0
  122. package/src/components/Chips/Chips.module.scss +49 -0
  123. package/src/components/Chips/Chips.tsx +78 -0
  124. package/src/components/Comment/Comment.module.scss +14 -0
  125. package/src/components/Comment/Comment.tsx +105 -0
  126. package/src/components/Dialog/Dialog.module.scss +0 -0
  127. package/src/components/Dialog/Dialog.tsx +12 -0
  128. package/src/components/Divider/Divider.module.scss +12 -0
  129. package/src/components/Divider/Divider.tsx +33 -0
  130. package/src/components/Editor/Editor.context.tsx +12 -0
  131. package/src/components/Editor/Editor.module.scss +40 -0
  132. package/src/components/Editor/Editor.tsx +174 -0
  133. package/src/components/Form/CheckBox/CheckBox.context.tsx +56 -0
  134. package/src/components/Form/CheckBox/CheckBox.module.scss +81 -0
  135. package/src/components/Form/CheckBox/CheckBox.tsx +196 -0
  136. package/src/components/Form/CheckBox/Checkbox.colors.tsx +42 -0
  137. package/src/components/Form/Dropdown/Dropdown.colors.tsx +125 -0
  138. package/src/components/Form/Dropdown/Dropdown.context.tsx +62 -0
  139. package/src/components/Form/Dropdown/Dropdown.module.scss +133 -0
  140. package/src/components/Form/Dropdown/Dropdown.tsx +404 -0
  141. package/src/components/Form/OTPInput/OTPInput.context.tsx +104 -0
  142. package/src/components/Form/OTPInput/OTPInput.module.scss +22 -0
  143. package/src/components/Form/OTPInput/OTPInput.tsx +67 -0
  144. package/src/components/Form/Radio/Radio.colors.tsx +42 -0
  145. package/src/components/Form/Radio/Radio.context.tsx +40 -0
  146. package/src/components/Form/Radio/Radio.module.scss +61 -0
  147. package/src/components/Form/Radio/Radio.tsx +174 -0
  148. package/src/components/Form/Switch/Switch.colors.tsx +42 -0
  149. package/src/components/Form/Switch/Switch.context.tsx +50 -0
  150. package/src/components/Form/Switch/Switch.module.scss +53 -0
  151. package/src/components/Form/Switch/Switch.tsx +151 -0
  152. package/src/components/Form/TextArea/TextArea.colors.tsx +76 -0
  153. package/src/components/Form/TextArea/TextArea.context.tsx +97 -0
  154. package/src/components/Form/TextArea/TextArea.module.scss +138 -0
  155. package/src/components/Form/TextArea/TextArea.tsx +246 -0
  156. package/src/components/Form/TextInput/TextInput.colors.tsx +76 -0
  157. package/src/components/Form/TextInput/TextInput.context.tsx +106 -0
  158. package/src/components/Form/TextInput/TextInput.module.scss +160 -0
  159. package/src/components/Form/TextInput/TextInput.tsx +225 -0
  160. package/src/components/GlobalStyle/GlobalStyle.tsx +20 -0
  161. package/src/components/HelperText/HelperText.module.scss +28 -0
  162. package/src/components/HelperText/HelperText.tsx +130 -0
  163. package/src/components/Icon/Icon.tsx +29 -0
  164. package/src/components/Icons/Add.tsx +20 -0
  165. package/src/components/Icons/AddAPhoto.tsx +21 -0
  166. package/src/components/Icons/ApprovalInactive.tsx +26 -0
  167. package/src/components/Icons/ArrowRight.tsx +24 -0
  168. package/src/components/Icons/AttachFile.tsx +20 -0
  169. package/src/components/Icons/Cancle.tsx +20 -0
  170. package/src/components/Icons/CancleFilled.tsx +20 -0
  171. package/src/components/Icons/Cart.tsx +20 -0
  172. package/src/components/Icons/CartFilled.tsx +20 -0
  173. package/src/components/Icons/Check.tsx +20 -0
  174. package/src/components/Icons/CheckBoxRound.tsx +21 -0
  175. package/src/components/Icons/CheckCircle.tsx +35 -0
  176. package/src/components/Icons/Close.tsx +20 -0
  177. package/src/components/Icons/Company.tsx +20 -0
  178. package/src/components/Icons/Download.tsx +20 -0
  179. package/src/components/Icons/DragHandle.tsx +20 -0
  180. package/src/components/Icons/Eco.tsx +20 -0
  181. package/src/components/Icons/EditSquare.tsx +20 -0
  182. package/src/components/Icons/Error.tsx +20 -0
  183. package/src/components/Icons/ErrorFilled.tsx +20 -0
  184. package/src/components/Icons/ExpandAll.tsx +20 -0
  185. package/src/components/Icons/ExpandLess.tsx +20 -0
  186. package/src/components/Icons/ExpandMore.tsx +20 -0
  187. package/src/components/Icons/Factory.tsx +20 -0
  188. package/src/components/Icons/FileUpload.tsx +20 -0
  189. package/src/components/Icons/FilecheckInactive.tsx +22 -0
  190. package/src/components/Icons/GoBefore.tsx +20 -0
  191. package/src/components/Icons/GoNext.tsx +20 -0
  192. package/src/components/Icons/HamburgerMenu.tsx +20 -0
  193. package/src/components/Icons/ImagecheckPlay.tsx +27 -0
  194. package/src/components/Icons/Inventory.tsx +20 -0
  195. package/src/components/Icons/KakaoTalk.tsx +22 -0
  196. package/src/components/Icons/ListAll.tsx +20 -0
  197. package/src/components/Icons/LocalShipping.tsx +20 -0
  198. package/src/components/Icons/Logout.tsx +20 -0
  199. package/src/components/Icons/Menu.tsx +20 -0
  200. package/src/components/Icons/Minus.tsx +18 -0
  201. package/src/components/Icons/ModeEdit.tsx +25 -0
  202. package/src/components/Icons/More.tsx +20 -0
  203. package/src/components/Icons/Naver.tsx +20 -0
  204. package/src/components/Icons/NaverBlog.tsx +22 -0
  205. package/src/components/Icons/OrderApprove.tsx +20 -0
  206. package/src/components/Icons/OrderInactive.tsx +20 -0
  207. package/src/components/Icons/OrderPlay.tsx +20 -0
  208. package/src/components/Icons/Outward.tsx +20 -0
  209. package/src/components/Icons/PayApprove.tsx +24 -0
  210. package/src/components/Icons/PayInactive.tsx +24 -0
  211. package/src/components/Icons/Personcard.tsx +20 -0
  212. package/src/components/Icons/PrintInactive.tsx +24 -0
  213. package/src/components/Icons/PrintPlay.tsx +24 -0
  214. package/src/components/Icons/Product.tsx +20 -0
  215. package/src/components/Icons/Search.tsx +20 -0
  216. package/src/components/Icons/Settings.tsx +20 -0
  217. package/src/components/Icons/ShippingDone.tsx +20 -0
  218. package/src/components/Icons/SupportAgent.tsx +20 -0
  219. package/src/components/Icons/SwapVert.tsx +21 -0
  220. package/src/components/Icons/Task.tsx +20 -0
  221. package/src/components/Icons/Upload.tsx +20 -0
  222. package/src/components/Icons/User.tsx +20 -0
  223. package/src/components/Icons/Warning.tsx +20 -0
  224. package/src/components/Icons/WarningAmber.tsx +21 -0
  225. package/src/components/Icons/WarningFilled.tsx +20 -0
  226. package/src/components/Icons/index.ts +62 -0
  227. package/src/components/LNB/LNB.context.tsx +32 -0
  228. package/src/components/LNB/LNB.module.scss +99 -0
  229. package/src/components/LNB/LNB.tsx +190 -0
  230. package/src/components/LNB/README.md +411 -0
  231. package/src/components/LNB/makeNavigation.ts +51 -0
  232. package/src/components/LNB/navigation.d.ts +15 -0
  233. package/src/components/LNB/navigation.json +211 -0
  234. package/src/components/Label/Label.colors.tsx +241 -0
  235. package/src/components/Label/Label.module.scss +31 -0
  236. package/src/components/Label/Label.tsx +54 -0
  237. package/src/components/LazyImage/LazyImage.module.scss +6 -0
  238. package/src/components/LazyImage/LazyImage.tsx +107 -0
  239. package/src/components/List/List.module.scss +81 -0
  240. package/src/components/List/List.tsx +91 -0
  241. package/src/components/List/README.md +87 -0
  242. package/src/components/MobilePicker/MobilePicker.context.tsx +22 -0
  243. package/src/components/MobilePicker/MobilePicker.module.scss +57 -0
  244. package/src/components/MobilePicker/MobilePicker.tsx +336 -0
  245. package/src/components/MobilePicker/README.md +159 -0
  246. package/src/components/Modal/Modal.tsx +77 -0
  247. package/src/components/Modal/README.md +130 -0
  248. package/src/components/Pagination/Pagination.colors.tsx +85 -0
  249. package/src/components/Pagination/Pagination.context.tsx +28 -0
  250. package/src/components/Pagination/Pagination.module.scss +60 -0
  251. package/src/components/Pagination/Pagination.tsx +234 -0
  252. package/src/components/Popup/Popup.context.tsx +15 -0
  253. package/src/components/Popup/Popup.module.scss +53 -0
  254. package/src/components/Popup/Popup.tsx +116 -0
  255. package/src/components/Popup/README.md +170 -0
  256. package/src/components/QRCode/QRCode.module.scss +2 -0
  257. package/src/components/QRCode/QRCode.tsx +61 -0
  258. package/src/components/ScrollCalendar/ScrollCalendar.context.tsx +26 -0
  259. package/src/components/ScrollCalendar/ScrollCalendar.module.scss +42 -0
  260. package/src/components/ScrollCalendar/ScrollCalendar.tsx +448 -0
  261. package/src/components/ScrollSpy/README.md +62 -0
  262. package/src/components/ScrollSpy/ScrollSpy.tsx +130 -0
  263. package/src/components/Sheet/README.md +92 -0
  264. package/src/components/Sheet/Sheet.context.tsx +23 -0
  265. package/src/components/Sheet/Sheet.module.scss +68 -0
  266. package/src/components/Sheet/Sheet.tsx +146 -0
  267. package/src/components/Slider/README.md +639 -0
  268. package/src/components/Slider/Slider.backup.tsx +477 -0
  269. package/src/components/Slider/Slider.context.tsx +67 -0
  270. package/src/components/Slider/Slider.module.scss +123 -0
  271. package/src/components/Slider/Slider.tsx +467 -0
  272. package/src/components/Stepper/README.md +320 -0
  273. package/src/components/Stepper/Stepper.context.tsx +49 -0
  274. package/src/components/Stepper/Stepper.module.scss +163 -0
  275. package/src/components/Stepper/Stepper.tsx +219 -0
  276. package/src/components/Tab/Tab.colors.tsx +54 -0
  277. package/src/components/Tab/Tab.context.tsx +64 -0
  278. package/src/components/Tab/Tab.module.scss +239 -0
  279. package/src/components/Tab/Tab.tsx +123 -0
  280. package/src/components/Tab/cx.ts +6 -0
  281. package/src/components/Table/README.md +162 -0
  282. package/src/components/Table/Table.context.tsx +23 -0
  283. package/src/components/Table/Table.hook.ts +51 -0
  284. package/src/components/Table/Table.module.scss +83 -0
  285. package/src/components/Table/Table.tsx +147 -0
  286. package/src/components/Thumbnail/README.md +302 -0
  287. package/src/components/Thumbnail/Thumbnail.context.tsx +42 -0
  288. package/src/components/Thumbnail/Thumbnail.module.scss +149 -0
  289. package/src/components/Thumbnail/Thumbnail.tsx +391 -0
  290. package/src/components/TimeInput/README.md +118 -0
  291. package/src/components/TimeInput/TimeInput.colors.tsx +76 -0
  292. package/src/components/TimeInput/TimeInput.context.tsx +58 -0
  293. package/src/components/TimeInput/TimeInput.module.scss +211 -0
  294. package/src/components/TimeInput/TimeInput.tsx +411 -0
  295. package/src/components/WeeklyCalendar/WeeklyCalendar.context.tsx +88 -0
  296. package/src/components/WeeklyCalendar/WeeklyCalendar.module.scss +225 -0
  297. package/src/components/WeeklyCalendar/WeeklyCalendar.tsx +772 -0
  298. package/src/components/WeeklyCalendar/dayjs.util.ts +336 -0
  299. package/src/components/WeeklyCalendar/weeklyCalendar.util.ts +583 -0
  300. package/src/components/WisywygEditor/Quill/Editor.tsx +148 -0
  301. package/src/constant/locale.constant.ts +6 -0
  302. package/src/globals.scss +80 -0
  303. package/src/hooks/useColorScheme.tsx +48 -0
  304. package/src/hooks/useElementRect.tsx +128 -0
  305. package/src/hooks/useIntersectionObserver.tsx +33 -0
  306. package/src/index.css +17 -0
  307. package/src/index.ts +187 -0
  308. package/src/main.tsx +10 -0
  309. package/src/styles/_fontSize.mixin.scss +57 -0
  310. package/src/styles/_fontWeight.mixin.scss +15 -0
  311. package/src/styles/_lineHeight.mixin.scss +57 -0
  312. package/src/styles/_scrollbar.mixin.scss +49 -0
  313. package/src/styles/baseColor.ts +297 -0
  314. package/src/styles/color.ts +272 -0
  315. package/src/styles/color2.ts +200 -0
  316. package/src/styles/scrollbar.README.md +72 -0
  317. package/src/styles/typography.scss +170 -0
  318. package/src/utils/aws.util.ts +180 -0
  319. package/src/utils/common.utill.ts +45 -0
  320. package/src/vite-env.d.ts +1 -0
  321. package/tsconfig.app.json +24 -0
  322. package/tsconfig.json +29 -0
  323. package/tsconfig.node.json +10 -0
  324. package/tsconfig.node.tsbuildinfo +1 -0
  325. package/tsconfig.tsbuildinfo +1 -0
  326. package/vite.config.d.ts +2 -0
  327. package/vite.config.js +47 -0
  328. package/vite.config.ts +50 -0
@@ -0,0 +1,61 @@
1
+ import React from "react";
2
+
3
+ export type CascaderOption = {
4
+ id: string;
5
+ label: string;
6
+ disabled?: boolean;
7
+ role?: "title" | "divider";
8
+ children?: CascaderOption[];
9
+ [key: string]: unknown;
10
+ };
11
+
12
+ export type OnSelectProps = {
13
+ option: CascaderOption;
14
+ level: number;
15
+ };
16
+
17
+ type CascaderContextType = {
18
+ options: CascaderOption[];
19
+ activeOptions?: CascaderOption[];
20
+ selectedOptions?: CascaderOption[][];
21
+ showChildrenCount?: boolean;
22
+ columnPositionFromParent?: boolean;
23
+ columnOpenAnimation?: boolean;
24
+ maxColumnView?: number;
25
+ onSelect?: (props: OnSelectProps) => void;
26
+
27
+ // private
28
+ selectedOptionTop?: number[];
29
+ setSelectedOptionTop?: React.Dispatch<React.SetStateAction<number[]>>;
30
+ };
31
+
32
+ const initialState: CascaderContextType = {
33
+ options: [],
34
+ showChildrenCount: false,
35
+ columnPositionFromParent: false,
36
+ columnOpenAnimation: false,
37
+ maxColumnView: 6,
38
+ };
39
+
40
+ export const CascaderContext =
41
+ React.createContext<CascaderContextType>(initialState);
42
+
43
+ export type CascaderProviderProps = React.PropsWithChildren<
44
+ CascaderContextType & {
45
+ className?: string;
46
+ }
47
+ >;
48
+
49
+ export const CascaderProvider = (props: CascaderProviderProps) => {
50
+ const { children } = props;
51
+
52
+ return (
53
+ <CascaderContext.Provider
54
+ value={{
55
+ ...props,
56
+ }}
57
+ >
58
+ {children}
59
+ </CascaderContext.Provider>
60
+ );
61
+ };
@@ -0,0 +1,502 @@
1
+ import React from "react";
2
+ import type { OnSelectProps, CascaderOption } from "./Cascader";
3
+
4
+ interface UseCascaderProps {
5
+ options: CascaderOption[];
6
+ multiple?: boolean;
7
+ }
8
+
9
+ export interface UseCascaderReturn {
10
+ /**
11
+ * 활성화(active)된 옵션들
12
+ */
13
+ activeOptions: CascaderOption[];
14
+
15
+ /**
16
+ * 선택된 옵션들
17
+ */
18
+ selectedOptions: CascaderOption[][];
19
+
20
+ /**
21
+ * 활성화(active)된 옵션들을 기반으로 각 레벨별 선택 가능한 옵션들의 배열을 생성합니다.
22
+ *
23
+ * returns
24
+ *
25
+ * - 각 레벨별 옵션 배열을 포함하는 2차원 배열
26
+ *
27
+ * - 첫 번째 레벨(index 0)은 항상 최상위 옵션들을 포함
28
+ *
29
+ * - 이후 레벨들은 활성화된 옵션의 자식들을 순차적으로 포함
30
+ *
31
+ */
32
+ columns: CascaderOption[][];
33
+
34
+ /**
35
+ * 선택된 옵션들 중 자식이 없는 최종 옵션들만 필터링하여 반환
36
+ *
37
+ * returns: [{ id: "gangnam", ... }, { id: "yeoksam1", ... }, { id: "yeoksam2", ... }]
38
+ */
39
+ selectedResult: CascaderOption[];
40
+
41
+ /**
42
+ * 옵션 클릭 시 처리하는 핸들러
43
+ *
44
+ * 해당 메소드를 Cascader.Root에 전달하여 사용합니다.
45
+ *
46
+ * params - 클릭된 옵션과 레벨 정보 { option: CascaderOption, level: number }
47
+ *
48
+ * example - selectHandler({ option: { id: "korea", ... }, level: 0 })
49
+ */
50
+ selectHandler: (params: OnSelectProps) => void;
51
+
52
+ /**
53
+ * 특정 옵션을 선택하는 핸들러
54
+ *
55
+ * 해당 옵션을 통해 선택하면 해당 옵션과 그 부모 옵션들을 선택하거나 해제합니다.
56
+ *
57
+ * 만약 해당 옵션을 제거했을때 선택된 부모까지 전부 체크해서 선택되어있는 최종옵션이 없으면 상위의 부모옵션도 선택을 해제합니다.
58
+ *
59
+ * 토글식으로 작동됩니다.
60
+ *
61
+ * params - 선택할 옵션의 ID { id: string }
62
+ *
63
+ * example - selectByIdHandler({ id: "gangnam" })
64
+ */
65
+ selectByIdHandler: (params: { id: string }) => void;
66
+
67
+ /**
68
+ * 모든 옵션을 초기화하는 핸들러
69
+ *
70
+ * params - 초기화할 옵션 종류 { active: boolean, selected: boolean }
71
+ *
72
+ * example - resetAll({ active: true, selected: true })
73
+ */
74
+ resetAll: (params?: { active?: boolean; selected?: boolean }) => void;
75
+
76
+ /**
77
+ * 특정 옵션과 해당 특정옵션의 자식중 선택되어 있는 옵션을 초기화하는 핸들러
78
+ *
79
+ * 해당 옵션을 초기화했을때 부모옵션까지 탐색해서 선택된 자식이 없을 경우 부모옵션도 초기화합니다.
80
+ *
81
+ * params - 초기화할 옵션의 ID { id: string }
82
+ *
83
+ * example - resetSelectedById({ id: "gangnam" })
84
+ */
85
+ resetSelectedById: (params: { id: string }) => void;
86
+
87
+ /**
88
+ * 특정 레벨까지 활성화(active)된 옵션들을 초기화하는 핸들러
89
+ *
90
+ * params - 초기화할 레벨 { level: number }
91
+ *
92
+ * example - resetActiveOptions({ level: 1 })
93
+ */
94
+ resetActiveOptions: (params?: { level?: number }) => void;
95
+ }
96
+
97
+ export function useCascader(props: UseCascaderProps): UseCascaderReturn {
98
+ const { options, multiple = false } = props;
99
+
100
+ // 현재 활성화된(열려있는) 옵션 상태
101
+ const [activeOptions, setActiveOptions] = React.useState<CascaderOption[]>(
102
+ []
103
+ );
104
+
105
+ // 현재 선택된 옵션 상태
106
+ const [selectedOptions, setSelectedOptions] = React.useState<
107
+ CascaderOption[][]
108
+ >([]);
109
+
110
+ // 옵션과 부모를 찾는 재귀 함수
111
+ interface FindOptionWithParentsProps {
112
+ options: CascaderOption[];
113
+ targetId: string;
114
+ parents?: CascaderOption[];
115
+ }
116
+ const findOptionWithParents = React.useCallback(
117
+ ({
118
+ options,
119
+ targetId,
120
+ parents = [],
121
+ }: FindOptionWithParentsProps): {
122
+ parent: CascaderOption;
123
+ target: CascaderOption;
124
+ } | null => {
125
+ // 모든 옵션을 순회하며 검색
126
+ for (const option of options) {
127
+ // 찾고자 하는 ID와 일치하는 옵션을 찾은 경우
128
+ if (option.id === targetId) {
129
+ // children이 있는 옵션은 중간 노드이므로 무시
130
+ if (option.children?.length) {
131
+ return null;
132
+ }
133
+ // 최종 옵션인 경우 마지막 부모와 함께 반환
134
+ return {
135
+ parent: parents[parents.length - 1],
136
+ target: option,
137
+ };
138
+ }
139
+
140
+ // 현재 옵션에 자식이 있는 경우 재귀적으로 검색
141
+ if (option.children?.length) {
142
+ const result = findOptionWithParents({
143
+ options: option.children,
144
+ targetId,
145
+ parents: [...parents, option],
146
+ });
147
+ if (result) return result;
148
+ }
149
+ }
150
+ // 찾지 못한 경우 null 반환
151
+ return null;
152
+ },
153
+ []
154
+ );
155
+
156
+ const columns = React.useMemo(() => {
157
+ const result: CascaderOption[][] = [];
158
+ result[0] = options;
159
+ // activeOptions가 있는 경우에만 실행
160
+ if (activeOptions.length > 0) {
161
+ // 현재 레벨의 옵션들을 저장하는 변수, 초기값은 최상위 옵션들
162
+ let currentLevelOptions = options;
163
+
164
+ // activeOptions를 순회하면서 각 레벨의 옵션들을 result 배열에 추가
165
+ activeOptions.forEach((active, index) => {
166
+ // 현재 레벨에서 active한 옵션을 찾음
167
+ const found = currentLevelOptions.find((opt) => opt.id === active.id);
168
+ // 찾은 옵션에 자식이 있는 경우
169
+ if (found?.children && found.children.length > 0) {
170
+ // 다음 레벨 탐색을 위해 현재 레벨의 옵션을 자식으로 업데이트
171
+ currentLevelOptions = found.children;
172
+ // 결과 배열의 다음 인덱스에 자식 옵션들을 저장
173
+ result[index + 1] = currentLevelOptions;
174
+ }
175
+ });
176
+ }
177
+
178
+ return result;
179
+ }, [activeOptions, options]);
180
+
181
+ const selectedResult = React.useMemo(() => {
182
+ // 선택된 옵션들 중 자식이 없는 최종 옵션들만 필터링하여 반환
183
+ return selectedOptions.reduce<CascaderOption[]>((acc, levelOptions) => {
184
+ // 현재 레벨의 옵션들 중 자식이 없는 옵션들만 필터링
185
+ const result = levelOptions.filter((option) => !option.children?.length);
186
+ // 누적된 결과와 현재 레벨의 결과를 합침
187
+ return [...acc, ...result];
188
+ }, []);
189
+ }, [selectedOptions]);
190
+
191
+ const selectHandler = (params: OnSelectProps) => {
192
+ const { option, level } = params;
193
+
194
+ const optionWithParent = {
195
+ ...option,
196
+ parentId: level > 0 ? activeOptions[level - 1]?.id : undefined,
197
+ };
198
+
199
+ const isSelected = selectedOptions[level]?.some(
200
+ (opt) => opt.id === option.id
201
+ );
202
+
203
+ if (isSelected) {
204
+ // 옵션이 선택되어 있지만 활성화되지 않은 상태이고, 자식이 있는 경우를 체크
205
+ const isSelectedButNotActive =
206
+ selectedOptions[level]?.some((opt) => opt.id === option.id) &&
207
+ activeOptions[level]?.id !== option.id &&
208
+ (option.children?.length ?? 0) > 0;
209
+
210
+ if (isSelectedButNotActive) {
211
+ // 선택되었지만 활성화되지 않은 옵션을 활성화
212
+ setActiveOptions((curr) => {
213
+ const newActive = [...curr];
214
+
215
+ // 현재 레벨의 옵션을 활성화하고 그 이후 레벨은 제거
216
+ newActive[level] = optionWithParent;
217
+ newActive.splice(level + 1);
218
+
219
+ return newActive;
220
+ });
221
+
222
+ return;
223
+ }
224
+ // 자식이 없는 최종 노드인 경우
225
+ if (!option.children?.length) {
226
+ setSelectedOptions((prev) => {
227
+ const newSelected = [...prev];
228
+ // 현재 레벨에서 선택된 옵션만 제거
229
+ newSelected[level] = newSelected[level].filter(
230
+ (opt) => opt.id !== option.id
231
+ );
232
+
233
+ // 특정 옵션 트리에서 선택된 최종 노드가 있는지 확인하는 재귀 함수
234
+ const hasSelectedEndNode = (options: CascaderOption[]): boolean => {
235
+ return options.some(
236
+ (opt) =>
237
+ (!opt.children?.length &&
238
+ newSelected.some((level) =>
239
+ level.some((selected) => selected.id === opt.id)
240
+ )) ||
241
+ (opt.children?.length && hasSelectedEndNode(opt.children))
242
+ );
243
+ };
244
+
245
+ // 현재 레벨부터 상위 레벨로 올라가면서 유효하지 않은 부모 옵션 제거
246
+ for (let i = level - 1; i >= 0; i--) {
247
+ if (newSelected[i]) {
248
+ newSelected[i] = newSelected[i].filter((opt) =>
249
+ opt.children?.length ? hasSelectedEndNode(opt.children) : true
250
+ );
251
+ }
252
+ }
253
+
254
+ // 선택된 옵션이 없는 빈 레벨 제거
255
+ return newSelected.filter((level) => level.length > 0);
256
+ });
257
+ }
258
+ }
259
+
260
+ // 활성화된 옵션 상태 업데이트
261
+ setActiveOptions((curr) => {
262
+ const newActive = [...curr];
263
+
264
+ // 이미 활성화되어 있거나 선택된 옵션인 경우 해당 레벨부터 제거
265
+ if (curr[level]?.id === option.id || isSelected) {
266
+ newActive.splice(level);
267
+ } else {
268
+ // 새로운 옵션을 활성화하고 그 이후 레벨은 제거
269
+ newActive[level] = optionWithParent;
270
+ newActive.splice(level + 1);
271
+ }
272
+
273
+ return newActive;
274
+ });
275
+ };
276
+
277
+ interface SelectByIdHandlerProps {
278
+ id: string;
279
+ }
280
+
281
+ const selectByIdHandler = React.useCallback(
282
+ (params: SelectByIdHandlerProps) => {
283
+ const { id } = params;
284
+
285
+ setSelectedOptions((prev) => {
286
+ // 이미 선택된 옵션인지 확인
287
+ const isAlreadySelected = prev.some((level) =>
288
+ level.some((opt) => opt.id === id)
289
+ );
290
+
291
+ if (isAlreadySelected) {
292
+ // 선택 해제 로직
293
+ return prev.filter((level) => !level.some((opt) => opt.id === id));
294
+ } else {
295
+ // 새로운 옵션 선택 로직
296
+ const result = findOptionWithParents({ options, targetId: id });
297
+ if (!result) return prev;
298
+
299
+ // 부모가 이미 있는지 확인
300
+ const parentExists = prev[0]?.some(
301
+ (opt) => opt.id === result.parent.id
302
+ );
303
+
304
+ if (parentExists) {
305
+ // 부모가 이미 있으면 자식만 추가
306
+ return [prev[0], [...(prev[1] || []), result.target]];
307
+ } else {
308
+ // 부모가 없으면 새로운 배열 생성
309
+ return [[result.parent], [...(prev[1] || []), result.target]];
310
+ }
311
+ }
312
+ });
313
+ },
314
+ [options, findOptionWithParents]
315
+ );
316
+
317
+ interface ResetAllHandlerProps {
318
+ active?: boolean;
319
+ selected?: boolean;
320
+ }
321
+
322
+ const resetAll = React.useCallback((params?: ResetAllHandlerProps) => {
323
+ const { active = true, selected = true } = params ?? {};
324
+
325
+ if (active) {
326
+ setActiveOptions([]);
327
+ }
328
+ if (selected) {
329
+ setSelectedOptions([]);
330
+ }
331
+ }, []);
332
+
333
+ interface ResetSelectedByIdHandlerProps {
334
+ id: string;
335
+ }
336
+
337
+ const resetSelectedById = React.useCallback(
338
+ (params: ResetSelectedByIdHandlerProps) => {
339
+ const { id } = params;
340
+
341
+ setSelectedOptions((prev) => {
342
+ const newSelected = [...prev];
343
+
344
+ // 일치하는 id를 가진 옵션의 레벨과 인덱스 찾기
345
+ let targetLevel = -1;
346
+ let targetIndex = -1;
347
+
348
+ // 모든 레벨을 순회하면서 target의 위치 찾기
349
+ newSelected.forEach((levelOptions, level) => {
350
+ const foundIndex = levelOptions.findIndex((opt) => opt.id === id);
351
+ if (foundIndex !== -1) {
352
+ targetLevel = level;
353
+ targetIndex = foundIndex;
354
+ }
355
+ });
356
+
357
+ if (targetLevel !== -1) {
358
+ // 찾은 target 옵션 제거
359
+ const targetOption = newSelected[targetLevel][targetIndex];
360
+ newSelected[targetLevel].splice(targetIndex, 1);
361
+
362
+ // target의 자식 옵션들을 재귀적으로 제거하는 함수
363
+ const removeChildrenRecursive = (
364
+ parentId: string,
365
+ fromLevel: number
366
+ ) => {
367
+ // fromLevel부터 끝까지 순회하면서 자식 옵션들 제거
368
+ for (let level = fromLevel; level < newSelected.length; level++) {
369
+ newSelected[level] = newSelected[level].filter((opt) => {
370
+ const isChild =
371
+ findOptionWithParents({ options, targetId: opt.id })?.parent
372
+ .id !== parentId;
373
+ return isChild;
374
+ });
375
+ }
376
+ };
377
+
378
+ // target의 자식들 제거 실행
379
+ removeChildrenRecursive(targetOption.id, targetLevel + 1);
380
+
381
+ // 자식이 없는 부모 옵션들을 제거하는 재귀 함수
382
+ const removeParentIfNoChildren = (currentLevel: number) => {
383
+ if (currentLevel < 0) return;
384
+
385
+ const parentOptions = newSelected[currentLevel];
386
+ if (!parentOptions) return;
387
+
388
+ // 현재 레벨의 부모들 중 자식이 없는 옵션 제거
389
+ newSelected[currentLevel] = parentOptions.filter((parentOpt) => {
390
+ // 해당 부모의 자식이 있는지 확인
391
+ const hasSelectedChildren = newSelected
392
+ .slice(currentLevel + 1)
393
+ .some((levelOpts) =>
394
+ levelOpts.some(
395
+ (opt) =>
396
+ findOptionWithParents({ options, targetId: opt.id })
397
+ ?.parent.id === parentOpt.id
398
+ )
399
+ );
400
+ return hasSelectedChildren;
401
+ });
402
+
403
+ // 상위 레벨로 올라가면서 재귀 실행
404
+ removeParentIfNoChildren(currentLevel - 1);
405
+ };
406
+
407
+ // 자식이 없는 부모 제거 실행
408
+ removeParentIfNoChildren(targetLevel - 1);
409
+
410
+ // 옵션이 없는 빈 레벨은 제거하고 반환
411
+ return newSelected.filter((level) => level.length > 0);
412
+ }
413
+
414
+ return newSelected;
415
+ });
416
+ },
417
+ [options, findOptionWithParents]
418
+ );
419
+
420
+ interface resetActiveOptionsHandlerProps {
421
+ level?: number;
422
+ }
423
+
424
+ const resetActiveOptions = React.useCallback(
425
+ (params?: resetActiveOptionsHandlerProps) => {
426
+ const { level = 0 } = params || {};
427
+
428
+ setActiveOptions((curr) => {
429
+ const newActive = [...curr];
430
+ newActive.splice(level, newActive.length - level);
431
+ return newActive;
432
+ });
433
+ },
434
+ []
435
+ );
436
+
437
+ // 선택된 옵션 추
438
+ React.useEffect(() => {
439
+ if (!multiple) {
440
+ const newSelected = activeOptions.map((option) => [option]);
441
+ setSelectedOptions(newSelected);
442
+ return;
443
+ }
444
+
445
+ // 활성화된 옵션 중 마지막 옵션 가져오기
446
+ const lastOption = activeOptions.at(-1);
447
+ // 마지막 옵션이 자식이 없는 경우에만 선택 처리
448
+ if (!lastOption?.children || lastOption.children?.length === 0) {
449
+ setSelectedOptions((prev) => {
450
+ const newSelected = [...prev];
451
+
452
+ // 마지막 옵션이 이미 선택되어 있는지 확인
453
+ const hasLastOption = prev.some((levelOptions) =>
454
+ levelOptions.some((opt) => opt.id === lastOption?.id)
455
+ );
456
+
457
+ // 활성화된 옵션들을 순회하면서 선택 상태 업데이트
458
+ activeOptions.forEach((active, index) => {
459
+ // 해당 레벨의 배열이 없으면 생성
460
+ if (!newSelected[index]) {
461
+ newSelected[index] = [];
462
+ }
463
+
464
+ // 마지막 레벨의 옵션 처리
465
+ if (index === activeOptions.length - 1) {
466
+ if (hasLastOption) {
467
+ // 이미 선택된 경우 제거
468
+ newSelected[index] = newSelected[index].filter(
469
+ (opt) => opt.id !== active.id
470
+ );
471
+ } else {
472
+ // 선택되지 않은 경우 추가
473
+ newSelected[index].push(active);
474
+ }
475
+ } else {
476
+ // 중간 레벨의 옵션들은 중복되지 않게 추가
477
+ if (!newSelected[index].some((opt) => opt.id === active.id)) {
478
+ newSelected[index].push(active);
479
+ }
480
+ }
481
+ });
482
+
483
+ // 빈 레벨 제거 후 반환
484
+ return newSelected.filter((level) => level.length > 0);
485
+ });
486
+ }
487
+ }, [activeOptions, multiple]);
488
+
489
+ const result = {
490
+ activeOptions,
491
+ selectedOptions,
492
+ columns,
493
+ selectedResult,
494
+ selectHandler,
495
+ selectByIdHandler,
496
+ resetAll,
497
+ resetSelectedById,
498
+ resetActiveOptions,
499
+ };
500
+
501
+ return result;
502
+ }
@@ -0,0 +1,143 @@
1
+ .Root {
2
+ position: relative;
3
+ display: inline-flex;
4
+ }
5
+
6
+ .Menu {
7
+ position: absolute;
8
+ top: 0;
9
+ left: 0;
10
+ display: flex;
11
+ border-radius: 4px;
12
+ align-items: flex-start;
13
+ }
14
+
15
+ .Column {
16
+ --selected-option-top: 0;
17
+ --max-column-view: 6;
18
+ position: relative;
19
+ left: 0;
20
+ top: 0;
21
+ translate: 0 var(--selected-option-top);
22
+ min-width: 180px;
23
+ max-height: calc(40px * var(--max-column-view));
24
+ overflow: auto;
25
+ box-sizing: border-box;
26
+ border: 1px solid #e8e8e9;
27
+ background: #fff;
28
+ margin-left: -1px;
29
+ display: flex;
30
+ flex-direction: column;
31
+ overscroll-behavior: contain;
32
+
33
+ &.columnOpenAnimation {
34
+ transition: translate 0.2s ease-in-out;
35
+ }
36
+
37
+ &::-webkit-scrollbar {
38
+ width: 6px;
39
+ }
40
+
41
+ &::-webkit-scrollbar-track {
42
+ background: transparent;
43
+ }
44
+
45
+ &::-webkit-scrollbar-thumb {
46
+ background: #e8e8e9;
47
+ border-radius: 2px;
48
+ }
49
+
50
+ &::-webkit-scrollbar-thumb:hover {
51
+ background: #d1d1d1;
52
+ }
53
+
54
+ &:first-child {
55
+ border-radius: 4px 0 0 4px;
56
+ margin-left: 0;
57
+ }
58
+
59
+ &:last-child {
60
+ border-radius: 0 4px 4px 0;
61
+ }
62
+ }
63
+
64
+ .Item {
65
+ --item-height: 40px;
66
+
67
+ height: var(--item-height);
68
+ box-sizing: border-box;
69
+ padding: 8px 12px;
70
+ cursor: pointer;
71
+ display: flex;
72
+ align-items: center;
73
+ justify-content: space-between;
74
+
75
+ &:hover {
76
+ background-color: #f5f5f5;
77
+ }
78
+
79
+ &.title {
80
+ font-weight: bold;
81
+ cursor: default;
82
+ background-color: transparent;
83
+
84
+ &:hover {
85
+ background-color: transparent;
86
+ }
87
+ }
88
+
89
+ &.divider {
90
+ height: 1px;
91
+ background-color: #e8e8e9;
92
+ cursor: default;
93
+ padding: 0;
94
+ margin: 8px 0;
95
+ flex-shrink: 0;
96
+
97
+ &:hover {
98
+ background-color: #e8e8e9;
99
+ }
100
+ }
101
+
102
+ &.isSelected {
103
+ font-weight: 500;
104
+ color: #688dee;
105
+ .GoNext {
106
+ & > path {
107
+ fill: #688dee;
108
+ }
109
+ }
110
+ }
111
+
112
+ &.disabled {
113
+ color: #ccc;
114
+ cursor: not-allowed;
115
+ .GoNext {
116
+ & > path {
117
+ fill: #ccc;
118
+ }
119
+ }
120
+
121
+ &:hover {
122
+ background-color: transparent;
123
+ }
124
+ }
125
+
126
+ .ItemText {
127
+ white-space: nowrap;
128
+ overflow: hidden;
129
+ text-overflow: ellipsis;
130
+ width: calc(180px - 56px);
131
+ flex-shrink: 0;
132
+ }
133
+ }
134
+
135
+ .GoNext {
136
+ flex-shrink: 0;
137
+
138
+ &.isSelected {
139
+ path {
140
+ fill: #688dee;
141
+ }
142
+ }
143
+ }