@cashub/ui 0.48.10 → 0.48.11

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.
@@ -31,7 +31,8 @@ const DatetimePickerV3 = _ref => {
31
31
  onBlur,
32
32
  allowClear = false,
33
33
  shouldCloseOnSelect = true,
34
- placeholderText
34
+ placeholderText,
35
+ allowTimeInputEmpty = false
35
36
  } = _ref;
36
37
  const datepickerRef = (0, _react.useRef)(null);
37
38
  const handleOnBlur = () => {
@@ -64,7 +65,8 @@ const DatetimePickerV3 = _ref => {
64
65
  datePickerProps.showTimeInput = true;
65
66
  datePickerProps.customTimeInput = /*#__PURE__*/(0, _jsxRuntime.jsx)(_TimePickerV.default, {
66
67
  selected: selected,
67
- onSelect: handleSelectTime
68
+ onSelect: handleSelectTime,
69
+ allowEmpty: allowTimeInputEmpty && !selected
68
70
  });
69
71
  }
70
72
  if (onBlur) {
@@ -31,10 +31,16 @@ const HOUR_OPTIONS = (0, _utils.generateRange)(0, 23).map(value => {
31
31
  const MINUTE_SECOND_OPTIONS = (0, _utils.generateRange)(0, 59).map(value => {
32
32
  return (0, _pad.default)(value, LENGTH, PAD_STRING);
33
33
  });
34
+ const EMPTY_TIME = {
35
+ hour: '',
36
+ minute: '',
37
+ second: ''
38
+ };
34
39
  const TimePickerV2 = _ref => {
35
40
  let {
36
41
  selected,
37
- onSelect
42
+ onSelect,
43
+ allowEmpty = false
38
44
  } = _ref;
39
45
  const [display, setDisplay] = (0, _react.useState)(false);
40
46
  const [targetElement, setTargetElement] = (0, _react.useState)(null);
@@ -44,6 +50,9 @@ const TimePickerV2 = _ref => {
44
50
 
45
51
  // use current time when time value is invalid
46
52
  if (isNaN(time)) {
53
+ if (allowEmpty) {
54
+ return EMPTY_TIME;
55
+ }
47
56
  time = new Date();
48
57
  }
49
58
  return {
@@ -71,6 +80,11 @@ const TimePickerV2 = _ref => {
71
80
  });
72
81
  });
73
82
  };
83
+ (0, _react.useEffect)(() => {
84
+ if (allowEmpty && !selected) {
85
+ setTime(EMPTY_TIME);
86
+ }
87
+ }, [allowEmpty, selected]);
74
88
  (0, _react.useEffect)(() => {
75
89
  if (typeof onSelect === 'function' && time.hour && time.minute && time.second) {
76
90
  onSelect("".concat(time.hour, ":").concat(time.minute, ":").concat(time.second));
@@ -84,7 +98,7 @@ const TimePickerV2 = _ref => {
84
98
  childNodes.forEach(panel => {
85
99
  const selectedItem = panel.querySelector('[aria-selected="true"]');
86
100
  if (panel.scrollHeight > panel.clientHeight) {
87
- panel.scrollTop = selectedItem.offsetTop;
101
+ panel.scrollTop = selectedItem ? selectedItem.offsetTop : 0;
88
102
  }
89
103
  });
90
104
  }
@@ -99,7 +113,7 @@ const TimePickerV2 = _ref => {
99
113
  type: "text",
100
114
  readOnly: true,
101
115
  onClick: handleToggle,
102
- value: "".concat(time.hour, ":").concat(time.minute, ":").concat(time.second)
116
+ value: time.hour && time.minute && time.second ? "".concat(time.hour, ":").concat(time.minute, ":").concat(time.second) : ''
103
117
  }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(Panel, _objectSpread(_objectSpread({
104
118
  ref: setPopperElement,
105
119
  $display: display,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cashub/ui",
3
- "version": "0.48.10",
3
+ "version": "0.48.11",
4
4
  "private": false,
5
5
  "author": "CasHUB Team",
6
6
  "description": "CasHUB UI components library",