@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,467 @@
1
+ "use client";
2
+ /* eslint-disable react-refresh/only-export-components */
3
+ import React from "react";
4
+ import cn from "classnames/bind";
5
+ import styles from "./Slider.module.scss";
6
+ import {
7
+ SliderContext,
8
+ SliderProvider,
9
+ SliderProviderProps,
10
+ } from "./Slider.context";
11
+
12
+ const cx = cn.bind(styles);
13
+
14
+ type MarkAsProps = {
15
+ label: string | number | React.ReactNode;
16
+ active: boolean;
17
+ };
18
+ type MarksProps = React.PropsWithChildren<{
19
+ className?: string;
20
+ as?: (props: MarkAsProps) => React.ReactNode;
21
+ }>;
22
+ const Marks = (props: MarksProps) => {
23
+ const { className, as } = props;
24
+
25
+ const {
26
+ progressRef,
27
+ marks,
28
+ markActiveEffect,
29
+ defaultValue,
30
+ max,
31
+ min,
32
+ invert,
33
+ } = React.useContext(SliderContext);
34
+
35
+ const markActiveCompare = React.useCallback(
36
+ (value: number) => {
37
+ if (!markActiveEffect) return false;
38
+ if (
39
+ progressRef?.current &&
40
+ defaultValue &&
41
+ max !== undefined &&
42
+ min !== undefined
43
+ ) {
44
+ const range = max - min;
45
+
46
+ // 실제값을 비율값으로 변환
47
+ const defaultValuePer = defaultValue.map((v) => {
48
+ return ((v - min) / range) * 100;
49
+ });
50
+
51
+ if (defaultValuePer.length > 1) {
52
+ // defaultValue 배열에 actualValue가 포함되는지 확인
53
+ return invert
54
+ ? value <= Math.min(...defaultValuePer) ||
55
+ value >= Math.max(...defaultValuePer)
56
+ : value >= Math.min(...defaultValuePer) &&
57
+ value <= Math.max(...defaultValuePer);
58
+ }
59
+ return invert
60
+ ? value >= Math.max(...defaultValuePer)
61
+ : value <= Math.max(...defaultValuePer);
62
+ }
63
+ return false; // progressRef가 없거나 defaultValue가 없을 경우 false 반환
64
+ },
65
+ [markActiveEffect, progressRef, defaultValue, min, max, invert]
66
+ );
67
+
68
+ return marks?.map(({ value, label }, idx) => (
69
+ <div
70
+ key={idx}
71
+ className={cx("Mark", className)}
72
+ style={{
73
+ left: `${value}%`,
74
+ }}
75
+ >
76
+ {as ? (
77
+ as({ label, active: markActiveCompare(value) })
78
+ ) : (
79
+ <div className={cx("Point")}>
80
+ <div
81
+ className={cx("Label", {
82
+ active: markActiveCompare(value),
83
+ })}
84
+ >
85
+ {label}
86
+ </div>
87
+ </div>
88
+ )}
89
+ </div>
90
+ ));
91
+ };
92
+ type ThumbAsProps = {
93
+ hidden: boolean;
94
+ isDragging: boolean;
95
+ children: React.ReactNode;
96
+ labelAlwaysOn?: boolean;
97
+ value?: string | number;
98
+ };
99
+ type ThumbProps = React.PropsWithChildren<{
100
+ index?: number;
101
+ className?: string;
102
+ as?: (props: ThumbAsProps) => React.ReactNode;
103
+ }>;
104
+ const Thumb = (props: ThumbProps) => {
105
+ const { index = 0, children, className, as } = props;
106
+
107
+ const {
108
+ progressRef,
109
+ min,
110
+ max,
111
+ step,
112
+ defaultValue,
113
+ labelAlwaysOn,
114
+ draggingIndex,
115
+ label,
116
+ scale,
117
+ onChange,
118
+ setDefaultValue,
119
+ } = React.useContext(SliderContext);
120
+
121
+ const thumbPosition = React.useMemo(() => {
122
+ if (
123
+ progressRef?.current &&
124
+ defaultValue !== undefined &&
125
+ max !== undefined &&
126
+ min !== undefined
127
+ ) {
128
+ const rect = progressRef.current.getBoundingClientRect();
129
+ const sliderWidth = rect.width;
130
+ const value = defaultValue[index];
131
+ const range = max - min;
132
+ const position = ((value - min) / range) * sliderWidth;
133
+
134
+ return position;
135
+ }
136
+ }, [progressRef, index, defaultValue, min, max]);
137
+
138
+ const valueView = React.useMemo(() => {
139
+ if (label === null) return;
140
+ return (
141
+ label?.(scale?.(defaultValue?.[index] ?? 0) ?? 0) ??
142
+ scale?.(defaultValue?.[index] ?? 0)
143
+ );
144
+ }, [index, defaultValue, scale, label]);
145
+
146
+ React.useEffect(() => {
147
+ if (!onChange && setDefaultValue) {
148
+ setDefaultValue((curr) => {
149
+ const newCurr = [...curr];
150
+ if (index !== 0 && max !== undefined) {
151
+ newCurr[index] =
152
+ newCurr[index - 1] + (step ?? 10) > max
153
+ ? max
154
+ : newCurr[index - 1] + (step ?? 10);
155
+ }
156
+ return newCurr;
157
+ });
158
+ }
159
+ }, [index, max, step, onChange, setDefaultValue]);
160
+
161
+ return (
162
+ <div
163
+ className={cx("Thumb", className)}
164
+ style={{
165
+ transform: `translate(calc(-50% + ${thumbPosition}px), calc(-50% + var(--progress-progress-height) / 2))`,
166
+ }}
167
+ >
168
+ {as ? (
169
+ as({
170
+ labelAlwaysOn,
171
+ hidden: label === null,
172
+ isDragging: draggingIndex === index,
173
+ value: valueView,
174
+ children,
175
+ })
176
+ ) : (
177
+ <div
178
+ className={cx("Point", {
179
+ labelAlwaysOn,
180
+ hidden: label === null,
181
+ isDragging: draggingIndex === index,
182
+ })}
183
+ data-value={valueView}
184
+ >
185
+ {children}
186
+ </div>
187
+ )}
188
+ </div>
189
+ );
190
+ };
191
+
192
+ type ProgressProps = {
193
+ children: React.ReactNode;
194
+ color?: React.CSSProperties["color"];
195
+ className?: string;
196
+ valueClassName?: string;
197
+ };
198
+ const Progress = (props: ProgressProps) => {
199
+ const { children, color = "#688DEE", className, valueClassName } = props;
200
+
201
+ const {
202
+ max,
203
+ min,
204
+ step,
205
+ progressRef,
206
+ readOnly,
207
+ disabled,
208
+ invert,
209
+ defaultValue,
210
+ draggingIndex,
211
+ onChange,
212
+ setDefaultValue,
213
+ setDraggingIndex,
214
+ } = React.useContext(SliderContext);
215
+
216
+ const rangeStyle = React.useMemo(() => {
217
+ if (
218
+ progressRef?.current &&
219
+ defaultValue &&
220
+ max !== undefined &&
221
+ min !== undefined
222
+ ) {
223
+ if (defaultValue?.length < 2) {
224
+ const value = defaultValue[0];
225
+ const range = max - min;
226
+ const position = ((value - min) / range) * 100;
227
+ return {
228
+ width: `${position}%`,
229
+ };
230
+ }
231
+ const minValue = Math.min(...defaultValue);
232
+ const maxValue = Math.max(...defaultValue);
233
+ const range = max - min;
234
+ const position = ((maxValue - min) / range) * 100; // 최대값에 대한 위치
235
+ const minPosition = ((minValue - min) / range) * 100; // 최소값에 대한 위치
236
+ const rect = progressRef.current.getBoundingClientRect();
237
+ const sliderWidth = rect.width;
238
+ const minPositionOffset = (minPosition / 100) * sliderWidth;
239
+ return {
240
+ width: `${position - minPosition}%`, // 최소값과 최대값 사이의 너비
241
+ transform: `translateX(${minPositionOffset}px)`, // 최소값에 대한 위치
242
+ };
243
+ }
244
+ }, [progressRef, defaultValue, max, min]);
245
+
246
+ // 마우스 위치에 따라 값을 계산하는 함수
247
+ const calculateValueFromPosition = React.useCallback(
248
+ (clientX: number) => {
249
+ if (
250
+ progressRef?.current &&
251
+ max !== undefined &&
252
+ min !== undefined &&
253
+ step !== undefined
254
+ ) {
255
+ const rect = progressRef.current.getBoundingClientRect();
256
+ const sliderWidth = rect.width;
257
+ const offsetX = clientX - rect.left;
258
+
259
+ // 비율 계산
260
+ const ratio = offsetX / sliderWidth;
261
+ let newValue = min + ratio * (max - min);
262
+
263
+ // step에 맞게 반올림
264
+ newValue = Math.round(newValue / step) * step;
265
+
266
+ // min, max 범위 내로 제한
267
+ return Math.max(min, Math.min(newValue, max));
268
+ }
269
+ return 0; // 기본값으로 반환
270
+ },
271
+ [progressRef, max, min, step]
272
+ );
273
+
274
+ const setValueHandler = React.useCallback(
275
+ (idx: number, value: number) => {
276
+ if (step === undefined || min === undefined || max === undefined) return;
277
+
278
+ const defaultSetChangeHandler = (curr: number[]) => {
279
+ const newCurr = [...curr];
280
+
281
+ if (idx !== 0 && value <= newCurr[0] && newCurr[0] === min) {
282
+ return newCurr;
283
+ } else if (
284
+ idx !== newCurr.length - 1 &&
285
+ value >= newCurr[newCurr.length - 1] &&
286
+ newCurr[newCurr.length - 1] === max
287
+ ) {
288
+ return newCurr;
289
+ } else {
290
+ newCurr[idx] = value;
291
+ }
292
+
293
+ // 좌에서 우
294
+ if (value >= newCurr[idx + 1]) {
295
+ for (let i = idx + 1; i < newCurr.length; i++) {
296
+ if (newCurr[i] + step > max) {
297
+ newCurr[i] = max;
298
+ break;
299
+ }
300
+
301
+ newCurr[i] += step;
302
+ }
303
+ }
304
+ // 우에서 좌
305
+ if (value <= newCurr[idx - 1]) {
306
+ for (let i = idx - 1; i >= 0; i--) {
307
+ if (newCurr[i] - step < min) {
308
+ newCurr[i] = min;
309
+ break;
310
+ }
311
+ newCurr[i] -= step;
312
+ }
313
+ }
314
+
315
+ return newCurr;
316
+ };
317
+
318
+ if (onChange) {
319
+ onChange({ idx, value, step, min, max, defaultSetChangeHandler });
320
+ } else {
321
+ setDefaultValue?.(defaultSetChangeHandler);
322
+ }
323
+ },
324
+ [onChange, setDefaultValue, step, min, max]
325
+ );
326
+
327
+ // 마우스를 클릭했을 때 처리하는 함수
328
+ const handleMouseDown = React.useCallback(
329
+ (e: React.MouseEvent<HTMLDivElement>) => {
330
+ e.preventDefault();
331
+ if (readOnly || disabled) return;
332
+ const newValue = calculateValueFromPosition(e.clientX);
333
+
334
+ let closestIndex = 0;
335
+ let minDiff = Infinity;
336
+ defaultValue?.forEach((val, index) => {
337
+ const diff = Math.abs(newValue - val);
338
+ if (diff < minDiff) {
339
+ minDiff = diff;
340
+ closestIndex = index;
341
+ }
342
+ });
343
+ setDraggingIndex?.(closestIndex);
344
+ setValueHandler(closestIndex, newValue);
345
+ },
346
+ [
347
+ readOnly,
348
+ disabled,
349
+ defaultValue,
350
+ calculateValueFromPosition,
351
+ setDraggingIndex,
352
+ setValueHandler,
353
+ ]
354
+ );
355
+
356
+ // 마우스를 움직일 때 처리하는 함수
357
+ const handleMouseMove = React.useCallback(
358
+ (e: MouseEvent) => {
359
+ e.preventDefault();
360
+ if (readOnly || disabled) return;
361
+ if (draggingIndex !== undefined) {
362
+ const newValue = calculateValueFromPosition(e.clientX);
363
+ setValueHandler(draggingIndex, newValue);
364
+ }
365
+ },
366
+ [
367
+ readOnly,
368
+ disabled,
369
+ draggingIndex,
370
+ calculateValueFromPosition,
371
+ setValueHandler,
372
+ ]
373
+ );
374
+
375
+ const handleMouseUp = React.useCallback(() => {
376
+ if (readOnly || disabled) return;
377
+ setDraggingIndex?.(undefined);
378
+ }, [readOnly, disabled, setDraggingIndex]);
379
+
380
+ React.useEffect(() => {
381
+ if (draggingIndex !== undefined) {
382
+ // 전역적으로 mousemove와 mouseup 이벤트 리스너를 등록
383
+ window.addEventListener("mousemove", handleMouseMove);
384
+ window.addEventListener("mouseup", handleMouseUp);
385
+ } else {
386
+ // 드래그가 끝나면 이벤트 리스너 제거
387
+ window.removeEventListener("mousemove", handleMouseMove);
388
+ window.removeEventListener("mouseup", handleMouseUp);
389
+ }
390
+
391
+ return () => {
392
+ // 컴포넌트 언마운트 시 이벤트 리스너 제거
393
+ window.removeEventListener("mousemove", handleMouseMove);
394
+ window.removeEventListener("mouseup", handleMouseUp);
395
+ };
396
+ }, [draggingIndex, handleMouseMove, handleMouseUp]);
397
+
398
+ return (
399
+ <div
400
+ ref={progressRef}
401
+ className={cx("Progress", className, { readOnly, disabled, invert })}
402
+ onMouseDown={handleMouseDown}
403
+ style={{
404
+ "--progress-value-color": color,
405
+ }}
406
+ >
407
+ <div className={cx("Value", valueClassName)} style={rangeStyle} />
408
+
409
+ {React.Children.map(children, (child, index) => {
410
+ if (React.isValidElement(child) && child.type === Thumb) {
411
+ return React.cloneElement(child, { index } as React.ComponentProps<
412
+ typeof Thumb
413
+ >);
414
+ }
415
+ return child;
416
+ })}
417
+ </div>
418
+ );
419
+ };
420
+
421
+ type OmitContext =
422
+ | "progressRef"
423
+ | "draggingIndex"
424
+ | "setDefaultValue"
425
+ | "setDraggingIndex";
426
+ const Root = (props: Omit<SliderProviderProps, OmitContext>) => {
427
+ const { children } = props;
428
+
429
+ if (props.step !== undefined && props.step <= 0)
430
+ throw new Error("step은 양수여야 합니다!");
431
+
432
+ const progressRef = React.useRef<HTMLDivElement>(null);
433
+
434
+ const [defaultValue, setDefaultValue] = React.useState([props.min ?? 0]);
435
+ const [draggingIndex, setDraggingIndex] = React.useState<number>();
436
+
437
+ const contextValue = React.useMemo(() => {
438
+ return {
439
+ ...props,
440
+ progressRef,
441
+ defaultValue,
442
+ draggingIndex,
443
+ setDefaultValue,
444
+ setDraggingIndex,
445
+ };
446
+ }, [props, defaultValue, draggingIndex, setDefaultValue, setDraggingIndex]);
447
+
448
+ React.useEffect(() => {
449
+ if (props.defaultValue) setDefaultValue(props.defaultValue);
450
+ }, [props.defaultValue]);
451
+
452
+ return <SliderProvider {...contextValue}>{children}</SliderProvider>;
453
+ };
454
+
455
+ interface ISlider {
456
+ Root: typeof Root;
457
+ Progress: typeof Progress;
458
+ Thumb: typeof Thumb;
459
+ Marks: typeof Marks;
460
+ }
461
+
462
+ export default {
463
+ Root,
464
+ Progress,
465
+ Thumb,
466
+ Marks,
467
+ } as ISlider;