@happeouikit/form-elements 2.2.0 → 2.2.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 +4 -0
- package/dist/DatePicker.js +65 -48
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/DatePicker.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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";
|
|
3
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
4
4
|
var _excluded = ["label", "locale", "width", "date", "type", "fromMonth", "disabledDays", "value", "pickerRef"],
|
|
5
5
|
_excluded2 = ["children"];
|
|
6
6
|
|
|
@@ -23,15 +23,43 @@ import { margin200, padding300 } from "@happeouikit/layout";
|
|
|
23
23
|
import { IconButton, ButtonSecondary } from "@happeouikit/buttons";
|
|
24
24
|
import { IconChevronLeft, IconChevronRight, IconCalendar, IconCheck } from "@happeouikit/icons";
|
|
25
25
|
import { radius500, shadow500 } from "@happeouikit/theme";
|
|
26
|
+
import { components } from "react-select";
|
|
26
27
|
import Dropdown from "./Dropdown"; // CSS
|
|
27
28
|
|
|
28
29
|
import "react-day-picker/lib/style.css";
|
|
29
30
|
import messages from "./messages";
|
|
30
|
-
import {
|
|
31
|
+
import { useDevWarningOnce } from "./utils";
|
|
31
32
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
32
33
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
33
34
|
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
34
35
|
|
|
36
|
+
var formatValue = function formatValue(value, locale) {
|
|
37
|
+
if (!value) return null;
|
|
38
|
+
return moment(value).locale(locale).format("L");
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
var CustomInput = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
42
|
+
return /*#__PURE__*/_jsxs("div", {
|
|
43
|
+
style: {
|
|
44
|
+
display: "flex",
|
|
45
|
+
alignItems: "center"
|
|
46
|
+
},
|
|
47
|
+
children: [/*#__PURE__*/_jsx(IconCalendar, {
|
|
48
|
+
style: {
|
|
49
|
+
position: "absolute",
|
|
50
|
+
paddingLeft: "10px",
|
|
51
|
+
fill: gray03,
|
|
52
|
+
height: "20px",
|
|
53
|
+
width: "20px",
|
|
54
|
+
boxSizing: "content-box"
|
|
55
|
+
}
|
|
56
|
+
}), /*#__PURE__*/_jsx("input", _objectSpread({
|
|
57
|
+
"data-testid": "datepicker-input",
|
|
58
|
+
ref: ref
|
|
59
|
+
}, props))]
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
35
63
|
var DatePicker = function DatePicker(_ref) {
|
|
36
64
|
var label = _ref.label,
|
|
37
65
|
locale = _ref.locale,
|
|
@@ -49,21 +77,21 @@ var DatePicker = function DatePicker(_ref) {
|
|
|
49
77
|
month = _useState2[0],
|
|
50
78
|
setMonth = _useState2[1];
|
|
51
79
|
|
|
80
|
+
var from = date.from,
|
|
81
|
+
to = date.to;
|
|
82
|
+
var formattedValue = formatValue(value || date[type], locale);
|
|
83
|
+
var isRangeMode = Boolean(from) && Boolean(to);
|
|
84
|
+
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.");
|
|
85
|
+
|
|
52
86
|
var onChangeMonthYear = function onChangeMonthYear(_ref2) {
|
|
53
87
|
var month = _ref2.month,
|
|
54
88
|
year = _ref2.year;
|
|
55
89
|
setMonth(new Date(year, month));
|
|
56
90
|
};
|
|
57
91
|
|
|
58
|
-
if (!date.to || date.to === "") {
|
|
59
|
-
date.to = value || "";
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
var to = date.to,
|
|
63
|
-
from = date.from;
|
|
64
92
|
return /*#__PURE__*/_jsxs(Wrapper, {
|
|
65
93
|
width: width,
|
|
66
|
-
hasRange:
|
|
94
|
+
hasRange: isRangeMode,
|
|
67
95
|
children: [label && /*#__PURE__*/_jsx("div", {
|
|
68
96
|
style: {
|
|
69
97
|
margin: "4px 0"
|
|
@@ -73,30 +101,26 @@ var DatePicker = function DatePicker(_ref) {
|
|
|
73
101
|
children: label
|
|
74
102
|
})
|
|
75
103
|
}), /*#__PURE__*/_jsx(DayPickerInput, _objectSpread({
|
|
76
|
-
component:
|
|
77
|
-
|
|
78
|
-
ref: ref
|
|
79
|
-
}, props));
|
|
80
|
-
}),
|
|
81
|
-
value: date[type] && moment(date[type]).locale(locale).format("L"),
|
|
104
|
+
component: CustomInput,
|
|
105
|
+
value: formattedValue,
|
|
82
106
|
formatDate: formatDate,
|
|
83
107
|
parseDate: parseDate,
|
|
84
|
-
placeholder:
|
|
108
|
+
placeholder: formatValue(new Date(), locale),
|
|
85
109
|
dayPickerProps: {
|
|
86
110
|
locale: locale,
|
|
87
111
|
localeUtils: MomentLocaleUtils,
|
|
88
112
|
className: "Range",
|
|
89
|
-
disabledDays:
|
|
113
|
+
disabledDays: isRangeMode ? {
|
|
90
114
|
before: from
|
|
91
115
|
} : disabledDays,
|
|
92
116
|
modifiers: {
|
|
93
117
|
before: from,
|
|
94
118
|
after: to
|
|
95
119
|
},
|
|
96
|
-
selectedDays:
|
|
120
|
+
selectedDays: isRangeMode ? {
|
|
97
121
|
from: from,
|
|
98
122
|
to: to
|
|
99
|
-
}
|
|
123
|
+
} : undefined,
|
|
100
124
|
navbarElement: /*#__PURE__*/_jsx(CustomNavbar, {
|
|
101
125
|
onChangeMonthYear: onChangeMonthYear,
|
|
102
126
|
disabledDays: disabledDays
|
|
@@ -116,9 +140,15 @@ DatePicker.defaultProps = {
|
|
|
116
140
|
from: "",
|
|
117
141
|
to: ""
|
|
118
142
|
},
|
|
119
|
-
locale: "en-gb"
|
|
143
|
+
locale: "en-gb",
|
|
144
|
+
label: "",
|
|
145
|
+
width: undefined,
|
|
146
|
+
value: undefined,
|
|
147
|
+
pickerRef: undefined,
|
|
148
|
+
disabledDays: []
|
|
120
149
|
};
|
|
121
150
|
DatePicker.propTypes = {
|
|
151
|
+
fromMonth: PropTypes.instanceOf(Date),
|
|
122
152
|
label: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
|
|
123
153
|
locale: PropTypes.string,
|
|
124
154
|
width: PropTypes.string,
|
|
@@ -138,13 +168,18 @@ DatePicker.propTypes = {
|
|
|
138
168
|
if (typeof from === "undefined" || typeof to === "undefined") {
|
|
139
169
|
return new Error("Date prop required. Format: { from: Date|number|string, to: Date|number|string }. ");
|
|
140
170
|
}
|
|
171
|
+
|
|
172
|
+
return null;
|
|
141
173
|
},
|
|
142
174
|
|
|
143
175
|
/** 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,
|
|
176
|
+
disabledDays: PropTypes.oneOfType([PropTypes.object, PropTypes.arrayOf(PropTypes.object)]),
|
|
145
177
|
|
|
146
178
|
/** Can be used to tap a ref to the picker. See Range select code example how to utilise. */
|
|
147
|
-
pickerRef: PropTypes.
|
|
179
|
+
pickerRef: PropTypes.oneOfType([PropTypes.func, // eslint-disable-next-line react/forbid-prop-types
|
|
180
|
+
PropTypes.shape({
|
|
181
|
+
current: PropTypes.any
|
|
182
|
+
})])
|
|
148
183
|
};
|
|
149
184
|
|
|
150
185
|
var CustomNavbar = function CustomNavbar(_ref3) {
|
|
@@ -209,27 +244,6 @@ var CustomNavbar = function CustomNavbar(_ref3) {
|
|
|
209
244
|
});
|
|
210
245
|
};
|
|
211
246
|
|
|
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
247
|
var MonthPicker = function MonthPicker(_ref4) {
|
|
234
248
|
var date = _ref4.date,
|
|
235
249
|
disabledDays = _ref4.disabledDays,
|
|
@@ -255,7 +269,7 @@ var MonthPicker = function MonthPicker(_ref4) {
|
|
|
255
269
|
|
|
256
270
|
var fromYear = before ? new Date(before).getFullYear() + 1 : 1939;
|
|
257
271
|
var toYear = after ? new Date(after).getFullYear() : new Date(currentYear + 10, 11).getFullYear();
|
|
258
|
-
var years = [];
|
|
272
|
+
var years = []; // eslint-disable-next-line no-plusplus
|
|
259
273
|
|
|
260
274
|
for (var i = toYear; i >= fromYear; i--) {
|
|
261
275
|
years.push({
|
|
@@ -277,6 +291,9 @@ var MonthPicker = function MonthPicker(_ref4) {
|
|
|
277
291
|
onMouseDown: function onMouseDown(e) {
|
|
278
292
|
return e.stopPropagation();
|
|
279
293
|
},
|
|
294
|
+
role: "option",
|
|
295
|
+
"aria-selected": true,
|
|
296
|
+
tabIndex: "0",
|
|
280
297
|
children: /*#__PURE__*/_jsx(components.Option, _objectSpread(_objectSpread({}, props), {}, {
|
|
281
298
|
children: children
|
|
282
299
|
}))
|
|
@@ -366,16 +383,16 @@ var Wrapper = styled.div.withConfig({
|
|
|
366
383
|
return width || "200px";
|
|
367
384
|
}, shadow500, radius500, function (_ref9) {
|
|
368
385
|
var hasRange = _ref9.hasRange;
|
|
369
|
-
return hasRange && "
|
|
386
|
+
return hasRange && css(["background-color:", ";border-radius:0;&:not(.DayPicker-Day--outside){color:", ";}"], toBgLight(active), gray01);
|
|
370
387
|
}, active, white, function (_ref10) {
|
|
371
388
|
var hasRange = _ref10.hasRange;
|
|
372
|
-
return hasRange && "
|
|
389
|
+
return hasRange && css(["::before{content:\"\";position:absolute;background-color:", ";width:10px;height:35px;top:0;right:0;z-index:-1;}"], toBgLight(active));
|
|
373
390
|
}, function (_ref11) {
|
|
374
391
|
var hasRange = _ref11.hasRange;
|
|
375
|
-
return hasRange && "
|
|
392
|
+
return hasRange && css(["::before{content:\"\";position:absolute;background-color:", ";width:10px;height:35px;top:0;left:0;z-index:-1;}"], toBgLight(active));
|
|
376
393
|
}, active, white, sansFamily, gray06, black, gray06, active, active, sansFamily, gray01, function (_ref12) {
|
|
377
394
|
var hasRange = _ref12.hasRange;
|
|
378
|
-
return hasRange && "
|
|
395
|
+
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
396
|
});
|
|
380
397
|
var NavBarContainer = styled.div.withConfig({
|
|
381
398
|
displayName: "DatePicker__NavBarContainer",
|