diginet-core-ui 1.3.24

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 (360) hide show
  1. package/assets/avatar/default.svg +3 -0
  2. package/assets/images/menu/dhr/Default.svg +13 -0
  3. package/assets/images/menu/dhr/MHRM00N0001.svg +14 -0
  4. package/assets/images/menu/dhr/MHRM09N0001.svg +1 -0
  5. package/assets/images/menu/dhr/MHRM09N0002.svg +3 -0
  6. package/assets/images/menu/dhr/MHRM09N0003.svg +25 -0
  7. package/assets/images/menu/dhr/MHRM25N0001.svg +26 -0
  8. package/assets/images/menu/dhr/MHRM29N0001.svg +30 -0
  9. package/assets/images/menu/dhr/MHRM29N0015.svg +63 -0
  10. package/assets/images/menu/dhr/MHRM39N0012.svg +43 -0
  11. package/assets/images/menu/dhr/MHRM39N0013.svg +24 -0
  12. package/assets/images/menu/dhr/MHRM39N0014.svg +14 -0
  13. package/assets/images/menu/dhr/MHRM39N0015.svg +36 -0
  14. package/assets/images/menu/dhr/MHRM39N0016.svg +23 -0
  15. package/assets/images/menu/dhr/MHRM77N0001.svg +28 -0
  16. package/assets/images/menu/dhr/MHRM84N0001.svg +27 -0
  17. package/assets/images/menu/dhr/MHRM84N0002.svg +24 -0
  18. package/assets/images/menu/dhr/MHRM89N0001.svg +16 -0
  19. package/assets/images/menu/dhr/MHRP00N0001.svg +10 -0
  20. package/assets/images/menu/dhr/MHRP09N0001.svg +22 -0
  21. package/assets/images/menu/dhr/MHRP09N0002.svg +19 -0
  22. package/assets/images/menu/dhr/MHRP09N0003.svg +12 -0
  23. package/assets/images/menu/dhr/MHRP09N0004.svg +6 -0
  24. package/assets/images/menu/dhr/MHRP09N0005.svg +10 -0
  25. package/assets/images/menu/dhr/MHRP09N0006.svg +17 -0
  26. package/assets/images/menu/dhr/MHRP09N0007.svg +15 -0
  27. package/assets/images/menu/dhr/MHRP09N0008.svg +8 -0
  28. package/assets/images/menu/dhr/MHRP09N0009.svg +10 -0
  29. package/assets/images/menu/dhr/MHRP09N0010.svg +12 -0
  30. package/assets/images/menu/dhr/MHRP09N0011.svg +16 -0
  31. package/assets/images/menu/dhr/MHRP09N0012.svg +6 -0
  32. package/assets/images/menu/dhr/MHRP09N0013.svg +8 -0
  33. package/assets/images/menu/dhr/MHRP09N0014.svg +11 -0
  34. package/assets/images/menu/dhr/MHRP09N0015.svg +12 -0
  35. package/assets/images/menu/dhr/MHRP09N0016.svg +18 -0
  36. package/assets/images/menu/dhr/MHRP09N0017.svg +18 -0
  37. package/assets/images/menu/dhr/MHRP09N0018.svg +12 -0
  38. package/assets/images/menu/dhr/MHRP09N0019.svg +13 -0
  39. package/assets/images/menu/dhr/MHRP09N0020.svg +17 -0
  40. package/assets/images/menu/dhr/MHRP09N0021.svg +10 -0
  41. package/assets/images/menu/dhr/MHRP09N0022.svg +16 -0
  42. package/assets/images/menu/dhr/MHRP09N0023.svg +8 -0
  43. package/assets/images/menu/dhr/MHRP09N0024.svg +15 -0
  44. package/assets/images/menu/dhr/MHRP09N0025.svg +16 -0
  45. package/assets/images/menu/dhr/MHRP09N0026.svg +13 -0
  46. package/assets/images/menu/dhr/MHRP09N0027.svg +10 -0
  47. package/assets/images/menu/dhr/MHRP13N0001.svg +9 -0
  48. package/assets/images/menu/dhr/MHRP21N0001.svg +12 -0
  49. package/assets/images/menu/dhr/MHRP21N0002.svg +13 -0
  50. package/assets/images/menu/dhr/MHRP25N0001.svg +13 -0
  51. package/assets/images/menu/dhr/MHRP25N0002.svg +16 -0
  52. package/assets/images/menu/dhr/MHRP25N0003.svg +38 -0
  53. package/assets/images/menu/dhr/MHRP25N0004.svg +17 -0
  54. package/assets/images/menu/dhr/MHRP25N0005.svg +20 -0
  55. package/assets/images/menu/dhr/MHRP29N0001.svg +18 -0
  56. package/assets/images/menu/dhr/MHRP29N0002.svg +15 -0
  57. package/assets/images/menu/dhr/MHRP29N0003.svg +20 -0
  58. package/assets/images/menu/dhr/MHRP29N0004.svg +21 -0
  59. package/assets/images/menu/dhr/MHRP29N0005.svg +21 -0
  60. package/assets/images/menu/dhr/MHRP29N0006.svg +14 -0
  61. package/assets/images/menu/dhr/MHRP29N0007.svg +19 -0
  62. package/assets/images/menu/dhr/MHRP29N0008.svg +20 -0
  63. package/assets/images/menu/dhr/MHRP29N0009.svg +11 -0
  64. package/assets/images/menu/dhr/MHRP29N0010.svg +11 -0
  65. package/assets/images/menu/dhr/MHRP29N0011.svg +12 -0
  66. package/assets/images/menu/dhr/MHRP29N0013.svg +27 -0
  67. package/assets/images/menu/dhr/MHRP29N0014.svg +32 -0
  68. package/assets/images/menu/dhr/MHRP29N0016.svg +54 -0
  69. package/assets/images/menu/dhr/MHRP29N0017.svg +24 -0
  70. package/assets/images/menu/dhr/MHRP29N0018.svg +44 -0
  71. package/assets/images/menu/dhr/MHRP29N0019.svg +17 -0
  72. package/assets/images/menu/dhr/MHRP29N0020.svg +11 -0
  73. package/assets/images/menu/dhr/MHRP38N0001.svg +13 -0
  74. package/assets/images/menu/dhr/MHRP38N0002.svg +14 -0
  75. package/assets/images/menu/dhr/MHRP39N0001.svg +15 -0
  76. package/assets/images/menu/dhr/MHRP39N0002.svg +13 -0
  77. package/assets/images/menu/dhr/MHRP39N0003.svg +16 -0
  78. package/assets/images/menu/dhr/MHRP39N0004.svg +22 -0
  79. package/assets/images/menu/dhr/MHRP39N0005.svg +16 -0
  80. package/assets/images/menu/dhr/MHRP39N0006.svg +17 -0
  81. package/assets/images/menu/dhr/MHRP39N0007.svg +13 -0
  82. package/assets/images/menu/dhr/MHRP39N0008.svg +3 -0
  83. package/assets/images/menu/dhr/MHRP39N0009.svg +3 -0
  84. package/assets/images/menu/dhr/MHRP39N0010.svg +7 -0
  85. package/assets/images/menu/dhr/MHRP39N0011.svg +14 -0
  86. package/assets/images/menu/dhr/MHRP39N0013.svg +10 -0
  87. package/assets/images/menu/dhr/MHRP39N0014.svg +11 -0
  88. package/assets/images/menu/dhr/MHRP39N1222.svg +12 -0
  89. package/assets/images/menu/dhr/MHRP51N0001.svg +9 -0
  90. package/assets/images/menu/dhr/MHRP51N0002.svg +13 -0
  91. package/assets/images/menu/dhr/MHRP52N0001.svg +21 -0
  92. package/assets/images/menu/dhr/MHRP52N0002.svg +21 -0
  93. package/assets/images/menu/dhr/MHRP52N0003.svg +16 -0
  94. package/assets/images/menu/dhr/MHRP75N0001.svg +19 -0
  95. package/assets/images/menu/dhr/MHRP75N0002.svg +25 -0
  96. package/assets/images/menu/dhr/MHRP75N0003.svg +3 -0
  97. package/assets/images/menu/dhr/MHRP75N0006.svg +14 -0
  98. package/assets/images/menu/dhr/MHRP75N0007.svg +19 -0
  99. package/assets/images/menu/dhr/MHRP75N0008.svg +19 -0
  100. package/assets/images/menu/dhr/MHRP77N0007.svg +28 -0
  101. package/assets/images/menu/dhr/MHRP77N0008.svg +17 -0
  102. package/assets/images/menu/dhr/MHRP77N0009.svg +19 -0
  103. package/assets/images/menu/dhr/MHRP77N0010.svg +20 -0
  104. package/assets/images/menu/dhr/MHRP89N1000.svg +6 -0
  105. package/assets/images/menu/dhr/MHRP89N1001.svg +6 -0
  106. package/assets/images/menu/dhr/W00F0001.svg +3 -0
  107. package/assets/images/menu/dhr/W00F0002.svg +3 -0
  108. package/assets/images/menu/dhr/W00F0003.svg +3 -0
  109. package/assets/images/menu/dhr/W00F0004.svg +3 -0
  110. package/assets/images/menu/dhr/W00F0005.svg +1 -0
  111. package/assets/images/menu/dhr/W09F2000-WEB5.svg +17 -0
  112. package/assets/images/menu/dhr/W09F2000.svg +6 -0
  113. package/assets/images/menu/dhr/W09F2002-WEB5.svg +21 -0
  114. package/assets/images/menu/dhr/W09F2005-WEB5.svg +13 -0
  115. package/assets/images/menu/dhr/W09F2020-WEB5.svg +16 -0
  116. package/assets/images/menu/dhr/W09F2022-WEB5.svg +20 -0
  117. package/assets/images/menu/dhr/W09F2150-WEB5.svg +16 -0
  118. package/assets/images/menu/dhr/W09F2152-WEB5.svg +20 -0
  119. package/assets/images/menu/dhr/W09F2160-WEB5.svg +14 -0
  120. package/assets/images/menu/dhr/W09F2162-WEB5.svg +18 -0
  121. package/assets/images/menu/dhr/W29F4006-WEB5.svg +19 -0
  122. package/assets/images/menu/dhr/W75F2260-WEB5.svg +15 -0
  123. package/assets/images/menu/dhr/W75F2261-WEB5.svg +19 -0
  124. package/assets/images/menu/dhr/W75F3005-WEB5.svg +13 -0
  125. package/assets/images/menu/dhr/W75F4070-WEB5.svg +21 -0
  126. package/assets/images/menu/dhr/W75F4071-WEB5.svg +17 -0
  127. package/assets/images/menu/dhr/W75F4100-WEB5.svg +14 -0
  128. package/assets/images/menu/dhr/W77F1011.svg +19 -0
  129. package/assets/images/menu/dhr/W77F1013.svg +22 -0
  130. package/assets/images/menu/erp/W00F0001.svg +3 -0
  131. package/assets/images/menu/erp/W00F0002.svg +3 -0
  132. package/assets/images/menu/erp/W00F0003.svg +3 -0
  133. package/assets/images/menu/erp/W00F0004.svg +3 -0
  134. package/assets/images/menu/erp/W05F0001.svg +16 -0
  135. package/assets/images/menu/erp/W05F0001N0000.svg +16 -0
  136. package/assets/images/menu/erp/W05F0004N0000.svg +6 -0
  137. package/assets/images/menu/erp/W05F0006.svg +30 -0
  138. package/assets/images/menu/erp/W05F0007N0000.svg +6 -0
  139. package/assets/images/menu/erp/W05F0008.svg +14 -0
  140. package/assets/images/menu/erp/W05F4000.svg +9 -0
  141. package/assets/images/menu/erp/W06F0001.svg +17 -0
  142. package/assets/images/menu/erp/W06F0001N0000.svg +17 -0
  143. package/assets/images/menu/erp/W06F0004N0000.svg +22 -0
  144. package/assets/images/menu/erp/W06F0005.svg +22 -0
  145. package/assets/images/menu/erp/W06F0006.svg +55 -0
  146. package/assets/images/menu/erp/W06F0008.svg +17 -0
  147. package/assets/images/menu/erp/WA3F1025.svg +5 -0
  148. package/assets/images/menu/erp/WA3F2100.svg +10 -0
  149. package/components/accordion/context.js +6 -0
  150. package/components/accordion/css.js +159 -0
  151. package/components/accordion/details.js +60 -0
  152. package/components/accordion/group.js +122 -0
  153. package/components/accordion/index.js +117 -0
  154. package/components/accordion/summary.js +175 -0
  155. package/components/alert/index.js +264 -0
  156. package/components/alert/notify.js +192 -0
  157. package/components/avatar/index.js +556 -0
  158. package/components/badge/index.js +223 -0
  159. package/components/button/icon.js +493 -0
  160. package/components/button/index.js +653 -0
  161. package/components/button/more.js +135 -0
  162. package/components/button/ripple-effect.js +85 -0
  163. package/components/card/body-card.js +67 -0
  164. package/components/card/card.js +127 -0
  165. package/components/card/context.js +6 -0
  166. package/components/card/index.js +50 -0
  167. package/components/chart/Pie/Circle.js +50 -0
  168. package/components/chart/Pie/Sector.js +142 -0
  169. package/components/chart/Pie/Sectors.js +91 -0
  170. package/components/chart/Pie/index.js +311 -0
  171. package/components/chart/Pie-v2/Circle.js +50 -0
  172. package/components/chart/Pie-v2/Sector.js +128 -0
  173. package/components/chart/Pie-v2/Sectors.js +224 -0
  174. package/components/chart/Pie-v2/index.js +397 -0
  175. package/components/chart/bar/Axis.js +79 -0
  176. package/components/chart/bar/Bar.js +365 -0
  177. package/components/chart/bar/Grid.js +115 -0
  178. package/components/chart/bar/Labels.js +175 -0
  179. package/components/chart/bar/Points.js +111 -0
  180. package/components/chart/bar/index.js +172 -0
  181. package/components/chart/bar-v2/Axis.js +79 -0
  182. package/components/chart/bar-v2/Bar.js +374 -0
  183. package/components/chart/bar-v2/Grid.js +115 -0
  184. package/components/chart/bar-v2/Labels.js +175 -0
  185. package/components/chart/bar-v2/Points.js +111 -0
  186. package/components/chart/bar-v2/index.js +172 -0
  187. package/components/chart/line/Axis.js +79 -0
  188. package/components/chart/line/Grid.js +115 -0
  189. package/components/chart/line/Labels.js +172 -0
  190. package/components/chart/line/Path.js +163 -0
  191. package/components/chart/line/Point.js +348 -0
  192. package/components/chart/line/Title.js +56 -0
  193. package/components/chart/line/index.js +174 -0
  194. package/components/chart/line-v2/Axis.js +79 -0
  195. package/components/chart/line-v2/Grid.js +115 -0
  196. package/components/chart/line-v2/Labels.js +172 -0
  197. package/components/chart/line-v2/Path.js +163 -0
  198. package/components/chart/line-v2/Point.js +354 -0
  199. package/components/chart/line-v2/Title.js +56 -0
  200. package/components/chart/line-v2/index.js +174 -0
  201. package/components/check-text/index.js +157 -0
  202. package/components/check-text/interview-confirmation.js +172 -0
  203. package/components/check-text/interview-status.js +138 -0
  204. package/components/chip/attach.js +180 -0
  205. package/components/chip/index.js +340 -0
  206. package/components/collapse/index.js +67 -0
  207. package/components/dialogs/colors.js +11 -0
  208. package/components/divider/index.js +71 -0
  209. package/components/divider/style.js +12 -0
  210. package/components/form-control/attachment/index.js +1890 -0
  211. package/components/form-control/calendar/function.js +673 -0
  212. package/components/form-control/calendar/index.js +248 -0
  213. package/components/form-control/calendar/range.js +293 -0
  214. package/components/form-control/checkbox/index.js +306 -0
  215. package/components/form-control/control/index.js +92 -0
  216. package/components/form-control/date-picker/index-old.js +953 -0
  217. package/components/form-control/date-picker/index.js +676 -0
  218. package/components/form-control/date-range-picker/index.js +1305 -0
  219. package/components/form-control/dropdown/index.js +1865 -0
  220. package/components/form-control/dropdown-box/index.js +292 -0
  221. package/components/form-control/form/context.js +5 -0
  222. package/components/form-control/form/index.js +41 -0
  223. package/components/form-control/form-group/index.js +118 -0
  224. package/components/form-control/helper-text/index.js +71 -0
  225. package/components/form-control/input-base/index.js +733 -0
  226. package/components/form-control/label/index.js +73 -0
  227. package/components/form-control/money-input/index.js +491 -0
  228. package/components/form-control/number-input/index.js +633 -0
  229. package/components/form-control/phone-input/index.js +433 -0
  230. package/components/form-control/radio/index.js +263 -0
  231. package/components/form-control/text-input/index.js +523 -0
  232. package/components/form-control/time-picker/index.js +829 -0
  233. package/components/form-control/time-picker/swiper.js +590 -0
  234. package/components/form-control/toggle/index.js +250 -0
  235. package/components/form-view/helper-text.js +33 -0
  236. package/components/form-view/index.js +107 -0
  237. package/components/form-view/input.js +129 -0
  238. package/components/form-view/label.js +38 -0
  239. package/components/index.js +100 -0
  240. package/components/list/list-item-action.js +82 -0
  241. package/components/list/list-item-icon.js +76 -0
  242. package/components/list/list-item-text.js +57 -0
  243. package/components/list/list-item.js +114 -0
  244. package/components/list/list.js +155 -0
  245. package/components/list/sub-header.js +61 -0
  246. package/components/modal/body.js +71 -0
  247. package/components/modal/context.js +6 -0
  248. package/components/modal/footer.js +63 -0
  249. package/components/modal/header.js +108 -0
  250. package/components/modal/index.js +69 -0
  251. package/components/modal/modal.js +339 -0
  252. package/components/others/extra/index.js +124 -0
  253. package/components/others/scrollbar/index.js +95 -0
  254. package/components/paging/page-info.js +298 -0
  255. package/components/paging/page-selector.js +281 -0
  256. package/components/paper/index.js +119 -0
  257. package/components/popover/index.js +417 -0
  258. package/components/popup/danger_popup.js +215 -0
  259. package/components/popup/index.js +469 -0
  260. package/components/popup/proposals_popup.js +364 -0
  261. package/components/popup/v2/danger-popup.js +17 -0
  262. package/components/popup/v2/index.js +460 -0
  263. package/components/popup/v2/info-popup.js +17 -0
  264. package/components/popup/v2/success-popup.js +17 -0
  265. package/components/popup/v2/warning-popup.js +17 -0
  266. package/components/popup/v2/yes-no-popup.js +20 -0
  267. package/components/progress/circular.js +414 -0
  268. package/components/progress/linear.js +327 -0
  269. package/components/rating/index.js +392 -0
  270. package/components/slider/slider-container.js +356 -0
  271. package/components/slider/slider-item.js +183 -0
  272. package/components/status/index.js +123 -0
  273. package/components/tab/context.js +3 -0
  274. package/components/tab/tab-container.js +83 -0
  275. package/components/tab/tab-header.js +133 -0
  276. package/components/tab/tab-panel.js +51 -0
  277. package/components/tab/tab.js +206 -0
  278. package/components/tooltip/index.js +602 -0
  279. package/components/tooltip/portal.js +13 -0
  280. package/components/transfer/index.js +489 -0
  281. package/components/tree-view/css.js +94 -0
  282. package/components/tree-view/index.js +1009 -0
  283. package/components/typography/index.js +218 -0
  284. package/css/styles.css +1 -0
  285. package/css/styles.css.map +1 -0
  286. package/global/index.js +175 -0
  287. package/icons/basic.js +6326 -0
  288. package/icons/effect.js +171 -0
  289. package/icons/general/clock/clock.js +21 -0
  290. package/icons/general/color-handler/background.js +41 -0
  291. package/icons/general/color-handler/text.js +41 -0
  292. package/icons/general/emoji/emoji.js +35 -0
  293. package/icons/general/font-properties/bold.js +21 -0
  294. package/icons/general/font-properties/font-family.js +35 -0
  295. package/icons/general/font-properties/font-size.js +27 -0
  296. package/icons/general/font-properties/italic.js +21 -0
  297. package/icons/general/font-properties/underline.js +31 -0
  298. package/icons/general/hyperlink/hyperlink.js +38 -0
  299. package/icons/general/indent/decrease.js +55 -0
  300. package/icons/general/indent/increase.js +55 -0
  301. package/icons/general/index.js +21 -0
  302. package/icons/general/list/bullets.js +77 -0
  303. package/icons/general/list/numbering.js +71 -0
  304. package/icons/general/picture/picture.js +21 -0
  305. package/icons/general/steps/redo.js +21 -0
  306. package/icons/general/steps/undo.js +21 -0
  307. package/icons/general/text-align/center.js +21 -0
  308. package/icons/general/text-align/justify.js +21 -0
  309. package/icons/general/text-align/left.js +21 -0
  310. package/icons/general/text-align/right.js +21 -0
  311. package/icons/index.js +3 -0
  312. package/icons/menu/dhr.js +2440 -0
  313. package/icons/menu/erp.js +490 -0
  314. package/icons/menu/index.js +5 -0
  315. package/icons/menu/v2/index.js +52 -0
  316. package/locale/index.js +11 -0
  317. package/package.json +45 -0
  318. package/readme.md +517 -0
  319. package/styles/animation.js +890 -0
  320. package/styles/color-helper.js +504 -0
  321. package/styles/colors.js +306 -0
  322. package/styles/general.js +48 -0
  323. package/styles/media-queries.js +10 -0
  324. package/styles/typography.js +122 -0
  325. package/styles/utils.js +10 -0
  326. package/theme/index.js +5 -0
  327. package/theme/make-styles.js +95 -0
  328. package/theme/set-theme.js +39 -0
  329. package/theme/settings.js +230 -0
  330. package/theme/theme-provider.js +68 -0
  331. package/theme/theme.js +56 -0
  332. package/theme/with-styles.js +17 -0
  333. package/theme/with-theme.js +11 -0
  334. package/utils/array/array.js +186 -0
  335. package/utils/console.js +34 -0
  336. package/utils/date.js +471 -0
  337. package/utils/error/error.js +62 -0
  338. package/utils/error/errors.js +247 -0
  339. package/utils/getFileType.js +32 -0
  340. package/utils/index.js +23 -0
  341. package/utils/iterator.js +45 -0
  342. package/utils/map-parent.js +53 -0
  343. package/utils/number.js +64 -0
  344. package/utils/object/extend.js +57 -0
  345. package/utils/object/object.js +68 -0
  346. package/utils/parseHTML.js +8 -0
  347. package/utils/promisify.js +38 -0
  348. package/utils/randomString.js +33 -0
  349. package/utils/remove-unicode.js +6 -0
  350. package/utils/render-portal.js +90 -0
  351. package/utils/renderHTML.js +21 -0
  352. package/utils/renderIcon.js +57 -0
  353. package/utils/string/capitalize.js +3 -0
  354. package/utils/string/capitalizeSentenceCase.js +10 -0
  355. package/utils/string/string.js +81 -0
  356. package/utils/type.js +90 -0
  357. package/utils/updatePosition.js +36 -0
  358. package/utils/useOnClickOutside.js +23 -0
  359. package/utils/usePortal.js +56 -0
  360. package/utils/validate.js +149 -0
@@ -0,0 +1,1865 @@
1
+ function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
+
3
+ /** @jsxRuntime classic */
4
+
5
+ /** @jsx jsx */
6
+ import { Fragment, memo, useState, useEffect, useMemo, useRef, useImperativeHandle, forwardRef } from 'react';
7
+ import ReactDOM from 'react-dom';
8
+ import PropTypes from 'prop-types';
9
+ import { jsx, css } from '@emotion/core';
10
+ import Icon, { Account } from '../../../icons';
11
+ import { InputBase, Chip, CircularProgress, Checkbox, TreeView, HelperText, Label } from '../../';
12
+ import { mapParent, randomString, updatePosition } from '../../../utils';
13
+ import { getGlobal } from '../../../global';
14
+ import { useTheme } from '../../../theme';
15
+ const {
16
+ colors,
17
+ typography: {
18
+ fontSize,
19
+ fontFamily
20
+ }
21
+ } = useTheme();
22
+ const timing = {},
23
+ currentValue = {},
24
+ currentObjectDefault = {},
25
+ isSearch = {},
26
+ allValue = {};
27
+ const separatorPattern = /\{\w+\}/g;
28
+ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
29
+ viewType,
30
+ itemMode,
31
+ itemMultipleSize,
32
+ required,
33
+ className,
34
+ label,
35
+ defaultValue,
36
+ value: valueProp,
37
+ searchDelayTime,
38
+ skip,
39
+ limit,
40
+ total,
41
+ placeholder,
42
+ error,
43
+ keyExpr,
44
+ displayExpr,
45
+ subText,
46
+ valueExpr,
47
+ noDataText,
48
+ iconDefault,
49
+ iconExpr,
50
+ treeViewID,
51
+ treeViewParentID,
52
+ clearAble,
53
+ closeAfterSelect,
54
+ disabled,
55
+ readOnly,
56
+ multiple,
57
+ allowSearch,
58
+ selectBox,
59
+ loading,
60
+ dataSource,
61
+ onKeyDown,
62
+ onInput,
63
+ onChange,
64
+ onLoadMore,
65
+ renderItem,
66
+ renderSelectedItem,
67
+ valueObjectDefault,
68
+ style,
69
+ inputProps,
70
+ inputStyle,
71
+ formStyle,
72
+ labelProps,
73
+ errorStyle,
74
+ refs,
75
+ children,
76
+ ...props
77
+ }, ref) => {
78
+ const dropdownRef = useRef(null);
79
+ const [unique] = useState(randomString(6, {
80
+ allowNumber: false,
81
+ allowSymbol: false
82
+ })),
83
+ timerRef = useRef(null),
84
+ formRef = useRef(null),
85
+ inputRef = useRef(null),
86
+ iconRef = useRef(null),
87
+ boxRef = useRef(null),
88
+ searchRef = useRef(null),
89
+ timeout = useRef(null);
90
+ /* Start styled */
91
+
92
+ const forInput = css`
93
+ display: flex;
94
+ flex: 1 1 auto;
95
+ ${!multiple && renderSelectedItem ? `width: calc(100% - 34px${clearAble ? ' - 18px' : ''})` : ''}
96
+ `;
97
+ const DropdownIcon = css`
98
+ display: inline-flex;
99
+ align-items: center;
100
+ position: relative;
101
+ height: inherit;
102
+ margin-right: 8px;
103
+ height: 32px;
104
+ width: 32px;
105
+ border-radius: 16px;
106
+ overflow: hidden;
107
+ img {
108
+ height: 32px;
109
+ width: 32px;
110
+ object-fit: cover;
111
+ }
112
+ `;
113
+ const DropdownInput = css`
114
+ display: flex;
115
+ align-items: center;
116
+ width: 100%;
117
+ border: none;
118
+ outline: none;
119
+ color: ${colors.input};
120
+ background-color: transparent;
121
+ padding-top: 0;
122
+ padding-bottom: ${viewType !== 'outlined' ? 0 : 'inherit'};
123
+ padding-left: ${viewType !== 'outlined' ? 0 : '16px'};
124
+ font-family: ${fontFamily};
125
+ font-style: normal;
126
+ font-weight: 500;
127
+ font-size: 16px;
128
+ line-height: ${multiple ? 30 : 24}px;
129
+ min-height: ${multiple ? 30 : 24}px;
130
+ &.dgn-dropdown-multiple {
131
+ flex-wrap: wrap;
132
+ /* max-height: max-content; */
133
+ word-break: break-word;
134
+ overflow: hidden;
135
+ ${!multiple ? 'min-height: 24px; max-width: 100%; white-space: nowrap;' : ''}
136
+ &::after {
137
+ content: '${placeholder}';
138
+ display: flex;
139
+ position: absolute;
140
+ align-items: center;
141
+ justify-content: center;
142
+ color: ${colors.placeholder};
143
+ }
144
+ &:not(:empty)::after {
145
+ visibility: hidden;
146
+ }
147
+ }
148
+ &:focus {
149
+ background-color: transparent;
150
+ }
151
+ .dropdown-item {
152
+ &:not(:last-child) {
153
+ margin-right: 5px;
154
+ }
155
+ svg {
156
+ box-sizing: border-box;
157
+ padding: ${itemMultipleSize === 'medium' ? 2 : 1}px;
158
+ }
159
+ }
160
+ .css-${DropdownIcon.name} {
161
+ ${renderSelectedItem ? `
162
+ min-height: 24px;
163
+ min-width: 24px;
164
+ ` : `
165
+ height: 24px;
166
+ width: 24px;
167
+ img {
168
+ height: 24px;
169
+ width: 24px;
170
+ }
171
+ `}
172
+ }
173
+ `;
174
+ const forIcon = css`
175
+ display: flex;
176
+ margin-left: 8px;
177
+ margin-right: ${viewType !== 'outlined' ? 2 : 16}px;
178
+ color: inherit;
179
+ align-items: center;
180
+ .icon-close {
181
+ display: none;
182
+ margin-right: 4px;
183
+ }
184
+ .dgn-dropdown-loading {
185
+ display: none;
186
+ }
187
+ `;
188
+ const DropdownForm = viewType !== 'outlined' ? css`
189
+ display: flex;
190
+ flex: 1 1 auto;
191
+ align-items: center;
192
+ position: relative;
193
+ padding-bottom: ${multiple ? 1 : 4}px;
194
+ padding-top: ${multiple ? 1 : 4}px;
195
+ box-sizing: border-box;
196
+ &:not(:focus-within):hover {
197
+ &::before {
198
+ border-bottom-color: ${colors.borderHover};
199
+ }
200
+ .css-${DropdownInput.name} {
201
+ color: ${colors.inputHover};
202
+ }
203
+ }
204
+ &:focus-within {
205
+ border-bottom-color: ${colors.borderFocus};
206
+ &::after {
207
+ border-bottom-color: inherit;
208
+ transform: scaleX(1);
209
+ }
210
+ .css-${DropdownInput.name} {
211
+ color: ${colors.inputHover};
212
+ }
213
+ }
214
+ &.dropdown-showing {
215
+ .icon-dropdown {
216
+ transform: rotateX(180deg);
217
+ }
218
+ }
219
+ &::placeholder {
220
+ color: ${colors.placeholder};
221
+ }
222
+ &::before {
223
+ content: '';
224
+ position: absolute;
225
+ left: 0;
226
+ right: 0;
227
+ bottom: 0;
228
+ border-bottom: 1px solid ${colors.border};
229
+ }
230
+ &::after {
231
+ content: '';
232
+ position: absolute;
233
+ left: 0px;
234
+ right: 0px;
235
+ bottom: -1px;
236
+ border-bottom: 2px solid transparent;
237
+ transform: scaleX(0);
238
+ transform-origin: center;
239
+ transition: all 0.2s ease;
240
+ }
241
+ ` : css`
242
+ display: flex;
243
+ flex: 1 1 auto;
244
+ align-items: center;
245
+ position: relative;
246
+ border: 1px solid ${colors.border};
247
+ border-radius: 4px;
248
+ min-height: 40px;
249
+ box-sizing: border-box;
250
+ &:not(:focus-within):hover {
251
+ background-color: ${colors.hover};
252
+ border-color: ${colors.borderHover};
253
+ input {
254
+ background-color: ${colors.hover};
255
+ }
256
+ }
257
+ &:focus-within {
258
+ border-color: ${colors.borderFocus};
259
+ &::after {
260
+ border-color: inherit;
261
+ }
262
+ }
263
+ &.dropdown-showing {
264
+ .icon-dropdown {
265
+ transform: rotateX(180deg);
266
+ }
267
+ }
268
+ &::placeholder {
269
+ color: ${colors.placeholder};
270
+ }
271
+ &::after {
272
+ content: '';
273
+ position: absolute;
274
+ left: -2px;
275
+ right: -2px;
276
+ top: -2px;
277
+ bottom: -2px;
278
+ border: 2px solid transparent;
279
+ border-radius: 4px;
280
+ pointer-events: none;
281
+ }
282
+ `;
283
+ const DropdownBox = css`
284
+ display: block;
285
+ position: relative;
286
+ width: 100%;
287
+ max-height: 280px;
288
+ overflow: overlay;
289
+ background-color: #FFF;
290
+ box-sizing: border-box;
291
+ border-radius: 4px;
292
+ box-shadow: 0px 4px 4px rgba(0, 0, 0, 0.25);
293
+ z-index: 9001;
294
+ &::-webkit-scrollbar {
295
+ width: 24px;
296
+ background-color: #FFF !important;
297
+ border-radius: 4px;
298
+ }
299
+ &::-webkit-scrollbar-thumb {
300
+ border-radius: 24px;
301
+ border: 8px solid transparent;
302
+ mix-blend-mode: normal;
303
+ background-color: ${colors.scrollbar} !important;
304
+ background-clip: content-box;
305
+ }
306
+ .DGN-UI-TreeView {
307
+ padding: 1px;
308
+ }
309
+ `;
310
+ const DropdownItem = css`
311
+ display: flex;
312
+ position: relative;
313
+ min-height: 40px;
314
+ width: 100%;
315
+ background-color: #FFF;
316
+ align-items: center;
317
+ justify-content: flex-start;
318
+ padding: 8px ${multiple && selectBox ? 0 : '16px'};
319
+ color: ${colors.text};
320
+ box-sizing: border-box;
321
+ user-select: none;
322
+ cursor: pointer;
323
+ &.no-data {
324
+ font-style: italic;
325
+ justify-content: center;
326
+ cursor: initial;
327
+ }
328
+ &:not(.no-data):hover,
329
+ &:not(.no-data):focus {
330
+ background-color: ${colors.hover};
331
+ color: ${colors.inputHover};
332
+ outline: none;
333
+ }
334
+ `;
335
+ const DropdownText = css`
336
+ font-family: ${fontFamily};
337
+ font-style: normal;
338
+ font-weight: 500;
339
+ font-size: ${fontSize};
340
+ line-height: 20px;
341
+ color: inherit;
342
+ .DGN-UI-Dropdown-PrimaryText {
343
+ display: block;
344
+ font-size: 14px;
345
+ line-height: 18px;
346
+ }
347
+ .DGN-UI-Dropdown-SubText {
348
+ display: block;
349
+ font-size: 12px;
350
+ line-height: 14px;
351
+ font-family: ${fontFamily};
352
+ color: ${colors.secondary};
353
+ }
354
+ `;
355
+ const DropdownRoot = css`
356
+ display: block;
357
+ position: relative;
358
+ margin-bottom: 20px;
359
+ min-width: 150px;
360
+ height: max-content;
361
+ &.error {
362
+ .css-${DropdownForm.name} {
363
+ border-color: ${colors.danger};
364
+ path {
365
+ fill: ${colors.danger};
366
+ }
367
+ &::before {
368
+ border-color: ${colors.danger};
369
+ }
370
+ }
371
+ }
372
+ &.dgn-dropdown-loading,
373
+ &.disabled {
374
+ pointer-events: none;
375
+ user-select: none;
376
+ .css-${DropdownInput.name} {
377
+ //color: ${colors.disabled} !important;
378
+ }
379
+ .css-${DropdownForm.name} {
380
+ border-color: ${colors.disabled};
381
+ .css-${forIcon.name} {
382
+ path {
383
+ fill: transparent;
384
+ }
385
+ }
386
+ &::before {
387
+ border-color: ${colors.disabled};
388
+ }
389
+ }
390
+ }
391
+ &.readOnly {
392
+ pointer-events: none;
393
+ user-select: none;
394
+ .css-${forIcon.name} {
395
+ pointer-events: none;
396
+ .icon-close {
397
+ display: none !important;
398
+ }
399
+ }
400
+ .css-${DropdownInput.name} {
401
+ .dropdown-item {
402
+ pointer-events: none;
403
+ }
404
+ }
405
+ }
406
+ `;
407
+ const Disabled = css`
408
+ pointer-events: none !important;
409
+ opacity: 0.4 !important;
410
+ `;
411
+ /* End styled */
412
+
413
+ /* Start handler */
414
+
415
+ const triggerInput = e => {
416
+ const target = e.currentTarget;
417
+ target.style.pointerEvents = 'none';
418
+
419
+ if (!boxRef.current) {
420
+ inputRef.current.focus();
421
+ inputRef.current.click();
422
+ } else {
423
+ onClickOutsideOfInput({
424
+ target: null
425
+ });
426
+ }
427
+
428
+ setTimeout(() => {
429
+ target.style.pointerEvents = null;
430
+ }, 200);
431
+ };
432
+
433
+ const triggerBlur = (blur = true) => {
434
+ if ((currentValue[unique] || currentValue[unique] === 0) && !multiple) {
435
+ setValueIntoInput(currentValue[unique]);
436
+ } else if (!multiple) {
437
+ setValueIntoInput('');
438
+ }
439
+
440
+ !!blur && inputRef.current.blur();
441
+ };
442
+
443
+ const onClickInput = e => {
444
+ if (!boxRef.current) {
445
+ if (!multiple || !Array.from(inputRef.current.querySelectorAll('.DGN-UI-Chip')).some(item => item.contains(e.target))) {
446
+ if ((renderSelectedItem || iconExpr && iconExpr !== 'none') && !multiple) {
447
+ inputRef.current.innerHTML = inputRef.current.textContent.trim();
448
+ inputRef.current.contentEditable = 'plaintext-only';
449
+ const caret = inputRef.current.childNodes.length ? 1 : 0;
450
+ const range = document.createRange();
451
+ range.setStart(inputRef.current, caret);
452
+ range.setEnd(inputRef.current, caret);
453
+ const sel = window.getSelection();
454
+ sel.removeAllRanges();
455
+ sel.addRange(range);
456
+ }
457
+
458
+ formRef.current.classList.add('dropdown-showing');
459
+ setTimeout(() => {
460
+ showDropdown();
461
+ setTimeout(() => {
462
+ if (children && boxRef.current && boxRef.current.querySelector('input')) {
463
+ boxRef.current.querySelector('input').focus();
464
+ }
465
+ }, 10);
466
+ }, timing[unique + 'Box'] ? 200 : 0);
467
+ }
468
+ } else if (multiple || itemMode === 'treeview') {
469
+ if (searchRef.current) {
470
+ searchRef.current.focus();
471
+ } else if (children && boxRef.current && boxRef.current.querySelector('input')) {
472
+ boxRef.current.querySelector('input').focus();
473
+ }
474
+ }
475
+ };
476
+
477
+ const onClickOutsideOfInput = event => {
478
+ if (inputRef.current && !inputRef.current.contains(event.target) && iconRef.current && !iconRef.current.contains(event.target) && boxRef.current && !boxRef.current.parentNode.parentNode.contains(event.target)) {
479
+ closeDropdown();
480
+ triggerBlur(false);
481
+ }
482
+ };
483
+
484
+ const showDropdown = () => {
485
+ if (displayExpr && Array.isArray(displayExpr)) {
486
+ displayExpr = displayExpr.join(' - ');
487
+ }
488
+
489
+ const keyArr = displayExpr.match(separatorPattern);
490
+ const dropdown = children ? jsx("div", {
491
+ css: DropdownBox,
492
+ ref: boxRef
493
+ }, children) : itemMode === 'normal' ? mapDropdown(null, keyArr) : mapTreeView();
494
+ const {
495
+ innerHeight
496
+ } = window;
497
+ const {
498
+ top,
499
+ left,
500
+ height,
501
+ width
502
+ } = formRef.current.getBoundingClientRect(); // Calculate to set position of Dropdown box
503
+
504
+ const dropdownHeight = Math.min(Math.max(1, (itemMode === 'normal' ? dropdown.props.children : mapParent(dataSource, treeViewID, treeViewParentID)).length || 1), 7) * 40 + (multiple ? 43 : 0);
505
+ let positionTop = top + height + 4;
506
+
507
+ if (top + height + 4 + dropdownHeight > innerHeight) {
508
+ if (top - dropdownHeight > 0) {
509
+ positionTop = top - dropdownHeight;
510
+ } else {
511
+ positionTop = innerHeight - dropdownHeight;
512
+ }
513
+ }
514
+
515
+ const el = document.createElement('div');
516
+ const elBox = document.createElement('div');
517
+ const elLoading = document.createElement('div');
518
+ el.style.cssText = `position: fixed; top: ${positionTop}px; left: ${left}px; width: ${width}px; background-color: #FFF; opacity: 0; transition: opacity 0.3s; z-index: 9001;`;
519
+ elLoading.style.cssText = `display: none; justify-content: center; align-items: center;position: absolute; top: 0; width: 100%; height: 100%; background-color: rgba(255, 255, 255, 0.6); border-radius: 4px; opacity: 0; transition: opacity 0.3s; z-index: 9002;`;
520
+ el.className = `DGN-UI-Portal DGN-Dropdown-${unique}`;
521
+ elBox.className = `DGN-Dropdown-Box`;
522
+ elLoading.className = `DGN-Dropdown-Loading`;
523
+ const node = document.body.appendChild(el);
524
+
525
+ if ((multiple || allowSearch) && itemMode === 'normal' && !children) {
526
+ var _searchRef$current;
527
+
528
+ const defaultSearch = !!onInput ? (_searchRef$current = searchRef.current) === null || _searchRef$current === void 0 ? void 0 : _searchRef$current.value : '';
529
+ const searchInput = jsx(InputBase, {
530
+ inputRef: searchRef,
531
+ viewType: 'outlined',
532
+ defaultValue: defaultSearch,
533
+ onChange: onChangeInput,
534
+ style: {
535
+ backgroundColor: '#FFF',
536
+ marginBottom: 1
537
+ },
538
+ onKeyDown: pressESCHandler,
539
+ autoFocus: true
540
+ });
541
+ const elSearch = document.createElement('div');
542
+ elSearch.className = `DGN-Dropdown-Box-Search`;
543
+ ReactDOM.render(searchInput, node.appendChild(elSearch));
544
+ } else {
545
+ inputRef.current.addEventListener('keydown', pressESCHandler);
546
+ }
547
+
548
+ ReactDOM.render(dropdown, node.appendChild(elBox));
549
+ ReactDOM.render(jsx(CircularProgress, {
550
+ size: 'xs'
551
+ }), node.appendChild(elLoading));
552
+ document.documentElement.style.overflow = 'hidden';
553
+ setTimeout(() => {
554
+ el.style.opacity = 1;
555
+ window.addEventListener('resize', customizeWidthDropdown);
556
+ document.addEventListener('wheel', onWheelHandler);
557
+ document.addEventListener('click', onClickOutsideOfInput);
558
+ document.addEventListener('keydown', preventScroll);
559
+ boxRef.current.addEventListener('keydown', moveOnItem);
560
+
561
+ if (onLoadMore && dataSource.length < total) {
562
+ boxRef.current.addEventListener('scroll', onLoadMoreHandler);
563
+ }
564
+ }, 10);
565
+ };
566
+
567
+ const moveOnItem = e => {
568
+ if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
569
+ let activeEl = document.activeElement;
570
+ activeEl = e.key === 'ArrowDown' ? activeEl.nextElementSibling : activeEl.previousElementSibling;
571
+
572
+ if (activeEl) {
573
+ activeEl.focus();
574
+ activeEl.scrollIntoView({
575
+ block: 'center',
576
+ behavior: "smooth"
577
+ });
578
+ }
579
+ }
580
+ };
581
+
582
+ const preventScroll = e => {
583
+ if (/Arrow(Up|Down)/.test(e.key)) {
584
+ e.preventDefault();
585
+ return false;
586
+ }
587
+
588
+ return true;
589
+ };
590
+
591
+ const pressESCHandler = event => {
592
+ if (event.key === 'Escape' || event.key === 'Tab') {
593
+ closeDropdown();
594
+ triggerBlur();
595
+ } else if (event.key === 'ArrowDown' && boxRef.current) {
596
+ boxRef.current.firstChild.focus();
597
+ }
598
+ };
599
+
600
+ const onWheelHandler = e => {
601
+ const node = document.querySelector(`.DGN-Dropdown-${unique}`);
602
+
603
+ if (!node) {
604
+ document.removeEventListener('wheel', onWheelHandler);
605
+ return;
606
+ }
607
+
608
+ if (!node.contains(e.target)) {
609
+ closeDropdown();
610
+ triggerBlur();
611
+ }
612
+ };
613
+
614
+ const closeDropdown = () => {
615
+ const node = document.querySelector(`.DGN-Dropdown-${unique}`);
616
+
617
+ if ((renderSelectedItem || iconExpr && iconExpr !== 'none') && !multiple && inputRef.current) {
618
+ inputRef.current.contentEditable = true;
619
+ }
620
+
621
+ if (node) {
622
+ node.style.pointerEvents = `none`;
623
+ node.style.transition = `opacity 0.5s`;
624
+ node.style.opacity = 0;
625
+ timing[unique + 'Box'] = setTimeout(() => {
626
+ clearTimeout(timing[unique + 'Box']);
627
+ timing[unique + 'Box'] = null;
628
+ node.remove();
629
+ boxRef.current = null;
630
+ }, 300);
631
+ !!formRef.current && formRef.current.classList.remove('dropdown-showing');
632
+ document.removeEventListener('click', onClickOutsideOfInput);
633
+ window.removeEventListener('resize', customizeWidthDropdown);
634
+ document.removeEventListener('wheel', onWheelHandler);
635
+ document.removeEventListener('keydown', preventScroll);
636
+
637
+ if (onLoadMore && boxRef.current) {
638
+ boxRef.current.removeEventListener('scroll', onLoadMoreHandler);
639
+ boxRef.current = null;
640
+ } // if (!multiple) {
641
+ // inputRef.current.removeEventListener('keydown', pressESCHandler);
642
+ // inputRef.current.removeEventListener('input', onChangeInput);
643
+ // }
644
+
645
+ }
646
+
647
+ document.documentElement.style.overflow = 'auto';
648
+ };
649
+
650
+ const renderDropdown = pattern => {
651
+ const keyArr = displayExpr.match(separatorPattern);
652
+ const dropdown = mapDropdown(pattern, keyArr);
653
+ const el = document.createElement('div');
654
+ el.className = `DGN-Dropdown-Box`;
655
+ const node = document.querySelector(`.DGN-Dropdown-${unique}`);
656
+
657
+ if (node) {
658
+ node.querySelector('.DGN-Dropdown-Box').remove();
659
+ ReactDOM.render(dropdown, node.appendChild(el));
660
+ setTimeout(() => {
661
+ boxRef.current.addEventListener('keydown', moveOnItem);
662
+
663
+ if (onLoadMore && dataSource.length < total) {
664
+ boxRef.current.addEventListener('scroll', onLoadMoreHandler);
665
+ }
666
+
667
+ updatePositionDropdown();
668
+ }, 0);
669
+ }
670
+ };
671
+
672
+ const mapDropdown = (pattern, keyArr) => {
673
+ const items = [];
674
+ const dataSourceUsable = [...dataSource];
675
+
676
+ if (onLoadMore && currentObjectDefault[unique].length) {
677
+ const length = currentObjectDefault[unique].length;
678
+ let existItemQuantity = 0;
679
+
680
+ for (let index = length - 1; index >= 0; index--) {
681
+ if (!dataSourceUsable.some(data => data[valueExpr] === currentObjectDefault[unique][index][valueExpr])) {
682
+ dataSourceUsable.unshift(currentObjectDefault[unique][index]);
683
+ } else {
684
+ // Nếu số lượng phần tử của valueObjectDefault tồn tại trong dataSource nhiều hơn hoặc bằng limit thì không remove nữa
685
+ if (++existItemQuantity > limit) {
686
+ continue;
687
+ }
688
+
689
+ currentObjectDefault[unique].splice(index, 1);
690
+ }
691
+ }
692
+ }
693
+
694
+ const length = dataSourceUsable.length;
695
+
696
+ for (let index = 0; index < length; index++) {
697
+ const data = dataSourceUsable[index];
698
+ let displayText = typeof data === 'object' ? keyArr ? renderData(data, keyArr) : data[displayExpr] : data;
699
+ if (pattern && !new RegExp(pattern).test(displayText.normalize())) continue;
700
+
701
+ if (renderItem && typeof renderItem === 'function') {
702
+ displayText = renderItem({
703
+ data,
704
+ index
705
+ });
706
+ } else if (subText) {
707
+ displayText = jsx(Fragment, null, jsx("span", {
708
+ className: 'DGN-UI-Dropdown-PrimaryText'
709
+ }, displayText), jsx("span", {
710
+ className: 'DGN-UI-Dropdown-SubText'
711
+ }, typeof subText === 'function' ? subText({
712
+ data,
713
+ index
714
+ }) : data[subText] || subText));
715
+ }
716
+
717
+ const value = typeof data === 'object' ? data[valueExpr] : data;
718
+ const itemDisabled = typeof data === 'object' ? data["disabled"] : data;
719
+ const icon = getIconFromData(data);
720
+
721
+ if (multiple && selectBox) {
722
+ const checked = currentValue[unique].includes(value);
723
+ items.push(jsx("div", {
724
+ key: index,
725
+ css: !itemDisabled ? DropdownItem : [Disabled, DropdownItem],
726
+ onClick: e => onChangeValueWithCheckbox(e) & onChangeValue(displayText, value, icon, data, index),
727
+ onKeyPress: e => {
728
+ if (e.key === 'Enter') e.currentTarget.firstChild.click();
729
+ },
730
+ tabIndex: -1
731
+ }, jsx(Checkbox, {
732
+ defaultChecked: checked,
733
+ style: {
734
+ width: '100%',
735
+ height: '100%',
736
+ padding: '0 16px'
737
+ },
738
+ value: value
739
+ }, icon && jsx("div", {
740
+ css: DropdownIcon
741
+ }, icon), jsx("div", {
742
+ css: DropdownText
743
+ }, displayText))));
744
+ } else {
745
+ items.push(jsx("div", {
746
+ key: index,
747
+ css: !itemDisabled ? DropdownItem : [Disabled, DropdownItem],
748
+ onClick: () => onChangeValue(displayText, value, icon, data, index),
749
+ onKeyPress: e => {
750
+ if (e.key === 'Enter') onChangeValue(displayText, value, icon, data, index);
751
+ },
752
+ tabIndex: -1
753
+ }, icon && jsx("div", {
754
+ css: DropdownIcon
755
+ }, icon), jsx("div", {
756
+ css: DropdownText
757
+ }, displayText)));
758
+ }
759
+
760
+ if (items.length === limit) {
761
+ timerRef.current = setTimeout(() => {
762
+ loadMoreItemsDropdown(index + 1, pattern);
763
+ }, 1000);
764
+ break;
765
+ }
766
+ }
767
+
768
+ return jsx("div", {
769
+ css: DropdownBox,
770
+ ref: boxRef
771
+ }, items.length ? items : jsx("div", {
772
+ css: DropdownItem,
773
+ className: 'no-data'
774
+ }, " ", noDataText, " "));
775
+ };
776
+
777
+ const mapTreeView = () => {
778
+ // if (!treeView[unique]) {
779
+ return jsx("div", {
780
+ css: DropdownBox,
781
+ ref: boxRef
782
+ }, jsx(TreeView, {
783
+ dataSource: dataSource,
784
+ displayExpr: displayExpr,
785
+ valueExpr: valueExpr,
786
+ multiple: multiple,
787
+ selectBox: selectBox,
788
+ allowSearch: allowSearch,
789
+ searchProps: {
790
+ autoFocus: true,
791
+ inputRef: searchRef
792
+ },
793
+ searchDelayTime: searchDelayTime,
794
+ id: treeViewID,
795
+ parentID: treeViewParentID,
796
+ value: typeof currentValue[unique] === 'string' ? [currentValue[unique]] : currentValue[unique],
797
+ onChange: (e, value) => onChangeValue('', multiple ? value : e.value),
798
+ renderItem: renderItem
799
+ })); // }
800
+ // return treeView[unique];
801
+ };
802
+
803
+ const loadMoreItemsDropdown = (i = 0, pattern) => {
804
+ const dataSourceUsable = [...dataSource]; // Nếu có load more thì đẩy đội tượng mặc định lên đầu
805
+
806
+ let notExistItem = 0;
807
+
808
+ if (onLoadMore && currentObjectDefault[unique].length) {
809
+ const length = currentObjectDefault[unique].length;
810
+
811
+ for (let index = length - 1; index >= 0; index--) {
812
+ if (!dataSourceUsable.some(data => data[valueExpr] === currentObjectDefault[unique][index][valueExpr])) {
813
+ notExistItem++;
814
+ dataSourceUsable.unshift(currentObjectDefault[unique][index]);
815
+ }
816
+ }
817
+ }
818
+
819
+ const length = dataSourceUsable.length;
820
+ let num = 0;
821
+
822
+ if (displayExpr && Array.isArray(displayExpr)) {
823
+ displayExpr = displayExpr.join(' - ');
824
+ }
825
+
826
+ const keyArr = displayExpr.match(separatorPattern);
827
+
828
+ for (i; i < length; i++) {
829
+ const data = { ...dataSourceUsable[i]
830
+ }; // Nếu đối tượng đã được hiển thị ở trên rồi thì không hiển thị ra nữa
831
+
832
+ if (onLoadMore && i > notExistItem && currentObjectDefault[unique].some(valueObject => valueObject[valueExpr] === data[valueExpr])) continue;
833
+ let displayText = typeof data === 'object' ? keyArr ? renderData(data, keyArr) : data[displayExpr] : data;
834
+ if (pattern && !new RegExp(pattern).test(displayText.normalize())) continue;
835
+ const value = typeof data === 'object' ? data[valueExpr] : data;
836
+ const icon = getIconFromData(data);
837
+
838
+ if (renderItem && typeof renderItem === 'function') {
839
+ displayText = renderItem({
840
+ data,
841
+ index: i
842
+ });
843
+ } else if (subText) {
844
+ displayText = jsx(Fragment, null, jsx("span", {
845
+ className: 'DGN-UI-Dropdown-PrimaryText'
846
+ }, displayText), jsx("span", {
847
+ className: 'DGN-UI-Dropdown-SubText'
848
+ }, typeof subText === 'function' ? subText({
849
+ data,
850
+ index: i
851
+ }) : data[subText] || subText));
852
+ }
853
+
854
+ const dropdownItem = document.createElement('div');
855
+ dropdownItem.className = `css-${DropdownItem.name}`;
856
+ dropdownItem.tabIndex = -1;
857
+ dropdownItem.addEventListener('click', () => onChangeValue(displayText, value, icon, data, i));
858
+ dropdownItem.addEventListener('keypress', e => {
859
+ if (e.key === 'Enter') dropdownItem.firstChild.click();
860
+ });
861
+ let item = null;
862
+
863
+ if (multiple && selectBox) {
864
+ const checked = currentValue[unique].includes(value);
865
+ item = jsx(Checkbox, {
866
+ defaultChecked: checked,
867
+ style: {
868
+ width: '100%',
869
+ height: '100%',
870
+ padding: '0 16px'
871
+ }
872
+ }, icon && jsx("div", {
873
+ css: DropdownIcon
874
+ }, icon), jsx("div", {
875
+ css: DropdownText
876
+ }, displayText));
877
+ } else {
878
+ item = jsx(Fragment, null, icon && jsx("div", {
879
+ css: DropdownIcon
880
+ }, icon), jsx("div", {
881
+ css: DropdownText
882
+ }, displayText));
883
+ }
884
+
885
+ if (!boxRef.current) {
886
+ return;
887
+ }
888
+
889
+ ReactDOM.render(item, boxRef.current.appendChild(dropdownItem));
890
+
891
+ if (++num === 100) {
892
+ timerRef.current = setTimeout(() => {
893
+ loadMoreItemsDropdown(i + 1, pattern);
894
+ }, 1000);
895
+ break;
896
+ }
897
+ }
898
+ };
899
+
900
+ const renderData = (data, keyArr) => {
901
+ const pattern = keyArr.join('|').replace(/([\{\}])/g, '\\$1');
902
+ const separatorArr = displayExpr.split(new RegExp(pattern));
903
+ let str = '';
904
+ let i = 0;
905
+
906
+ for (i; i < keyArr.length; i++) {
907
+ str += separatorArr[i] + (data[keyArr[i].replace(/\W/g, '')] !== undefined ? data[keyArr[i].replace(/\W/g, '')] : keyArr[i]);
908
+ }
909
+
910
+ return str + separatorArr[i];
911
+ };
912
+
913
+ const getIconFromData = data => {
914
+ if (!iconExpr || iconExpr === 'none') return null;
915
+
916
+ if (typeof iconExpr === 'string') {
917
+ return data[iconExpr] ? jsx("img", {
918
+ src: data[iconExpr],
919
+ alt: data[valueExpr]
920
+ }) : iconDefault ? jsx("img", {
921
+ src: iconDefault,
922
+ alt: data[valueExpr],
923
+ style: iconExpr.style
924
+ }) : jsx(Account, {
925
+ width: 32,
926
+ height: 32
927
+ });
928
+ }
929
+
930
+ let prefix = iconExpr.prefix || '';
931
+ const suffix = iconExpr.suffix || '';
932
+ const url = data[iconExpr.key];
933
+
934
+ if (prefix && /^http/i.test(prefix) && /^http/i.test(url)) {
935
+ prefix = '';
936
+ }
937
+
938
+ return url ? jsx("img", {
939
+ src: prefix + url + suffix,
940
+ alt: data[valueExpr],
941
+ style: iconExpr.style,
942
+ onError: onErrorRenderIcon
943
+ }) : iconDefault ? jsx("img", {
944
+ src: iconDefault,
945
+ alt: data[valueExpr],
946
+ style: iconExpr.style
947
+ }) : jsx(Account, {
948
+ width: 32,
949
+ height: 32
950
+ });
951
+ };
952
+
953
+ const onErrorRenderIcon = e => {
954
+ if (iconDefault) {
955
+ e.target.src = iconDefault;
956
+ } else {
957
+ const parent = e.target.parentNode;
958
+ e.target.remove();
959
+ parent.innerHTML = `<svg width="32" height="32" viewBox="0 0 20 20" fill="none">
960
+ <path fill-rule="evenodd" clip-rule="evenodd" d="M10 0C4.47998 0 0 4.48 0 10C0 15.52 4.47998 20 10 20C15.52 20 20 15.52 20 10C20 4.48 15.52 0 10 0ZM10 3C11.66 3 13 4.34 13 6C13 7.66 11.66 9 10 9C8.34003 9 7 7.66 7 6C7 4.34 8.34003 3 10 3ZM4 13.98C5.28998 15.92 7.5 17.2 10 17.2C12.5 17.2 14.71 15.92 16 13.98C15.97 11.99 11.99 10.9 10 10.9C8 10.9 4.03003 11.99 4 13.98Z" fill="#7F828E"/>
961
+ </svg>`;
962
+ }
963
+ };
964
+
965
+ const customizeWidthDropdown = () => {
966
+ if (!dropdownRef.current) {
967
+ window.removeEventListener('resize', customizeWidthDropdown);
968
+ return;
969
+ }
970
+
971
+ const {
972
+ width
973
+ } = dropdownRef.current.getBoundingClientRect();
974
+
975
+ if (document.querySelector(`.DGN-Dropdown-${unique}`)) {
976
+ document.querySelector(`.DGN-Dropdown-${unique}`).style.width = width + 'px';
977
+ }
978
+
979
+ updatePositionDropdown();
980
+ };
981
+
982
+ const updatePositionDropdown = () => {
983
+ const node = document.querySelector(`.DGN-Dropdown-${unique}`);
984
+
985
+ if (!formRef.current || !node) {
986
+ document.removeEventListener('wheel', onWheelHandler);
987
+ return;
988
+ }
989
+
990
+ updatePosition(formRef.current, node, closeDropdown);
991
+ };
992
+
993
+ const onLoadMoreHandler = e => {
994
+ const {
995
+ scrollTop,
996
+ scrollHeight,
997
+ offsetHeight
998
+ } = e.target;
999
+
1000
+ if (scrollHeight === Math.ceil(scrollTop) + offsetHeight && boxRef.current) {
1001
+ const length = boxRef.current.querySelectorAll(`.css-${DropdownItem.name}`).length;
1002
+ boxRef.current.removeEventListener('scroll', onLoadMoreHandler);
1003
+ !!onLoadMore && onLoadMore({
1004
+ skip: length,
1005
+ limit: limit
1006
+ });
1007
+ }
1008
+ };
1009
+
1010
+ const onPreventKeyDownHandler = e => {
1011
+ e.preventDefault();
1012
+ return false;
1013
+ };
1014
+
1015
+ const onChangeInput = e => {
1016
+ if (onInput) {
1017
+ isSearch[unique] = true;
1018
+ const valueInput = e.target.value;
1019
+ const text = (valueInput || e.target.textContent).normalize();
1020
+
1021
+ if (timeout.current) {
1022
+ if (timing[unique]) {
1023
+ clearTimeout(timing[unique]);
1024
+ }
1025
+
1026
+ timing[unique] = setTimeout(() => {
1027
+ e.target.value = text;
1028
+ onInput(e);
1029
+ e.target.value = valueInput;
1030
+ }, timeout.current);
1031
+ } else {
1032
+ e.target.value = text;
1033
+ onInput(e);
1034
+ e.target.value = valueInput;
1035
+ }
1036
+
1037
+ return;
1038
+ }
1039
+
1040
+ const value = e.target.value || e.target.textContent;
1041
+
1042
+ if (renderSelectedItem && e.target.childNodes && Array.from(e.target.childNodes).some(node => node.toString() !== '[object Text]')) {
1043
+ const cursor = document.getSelection().anchorOffset;
1044
+ e.target.innerHTML = value;
1045
+ document.getSelection().collapse(e.target, cursor);
1046
+ }
1047
+
1048
+ if (timing[unique]) clearTimeout(timing[unique]);
1049
+ timing[unique] = setTimeout(() => {
1050
+ if (timerRef.current) {
1051
+ clearTimeout(timerRef.current);
1052
+ timerRef.current = null;
1053
+ }
1054
+
1055
+ renderDropdown(new RegExp(value.normalize(), 'gim'));
1056
+ }, timeout.current || 700);
1057
+ };
1058
+
1059
+ const onChangeValue = (displayText, value, icon, data, index) => {
1060
+ if (itemMode === 'treeview') {
1061
+ if (valueProp === undefined) {
1062
+ setValueIntoInput(value);
1063
+ }
1064
+
1065
+ !!onChange && onChange({
1066
+ value
1067
+ });
1068
+ setTimeout(() => {
1069
+ updatePositionDropdown();
1070
+ }, 0);
1071
+ } else if (multiple) {
1072
+ if (!Array.isArray(currentValue[unique])) currentValue[unique] = [];
1073
+ const newValueArr = [...currentValue[unique]];
1074
+
1075
+ if (!currentValue[unique].some(v => JSON.stringify(v) === JSON.stringify(value))) {
1076
+ newValueArr.push(value);
1077
+
1078
+ if (valueProp === undefined) {
1079
+ let item = null;
1080
+
1081
+ if (renderSelectedItem && typeof renderSelectedItem === 'function') {
1082
+ item = renderSelectedItem({
1083
+ data,
1084
+ index
1085
+ });
1086
+ } else {
1087
+ item = jsx(Chip, {
1088
+ startIcon: icon,
1089
+ label: displayText,
1090
+ size: itemMultipleSize,
1091
+ clearAble: true,
1092
+ onRemove: e => onRemove(e, value),
1093
+ style: {
1094
+ margin: '3px 0'
1095
+ }
1096
+ });
1097
+ }
1098
+
1099
+ const el = document.createElement('div');
1100
+ el.className = 'dropdown-item';
1101
+ el.style.display = 'flex';
1102
+ ReactDOM.render(item, inputRef.current.appendChild(el));
1103
+ }
1104
+
1105
+ !!onChange && onChange({
1106
+ value: newValueArr,
1107
+ data
1108
+ });
1109
+ } else if (selectBox) {
1110
+ const index = newValueArr.indexOf(value);
1111
+ newValueArr.splice(index, 1);
1112
+
1113
+ if (valueProp === undefined) {
1114
+ const nodes = inputRef.current.querySelectorAll('.dropdown-item');
1115
+ nodes[index].remove();
1116
+ }
1117
+
1118
+ !!onChange && onChange({
1119
+ value: newValueArr,
1120
+ data
1121
+ });
1122
+ }
1123
+
1124
+ setTimeout(() => {
1125
+ updatePositionDropdown();
1126
+ }, 0);
1127
+ } else {
1128
+ const isChanged = currentValue[unique] !== value ? true : false;
1129
+
1130
+ if (isChanged) {
1131
+ if (valueProp === undefined) {
1132
+ if (clearAble) {
1133
+ iconRef.current.querySelector('.icon-close').style.display = 'flex';
1134
+ }
1135
+
1136
+ allValue[unique].push(value);
1137
+ setValueIntoInput(value);
1138
+ }
1139
+
1140
+ !!onChange && onChange({
1141
+ value,
1142
+ data
1143
+ });
1144
+ }
1145
+ }
1146
+
1147
+ if (closeAfterSelect) {
1148
+ closeDropdown();
1149
+ }
1150
+ };
1151
+
1152
+ const onChangeValueWithCheckbox = e => {
1153
+ const firstChild = e.currentTarget.firstChild;
1154
+
1155
+ if (!firstChild.contains(e.target)) {
1156
+ firstChild.click();
1157
+ }
1158
+ };
1159
+
1160
+ const onRemove = (e, value) => {
1161
+ const index = currentValue[unique].findIndex(v => JSON.stringify(v) === JSON.stringify(value));
1162
+
1163
+ if (index !== -1) {
1164
+ currentValue[unique].splice(index, 1);
1165
+ setTimeout(() => {
1166
+ if (boxRef.current && multiple && selectBox && !children) {
1167
+ const input = boxRef.current.querySelector(`input[value="${value}"]`);
1168
+
1169
+ if (input) {
1170
+ input.checked = false;
1171
+ }
1172
+ }
1173
+
1174
+ !!e && !!e.parentNode && e.parentNode.remove();
1175
+ }, 0);
1176
+ !!onChange && onChange({
1177
+ value: currentValue[unique],
1178
+ removed: value
1179
+ });
1180
+ }
1181
+ };
1182
+
1183
+ const onClear = e => {
1184
+ currentValue[unique] = multiple ? [] : '';
1185
+
1186
+ if (inputRef.current.tagName.toLowerCase() === 'div') {
1187
+ inputRef.current.innerHTML = '';
1188
+
1189
+ if (boxRef.current) {
1190
+ boxRef.current.querySelectorAll('input').forEach(input => input.checked = false);
1191
+ }
1192
+ } else {
1193
+ inputRef.current.value = '';
1194
+ } // onChangeValue('', '');
1195
+
1196
+
1197
+ e && e.target && e.target.blur();
1198
+ updatePositionDropdown();
1199
+
1200
+ if (clearAble) {
1201
+ iconRef.current.querySelector('.icon-close').style.display = null;
1202
+ }
1203
+
1204
+ !!onChange && onChange({
1205
+ value: currentValue[unique]
1206
+ });
1207
+ };
1208
+
1209
+ const setPreviousValue = () => {
1210
+ allValue[unique].pop();
1211
+ setValueIntoInput(allValue[unique][allValue[unique].length - 1]);
1212
+ };
1213
+
1214
+ const setValueIntoInput = source => {
1215
+ if (!source && source !== 0) {
1216
+ if (multiple) {
1217
+ inputRef.current.innerHTML = '';
1218
+ currentValue[unique] = [];
1219
+ } else {
1220
+ if (renderSelectedItem || iconExpr && iconExpr !== 'none' && !isSearch[unique]) {
1221
+ inputRef.current.innerHTML = '';
1222
+ } else if (!isSearch[unique]) {
1223
+ inputRef.current.value = '';
1224
+ }
1225
+
1226
+ currentValue[unique] = '';
1227
+ }
1228
+
1229
+ return;
1230
+ }
1231
+
1232
+ const length = dataSource.length;
1233
+ const displayKey = keyExpr || displayExpr;
1234
+
1235
+ if (displayKey && Array.isArray(displayKey)) {
1236
+ displayExpr = displayExpr.join(' - ');
1237
+ }
1238
+
1239
+ const keyArr = displayKey.match(separatorPattern);
1240
+
1241
+ if (multiple) {
1242
+ let valueArr = source;
1243
+
1244
+ if (!Array.isArray(valueArr)) {
1245
+ valueArr = [valueArr];
1246
+ }
1247
+
1248
+ valueArr = [...new Set(valueArr)];
1249
+ currentValue[unique] = [];
1250
+ inputRef.current.innerHTML = '';
1251
+ valueArr.forEach(v => {
1252
+ for (let i = 0; i < length; i++) {
1253
+ if (typeof dataSource[i] === 'object' && dataSource[i][valueExpr] === v || dataSource[i] === v) {
1254
+ setMultipleValueHandler(dataSource[i], v, keyArr, i);
1255
+ return;
1256
+ }
1257
+ }
1258
+
1259
+ if (onLoadMore && currentObjectDefault[unique].length) {
1260
+ const itemOfValue = currentObjectDefault[unique].find(valueObject => valueObject[valueExpr] === v || valueObject === v);
1261
+
1262
+ if (itemOfValue) {
1263
+ setMultipleValueHandler(itemOfValue, v, keyArr);
1264
+ }
1265
+ }
1266
+ });
1267
+
1268
+ if (clearAble && iconRef.current && iconRef.current.querySelector('.icon-close')) {
1269
+ iconRef.current.querySelector('.icon-close').style.display = valueArr.length ? 'flex' : null;
1270
+ }
1271
+ } else {
1272
+ currentValue[unique] = source;
1273
+
1274
+ for (let i = 0; i < length; i++) {
1275
+ if (dataSource[i][valueExpr] === source || dataSource[i] === source) {
1276
+ setSingleValueHandler(dataSource[i], keyArr);
1277
+ return;
1278
+ }
1279
+ }
1280
+
1281
+ if (onLoadMore && currentObjectDefault[unique].length) {
1282
+ const itemOfValue = currentObjectDefault[unique].find(valueObject => valueObject[valueExpr] === source || valueObject === source);
1283
+
1284
+ if (itemOfValue) {
1285
+ setSingleValueHandler(itemOfValue, keyArr);
1286
+ return;
1287
+ }
1288
+ }
1289
+
1290
+ if (!isSearch[unique]) {
1291
+ inputRef.current.value = '';
1292
+ }
1293
+
1294
+ if (clearAble && iconRef.current && iconRef.current.querySelector('.icon-close')) {
1295
+ iconRef.current.querySelector('.icon-close').style.display = null;
1296
+ }
1297
+ }
1298
+ };
1299
+
1300
+ const setMultipleValueHandler = (data, value, keyArr, index) => {
1301
+ let item = null;
1302
+
1303
+ if (renderSelectedItem && typeof renderSelectedItem === 'function') {
1304
+ item = renderSelectedItem({
1305
+ data,
1306
+ index
1307
+ });
1308
+ } else {
1309
+ const icon = getIconFromData(data);
1310
+ const text = keyArr ? renderData(data, keyArr) : data[keyExpr || displayExpr];
1311
+ item = jsx(Chip, {
1312
+ startIcon: icon,
1313
+ label: text,
1314
+ size: itemMultipleSize,
1315
+ clearAble: true,
1316
+ onRemove: e => onRemove(e, value),
1317
+ style: {
1318
+ margin: '3px 0'
1319
+ }
1320
+ });
1321
+ }
1322
+
1323
+ const el = document.createElement('div');
1324
+ el.className = 'dropdown-item';
1325
+ el.style.display = 'flex';
1326
+ ReactDOM.render(item, inputRef.current.appendChild(el));
1327
+ currentValue[unique].push(value);
1328
+ };
1329
+
1330
+ const setSingleValueHandler = (data, keyArr) => {
1331
+ if (renderSelectedItem && typeof renderSelectedItem === 'function') {
1332
+ inputRef.current.innerHTML = '';
1333
+ const item = renderSelectedItem({
1334
+ data
1335
+ });
1336
+ const el = document.createElement('div');
1337
+ el.style.display = 'flex';
1338
+ el.style.minHeight = '24px';
1339
+ ReactDOM.render(item, inputRef.current.appendChild(el));
1340
+ } else if (iconExpr && iconExpr !== 'none') {
1341
+ inputRef.current.innerHTML = '';
1342
+ const icon = getIconFromData(data);
1343
+ const text = keyArr ? renderData(data, keyArr) : data[keyExpr || displayExpr] || data;
1344
+ const valueWithIcon = jsx(Fragment, null, icon && jsx("div", {
1345
+ css: DropdownIcon
1346
+ }, icon), jsx("div", {
1347
+ css: DropdownText
1348
+ }, text));
1349
+ const el = document.createElement('div');
1350
+ el.style.cssText = 'display: flex; align-items: center; min-height:24px;';
1351
+ ReactDOM.render(valueWithIcon, inputRef.current.appendChild(el));
1352
+ } else {
1353
+ const text = keyArr ? renderData(data, keyArr) : data[keyExpr || displayExpr] || data;
1354
+ inputRef.current.value = text;
1355
+ }
1356
+
1357
+ if (clearAble) {
1358
+ iconRef.current.querySelector('.icon-close').style.display = 'flex';
1359
+ }
1360
+ };
1361
+
1362
+ useImperativeHandle(ref, () => ({
1363
+ closeDropdown: () => {
1364
+ closeDropdown();
1365
+ },
1366
+ showDropdown: () => {
1367
+ showDropdown();
1368
+ },
1369
+ onClear,
1370
+ setPreviousValue,
1371
+ DOM: dropdownRef.current
1372
+ }));
1373
+ useEffect(() => {
1374
+ currentObjectDefault[unique] = onLoadMore && valueObjectDefault ? Array.isArray(valueObjectDefault) ? [...valueObjectDefault] : [valueObjectDefault] : [];
1375
+ return () => {
1376
+ currentObjectDefault[unique] = null;
1377
+ };
1378
+ }, [valueObjectDefault]);
1379
+ useEffect(() => {
1380
+ !!refs && refs(dropdownRef);
1381
+ allValue[unique] = [];
1382
+
1383
+ if (defaultValue !== undefined && JSON.stringify(defaultValue) !== '[]') {
1384
+ setValueIntoInput(defaultValue);
1385
+ }
1386
+
1387
+ return () => {
1388
+ allValue[unique] = null;
1389
+ closeDropdown();
1390
+ };
1391
+ }, []);
1392
+ useEffect(() => {
1393
+ if (searchDelayTime) {
1394
+ var _searchDelayTime$matc, _searchDelayTime$matc2;
1395
+
1396
+ const units = {
1397
+ m: 60000,
1398
+ s: 1000,
1399
+ ms: 1
1400
+ };
1401
+ timeout.current = typeof searchDelayTime === 'number' ? searchDelayTime : (((_searchDelayTime$matc = searchDelayTime.match(/[^a-z]+/i)) === null || _searchDelayTime$matc === void 0 ? void 0 : _searchDelayTime$matc[0]) || 1) * units[((_searchDelayTime$matc2 = searchDelayTime.match(/ms|s|m/i)) === null || _searchDelayTime$matc2 === void 0 ? void 0 : _searchDelayTime$matc2[0]) || 's'];
1402
+ return () => {
1403
+ timeout.current = null;
1404
+ };
1405
+ }
1406
+ }, [searchDelayTime]);
1407
+ useEffect(() => {
1408
+ if (allValue[unique][allValue[unique].length - 1] !== valueProp) {
1409
+ allValue[unique].push(valueProp);
1410
+ }
1411
+ }, [valueProp]);
1412
+ useEffect(() => {
1413
+ if (loading) {
1414
+ iconRef.current.querySelector('.dgn-dropdown-loading').style.display = 'flex';
1415
+
1416
+ if (clearAble) {
1417
+ iconRef.current.querySelector('.icon-close').style.display = null;
1418
+ }
1419
+
1420
+ iconRef.current.querySelector('.icon-dropdown').style.display = 'none';
1421
+ dropdownRef.current.classList.add('dgn-dropdown-loading');
1422
+
1423
+ if (boxRef.current) {
1424
+ var _boxRef$current$paren, _boxRef$current$paren2;
1425
+
1426
+ const loadingNode = (_boxRef$current$paren = boxRef.current.parentNode) === null || _boxRef$current$paren === void 0 ? void 0 : (_boxRef$current$paren2 = _boxRef$current$paren.parentNode) === null || _boxRef$current$paren2 === void 0 ? void 0 : _boxRef$current$paren2.querySelector('.DGN-Dropdown-Loading');
1427
+
1428
+ if (loadingNode) {
1429
+ // boxRef.current.style.overflow = 'hidden';
1430
+ loadingNode.style.display = 'flex';
1431
+ setTimeout(() => {
1432
+ loadingNode.style.opacity = 1;
1433
+ }, 0);
1434
+ }
1435
+ }
1436
+
1437
+ return () => {
1438
+ if (iconRef.current && dropdownRef.current) {
1439
+ iconRef.current.querySelector('.dgn-dropdown-loading').style.display = null;
1440
+ iconRef.current.querySelector('.icon-dropdown').style.display = null;
1441
+
1442
+ if (clearAble && currentValue[unique] && typeof currentValue[unique] === 'string') {
1443
+ iconRef.current.querySelector('.icon-close').style.display = 'flex';
1444
+ }
1445
+
1446
+ dropdownRef.current.classList.remove('dgn-dropdown-loading');
1447
+
1448
+ if (boxRef.current) {
1449
+ // const loadingNode = boxRef.current.parentNode?.parentNode?.querySelector('.DGN-Dropdown-Loading');
1450
+ const loadingNode = document.querySelector('.DGN-Dropdown-Loading');
1451
+
1452
+ if (loadingNode) {
1453
+ // boxRef.current.style.overflow = null;
1454
+ loadingNode.style.opacity = 0;
1455
+ setTimeout(() => {
1456
+ loadingNode.style.display = 'none';
1457
+ }, 300);
1458
+ }
1459
+ }
1460
+ }
1461
+ };
1462
+ }
1463
+ }, [loading]);
1464
+ useEffect(() => {
1465
+ if (error && !valueProp && valueProp !== 0) {
1466
+ dropdownRef.current.classList.add('error');
1467
+ return () => {
1468
+ if (dropdownRef.current) {
1469
+ dropdownRef.current.classList.remove('error');
1470
+ }
1471
+ };
1472
+ }
1473
+ }, [error, valueProp]);
1474
+ useEffect(() => {
1475
+ if (valueProp !== undefined && (!boxRef.current || children || JSON.stringify(valueProp) !== JSON.stringify(currentValue[unique]))) {
1476
+ setValueIntoInput(valueProp);
1477
+ }
1478
+ }, [valueProp, dataSource]);
1479
+ useEffect(() => {
1480
+ inputRef.current.readOnly = readOnly || inputProps.readOnly;
1481
+
1482
+ if (disabled) {
1483
+ dropdownRef.current.classList.add('disabled');
1484
+ iconRef.current.querySelector('.icon-dropdown').style.pointerEvents = 'none';
1485
+ } else if (!readOnly) {
1486
+ inputRef.current.addEventListener('click', onClickInput);
1487
+ inputRef.current.addEventListener('input', onChangeInput);
1488
+ !!onLoadMore && boxRef.current && boxRef.current.addEventListener('scroll', onLoadMoreHandler);
1489
+ } else {
1490
+ dropdownRef.current.classList.add('readOnly');
1491
+ iconRef.current.querySelector('.icon-dropdown').style.pointerEvents = 'none';
1492
+
1493
+ if (multiple) {
1494
+ inputRef.current.contentEditable = false;
1495
+ }
1496
+ }
1497
+
1498
+ if (disabled || readOnly || children) {
1499
+ inputRef.current.addEventListener('keydown', onPreventKeyDownHandler);
1500
+ } else {
1501
+ inputRef.current.addEventListener('keydown', onKeyDown);
1502
+ }
1503
+
1504
+ return () => {
1505
+ if (!dropdownRef.current || !inputRef.current || !iconRef.current) return;
1506
+
1507
+ if (disabled) {
1508
+ dropdownRef.current.classList.remove('disabled');
1509
+ iconRef.current.querySelector('.icon-dropdown').style.pointerEvents = null;
1510
+ } else if (!readOnly) {
1511
+ inputRef.current.removeEventListener('click', onClickInput);
1512
+ inputRef.current.removeEventListener('input', onChangeInput);
1513
+ } else {
1514
+ dropdownRef.current.classList.remove('readOnly');
1515
+ iconRef.current.querySelector('.icon-dropdown').style.pointerEvents = null;
1516
+
1517
+ if (multiple) {
1518
+ inputRef.current.contentEditable = true;
1519
+ }
1520
+ }
1521
+
1522
+ if (disabled || readOnly || children) {
1523
+ inputRef.current.removeEventListener('keydown', onPreventKeyDownHandler);
1524
+ } else {
1525
+ inputRef.current.removeEventListener('keydown', onKeyDown);
1526
+ }
1527
+
1528
+ closeDropdown();
1529
+ };
1530
+ }, [disabled, readOnly, displayExpr, multiple, allowSearch, viewType, closeAfterSelect, selectBox]);
1531
+ useEffect(() => {
1532
+ if (!disabled && !readOnly) {
1533
+ inputRef.current.addEventListener('click', onClickInput);
1534
+ inputRef.current.addEventListener('input', onChangeInput);
1535
+ }
1536
+
1537
+ return () => {
1538
+ if (!disabled && !readOnly && inputRef.current) {
1539
+ inputRef.current.removeEventListener('click', onClickInput);
1540
+ inputRef.current.removeEventListener('input', onChangeInput);
1541
+ }
1542
+ };
1543
+ }, [onChange, children]);
1544
+ useEffect(() => {
1545
+ if (!disabled && !readOnly) {
1546
+ inputRef.current.addEventListener('click', onClickInput);
1547
+ }
1548
+
1549
+ if (boxRef.current) {
1550
+ if (!disabled && !readOnly) {
1551
+ inputRef.current.addEventListener('input', onChangeInput);
1552
+ }
1553
+
1554
+ const length = boxRef.current.querySelectorAll(`.css-${DropdownItem.name}`).length;
1555
+
1556
+ if (length < dataSource.length + currentObjectDefault[unique].length && !isSearch[unique]) {
1557
+ loadMoreItemsDropdown(length);
1558
+ !!onLoadMore && dataSource.length < total && boxRef.current.addEventListener('scroll', onLoadMoreHandler);
1559
+ } else {
1560
+ isSearch[unique] = false;
1561
+ renderDropdown();
1562
+ }
1563
+ } else {
1564
+ if (!multiple && !disabled && !readOnly) {
1565
+ inputRef.current.addEventListener('input', onChangeInput);
1566
+ }
1567
+ }
1568
+
1569
+ return () => {
1570
+ if (inputRef.current) {
1571
+ inputRef.current.removeEventListener('input', onChangeInput);
1572
+ inputRef.current.removeEventListener('click', onClickInput);
1573
+ }
1574
+
1575
+ !!boxRef.current && boxRef.current.removeEventListener('scroll', onLoadMoreHandler);
1576
+ };
1577
+ }, [dataSource]);
1578
+ /* End handler */
1579
+
1580
+ /* Start component */
1581
+
1582
+ const labelComp = useMemo(() => label ? jsx(Label, _extends({
1583
+ required: required,
1584
+ disabled: disabled
1585
+ }, labelProps), label) : null, [label, required, disabled]);
1586
+ const inputComp = useMemo(() => jsx("div", {
1587
+ css: DropdownForm,
1588
+ ref: formRef,
1589
+ className: 'DGN-UI-Dropdown-Form',
1590
+ style: formStyle
1591
+ }, jsx("div", {
1592
+ css: forInput
1593
+ }, multiple ? jsx("div", _extends({}, inputProps, {
1594
+ style: {
1595
+ cursor: 'text',
1596
+ ...inputStyle
1597
+ },
1598
+ ref: inputRef,
1599
+ css: DropdownInput,
1600
+ className: 'dgn-dropdown-multiple ' + (inputProps.className || ''),
1601
+ type: "text",
1602
+ onChange: e => {
1603
+ e.preventDefault();
1604
+ return false;
1605
+ }
1606
+ })) : renderSelectedItem || iconExpr && iconExpr !== 'none' ? jsx("div", _extends({}, inputProps, {
1607
+ contentEditable: true,
1608
+ style: inputStyle,
1609
+ ref: inputRef,
1610
+ css: DropdownInput,
1611
+ className: 'dgn-dropdown-multiple ' + (inputProps.className || ''),
1612
+ type: "text",
1613
+ onKeyDown: e => {
1614
+ if (e.key === 'Enter') {
1615
+ e.preventDefault();
1616
+ return false;
1617
+ }
1618
+ }
1619
+ })) : jsx("input", _extends({}, inputProps, {
1620
+ style: inputStyle,
1621
+ ref: inputRef,
1622
+ css: DropdownInput,
1623
+ type: "text",
1624
+ placeholder: placeholder
1625
+ }))), jsx("div", {
1626
+ ref: iconRef,
1627
+ css: forIcon
1628
+ }, jsx("span", {
1629
+ className: 'dgn-dropdown-loading'
1630
+ }, jsx(CircularProgress, {
1631
+ width: 24,
1632
+ strokeWidth: 2
1633
+ })), clearAble && jsx(Icon, {
1634
+ name: 'Close',
1635
+ width: 12,
1636
+ className: 'icon-close',
1637
+ onClick: onClear
1638
+ }), jsx(Icon, {
1639
+ name: 'ArrowDown',
1640
+ className: 'icon-dropdown',
1641
+ onClick: triggerInput,
1642
+ style: {
1643
+ transition: 'transform 0.5s',
1644
+ minHeight: '24px'
1645
+ }
1646
+ }))), [viewType, inputProps, inputStyle, multiple, clearAble, onChange]);
1647
+ const errorComp = useMemo(() => !!error && !valueProp && valueProp !== 0 && jsx(HelperText, {
1648
+ disabled: disabled,
1649
+ style: {
1650
+ minHeight: '16px',
1651
+ position: 'absolute',
1652
+ top: '100%',
1653
+ ...errorStyle
1654
+ }
1655
+ }, error), [error, valueProp, disabled]);
1656
+ /* End component */
1657
+
1658
+ return jsx("div", _extends({
1659
+ ref: dropdownRef,
1660
+ css: DropdownRoot,
1661
+ className: ['DGN-UI-Dropdown', className].join(' ').trim(),
1662
+ style: style
1663
+ }, props), labelComp, inputComp, errorComp);
1664
+ }));
1665
+ Dropdown.defaultProps = {
1666
+ viewType: 'underlined',
1667
+ itemMode: 'normal',
1668
+ itemMultipleSize: 'medium',
1669
+ className: '',
1670
+ label: '',
1671
+ placeholder: '',
1672
+ error: '',
1673
+ iconExpr: 'none',
1674
+ valueExpr: 'id',
1675
+ displayExpr: 'name',
1676
+ noDataText: getGlobal('noDataText'),
1677
+ skip: 0,
1678
+ limit: 50,
1679
+ total: Number.MAX_SAFE_INTEGER,
1680
+ clearAble: false,
1681
+ loading: false,
1682
+ disabled: false,
1683
+ readOnly: false,
1684
+ required: false,
1685
+ multiple: false,
1686
+ allowSearch: false,
1687
+ selectBox: false,
1688
+ closeAfterSelect: true,
1689
+ inputProps: {},
1690
+ formStyle: {},
1691
+ dataSource: [],
1692
+ onInput: null
1693
+ };
1694
+ Dropdown.propTypes = {
1695
+ /** the type of border you want to display */
1696
+ viewType: PropTypes.oneOf(['underlined', 'outlined']),
1697
+
1698
+ /** the mode of item when rendering */
1699
+ itemMode: PropTypes.oneOf(['normal', 'table', 'treeview']),
1700
+
1701
+ /** Use for Chip component, the selected item was render default */
1702
+ itemMultipleSize: PropTypes.oneOf(['small', 'medium']),
1703
+
1704
+ /** class for dropdown */
1705
+ className: PropTypes.string,
1706
+
1707
+ /** label for input */
1708
+ label: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
1709
+
1710
+ /** hints for input */
1711
+ placeholder: PropTypes.string,
1712
+
1713
+ /** error for input */
1714
+ error: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
1715
+
1716
+ /** Used to identify the parent key (only used for itemMode is 'treeview') */
1717
+ treeViewID: PropTypes.string,
1718
+
1719
+ /** used for mapping into a nested list (only used for itemMode is 'treeview') */
1720
+ treeViewParentID: PropTypes.string,
1721
+
1722
+ /** statement when there is no data */
1723
+ noDataText: PropTypes.string,
1724
+
1725
+ /** display this icon if not found the icon follow iconExpr */
1726
+ iconDefault: PropTypes.string,
1727
+
1728
+ /** field name used for icon display<br/>
1729
+ * Example:<br/>
1730
+ * &nbsp;&nbsp;string: 'icon'<br/>
1731
+ * &nbsp;&nbsp;object: {<br/>
1732
+ * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;key: 'icon',<br/>
1733
+ * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;prefix: 'https://imglink.com',<br/>
1734
+ * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;suffix: '.jpg'<br/>
1735
+ * &nbsp;&nbsp;}
1736
+ */
1737
+ iconExpr: PropTypes.oneOfType([PropTypes.string, PropTypes.shape({
1738
+ key: PropTypes.string,
1739
+ prefix: PropTypes.string,
1740
+ suffix: PropTypes.string,
1741
+ style: PropTypes.object
1742
+ })]),
1743
+
1744
+ /** default value is displayed for first render */
1745
+ defaultValue: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.array]),
1746
+
1747
+ /** the displayed value for each change */
1748
+ value: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.array]),
1749
+
1750
+ /** field name used for text display in input */
1751
+ keyExpr: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.array]),
1752
+
1753
+ /** field name used for text display<br/>
1754
+ * Example: 'name', '{id} - {name}', '{age} age(s)'<br/>
1755
+ * Note: don't use 'id - name', return undefined
1756
+ */
1757
+ displayExpr: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.array]),
1758
+
1759
+ /** display sub content */
1760
+ subText: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
1761
+
1762
+ /** the field name used for the returned result */
1763
+ valueExpr: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
1764
+
1765
+ /**
1766
+ * duration wait enter search content on search<br/>
1767
+ * Example: 700 -> 700ms, '700ms' -> 700ms, '0.7s' -> 700ms, '1m' -> 60000ms
1768
+ */
1769
+ searchDelayTime: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
1770
+
1771
+ /** number of items is ignored */
1772
+ skip: PropTypes.number,
1773
+
1774
+ /** number of elements that are rendered each time */
1775
+ limit: PropTypes.number,
1776
+
1777
+ /** The total number of elements in the dropdown */
1778
+ total: PropTypes.number,
1779
+
1780
+ /** display the clear icon if true */
1781
+ clearAble: PropTypes.bool,
1782
+
1783
+ /** shows data loading status */
1784
+ loading: PropTypes.bool,
1785
+
1786
+ /** prevent all event if true, hide all icon */
1787
+ disabled: PropTypes.bool,
1788
+
1789
+ /** prevent all event if true */
1790
+ readOnly: PropTypes.bool,
1791
+
1792
+ /** auto close after select an item */
1793
+ closeAfterSelect: PropTypes.bool,
1794
+
1795
+ /** At least one item is required */
1796
+ required: PropTypes.bool,
1797
+
1798
+ /** allows to attach multiple items */
1799
+ multiple: PropTypes.bool,
1800
+
1801
+ /** display input box search if true */
1802
+ allowSearch: PropTypes.bool,
1803
+
1804
+ /** show checkbox in each dropdown item */
1805
+ selectBox: PropTypes.bool,
1806
+
1807
+ /** an object default for value (use for load more) */
1808
+ valueObjectDefault: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
1809
+
1810
+ /** style inline for dropdown */
1811
+ style: PropTypes.object,
1812
+
1813
+ /** props of input in Dropdown component */
1814
+ inputProps: PropTypes.object,
1815
+
1816
+ /** style inline of input in Dropdown component */
1817
+ inputStyle: PropTypes.object,
1818
+
1819
+ /** style inline of box contain input and icon in Dropdown component */
1820
+ formStyle: PropTypes.object,
1821
+
1822
+ /** style inline of label in Dropdown component */
1823
+ labelProps: PropTypes.object,
1824
+
1825
+ /** style inline of error in Dropdown component */
1826
+ errorStyle: PropTypes.object,
1827
+
1828
+ /** The array of elements that appear in the dropdown */
1829
+ dataSource: PropTypes.array,
1830
+
1831
+ /** The function to get ref of Dropdown component */
1832
+ refs: PropTypes.func,
1833
+
1834
+ /** function displays items by custom<br/>
1835
+ * renderItem={(data, index) => data.name + ' - ' + data.role}<br/>
1836
+ * --> such as: displayExpr={'name - role'}
1837
+ */
1838
+ renderItem: PropTypes.func,
1839
+
1840
+ /** function displays selected items by custom, example:<br/>
1841
+ * renderItem={(data, index) => index + ' - ' + data.name}<br/>
1842
+ */
1843
+ renderSelectedItem: PropTypes.func,
1844
+
1845
+ /** the function will run when entering input<br/>
1846
+ * if undefined: the filter function will run (default)
1847
+ */
1848
+ onInput: PropTypes.func,
1849
+
1850
+ /** the function will run when key down input */
1851
+ onKeyDown: PropTypes.func,
1852
+
1853
+ /** the function will run when select or remove one item */
1854
+ onChange: PropTypes.func,
1855
+
1856
+ /** the function will run when scroll near the end */
1857
+ onLoadMore: PropTypes.func,
1858
+
1859
+ /** the contents in Dropdown box (Exp: TreeView) */
1860
+ children: PropTypes.node,
1861
+
1862
+ /** any props else */
1863
+ props: PropTypes.any
1864
+ };
1865
+ export default Dropdown;