@happeouikit/form-elements 2.2.0 → 2.3.4
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 +16 -0
- package/dist/Badge.js +1 -1
- package/dist/Checkbox.js +32 -13
- package/dist/DatePicker.js +92 -64
- package/dist/DateTimePicker.js +82 -57
- package/dist/Dropdown.js +5 -6
- package/dist/Input.js +19 -12
- package/dist/Link.js +6 -6
- package/dist/RadioButton.js +2 -3
- package/dist/Switch.js +4 -5
- package/dist/Tag.js +3 -4
- package/dist/Textarea.js +2 -3
- package/dist/Typeahead/Typeahead.js +234 -0
- package/dist/Typeahead/TypeaheadDropdown.js +27 -0
- package/dist/Typeahead/TypeaheadError.js +16 -0
- package/dist/Typeahead/TypeaheadList.js +37 -0
- package/dist/Typeahead/TypeaheadLoading.js +26 -0
- package/dist/Typeahead/TypeaheadMessage.js +41 -0
- package/dist/Typeahead/TypeaheadNoResults.js +19 -0
- package/dist/Typeahead/messages.js +29 -0
- package/dist/index.js +2 -1
- package/dist/utils.js +10 -1
- package/package.json +4 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 2.3.4
|
|
4
|
+
|
|
5
|
+
- [Fixed] DatePicker. Added htmlFor to the label and input ID autogeneration. Accessibility issue.
|
|
6
|
+
|
|
7
|
+
## 2.3.1
|
|
8
|
+
|
|
9
|
+
- [Fixed] remove role from span, keep role on input only
|
|
10
|
+
|
|
11
|
+
## 2.3.0
|
|
12
|
+
|
|
13
|
+
- [Added] Typeahead component
|
|
14
|
+
|
|
15
|
+
## 2.2.1
|
|
16
|
+
|
|
17
|
+
- [Fixed] build dist
|
|
18
|
+
|
|
3
19
|
## 2.2.0
|
|
4
20
|
|
|
5
21
|
- [Fixed] DatePicker. inability to control component by value prop
|
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: "
|
|
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)
|
|
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
|
|
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
|
-
|
|
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:
|
|
38
|
+
disabled: rest.disabled,
|
|
26
39
|
children: [/*#__PURE__*/_jsx("input", _objectSpread({
|
|
27
|
-
|
|
28
|
-
|
|
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: "
|
|
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: "
|
|
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: "
|
|
57
|
-
})(["display:flex;align-items:center;position:relative;cursor:", ";user-select:none;padding:4px 0;input{
|
|
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: "
|
|
88
|
+
componentId: "tc08iy-3"
|
|
70
89
|
})(["display:inline-block;position:relative;margin-left:30px;color:", ";"], gray01);
|
|
71
90
|
export default Checkbox;
|
package/dist/DatePicker.js
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
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
|
-
|
|
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)
|
|
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
|
|
|
11
|
-
import React, { useState } from "react";
|
|
9
|
+
import React, { useState, useRef } from "react";
|
|
12
10
|
import PropTypes from "prop-types";
|
|
13
11
|
import styled, { css } from "styled-components";
|
|
14
12
|
import DayPickerInput from "react-day-picker/DayPickerInput";
|
|
@@ -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 {
|
|
29
|
+
import { useDevWarningOnce, uuidv4 } 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,61 +68,67 @@ var DatePicker = function DatePicker(_ref) {
|
|
|
42
68
|
disabledDays = _ref.disabledDays,
|
|
43
69
|
value = _ref.value,
|
|
44
70
|
pickerRef = _ref.pickerRef,
|
|
45
|
-
|
|
71
|
+
_ref$inputProps = _ref.inputProps,
|
|
72
|
+
inputProps = _ref$inputProps === void 0 ? {} : _ref$inputProps,
|
|
73
|
+
props = _objectWithoutProperties(_ref, ["label", "locale", "width", "date", "type", "fromMonth", "disabledDays", "value", "pickerRef", "inputProps"]);
|
|
74
|
+
|
|
75
|
+
// Stores the ID of the input field. If "id" isn't provided, it will be generated
|
|
76
|
+
// to improve accessibility by linking label to the input field.
|
|
77
|
+
var _useRef = useRef(inputProps.id || uuidv4()),
|
|
78
|
+
datePickerId = _useRef.current;
|
|
46
79
|
|
|
47
80
|
var _useState = useState(fromMonth),
|
|
48
81
|
_useState2 = _slicedToArray(_useState, 2),
|
|
49
82
|
month = _useState2[0],
|
|
50
83
|
setMonth = _useState2[1];
|
|
51
84
|
|
|
85
|
+
var from = date.from,
|
|
86
|
+
to = date.to;
|
|
87
|
+
var formattedValue = formatValue(value || date[type], locale);
|
|
88
|
+
var isRangeMode = Boolean(from) && Boolean(to);
|
|
89
|
+
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.");
|
|
90
|
+
|
|
52
91
|
var onChangeMonthYear = function onChangeMonthYear(_ref2) {
|
|
53
92
|
var month = _ref2.month,
|
|
54
93
|
year = _ref2.year;
|
|
55
94
|
setMonth(new Date(year, month));
|
|
56
95
|
};
|
|
57
96
|
|
|
58
|
-
if (!date.to || date.to === "") {
|
|
59
|
-
date.to = value || "";
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
var to = date.to,
|
|
63
|
-
from = date.from;
|
|
64
97
|
return /*#__PURE__*/_jsxs(Wrapper, {
|
|
65
98
|
width: width,
|
|
66
|
-
hasRange:
|
|
67
|
-
children: [label && /*#__PURE__*/_jsx("
|
|
99
|
+
hasRange: isRangeMode,
|
|
100
|
+
children: [label && /*#__PURE__*/_jsx("label", {
|
|
101
|
+
htmlFor: datePickerId,
|
|
102
|
+
"aria-label": label,
|
|
68
103
|
style: {
|
|
69
104
|
margin: "4px 0"
|
|
70
105
|
},
|
|
71
106
|
children: /*#__PURE__*/_jsx(BodyUI, {
|
|
107
|
+
as: "span",
|
|
72
108
|
color: gray01,
|
|
73
109
|
children: label
|
|
74
110
|
})
|
|
75
111
|
}), /*#__PURE__*/_jsx(DayPickerInput, _objectSpread({
|
|
76
|
-
component:
|
|
77
|
-
|
|
78
|
-
ref: ref
|
|
79
|
-
}, props));
|
|
80
|
-
}),
|
|
81
|
-
value: date[type] && moment(date[type]).locale(locale).format("L"),
|
|
112
|
+
component: CustomInput,
|
|
113
|
+
value: formattedValue,
|
|
82
114
|
formatDate: formatDate,
|
|
83
115
|
parseDate: parseDate,
|
|
84
|
-
placeholder:
|
|
116
|
+
placeholder: formatValue(new Date(), locale),
|
|
85
117
|
dayPickerProps: {
|
|
86
118
|
locale: locale,
|
|
87
119
|
localeUtils: MomentLocaleUtils,
|
|
88
120
|
className: "Range",
|
|
89
|
-
disabledDays:
|
|
121
|
+
disabledDays: isRangeMode ? {
|
|
90
122
|
before: from
|
|
91
123
|
} : disabledDays,
|
|
92
124
|
modifiers: {
|
|
93
125
|
before: from,
|
|
94
126
|
after: to
|
|
95
127
|
},
|
|
96
|
-
selectedDays:
|
|
128
|
+
selectedDays: isRangeMode ? {
|
|
97
129
|
from: from,
|
|
98
130
|
to: to
|
|
99
|
-
}
|
|
131
|
+
} : undefined,
|
|
100
132
|
navbarElement: /*#__PURE__*/_jsx(CustomNavbar, {
|
|
101
133
|
onChangeMonthYear: onChangeMonthYear,
|
|
102
134
|
disabledDays: disabledDays
|
|
@@ -104,7 +136,10 @@ var DatePicker = function DatePicker(_ref) {
|
|
|
104
136
|
showOutsideDays: true,
|
|
105
137
|
month: month
|
|
106
138
|
},
|
|
107
|
-
ref: pickerRef
|
|
139
|
+
ref: pickerRef,
|
|
140
|
+
inputProps: _objectSpread({
|
|
141
|
+
id: datePickerId
|
|
142
|
+
}, inputProps)
|
|
108
143
|
}, props), date[type])]
|
|
109
144
|
});
|
|
110
145
|
};
|
|
@@ -116,9 +151,15 @@ DatePicker.defaultProps = {
|
|
|
116
151
|
from: "",
|
|
117
152
|
to: ""
|
|
118
153
|
},
|
|
119
|
-
locale: "en-gb"
|
|
154
|
+
locale: "en-gb",
|
|
155
|
+
label: "",
|
|
156
|
+
width: undefined,
|
|
157
|
+
value: undefined,
|
|
158
|
+
pickerRef: undefined,
|
|
159
|
+
disabledDays: []
|
|
120
160
|
};
|
|
121
161
|
DatePicker.propTypes = {
|
|
162
|
+
fromMonth: PropTypes.instanceOf(Date),
|
|
122
163
|
label: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
|
|
123
164
|
locale: PropTypes.string,
|
|
124
165
|
width: PropTypes.string,
|
|
@@ -138,13 +179,18 @@ DatePicker.propTypes = {
|
|
|
138
179
|
if (typeof from === "undefined" || typeof to === "undefined") {
|
|
139
180
|
return new Error("Date prop required. Format: { from: Date|number|string, to: Date|number|string }. ");
|
|
140
181
|
}
|
|
182
|
+
|
|
183
|
+
return null;
|
|
141
184
|
},
|
|
142
185
|
|
|
143
186
|
/** 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,
|
|
187
|
+
disabledDays: PropTypes.oneOfType([PropTypes.object, PropTypes.arrayOf(PropTypes.object)]),
|
|
145
188
|
|
|
146
189
|
/** Can be used to tap a ref to the picker. See Range select code example how to utilise. */
|
|
147
|
-
pickerRef: PropTypes.
|
|
190
|
+
pickerRef: PropTypes.oneOfType([PropTypes.func, // eslint-disable-next-line react/forbid-prop-types
|
|
191
|
+
PropTypes.shape({
|
|
192
|
+
current: PropTypes.any
|
|
193
|
+
})])
|
|
148
194
|
};
|
|
149
195
|
|
|
150
196
|
var CustomNavbar = function CustomNavbar(_ref3) {
|
|
@@ -209,27 +255,6 @@ var CustomNavbar = function CustomNavbar(_ref3) {
|
|
|
209
255
|
});
|
|
210
256
|
};
|
|
211
257
|
|
|
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
258
|
var MonthPicker = function MonthPicker(_ref4) {
|
|
234
259
|
var date = _ref4.date,
|
|
235
260
|
disabledDays = _ref4.disabledDays,
|
|
@@ -255,7 +280,7 @@ var MonthPicker = function MonthPicker(_ref4) {
|
|
|
255
280
|
|
|
256
281
|
var fromYear = before ? new Date(before).getFullYear() + 1 : 1939;
|
|
257
282
|
var toYear = after ? new Date(after).getFullYear() : new Date(currentYear + 10, 11).getFullYear();
|
|
258
|
-
var years = [];
|
|
283
|
+
var years = []; // eslint-disable-next-line no-plusplus
|
|
259
284
|
|
|
260
285
|
for (var i = toYear; i >= fromYear; i--) {
|
|
261
286
|
years.push({
|
|
@@ -271,13 +296,16 @@ var MonthPicker = function MonthPicker(_ref4) {
|
|
|
271
296
|
|
|
272
297
|
var DropdownYearOption = function DropdownYearOption(_ref6) {
|
|
273
298
|
var children = _ref6.children,
|
|
274
|
-
props = _objectWithoutProperties(_ref6,
|
|
299
|
+
props = _objectWithoutProperties(_ref6, ["children"]);
|
|
275
300
|
|
|
276
301
|
return components.Option && /*#__PURE__*/_jsx("div", {
|
|
277
302
|
onMouseDown: function onMouseDown(e) {
|
|
278
303
|
return e.stopPropagation();
|
|
279
304
|
},
|
|
280
|
-
|
|
305
|
+
role: "option",
|
|
306
|
+
"aria-selected": true,
|
|
307
|
+
tabIndex: "0",
|
|
308
|
+
children: /*#__PURE__*/_jsx(components.Option, _objectSpread({}, props, {
|
|
281
309
|
children: children
|
|
282
310
|
}))
|
|
283
311
|
});
|
|
@@ -336,23 +364,23 @@ var MonthPicker = function MonthPicker(_ref4) {
|
|
|
336
364
|
|
|
337
365
|
var YearMonthSelectContainer = styled.div.withConfig({
|
|
338
366
|
displayName: "DatePicker__YearMonthSelectContainer",
|
|
339
|
-
componentId: "
|
|
367
|
+
componentId: "ce3xgi-0"
|
|
340
368
|
})(["position:absolute;z-index:1;top:0;bottom:0;left:0;right:0;background-color:", ";padding:", ";"], white, padding300);
|
|
341
369
|
var ActionList = styled.div.withConfig({
|
|
342
370
|
displayName: "DatePicker__ActionList",
|
|
343
|
-
componentId: "
|
|
371
|
+
componentId: "ce3xgi-1"
|
|
344
372
|
})(["display:flex;align-items:center;justify-content:flex-end;margin-top:", ";"], padding300);
|
|
345
373
|
var YearSelectContainer = styled.div.withConfig({
|
|
346
374
|
displayName: "DatePicker__YearSelectContainer",
|
|
347
|
-
componentId: "
|
|
375
|
+
componentId: "ce3xgi-2"
|
|
348
376
|
})(["align-items:center;justify-content:center;margin-bottom:", ";> div{width:100%;}"], margin200);
|
|
349
377
|
var MonthUl = styled.ul.withConfig({
|
|
350
378
|
displayName: "DatePicker__MonthUl",
|
|
351
|
-
componentId: "
|
|
379
|
+
componentId: "ce3xgi-3"
|
|
352
380
|
})(["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
381
|
var MonthSelectButton2 = styled(ButtonSecondary).withConfig({
|
|
354
382
|
displayName: "DatePicker__MonthSelectButton2",
|
|
355
|
-
componentId: "
|
|
383
|
+
componentId: "ce3xgi-4"
|
|
356
384
|
})(["padding:8px;", ""], function (_ref7) {
|
|
357
385
|
var $isActive = _ref7.$isActive;
|
|
358
386
|
return $isActive && css(["background-color:", ";p{color:", ";font-weight:bold;}"], lighten(active, 0.9), active);
|
|
@@ -360,25 +388,25 @@ var MonthSelectButton2 = styled(ButtonSecondary).withConfig({
|
|
|
360
388
|
var borderRadius = "100px";
|
|
361
389
|
var Wrapper = styled.div.withConfig({
|
|
362
390
|
displayName: "DatePicker__Wrapper",
|
|
363
|
-
componentId: "
|
|
391
|
+
componentId: "ce3xgi-5"
|
|
364
392
|
})(["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
393
|
var width = _ref8.width;
|
|
366
394
|
return width || "200px";
|
|
367
395
|
}, shadow500, radius500, function (_ref9) {
|
|
368
396
|
var hasRange = _ref9.hasRange;
|
|
369
|
-
return hasRange && "
|
|
397
|
+
return hasRange && css(["background-color:", ";border-radius:0;&:not(.DayPicker-Day--outside){color:", ";}"], toBgLight(active), gray01);
|
|
370
398
|
}, active, white, function (_ref10) {
|
|
371
399
|
var hasRange = _ref10.hasRange;
|
|
372
|
-
return hasRange && "
|
|
400
|
+
return hasRange && css(["::before{content:\"\";position:absolute;background-color:", ";width:10px;height:35px;top:0;right:0;z-index:-1;}"], toBgLight(active));
|
|
373
401
|
}, function (_ref11) {
|
|
374
402
|
var hasRange = _ref11.hasRange;
|
|
375
|
-
return hasRange && "
|
|
403
|
+
return hasRange && css(["::before{content:\"\";position:absolute;background-color:", ";width:10px;height:35px;top:0;left:0;z-index:-1;}"], toBgLight(active));
|
|
376
404
|
}, active, white, sansFamily, gray06, black, gray06, active, active, sansFamily, gray01, function (_ref12) {
|
|
377
405
|
var hasRange = _ref12.hasRange;
|
|
378
|
-
return hasRange && "
|
|
406
|
+
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
407
|
});
|
|
380
408
|
var NavBarContainer = styled.div.withConfig({
|
|
381
409
|
displayName: "DatePicker__NavBarContainer",
|
|
382
|
-
componentId: "
|
|
410
|
+
componentId: "ce3xgi-6"
|
|
383
411
|
})(["display:flex;align-items:center;justify-content:space-between;padding:16px 14px 0px 14px;"]);
|
|
384
412
|
export default DatePicker;
|
package/dist/DateTimePicker.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
-
|
|
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
|
-
|
|
37
|
-
|
|
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
|
|
55
|
-
|
|
56
|
-
|
|
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
|
-
|
|
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
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
var
|
|
100
|
-
var
|
|
101
|
-
|
|
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: "
|
|
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
|
-
|
|
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;
|