@cashub/ui-elv 1.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 (304) hide show
  1. package/Tab/Tab.js +28 -0
  2. package/Tab/TabList.js +167 -0
  3. package/Tab/TabPanel.js +49 -0
  4. package/Tab/TabTab.js +105 -0
  5. package/Tab/index.js +30 -0
  6. package/Tab/subComponent/TabContext.js +9 -0
  7. package/Tab/subComponent/TabListV2.js +25 -0
  8. package/Tab/subComponent/TabPanelV2.js +52 -0
  9. package/Tab/subComponent/TabTabV2.js +63 -0
  10. package/VerticalTab/TabList.js +27 -0
  11. package/VerticalTab/TabPanel.js +52 -0
  12. package/VerticalTab/TabTab.js +70 -0
  13. package/VerticalTab/VerticalTab.js +41 -0
  14. package/VerticalTab/index.js +16 -0
  15. package/VerticalTab/subComponent/TabContext.js +9 -0
  16. package/alert/Alert.js +29 -0
  17. package/alert/index.js +13 -0
  18. package/animate/Collapse.js +71 -0
  19. package/animate/Loader.js +58 -0
  20. package/animate/NumberCounter.js +51 -0
  21. package/animate/PulseRing.js +35 -0
  22. package/animate/Spinner.js +18 -0
  23. package/animate/index.js +41 -0
  24. package/assets/css/autocomplete.css +16 -0
  25. package/assets/css/font.css +4 -0
  26. package/assets/css/global.css +2 -0
  27. package/assets/font/helvetica/Helvetica.ttf +0 -0
  28. package/assets/font/nanumGothic/NanumGothic-Bold.ttf +0 -0
  29. package/assets/font/nanumGothic/NanumGothic-ExtraBold.ttf +0 -0
  30. package/assets/font/nanumGothic/NanumGothic-Regular.ttf +0 -0
  31. package/assets/icons/app-management.png +0 -0
  32. package/assets/icons/burger-black.png +0 -0
  33. package/assets/icons/burger-white.png +0 -0
  34. package/assets/icons/burger.png +0 -0
  35. package/assets/icons/file.svg +1 -0
  36. package/assets/icons/map_icon1.png +0 -0
  37. package/assets/icons/map_icon4.png +0 -0
  38. package/assets/images/bg-aside.png +0 -0
  39. package/assets/images/bg-chart-circle.png +0 -0
  40. package/assets/images/bg-chart-triangle.png +0 -0
  41. package/assets/images/cashub-logo-only.png +0 -0
  42. package/assets/images/default-user.jpg +0 -0
  43. package/assets/images/logo-cashub.png +0 -0
  44. package/assets/images/map.png +0 -0
  45. package/assets/images/qrcode.png +0 -0
  46. package/backdrop/BaseBackdrop.js +18 -0
  47. package/backdrop/LoadingBackdrop.js +17 -0
  48. package/backdrop/ModalBackdrop.js +15 -0
  49. package/backdrop/index.js +27 -0
  50. package/badge/Badge.js +26 -0
  51. package/badge/BadgeDot.js +18 -0
  52. package/badge/BadgeFill.js +49 -0
  53. package/badge/BadgeFillTriangle.js +147 -0
  54. package/badge/BadgeWithText.js +31 -0
  55. package/badge/index.js +41 -0
  56. package/billing/BarChart.js +51 -0
  57. package/billing/Grid.js +45 -0
  58. package/billing/Header2.js +25 -0
  59. package/billing/Header3.js +37 -0
  60. package/billing/Paragraph.js +33 -0
  61. package/billing/ParagraphGroup.js +22 -0
  62. package/billing/ParagraphText.js +26 -0
  63. package/billing/Section.js +50 -0
  64. package/billing/SectionBody.js +17 -0
  65. package/billing/SectionHeader.js +26 -0
  66. package/billing/__stories__/BarChart.stories.js_bak +46 -0
  67. package/billing/__stories__/Grid.stories.js_bak +57 -0
  68. package/billing/__stories__/Header2.stories.js_bak +62 -0
  69. package/billing/__stories__/Header3.stories.js_bak +69 -0
  70. package/billing/__stories__/Paragraph.stories.js_bak +84 -0
  71. package/billing/__stories__/ParagraphGroup.stories.js_bak +68 -0
  72. package/billing/__stories__/ParagraphText.stories.js_bak +64 -0
  73. package/billing/__stories__/Section.stories.js_bak +115 -0
  74. package/billing/__stories__/SectionBody.stories.js_bak +62 -0
  75. package/billing/__stories__/SectionHeader.stories.js-bak +68 -0
  76. package/breadcrumb/Breadcrumb.js +78 -0
  77. package/breadcrumb/index.js +13 -0
  78. package/button/Button.js +154 -0
  79. package/button/ButtonGroup.js +61 -0
  80. package/button/IconButton.js +72 -0
  81. package/button/ScrollToTopButton.js +54 -0
  82. package/button/index.js +34 -0
  83. package/callout/Callout.js +52 -0
  84. package/callout/index.js +13 -0
  85. package/chart/BarChart.js +148 -0
  86. package/chart/DoughnutChart.js +118 -0
  87. package/chart/LineChart.js +146 -0
  88. package/chart/SingleBarChart.js +42 -0
  89. package/chart/index.js +52 -0
  90. package/chart/utils/centerTextPlugin.js +62 -0
  91. package/chart/utils/customTooltip.js +94 -0
  92. package/chart/utils/htmlLegendPlugin.js +89 -0
  93. package/chart/utils/index.js +27 -0
  94. package/chart/utils/padEmptyChartBar.js +53 -0
  95. package/chart/utils/yAxisTopTitlePlugin.js +49 -0
  96. package/container/FlexContainer.js +40 -0
  97. package/container/index.js +13 -0
  98. package/cropper/Cropper.js +54 -0
  99. package/cropper/CropperModalHandler.js +41 -0
  100. package/cropper/index.js +20 -0
  101. package/cropper/subComponent/CropImageModal.js +79 -0
  102. package/datetimePicker/DatePicker.js +363 -0
  103. package/datetimePicker/DatePickerV2.js +407 -0
  104. package/datetimePicker/DatetimePicker.js +240 -0
  105. package/datetimePicker/DatetimePickerV2.js +395 -0
  106. package/datetimePicker/DatetimePickerV3.js +279 -0
  107. package/datetimePicker/TimeInput.js +56 -0
  108. package/datetimePicker/TimePicker.js +317 -0
  109. package/datetimePicker/TimePickerStyle.js +64 -0
  110. package/datetimePicker/TimePickerV2.js +208 -0
  111. package/datetimePicker/accordion/Month.js +254 -0
  112. package/datetimePicker/accordion/Year.js +284 -0
  113. package/datetimePicker/hooks/index.js +27 -0
  114. package/datetimePicker/hooks/useChangeNumber.js +42 -0
  115. package/datetimePicker/hooks/useDecrease.js +38 -0
  116. package/datetimePicker/hooks/useIncrease.js +38 -0
  117. package/datetimePicker/index.js +69 -0
  118. package/datetimePicker/provider/constant.js +43 -0
  119. package/datetimePicker/subComponent/Accordion.js +373 -0
  120. package/datetimePicker/subComponent/CustomTimeInput.js +47 -0
  121. package/datetimePicker/subComponent/DateTimePickerContext.js +9 -0
  122. package/datetimePicker/utils/GMTDate.js +15 -0
  123. package/datetimePicker/utils/pad.js +13 -0
  124. package/datetimePicker/utils/toUTC0.js +13 -0
  125. package/descriptionList/DescriptionDetail.js +28 -0
  126. package/descriptionList/DescriptionList.js +25 -0
  127. package/descriptionList/DescriptionTerm.js +14 -0
  128. package/descriptionList/index.js +27 -0
  129. package/divider/Divider.js +31 -0
  130. package/divider/index.js +13 -0
  131. package/dropdown/Dropdown.js +55 -0
  132. package/dropdown/DropdownButtonOption.js +43 -0
  133. package/dropdown/DropdownContent.js +90 -0
  134. package/dropdown/DropdownDivOption.js +26 -0
  135. package/dropdown/DropdownItem.js +26 -0
  136. package/dropdown/DropdownLinkOption.js +24 -0
  137. package/dropdown/DropdownToggle.js +38 -0
  138. package/dropdown/index.js +42 -0
  139. package/dropdown/subComponent/DropdownContext.js +9 -0
  140. package/dropzone/FileDropzone.js +479 -0
  141. package/dropzone/ImageDropzone.js +334 -0
  142. package/dropzone/index.js +20 -0
  143. package/dropzone/subComponent/Message.js +26 -0
  144. package/figure/IconFigure.js +42 -0
  145. package/figure/ImageFigure.js +38 -0
  146. package/figure/index.js +20 -0
  147. package/file/HiddenFileInput.js +15 -0
  148. package/file/index.js +13 -0
  149. package/form/Checkbox.js +166 -0
  150. package/form/Fieldset.js +18 -0
  151. package/form/FormItem.js +22 -0
  152. package/form/Input.js +66 -0
  153. package/form/Label.js +61 -0
  154. package/form/MutedText.js +21 -0
  155. package/form/PasswordInput.js +47 -0
  156. package/form/RadioButton.js +103 -0
  157. package/form/SearchSelect.js +181 -0
  158. package/form/Searchbox.js +98 -0
  159. package/form/Slider.js +46 -0
  160. package/form/SwitchButton.js +105 -0
  161. package/form/Textarea.js +41 -0
  162. package/form/TreeView.js +73 -0
  163. package/form/index.js +104 -0
  164. package/grid/Column.js +46 -0
  165. package/grid/Grid.js +35 -0
  166. package/grid/index.js +20 -0
  167. package/heading/Heading1.js +21 -0
  168. package/heading/Heading2.js +28 -0
  169. package/heading/Heading3.js +49 -0
  170. package/heading/index.js +27 -0
  171. package/helmet/Helmet.js +23 -0
  172. package/helmet/index.js +20 -0
  173. package/iconbox/ApplicationIconBox.js +81 -0
  174. package/iconbox/IconBox.js +67 -0
  175. package/iconbox/IconBoxV2.js +72 -0
  176. package/iconbox/index.js +27 -0
  177. package/iconbox/subComponent/IconBoxFigure.js +50 -0
  178. package/iconbox/subComponent/IconBoxImage.js +42 -0
  179. package/image/ImageFluid.js +17 -0
  180. package/image/UploadImage.js +250 -0
  181. package/image/index.js +20 -0
  182. package/index.js +568 -0
  183. package/jsoneditor/JsonEditor.js +142 -0
  184. package/jsoneditor/index.js +13 -0
  185. package/keyframe/Pulse.js +21 -0
  186. package/keyframe/Spin.js +13 -0
  187. package/layout/Aside.js +48 -0
  188. package/layout/AsideHeader.jsx +27 -0
  189. package/layout/Backdrop.js +23 -0
  190. package/layout/Container.js +39 -0
  191. package/layout/Footer.js +45 -0
  192. package/layout/Header.jsx +55 -0
  193. package/layout/Layout.jsx +84 -0
  194. package/layout/Logo.jsx +17 -0
  195. package/layout/MenuIcon.jsx +27 -0
  196. package/layout/Sidebar.jsx +271 -0
  197. package/layout/index.js +13 -0
  198. package/link/LinkSpan.js +69 -0
  199. package/link/index.js +13 -0
  200. package/map/GoogleMap.js +448 -0
  201. package/map/GoogleReverseGeolocation.js +200 -0
  202. package/map/LeafletMap.js +231 -0
  203. package/map/LeafletReverseGeolocation.js +101 -0
  204. package/map/index.js +34 -0
  205. package/map/subComponent/BasicLeafletMap.js +34 -0
  206. package/map/subComponent/GoogleMapContainer.js +29 -0
  207. package/map/subComponent/GoogleMapPopup.js +109 -0
  208. package/map/subComponent/GoogleMapWrapper.js +40 -0
  209. package/map/subComponent/LeafletDrawControl.js +127 -0
  210. package/map/subComponent/LeafletMapContainer.js +173 -0
  211. package/map/subComponent/MapSearchBoxControl.js +54 -0
  212. package/modal/StateModal.js +178 -0
  213. package/modal/TitleModal.js +250 -0
  214. package/modal/index.js +20 -0
  215. package/package.json +54 -0
  216. package/page/Disclaimer.js +128 -0
  217. package/page/index.js +13 -0
  218. package/paginate/Paginate.js +137 -0
  219. package/paginate/index.js +13 -0
  220. package/popover/Popover.js +91 -0
  221. package/popover/index.js +13 -0
  222. package/qrcode/QRCode.js +58 -0
  223. package/qrcode/QRCodeContainter.js +34 -0
  224. package/qrcode/index.js +20 -0
  225. package/ribbon/Ribbon.js +42 -0
  226. package/ribbon/index.js +13 -0
  227. package/section/Section.js +133 -0
  228. package/section/SectionBody.js +52 -0
  229. package/section/SectionHeader.js +70 -0
  230. package/section/SectionToolbar.js +18 -0
  231. package/section/SectionToolbarItem.js +17 -0
  232. package/section/index.js +41 -0
  233. package/select/InputSelect.js +270 -0
  234. package/select/Select.js +818 -0
  235. package/select/index.js +20 -0
  236. package/select/subComponent/Checkbox.js +48 -0
  237. package/select/subComponent/Footer.js +13 -0
  238. package/select/subComponent/ListBox.js +30 -0
  239. package/select/subComponent/Option.js +45 -0
  240. package/select/subComponent/OptionGroup.js +23 -0
  241. package/select/subComponent/Options.js +32 -0
  242. package/select/subComponent/SearchBox.js +58 -0
  243. package/select/subComponent/SelectedMultipleCount.js +39 -0
  244. package/select/subComponent/SelectedMultipleTags.js +54 -0
  245. package/select/subComponent/SelectedMultipleText.js +70 -0
  246. package/select/subComponent/SelectedSingle.js +17 -0
  247. package/styles/GlobalStyle.js +334 -0
  248. package/styles/config/breakpoint.style.js +13 -0
  249. package/styles/config/header.style.js +10 -0
  250. package/styles/config/sidebar.style.js +17 -0
  251. package/styles/index.js +20 -0
  252. package/styles/mixin/backgroundColor.js +44 -0
  253. package/styles/mixin/borderColor.js +37 -0
  254. package/styles/mixin/color.js +37 -0
  255. package/styles/mixin/colorOnBackground.js +37 -0
  256. package/styles/mixin/inputPlaceholder.js +30 -0
  257. package/styles/mixin/media.js +21 -0
  258. package/styles/mixin/rounded.js +30 -0
  259. package/styles/mixin/scrollbar.js +32 -0
  260. package/styles/theme/dark.theme.js +97 -0
  261. package/styles/theme/light.theme.js +97 -0
  262. package/styles/theme/white.theme.js +97 -0
  263. package/styles/themes.js +16 -0
  264. package/table/GridTable.js +336 -0
  265. package/table/ImageBox.js +45 -0
  266. package/table/InfiniteGridTable.js +403 -0
  267. package/table/PermissionTable.js +64 -0
  268. package/table/SimpleGridTable.js +143 -0
  269. package/table/Table.js +568 -0
  270. package/table/__mock__/columns.js +70 -0
  271. package/table/__mock__/data.js +536 -0
  272. package/table/hooks/index.js +20 -0
  273. package/table/hooks/useCalculateDataRange.js +28 -0
  274. package/table/hooks/useGenerateSort.js +39 -0
  275. package/table/index.js +48 -0
  276. package/table/subComponent/BaseTableHeadCell.js +62 -0
  277. package/table/subComponent/GridTableFooter.js +24 -0
  278. package/table/subComponent/GridTableHeadCell.js +20 -0
  279. package/table/subComponent/Resizer.js +77 -0
  280. package/table/subComponent/TableFooter.js +31 -0
  281. package/table/subComponent/TableFooterInfo.js +13 -0
  282. package/table/subComponent/TableFooterPager.js +33 -0
  283. package/table/subComponent/TableHeadCell.js +19 -0
  284. package/table/subComponent/TableSort.js +38 -0
  285. package/tagify/TagifyStyle.js +60 -0
  286. package/tagify/Tags.js +56 -0
  287. package/tagify/index.js +27 -0
  288. package/tagify/templates/getCreateButtonTemplate.js +18 -0
  289. package/text/Paragraph.js +86 -0
  290. package/text/index.js +13 -0
  291. package/timeline/Timeline.js +139 -0
  292. package/timeline/index.js +13 -0
  293. package/toast/CustomToastContainer.js +45 -0
  294. package/toast/MessageContainer.js +51 -0
  295. package/toast/index.js +36 -0
  296. package/toast/show.js +39 -0
  297. package/toast/style.css +1 -0
  298. package/tooltip/Tooltip.js +140 -0
  299. package/tooltip/index.js +13 -0
  300. package/treeView/TreeViewV2.js +38 -0
  301. package/treeView/TreeflexStyle.js +49 -0
  302. package/treeView/index.js +20 -0
  303. package/wizard/Wizard.js +251 -0
  304. package/wizard/index.js +13 -0
@@ -0,0 +1,395 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _react = require("react");
8
+ var _reactI18next = require("react-i18next");
9
+ var _reactOutsideClickHandler = _interopRequireDefault(require("react-outside-click-handler"));
10
+ var _styledComponents = _interopRequireWildcard(require("styled-components"));
11
+ var _hooks = require("@cashub/hooks");
12
+ var _utils = require("@cashub/utils");
13
+ var _DateTimePickerContext = _interopRequireDefault(require("./subComponent/DateTimePickerContext"));
14
+ var _Button = _interopRequireDefault(require("../button/Button"));
15
+ var _Input = _interopRequireDefault(require("../form/Input"));
16
+ var _Month = _interopRequireDefault(require("./accordion/Month"));
17
+ var _Year = _interopRequireDefault(require("./accordion/Year"));
18
+ var _TimePicker = _interopRequireDefault(require("./TimePicker"));
19
+ var _GMTDate = _interopRequireDefault(require("./utils/GMTDate"));
20
+ var _jsxRuntime = require("react/jsx-runtime");
21
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
22
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
23
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
24
+ const DatetimePickerV2 = _ref => {
25
+ let {
26
+ selected,
27
+ fixedYear,
28
+ minDate,
29
+ maxDate,
30
+ onConfirm,
31
+ disabled,
32
+ onBlur
33
+ } = _ref;
34
+ const {
35
+ t
36
+ } = (0, _reactI18next.useTranslation)();
37
+ const [toggleElement, setToggleElement] = (0, _react.useState)(null);
38
+ const [contentElement, setContentElement] = (0, _react.useState)(null);
39
+ const [inputValue, setInputValue] = (0, _react.useState)(selected ? (0, _utils.datetimeTFormat)(selected) : '');
40
+ const [selectedDate, setSelectedDate] = (0, _react.useState)(selected ? (0, _utils.datetimeTFormat)((0, _GMTDate.default)(selected)) : (0, _utils.datetimeTFormat)((0, _GMTDate.default)(new Date())));
41
+ const [confirmDate, setConfirmDate] = (0, _react.useState)(selected ? (0, _utils.datetimeTFormat)(selected) : '');
42
+ const [displayPicker, setDisplayPicker] = (0, _react.useState)(false);
43
+ const [time, setTime] = (0, _react.useState)(() => {
44
+ const date = new Date((0, _utils.datetimeTFormat)(selected ? selected : (0, _utils.formatDate)(new Date())));
45
+ if (!selected) date.setHours(0, 0, 0, 0);
46
+ return `${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`;
47
+ });
48
+ const [accordionCurrentDisplayType, setAccordionCurrentDisplayType] = (0, _react.useState)(null);
49
+ const {
50
+ styles,
51
+ attributes,
52
+ state,
53
+ update
54
+ } = (0, _hooks.useCustomPopper)(toggleElement, contentElement, {
55
+ strategy: 'absolute',
56
+ placement: 'bottom-start'
57
+ });
58
+ const context = {
59
+ fixedYear,
60
+ minDate,
61
+ maxDate,
62
+ selectedDate,
63
+ setSelectedDate,
64
+ setAccordionCurrentDisplayType
65
+ };
66
+ const handleToggle = () => {
67
+ if (displayPicker && onBlur) {
68
+ onBlur();
69
+ }
70
+ setDisplayPicker(!displayPicker);
71
+ update();
72
+ };
73
+ const handleDisplayAccordionContent = (0, _react.useCallback)(type => {
74
+ if (accordionCurrentDisplayType === type) {
75
+ setAccordionCurrentDisplayType(null);
76
+ } else {
77
+ setAccordionCurrentDisplayType(type);
78
+ }
79
+ }, [accordionCurrentDisplayType]);
80
+ const handleConfirm = (0, _react.useCallback)(() => {
81
+ if (!confirmDate) return;
82
+ setSelectedDate(confirmDate);
83
+ onConfirm(inputValue);
84
+ setDisplayPicker(false);
85
+ setAccordionCurrentDisplayType(null);
86
+ if (displayPicker && onBlur) {
87
+ onBlur();
88
+ }
89
+ }, [confirmDate, inputValue, onConfirm, onBlur, displayPicker]);
90
+ const handleChangeDate = (0, _react.useCallback)((daysOfMonthForSelectedDate, firstWeekOfMonth, dayIndex, day) => {
91
+ const date = new Date(selectedDate);
92
+ // 先把日期設定成所有月分都有的日期,設定月份時才不會設定到非預期的date
93
+ date.setDate(1);
94
+ const selectedYear = date.getFullYear();
95
+ const selectedMonth = date.getMonth();
96
+ if (!fixedYear) {
97
+ if (dayIndex < firstWeekOfMonth && selectedYear >= 1) {
98
+ if (selectedMonth === 0) {
99
+ date.setFullYear(selectedYear - 1);
100
+ date.setMonth(11);
101
+ } else {
102
+ date.setMonth(selectedMonth - 1);
103
+ }
104
+ } else if (dayIndex >= daysOfMonthForSelectedDate + firstWeekOfMonth) {
105
+ if (selectedMonth === 11) {
106
+ date.setFullYear(selectedYear + 1);
107
+ date.setMonth(0);
108
+ } else {
109
+ date.setMonth(selectedMonth + 1);
110
+ }
111
+ }
112
+ date.setDate(day);
113
+ setSelectedDate((0, _utils.datetimeTFormat)(date));
114
+ setConfirmDate((0, _utils.datetimeTFormat)(date));
115
+ } else if (fixedYear) {
116
+ if (dayIndex < firstWeekOfMonth) {
117
+ if (selectedMonth === 0) {
118
+ return;
119
+ }
120
+ date.setMonth(selectedMonth - 1);
121
+ } else if (dayIndex >= daysOfMonthForSelectedDate + firstWeekOfMonth) {
122
+ if (selectedMonth === 11) {
123
+ return;
124
+ }
125
+ date.setMonth(selectedMonth + 1);
126
+ }
127
+ date.setDate(day);
128
+ setSelectedDate((0, _utils.datetimeTFormat)(date));
129
+ setConfirmDate((0, _utils.datetimeTFormat)(date));
130
+ }
131
+ }, [fixedYear, selectedDate]);
132
+ const handleDisabled = (0, _react.useCallback)((firstWeekOfMonth, lastWeekOfMonth, daysOfMonthForSelectedDate, dayIndex, day) => {
133
+ let [year, month] = selectedDate.split('-');
134
+ if (year === '0001' && month === '01' && firstWeekOfMonth >= dayIndex + 1) {
135
+ return true;
136
+ }
137
+ let myDay = day.toString();
138
+ if (myDay.length === 1) myDay = `0${myDay}`;
139
+ if (fixedYear) {
140
+ if (month === '01' && dayIndex + 1 <= firstWeekOfMonth) {
141
+ // disabledDateInJan
142
+ return dayIndex < firstWeekOfMonth;
143
+ } else if (month === '12' && day + firstWeekOfMonth < dayIndex + 1) {
144
+ // disabledDateInDec
145
+ return dayIndex >= daysOfMonthForSelectedDate + firstWeekOfMonth;
146
+ }
147
+ }
148
+ if (month === '01' && firstWeekOfMonth !== 0 && dayIndex + 1 <= firstWeekOfMonth) {
149
+ year = (+year - 1).toString();
150
+ } else if (month === '12' && lastWeekOfMonth !== 6 && day + firstWeekOfMonth < dayIndex + 1) {
151
+ year = (+year + 1).toString();
152
+ }
153
+ month = firstWeekOfMonth >= dayIndex + 1 ? +month - 1 : daysOfMonthForSelectedDate + firstWeekOfMonth < dayIndex + 1 ? +month + 1 : +month;
154
+ if (month === 0) {
155
+ month = 12;
156
+ } else if (month === 13) {
157
+ month = 1;
158
+ }
159
+ if (year.length === 1) year = `000${year}`;
160
+ if (year.length === 2) year = `00${year}`;
161
+ if (year.length === 3) year = `0${year}`;
162
+ if (month.toString().length === 1) month = `0${month}`;else month = month.toString();
163
+ const compareMinDateDate = (0, _utils.formatDate)((0, _utils.datetimeTFormat)(new Date((0, _GMTDate.default)((0, _utils.formatDate)(new Date(`${year}-${month}-${myDay}`)), 'date')).setHours(23, 59, 59, 59)));
164
+ const compareMaxDateDate = (0, _utils.formatDate)((0, _utils.datetimeTFormat)(new Date((0, _GMTDate.default)((0, _utils.formatDate)(new Date(`${year}-${month}-${myDay}`)), 'date')).setHours(0, 0, 0, 0)));
165
+ if (minDate && !maxDate && minDate > compareMinDateDate) {
166
+ return true;
167
+ }
168
+ if (maxDate && !minDate && maxDate < compareMaxDateDate) {
169
+ return true;
170
+ }
171
+ if (maxDate && minDate && (minDate > compareMinDateDate || maxDate < compareMaxDateDate)) {
172
+ return true;
173
+ }
174
+ return false;
175
+ }, [fixedYear, minDate, maxDate, selectedDate]);
176
+ const handleSelectedDay = (0, _react.useCallback)((day, index, firstWeekOfMonth, lastWeekOfMonth, totalDays) => {
177
+ const selectedDateObj = new Date(selectedDate);
178
+ const confirmDateObj = new Date(confirmDate);
179
+ if (confirmDateObj.getFullYear() === selectedDateObj.getFullYear() && confirmDateObj.getMonth() === selectedDateObj.getMonth() && confirmDateObj.getDate() === day) {
180
+ if (index + 1 > firstWeekOfMonth && index < totalDays - (6 - lastWeekOfMonth)) {
181
+ return true;
182
+ }
183
+ return false;
184
+ }
185
+ return false;
186
+ }, [selectedDate, confirmDate]);
187
+ const days = (0, _react.useMemo)(() => {
188
+ let date = new Date(selectedDate);
189
+ // 先把日期設定成所有月分都有的日期,設定月份時才不會設定到非預期的date
190
+ date.setDate(1);
191
+ date.setMonth(date.getMonth() + 1);
192
+ date.setDate(0);
193
+ const daysOfMonthForSelectedDate = date.getDate();
194
+ date = new Date(selectedDate);
195
+ date.setMonth(date.getMonth() + 1 - 1);
196
+ date.setDate(0);
197
+ const daysOfPrevioueMonthForSelectedDate = date.getDate();
198
+ date = new Date(selectedDate);
199
+ // 先把日期設定成所有月分都有的日期,設定月份時才不會設定到非預期的date
200
+ date.setDate(1);
201
+ const firstWeekOfMonth = date.getDay();
202
+ date = new Date(selectedDate);
203
+ // 先把日期設定成所有月分都有的日期,設定月份時才不會設定到非預期的date
204
+ date.setDate(1);
205
+ date.setMonth(date.getMonth() + 1);
206
+ date.setDate(0);
207
+ const lastWeekOfMonth = date.getDay();
208
+ const days = [];
209
+ for (const day of [...Array(daysOfMonthForSelectedDate).keys()]) {
210
+ days.push(day + 1);
211
+ }
212
+ if (firstWeekOfMonth !== 0) {
213
+ for (let index = daysOfPrevioueMonthForSelectedDate; index > daysOfPrevioueMonthForSelectedDate - firstWeekOfMonth; index -= 1) {
214
+ if (date.getFullYear() === 1 && date.getMonth() === 0) {
215
+ days.unshift(null);
216
+ } else {
217
+ days.unshift(index);
218
+ }
219
+ }
220
+ }
221
+ if (lastWeekOfMonth !== 6) {
222
+ for (let index = 1; index <= 6 - lastWeekOfMonth; index += 1) {
223
+ days.push(index);
224
+ }
225
+ }
226
+ return days.map((day, index, arr) => {
227
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(Day, {
228
+ disabled: handleDisabled(firstWeekOfMonth, lastWeekOfMonth, daysOfMonthForSelectedDate, index, day),
229
+ onClick: () => {
230
+ handleChangeDate(daysOfMonthForSelectedDate, firstWeekOfMonth, index, day);
231
+ },
232
+ selected: handleSelectedDay(day, index, firstWeekOfMonth, lastWeekOfMonth, arr.length, daysOfMonthForSelectedDate),
233
+ children: day
234
+ }, index);
235
+ });
236
+ }, [selectedDate, handleChangeDate, handleSelectedDay, handleDisabled]);
237
+ const weeks = (0, _react.useMemo)(() => {
238
+ return ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'].map(week => /*#__PURE__*/(0, _jsxRuntime.jsx)(Week, {
239
+ children: week
240
+ }, week));
241
+ }, []);
242
+ (0, _react.useEffect)(() => {
243
+ if (!selected) return;
244
+ const date = (0, _utils.datetimeTFormat)(selected);
245
+ const [, time] = date.split('T');
246
+ setSelectedDate(date);
247
+ setConfirmDate(date);
248
+ setTime(time);
249
+ }, [selected]);
250
+ (0, _react.useEffect)(() => {
251
+ if (!confirmDate) return;
252
+ const date = (0, _utils.formatDate)(confirmDate, 'date');
253
+ setInputValue(`${date} ${time}`);
254
+ }, [confirmDate, time]);
255
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_DateTimePickerContext.default.Provider, {
256
+ value: context,
257
+ children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactOutsideClickHandler.default, {
258
+ onOutsideClick: handleConfirm,
259
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(PickerInput, {
260
+ ref: setToggleElement,
261
+ value: inputValue,
262
+ onClick: handleToggle,
263
+ readOnly: true,
264
+ disabled: disabled
265
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(Wrapper, {
266
+ ...attributes.popper,
267
+ style: styles.popper,
268
+ placement: state && state.placement,
269
+ ref: setContentElement,
270
+ displayPicker: displayPicker,
271
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(Body, {
272
+ accordionCurrentDisplayType: accordionCurrentDisplayType,
273
+ children: [!fixedYear && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Year.default, {
274
+ expand: accordionCurrentDisplayType === 'year',
275
+ handleDisplayAccordionContent: () => {
276
+ handleDisplayAccordionContent('year');
277
+ }
278
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Month.default, {
279
+ expand: accordionCurrentDisplayType === 'month',
280
+ handleDisplayAccordionContent: () => {
281
+ handleDisplayAccordionContent('month');
282
+ },
283
+ confirmDate: confirmDate
284
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(DateContent, {
285
+ children: [weeks, days]
286
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_TimePicker.default, {
287
+ value: time,
288
+ onChange: setTime
289
+ })]
290
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(Footer, {
291
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(ConfirmButton, {
292
+ fullWidth: true,
293
+ alignCenter: true,
294
+ onClick: handleConfirm,
295
+ children: t('Confirm')
296
+ })
297
+ })]
298
+ })]
299
+ })
300
+ });
301
+ };
302
+ const Wrapper = _styledComponents.default.div`
303
+ padding-bottom: var(--spacing-s);
304
+ background: var(--color-background1);
305
+ border-radius: var(--border-radius);
306
+ border: var(--border-width) solid var(--border-color);
307
+ box-shadow: var(--box-shadow);
308
+ overflow: hidden;
309
+ width: 286px;
310
+ z-index: 1;
311
+ color: var(--font-on-background);
312
+
313
+ display: ${_ref2 => {
314
+ let {
315
+ displayPicker
316
+ } = _ref2;
317
+ return displayPicker ? 'block' : 'none';
318
+ }};
319
+ `;
320
+ const Week = _styledComponents.default.div`
321
+ height: 36px;
322
+ width: calc(100% / 7);
323
+ border-radius: var(--border-radius-s);
324
+ line-height: 36px;
325
+ text-align: center;
326
+ `;
327
+ const Body = _styledComponents.default.div`
328
+ ${_ref3 => {
329
+ let {
330
+ accordionCurrentDisplayType
331
+ } = _ref3;
332
+ return accordionCurrentDisplayType && (0, _styledComponents.css)`
333
+ height: 216px;
334
+ `;
335
+ }}
336
+
337
+ overflow: hidden;
338
+ padding: ${_ref4 => {
339
+ let {
340
+ accordionCurrentDisplayType
341
+ } = _ref4;
342
+ return accordionCurrentDisplayType === 'year' ? ' 0 4px var(--spacing-s) var(--spacing-s)' : '0 var(--spacing-s) 0 var(--spacing-s)';
343
+ }};
344
+ `;
345
+ const Footer = _styledComponents.default.div`
346
+ padding: 0 var(--spacing-s);
347
+ `;
348
+ const PickerInput = (0, _styledComponents.default)(_Input.default)`
349
+ &:disabled {
350
+ cursor: not-allowed;
351
+ opacity: 0.5;
352
+ }
353
+ `;
354
+ const Day = _styledComponents.default.button`
355
+ width: calc(100% / 7);
356
+ height: 36px;
357
+ border-radius: var(--border-radius-s);
358
+ line-height: 36px;
359
+ text-align: center;
360
+ padding: 0;
361
+ border: 0;
362
+ background: var(--color-background1);
363
+ color: var(--font-on-background);
364
+ &:hover {
365
+ background: var(--color-primary);
366
+ }
367
+
368
+ ${_ref5 => {
369
+ let {
370
+ selected
371
+ } = _ref5;
372
+ return selected && 'background: var(--color-hover);';
373
+ }}
374
+
375
+ ${_ref6 => {
376
+ let {
377
+ disabled
378
+ } = _ref6;
379
+ return disabled && (0, _styledComponents.css)`
380
+ color: var(--font-on-mute);
381
+ background: none;
382
+ &:hover {
383
+ background: none;
384
+ }
385
+ `;
386
+ }}
387
+ `;
388
+ const ConfirmButton = (0, _styledComponents.default)(_Button.default)`
389
+ margin: 16px auto 0;
390
+ `;
391
+ const DateContent = _styledComponents.default.div`
392
+ display: flex;
393
+ flex-wrap: wrap;
394
+ `;
395
+ var _default = exports.default = DatetimePickerV2;
@@ -0,0 +1,279 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _react = require("react");
8
+ var _styledComponents = _interopRequireDefault(require("styled-components"));
9
+ var _reactDatepicker = _interopRequireDefault(require("react-datepicker"));
10
+ require("react-datepicker/dist/react-datepicker.css");
11
+ var _TimePickerV = _interopRequireDefault(require("./TimePickerV2"));
12
+ var _jsxRuntime = require("react/jsx-runtime");
13
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
+ const setDateTime = (date, value) => {
15
+ const [hh, mm, ss] = value.split(':');
16
+ date.setHours(Number(hh) || 0, Number(mm) || 0, Number(ss) || 0, 0);
17
+ };
18
+ const DatetimePickerV3 = _ref => {
19
+ let {
20
+ selected = '',
21
+ onChange,
22
+ dateFormat = 'yyyy-MM-dd HH:mm:ss',
23
+ minDate,
24
+ maxDate,
25
+ showTimeInput,
26
+ readOnly,
27
+ disabled,
28
+ onBlur,
29
+ allowClear = false,
30
+ shouldCloseOnSelect = true,
31
+ placeholderText,
32
+ allowTimeInputEmpty = false
33
+ } = _ref;
34
+ const datepickerRef = (0, _react.useRef)(null);
35
+ const pendingTimeRef = (0, _react.useRef)(null);
36
+ const handleOnBlur = () => {
37
+ pendingTimeRef.current = null;
38
+ if (typeof onBlur === 'function') {
39
+ onBlur();
40
+ }
41
+ };
42
+ const selectedDate = (0, _react.useMemo)(() => {
43
+ return selected ? new Date(Date.parse(selected)) : '';
44
+ }, [selected]);
45
+ const handleChange = (0, _react.useCallback)(date => {
46
+ // when showTimeInput and DatetimePicker no value yet
47
+ if (showTimeInput && !selected && date) {
48
+ // if time selected before date, use selected time
49
+ if (pendingTimeRef.current) {
50
+ setDateTime(date, pendingTimeRef.current);
51
+ pendingTimeRef.current = null;
52
+ } else {
53
+ // if date selected before time, use current time
54
+ const now = new Date();
55
+ date.setHours(now.getHours(), now.getMinutes(), now.getSeconds(), 0);
56
+ }
57
+ }
58
+ onChange(date);
59
+ }, [onChange, selected, showTimeInput]);
60
+ const datePickerProps = {
61
+ dateFormat,
62
+ disabled,
63
+ onChange: handleChange,
64
+ selected: selectedDate,
65
+ minDate: minDate ? new Date(Date.parse(minDate)) : '',
66
+ maxDate: maxDate ? new Date(Date.parse(maxDate)) : '',
67
+ isClearable: allowClear && selected,
68
+ shouldCloseOnSelect,
69
+ placeholderText
70
+ };
71
+ const handleSelectTime = (0, _react.useCallback)(value => {
72
+ if (selectedDate) {
73
+ setDateTime(selectedDate, value);
74
+ onChange(selectedDate);
75
+ } else {
76
+ pendingTimeRef.current = value;
77
+ }
78
+ },
79
+ // NOTE: Adding onChange to the dependency list will cause a rerender loop
80
+ [selectedDate]);
81
+ if (showTimeInput) {
82
+ datePickerProps.showTimeInput = true;
83
+ datePickerProps.customTimeInput = /*#__PURE__*/(0, _jsxRuntime.jsx)(_TimePickerV.default, {
84
+ selected: selected,
85
+ onSelect: handleSelectTime,
86
+ allowEmpty: allowTimeInputEmpty && !selected
87
+ });
88
+ }
89
+ datePickerProps.onCalendarClose = handleOnBlur;
90
+ (0, _react.useEffect)(() => {
91
+ // set input to readonly
92
+ if (datepickerRef && datepickerRef.current && readOnly) {
93
+ datepickerRef.current.input.readOnly = readOnly;
94
+ }
95
+ }, [readOnly]);
96
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(Wrapper, {
97
+ disabled: disabled,
98
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactDatepicker.default, {
99
+ ...datePickerProps,
100
+ ref: datepickerRef
101
+ })
102
+ });
103
+ };
104
+ const Wrapper = _styledComponents.default.div`
105
+ .react-datepicker-wrapper,
106
+ .react-datepicker__input-container {
107
+ width: 100%;
108
+
109
+ > input {
110
+ width: 100%;
111
+ height: 36px;
112
+ color: var(--font-on-background);
113
+ background: transparent;
114
+ border-radius: var(--border-radius-l);
115
+ border: var(--border-width) solid var(--border-color);
116
+ padding: 0 var(--spacing-s);
117
+ outline: none;
118
+
119
+ ${_ref2 => {
120
+ let {
121
+ disabled
122
+ } = _ref2;
123
+ return disabled ? 'cursor: not-allowed; opacity: 0.5;' : '';
124
+ }}
125
+ }
126
+
127
+ > input + button {
128
+ padding: 0;
129
+ right: var(--spacing-s);
130
+ &::after {
131
+ color: var(--color-primary);
132
+ background-color: transparent;
133
+ font-size: 24px;
134
+ padding: 0;
135
+ }
136
+ }
137
+ }
138
+
139
+ .react-datepicker-popper {
140
+ z-index: 2;
141
+ }
142
+
143
+ .react-datepicker-popper[data-placement^='top'] {
144
+ padding-bottom: var(--spacing-xs);
145
+ }
146
+
147
+ .react-datepicker-popper[data-placement^='bottom'] {
148
+ padding-top: var(--spacing-xs);
149
+ }
150
+
151
+ .react-datepicker {
152
+ box-shadow: var(--box-shadow);
153
+ border-radius: var(--border-radius);
154
+ border: var(--border-width) solid var(--border-color);
155
+ padding: var(--spacing-s);
156
+ font-size: var(--font-body1);
157
+ color: var(--font-on-background);
158
+ background: var(--color-background1);
159
+
160
+ .react-datepicker__triangle {
161
+ &::before,
162
+ &::after {
163
+ display: none;
164
+ }
165
+ }
166
+
167
+ .react-datepicker__header {
168
+ border: none;
169
+ padding: 0;
170
+ background: var(--color-background1);
171
+ }
172
+
173
+ .react-datepicker__current-month {
174
+ line-height: 36px;
175
+ color: var(--font-on-background);
176
+ font-size: var(--font-body1);
177
+ font-weight: var(--font-normal);
178
+ }
179
+
180
+ .react-datepicker__day-names {
181
+ margin: 0;
182
+ }
183
+
184
+ .react-datepicker__day-name,
185
+ .react-datepicker__day {
186
+ width: 36px;
187
+ height: 36px;
188
+ line-height: 36px;
189
+ color: var(--font-on-background);
190
+ font-weight: var(--font-normal);
191
+ margin: 0;
192
+ border-radius: 4px;
193
+ }
194
+
195
+ .react-datepicker__day:hover {
196
+ background: var(--color-hover);
197
+ }
198
+
199
+ .react-datepicker__day--disabled {
200
+ color: var(--font-on-mute);
201
+ background: none !important;
202
+ }
203
+ }
204
+
205
+ .react-datepicker__month {
206
+ margin: 0;
207
+ }
208
+
209
+ .react-datepicker__navigation {
210
+ top: 0;
211
+ width: 36px;
212
+ height: 36px;
213
+ margin: var(--spacing-s) var(--spacing-s) 0 var(--spacing-s);
214
+ border-radius: 4px;
215
+
216
+ &.react-datepicker__navigation--previous {
217
+ left: 0;
218
+ }
219
+
220
+ &.react-datepicker__navigation--next {
221
+ right: 0;
222
+ }
223
+
224
+ &:hover {
225
+ background: var(--color-hover);
226
+ }
227
+
228
+ .react-datepicker__navigation-icon::before {
229
+ border-color: var(--font-on-background);
230
+ }
231
+
232
+ .react-datepicker__navigation-icon--previous::before {
233
+ right: -4px;
234
+ }
235
+
236
+ .react-datepicker__navigation-icon--next::before {
237
+ left: -4px;
238
+ }
239
+ }
240
+
241
+ .react-datepicker__day--selected,
242
+ .react-datepicker__day--in-selecting-range,
243
+ .react-datepicker__day--in-range,
244
+ .react-datepicker__month-text--selected,
245
+ .react-datepicker__month-text--in-selecting-range,
246
+ .react-datepicker__month-text--in-range,
247
+ .react-datepicker__quarter-text--selected,
248
+ .react-datepicker__quarter-text--in-selecting-range,
249
+ .react-datepicker__quarter-text--in-range,
250
+ .react-datepicker__year-text--selected,
251
+ .react-datepicker__year-text--in-selecting-range,
252
+ .react-datepicker__year-text--in-range {
253
+ background: var(--color-primary) !important;
254
+ }
255
+
256
+ .react-datepicker__day--keyboard-selected,
257
+ .react-datepicker__month-text--keyboard-selected,
258
+ .react-datepicker__quarter-text--keyboard-selected,
259
+ .react-datepicker__year-text--keyboard-selected {
260
+ background: none;
261
+ }
262
+
263
+ .react-datepicker__input-time-container {
264
+ margin: 0;
265
+ margin-top: var(--spacing-s);
266
+ margin-left: var(--spacing-xs);
267
+
268
+ .react-datepicker-time__input input {
269
+ height: 36px;
270
+ padding: 0 var(--spacing-xs);
271
+ border-radius: var(--border-radius);
272
+ border: var(--border-width) solid var(--border-color);
273
+ background: transparent;
274
+ color: var(--font-on-background);
275
+ outline: none;
276
+ }
277
+ }
278
+ `;
279
+ var _default = exports.default = DatetimePickerV3;