@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,407 @@
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 _md = require("react-icons/md");
12
+ var _hooks = require("@cashub/hooks");
13
+ var _utils = require("@cashub/utils");
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 _DateTimePickerContext = _interopRequireDefault(require("./subComponent/DateTimePickerContext"));
19
+ var _toUTC = _interopRequireDefault(require("./utils/toUTC0"));
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 DEFAULT_TIME = '00:00:00';
25
+ const DatePickerV2 = _ref => {
26
+ let {
27
+ selected,
28
+ fixedYear,
29
+ allowClear,
30
+ minDate,
31
+ maxDate,
32
+ onConfirm,
33
+ disabled
34
+ } = _ref;
35
+ const {
36
+ t
37
+ } = (0, _reactI18next.useTranslation)();
38
+ const [toggleElement, setToggleElement] = (0, _react.useState)(null);
39
+ const [contentElement, setContentElement] = (0, _react.useState)(null);
40
+ const [selectedDate, setSelectedDate] = (0, _react.useState)(() => {
41
+ const defaultDate = selected ? new Date(selected) : new Date();
42
+ return `${(0, _utils.formatDate)((0, _toUTC.default)(defaultDate), 'date')} ${DEFAULT_TIME}`;
43
+ });
44
+ const [confirmDate, setConfirmDate] = (0, _react.useState)(selected ? (0, _utils.formatDate)((0, _toUTC.default)(selected), 'date') : '');
45
+ const [displayPicker, setDisplayPicker] = (0, _react.useState)(false);
46
+ const [accordionCurrentDisplayType, setAccordionCurrentDisplayType] = (0, _react.useState)(null);
47
+ const weeks = (0, _react.useMemo)(() => {
48
+ return ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'].map(week => /*#__PURE__*/(0, _jsxRuntime.jsx)(Week, {
49
+ children: week
50
+ }, week));
51
+ }, []);
52
+ const minDateWithTime = (0, _react.useMemo)(() => {
53
+ if (!minDate) return;
54
+ return `${minDate} 00:00:00`;
55
+ }, [minDate]);
56
+ const maxDateWithTime = (0, _react.useMemo)(() => {
57
+ if (!maxDate) return;
58
+ return `${maxDate} 00:00:00`;
59
+ }, [maxDate]);
60
+ const {
61
+ styles,
62
+ attributes,
63
+ state,
64
+ update
65
+ } = (0, _hooks.useCustomPopper)(toggleElement, contentElement, {
66
+ strategy: 'absolute',
67
+ placement: 'bottom-start'
68
+ });
69
+ const context = {
70
+ fixedYear,
71
+ minDate: minDateWithTime,
72
+ maxDate: maxDateWithTime,
73
+ selectedDate,
74
+ setSelectedDate,
75
+ setAccordionCurrentDisplayType
76
+ };
77
+ const handleToggle = () => {
78
+ setDisplayPicker(!displayPicker);
79
+ update();
80
+ };
81
+ const changeDisplayAccordion = (0, _react.useCallback)(type => {
82
+ if (accordionCurrentDisplayType === type) {
83
+ setAccordionCurrentDisplayType(null);
84
+ } else {
85
+ setAccordionCurrentDisplayType(type);
86
+ }
87
+ }, [accordionCurrentDisplayType]);
88
+ const handleConfirm = (0, _react.useCallback)(() => {
89
+ if (confirmDate) {
90
+ onConfirm(confirmDate);
91
+ }
92
+ setDisplayPicker(false);
93
+ setAccordionCurrentDisplayType(null);
94
+ }, [confirmDate, onConfirm]);
95
+ const handleChangeDate = (0, _react.useCallback)((daysOfMonthForSelectedDate, firstWeekOfMonth, dayIndex, day) => {
96
+ const date = new Date(selectedDate);
97
+ // 先把日期設定成所有月分都有的日期,設定月份時才不會設定到非預期的date
98
+ date.setDate(1);
99
+ const selectedYear = date.getFullYear();
100
+ const selectedMonth = date.getMonth();
101
+ if (!fixedYear) {
102
+ if (dayIndex < firstWeekOfMonth && selectedYear >= 1) {
103
+ if (selectedMonth === 0) {
104
+ date.setFullYear(selectedYear - 1);
105
+ date.setMonth(11);
106
+ } else {
107
+ date.setMonth(selectedMonth - 1);
108
+ }
109
+ } else if (dayIndex >= daysOfMonthForSelectedDate + firstWeekOfMonth) {
110
+ if (selectedMonth === 11) {
111
+ date.setFullYear(selectedYear + 1);
112
+ date.setMonth(0);
113
+ } else {
114
+ date.setMonth(selectedMonth + 1);
115
+ }
116
+ }
117
+ date.setDate(day);
118
+ } else if (fixedYear) {
119
+ if (dayIndex < firstWeekOfMonth) {
120
+ if (selectedMonth === 0) {
121
+ return;
122
+ }
123
+ date.setMonth(selectedMonth - 1);
124
+ } else if (dayIndex >= daysOfMonthForSelectedDate + firstWeekOfMonth) {
125
+ if (selectedMonth === 11) {
126
+ return;
127
+ }
128
+ date.setMonth(selectedMonth + 1);
129
+ }
130
+ date.setDate(day);
131
+ }
132
+ const formattedDate = (0, _utils.formatDate)(date, 'date');
133
+ setSelectedDate(`${formattedDate} ${DEFAULT_TIME}`);
134
+ setConfirmDate(formattedDate);
135
+ }, [fixedYear, selectedDate]);
136
+ const handleDisabled = (0, _react.useCallback)((firstDayOfMonth, lastDayOfMonth, daysOfMonthForSelectedDate, dayIndex, day) => {
137
+ let [year, month] = selectedDate.split('-');
138
+
139
+ // disabled date before first month of first year
140
+ if (year === '0001' && month === '01' && dayIndex < firstDayOfMonth) {
141
+ return true;
142
+ }
143
+ let myDay = day.toString();
144
+ if (myDay.length === 1) myDay = `0${myDay}`;
145
+ if (fixedYear) {
146
+ if (month === '01') {
147
+ // disabled date before first month
148
+ return dayIndex < firstDayOfMonth;
149
+ } else if (month === '12') {
150
+ // disabled date in december
151
+ return dayIndex >= daysOfMonthForSelectedDate + firstDayOfMonth;
152
+ }
153
+ }
154
+
155
+ // previous year's date
156
+ if (month === '01' && firstDayOfMonth !== 0 && dayIndex + 1 <= firstDayOfMonth) {
157
+ year = +year - 1;
158
+ }
159
+
160
+ // next year's date
161
+ if (month === '12' && lastDayOfMonth !== 6 && day + firstDayOfMonth < dayIndex + 1) {
162
+ year = +year + 1;
163
+ }
164
+ month = firstDayOfMonth >= dayIndex + 1 ? +month - 1 : daysOfMonthForSelectedDate + firstDayOfMonth < dayIndex + 1 ? +month + 1 : +month;
165
+ if (month < 1) {
166
+ month = 12;
167
+ } else if (month > 12) {
168
+ month = 1;
169
+ }
170
+ month = month.toString();
171
+ if (month.length === 1) {
172
+ month = `0${month}`;
173
+ }
174
+ year = year.toString();
175
+ if (year.length === 1) year = `000${year}`;
176
+ if (year.length === 2) year = `00${year}`;
177
+ if (year.length === 3) year = `0${year}`;
178
+ const currentDate = `${year}-${month}-${myDay} ${DEFAULT_TIME}`;
179
+ if (minDateWithTime && currentDate < minDateWithTime) {
180
+ return true;
181
+ }
182
+ if (maxDateWithTime && currentDate > maxDateWithTime) {
183
+ return true;
184
+ }
185
+ return false;
186
+ }, [fixedYear, minDateWithTime, maxDateWithTime, selectedDate]);
187
+ const isSelectedDay = (0, _react.useCallback)((day, index, firstDayOfMonth, daysOfMonthForSelectedDate) => {
188
+ const selectedDateObj = new Date(selectedDate);
189
+ const confirmDateObj = (0, _toUTC.default)(new Date(confirmDate));
190
+ if (confirmDateObj.getFullYear() === selectedDateObj.getFullYear() && confirmDateObj.getMonth() === selectedDateObj.getMonth() && confirmDateObj.getDate() === day) {
191
+ if (index + 1 > firstDayOfMonth && index < daysOfMonthForSelectedDate + firstDayOfMonth) {
192
+ return true;
193
+ }
194
+ return false;
195
+ }
196
+ return false;
197
+ }, [selectedDate, confirmDate]);
198
+ const getLastDateOfMonth = selectedDate => {
199
+ const date = new Date(selectedDate);
200
+
201
+ // 先把日期設定成所有月分都有的日期,設定月份時才不會設定到非預期的date
202
+ date.setDate(1);
203
+ date.setMonth(date.getMonth() + 1);
204
+ date.setDate(0);
205
+ return date;
206
+ };
207
+ const days = (0, _react.useMemo)(() => {
208
+ const lastDateOfSelectedDate = getLastDateOfMonth(selectedDate);
209
+ const daysOfMonthForSelectedDate = lastDateOfSelectedDate.getDate();
210
+ const lastDayOfMonth = lastDateOfSelectedDate.getDay();
211
+ let date = new Date(selectedDate);
212
+ date.setMonth(date.getMonth() + 1 - 1);
213
+ date.setDate(0);
214
+ const daysOfPrevioueMonthForSelectedDate = date.getDate();
215
+ date = new Date(selectedDate);
216
+ // 先把日期設定成所有月分都有的日期,設定月份時才不會設定到非預期的date
217
+ date.setDate(1);
218
+ const firstDayOfMonth = date.getDay();
219
+ const days = [...Array(daysOfMonthForSelectedDate)].map((value, index) => {
220
+ return index + 1;
221
+ });
222
+ if (firstDayOfMonth !== 0) {
223
+ for (let index = daysOfPrevioueMonthForSelectedDate; index > daysOfPrevioueMonthForSelectedDate - firstDayOfMonth; index -= 1) {
224
+ if (date.getFullYear() === 1 && date.getMonth() === 0) {
225
+ days.unshift(null);
226
+ } else {
227
+ days.unshift(index);
228
+ }
229
+ }
230
+ }
231
+ if (lastDayOfMonth !== 6) {
232
+ for (let index = 1; index <= 6 - lastDayOfMonth; index += 1) {
233
+ days.push(index);
234
+ }
235
+ }
236
+ return days.map((day, index) => {
237
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(Day, {
238
+ disabled: handleDisabled(firstDayOfMonth, lastDayOfMonth, daysOfMonthForSelectedDate, index, day),
239
+ onClick: () => {
240
+ handleChangeDate(daysOfMonthForSelectedDate, firstDayOfMonth, index, day);
241
+ },
242
+ selected: isSelectedDay(day, index, firstDayOfMonth, daysOfMonthForSelectedDate),
243
+ children: day
244
+ }, index);
245
+ });
246
+ }, [selectedDate, handleChangeDate, isSelectedDay, handleDisabled]);
247
+ (0, _react.useEffect)(() => {
248
+ if (selected) {
249
+ const formattedDate = (0, _utils.formatDate)((0, _toUTC.default)(selected), 'date');
250
+ setSelectedDate(`${formattedDate} ${DEFAULT_TIME}`);
251
+ setConfirmDate(formattedDate);
252
+ } else {
253
+ setConfirmDate('');
254
+ }
255
+ }, [selected]);
256
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_DateTimePickerContext.default.Provider, {
257
+ value: context,
258
+ children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactOutsideClickHandler.default, {
259
+ onOutsideClick: handleConfirm,
260
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(Wrapper, {
261
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Input.default, {
262
+ disabled: disabled,
263
+ ref: setToggleElement,
264
+ value: confirmDate,
265
+ onClick: handleToggle,
266
+ readOnly: true
267
+ }), confirmDate && !disabled && allowClear && /*#__PURE__*/(0, _jsxRuntime.jsx)(CloseButton, {
268
+ onClick: () => {
269
+ setConfirmDate('');
270
+ onConfirm('');
271
+ }
272
+ })]
273
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(Picker, {
274
+ ...attributes.popper,
275
+ style: styles.popper,
276
+ placement: state && state.placement,
277
+ ref: setContentElement,
278
+ displayPicker: displayPicker,
279
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(Body, {
280
+ accordionCurrentDisplayType: accordionCurrentDisplayType,
281
+ children: [!fixedYear && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Year.default, {
282
+ expand: accordionCurrentDisplayType === 'year',
283
+ handleDisplayAccordionContent: () => {
284
+ changeDisplayAccordion('year');
285
+ }
286
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Month.default, {
287
+ expand: accordionCurrentDisplayType === 'month',
288
+ handleDisplayAccordionContent: () => {
289
+ changeDisplayAccordion('month');
290
+ },
291
+ confirmDate: confirmDate
292
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(DateContent, {
293
+ children: [weeks, days]
294
+ })]
295
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(Footer, {
296
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(ConfirmButton, {
297
+ fullWidth: true,
298
+ alignCenter: true,
299
+ onClick: handleConfirm,
300
+ children: t('Confirm')
301
+ })
302
+ })]
303
+ })]
304
+ })
305
+ });
306
+ };
307
+ const Wrapper = _styledComponents.default.div`
308
+ position: relative;
309
+ `;
310
+ const CloseButton = (0, _styledComponents.default)(_md.MdClose)`
311
+ position: absolute;
312
+ top: 50%;
313
+ transform: translateY(-50%);
314
+ color: var(--font-on-background);
315
+ font-size: var(--font-body1);
316
+ right: var(--spacing-s);
317
+ cursor: pointer;
318
+ `;
319
+ CloseButton.displayName = 'CloseButton';
320
+ const Picker = _styledComponents.default.div`
321
+ padding-bottom: var(--spacing-s);
322
+ background: var(--color-background1);
323
+ border-radius: var(--border-radius);
324
+ border: var(--border-width) solid var(--border-color);
325
+ box-shadow: var(--box-shadow);
326
+ overflow: hidden;
327
+ width: 286px;
328
+ z-index: 1;
329
+ color: var(--font-on-background);
330
+
331
+ display: ${_ref2 => {
332
+ let {
333
+ displayPicker
334
+ } = _ref2;
335
+ return displayPicker ? 'block' : 'none';
336
+ }};
337
+ `;
338
+ const Week = _styledComponents.default.div`
339
+ width: calc(100% / 7);
340
+ height: 36px;
341
+ border-radius: var(--border-radius-s);
342
+ line-height: 36px;
343
+ text-align: center;
344
+ `;
345
+ const Body = _styledComponents.default.div`
346
+ ${_ref3 => {
347
+ let {
348
+ accordionCurrentDisplayType
349
+ } = _ref3;
350
+ return accordionCurrentDisplayType && (0, _styledComponents.css)`
351
+ height: 216px;
352
+ `;
353
+ }}
354
+
355
+ overflow: hidden;
356
+ padding: ${_ref4 => {
357
+ let {
358
+ accordionCurrentDisplayType
359
+ } = _ref4;
360
+ return accordionCurrentDisplayType === 'year' ? ' 0 4px var(--spacing-s) var(--spacing-s)' : '0 var(--spacing-s) 0 var(--spacing-s)';
361
+ }};
362
+ `;
363
+ const Footer = _styledComponents.default.div`
364
+ padding: 0 var(--spacing-s);
365
+ `;
366
+ const Day = _styledComponents.default.button`
367
+ width: calc(100% / 7);
368
+ height: 36px;
369
+ border-radius: var(--border-radius-s);
370
+ line-height: 36px;
371
+ text-align: center;
372
+ padding: 0;
373
+ border: 0;
374
+ background: var(--color-background1);
375
+ color: var(--font-on-background);
376
+ &:hover {
377
+ background: var(--color-primary);
378
+ }
379
+
380
+ ${_ref5 => {
381
+ let {
382
+ selected
383
+ } = _ref5;
384
+ return selected && 'background: var(--color-hover);';
385
+ }}
386
+
387
+ ${_ref6 => {
388
+ let {
389
+ disabled
390
+ } = _ref6;
391
+ return disabled && (0, _styledComponents.css)`
392
+ color: var(--font-on-mute);
393
+ background: none;
394
+ &:hover {
395
+ background: none;
396
+ }
397
+ `;
398
+ }}
399
+ `;
400
+ const ConfirmButton = (0, _styledComponents.default)(_Button.default)`
401
+ margin: 16px auto 0;
402
+ `;
403
+ const DateContent = _styledComponents.default.div`
404
+ display: flex;
405
+ flex-wrap: wrap;
406
+ `;
407
+ var _default = exports.default = DatePickerV2;
@@ -0,0 +1,240 @@
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 _CustomTimeInput = _interopRequireDefault(require("./subComponent/CustomTimeInput"));
12
+ var _jsxRuntime = require("react/jsx-runtime");
13
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
+ const DatetimePicker = _ref => {
15
+ let {
16
+ selected = '',
17
+ onChange,
18
+ dateFormat = 'yyyy-MM-dd HH:mm:ss',
19
+ minDate,
20
+ maxDate,
21
+ showTimeInput,
22
+ readOnly,
23
+ disabled,
24
+ onBlur,
25
+ allowClear = false,
26
+ shouldCloseOnSelect = true
27
+ } = _ref;
28
+ const datepickerRef = (0, _react.useRef)(null);
29
+ const handleOnBlur = () => {
30
+ onBlur();
31
+ };
32
+ const datePickerProps = {
33
+ dateFormat,
34
+ disabled,
35
+ onChange,
36
+ selected: selected ? new Date(Date.parse(selected)) : '',
37
+ minDate: minDate ? new Date(Date.parse(minDate)) : '',
38
+ maxDate: maxDate ? new Date(Date.parse(maxDate)) : '',
39
+ isClearable: allowClear && selected && !disabled,
40
+ shouldCloseOnSelect
41
+ };
42
+ if (showTimeInput) {
43
+ datePickerProps.showTimeInput = true;
44
+ datePickerProps.customTimeInput = /*#__PURE__*/(0, _jsxRuntime.jsx)(_CustomTimeInput.default, {
45
+ onCustomChange: onChange
46
+ });
47
+ }
48
+ if (onBlur) {
49
+ datePickerProps.onCalendarClose = handleOnBlur;
50
+ }
51
+ (0, _react.useEffect)(() => {
52
+ // set input to readonly
53
+ if (datepickerRef && datepickerRef.current && readOnly) {
54
+ datepickerRef.current.input.readOnly = readOnly;
55
+ }
56
+ }, [readOnly]);
57
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(Wrapper, {
58
+ disabled: disabled,
59
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactDatepicker.default, {
60
+ ...datePickerProps,
61
+ ref: datepickerRef
62
+ })
63
+ });
64
+ };
65
+ const Wrapper = _styledComponents.default.div`
66
+ .react-datepicker-wrapper,
67
+ .react-datepicker__input-container {
68
+ width: 100%;
69
+
70
+ > input {
71
+ width: 100%;
72
+ height: 36px;
73
+ color: var(--font-on-background);
74
+ background: transparent;
75
+ border-radius: var(--border-radius-l);
76
+ border: var(--border-width) solid var(--border-color);
77
+ padding: 0 var(--spacing-s);
78
+ outline: none;
79
+
80
+ ${_ref2 => {
81
+ let {
82
+ disabled
83
+ } = _ref2;
84
+ return disabled ? 'cursor: not-allowed; opacity: 0.5;' : '';
85
+ }}
86
+ }
87
+
88
+ > input + button {
89
+ padding: 0;
90
+ right: var(--spacing-s);
91
+ &::after {
92
+ color: var(--color-primary);
93
+ background-color: transparent;
94
+ font-size: 24px;
95
+ padding: 0;
96
+ }
97
+ }
98
+ }
99
+
100
+ .react-datepicker-popper {
101
+ z-index: 2;
102
+ }
103
+
104
+ .react-datepicker-popper[data-placement^='top'] {
105
+ padding-bottom: var(--spacing-xs);
106
+ }
107
+
108
+ .react-datepicker-popper[data-placement^='bottom'] {
109
+ padding-top: var(--spacing-xs);
110
+ }
111
+
112
+ .react-datepicker {
113
+ box-shadow: var(--box-shadow);
114
+ border-radius: var(--border-radius);
115
+ border: var(--border-width) solid var(--border-color);
116
+ padding: var(--spacing-s);
117
+ font-size: var(--font-body1);
118
+ color: var(--font-on-background);
119
+ background: var(--color-background1);
120
+
121
+ .react-datepicker__triangle {
122
+ &::before,
123
+ &::after {
124
+ display: none;
125
+ }
126
+ }
127
+
128
+ .react-datepicker__header {
129
+ border: none;
130
+ padding: 0;
131
+ background: var(--color-background1);
132
+ }
133
+
134
+ .react-datepicker__current-month {
135
+ line-height: 36px;
136
+ color: var(--font-on-background);
137
+ font-size: var(--font-body1);
138
+ font-weight: var(--font-normal);
139
+ }
140
+
141
+ .react-datepicker__day-names {
142
+ margin: 0;
143
+ }
144
+
145
+ .react-datepicker__day-name,
146
+ .react-datepicker__day {
147
+ width: 36px;
148
+ height: 36px;
149
+ line-height: 36px;
150
+ color: var(--font-on-background);
151
+ font-weight: var(--font-normal);
152
+ margin: 0;
153
+ border-radius: 4px;
154
+ }
155
+
156
+ .react-datepicker__day:hover {
157
+ background: var(--color-hover);
158
+ }
159
+
160
+ .react-datepicker__day--disabled {
161
+ color: var(--font-on-mute);
162
+ background: none !important;
163
+ }
164
+ }
165
+
166
+ .react-datepicker__month {
167
+ margin: 0;
168
+ }
169
+
170
+ .react-datepicker__navigation {
171
+ top: 0;
172
+ width: 36px;
173
+ height: 36px;
174
+ margin: var(--spacing-s) var(--spacing-s) 0 var(--spacing-s);
175
+ border-radius: 4px;
176
+
177
+ &.react-datepicker__navigation--previous {
178
+ left: 0;
179
+ }
180
+
181
+ &.react-datepicker__navigation--next {
182
+ right: 0;
183
+ }
184
+
185
+ &:hover {
186
+ background: var(--color-hover);
187
+ }
188
+
189
+ .react-datepicker__navigation-icon::before {
190
+ border-color: var(--font-on-background);
191
+ }
192
+
193
+ .react-datepicker__navigation-icon--previous::before {
194
+ right: -4px;
195
+ }
196
+
197
+ .react-datepicker__navigation-icon--next::before {
198
+ left: -4px;
199
+ }
200
+ }
201
+
202
+ .react-datepicker__day--selected,
203
+ .react-datepicker__day--in-selecting-range,
204
+ .react-datepicker__day--in-range,
205
+ .react-datepicker__month-text--selected,
206
+ .react-datepicker__month-text--in-selecting-range,
207
+ .react-datepicker__month-text--in-range,
208
+ .react-datepicker__quarter-text--selected,
209
+ .react-datepicker__quarter-text--in-selecting-range,
210
+ .react-datepicker__quarter-text--in-range,
211
+ .react-datepicker__year-text--selected,
212
+ .react-datepicker__year-text--in-selecting-range,
213
+ .react-datepicker__year-text--in-range {
214
+ background: var(--color-primary) !important;
215
+ }
216
+
217
+ .react-datepicker__day--keyboard-selected,
218
+ .react-datepicker__month-text--keyboard-selected,
219
+ .react-datepicker__quarter-text--keyboard-selected,
220
+ .react-datepicker__year-text--keyboard-selected {
221
+ background: none;
222
+ }
223
+
224
+ .react-datepicker__input-time-container {
225
+ margin: 0;
226
+ margin-top: var(--spacing-s);
227
+ margin-left: var(--spacing-xs);
228
+
229
+ .react-datepicker-time__input input {
230
+ height: 36px;
231
+ padding: 0 var(--spacing-xs);
232
+ border-radius: var(--border-radius);
233
+ border: var(--border-width) solid var(--border-color);
234
+ background: transparent;
235
+ color: var(--font-on-background);
236
+ outline: none;
237
+ }
238
+ }
239
+ `;
240
+ var _default = exports.default = DatetimePicker;