@happeouikit/form-elements 2.1.0 → 2.3.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.3.1
4
+
5
+ - [Fixed] remove role from span, keep role on input only
6
+
7
+ ## 2.3.0
8
+
9
+ - [Added] Typeahead component
10
+
11
+ ## 2.2.1
12
+
13
+ - [Fixed] build dist
14
+
15
+ ## 2.2.0
16
+
17
+ - [Fixed] DatePicker. inability to control component by value prop
18
+ - [Fixed] DatePicker. focus loss on edit
19
+ - [Fixed] DatePicker. selected date highlight in the UI
20
+ - [Fixed] DatePicker. PropTypes
21
+ - [Fixed] DatePicker. disabled `react/jsx-props-no-spreading eslint rule`
22
+
3
23
  ## 2.1.0
4
24
 
5
25
  - [Added] CheckboxGroup component
package/dist/Badge.js CHANGED
@@ -25,7 +25,7 @@ var Badge = function Badge(_ref) {
25
25
 
26
26
  var Wrapper = styled.span.withConfig({
27
27
  displayName: "Badge__Wrapper",
28
- componentId: "sc-xyqvne-0"
28
+ componentId: "xyqvne-0"
29
29
  })(["display:inline-block;background:", ";padding:4px 8px;border-radius:100px;"], function (_ref2) {
30
30
  var color = _ref2.color,
31
31
  isFilled = _ref2.isFilled;
package/dist/Checkbox.js CHANGED
@@ -1,12 +1,11 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
- var _excluded = ["label", "background"];
4
3
 
5
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
4
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
6
5
 
7
6
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
8
7
 
9
- import React from "react";
8
+ import { useRef } from "react";
10
9
  import styled from "styled-components";
11
10
  import PropTypes from "prop-types";
12
11
  import { white, active, gray01, gray06, gray08 } from "@happeouikit/colors";
@@ -18,14 +17,34 @@ import { jsxs as _jsxs } from "react/jsx-runtime";
18
17
  var Checkbox = function Checkbox(_ref) {
19
18
  var label = _ref.label,
20
19
  background = _ref.background,
21
- props = _objectWithoutProperties(_ref, _excluded);
20
+ role = _ref.role,
21
+ rest = _objectWithoutProperties(_ref, ["label", "background", "role"]);
22
+
23
+ var checkboxRef = useRef();
24
+
25
+ var onKeyDown = function onKeyDown(event) {
26
+ if (event.key.match(/enter|spacebar|\W{1}/i)) {
27
+ event.preventDefault();
28
+ checkboxRef.current.checked = !checkboxRef.current.checked;
29
+
30
+ if (typeof rest.onChange === "function") {
31
+ rest.onChange(event);
32
+ }
33
+ }
34
+ };
22
35
 
23
36
  return /*#__PURE__*/_jsxs(CheckboxWrapper, {
24
37
  background: background,
25
- disabled: props.disabled,
38
+ disabled: rest.disabled,
26
39
  children: [/*#__PURE__*/_jsx("input", _objectSpread({
27
- type: "checkbox"
28
- }, props)), /*#__PURE__*/_jsx(StyledCheckbox, _objectSpread(_objectSpread({}, props), {}, {
40
+ ref: checkboxRef,
41
+ type: "checkbox",
42
+ tabIndex: "-1",
43
+ role: role
44
+ }, rest)), /*#__PURE__*/_jsx(StyledCheckbox, _objectSpread({
45
+ onKeyDown: onKeyDown,
46
+ tabIndex: 0
47
+ }, rest, {
29
48
  children: /*#__PURE__*/_jsx(Checkmark, {})
30
49
  })), label && /*#__PURE__*/_jsx(Label, {
31
50
  children: label
@@ -45,16 +64,16 @@ Checkbox.defaultProps = {
45
64
  };
46
65
  var StyledCheckbox = styled.span.withConfig({
47
66
  displayName: "Checkbox__StyledCheckbox",
48
- componentId: "sc-tc08iy-0"
49
- })(["cursor:pointer;position:absolute;height:18px;width:18px;border-radius:3px;background-color:", ";border:2px solid ", ";box-sizing:content-box !important;"], white, gray06);
67
+ componentId: "tc08iy-0"
68
+ })(["cursor:pointer;position:absolute;height:18px;width:18px;border-radius:3px;background-color:", ";border:2px solid ", ";box-sizing:content-box !important;&:focus-visible{outline:0;box-shadow:0 0 0 1px ", ";}"], white, gray06, active);
50
69
  var Checkmark = styled(IconCheck).withConfig({
51
70
  displayName: "Checkbox__Checkmark",
52
- componentId: "sc-tc08iy-1"
71
+ componentId: "tc08iy-1"
53
72
  })(["position:absolute;display:none;fill:", ";width:18px;height:16px;top:50%;transform:translateY(-50%);"], white);
54
73
  var CheckboxWrapper = styled.label.withConfig({
55
74
  displayName: "Checkbox__CheckboxWrapper",
56
- componentId: "sc-tc08iy-2"
57
- })(["display:flex;align-items:center;position:relative;cursor:", ";user-select:none;padding:4px 0;input{display:none;}input:checked + ", "{background:", ";border:", ";}input:checked + ", " > svg{display:block;}input:disabled + ", "{cursor:not-allowed;background:", ";border:2px solid ", ";}input:disabled ~ p{color:", ";}"], function (_ref2) {
75
+ componentId: "tc08iy-2"
76
+ })(["display:flex;align-items:center;position:relative;cursor:", ";user-select:none;padding:4px 0;input{opacity:0;width:0;height:0;}input:checked + ", "{background:", ";border:", ";}input:checked + ", " > svg{display:block;}input:disabled + ", "{cursor:not-allowed;background:", ";border:2px solid ", ";}input:disabled ~ p{color:", ";}"], function (_ref2) {
58
77
  var disabled = _ref2.disabled;
59
78
  return disabled ? "not-allowed" : " pointer";
60
79
  }, StyledCheckbox, function (_ref3) {
@@ -66,6 +85,6 @@ var CheckboxWrapper = styled.label.withConfig({
66
85
  }, StyledCheckbox, StyledCheckbox, gray08, gray08, gray06);
67
86
  var Label = styled(TextZeta).withConfig({
68
87
  displayName: "Checkbox__Label",
69
- componentId: "sc-tc08iy-3"
88
+ componentId: "tc08iy-3"
70
89
  })(["display:inline-block;position:relative;margin-left:30px;color:", ";"], gray01);
71
90
  export default Checkbox;
@@ -1,10 +1,8 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
1
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
2
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
4
- var _excluded = ["label", "locale", "width", "date", "type", "fromMonth", "disabledDays", "value", "pickerRef"],
5
- _excluded2 = ["children"];
3
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
6
4
 
7
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
5
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
8
6
 
9
7
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
10
8
 
@@ -23,15 +21,43 @@ import { margin200, padding300 } from "@happeouikit/layout";
23
21
  import { IconButton, ButtonSecondary } from "@happeouikit/buttons";
24
22
  import { IconChevronLeft, IconChevronRight, IconCalendar, IconCheck } from "@happeouikit/icons";
25
23
  import { radius500, shadow500 } from "@happeouikit/theme";
24
+ import { components } from "react-select";
26
25
  import Dropdown from "./Dropdown"; // CSS
27
26
 
28
27
  import "react-day-picker/lib/style.css";
29
28
  import messages from "./messages";
30
- import { components } from "react-select";
29
+ import { useDevWarningOnce } from "./utils";
31
30
  import { jsx as _jsx } from "react/jsx-runtime";
32
31
  import { jsxs as _jsxs } from "react/jsx-runtime";
33
32
  import { Fragment as _Fragment } from "react/jsx-runtime";
34
33
 
34
+ var formatValue = function formatValue(value, locale) {
35
+ if (!value) return null;
36
+ return moment(value).locale(locale).format("L");
37
+ };
38
+
39
+ var CustomInput = /*#__PURE__*/React.forwardRef(function (props, ref) {
40
+ return /*#__PURE__*/_jsxs("div", {
41
+ style: {
42
+ display: "flex",
43
+ alignItems: "center"
44
+ },
45
+ children: [/*#__PURE__*/_jsx(IconCalendar, {
46
+ style: {
47
+ position: "absolute",
48
+ paddingLeft: "10px",
49
+ fill: gray03,
50
+ height: "20px",
51
+ width: "20px",
52
+ boxSizing: "content-box"
53
+ }
54
+ }), /*#__PURE__*/_jsx("input", _objectSpread({
55
+ "data-testid": "datepicker-input",
56
+ ref: ref
57
+ }, props))]
58
+ });
59
+ });
60
+
35
61
  var DatePicker = function DatePicker(_ref) {
36
62
  var label = _ref.label,
37
63
  locale = _ref.locale,
@@ -42,28 +68,28 @@ var DatePicker = function DatePicker(_ref) {
42
68
  disabledDays = _ref.disabledDays,
43
69
  value = _ref.value,
44
70
  pickerRef = _ref.pickerRef,
45
- props = _objectWithoutProperties(_ref, _excluded);
71
+ props = _objectWithoutProperties(_ref, ["label", "locale", "width", "date", "type", "fromMonth", "disabledDays", "value", "pickerRef"]);
46
72
 
47
73
  var _useState = useState(fromMonth),
48
74
  _useState2 = _slicedToArray(_useState, 2),
49
75
  month = _useState2[0],
50
76
  setMonth = _useState2[1];
51
77
 
78
+ var from = date.from,
79
+ to = date.to;
80
+ var formattedValue = formatValue(value || date[type], locale);
81
+ var isRangeMode = Boolean(from) && Boolean(to);
82
+ 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.");
83
+
52
84
  var onChangeMonthYear = function onChangeMonthYear(_ref2) {
53
85
  var month = _ref2.month,
54
86
  year = _ref2.year;
55
87
  setMonth(new Date(year, month));
56
88
  };
57
89
 
58
- if (!date.to || date.to === "") {
59
- date.to = value || "";
60
- }
61
-
62
- var to = date.to,
63
- from = date.from;
64
90
  return /*#__PURE__*/_jsxs(Wrapper, {
65
91
  width: width,
66
- hasRange: Boolean(from) && Boolean(to),
92
+ hasRange: isRangeMode,
67
93
  children: [label && /*#__PURE__*/_jsx("div", {
68
94
  style: {
69
95
  margin: "4px 0"
@@ -73,30 +99,26 @@ var DatePicker = function DatePicker(_ref) {
73
99
  children: label
74
100
  })
75
101
  }), /*#__PURE__*/_jsx(DayPickerInput, _objectSpread({
76
- component: /*#__PURE__*/React.forwardRef(function (props, ref) {
77
- return /*#__PURE__*/_jsx(CustomInput, _objectSpread({
78
- ref: ref
79
- }, props));
80
- }),
81
- value: date[type] && moment(date[type]).locale(locale).format("L"),
102
+ component: CustomInput,
103
+ value: formattedValue,
82
104
  formatDate: formatDate,
83
105
  parseDate: parseDate,
84
- placeholder: "".concat(formatDate(new Date(), "L", locale)),
106
+ placeholder: formatValue(new Date(), locale),
85
107
  dayPickerProps: {
86
108
  locale: locale,
87
109
  localeUtils: MomentLocaleUtils,
88
110
  className: "Range",
89
- disabledDays: type === "to" && from ? {
111
+ disabledDays: isRangeMode ? {
90
112
  before: from
91
113
  } : disabledDays,
92
114
  modifiers: {
93
115
  before: from,
94
116
  after: to
95
117
  },
96
- selectedDays: [date[type] && new Date(date[type]), {
118
+ selectedDays: isRangeMode ? {
97
119
  from: from,
98
120
  to: to
99
- }],
121
+ } : undefined,
100
122
  navbarElement: /*#__PURE__*/_jsx(CustomNavbar, {
101
123
  onChangeMonthYear: onChangeMonthYear,
102
124
  disabledDays: disabledDays
@@ -116,9 +138,15 @@ DatePicker.defaultProps = {
116
138
  from: "",
117
139
  to: ""
118
140
  },
119
- locale: "en-gb"
141
+ locale: "en-gb",
142
+ label: "",
143
+ width: undefined,
144
+ value: undefined,
145
+ pickerRef: undefined,
146
+ disabledDays: []
120
147
  };
121
148
  DatePicker.propTypes = {
149
+ fromMonth: PropTypes.instanceOf(Date),
122
150
  label: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
123
151
  locale: PropTypes.string,
124
152
  width: PropTypes.string,
@@ -138,13 +166,18 @@ DatePicker.propTypes = {
138
166
  if (typeof from === "undefined" || typeof to === "undefined") {
139
167
  return new Error("Date prop required. Format: { from: Date|number|string, to: Date|number|string }. ");
140
168
  }
169
+
170
+ return null;
141
171
  },
142
172
 
143
173
  /** 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) } */
144
- disabledDays: PropTypes.object,
174
+ disabledDays: PropTypes.oneOfType([PropTypes.object, PropTypes.arrayOf(PropTypes.object)]),
145
175
 
146
176
  /** Can be used to tap a ref to the picker. See Range select code example how to utilise. */
147
- pickerRef: PropTypes.object
177
+ pickerRef: PropTypes.oneOfType([PropTypes.func, // eslint-disable-next-line react/forbid-prop-types
178
+ PropTypes.shape({
179
+ current: PropTypes.any
180
+ })])
148
181
  };
149
182
 
150
183
  var CustomNavbar = function CustomNavbar(_ref3) {
@@ -209,27 +242,6 @@ var CustomNavbar = function CustomNavbar(_ref3) {
209
242
  });
210
243
  };
211
244
 
212
- var CustomInput = /*#__PURE__*/React.forwardRef(function (props, ref) {
213
- return /*#__PURE__*/_jsxs("div", {
214
- style: {
215
- display: "flex",
216
- alignItems: "center"
217
- },
218
- children: [/*#__PURE__*/_jsx(IconCalendar, {
219
- style: {
220
- position: "absolute",
221
- paddingLeft: "10px",
222
- fill: gray03,
223
- height: "20px",
224
- width: "20px",
225
- boxSizing: "content-box"
226
- }
227
- }), /*#__PURE__*/_jsx("input", _objectSpread({
228
- ref: ref
229
- }, props))]
230
- });
231
- });
232
-
233
245
  var MonthPicker = function MonthPicker(_ref4) {
234
246
  var date = _ref4.date,
235
247
  disabledDays = _ref4.disabledDays,
@@ -255,7 +267,7 @@ var MonthPicker = function MonthPicker(_ref4) {
255
267
 
256
268
  var fromYear = before ? new Date(before).getFullYear() + 1 : 1939;
257
269
  var toYear = after ? new Date(after).getFullYear() : new Date(currentYear + 10, 11).getFullYear();
258
- var years = [];
270
+ var years = []; // eslint-disable-next-line no-plusplus
259
271
 
260
272
  for (var i = toYear; i >= fromYear; i--) {
261
273
  years.push({
@@ -271,13 +283,16 @@ var MonthPicker = function MonthPicker(_ref4) {
271
283
 
272
284
  var DropdownYearOption = function DropdownYearOption(_ref6) {
273
285
  var children = _ref6.children,
274
- props = _objectWithoutProperties(_ref6, _excluded2);
286
+ props = _objectWithoutProperties(_ref6, ["children"]);
275
287
 
276
288
  return components.Option && /*#__PURE__*/_jsx("div", {
277
289
  onMouseDown: function onMouseDown(e) {
278
290
  return e.stopPropagation();
279
291
  },
280
- children: /*#__PURE__*/_jsx(components.Option, _objectSpread(_objectSpread({}, props), {}, {
292
+ role: "option",
293
+ "aria-selected": true,
294
+ tabIndex: "0",
295
+ children: /*#__PURE__*/_jsx(components.Option, _objectSpread({}, props, {
281
296
  children: children
282
297
  }))
283
298
  });
@@ -336,23 +351,23 @@ var MonthPicker = function MonthPicker(_ref4) {
336
351
 
337
352
  var YearMonthSelectContainer = styled.div.withConfig({
338
353
  displayName: "DatePicker__YearMonthSelectContainer",
339
- componentId: "sc-ce3xgi-0"
354
+ componentId: "ce3xgi-0"
340
355
  })(["position:absolute;z-index:1;top:0;bottom:0;left:0;right:0;background-color:", ";padding:", ";"], white, padding300);
341
356
  var ActionList = styled.div.withConfig({
342
357
  displayName: "DatePicker__ActionList",
343
- componentId: "sc-ce3xgi-1"
358
+ componentId: "ce3xgi-1"
344
359
  })(["display:flex;align-items:center;justify-content:flex-end;margin-top:", ";"], padding300);
345
360
  var YearSelectContainer = styled.div.withConfig({
346
361
  displayName: "DatePicker__YearSelectContainer",
347
- componentId: "sc-ce3xgi-2"
362
+ componentId: "ce3xgi-2"
348
363
  })(["align-items:center;justify-content:center;margin-bottom:", ";> div{width:100%;}"], margin200);
349
364
  var MonthUl = styled.ul.withConfig({
350
365
  displayName: "DatePicker__MonthUl",
351
- componentId: "sc-ce3xgi-3"
366
+ componentId: "ce3xgi-3"
352
367
  })(["display:grid;grid-template-columns:1fr 1fr 1fr 1fr;grid-gap:8px;width:100%;margin:", " 0 0 0;padding:0;list-style:none;li{width:100%;}"], padding300);
353
368
  var MonthSelectButton2 = styled(ButtonSecondary).withConfig({
354
369
  displayName: "DatePicker__MonthSelectButton2",
355
- componentId: "sc-ce3xgi-4"
370
+ componentId: "ce3xgi-4"
356
371
  })(["padding:8px;", ""], function (_ref7) {
357
372
  var $isActive = _ref7.$isActive;
358
373
  return $isActive && css(["background-color:", ";p{color:", ";font-weight:bold;}"], lighten(active, 0.9), active);
@@ -360,25 +375,25 @@ var MonthSelectButton2 = styled(ButtonSecondary).withConfig({
360
375
  var borderRadius = "100px";
361
376
  var Wrapper = styled.div.withConfig({
362
377
  displayName: "DatePicker__Wrapper",
363
- componentId: "sc-ce3xgi-5"
378
+ componentId: "ce3xgi-5"
364
379
  })(["display:flex;flex-direction:column;width:", ";.DayPickerInput-Overlay{margin-top:8px;box-shadow:", ";border-radius:", ";}.DayPickerInput{.Range{.DayPicker-Day{min-width:21px;:focus{outline:none;}&.DayPicker-Day--selected:not(.DayPicker-Day--before):not(.DayPicker-Day--after){", "}&.DayPicker-Day--selected{background-color:", ";color:", ";}&.DayPicker-Day--before{position:relative;", "}&.DayPicker-Day--after{position:relative;", "}&.DayPicker-Day--today:not(.DayPicker-Day--selected){color:", ";}&.DayPicker-Day--outside{&.DayPicker-Day--before,&.DayPicker-Day--after{color:", ";}}}}input{font-family:", ";width:100%;border-radius:4px;border:solid 1px ", ";box-sizing:border-box;box-shadow:none;font-size:14px;padding:9px 12px 9px 38px;font-weight:normal;font-style:normal;font-stretch:normal;line-height:1.43;letter-spacing:0.3px;color:", ";:hover{border-color:", ";}:active{outline:none;box-shadow:none;border-color:", ";}:focus{outline:none;border-color:", ";}}.DayPicker-wrapper{font-family:", ";color:", ";letter-spacing:-0.3px;font-size:14px;font-weight:normal;}.DayPicker-Week{", " .DayPicker-Day--selected{&:first-child{&.DayPicker-Day--after{::before{content:none;}}}&:last-child{&.DayPicker-Day--before{::before{content:none;}}}}}.DayPicker-Caption{display:none;}}"], function (_ref8) {
365
380
  var width = _ref8.width;
366
381
  return width || "200px";
367
382
  }, shadow500, radius500, function (_ref9) {
368
383
  var hasRange = _ref9.hasRange;
369
- return hasRange && "\n background-color: ".concat(toBgLight(active), ";\n border-radius: 0;\n &:not(.DayPicker-Day--outside) {\n color: ").concat(gray01, ";\n }\n ");
384
+ return hasRange && css(["background-color:", ";border-radius:0;&:not(.DayPicker-Day--outside){color:", ";}"], toBgLight(active), gray01);
370
385
  }, active, white, function (_ref10) {
371
386
  var hasRange = _ref10.hasRange;
372
- return hasRange && "\n ::before {\n content: \"\";\n position: absolute;\n background-color: ".concat(toBgLight(active), ";\n width: 10px;\n height: 35px;\n top: 0;\n right: 0;\n z-index: -1;\n }\n ");
387
+ return hasRange && css(["::before{content:\"\";position:absolute;background-color:", ";width:10px;height:35px;top:0;right:0;z-index:-1;}"], toBgLight(active));
373
388
  }, function (_ref11) {
374
389
  var hasRange = _ref11.hasRange;
375
- return hasRange && "\n ::before {\n content: \"\";\n position: absolute;\n background-color: ".concat(toBgLight(active), ";\n width: 10px;\n height: 35px;\n top: 0;\n left: 0;\n z-index: -1;\n }\n ");
390
+ return hasRange && css(["::before{content:\"\";position:absolute;background-color:", ";width:10px;height:35px;top:0;left:0;z-index:-1;}"], toBgLight(active));
376
391
  }, active, white, sansFamily, gray06, black, gray06, active, active, sansFamily, gray01, function (_ref12) {
377
392
  var hasRange = _ref12.hasRange;
378
- return hasRange && "\n .DayPicker-Day--selected:not(.DayPicker-Day--before):not(.DayPicker-Day--after) {\n &:first-child {\n border-top-left-radius: ".concat(borderRadius, " !important;\n border-bottom-left-radius: ").concat(borderRadius, " !important;\n }\n &:last-child {\n border-top-right-radius: ").concat(borderRadius, " !important;\n border-bottom-right-radius: ").concat(borderRadius, " !important;\n }\n }\n ");
393
+ return hasRange && css([".DayPicker-Day--selected:not(.DayPicker-Day--before):not(.DayPicker-Day--after){&:first-child{border-top-left-radius:", " !important;border-bottom-left-radius:", " !important;}&:last-child{border-top-right-radius:", " !important;border-bottom-right-radius:", " !important;}}"], borderRadius, borderRadius, borderRadius, borderRadius);
379
394
  });
380
395
  var NavBarContainer = styled.div.withConfig({
381
396
  displayName: "DatePicker__NavBarContainer",
382
- componentId: "sc-ce3xgi-6"
397
+ componentId: "ce3xgi-6"
383
398
  })(["display:flex;align-items:center;justify-content:space-between;padding:16px 14px 0px 14px;"]);
384
399
  export default DatePicker;
@@ -1,5 +1,7 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
- import React, { useState } from "react";
2
+
3
+ /* eslint-disable radix */
4
+ import React, { useState, useCallback } from "react";
3
5
  import styled from "styled-components";
4
6
  import moment from "moment";
5
7
  import debounce from "lodash.debounce";
@@ -33,8 +35,8 @@ var DateTimePicker = function DateTimePicker(_ref) {
33
35
 
34
36
  var _useState5 = useState(inputMode),
35
37
  _useState6 = _slicedToArray(_useState5, 2),
36
- mode = _useState6[0],
37
- setMode = _useState6[1];
38
+ selectedMode = _useState6[0],
39
+ setSelectedMode = _useState6[1];
38
40
 
39
41
  var _useState7 = useState(DEFAULT_INPUT_STATE),
40
42
  _useState8 = _slicedToArray(_useState7, 2),
@@ -51,25 +53,11 @@ var DateTimePicker = function DateTimePicker(_ref) {
51
53
  timeValue = _useState12[0],
52
54
  setTimeValue = _useState12[1];
53
55
 
54
- var handleDateSelected = function handleDateSelected(date) {
55
- setSelectedDate(date);
56
- setDateTime();
57
- };
58
-
59
- var handleTimeSelected = function handleTimeSelected(time) {
60
- if (time.length !== 2) {
61
- setTimeInputState("error");
62
- setTimeInputErrorMessage(intl.formatMessage(messages.wrongFormat));
63
- return;
64
- }
65
-
66
- setSelectedTime(time);
67
- setDateTime();
68
- };
69
-
70
- var validateTime = function validateTime(time) {
56
+ var validateTime = useCallback(function (_ref2) {
57
+ var time = _ref2.time,
58
+ mode = _ref2.mode;
71
59
  var hour = parseInt(time[0]);
72
- var minute = parseInt(time[1]);
60
+ var minute = parseInt(time[1]); // eslint-disable-next-line no-restricted-globals
73
61
 
74
62
  if (isNaN(hour) || isNaN(minute)) {
75
63
  setTimeInputState("error");
@@ -77,7 +65,10 @@ var DateTimePicker = function DateTimePicker(_ref) {
77
65
  return false;
78
66
  }
79
67
 
80
- if (mode !== "24h" && hour > 12 || hour > 23 || minute > 59) {
68
+ 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
+ var timeValue = hour < 10 ? "0".concat(hour, ":").concat(time[1]) : "".concat(hour, ":").concat(time[1]);
70
+
71
+ if (!regex.test(timeValue)) {
81
72
  setTimeInputState("error");
82
73
  setTimeInputErrorMessage(intl.formatMessage(messages.invalidTime));
83
74
  return false;
@@ -85,36 +76,20 @@ var DateTimePicker = function DateTimePicker(_ref) {
85
76
 
86
77
  setTimeInputState(DEFAULT_INPUT_STATE);
87
78
  return true;
88
- };
89
-
90
- var onChangeMode = function onChangeMode(_ref2) {
91
- var value = _ref2.value;
92
- setMode(value);
93
- setDateTime();
94
- };
95
-
96
- var handleTimeSelectedDebounced = debounce(handleTimeSelected, 500);
97
-
98
- var onChangeTime = function onChangeTime(event) {
99
- var timeString = event.target.value;
100
- var newTime = timeString;
101
- setTimeInputState(DEFAULT_INPUT_STATE);
102
-
103
- if (timeString.match(TIME_REGEX)) {
104
- newTime = "".concat(timeString.slice(0, 2), ":").concat(timeString.slice(2));
105
- }
106
-
107
- setTimeValue(newTime);
108
- handleTimeSelectedDebounced(newTime.split(":"));
109
- };
110
-
111
- var setDateTime = function setDateTime() {
112
- if (!selectedTime || !mode) return;
113
- if (!validateTime(selectedTime)) return;
114
- if (!selectedDate) return;
115
- var hour = parseInt(selectedTime[0]);
116
- var minute = parseInt(selectedTime[1]);
117
- var selectedDateTime = moment(selectedDate);
79
+ }, [intl]);
80
+ var setDateTime = useCallback(function (_ref3) {
81
+ var date = _ref3.date,
82
+ time = _ref3.time,
83
+ mode = _ref3.mode;
84
+ if (!time || !mode) return;
85
+ if (!validateTime({
86
+ time: time,
87
+ mode: mode
88
+ })) return;
89
+ if (!date) return;
90
+ var hour = parseInt(time[0]);
91
+ var minute = parseInt(time[1]);
92
+ var selectedDateTime = moment(date);
118
93
 
119
94
  if (mode === "am" && hour === 12) {
120
95
  selectedDateTime.hour(0);
@@ -128,8 +103,56 @@ var DateTimePicker = function DateTimePicker(_ref) {
128
103
 
129
104
  selectedDateTime.minute(minute);
130
105
  if (onChange) onChange(selectedDateTime.toDate());
131
- };
106
+ }, [onChange, validateTime]);
107
+ var handleDateSelected = useCallback(function (date) {
108
+ setSelectedDate(date);
109
+ setDateTime({
110
+ date: date,
111
+ time: selectedTime,
112
+ mode: selectedMode
113
+ });
114
+ }, [selectedMode, selectedTime, setDateTime]);
115
+ var handleOnKeyPress = useCallback(function (event) {
116
+ if (event.charCode < 48 || event.charCode > 58) {
117
+ event.preventDefault();
118
+ }
119
+ }, []);
120
+ var handleTimeSelected = useCallback(function (time) {
121
+ if (time.length !== 2) {
122
+ setTimeInputState("error");
123
+ setTimeInputErrorMessage(intl.formatMessage(messages.wrongFormat));
124
+ return;
125
+ }
132
126
 
127
+ setSelectedTime(time);
128
+ setDateTime({
129
+ date: selectedDate,
130
+ time: time,
131
+ mode: selectedMode
132
+ });
133
+ }, [intl, selectedDate, selectedMode, setDateTime]);
134
+ var onChangeMode = useCallback(function (_ref4) {
135
+ var value = _ref4.value;
136
+ setSelectedMode(value);
137
+ setDateTime({
138
+ date: selectedDate,
139
+ time: selectedTime,
140
+ mode: value
141
+ });
142
+ }, [selectedDate, selectedTime, setDateTime]);
143
+ var handleTimeSelectedDebounced = debounce(handleTimeSelected, 500);
144
+ var onChangeTime = useCallback(function (event) {
145
+ var timeString = event.target.value;
146
+ var newTime = timeString;
147
+ setTimeInputState(DEFAULT_INPUT_STATE);
148
+
149
+ if (timeString.match(TIME_REGEX)) {
150
+ newTime = "".concat(timeString.slice(0, 2), ":").concat(timeString.slice(2));
151
+ }
152
+
153
+ setTimeValue(newTime);
154
+ handleTimeSelectedDebounced(newTime.split(":"));
155
+ }, [handleTimeSelectedDebounced]);
133
156
  return /*#__PURE__*/_jsxs(Wrapper, {
134
157
  children: [/*#__PURE__*/_jsx(DatePicker, {
135
158
  width: "100%",
@@ -142,7 +165,8 @@ var DateTimePicker = function DateTimePicker(_ref) {
142
165
  onChange: onChangeTime,
143
166
  state: timeInputState,
144
167
  errorMessage: timeInputErrorMessage,
145
- value: timeValue
168
+ value: timeValue,
169
+ onKeyPress: handleOnKeyPress
146
170
  }), /*#__PURE__*/_jsx("div", {
147
171
  style: {
148
172
  paddingTop: "28px"
@@ -170,14 +194,15 @@ var DateTimePicker = function DateTimePicker(_ref) {
170
194
 
171
195
  var Wrapper = styled.div.withConfig({
172
196
  displayName: "DateTimePicker__Wrapper",
173
- componentId: "sc-sdui13-0"
197
+ componentId: "sdui13-0"
174
198
  })(["display:grid;grid-template-columns:180px 90px 90px;column-gap:8px;"]);
175
199
  DateTimePicker.propTypes = {
176
200
  onChange: PropTypes.func.isRequired,
177
201
  label: PropTypes.string,
178
- mode: PropTypes.oneOf(["am", "pm", "24h"])
202
+ inputMode: PropTypes.oneOf(["am", "pm", "24h"])
179
203
  };
180
204
  DateTimePicker.defaultProps = {
181
- inputMode: "am"
205
+ inputMode: "am",
206
+ label: undefined
182
207
  };
183
208
  export default DateTimePicker;
package/dist/Dropdown.js CHANGED
@@ -1,8 +1,7 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
- var _excluded = ["label"];
4
3
 
5
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
4
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
6
5
 
7
6
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
8
7
 
@@ -18,7 +17,7 @@ import { jsxs as _jsxs } from "react/jsx-runtime";
18
17
 
19
18
  var Dropdown = function Dropdown(_ref, ref) {
20
19
  var label = _ref.label,
21
- props = _objectWithoutProperties(_ref, _excluded);
20
+ props = _objectWithoutProperties(_ref, ["label"]);
22
21
 
23
22
  var dropdownRef = useRef();
24
23
  useImperativeHandle(ref, function () {
@@ -47,7 +46,7 @@ var Dropdown = function Dropdown(_ref, ref) {
47
46
  };
48
47
 
49
48
  var DropdownIndicator = function DropdownIndicator(props) {
50
- return components.DropdownIndicator && /*#__PURE__*/_jsx(components.DropdownIndicator, _objectSpread(_objectSpread({}, props), {}, {
49
+ return components.DropdownIndicator && /*#__PURE__*/_jsx(components.DropdownIndicator, _objectSpread({}, props, {
51
50
  children: /*#__PURE__*/_jsx(IconArrowDropDown, {
52
51
  width: "24px",
53
52
  height: "24px",
@@ -62,10 +61,10 @@ export var dropdownStyles = css(["min-width:200px;width:auto;font-family:", ";le
62
61
  });
63
62
  var StyledDropdown = styled(Select).withConfig({
64
63
  displayName: "Dropdown__StyledDropdown",
65
- componentId: "sc-pcee56-0"
64
+ componentId: "pcee56-0"
66
65
  })(["", ""], dropdownStyles);
67
66
  var Label = styled.div.withConfig({
68
67
  displayName: "Dropdown__Label",
69
- componentId: "sc-pcee56-1"
68
+ componentId: "pcee56-1"
70
69
  })(["margin:4px 0;"]);
71
70
  export default /*#__PURE__*/forwardRef(Dropdown);