@cashub/ui 0.17.12 → 0.18.1

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.
@@ -15,6 +15,8 @@ var _reactOutsideClickHandler = _interopRequireDefault(require("react-outside-cl
15
15
 
16
16
  var _styledComponents = _interopRequireWildcard(require("styled-components"));
17
17
 
18
+ var _md = require("react-icons/md");
19
+
18
20
  var _hooks = require("@cashub/hooks");
19
21
 
20
22
  var _utils = require("@cashub/utils");
@@ -29,11 +31,11 @@ var _Year = _interopRequireDefault(require("./accordion/Year"));
29
31
 
30
32
  var _DateTimePickerContext = _interopRequireDefault(require("./subComponent/DateTimePickerContext"));
31
33
 
32
- var _GMTDate = _interopRequireDefault(require("./utils/GMTDate"));
34
+ var _toUTC = _interopRequireDefault(require("./utils/toUTC0"));
33
35
 
34
36
  var _jsxRuntime = require("react/jsx-runtime");
35
37
 
36
- var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10;
38
+ var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10, _templateObject11;
37
39
 
38
40
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
39
41
 
@@ -69,11 +71,14 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
69
71
 
70
72
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
71
73
 
74
+ var DEFAULT_TIME = '00:00:00';
75
+
72
76
  var DatePickerV2 = function DatePickerV2(_ref) {
73
77
  var selected = _ref.selected,
74
78
  fixedYear = _ref.fixedYear,
75
- maxDate = _ref.maxDate,
79
+ allowClear = _ref.allowClear,
76
80
  minDate = _ref.minDate,
81
+ maxDate = _ref.maxDate,
77
82
  onConfirm = _ref.onConfirm,
78
83
  disabled = _ref.disabled;
79
84
 
@@ -85,17 +90,20 @@ var DatePickerV2 = function DatePickerV2(_ref) {
85
90
  toggleElement = _useState2[0],
86
91
  setToggleElement = _useState2[1];
87
92
 
88
- var _useState3 = (0, _react.useState)(selected ? (0, _utils.datetimeTFormat)(selected) : ''),
93
+ var _useState3 = (0, _react.useState)(null),
89
94
  _useState4 = _slicedToArray(_useState3, 2),
90
- inputValue = _useState4[0],
91
- setInputValue = _useState4[1];
95
+ contentElement = _useState4[0],
96
+ setContentElement = _useState4[1];
92
97
 
93
- var _useState5 = (0, _react.useState)(selected ? (0, _utils.datetimeTFormat)((0, _GMTDate.default)(selected)) : (0, _utils.datetimeTFormat)((0, _GMTDate.default)(new Date()))),
98
+ var _useState5 = (0, _react.useState)(function () {
99
+ var defaultDate = selected ? new Date(selected) : new Date();
100
+ return "".concat((0, _utils.formatDate)((0, _toUTC.default)(defaultDate), 'date'), " ").concat(DEFAULT_TIME);
101
+ }),
94
102
  _useState6 = _slicedToArray(_useState5, 2),
95
103
  selectedDate = _useState6[0],
96
104
  setSelectedDate = _useState6[1];
97
105
 
98
- var _useState7 = (0, _react.useState)(selected ? (0, _utils.datetimeTFormat)(selected) : ''),
106
+ var _useState7 = (0, _react.useState)(selected ? (0, _utils.formatDate)((0, _toUTC.default)(selected), 'date') : ''),
99
107
  _useState8 = _slicedToArray(_useState7, 2),
100
108
  confirmDate = _useState8[0],
101
109
  setConfirmDate = _useState8[1];
@@ -107,13 +115,24 @@ var DatePickerV2 = function DatePickerV2(_ref) {
107
115
 
108
116
  var _useState11 = (0, _react.useState)(null),
109
117
  _useState12 = _slicedToArray(_useState11, 2),
110
- contentElement = _useState12[0],
111
- setContentElement = _useState12[1];
118
+ accordionCurrentDisplayType = _useState12[0],
119
+ setAccordionCurrentDisplayType = _useState12[1];
112
120
 
113
- var _useState13 = (0, _react.useState)(null),
114
- _useState14 = _slicedToArray(_useState13, 2),
115
- accordionCurrentDisplayType = _useState14[0],
116
- setAccordionCurrentDisplayType = _useState14[1];
121
+ var weeks = (0, _react.useMemo)(function () {
122
+ return ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'].map(function (week) {
123
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(Week, {
124
+ children: week
125
+ }, week);
126
+ });
127
+ }, []);
128
+ var minDateWithTime = (0, _react.useMemo)(function () {
129
+ if (!minDate) return;
130
+ return "".concat(minDate, " 00:00:00");
131
+ }, [minDate]);
132
+ var maxDateWithTime = (0, _react.useMemo)(function () {
133
+ if (!maxDate) return;
134
+ return "".concat(maxDate, " 00:00:00");
135
+ }, [maxDate]);
117
136
 
118
137
  var _useCustomPopper = (0, _hooks.useCustomPopper)(toggleElement, contentElement, {
119
138
  strategy: 'absolute',
@@ -125,14 +144,12 @@ var DatePickerV2 = function DatePickerV2(_ref) {
125
144
  update = _useCustomPopper.update;
126
145
 
127
146
  var context = {
128
- inputValue: inputValue,
147
+ fixedYear: fixedYear,
148
+ minDate: minDateWithTime,
149
+ maxDate: maxDateWithTime,
129
150
  selectedDate: selectedDate,
130
151
  setSelectedDate: setSelectedDate,
131
- minDate: minDate,
132
- maxDate: maxDate,
133
- fixedYear: fixedYear,
134
- setAccordionCurrentDisplayType: setAccordionCurrentDisplayType,
135
- setInputValue: setInputValue
152
+ setAccordionCurrentDisplayType: setAccordionCurrentDisplayType
136
153
  };
137
154
 
138
155
  var handleToggle = function handleToggle() {
@@ -140,49 +157,21 @@ var DatePickerV2 = function DatePickerV2(_ref) {
140
157
  update();
141
158
  };
142
159
 
143
- var _handleDisplayAccordionContent = (0, _react.useCallback)(function (type) {
160
+ var changeDisplayAccordion = (0, _react.useCallback)(function (type) {
144
161
  if (accordionCurrentDisplayType === type) {
145
162
  setAccordionCurrentDisplayType(null);
146
163
  } else {
147
164
  setAccordionCurrentDisplayType(type);
148
165
  }
149
166
  }, [accordionCurrentDisplayType]);
150
-
151
- var handleChangeYear = function handleChangeYear(selected) {
152
- var date = new Date(selectedDate);
153
-
154
- if (selected === 'previous') {
155
- if (date.getFullYear() > 1) {
156
- date.setFullYear(date.getFullYear() - 1);
157
- }
158
- } else if (selected === 'next') {
159
- date.setFullYear(date.getFullYear() + 1);
160
- }
161
-
162
- setSelectedDate((0, _utils.datetimeTFormat)(date));
163
- setAccordionCurrentDisplayType(null);
164
- };
165
-
166
- var handleChangeMonth = function handleChangeMonth(selected) {
167
- var date = new Date(selectedDate);
168
-
169
- if (selected === 'previous') {
170
- date.setMonth(date.getMonth() <= 0 ? 11 : date.getMonth() - 1);
171
- } else if (selected === 'next') {
172
- date.setMonth(date.getMonth() >= 11 ? 0 : date.getMonth() + 1);
167
+ var handleConfirm = (0, _react.useCallback)(function () {
168
+ if (confirmDate) {
169
+ onConfirm(confirmDate);
173
170
  }
174
171
 
175
- setSelectedDate((0, _utils.datetimeTFormat)(date));
176
- setAccordionCurrentDisplayType(null);
177
- };
178
-
179
- var handleConfirm = (0, _react.useCallback)(function () {
180
- if (!confirmDate) return;
181
- setSelectedDate(confirmDate);
182
- onConfirm("".concat(inputValue, " 00:00:00"));
183
172
  setDisplayPicker(false);
184
173
  setAccordionCurrentDisplayType(null);
185
- }, [confirmDate, inputValue, onConfirm]);
174
+ }, [confirmDate, onConfirm]);
186
175
  var handleChangeDate = (0, _react.useCallback)(function (daysOfMonthForSelectedDate, firstWeekOfMonth, dayIndex, day) {
187
176
  var date = new Date(selectedDate); // 先把日期設定成所有月分都有的日期,設定月份時才不會設定到非預期的date
188
177
 
@@ -208,8 +197,6 @@ var DatePickerV2 = function DatePickerV2(_ref) {
208
197
  }
209
198
 
210
199
  date.setDate(day);
211
- setSelectedDate((0, _utils.datetimeTFormat)(date));
212
- setConfirmDate((0, _utils.datetimeTFormat)(date));
213
200
  } else if (fixedYear) {
214
201
  if (dayIndex < firstWeekOfMonth) {
215
202
  if (selectedMonth === 0) {
@@ -226,17 +213,20 @@ var DatePickerV2 = function DatePickerV2(_ref) {
226
213
  }
227
214
 
228
215
  date.setDate(day);
229
- setSelectedDate((0, _utils.datetimeTFormat)(date));
230
- setConfirmDate((0, _utils.datetimeTFormat)(date));
231
216
  }
217
+
218
+ var formattedDate = (0, _utils.formatDate)(date, 'date');
219
+ setSelectedDate("".concat(formattedDate, " ").concat(DEFAULT_TIME));
220
+ setConfirmDate(formattedDate);
232
221
  }, [fixedYear, selectedDate]);
233
- var handleDisabled = (0, _react.useCallback)(function (firstWeekOfMonth, lastWeekOfMonth, daysOfMonthForSelectedDate, dayIndex, day) {
222
+ var handleDisabled = (0, _react.useCallback)(function (firstDayOfMonth, lastDayOfMonth, daysOfMonthForSelectedDate, dayIndex, day) {
234
223
  var _selectedDate$split = selectedDate.split('-'),
235
224
  _selectedDate$split2 = _slicedToArray(_selectedDate$split, 2),
236
225
  year = _selectedDate$split2[0],
237
- month = _selectedDate$split2[1];
226
+ month = _selectedDate$split2[1]; // disabled date before first month of first year
238
227
 
239
- if (year === '0001' && month === '01' && firstWeekOfMonth >= dayIndex + 1) {
228
+
229
+ if (year === '0001' && month === '01' && dayIndex < firstDayOfMonth) {
240
230
  return true;
241
231
  }
242
232
 
@@ -244,56 +234,61 @@ var DatePickerV2 = function DatePickerV2(_ref) {
244
234
  if (myDay.length === 1) myDay = "0".concat(myDay);
245
235
 
246
236
  if (fixedYear) {
247
- if (month === '01' && dayIndex + 1 <= firstWeekOfMonth) {
248
- // disabled date in january
249
- return dayIndex < firstWeekOfMonth;
250
- } else if (month === '12' && day + firstWeekOfMonth < dayIndex + 1) {
237
+ if (month === '01') {
238
+ // disabled date before first month
239
+ return dayIndex < firstDayOfMonth;
240
+ } else if (month === '12') {
251
241
  // disabled date in december
252
- return dayIndex >= daysOfMonthForSelectedDate + firstWeekOfMonth;
242
+ return dayIndex >= daysOfMonthForSelectedDate + firstDayOfMonth;
253
243
  }
254
- }
244
+ } // previous year's date
245
+
246
+
247
+ if (month === '01' && firstDayOfMonth !== 0 && dayIndex + 1 <= firstDayOfMonth) {
248
+ year = +year - 1;
249
+ } // next year's date
255
250
 
256
- if (month === '01' && firstWeekOfMonth !== 0 && dayIndex + 1 <= firstWeekOfMonth) {
257
- year = (+year - 1).toString();
258
- } else if (month === '12' && lastWeekOfMonth !== 6 && day + firstWeekOfMonth < dayIndex + 1) {
259
- year = (+year + 1).toString();
251
+
252
+ if (month === '12' && lastDayOfMonth !== 6 && day + firstDayOfMonth < dayIndex + 1) {
253
+ year = +year + 1;
260
254
  }
261
255
 
262
- month = firstWeekOfMonth >= dayIndex + 1 ? +month - 1 : daysOfMonthForSelectedDate + firstWeekOfMonth < dayIndex + 1 ? +month + 1 : +month;
256
+ month = firstDayOfMonth >= dayIndex + 1 ? +month - 1 : daysOfMonthForSelectedDate + firstDayOfMonth < dayIndex + 1 ? +month + 1 : +month;
263
257
 
264
- if (month === 0) {
258
+ if (month < 1) {
265
259
  month = 12;
266
- } else if (month === 13) {
260
+ } else if (month > 12) {
267
261
  month = 1;
268
262
  }
269
263
 
270
- if (month.toString().length === 1) month = "0".concat(month);else month = month.toString();
264
+ month = month.toString();
265
+
266
+ if (month.length === 1) {
267
+ month = "0".concat(month);
268
+ }
269
+
270
+ year = year.toString();
271
271
  if (year.length === 1) year = "000".concat(year);
272
272
  if (year.length === 2) year = "00".concat(year);
273
273
  if (year.length === 3) year = "0".concat(year);
274
- var compareMinDateDate = (0, _utils.formatDate)((0, _utils.datetimeTFormat)(new Date((0, _GMTDate.default)((0, _utils.formatDate)(new Date("".concat(year, "-").concat(month, "-").concat(myDay))), 'date')).setHours(23, 59, 59, 59)));
275
- var compareMaxDateDate = (0, _utils.formatDate)((0, _utils.datetimeTFormat)(new Date((0, _GMTDate.default)((0, _utils.formatDate)(new Date("".concat(year, "-").concat(month, "-").concat(myDay))), 'date')).setHours(0, 0, 0, 0)));
274
+ var currentDate = "".concat(year, "-").concat(month, "-").concat(myDay, " ").concat(DEFAULT_TIME);
276
275
 
277
- if (minDate && !maxDate && minDate > compareMinDateDate) {
276
+ if (minDateWithTime && currentDate < minDateWithTime) {
278
277
  return true;
279
278
  }
280
279
 
281
- if (maxDate && !minDate && maxDate < compareMaxDateDate) {
282
- return true;
283
- }
284
-
285
- if (maxDate && minDate && (minDate > compareMinDateDate || maxDate < compareMaxDateDate)) {
280
+ if (maxDateWithTime && currentDate > maxDateWithTime) {
286
281
  return true;
287
282
  }
288
283
 
289
284
  return false;
290
- }, [fixedYear, minDate, maxDate, selectedDate]);
291
- var handleSelectedDay = (0, _react.useCallback)(function (day, index, firstWeekOfMonth, lastWeekOfMonth, totalDays) {
285
+ }, [fixedYear, minDateWithTime, maxDateWithTime, selectedDate]);
286
+ var isSelectedDay = (0, _react.useCallback)(function (day, index, firstDayOfMonth, daysOfMonthForSelectedDate) {
292
287
  var selectedDateObj = new Date(selectedDate);
293
- var confirmDateObj = new Date(confirmDate);
288
+ var confirmDateObj = (0, _toUTC.default)(new Date(confirmDate));
294
289
 
295
290
  if (confirmDateObj.getFullYear() === selectedDateObj.getFullYear() && confirmDateObj.getMonth() === selectedDateObj.getMonth() && confirmDateObj.getDate() === day) {
296
- if (index + 1 > firstWeekOfMonth && index < totalDays - (6 - lastWeekOfMonth)) {
291
+ if (index + 1 > firstDayOfMonth && index < daysOfMonthForSelectedDate + firstDayOfMonth) {
297
292
  return true;
298
293
  }
299
294
 
@@ -302,36 +297,35 @@ var DatePickerV2 = function DatePickerV2(_ref) {
302
297
 
303
298
  return false;
304
299
  }, [selectedDate, confirmDate]);
305
- var days = (0, _react.useMemo)(function () {
300
+
301
+ var getLastDateOfMonth = function getLastDateOfMonth(selectedDate) {
306
302
  var date = new Date(selectedDate); // 先把日期設定成所有月分都有的日期,設定月份時才不會設定到非預期的date
307
303
 
308
304
  date.setDate(1);
309
305
  date.setMonth(date.getMonth() + 1);
310
306
  date.setDate(0);
311
- var daysOfMonthForSelectedDate = date.getDate();
312
- date = new Date(selectedDate);
307
+ return date;
308
+ };
309
+
310
+ var days = (0, _react.useMemo)(function () {
311
+ var lastDateOfSelectedDate = getLastDateOfMonth(selectedDate);
312
+ var daysOfMonthForSelectedDate = lastDateOfSelectedDate.getDate();
313
+ var lastDayOfMonth = lastDateOfSelectedDate.getDay();
314
+ var date = new Date(selectedDate);
313
315
  date.setMonth(date.getMonth() + 1 - 1);
314
316
  date.setDate(0);
315
317
  var daysOfPrevioueMonthForSelectedDate = date.getDate();
316
318
  date = new Date(selectedDate); // 先把日期設定成所有月分都有的日期,設定月份時才不會設定到非預期的date
317
319
 
318
320
  date.setDate(1);
319
- var firstWeekOfMonth = date.getDay();
320
- date = new Date(selectedDate); // 先把日期設定成所有月分都有的日期,設定月份時才不會設定到非預期的date
321
-
322
- date.setDate(1);
323
- date.setMonth(date.getMonth() + 1);
324
- date.setDate(0);
325
- var lastWeekOfMonth = date.getDay();
326
- var days = [];
321
+ var firstDayOfMonth = date.getDay();
327
322
 
328
- for (var _i2 = 0, _arr2 = _toConsumableArray(Array(daysOfMonthForSelectedDate).keys()); _i2 < _arr2.length; _i2++) {
329
- var day = _arr2[_i2];
330
- days.push(day + 1);
331
- }
323
+ var days = _toConsumableArray(Array(daysOfMonthForSelectedDate)).map(function (value, index) {
324
+ return index + 1;
325
+ });
332
326
 
333
- if (firstWeekOfMonth !== 0) {
334
- for (var index = daysOfPrevioueMonthForSelectedDate; index > daysOfPrevioueMonthForSelectedDate - firstWeekOfMonth; index -= 1) {
327
+ if (firstDayOfMonth !== 0) {
328
+ for (var index = daysOfPrevioueMonthForSelectedDate; index > daysOfPrevioueMonthForSelectedDate - firstDayOfMonth; index -= 1) {
335
329
  if (date.getFullYear() === 1 && date.getMonth() === 0) {
336
330
  days.unshift(null);
337
331
  } else {
@@ -340,50 +334,50 @@ var DatePickerV2 = function DatePickerV2(_ref) {
340
334
  }
341
335
  }
342
336
 
343
- if (lastWeekOfMonth !== 6) {
344
- for (var _index = 1; _index <= 6 - lastWeekOfMonth; _index += 1) {
337
+ if (lastDayOfMonth !== 6) {
338
+ for (var _index = 1; _index <= 6 - lastDayOfMonth; _index += 1) {
345
339
  days.push(_index);
346
340
  }
347
341
  }
348
342
 
349
- return days.map(function (day, index, arr) {
343
+ return days.map(function (day, index) {
350
344
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(Day, {
351
- disabled: handleDisabled(firstWeekOfMonth, lastWeekOfMonth, daysOfMonthForSelectedDate, index, day),
345
+ disabled: handleDisabled(firstDayOfMonth, lastDayOfMonth, daysOfMonthForSelectedDate, index, day),
352
346
  onClick: function onClick() {
353
- handleChangeDate(daysOfMonthForSelectedDate, firstWeekOfMonth, index, day);
347
+ handleChangeDate(daysOfMonthForSelectedDate, firstDayOfMonth, index, day);
354
348
  },
355
- selected: handleSelectedDay(day, index, firstWeekOfMonth, lastWeekOfMonth, arr.length, daysOfMonthForSelectedDate),
349
+ selected: isSelectedDay(day, index, firstDayOfMonth, daysOfMonthForSelectedDate),
356
350
  children: day
357
351
  }, index);
358
352
  });
359
- }, [selectedDate, handleChangeDate, handleSelectedDay, handleDisabled]);
360
- var weeks = (0, _react.useMemo)(function () {
361
- return ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'].map(function (week) {
362
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(Week, {
363
- children: week
364
- }, week);
365
- });
366
- }, []);
353
+ }, [selectedDate, handleChangeDate, isSelectedDay, handleDisabled]);
367
354
  (0, _react.useEffect)(function () {
368
- if (!selected) return;
369
- setSelectedDate((0, _utils.datetimeTFormat)(selected));
370
- setConfirmDate((0, _utils.datetimeTFormat)(selected));
355
+ if (selected) {
356
+ var formattedDate = (0, _utils.formatDate)((0, _toUTC.default)(selected), 'date');
357
+ setSelectedDate("".concat(formattedDate, " ").concat(DEFAULT_TIME));
358
+ setConfirmDate(formattedDate);
359
+ } else {
360
+ setConfirmDate('');
361
+ }
371
362
  }, [selected]);
372
- (0, _react.useEffect)(function () {
373
- if (!confirmDate) return;
374
- setInputValue((0, _utils.formatDate)(confirmDate, 'date'));
375
- }, [confirmDate]);
376
363
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_DateTimePickerContext.default.Provider, {
377
364
  value: context,
378
365
  children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactOutsideClickHandler.default, {
379
366
  onOutsideClick: handleConfirm,
380
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(PickerInput, {
381
- disabled: disabled,
382
- ref: setToggleElement,
383
- value: inputValue,
384
- onClick: handleToggle,
385
- readOnly: true
386
- }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(Wrapper, _objectSpread(_objectSpread({}, attributes.popper), {}, {
367
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(Wrapper, {
368
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Input.default, {
369
+ disabled: disabled,
370
+ ref: setToggleElement,
371
+ value: confirmDate,
372
+ onClick: handleToggle,
373
+ readOnly: true
374
+ }), confirmDate && !disabled && allowClear && /*#__PURE__*/(0, _jsxRuntime.jsx)(CloseButton, {
375
+ onClick: function onClick() {
376
+ setConfirmDate('');
377
+ onConfirm('');
378
+ }
379
+ })]
380
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(Picker, _objectSpread(_objectSpread({}, attributes.popper), {}, {
387
381
  style: styles.popper,
388
382
  placement: state && state.placement,
389
383
  ref: setContentElement,
@@ -391,16 +385,14 @@ var DatePickerV2 = function DatePickerV2(_ref) {
391
385
  children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(Body, {
392
386
  accordionCurrentDisplayType: accordionCurrentDisplayType,
393
387
  children: [!fixedYear && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Year.default, {
394
- handleChangeTitle: handleChangeYear,
395
388
  expand: accordionCurrentDisplayType === 'year',
396
389
  handleDisplayAccordionContent: function handleDisplayAccordionContent() {
397
- _handleDisplayAccordionContent('year');
390
+ changeDisplayAccordion('year');
398
391
  }
399
392
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Month.default, {
400
- handleChangeTitle: handleChangeMonth,
401
393
  expand: accordionCurrentDisplayType === 'month',
402
394
  handleDisplayAccordionContent: function handleDisplayAccordionContent() {
403
- _handleDisplayAccordionContent('month');
395
+ changeDisplayAccordion('month');
404
396
  },
405
397
  confirmDate: confirmDate
406
398
  }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(DateContent, {
@@ -419,36 +411,39 @@ var DatePickerV2 = function DatePickerV2(_ref) {
419
411
  });
420
412
  };
421
413
 
422
- var Wrapper = _styledComponents.default.div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n padding-bottom: var(--spacing-s);\n background: var(--color-background1);\n border-radius: var(--border-radius);\n border: var(--border-width) solid var(--border-color);\n box-shadow: var(--box-shadow);\n overflow: hidden;\n width: 286px;\n z-index: 1;\n color: var(--font-on-background);\n\n display: ", ";\n"])), function (_ref2) {
414
+ var Wrapper = _styledComponents.default.div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n position: relative;\n"])));
415
+
416
+ var CloseButton = (0, _styledComponents.default)(_md.MdClose)(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n position: absolute;\n top: 50%;\n transform: translateY(-50%);\n color: var(--font-on-background);\n font-size: var(--font-body1);\n right: var(--spacing-s);\n cursor: pointer;\n"])));
417
+ CloseButton.displayName = 'CloseButton';
418
+
419
+ var Picker = _styledComponents.default.div(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n padding-bottom: var(--spacing-s);\n background: var(--color-background1);\n border-radius: var(--border-radius);\n border: var(--border-width) solid var(--border-color);\n box-shadow: var(--box-shadow);\n overflow: hidden;\n width: 286px;\n z-index: 1;\n color: var(--font-on-background);\n\n display: ", ";\n"])), function (_ref2) {
423
420
  var displayPicker = _ref2.displayPicker;
424
421
  return displayPicker ? 'block' : 'none';
425
422
  });
426
423
 
427
- var Week = _styledComponents.default.div(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n width: calc(100% / 7);\n height: 36px;\n border-radius: var(--border-radius-s);\n line-height: 36px;\n text-align: center;\n"])));
424
+ var Week = _styledComponents.default.div(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n width: calc(100% / 7);\n height: 36px;\n border-radius: var(--border-radius-s);\n line-height: 36px;\n text-align: center;\n"])));
428
425
 
429
- var Body = _styledComponents.default.div(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n ", "\n\n overflow: hidden;\n padding: ", ";\n"])), function (_ref3) {
426
+ var Body = _styledComponents.default.div(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n ", "\n\n overflow: hidden;\n padding: ", ";\n"])), function (_ref3) {
430
427
  var accordionCurrentDisplayType = _ref3.accordionCurrentDisplayType;
431
- return accordionCurrentDisplayType && (0, _styledComponents.css)(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n height: 216px;\n "])));
428
+ return accordionCurrentDisplayType && (0, _styledComponents.css)(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["\n height: 216px;\n "])));
432
429
  }, function (_ref4) {
433
430
  var accordionCurrentDisplayType = _ref4.accordionCurrentDisplayType;
434
431
  return accordionCurrentDisplayType === 'year' ? ' 0 4px var(--spacing-s) var(--spacing-s)' : '0 var(--spacing-s) 0 var(--spacing-s)';
435
432
  });
436
433
 
437
- var Footer = _styledComponents.default.div(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n padding: 0 var(--spacing-s);\n"])));
438
-
439
- var PickerInput = (0, _styledComponents.default)(_Input.default)(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["\n &:disabled {\n cursor: not-allowed;\n opacity: 0.5;\n }\n"])));
434
+ var Footer = _styledComponents.default.div(_templateObject7 || (_templateObject7 = _taggedTemplateLiteral(["\n padding: 0 var(--spacing-s);\n"])));
440
435
 
441
- var Day = _styledComponents.default.button(_templateObject7 || (_templateObject7 = _taggedTemplateLiteral(["\n width: calc(100% / 7);\n height: 36px;\n border-radius: var(--border-radius-s);\n line-height: 36px;\n text-align: center;\n padding: 0;\n border: 0;\n background: var(--color-background1);\n color: var(--font-on-background);\n &:hover {\n background: var(--color-primary);\n }\n\n ", "\n\n ", "\n"])), function (_ref5) {
436
+ var Day = _styledComponents.default.button(_templateObject8 || (_templateObject8 = _taggedTemplateLiteral(["\n width: calc(100% / 7);\n height: 36px;\n border-radius: var(--border-radius-s);\n line-height: 36px;\n text-align: center;\n padding: 0;\n border: 0;\n background: var(--color-background1);\n color: var(--font-on-background);\n &:hover {\n background: var(--color-primary);\n }\n\n ", "\n\n ", "\n"])), function (_ref5) {
442
437
  var selected = _ref5.selected;
443
438
  return selected && 'background: var(--color-hover);';
444
439
  }, function (_ref6) {
445
440
  var disabled = _ref6.disabled;
446
- return disabled && (0, _styledComponents.css)(_templateObject8 || (_templateObject8 = _taggedTemplateLiteral(["\n color: var(--font-on-mute);\n background: none;\n &:hover {\n background: none;\n }\n "])));
441
+ return disabled && (0, _styledComponents.css)(_templateObject9 || (_templateObject9 = _taggedTemplateLiteral(["\n color: var(--font-on-mute);\n background: none;\n &:hover {\n background: none;\n }\n "])));
447
442
  });
448
443
 
449
- var ConfirmButton = (0, _styledComponents.default)(_Button.default)(_templateObject9 || (_templateObject9 = _taggedTemplateLiteral(["\n margin: 16px auto 0;\n"])));
444
+ var ConfirmButton = (0, _styledComponents.default)(_Button.default)(_templateObject10 || (_templateObject10 = _taggedTemplateLiteral(["\n margin: 16px auto 0;\n"])));
450
445
 
451
- var DateContent = _styledComponents.default.div(_templateObject10 || (_templateObject10 = _taggedTemplateLiteral(["\n display: flex;\n flex-wrap: wrap;\n"])));
446
+ var DateContent = _styledComponents.default.div(_templateObject11 || (_templateObject11 = _taggedTemplateLiteral(["\n display: flex;\n flex-wrap: wrap;\n"])));
452
447
 
453
448
  var _default = DatePickerV2;
454
449
  exports.default = _default;
@@ -74,8 +74,8 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
74
74
  var DatetimePickerV2 = function DatetimePickerV2(_ref) {
75
75
  var selected = _ref.selected,
76
76
  fixedYear = _ref.fixedYear,
77
- maxDate = _ref.maxDate,
78
77
  minDate = _ref.minDate,
78
+ maxDate = _ref.maxDate,
79
79
  onConfirm = _ref.onConfirm,
80
80
  disabled = _ref.disabled,
81
81
  onBlur = _ref.onBlur;
@@ -88,30 +88,30 @@ var DatetimePickerV2 = function DatetimePickerV2(_ref) {
88
88
  toggleElement = _useState2[0],
89
89
  setToggleElement = _useState2[1];
90
90
 
91
- var _useState3 = (0, _react.useState)(selected ? (0, _utils.datetimeTFormat)(selected) : ''),
91
+ var _useState3 = (0, _react.useState)(null),
92
92
  _useState4 = _slicedToArray(_useState3, 2),
93
- inputValue = _useState4[0],
94
- setInputValue = _useState4[1];
93
+ contentElement = _useState4[0],
94
+ setContentElement = _useState4[1];
95
95
 
96
- var _useState5 = (0, _react.useState)(selected ? (0, _utils.datetimeTFormat)((0, _GMTDate.default)(selected)) : (0, _utils.datetimeTFormat)((0, _GMTDate.default)(new Date()))),
96
+ var _useState5 = (0, _react.useState)(selected ? (0, _utils.datetimeTFormat)(selected) : ''),
97
97
  _useState6 = _slicedToArray(_useState5, 2),
98
- selectedDate = _useState6[0],
99
- setSelectedDate = _useState6[1];
98
+ inputValue = _useState6[0],
99
+ setInputValue = _useState6[1];
100
100
 
101
- var _useState7 = (0, _react.useState)(selected ? (0, _utils.datetimeTFormat)(selected) : ''),
101
+ var _useState7 = (0, _react.useState)(selected ? (0, _utils.datetimeTFormat)((0, _GMTDate.default)(selected)) : (0, _utils.datetimeTFormat)((0, _GMTDate.default)(new Date()))),
102
102
  _useState8 = _slicedToArray(_useState7, 2),
103
- confirmDate = _useState8[0],
104
- setConfirmDate = _useState8[1];
103
+ selectedDate = _useState8[0],
104
+ setSelectedDate = _useState8[1];
105
105
 
106
- var _useState9 = (0, _react.useState)(false),
106
+ var _useState9 = (0, _react.useState)(selected ? (0, _utils.datetimeTFormat)(selected) : ''),
107
107
  _useState10 = _slicedToArray(_useState9, 2),
108
- displayPicker = _useState10[0],
109
- setDisplayPicker = _useState10[1];
108
+ confirmDate = _useState10[0],
109
+ setConfirmDate = _useState10[1];
110
110
 
111
- var _useState11 = (0, _react.useState)(null),
111
+ var _useState11 = (0, _react.useState)(false),
112
112
  _useState12 = _slicedToArray(_useState11, 2),
113
- contentElement = _useState12[0],
114
- setContentElement = _useState12[1];
113
+ displayPicker = _useState12[0],
114
+ setDisplayPicker = _useState12[1];
115
115
 
116
116
  var _useState13 = (0, _react.useState)(function () {
117
117
  var date = new Date((0, _utils.datetimeTFormat)(selected ? selected : (0, _utils.formatDate)(new Date())));
@@ -137,14 +137,12 @@ var DatetimePickerV2 = function DatetimePickerV2(_ref) {
137
137
  update = _useCustomPopper.update;
138
138
 
139
139
  var context = {
140
- inputValue: inputValue,
141
- selectedDate: selectedDate,
142
- setSelectedDate: setSelectedDate,
140
+ fixedYear: fixedYear,
143
141
  minDate: minDate,
144
142
  maxDate: maxDate,
145
- fixedYear: fixedYear,
146
- setAccordionCurrentDisplayType: setAccordionCurrentDisplayType,
147
- setInputValue: setInputValue
143
+ selectedDate: selectedDate,
144
+ setSelectedDate: setSelectedDate,
145
+ setAccordionCurrentDisplayType: setAccordionCurrentDisplayType
148
146
  };
149
147
 
150
148
  var handleToggle = function handleToggle() {
@@ -164,34 +162,6 @@ var DatetimePickerV2 = function DatetimePickerV2(_ref) {
164
162
  }
165
163
  }, [accordionCurrentDisplayType]);
166
164
 
167
- var handleChangeYear = function handleChangeYear(selected) {
168
- var date = new Date(selectedDate);
169
-
170
- if (selected === 'previous') {
171
- if (date.getFullYear() > 1) {
172
- date.setFullYear(date.getFullYear() - 1);
173
- }
174
- } else if (selected === 'next') {
175
- date.setFullYear(date.getFullYear() + 1);
176
- }
177
-
178
- setSelectedDate((0, _utils.datetimeTFormat)(date));
179
- setAccordionCurrentDisplayType(null);
180
- };
181
-
182
- var handleChangeMonth = function handleChangeMonth(selected) {
183
- var date = new Date(selectedDate);
184
-
185
- if (selected === 'previous') {
186
- date.setMonth(date.getMonth() <= 0 ? 11 : date.getMonth() - 1);
187
- } else if (selected === 'next') {
188
- date.setMonth(date.getMonth() >= 11 ? 0 : date.getMonth() + 1);
189
- }
190
-
191
- setSelectedDate((0, _utils.datetimeTFormat)(date));
192
- setAccordionCurrentDisplayType(null);
193
- };
194
-
195
165
  var handleConfirm = (0, _react.useCallback)(function () {
196
166
  if (!confirmDate) return;
197
167
  setSelectedDate(confirmDate);
@@ -419,13 +389,11 @@ var DatetimePickerV2 = function DatetimePickerV2(_ref) {
419
389
  children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(Body, {
420
390
  accordionCurrentDisplayType: accordionCurrentDisplayType,
421
391
  children: [!fixedYear && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Year.default, {
422
- handleChangeTitle: handleChangeYear,
423
392
  expand: accordionCurrentDisplayType === 'year',
424
393
  handleDisplayAccordionContent: function handleDisplayAccordionContent() {
425
394
  _handleDisplayAccordionContent('year');
426
395
  }
427
396
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Month.default, {
428
- handleChangeTitle: handleChangeMonth,
429
397
  expand: accordionCurrentDisplayType === 'month',
430
398
  handleDisplayAccordionContent: function handleDisplayAccordionContent() {
431
399
  _handleDisplayAccordionContent('month');
@@ -35,8 +35,7 @@ function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(
35
35
 
36
36
  var Month = function Month(_ref) {
37
37
  var expand = _ref.expand,
38
- handleDisplayAccordionContent = _ref.handleDisplayAccordionContent,
39
- handleChangeTitle = _ref.handleChangeTitle;
38
+ handleDisplayAccordionContent = _ref.handleDisplayAccordionContent;
40
39
 
41
40
  var _useContext = (0, _react.useContext)(_DateTimePickerContext.default),
42
41
  selectedDate = _useContext.selectedDate,
@@ -47,14 +46,22 @@ var Month = function Month(_ref) {
47
46
  setAccordionCurrentDisplayType = _useContext.setAccordionCurrentDisplayType;
48
47
 
49
48
  var handleChangeMonth = (0, _react.useCallback)(function (month) {
50
- setSelectedDate(function () {
51
- var date = new Date(selectedDate);
52
- date.setDate(1);
53
- date.setMonth(month);
54
- return (0, _utils.datetimeTFormat)(date);
55
- });
49
+ var date = new Date(selectedDate);
50
+ date.setMonth(month);
51
+ setSelectedDate((0, _utils.datetimeTFormat)(date));
56
52
  setAccordionCurrentDisplayType(null);
57
53
  }, [setAccordionCurrentDisplayType, setSelectedDate, selectedDate]);
54
+
55
+ var changeToPreviousMonth = function changeToPreviousMonth() {
56
+ var date = new Date(selectedDate);
57
+ handleChangeMonth(date.getMonth() <= 0 ? 11 : date.getMonth() - 1);
58
+ };
59
+
60
+ var changeToNextMonth = function changeToNextMonth() {
61
+ var date = new Date(selectedDate);
62
+ handleChangeMonth(date.getMonth() >= 11 ? 0 : date.getMonth() + 1);
63
+ };
64
+
58
65
  var handleMonthItemDisable = (0, _react.useCallback)(function (month) {
59
66
  var minDayDate;
60
67
  var maxDayDate;
@@ -129,17 +136,13 @@ var Month = function Month(_ref) {
129
136
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
130
137
  children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(Header, {
131
138
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(IconButton, {
132
- onClick: function onClick() {
133
- handleChangeTitle('previous');
134
- },
139
+ onClick: changeToPreviousMonth,
135
140
  disabled: handleDisableArrow('previous'),
136
141
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_md.MdArrowBackIosNew, {})
137
142
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
138
143
  children: _constant.MONTH[new Date(selectedDate).getMonth()].text
139
144
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(IconButton, {
140
- onClick: function onClick() {
141
- handleChangeTitle('next');
142
- },
145
+ onClick: changeToNextMonth,
143
146
  disabled: handleDisableArrow('next'),
144
147
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_md.MdArrowForwardIos, {})
145
148
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(IconButton, {
@@ -55,15 +55,14 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
55
55
 
56
56
  var Year = function Year(_ref) {
57
57
  var expand = _ref.expand,
58
- handleDisplayAccordionContent = _ref.handleDisplayAccordionContent,
59
- handleChangeTitle = _ref.handleChangeTitle;
58
+ handleDisplayAccordionContent = _ref.handleDisplayAccordionContent;
60
59
 
61
60
  var _useContext = (0, _react.useContext)(_DateTimePickerContext.default),
62
- selectedDate = _useContext.selectedDate,
63
- setSelectedDate = _useContext.setSelectedDate,
61
+ fixedYear = _useContext.fixedYear,
64
62
  minDate = _useContext.minDate,
65
63
  maxDate = _useContext.maxDate,
66
- fixedYear = _useContext.fixedYear,
64
+ selectedDate = _useContext.selectedDate,
65
+ setSelectedDate = _useContext.setSelectedDate,
67
66
  setAccordionCurrentDisplayType = _useContext.setAccordionCurrentDisplayType;
68
67
 
69
68
  var bodyRef = (0, _react.useRef)(null);
@@ -77,11 +76,22 @@ var Year = function Year(_ref) {
77
76
  var minYear = minDate ? new Date((0, _utils.datetimeTFormat)(minDate)).getFullYear() : 1;
78
77
  var maxYear = maxDate ? new Date((0, _utils.datetimeTFormat)(maxDate)).getFullYear() : null;
79
78
  var handleChangeYear = (0, _react.useCallback)(function (year) {
80
- var data = new Date(selectedDate);
81
- data.setFullYear(year);
82
- setSelectedDate((0, _utils.datetimeTFormat)(data));
79
+ var date = new Date(selectedDate);
80
+ date.setFullYear(year);
81
+ setSelectedDate((0, _utils.datetimeTFormat)(date));
83
82
  setAccordionCurrentDisplayType(null);
84
83
  }, [selectedDate, setAccordionCurrentDisplayType, setSelectedDate]);
84
+ var changeToPreviousYear = (0, _react.useCallback)(function () {
85
+ var date = new Date(selectedDate);
86
+
87
+ if (date.getFullYear() > 1) {
88
+ handleChangeYear(date.getFullYear() - 1);
89
+ }
90
+ }, [selectedDate, handleChangeYear]);
91
+ var changeToNextYear = (0, _react.useCallback)(function () {
92
+ var date = new Date(selectedDate);
93
+ handleChangeYear(date.getFullYear() + 1);
94
+ }, [selectedDate, handleChangeYear]);
85
95
  var handleYearItemDisable = (0, _react.useCallback)(function (year) {
86
96
  if (minDate !== undefined && maxDate !== undefined) {
87
97
  return !(minYear <= year && year <= maxYear);
@@ -182,17 +192,13 @@ var Year = function Year(_ref) {
182
192
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
183
193
  children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(Header, {
184
194
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(IconButton, {
185
- onClick: function onClick() {
186
- handleChangeTitle('previous');
187
- },
195
+ onClick: changeToPreviousYear,
188
196
  disabled: handleDisableArrow('previous'),
189
197
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_md.MdArrowBackIosNew, {})
190
198
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
191
199
  children: new Date(selectedDate).getFullYear()
192
200
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(IconButton, {
193
- onClick: function onClick() {
194
- handleChangeTitle('next');
195
- },
201
+ onClick: changeToNextYear,
196
202
  disabled: handleDisableArrow('next'),
197
203
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_md.MdArrowForwardIos, {})
198
204
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(IconButton, {
@@ -221,12 +227,12 @@ var IconButton = _styledComponents.default.button(_templateObject2 || (_template
221
227
  return right && "\n position: absolute;\n right: 0;\n ".concat(rotate && (0, _styledComponents.css)(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n transform: rotate(180deg);\n "]))), "\n ");
222
228
  });
223
229
 
224
- var Body = _styledComponents.default.div(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n flex-wrap: wrap;\n height: 0;\n width: 100%;\n display: ", ";\n\n ", "\n\n transition: 0.3s;\n"])), function (_ref4) {
230
+ var Body = _styledComponents.default.div(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n flex-wrap: wrap;\n height: 0;\n width: 100%;\n display: ", ";\n transition: 0.3s;\n overflow-y: scroll;\n gap: 12px 0;\n ", "\n\n ", "\n"])), function (_ref4) {
225
231
  var expand = _ref4.expand;
226
232
  return expand ? 'flex' : 'none';
227
- }, function (_ref5) {
233
+ }, _scrollbar.default, function (_ref5) {
228
234
  var fixedYear = _ref5.fixedYear;
229
- return (0, _styledComponents.css)(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["\n min-height: ", "px};\n transition: .3s;\n overflow-y: scroll;\n gap: 12px 0;\n ", "\n "])), fixedYear ? '144' : '192', _scrollbar.default);
235
+ return (0, _styledComponents.css)(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["\n height: ", "px};\n "])), fixedYear ? '144' : '192');
230
236
  });
231
237
 
232
238
  var Item = _styledComponents.default.button(_templateObject7 || (_templateObject7 = _taggedTemplateLiteral(["\n width: calc(100% / 3);\n height: 36px;\n line-height: 36px;\n text-align: center;\n border-radius: var(--border-radius-s);\n padding: 0;\n border: none;\n color: var(--font-on-background);\n background: var(--color-background1);\n\n &:hover {\n ", "\n }\n\n ", "\n\n ", "\n"])), function (_ref6) {
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var toUTC0 = function toUTC0(date) {
9
+ if (!date) return;
10
+ var newDate = new Date(date);
11
+ newDate.setTime(newDate.getTime() + newDate.getTimezoneOffset() * 60 * 1000);
12
+ return newDate;
13
+ };
14
+
15
+ var _default = toUTC0;
16
+ exports.default = _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cashub/ui",
3
- "version": "0.17.12",
3
+ "version": "0.18.1",
4
4
  "private": false,
5
5
  "author": "CASHUB Team",
6
6
  "description": "CASHUB UI components library",