@semcore/time-picker 4.53.0-prerelease.0 → 4.53.0-prerelease.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.
Files changed (78) hide show
  1. package/lib/cjs/PickerFormat.js +85 -0
  2. package/lib/cjs/PickerFormat.js.map +1 -0
  3. package/lib/cjs/{component/PickerInput/PickerInput.js → PickerInput.js} +108 -89
  4. package/lib/cjs/PickerInput.js.map +1 -0
  5. package/lib/cjs/TimePicker.js +360 -0
  6. package/lib/cjs/TimePicker.js.map +1 -0
  7. package/lib/cjs/index.d.js +2 -0
  8. package/lib/cjs/index.d.js.map +1 -0
  9. package/lib/cjs/index.js +5 -6
  10. package/lib/cjs/index.js.map +1 -1
  11. package/lib/cjs/{component/PickerFormat/picker-format.shadow.css → style/time-picker.shadow.css} +62 -2
  12. package/lib/cjs/translations/__intergalactic-dynamic-locales.js +5 -4
  13. package/lib/cjs/translations/__intergalactic-dynamic-locales.js.map +1 -1
  14. package/lib/es6/PickerFormat.js +79 -0
  15. package/lib/es6/PickerFormat.js.map +1 -0
  16. package/lib/es6/{component/PickerInput/PickerInput.js → PickerInput.js} +106 -90
  17. package/lib/es6/PickerInput.js.map +1 -0
  18. package/lib/es6/TimePicker.js +348 -0
  19. package/lib/es6/TimePicker.js.map +1 -0
  20. package/lib/es6/index.d.js +2 -0
  21. package/lib/es6/index.d.js.map +1 -0
  22. package/lib/es6/index.js +2 -2
  23. package/lib/es6/index.js.map +1 -1
  24. package/lib/{esm/component/PickerFormat/picker-format.shadow.css → es6/style/time-picker.shadow.css} +62 -2
  25. package/lib/es6/translations/__intergalactic-dynamic-locales.js +2 -2
  26. package/lib/es6/translations/__intergalactic-dynamic-locales.js.map +1 -1
  27. package/lib/esm/PickerFormat.mjs +70 -0
  28. package/lib/esm/{component/PickerInput/PickerInput.mjs → PickerInput.mjs} +100 -92
  29. package/lib/esm/TimePicker.mjs +305 -0
  30. package/lib/esm/index.mjs +7 -3
  31. package/lib/{es6/component/PickerFormat/picker-format.shadow.css → esm/style/time-picker.shadow.css} +62 -2
  32. package/lib/esm/translations/__intergalactic-dynamic-locales.mjs +2 -2
  33. package/lib/types/index.d.ts +63 -2
  34. package/package.json +7 -7
  35. package/lib/cjs/component/PickerFormat/PickerFormat.js +0 -93
  36. package/lib/cjs/component/PickerFormat/PickerFormat.js.map +0 -1
  37. package/lib/cjs/component/PickerFormat/PickerFormat.type.js +0 -2
  38. package/lib/cjs/component/PickerFormat/PickerFormat.type.js.map +0 -1
  39. package/lib/cjs/component/PickerInput/PickerInput.js.map +0 -1
  40. package/lib/cjs/component/PickerInput/PickerInput.type.js +0 -2
  41. package/lib/cjs/component/PickerInput/PickerInput.type.js.map +0 -1
  42. package/lib/cjs/component/PickerInput/picker-input.shadow.css +0 -11
  43. package/lib/cjs/component/TimePicker/TimePicker.js +0 -254
  44. package/lib/cjs/component/TimePicker/TimePicker.js.map +0 -1
  45. package/lib/cjs/component/TimePicker/TimePicker.type.js +0 -2
  46. package/lib/cjs/component/TimePicker/TimePicker.type.js.map +0 -1
  47. package/lib/cjs/component/TimePicker/time-picker.shadow.css +0 -34
  48. package/lib/cjs/entity/TimePickerEntity.js +0 -101
  49. package/lib/cjs/entity/TimePickerEntity.js.map +0 -1
  50. package/lib/es6/component/PickerFormat/PickerFormat.js +0 -88
  51. package/lib/es6/component/PickerFormat/PickerFormat.js.map +0 -1
  52. package/lib/es6/component/PickerFormat/PickerFormat.type.js +0 -2
  53. package/lib/es6/component/PickerFormat/PickerFormat.type.js.map +0 -1
  54. package/lib/es6/component/PickerInput/PickerInput.js.map +0 -1
  55. package/lib/es6/component/PickerInput/PickerInput.type.js +0 -2
  56. package/lib/es6/component/PickerInput/PickerInput.type.js.map +0 -1
  57. package/lib/es6/component/PickerInput/picker-input.shadow.css +0 -11
  58. package/lib/es6/component/TimePicker/TimePicker.js +0 -250
  59. package/lib/es6/component/TimePicker/TimePicker.js.map +0 -1
  60. package/lib/es6/component/TimePicker/TimePicker.type.js +0 -2
  61. package/lib/es6/component/TimePicker/TimePicker.type.js.map +0 -1
  62. package/lib/es6/component/TimePicker/time-picker.shadow.css +0 -34
  63. package/lib/es6/entity/TimePickerEntity.js +0 -94
  64. package/lib/es6/entity/TimePickerEntity.js.map +0 -1
  65. package/lib/esm/component/PickerFormat/PickerFormat.mjs +0 -86
  66. package/lib/esm/component/PickerInput/picker-input.shadow.css +0 -11
  67. package/lib/esm/component/TimePicker/TimePicker.mjs +0 -233
  68. package/lib/esm/component/TimePicker/TimePicker.type.mjs +0 -1
  69. package/lib/esm/component/TimePicker/time-picker.shadow.css +0 -34
  70. package/lib/esm/entity/TimePickerEntity.mjs +0 -90
  71. package/lib/types/component/PickerFormat/PickerFormat.d.ts +0 -17
  72. package/lib/types/component/PickerFormat/PickerFormat.type.d.ts +0 -16
  73. package/lib/types/component/PickerInput/PickerInput.d.ts +0 -54
  74. package/lib/types/component/PickerInput/PickerInput.type.d.ts +0 -13
  75. package/lib/types/component/TimePicker/TimePicker.d.ts +0 -3
  76. package/lib/types/component/TimePicker/TimePicker.type.d.ts +0 -50
  77. package/lib/types/entity/TimePickerEntity.d.ts +0 -22
  78. package/lib/types/translations/__intergalactic-dynamic-locales.d.ts +0 -114
@@ -1,90 +1,97 @@
1
1
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
4
  import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
4
5
  import _createClass from "@babel/runtime/helpers/esm/createClass";
5
- import _callSuper from "@babel/runtime/helpers/esm/callSuper";
6
+ import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
6
7
  import _inherits from "@babel/runtime/helpers/esm/inherits";
8
+ import _createSuper from "@babel/runtime/helpers/esm/createSuper";
7
9
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
8
- import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
9
10
  import { sstyled, assignProps, Component } from "@semcore/core";
10
- import { callAllEventHandlers } from "@semcore/core/lib/utils/assignProps";
11
+ import React from "react";
11
12
  import Input from "@semcore/input";
12
13
  import Select from "@semcore/select";
13
- import React from "react";
14
- var _excluded = ["styles", "step", "onSelect", "time", "size", "disabled", "onVisibleChange", "ariaLabel"];
15
- /*!__reshadow-styles__:"./picker-input.shadow.css"*/
16
- var style = (
17
- /*__reshadow_css_start__*/
18
- (sstyled.insert(
19
- /*__inner_css_start__*/
20
- ".___SPickerInput_p1g8c_gg_._size_l_p1g8c_gg_,.___SPickerInput_p1g8c_gg_._size_m_p1g8c_gg_{width:19px;margin:0 var(--intergalactic-spacing-2x, 8px);padding:0}.___SPickerInput_p1g8c_gg_._size_l_p1g8c_gg_{width:21px}",
21
- /*__inner_css_end__*/
22
- "p1g8c_gg_"
23
- ), /*__reshadow_css_end__*/
24
- {
25
- "__SPickerInput": "___SPickerInput_p1g8c_gg_",
26
- "_size_m": "_size_m_p1g8c_gg_",
27
- "_size_l": "_size_l_p1g8c_gg_"
28
- })
29
- );
30
- function getOptions(minMax) {
31
- var step = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 1;
32
- var _minMax = _slicedToArray(minMax, 2), min = _minMax[0], max = _minMax[1];
14
+ import { withLeadingZero, intOrDefault } from "./TimePicker.mjs";
15
+ import { callAllEventHandlers } from "@semcore/utils/lib/assignProps";
16
+ var _excluded = ["styles", "step", "onSelect", "time", "size", "disabled", "onVisibleChange"];
17
+ var MAP_FIELD_TO_TIME = {
18
+ hours: 0,
19
+ minutes: 1
20
+ };
21
+ var MAP_SIZE_SELECT = {
22
+ m: "m",
23
+ l: "l"
24
+ };
25
+ function getOptions(min, max) {
26
+ var step = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : 1;
33
27
  var length = Number(((max + 1 - min) / step).toFixed(0));
34
28
  var options = Array(length).fill("");
35
29
  var numValue = min;
36
- return options.map(function(_i, index) {
30
+ return options.map(function(i, index) {
37
31
  numValue = index === 0 ? numValue : numValue + step;
38
- var value = String(numValue).padStart(2, "0");
32
+ var value = withLeadingZero(String(numValue));
39
33
  return /* @__PURE__ */ React.createElement(Select.Option, {
40
34
  value,
41
35
  key: value
42
36
  }, value);
43
37
  });
44
38
  }
45
- var AbstractPickerInput = /* @__PURE__ */ (function(_Component) {
46
- function AbstractPickerInput2() {
39
+ var defaultPopperOffset = [-8, 4];
40
+ var ItemPicker = /* @__PURE__ */ function(_Component) {
41
+ _inherits(ItemPicker2, _Component);
42
+ var _super = _createSuper(ItemPicker2);
43
+ function ItemPicker2() {
47
44
  var _this;
48
- _classCallCheck(this, AbstractPickerInput2);
45
+ _classCallCheck(this, ItemPicker2);
49
46
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
50
47
  args[_key] = arguments[_key];
51
48
  }
52
- _this = _callSuper(this, AbstractPickerInput2, [].concat(args));
53
- _defineProperty(_this, "state", {
49
+ _this = _super.call.apply(_super, [this].concat(args));
50
+ _defineProperty(_assertThisInitialized(_this), "inputRef", /* @__PURE__ */ React.createRef());
51
+ _defineProperty(_assertThisInitialized(_this), "state", {
54
52
  dirtyValue: void 0,
55
53
  visible: false
56
54
  });
57
- _defineProperty(_this, "inputRef", /* @__PURE__ */ React.createRef());
58
- _defineProperty(_this, "parseValueWithMinMax", function(value) {
59
- var _this$minMax = _slicedToArray(_this.minMax, 2), min = _this$minMax[0], max = _this$minMax[1];
60
- var numberValue = isNaN(Number(value)) ? min : Number(value);
61
- return String(Math.max(min, Math.min(max, numberValue)));
55
+ _defineProperty(_assertThisInitialized(_this), "parseValueWithMinMax", function(value) {
56
+ var _this$minMax = _this.minMax(), _this$minMax2 = _slicedToArray(_this$minMax, 2), min = _this$minMax2[0], max = _this$minMax2[1];
57
+ return String(Math.max(min, Math.min(max, value)));
62
58
  });
63
- _defineProperty(_this, "handleChange", function(value, event) {
59
+ _defineProperty(_assertThisInitialized(_this), "handleChange", function(value, event) {
64
60
  event.stopPropagation();
65
- var inputValue = value.replace(/[^0-9]/g, "");
66
- var numberValue = Number(inputValue);
61
+ var numberValue = intOrDefault(Number(value), NaN);
67
62
  if (!Number.isNaN(numberValue)) {
68
63
  _this.setState({
69
- dirtyValue: inputValue.slice(-2)
64
+ dirtyValue: value.slice(-2)
70
65
  });
71
66
  }
72
67
  });
73
- _defineProperty(_this, "handleBlur", function(event) {
68
+ _defineProperty(_assertThisInitialized(_this), "handleBlur", function(event) {
74
69
  return _this.submitChanges(event);
75
70
  });
76
- _defineProperty(_this, "handleSelect", function(value, event) {
71
+ _defineProperty(_assertThisInitialized(_this), "handleKeyDown", function() {
72
+ });
73
+ _defineProperty(_assertThisInitialized(_this), "handleSelect", function(value, event) {
77
74
  _this.dispatchOnChange(value, event);
78
75
  });
79
- _defineProperty(_this, "handleVisibleChange", function(visible) {
76
+ _defineProperty(_assertThisInitialized(_this), "handleVisibleChange", function(visible) {
80
77
  return _this.setState({
81
78
  visible
82
79
  });
83
80
  });
81
+ _defineProperty(_assertThisInitialized(_this), "getAriaLabel", function() {
82
+ var getI18nText = _this.asProps._getI18nText;
83
+ if (_this.field === "hours") return getI18nText("hours");
84
+ if (_this.field === "minutes") return getI18nText("minutes");
85
+ return void 0;
86
+ });
84
87
  return _this;
85
88
  }
86
- _inherits(AbstractPickerInput2, _Component);
87
- return _createClass(AbstractPickerInput2, [{
89
+ _createClass(ItemPicker2, [{
90
+ key: "minMax",
91
+ value: function minMax() {
92
+ return [];
93
+ }
94
+ }, {
88
95
  key: "dispatchOnChange",
89
96
  value: function dispatchOnChange(value, event) {
90
97
  this.setState({
@@ -106,17 +113,18 @@ var AbstractPickerInput = /* @__PURE__ */ (function(_Component) {
106
113
  value: function render() {
107
114
  var _ref = this.asProps, _ref2;
108
115
  var SPickerInput = Select.Trigger;
109
- var _this$asProps = this.asProps, styles = _this$asProps.styles, step = _this$asProps.step, onSelect = _this$asProps.onSelect, time = _this$asProps.time, size = _this$asProps.size, disabled = _this$asProps.disabled, onVisibleChange = _this$asProps.onVisibleChange, ariaLabel = _this$asProps.ariaLabel, other = _objectWithoutProperties(_this$asProps, _excluded);
116
+ var _this$asProps = this.asProps, styles = _this$asProps.styles, step = _this$asProps.step, onSelect = _this$asProps.onSelect, time = _this$asProps.time, size = _this$asProps.size, disabled = _this$asProps.disabled, onVisibleChange = _this$asProps.onVisibleChange, other = _objectWithoutProperties(_this$asProps, _excluded);
110
117
  var _this$state = this.state, dirtyValue = _this$state.dirtyValue, visible = _this$state.visible;
111
- var value = dirtyValue === void 0 ? time : dirtyValue;
118
+ var timeValue = time[MAP_FIELD_TO_TIME[this.field]];
119
+ var value = dirtyValue === void 0 ? timeValue : dirtyValue;
120
+ var _this$minMax3 = this.minMax(), _this$minMax4 = _slicedToArray(_this$minMax3, 2), min = _this$minMax4[0], max = _this$minMax4[1];
112
121
  return _ref2 = sstyled(styles), /* @__PURE__ */ React.createElement(Select, _ref2.cn("Select", _objectSpread(_objectSpread({}, other), {}, {
113
122
  "interaction": "focus",
114
- "size": size,
123
+ "size": size ? MAP_SIZE_SELECT[size] : false,
115
124
  "onChange": callAllEventHandlers(onSelect, this.handleSelect),
116
125
  "onVisibleChange": callAllEventHandlers(onVisibleChange, this.handleVisibleChange),
117
126
  "visible": visible,
118
- "value": time,
119
- "defaultHighlightedIndex": time ? null : 0
127
+ "value": timeValue
120
128
  })), /* @__PURE__ */ React.createElement(SPickerInput, _ref2.cn("SPickerInput", _objectSpread({}, assignProps({
121
129
  "tag": Input.Value,
122
130
  "ref": this.inputRef,
@@ -125,38 +133,39 @@ var AbstractPickerInput = /* @__PURE__ */ (function(_Component) {
125
133
  "disabled": disabled,
126
134
  "neighborLocation": false,
127
135
  "value": value,
128
- "aria-label": ariaLabel,
136
+ "aria-label": this.getAriaLabel(),
129
137
  "onChange": this.handleChange,
130
138
  "onBlur": this.handleBlur,
131
139
  "onKeyDown": this.handleKeyDown
132
140
  }, _ref)))), /* @__PURE__ */ React.createElement(Select.Menu, {
133
141
  hMax: 180
134
- }, getOptions(this.minMax, step)));
142
+ }, getOptions(min, max, step)));
135
143
  }
136
144
  }]);
137
- })(Component);
138
- _defineProperty(AbstractPickerInput, "style", style);
139
- _defineProperty(AbstractPickerInput, "defaultProps", function(_) {
140
- return {
141
- placeholder: "00",
142
- offset: [-8, 4]
143
- };
145
+ return ItemPicker2;
146
+ }(Component);
147
+ _defineProperty(ItemPicker, "defaultProps", {
148
+ placeholder: "00",
149
+ offset: defaultPopperOffset
144
150
  });
145
- var Hours = /* @__PURE__ */ (function(_AbstractPickerInput2) {
151
+ var Hours = /* @__PURE__ */ function(_ItemPicker) {
152
+ _inherits(Hours2, _ItemPicker);
153
+ var _super2 = _createSuper(Hours2);
146
154
  function Hours2() {
147
155
  var _this2;
148
156
  _classCallCheck(this, Hours2);
149
157
  for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
150
158
  args[_key2] = arguments[_key2];
151
159
  }
152
- _this2 = _callSuper(this, Hours2, [].concat(args));
153
- _defineProperty(_this2, "handleKeyDown", function(event) {
160
+ _this2 = _super2.call.apply(_super2, [this].concat(args));
161
+ _defineProperty(_assertThisInitialized(_this2), "field", "hours");
162
+ _defineProperty(_assertThisInitialized(_this2), "handleKeyDown", function(event) {
154
163
  var currentTarget = event.currentTarget;
155
164
  if (event.key === "Enter") {
156
165
  _this2.submitChanges(event);
157
166
  }
158
167
  if (event.key === "ArrowRight") {
159
- if (currentTarget.selectionStart && currentTarget.selectionStart >= currentTarget.value.length && currentTarget.selectionStart === currentTarget.selectionEnd) {
168
+ if (currentTarget.selectionStart >= currentTarget.value.length && currentTarget.selectionStart === currentTarget.selectionEnd) {
160
169
  event.preventDefault();
161
170
  _this2.focusNext();
162
171
  }
@@ -164,17 +173,15 @@ var Hours = /* @__PURE__ */ (function(_AbstractPickerInput2) {
164
173
  });
165
174
  return _this2;
166
175
  }
167
- _inherits(Hours2, _AbstractPickerInput2);
168
- return _createClass(Hours2, [{
169
- key: "field",
170
- get: function get() {
171
- return "hours";
172
- }
173
- }, {
176
+ _createClass(Hours2, [{
174
177
  key: "minMax",
175
- get: function get() {
178
+ value: function minMax() {
176
179
  var is12Hour = this.asProps.is12Hour;
177
- return is12Hour ? [1, 12] : [0, 23];
180
+ if (is12Hour) {
181
+ return [1, 12];
182
+ } else {
183
+ return [0, 23];
184
+ }
178
185
  }
179
186
  }, {
180
187
  key: "focusNext",
@@ -188,7 +195,7 @@ var Hours = /* @__PURE__ */ (function(_AbstractPickerInput2) {
188
195
  }
189
196
  }, {
190
197
  key: "componentDidUpdate",
191
- value: function componentDidUpdate(_, prevState) {
198
+ value: function componentDidUpdate(_prevProps, prevState) {
192
199
  var dirtyValue = this.state.dirtyValue;
193
200
  if (prevState.dirtyValue === void 0 || dirtyValue === void 0) return;
194
201
  if (prevState.dirtyValue.length === 1 && dirtyValue.length === 2) {
@@ -196,24 +203,29 @@ var Hours = /* @__PURE__ */ (function(_AbstractPickerInput2) {
196
203
  }
197
204
  }
198
205
  }]);
199
- })(AbstractPickerInput);
200
- _defineProperty(Hours, "defaultProps", function(props) {
201
- return _objectSpread(_objectSpread({}, AbstractPickerInput.defaultProps(props)), {}, {
202
- ml: props.size === "l" ? 3 : void 0
206
+ return Hours2;
207
+ }(ItemPicker);
208
+ _defineProperty(Hours, "defaultProps", function(_ref3) {
209
+ var size = _ref3.size;
210
+ return _objectSpread(_objectSpread({}, ItemPicker.defaultProps), {}, {
211
+ ml: size === "l" ? 3 : void 0
203
212
  });
204
213
  });
205
- var Minutes = /* @__PURE__ */ (function(_AbstractPickerInput3) {
214
+ var Minutes = /* @__PURE__ */ function(_ItemPicker2) {
215
+ _inherits(Minutes2, _ItemPicker2);
216
+ var _super3 = _createSuper(Minutes2);
206
217
  function Minutes2() {
207
218
  var _this3;
208
219
  _classCallCheck(this, Minutes2);
209
220
  for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
210
221
  args[_key3] = arguments[_key3];
211
222
  }
212
- _this3 = _callSuper(this, Minutes2, [].concat(args));
213
- _defineProperty(_this3, "handleKeyDown", function(event) {
223
+ _this3 = _super3.call.apply(_super3, [this].concat(args));
224
+ _defineProperty(_assertThisInitialized(_this3), "field", "minutes");
225
+ _defineProperty(_assertThisInitialized(_this3), "handleKeyDown", function(event) {
214
226
  var currentTarget = event.currentTarget;
215
227
  if (event.key === "ArrowLeft") {
216
- if (currentTarget.selectionStart && currentTarget.selectionStart <= 0 && currentTarget.selectionStart === currentTarget.selectionEnd) {
228
+ if (currentTarget.selectionStart <= 0 && currentTarget.selectionStart === currentTarget.selectionEnd) {
217
229
  event.preventDefault();
218
230
  _this3.focusPrev();
219
231
  }
@@ -228,15 +240,9 @@ var Minutes = /* @__PURE__ */ (function(_AbstractPickerInput3) {
228
240
  });
229
241
  return _this3;
230
242
  }
231
- _inherits(Minutes2, _AbstractPickerInput3);
232
- return _createClass(Minutes2, [{
233
- key: "field",
234
- get: function get() {
235
- return "minutes";
236
- }
237
- }, {
243
+ _createClass(Minutes2, [{
238
244
  key: "minMax",
239
- get: function get() {
245
+ value: function minMax() {
240
246
  return [0, 59];
241
247
  }
242
248
  }, {
@@ -250,10 +256,12 @@ var Minutes = /* @__PURE__ */ (function(_AbstractPickerInput3) {
250
256
  }
251
257
  }
252
258
  }]);
253
- })(AbstractPickerInput);
254
- _defineProperty(Minutes, "defaultProps", function(props) {
255
- return _objectSpread(_objectSpread({}, AbstractPickerInput.defaultProps(props)), {}, {
256
- mr: props.size === "l" ? 3 : void 0
259
+ return Minutes2;
260
+ }(ItemPicker);
261
+ _defineProperty(Minutes, "defaultProps", function(_ref4) {
262
+ var size = _ref4.size;
263
+ return _objectSpread(_objectSpread({}, ItemPicker.defaultProps), {}, {
264
+ mr: size === "l" ? 3 : void 0
257
265
  });
258
266
  });
259
267
  export {
@@ -0,0 +1,305 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
4
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
5
+ import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
6
+ import _inherits from "@babel/runtime/helpers/esm/inherits";
7
+ import _createSuper from "@babel/runtime/helpers/esm/createSuper";
8
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
9
+ import { sstyled } from "@semcore/utils/lib/core/index";
10
+ import createComponent, { sstyled as sstyled$1, assignProps, Component } from "@semcore/core";
11
+ import React from "react";
12
+ import Input from "@semcore/input";
13
+ import { Box } from "@semcore/flex-box";
14
+ import { Hours, Minutes } from "./PickerInput.mjs";
15
+ import TimePickerFormat from "./PickerFormat.mjs";
16
+ import { localizedMessages } from "./translations/__intergalactic-dynamic-locales.mjs";
17
+ import i18nEnhance from "@semcore/utils/lib/enhances/i18nEnhance";
18
+ import keyboardFocusEnhance from "@semcore/utils/lib/enhances/keyboardFocusEnhance";
19
+ /*!__reshadow-styles__:"./style/time-picker.shadow.css"*/
20
+ var style = (
21
+ /*__reshadow_css_start__*/
22
+ (sstyled.insert(
23
+ /*__inner_css_start__*/
24
+ ".___STimePicker_kh2hk_gg_{position:relative;width:auto;outline:0}.___STimePicker_kh2hk_gg_.__keyboardFocused_kh2hk_gg_:focus{box-shadow:var(--intergalactic-keyboard-focus, 0px 0px 0px 3px rgba(0, 18, 193, 0.441))}.___STimePicker_kh2hk_gg_.__disabled_kh2hk_gg_{color:var(--intergalactic-text-secondary, rgba(0, 3, 0, 0.583));cursor:default}@supports (color:color(display-p3 0 0 0)){.___STimePicker_kh2hk_gg_.__disabled_kh2hk_gg_{color:var(--intergalactic-text-secondary, rgba(0, 3, 0, 0.583))}@media (color-gamut:p3){.___STimePicker_kh2hk_gg_.__disabled_kh2hk_gg_{color:var(--intergalactic-text-secondary, color(display-p3 0.00228 0.01289 0.00252 / 0.583))}}}.___SPickerInput_kh2hk_gg_{box-sizing:content-box;text-align:center;z-index:1;height:1.5em}.___SPickerInput_kh2hk_gg_.__placeholder_kh2hk_gg_{text-overflow:initial}.___SPickerInput_kh2hk_gg_:focus{background-color:var(--intergalactic-bg-highlight-focus, rgba(0, 31, 207, 0.093))}@supports (color:color(display-p3 0 0 0)){.___SPickerInput_kh2hk_gg_:focus{background-color:var(--intergalactic-bg-highlight-focus, rgba(0, 31, 207, 0.093))}@media (color-gamut:p3){.___SPickerInput_kh2hk_gg_:focus{background-color:var(--intergalactic-bg-highlight-focus, color(display-p3 0.02831 0.11224 0.78317 / 0.093))}}}.___SPickerInput_kh2hk_gg_._size_l_kh2hk_gg_,.___SPickerInput_kh2hk_gg_._size_m_kh2hk_gg_{width:19px;margin:0 var(--intergalactic-spacing-2x, 8px);padding:0}.___SPickerInput_kh2hk_gg_._size_l_kh2hk_gg_{width:21px}.___SPickerFormat_kh2hk_gg_{flex-shrink:0;position:relative;display:inline-flex;padding:0;white-space:nowrap;font-family:inherit;font-weight:var(--intergalactic-medium, 500);line-height:normal;-webkit-text-decoration:none;text-decoration:none;align-items:center;border:1px solid var(--intergalactic-border-primary, rgba(0, 12, 8, 0.161));border-radius:0 var(--intergalactic-control-rounded, 6px) var(--intergalactic-control-rounded, 6px)0;outline:0;box-shadow:none;cursor:pointer;box-sizing:border-box;overflow:visible;-webkit-user-select:none;-moz-user-select:none;user-select:none;touch-action:manipulation;-webkit-tap-highlight-color:transparent;color:var(--intergalactic-text-secondary, rgba(0, 3, 0, 0.583));background-color:var(--intergalactic-bg-secondary-neutral, rgb(248, 249, 248))}@supports (color:color(display-p3 0 0 0)){.___SPickerFormat_kh2hk_gg_{border:1px solid var(--intergalactic-border-primary, rgba(0, 12, 8, 0.161));color:var(--intergalactic-text-secondary, rgba(0, 3, 0, 0.583))}@media (color-gamut:p3){.___SPickerFormat_kh2hk_gg_{border:1px solid var(--intergalactic-border-primary, color(display-p3 0.00798 0.04498 0.03219 / 0.161));color:var(--intergalactic-text-secondary, color(display-p3 0.00228 0.01289 0.00252 / 0.583))}}}@media (hover:hover){.___SPickerFormat_kh2hk_gg_:hover{color:var(--intergalactic-text-secondary, rgba(0, 3, 0, 0.583));background-color:var(--intergalactic-bg-secondary-neutral-hover, rgb(241, 242, 242))}@supports (color:color(display-p3 0 0 0)){.___SPickerFormat_kh2hk_gg_:hover{color:var(--intergalactic-text-secondary, rgba(0, 3, 0, 0.583))}@media (color-gamut:p3){.___SPickerFormat_kh2hk_gg_:hover{color:var(--intergalactic-text-secondary, color(display-p3 0.00228 0.01289 0.00252 / 0.583))}}}}.___SPickerFormat_kh2hk_gg_.__active_kh2hk_gg_,.___SPickerFormat_kh2hk_gg_:active{color:var(--intergalactic-text-secondary, rgba(0, 3, 0, 0.583));background-color:var(--intergalactic-bg-secondary-neutral-active, rgb(234, 235, 235))}@supports (color:color(display-p3 0 0 0)){.___SPickerFormat_kh2hk_gg_.__active_kh2hk_gg_,.___SPickerFormat_kh2hk_gg_:active{color:var(--intergalactic-text-secondary, rgba(0, 3, 0, 0.583))}@media (color-gamut:p3){.___SPickerFormat_kh2hk_gg_.__active_kh2hk_gg_,.___SPickerFormat_kh2hk_gg_:active{color:var(--intergalactic-text-secondary, color(display-p3 0.00228 0.01289 0.00252 / 0.583))}}}.___SPickerFormat_kh2hk_gg_:focus,.___SPickerFormat_kh2hk_gg_:focus-visible{outline:0}.___SPickerFormat_kh2hk_gg_._size_m_kh2hk_gg_{height:var(--intergalactic-form-control-m, 28px);font-size:var(--intergalactic-fs-200, 14px);margin:0-1px 0 0}.___SPickerFormat_kh2hk_gg_._size_m_kh2hk_gg_ .___SPickerFormatText_kh2hk_gg_{margin:0 var(--intergalactic-spacing-2x, 8px)}.___SPickerFormat_kh2hk_gg_._size_l_kh2hk_gg_{height:var(--intergalactic-form-control-l, 40px);font-size:var(--intergalactic-fs-300, 16px);margin:0 calc(-1*var(--intergalactic-spacing-1x, 4px))0 0}.___SPickerFormat_kh2hk_gg_._size_l_kh2hk_gg_ .___SPickerFormatText_kh2hk_gg_{margin:0 var(--intergalactic-spacing-3x, 12px)}.___SPickerFormat_kh2hk_gg_.__disabled_kh2hk_gg_{opacity:var(--intergalactic-disabled-opacity, 0.4);cursor:default;pointer-events:none;border-color:transparent transparent transparent var(--intergalactic-border-primary, rgba(0, 12, 8, 0.161))}@supports (color:color(display-p3 0 0 0)){.___SPickerFormat_kh2hk_gg_.__disabled_kh2hk_gg_{border-color:transparent transparent transparent var(--intergalactic-border-primary, rgba(0, 12, 8, 0.161))}@media (color-gamut:p3){.___SPickerFormat_kh2hk_gg_.__disabled_kh2hk_gg_{border-color:transparent transparent transparent var(--intergalactic-border-primary, color(display-p3 0.00798 0.04498 0.03219 / 0.161))}}}.___SPickerFormat_kh2hk_gg_.__keyboardFocused_kh2hk_gg_{box-shadow:var(--intergalactic-keyboard-focus, 0px 0px 0px 3px rgba(0, 18, 193, 0.441))}.___STimePickerSeparator_kh2hk_gg_{color:var(--intergalactic-text-primary, rgba(1, 5, 0, 0.899))}.___STimePickerSeparator_kh2hk_gg_.__disabled_kh2hk_gg_{opacity:var(--intergalactic-disabled-opacity, 0.4);pointer-events:none}",
25
+ /*__inner_css_end__*/
26
+ "kh2hk_gg_"
27
+ ), /*__reshadow_css_end__*/
28
+ {
29
+ "__STimePicker": "___STimePicker_kh2hk_gg_",
30
+ "_keyboardFocused": "__keyboardFocused_kh2hk_gg_",
31
+ "_disabled": "__disabled_kh2hk_gg_",
32
+ "__SPickerInput": "___SPickerInput_kh2hk_gg_",
33
+ "_size_m": "_size_m_kh2hk_gg_",
34
+ "_size_l": "_size_l_kh2hk_gg_",
35
+ "__SPickerFormat": "___SPickerFormat_kh2hk_gg_",
36
+ "__STimePickerSeparator": "___STimePickerSeparator_kh2hk_gg_",
37
+ "_placeholder": "__placeholder_kh2hk_gg_",
38
+ "_active": "__active_kh2hk_gg_",
39
+ "__SPickerFormatText": "___SPickerFormatText_kh2hk_gg_"
40
+ })
41
+ );
42
+ var MAP_MERIDIEM = {
43
+ AM: "PM",
44
+ PM: "AM"
45
+ };
46
+ var MAP_FIELD_TO_TIME = {
47
+ hours: 0,
48
+ minutes: 1
49
+ };
50
+ function intOrDefault(value) {
51
+ var def = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 0;
52
+ var number = Number.parseInt(value);
53
+ return Number.isNaN(number) ? def : number;
54
+ }
55
+ function withLeadingZero(value) {
56
+ value = String(value);
57
+ if (value.length === 1) return "0".concat(value);
58
+ return String(value);
59
+ }
60
+ function meridiemByHours(hours) {
61
+ return hours >= 12 ? "PM" : "AM";
62
+ }
63
+ function formatHoursTo12(hours) {
64
+ var nHours = intOrDefault(hours, NaN);
65
+ if (Number.isNaN(nHours)) return hours;
66
+ if (nHours === 0) return 12;
67
+ if (nHours > 12) return nHours - 12;
68
+ return hours;
69
+ }
70
+ function formatHoursTo24(hours, meridiem) {
71
+ var nHours = intOrDefault(hours, NaN);
72
+ if (Number.isNaN(nHours)) return hours;
73
+ if (meridiem === "AM") {
74
+ if (nHours === 12) return 0;
75
+ }
76
+ if (meridiem === "PM") {
77
+ if (nHours < 12) return nHours + 12;
78
+ }
79
+ return hours;
80
+ }
81
+ var TimePickerRoot = /* @__PURE__ */ function(_Component) {
82
+ _inherits(TimePickerRoot2, _Component);
83
+ var _super = _createSuper(TimePickerRoot2);
84
+ function TimePickerRoot2() {
85
+ var _this;
86
+ _classCallCheck(this, TimePickerRoot2);
87
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
88
+ args[_key] = arguments[_key];
89
+ }
90
+ _this = _super.call.apply(_super, [this].concat(args));
91
+ _defineProperty(_assertThisInitialized(_this), "hoursInputRef", /* @__PURE__ */ React.createRef());
92
+ _defineProperty(_assertThisInitialized(_this), "minutesInputRef", /* @__PURE__ */ React.createRef());
93
+ _defineProperty(_assertThisInitialized(_this), "_lastMeridiem", "AM");
94
+ _defineProperty(_assertThisInitialized(_this), "handleValueChange", function(value, field, event) {
95
+ var is12Hour = _this.asProps.is12Hour;
96
+ var _assertThisInitialize = _assertThisInitialized(_this), meridiem = _assertThisInitialize.meridiem;
97
+ var time;
98
+ if (field) {
99
+ time = _this.value.split(":");
100
+ time[MAP_FIELD_TO_TIME[field]] = value;
101
+ } else {
102
+ time = value.split(":");
103
+ }
104
+ var _time = time, _time2 = _slicedToArray(_time, 2), _time2$ = _time2[0], hours = _time2$ === void 0 ? "" : _time2$, _time2$2 = _time2[1], minutes = _time2$2 === void 0 ? "" : _time2$2;
105
+ if (is12Hour) hours = String(formatHoursTo12(hours));
106
+ value = _this.timeToValue([hours, minutes], meridiem);
107
+ _this.handlers.value(value, event);
108
+ });
109
+ _defineProperty(_assertThisInitialized(_this), "handleMeridiemClick", function(event) {
110
+ var is12Hour = _this.asProps.is12Hour;
111
+ var _assertThisInitialize2 = _assertThisInitialized(_this), value = _assertThisInitialize2.value, meridiem = _assertThisInitialize2.meridiem;
112
+ var _value$split = value.split(":"), _value$split2 = _slicedToArray(_value$split, 2), _value$split2$ = _value$split2[0], hours = _value$split2$ === void 0 ? "" : _value$split2$, _value$split2$2 = _value$split2[1], minutes = _value$split2$2 === void 0 ? "" : _value$split2$2;
113
+ if (is12Hour) hours = String(formatHoursTo12(hours));
114
+ value = _this.timeToValue([hours, minutes], MAP_MERIDIEM[meridiem]);
115
+ _this.handlers.value(value, event);
116
+ });
117
+ _defineProperty(_assertThisInitialized(_this), "_getHoursAndMinutesProps", function() {
118
+ var _this$asProps = _this.asProps, is12Hour = _this$asProps.is12Hour, size = _this$asProps.size, disabled = _this$asProps.disabled, getI18nText = _this$asProps.getI18nText;
119
+ var time = _this.valueToTime(_this.value);
120
+ return {
121
+ time,
122
+ size,
123
+ is12Hour,
124
+ disabled,
125
+ $onValueChange: _this.handleValueChange,
126
+ minutesInputRef: _this.minutesInputRef,
127
+ hoursInputRef: _this.hoursInputRef,
128
+ _getI18nText: getI18nText
129
+ };
130
+ });
131
+ _defineProperty(_assertThisInitialized(_this), "getHoursProps", function() {
132
+ return _objectSpread(_objectSpread({}, _this._getHoursAndMinutesProps()), {}, {
133
+ ref: _this.hoursInputRef
134
+ });
135
+ });
136
+ _defineProperty(_assertThisInitialized(_this), "getMinutesProps", function() {
137
+ return _objectSpread(_objectSpread({}, _this._getHoursAndMinutesProps()), {}, {
138
+ ref: _this.minutesInputRef
139
+ });
140
+ });
141
+ return _this;
142
+ }
143
+ _createClass(TimePickerRoot2, [{
144
+ key: "uncontrolledProps",
145
+ value: (
146
+ // default AM
147
+ function uncontrolledProps() {
148
+ return {
149
+ value: null,
150
+ title: null
151
+ };
152
+ }
153
+ )
154
+ }, {
155
+ key: "componentDidMount",
156
+ value: function componentDidMount() {
157
+ var _document$querySelect;
158
+ var _this$asProps2 = this.asProps, id = _this$asProps2.id, ariaDescribedBy = _this$asProps2["aria-describedby"];
159
+ var selector = "[for=".concat(id, "]");
160
+ var titleElement = (_document$querySelect = document.querySelector(selector)) !== null && _document$querySelect !== void 0 ? _document$querySelect : document.querySelector("#".concat(ariaDescribedBy));
161
+ if (titleElement) {
162
+ this.handlers.title(titleElement.textContent);
163
+ }
164
+ }
165
+ }, {
166
+ key: "value",
167
+ get: function get() {
168
+ var value = this.asProps.value;
169
+ return value === null || value === void 0 ? ":" : value;
170
+ }
171
+ }, {
172
+ key: "meridiem",
173
+ get: function get() {
174
+ var value = this.asProps.value;
175
+ var _value$split3 = value.split(":"), _value$split4 = _slicedToArray(_value$split3, 1), _value$split4$ = _value$split4[0], hours = _value$split4$ === void 0 ? "" : _value$split4$;
176
+ var nHours = intOrDefault(hours, NaN);
177
+ if (!Number.isNaN(nHours)) {
178
+ this._lastMeridiem = meridiemByHours(nHours);
179
+ }
180
+ return this._lastMeridiem;
181
+ }
182
+ }, {
183
+ key: "valueToTime",
184
+ value: function valueToTime(value) {
185
+ var is12Hour = this.asProps.is12Hour;
186
+ var _value$split5 = value.split(":"), _value$split6 = _slicedToArray(_value$split5, 2), _value$split6$ = _value$split6[0], hours = _value$split6$ === void 0 ? "" : _value$split6$, _value$split6$2 = _value$split6[1], minutes = _value$split6$2 === void 0 ? "" : _value$split6$2;
187
+ if (is12Hour) hours = formatHoursTo12(hours);
188
+ hours = withLeadingZero(hours);
189
+ minutes = withLeadingZero(minutes);
190
+ return [hours, minutes];
191
+ }
192
+ }, {
193
+ key: "timeToValue",
194
+ value: function timeToValue(time, meridiem) {
195
+ var is12Hour = this.asProps.is12Hour;
196
+ var _time3 = _slicedToArray(time, 2), _time3$ = _time3[0], hours = _time3$ === void 0 ? "" : _time3$, _time3$2 = _time3[1], minutes = _time3$2 === void 0 ? "" : _time3$2;
197
+ hours = intOrDefault(hours, hours);
198
+ minutes = intOrDefault(minutes, minutes);
199
+ if (is12Hour) hours = formatHoursTo24(hours, meridiem);
200
+ return "".concat(hours, ":").concat(minutes);
201
+ }
202
+ }, {
203
+ key: "getSeparatorProps",
204
+ value: function getSeparatorProps() {
205
+ return {
206
+ disabled: this.asProps.disabled,
207
+ hoursInputRef: this.hoursInputRef
208
+ };
209
+ }
210
+ }, {
211
+ key: "getFormatProps",
212
+ value: function getFormatProps() {
213
+ var _this$asProps3 = this.asProps, size = _this$asProps3.size, disabled = _this$asProps3.disabled, disablePortal = _this$asProps3.disablePortal, getI18nText = _this$asProps3.getI18nText;
214
+ return {
215
+ size,
216
+ disabled,
217
+ disablePortal,
218
+ meridiem: this.meridiem,
219
+ onClick: this.handleMeridiemClick,
220
+ getI18nText
221
+ };
222
+ }
223
+ }, {
224
+ key: "render",
225
+ value: function render() {
226
+ var _ref = this.asProps, _ref3;
227
+ var STimePicker = Input;
228
+ var _this$asProps4 = this.asProps, styles = _this$asProps4.styles, Children = _this$asProps4.Children, value = _this$asProps4.value, is12Hour = _this$asProps4.is12Hour, getI18nText = _this$asProps4.getI18nText, title = _this$asProps4.title;
229
+ var _this$valueToTime = this.valueToTime(this.value), _this$valueToTime2 = _slicedToArray(_this$valueToTime, 2), hours = _this$valueToTime2[0], minutes = _this$valueToTime2[1];
230
+ var label = value ? "".concat(title, " ").concat(getI18nText("title", {
231
+ time: "".concat(hours, ":").concat(withLeadingZero(minutes)),
232
+ meridiem: is12Hour ? this.meridiem : ""
233
+ })) : "".concat(title, " ").concat(getI18nText("titleEmpty"));
234
+ return _ref3 = sstyled$1(styles), /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(STimePicker, _ref3.cn("STimePicker", _objectSpread({}, assignProps({
235
+ "role": "group",
236
+ "aria-label": label,
237
+ "__excludeProps": ["value", "title"]
238
+ }, _ref))), /* @__PURE__ */ React.createElement(Children, _ref3.cn("Children", {}))));
239
+ }
240
+ }]);
241
+ return TimePickerRoot2;
242
+ }(Component);
243
+ _defineProperty(TimePickerRoot, "displayName", "TimePicker");
244
+ _defineProperty(TimePickerRoot, "style", style);
245
+ _defineProperty(TimePickerRoot, "enhance", [i18nEnhance(localizedMessages), keyboardFocusEnhance()]);
246
+ _defineProperty(TimePickerRoot, "defaultProps", function(_ref5) {
247
+ var is12Hour = _ref5.is12Hour;
248
+ return {
249
+ defaultValue: "",
250
+ size: "m",
251
+ children: /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(TimePicker.Hours, null), /* @__PURE__ */ React.createElement(TimePicker.Separator, null), /* @__PURE__ */ React.createElement(TimePicker.Minutes, null), is12Hour && /* @__PURE__ */ React.createElement(TimePicker.Format, null)),
252
+ i18n: localizedMessages,
253
+ locale: "en",
254
+ defaultTitle: ""
255
+ };
256
+ });
257
+ var Separator = /* @__PURE__ */ function(_Component2) {
258
+ _inherits(Separator2, _Component2);
259
+ var _super2 = _createSuper(Separator2);
260
+ function Separator2() {
261
+ var _this2;
262
+ _classCallCheck(this, Separator2);
263
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
264
+ args[_key2] = arguments[_key2];
265
+ }
266
+ _this2 = _super2.call.apply(_super2, [this].concat(args));
267
+ _defineProperty(_assertThisInitialized(_this2), "handlerClick", function() {
268
+ if (_this2.asProps.hoursInputRef.current) {
269
+ var _this2$asProps$hoursI;
270
+ (_this2$asProps$hoursI = _this2.asProps.hoursInputRef.current) === null || _this2$asProps$hoursI === void 0 ? void 0 : _this2$asProps$hoursI.focus();
271
+ }
272
+ });
273
+ return _this2;
274
+ }
275
+ _createClass(Separator2, [{
276
+ key: "render",
277
+ value: function render() {
278
+ var _ref2 = this.asProps, _ref4;
279
+ var STimePickerSeparator = Box;
280
+ var styles = this.asProps.styles;
281
+ return _ref4 = sstyled$1(styles), /* @__PURE__ */ React.createElement(STimePickerSeparator, _ref4.cn("STimePickerSeparator", _objectSpread({}, assignProps({
282
+ "onClick": this.handlerClick,
283
+ "aria-hidden": "true"
284
+ }, _ref2))));
285
+ }
286
+ }]);
287
+ return Separator2;
288
+ }(Component);
289
+ _defineProperty(Separator, "defaultProps", {
290
+ children: ":"
291
+ });
292
+ var TimePicker = createComponent(TimePickerRoot, {
293
+ Hours,
294
+ Minutes,
295
+ Separator,
296
+ Format: TimePickerFormat
297
+ });
298
+ export {
299
+ TimePicker as default,
300
+ formatHoursTo12,
301
+ formatHoursTo24,
302
+ intOrDefault,
303
+ meridiemByHours,
304
+ withLeadingZero
305
+ };
package/lib/esm/index.mjs CHANGED
@@ -1,5 +1,9 @@
1
- import { default as default2 } from "./component/TimePicker/TimePicker.mjs";
2
- import "./component/TimePicker/TimePicker.type.mjs";
1
+ import { default as default2, formatHoursTo12, formatHoursTo24, intOrDefault, meridiemByHours, withLeadingZero } from "./TimePicker.mjs";
3
2
  export {
4
- default2 as default
3
+ default2 as default,
4
+ formatHoursTo12,
5
+ formatHoursTo24,
6
+ intOrDefault,
7
+ meridiemByHours,
8
+ withLeadingZero
5
9
  };