@happeouikit/form-elements 2.3.21 → 2.3.22

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.3.22
4
+
5
+ - [Fixed] input
6
+
3
7
  ## 2.3.21
4
8
 
5
9
  - [Added] support for indeterminate state of checkbox
package/dist/Badge.js CHANGED
@@ -4,13 +4,12 @@ import styled from "styled-components";
4
4
  import { TinyText } from "@happeouikit/typography";
5
5
  import { toBgLight, active, white } from "@happeouikit/colors";
6
6
  import { jsx as _jsx } from "react/jsx-runtime";
7
-
8
7
  var Badge = function Badge(_ref) {
9
8
  var text = _ref.text,
10
- isFilled = _ref.isFilled,
11
- _ref$color = _ref.color,
12
- color = _ref$color === void 0 ? active : _ref$color,
13
- applyCustomStylings = _ref.applyCustomStylings;
9
+ isFilled = _ref.isFilled,
10
+ _ref$color = _ref.color,
11
+ color = _ref$color === void 0 ? active : _ref$color,
12
+ applyCustomStylings = _ref.applyCustomStylings;
14
13
  return /*#__PURE__*/_jsx(Wrapper, {
15
14
  color: color,
16
15
  isFilled: isFilled,
@@ -22,13 +21,12 @@ var Badge = function Badge(_ref) {
22
21
  })
23
22
  });
24
23
  };
25
-
26
24
  var Wrapper = styled.span.withConfig({
27
25
  displayName: "Badge__Wrapper",
28
26
  componentId: "sc-xyqvne-0"
29
27
  })(["display:inline-block;background:", ";padding:4px 8px;border-radius:100px;"], function (_ref2) {
30
28
  var color = _ref2.color,
31
- isFilled = _ref2.isFilled;
29
+ isFilled = _ref2.isFilled;
32
30
  return isFilled ? color : toBgLight(color);
33
31
  });
34
32
  Badge.propTypes = {
package/dist/Checkbox.js CHANGED
@@ -1,11 +1,8 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
3
  var _excluded = ["label", "background", "role", "indeterminate"];
4
-
5
4
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
6
-
7
5
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
8
-
9
6
  import { useRef } from "react";
10
7
  import styled from "styled-components";
11
8
  import PropTypes from "prop-types";
@@ -14,27 +11,22 @@ import { TextZeta } from "@happeouikit/typography";
14
11
  import { IconCheck, IconRemove } from "@happeouikit/icons";
15
12
  import { jsx as _jsx } from "react/jsx-runtime";
16
13
  import { jsxs as _jsxs } from "react/jsx-runtime";
17
-
18
14
  var Checkbox = function Checkbox(_ref) {
19
15
  var label = _ref.label,
20
- background = _ref.background,
21
- role = _ref.role,
22
- indeterminate = _ref.indeterminate,
23
- rest = _objectWithoutProperties(_ref, _excluded);
24
-
16
+ background = _ref.background,
17
+ role = _ref.role,
18
+ indeterminate = _ref.indeterminate,
19
+ rest = _objectWithoutProperties(_ref, _excluded);
25
20
  var checkboxRef = useRef();
26
-
27
21
  var onKeyDown = function onKeyDown(event) {
28
22
  if (event.key.match(/enter|spacebar|\W{1}/i)) {
29
23
  event.preventDefault();
30
24
  checkboxRef.current.checked = !checkboxRef.current.checked;
31
-
32
25
  if (typeof rest.onChange === "function") {
33
26
  rest.onChange(event);
34
27
  }
35
28
  }
36
29
  };
37
-
38
30
  return /*#__PURE__*/_jsxs(CheckboxWrapper, {
39
31
  background: background,
40
32
  disabled: rest.disabled,
@@ -58,7 +50,6 @@ var Checkbox = function Checkbox(_ref) {
58
50
  })]
59
51
  });
60
52
  };
61
-
62
53
  Checkbox.propTypes = {
63
54
  label: PropTypes.node,
64
55
  checked: PropTypes.bool,
@@ -5,7 +5,6 @@ import PropTypes from "prop-types";
5
5
  import Checkbox from "./Checkbox";
6
6
  import { devWarning, getValidChildrenArray, isString, useDevWarningOnce } from "./utils";
7
7
  import { jsx as _jsx } from "react/jsx-runtime";
8
-
9
8
  var getOptions = function getOptions(options) {
10
9
  return options.map(function (option) {
11
10
  return isString(option) ? {
@@ -14,7 +13,6 @@ var getOptions = function getOptions(options) {
14
13
  } : option;
15
14
  });
16
15
  };
17
-
18
16
  var sortValuesByOrderInOptions = function sortValuesByOrderInOptions(options) {
19
17
  return function (a, b) {
20
18
  var indexA = options.findIndex(function (opt) {
@@ -26,14 +24,12 @@ var sortValuesByOrderInOptions = function sortValuesByOrderInOptions(options) {
26
24
  return indexA - indexB;
27
25
  };
28
26
  };
29
-
30
27
  var getOptionsFromChildren = function getOptionsFromChildren(children) {
31
28
  return getValidChildrenArray(children).map(function (_ref) {
32
29
  var option = _ref.props;
33
30
  return option;
34
31
  });
35
32
  };
36
-
37
33
  var getChildrenDefaultValue = function getChildrenDefaultValue(options) {
38
34
  return options.filter(function (_ref2) {
39
35
  var defaultChecked = _ref2.defaultChecked;
@@ -43,19 +39,17 @@ var getChildrenDefaultValue = function getChildrenDefaultValue(options) {
43
39
  return value;
44
40
  });
45
41
  };
46
-
47
42
  var optionsWarning = "[CheckboxGroup] Both the `children` and `options` props have been used.\n The `options` prop will be ignored. To get rid of this warning, remove one of these props.";
48
43
  var defaultValueWarning = "[CheckboxGroup] Both the `defaultChecked` and `defaultValue` props have been used.\n The `defaultValue` prop will be ignored. To get rid of this warning, remove one of these props.";
49
-
50
44
  var CheckboxGroup = function CheckboxGroup(_ref4) {
51
45
  var value = _ref4.value,
52
- disabled = _ref4.disabled,
53
- name = _ref4.name,
54
- children = _ref4.children,
55
- className = _ref4.className,
56
- rawOptions = _ref4.options,
57
- onGroupChange = _ref4.onChange,
58
- groupDefaultValue = _ref4.defaultValue;
46
+ disabled = _ref4.disabled,
47
+ name = _ref4.name,
48
+ children = _ref4.children,
49
+ className = _ref4.className,
50
+ rawOptions = _ref4.options,
51
+ onGroupChange = _ref4.onChange,
52
+ groupDefaultValue = _ref4.defaultValue;
59
53
  useDevWarningOnce(children && rawOptions, optionsWarning);
60
54
  var options = useMemo(function () {
61
55
  return children ? getOptionsFromChildren(children) : getOptions(rawOptions);
@@ -63,45 +57,36 @@ var CheckboxGroup = function CheckboxGroup(_ref4) {
63
57
  var defaultValue = useMemo(function () {
64
58
  var childrenDefaultValue = getChildrenDefaultValue(options);
65
59
  var hasChildrenDefaultValue = Boolean(childrenDefaultValue.length);
66
-
67
60
  if (hasChildrenDefaultValue && groupDefaultValue) {
68
61
  devWarning(defaultValueWarning);
69
62
  }
70
-
71
63
  return hasChildrenDefaultValue ? childrenDefaultValue : groupDefaultValue;
72
64
  }, [options, groupDefaultValue]);
73
-
74
65
  var _useState = useState(value || defaultValue || []),
75
- _useState2 = _slicedToArray(_useState, 2),
76
- groupValue = _useState2[0],
77
- setGroupValue = _useState2[1];
78
-
66
+ _useState2 = _slicedToArray(_useState, 2),
67
+ groupValue = _useState2[0],
68
+ setGroupValue = _useState2[1];
79
69
  useEffect(function () {
80
70
  if (value) {
81
71
  setGroupValue(value);
82
72
  }
83
73
  }, [value]);
84
-
85
74
  var isChecked = function isChecked(optionValue) {
86
75
  return groupValue.includes(optionValue);
87
76
  };
88
-
89
77
  var handleChange = function handleChange(option, event) {
90
78
  if (option.onChange) {
91
79
  option.onChange(event);
92
80
  }
93
-
94
81
  var newValue = event.target.checked ? [].concat(_toConsumableArray(groupValue), [option.value]) : groupValue.filter(function (val) {
95
82
  return val !== option.value;
96
83
  });
97
84
  var newSortedValue = newValue.sort(sortValuesByOrderInOptions(options));
98
85
  setGroupValue(newSortedValue);
99
-
100
86
  if (onGroupChange) {
101
87
  onGroupChange(newSortedValue);
102
88
  }
103
89
  };
104
-
105
90
  return /*#__PURE__*/_jsx("div", {
106
91
  className: className,
107
92
  children: options.map(function (option) {
@@ -117,7 +102,6 @@ var CheckboxGroup = function CheckboxGroup(_ref4) {
117
102
  })
118
103
  });
119
104
  };
120
-
121
105
  var optionPropType = PropTypes.oneOfType([PropTypes.shape({
122
106
  label: PropTypes.string,
123
107
  value: PropTypes.string.isRequired,
@@ -2,12 +2,9 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
3
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
4
4
  var _excluded = ["label", "locale", "width", "date", "type", "fromMonth", "disabledDays", "value", "pickerRef", "inputProps", "dayPickerProps"],
5
- _excluded2 = ["children"];
6
-
5
+ _excluded2 = ["children"];
7
6
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
8
-
9
7
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
10
-
11
8
  import React, { useState, useRef, useMemo } from "react";
12
9
  import PropTypes from "prop-types";
13
10
  import styled, { css } from "styled-components";
@@ -24,20 +21,19 @@ import { IconButton, ButtonSecondary } from "@happeouikit/buttons";
24
21
  import { IconChevronLeft, IconChevronRight, IconCalendar, IconCheck } from "@happeouikit/icons";
25
22
  import { radius500, shadow500 } from "@happeouikit/theme";
26
23
  import { components } from "react-select";
27
- import Dropdown from "./Dropdown"; // CSS
24
+ import Dropdown from "./Dropdown";
28
25
 
26
+ // CSS
29
27
  import "react-day-picker/lib/style.css";
30
28
  import messages from "./messages";
31
29
  import { useDevWarningOnce, uuidv4 } from "./utils";
32
30
  import { jsx as _jsx } from "react/jsx-runtime";
33
31
  import { jsxs as _jsxs } from "react/jsx-runtime";
34
32
  import { Fragment as _Fragment } from "react/jsx-runtime";
35
-
36
33
  var formatValue = function formatValue(value, locale) {
37
34
  if (!value) return null;
38
35
  return moment(value).locale(locale).format("L");
39
36
  };
40
-
41
37
  var CustomInput = /*#__PURE__*/React.forwardRef(function (props, ref) {
42
38
  return /*#__PURE__*/_jsxs("div", {
43
39
  style: {
@@ -59,47 +55,41 @@ var CustomInput = /*#__PURE__*/React.forwardRef(function (props, ref) {
59
55
  }, props))]
60
56
  });
61
57
  });
62
-
63
58
  var DatePicker = function DatePicker(_ref) {
64
59
  var label = _ref.label,
65
- locale = _ref.locale,
66
- width = _ref.width,
67
- date = _ref.date,
68
- type = _ref.type,
69
- fromMonth = _ref.fromMonth,
70
- disabledDays = _ref.disabledDays,
71
- value = _ref.value,
72
- pickerRef = _ref.pickerRef,
73
- _ref$inputProps = _ref.inputProps,
74
- inputProps = _ref$inputProps === void 0 ? {} : _ref$inputProps,
75
- _ref$dayPickerProps = _ref.dayPickerProps,
76
- dayPickerProps = _ref$dayPickerProps === void 0 ? {} : _ref$dayPickerProps,
77
- props = _objectWithoutProperties(_ref, _excluded);
78
-
60
+ locale = _ref.locale,
61
+ width = _ref.width,
62
+ date = _ref.date,
63
+ type = _ref.type,
64
+ fromMonth = _ref.fromMonth,
65
+ disabledDays = _ref.disabledDays,
66
+ value = _ref.value,
67
+ pickerRef = _ref.pickerRef,
68
+ _ref$inputProps = _ref.inputProps,
69
+ inputProps = _ref$inputProps === void 0 ? {} : _ref$inputProps,
70
+ _ref$dayPickerProps = _ref.dayPickerProps,
71
+ dayPickerProps = _ref$dayPickerProps === void 0 ? {} : _ref$dayPickerProps,
72
+ props = _objectWithoutProperties(_ref, _excluded);
79
73
  // Stores the ID of the input field. If "id" isn't provided, it will be generated
80
74
  // to improve accessibility by linking label to the input field.
81
75
  var _useRef = useRef(inputProps.id || uuidv4()),
82
- datePickerId = _useRef.current;
83
-
76
+ datePickerId = _useRef.current;
84
77
  var _useState = useState(fromMonth),
85
- _useState2 = _slicedToArray(_useState, 2),
86
- month = _useState2[0],
87
- setMonth = _useState2[1];
88
-
78
+ _useState2 = _slicedToArray(_useState, 2),
79
+ month = _useState2[0],
80
+ setMonth = _useState2[1];
89
81
  var from = date.from,
90
- to = date.to;
82
+ to = date.to;
91
83
  var localeFormat = moment.localeData(locale).longDateFormat("L");
92
84
  var formattedValue = formatValue(value || date[type], locale);
93
85
  var isRangeMode = Boolean(from) && Boolean(to);
94
86
  var intl = useIntl();
95
87
  useDevWarningOnce(value && date[type], "[DatePicker] Both the `value` and `date` props have been used.\n The `date` prop will be ignored. To get rid of this warning, remove one of these props.");
96
-
97
88
  var onChangeMonthYear = function onChangeMonthYear(_ref2) {
98
89
  var month = _ref2.month,
99
- year = _ref2.year;
90
+ year = _ref2.year;
100
91
  setMonth(new Date(year, month));
101
92
  };
102
-
103
93
  var pickerDisabledDays = useMemo(function () {
104
94
  if (isRangeMode) {
105
95
  if (type === "from") {
@@ -108,13 +98,11 @@ var DatePicker = function DatePicker(_ref) {
108
98
  after: to || disabledDays.after
109
99
  };
110
100
  }
111
-
112
101
  return {
113
102
  before: from || disabledDays.before,
114
103
  after: disabledDays.after
115
104
  };
116
105
  }
117
-
118
106
  return disabledDays;
119
107
  }, [type, isRangeMode, disabledDays, from, to]);
120
108
  return /*#__PURE__*/_jsxs(Wrapper, {
@@ -168,7 +156,6 @@ var DatePicker = function DatePicker(_ref) {
168
156
  }, props), date[type])]
169
157
  });
170
158
  };
171
-
172
159
  DatePicker.defaultProps = {
173
160
  type: "to",
174
161
  fromMonth: new Date() || "",
@@ -188,52 +175,44 @@ DatePicker.propTypes = {
188
175
  label: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
189
176
  locale: PropTypes.string,
190
177
  width: PropTypes.string,
191
-
192
178
  /** Type is used to pick the date[type] value to display. Useful when range with 2 inputs (from & to). */
193
179
  type: PropTypes.oneOf(["from", "to"]),
194
-
195
180
  /** Use either value or date.to properties. If you use value it will overwrite the date.to if it is empty string. */
196
181
  value: PropTypes.instanceOf(Date),
197
-
198
182
  /** Format: { from: Date|number|string, to: Date|number|string } */
199
183
  date: function date(props, propName) {
200
184
  var _props$propName = props[propName],
201
- from = _props$propName.from,
202
- to = _props$propName.to;
203
-
185
+ from = _props$propName.from,
186
+ to = _props$propName.to;
204
187
  if (typeof from === "undefined" || typeof to === "undefined") {
205
188
  return new Error("Date prop required. Format: { from: Date|number|string, to: Date|number|string }. ");
206
189
  }
207
-
208
190
  return null;
209
191
  },
210
-
211
192
  /** Can be used to disable range of dates. Also restricts the year selector. Example: { after: new Date(2025, 0, 0), before: new Date(2020, 0, 0) } */
212
193
  disabledDays: PropTypes.oneOfType([PropTypes.object, PropTypes.arrayOf(PropTypes.object)]),
213
-
214
194
  /** Can be used to tap a ref to the picker. See Range select code example how to utilise. */
215
- pickerRef: PropTypes.oneOfType([PropTypes.func, // eslint-disable-next-line react/forbid-prop-types
195
+ pickerRef: PropTypes.oneOfType([PropTypes.func,
196
+ // eslint-disable-next-line react/forbid-prop-types
216
197
  PropTypes.shape({
217
198
  current: PropTypes.any
218
199
  })])
219
200
  };
220
-
221
201
  var CustomNavbar = function CustomNavbar(_ref3) {
222
202
  var month = _ref3.month,
223
- previousMonth = _ref3.previousMonth,
224
- nextMonth = _ref3.nextMonth,
225
- onPreviousClick = _ref3.onPreviousClick,
226
- onNextClick = _ref3.onNextClick,
227
- onChangeMonthYear = _ref3.onChangeMonthYear,
228
- disabledDays = _ref3.disabledDays;
203
+ previousMonth = _ref3.previousMonth,
204
+ nextMonth = _ref3.nextMonth,
205
+ onPreviousClick = _ref3.onPreviousClick,
206
+ onNextClick = _ref3.onNextClick,
207
+ onChangeMonthYear = _ref3.onChangeMonthYear,
208
+ disabledDays = _ref3.disabledDays;
229
209
  var intl = useIntl();
230
-
231
210
  var _useState3 = useState(false),
232
- _useState4 = _slicedToArray(_useState3, 2),
233
- showYearMonthPicker = _useState4[0],
234
- setShowYearMonthPicker = _useState4[1]; // using toDateString due to previousMonth and nextMonth are at 12:00
235
-
211
+ _useState4 = _slicedToArray(_useState3, 2),
212
+ showYearMonthPicker = _useState4[0],
213
+ setShowYearMonthPicker = _useState4[1];
236
214
 
215
+ // using toDateString due to previousMonth and nextMonth are at 12:00
237
216
  var enabledPreviousArrow = useMemo(function () {
238
217
  return !(disabledDays !== null && disabledDays !== void 0 && disabledDays.before) || new Date(previousMonth.toDateString()) >= moment(disabledDays.before).startOf("month");
239
218
  }, [previousMonth, disabledDays]);
@@ -297,48 +276,40 @@ var CustomNavbar = function CustomNavbar(_ref3) {
297
276
  })]
298
277
  });
299
278
  };
300
-
301
279
  var MonthPicker = function MonthPicker(_ref4) {
302
280
  var date = _ref4.date,
303
- disabledDays = _ref4.disabledDays,
304
- onChange = _ref4.onChange;
281
+ disabledDays = _ref4.disabledDays,
282
+ onChange = _ref4.onChange;
305
283
  var intl = useIntl();
306
-
307
284
  var _useState5 = useState(new Date(date).getMonth()),
308
- _useState6 = _slicedToArray(_useState5, 2),
309
- selectedMonth = _useState6[0],
310
- setSelectedMonth = _useState6[1];
311
-
285
+ _useState6 = _slicedToArray(_useState5, 2),
286
+ selectedMonth = _useState6[0],
287
+ setSelectedMonth = _useState6[1];
312
288
  var _useState7 = useState(new Date(date).getFullYear()),
313
- _useState8 = _slicedToArray(_useState7, 2),
314
- selectedYear = _useState8[0],
315
- setSelectedYear = _useState8[1];
316
-
289
+ _useState8 = _slicedToArray(_useState7, 2),
290
+ selectedYear = _useState8[0],
291
+ setSelectedYear = _useState8[1];
317
292
  var _ref5 = disabledDays || {},
318
- after = _ref5.after,
319
- before = _ref5.before;
320
-
293
+ after = _ref5.after,
294
+ before = _ref5.before;
321
295
  var getYears = function getYears() {
322
296
  var currentYear = new Date().getFullYear();
323
-
324
297
  var _ref6 = disabledDays || {},
325
- after = _ref6.after,
326
- before = _ref6.before;
327
-
298
+ after = _ref6.after,
299
+ before = _ref6.before;
328
300
  var fromYear = before ? new Date(before).getFullYear() : 1939;
329
301
  var toYear = after ? new Date(after).getFullYear() : new Date(currentYear + 10, 11).getFullYear();
330
- var years = []; // eslint-disable-next-line no-plusplus
302
+ var years = [];
331
303
 
304
+ // eslint-disable-next-line no-plusplus
332
305
  for (var i = toYear; i >= fromYear; i--) {
333
306
  years.push({
334
307
  label: i,
335
308
  value: i
336
309
  });
337
310
  }
338
-
339
311
  return years;
340
312
  };
341
-
342
313
  var isDisabledMonth = function isDisabledMonth(month) {
343
314
  var monthDate = moment().set({
344
315
  year: selectedYear,
@@ -346,13 +317,10 @@ var MonthPicker = function MonthPicker(_ref4) {
346
317
  }).startOf("month");
347
318
  return before && monthDate < moment(before).startOf("month") || after && monthDate > moment(after).startOf("month");
348
319
  };
349
-
350
320
  var months = moment.monthsShort();
351
-
352
321
  var DropdownYearOption = function DropdownYearOption(_ref7) {
353
322
  var children = _ref7.children,
354
- props = _objectWithoutProperties(_ref7, _excluded2);
355
-
323
+ props = _objectWithoutProperties(_ref7, _excluded2);
356
324
  return components.Option && /*#__PURE__*/_jsx("div", {
357
325
  onMouseDown: function onMouseDown(e) {
358
326
  return e.stopPropagation();
@@ -365,7 +333,6 @@ var MonthPicker = function MonthPicker(_ref4) {
365
333
  }))
366
334
  });
367
335
  };
368
-
369
336
  return /*#__PURE__*/_jsxs(YearMonthSelectContainer, {
370
337
  children: [/*#__PURE__*/_jsx(YearSelectContainer, {
371
338
  "data-testid": "yearmonth-dropdown-select",
@@ -420,7 +387,6 @@ var MonthPicker = function MonthPicker(_ref4) {
420
387
  })]
421
388
  });
422
389
  };
423
-
424
390
  var YearMonthSelectContainer = styled.div.withConfig({
425
391
  displayName: "DatePicker__YearMonthSelectContainer",
426
392
  componentId: "sc-ce3xgi-0"
@@ -1,5 +1,4 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
-
3
2
  /* eslint-disable radix */
4
3
  import React, { useState, useCallback } from "react";
5
4
  import styled from "styled-components";
@@ -15,72 +14,62 @@ import { jsx as _jsx } from "react/jsx-runtime";
15
14
  import { jsxs as _jsxs } from "react/jsx-runtime";
16
15
  var TIME_REGEX = /^\d{4}$/g;
17
16
  var DEFAULT_INPUT_STATE = "default";
18
-
19
17
  var DateTimePicker = function DateTimePicker(_ref) {
20
18
  var label = _ref.label,
21
- value = _ref.value,
22
- onChange = _ref.onChange,
23
- inputMode = _ref.inputMode;
19
+ value = _ref.value,
20
+ onChange = _ref.onChange,
21
+ inputMode = _ref.inputMode;
24
22
  var intl = useIntl();
25
-
26
23
  var _useState = useState(value),
27
- _useState2 = _slicedToArray(_useState, 2),
28
- selectedDate = _useState2[0],
29
- setSelectedDate = _useState2[1];
30
-
24
+ _useState2 = _slicedToArray(_useState, 2),
25
+ selectedDate = _useState2[0],
26
+ setSelectedDate = _useState2[1];
31
27
  var _useState3 = useState(value),
32
- _useState4 = _slicedToArray(_useState3, 2),
33
- selectedTime = _useState4[0],
34
- setSelectedTime = _useState4[1];
35
-
28
+ _useState4 = _slicedToArray(_useState3, 2),
29
+ selectedTime = _useState4[0],
30
+ setSelectedTime = _useState4[1];
36
31
  var _useState5 = useState(inputMode),
37
- _useState6 = _slicedToArray(_useState5, 2),
38
- selectedMode = _useState6[0],
39
- setSelectedMode = _useState6[1];
40
-
32
+ _useState6 = _slicedToArray(_useState5, 2),
33
+ selectedMode = _useState6[0],
34
+ setSelectedMode = _useState6[1];
41
35
  var _useState7 = useState(DEFAULT_INPUT_STATE),
42
- _useState8 = _slicedToArray(_useState7, 2),
43
- timeInputState = _useState8[0],
44
- setTimeInputState = _useState8[1];
45
-
36
+ _useState8 = _slicedToArray(_useState7, 2),
37
+ timeInputState = _useState8[0],
38
+ setTimeInputState = _useState8[1];
46
39
  var _useState9 = useState(),
47
- _useState10 = _slicedToArray(_useState9, 2),
48
- timeInputErrorMessage = _useState10[0],
49
- setTimeInputErrorMessage = _useState10[1];
50
-
40
+ _useState10 = _slicedToArray(_useState9, 2),
41
+ timeInputErrorMessage = _useState10[0],
42
+ setTimeInputErrorMessage = _useState10[1];
51
43
  var _useState11 = useState(""),
52
- _useState12 = _slicedToArray(_useState11, 2),
53
- timeValue = _useState12[0],
54
- setTimeValue = _useState12[1];
55
-
44
+ _useState12 = _slicedToArray(_useState11, 2),
45
+ timeValue = _useState12[0],
46
+ setTimeValue = _useState12[1];
56
47
  var validateTime = useCallback(function (_ref2) {
57
48
  var time = _ref2.time,
58
- mode = _ref2.mode;
49
+ mode = _ref2.mode;
59
50
  var hour = parseInt(time[0]);
60
- var minute = parseInt(time[1]); // eslint-disable-next-line no-restricted-globals
51
+ var minute = parseInt(time[1]);
61
52
 
53
+ // eslint-disable-next-line no-restricted-globals
62
54
  if (isNaN(hour) || isNaN(minute)) {
63
55
  setTimeInputState("error");
64
56
  setTimeInputErrorMessage(intl.formatMessage(messages.notNumber));
65
57
  return false;
66
58
  }
67
-
68
59
  var regex = new RegExp(mode === "24h" ? "([0-1][0-9]{1}|[2][0-3]{1}):([0-5]{1}[0-9]{1})" : "([0][1-9]|[1][0-2]{1}):([0-5]{1}[0-9]{1})");
69
60
  var timeValue = hour < 10 ? "0".concat(hour, ":").concat(time[1]) : "".concat(hour, ":").concat(time[1]);
70
-
71
61
  if (!regex.test(timeValue)) {
72
62
  setTimeInputState("error");
73
63
  setTimeInputErrorMessage(intl.formatMessage(messages.invalidTime));
74
64
  return false;
75
65
  }
76
-
77
66
  setTimeInputState(DEFAULT_INPUT_STATE);
78
67
  return true;
79
68
  }, [intl]);
80
69
  var setDateTime = useCallback(function (_ref3) {
81
70
  var date = _ref3.date,
82
- time = _ref3.time,
83
- mode = _ref3.mode;
71
+ time = _ref3.time,
72
+ mode = _ref3.mode;
84
73
  if (!time || !mode) return;
85
74
  if (!validateTime({
86
75
  time: time,
@@ -90,7 +79,6 @@ var DateTimePicker = function DateTimePicker(_ref) {
90
79
  var hour = parseInt(time[0]);
91
80
  var minute = parseInt(time[1]);
92
81
  var selectedDateTime = moment(date);
93
-
94
82
  if (mode === "am" && hour === 12) {
95
83
  selectedDateTime.hour(0);
96
84
  } else if (mode === "pm" && hour === 12) {
@@ -100,7 +88,6 @@ var DateTimePicker = function DateTimePicker(_ref) {
100
88
  } else {
101
89
  selectedDateTime.hour(hour);
102
90
  }
103
-
104
91
  selectedDateTime.minute(minute);
105
92
  if (onChange) onChange(selectedDateTime.toDate());
106
93
  }, [onChange, validateTime]);
@@ -123,7 +110,6 @@ var DateTimePicker = function DateTimePicker(_ref) {
123
110
  setTimeInputErrorMessage(intl.formatMessage(messages.wrongFormat));
124
111
  return;
125
112
  }
126
-
127
113
  setSelectedTime(time);
128
114
  setDateTime({
129
115
  date: selectedDate,
@@ -145,11 +131,9 @@ var DateTimePicker = function DateTimePicker(_ref) {
145
131
  var timeString = event.target.value;
146
132
  var newTime = timeString;
147
133
  setTimeInputState(DEFAULT_INPUT_STATE);
148
-
149
134
  if (timeString.match(TIME_REGEX)) {
150
135
  newTime = "".concat(timeString.slice(0, 2), ":").concat(timeString.slice(2));
151
136
  }
152
-
153
137
  setTimeValue(newTime);
154
138
  handleTimeSelectedDebounced(newTime.split(":"));
155
139
  }, [handleTimeSelectedDebounced]);
@@ -191,7 +175,6 @@ var DateTimePicker = function DateTimePicker(_ref) {
191
175
  })]
192
176
  });
193
177
  };
194
-
195
178
  var Wrapper = styled.div.withConfig({
196
179
  displayName: "DateTimePicker__Wrapper",
197
180
  componentId: "sc-sdui13-0"