@happeouikit/form-elements 2.3.8 → 2.3.13
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 +21 -0
- package/dist/DatePicker.js +80 -31
- package/dist/Switch.js +1 -1
- package/dist/messages.js +4 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 2.3.13
|
|
4
|
+
|
|
5
|
+
- [Added] Handle css states of Switch
|
|
6
|
+
|
|
7
|
+
## 2.3.12
|
|
8
|
+
|
|
9
|
+
- [Fixed] publish datepicker new version
|
|
10
|
+
|
|
11
|
+
## 2.3.11
|
|
12
|
+
|
|
13
|
+
- [Fixed] publish new version
|
|
14
|
+
|
|
15
|
+
## 2.3.10
|
|
16
|
+
|
|
17
|
+
- [Fixed] DatePicker doesn't propagate disabled dates correctly
|
|
18
|
+
- [Added] DatePicker styles for disabled buttons
|
|
19
|
+
|
|
20
|
+
## 2.3.9
|
|
21
|
+
|
|
22
|
+
- [Added] DatePicker. Added accessible description for DatePicker input
|
|
23
|
+
|
|
3
24
|
## 2.3.8
|
|
4
25
|
|
|
5
26
|
- [Fixed] Switch a11y issues.
|
package/dist/DatePicker.js
CHANGED
|
@@ -8,7 +8,7 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
|
|
|
8
8
|
|
|
9
9
|
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
10
|
|
|
11
|
-
import React, { useState, useRef } from "react";
|
|
11
|
+
import React, { useState, useRef, useMemo } from "react";
|
|
12
12
|
import PropTypes from "prop-types";
|
|
13
13
|
import styled, { css } from "styled-components";
|
|
14
14
|
import DayPickerInput from "react-day-picker/DayPickerInput";
|
|
@@ -18,7 +18,7 @@ import MomentLocaleUtils, { formatDate, parseDate } from "react-day-picker/momen
|
|
|
18
18
|
import "moment/locale/en-gb";
|
|
19
19
|
import { Tooltip } from "@happeouikit/tooltip";
|
|
20
20
|
import { BodyUI, sansFamily } from "@happeouikit/typography";
|
|
21
|
-
import { gray06, black, active, gray01, toBgLight, lighten, white, gray03 } from "@happeouikit/colors";
|
|
21
|
+
import { gray06, black, active, gray01, toBgLight, lighten, white, gray03, gray05 } from "@happeouikit/colors";
|
|
22
22
|
import { margin200, padding300 } from "@happeouikit/layout";
|
|
23
23
|
import { IconButton, ButtonSecondary } from "@happeouikit/buttons";
|
|
24
24
|
import { IconChevronLeft, IconChevronRight, IconCalendar, IconCheck } from "@happeouikit/icons";
|
|
@@ -88,8 +88,10 @@ var DatePicker = function DatePicker(_ref) {
|
|
|
88
88
|
|
|
89
89
|
var from = date.from,
|
|
90
90
|
to = date.to;
|
|
91
|
+
var localeFormat = moment.localeData(locale).longDateFormat("L");
|
|
91
92
|
var formattedValue = formatValue(value || date[type], locale);
|
|
92
93
|
var isRangeMode = Boolean(from) && Boolean(to);
|
|
94
|
+
var intl = useIntl();
|
|
93
95
|
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.");
|
|
94
96
|
|
|
95
97
|
var onChangeMonthYear = function onChangeMonthYear(_ref2) {
|
|
@@ -98,6 +100,23 @@ var DatePicker = function DatePicker(_ref) {
|
|
|
98
100
|
setMonth(new Date(year, month));
|
|
99
101
|
};
|
|
100
102
|
|
|
103
|
+
var pickerDisabledDays = useMemo(function () {
|
|
104
|
+
if (isRangeMode) {
|
|
105
|
+
if (type === "from") {
|
|
106
|
+
return {
|
|
107
|
+
before: disabledDays.before,
|
|
108
|
+
after: to || disabledDays.after
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return {
|
|
113
|
+
before: from || disabledDays.before,
|
|
114
|
+
after: disabledDays.after
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return disabledDays;
|
|
119
|
+
}, [type, isRangeMode, disabledDays, from, to]);
|
|
101
120
|
return /*#__PURE__*/_jsxs(Wrapper, {
|
|
102
121
|
width: width,
|
|
103
122
|
hasRange: isRangeMode,
|
|
@@ -122,9 +141,7 @@ var DatePicker = function DatePicker(_ref) {
|
|
|
122
141
|
locale: locale,
|
|
123
142
|
localeUtils: MomentLocaleUtils,
|
|
124
143
|
className: "Range",
|
|
125
|
-
disabledDays:
|
|
126
|
-
before: from
|
|
127
|
-
} : disabledDays,
|
|
144
|
+
disabledDays: pickerDisabledDays,
|
|
128
145
|
modifiers: {
|
|
129
146
|
before: from,
|
|
130
147
|
after: to
|
|
@@ -135,14 +152,18 @@ var DatePicker = function DatePicker(_ref) {
|
|
|
135
152
|
} : undefined,
|
|
136
153
|
navbarElement: /*#__PURE__*/_jsx(CustomNavbar, {
|
|
137
154
|
onChangeMonthYear: onChangeMonthYear,
|
|
138
|
-
disabledDays:
|
|
155
|
+
disabledDays: pickerDisabledDays
|
|
139
156
|
}),
|
|
140
157
|
showOutsideDays: true,
|
|
141
158
|
month: month
|
|
142
159
|
}, dayPickerProps),
|
|
143
160
|
ref: pickerRef,
|
|
144
161
|
inputProps: _objectSpread({
|
|
145
|
-
id: datePickerId
|
|
162
|
+
id: datePickerId,
|
|
163
|
+
"aria-label": label,
|
|
164
|
+
"aria-description": intl.formatMessage(messages.selectDateFormatDescription, {
|
|
165
|
+
localeFormat: localeFormat
|
|
166
|
+
})
|
|
146
167
|
}, inputProps)
|
|
147
168
|
}, props), date[type])]
|
|
148
169
|
});
|
|
@@ -199,6 +220,8 @@ DatePicker.propTypes = {
|
|
|
199
220
|
|
|
200
221
|
var CustomNavbar = function CustomNavbar(_ref3) {
|
|
201
222
|
var month = _ref3.month,
|
|
223
|
+
previousMonth = _ref3.previousMonth,
|
|
224
|
+
nextMonth = _ref3.nextMonth,
|
|
202
225
|
onPreviousClick = _ref3.onPreviousClick,
|
|
203
226
|
onNextClick = _ref3.onNextClick,
|
|
204
227
|
onChangeMonthYear = _ref3.onChangeMonthYear,
|
|
@@ -208,17 +231,29 @@ var CustomNavbar = function CustomNavbar(_ref3) {
|
|
|
208
231
|
var _useState3 = useState(false),
|
|
209
232
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
210
233
|
showYearMonthPicker = _useState4[0],
|
|
211
|
-
setShowYearMonthPicker = _useState4[1];
|
|
212
|
-
|
|
234
|
+
setShowYearMonthPicker = _useState4[1]; // using toDateString due to previousMonth and nextMonth are at 12:00
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
var enabledPreviousArrow = useMemo(function () {
|
|
238
|
+
return new Date(previousMonth.toDateString()) >= moment(disabledDays.before).startOf("month");
|
|
239
|
+
}, [previousMonth, disabledDays]);
|
|
240
|
+
var enabledNextArrow = useMemo(function () {
|
|
241
|
+
return new Date(nextMonth.toDateString()) <= moment(disabledDays.after).startOf("month");
|
|
242
|
+
}, [nextMonth, disabledDays]);
|
|
243
|
+
var disabledStyle = {
|
|
244
|
+
fill: gray06,
|
|
245
|
+
cursor: "default"
|
|
246
|
+
};
|
|
213
247
|
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
214
248
|
children: [/*#__PURE__*/_jsxs(NavBarContainer, {
|
|
215
249
|
children: [/*#__PURE__*/_jsx(IconButton, {
|
|
216
250
|
icon: IconChevronLeft,
|
|
217
251
|
isActionIcon: true,
|
|
218
252
|
onClick: function onClick() {
|
|
219
|
-
return onPreviousClick();
|
|
253
|
+
return enabledPreviousArrow && onPreviousClick();
|
|
220
254
|
},
|
|
221
255
|
"aria-label": intl.formatMessage(messages.pickerPrevMonth),
|
|
256
|
+
style: !enabledPreviousArrow && disabledStyle || {},
|
|
222
257
|
"data-tip": true,
|
|
223
258
|
"data-for": "datepicker-prev-month",
|
|
224
259
|
"data-testid": "datepicker-select-prev-month"
|
|
@@ -235,9 +270,10 @@ var CustomNavbar = function CustomNavbar(_ref3) {
|
|
|
235
270
|
icon: IconChevronRight,
|
|
236
271
|
isActionIcon: true,
|
|
237
272
|
onClick: function onClick() {
|
|
238
|
-
return onNextClick();
|
|
273
|
+
return enabledNextArrow && onNextClick();
|
|
239
274
|
},
|
|
240
275
|
"aria-label": intl.formatMessage(messages.pickerNextMonth),
|
|
276
|
+
style: !enabledNextArrow && disabledStyle || {},
|
|
241
277
|
"data-tip": true,
|
|
242
278
|
"data-for": "datepicker-next-month",
|
|
243
279
|
"data-testid": "datepicker-select-next-month"
|
|
@@ -278,14 +314,18 @@ var MonthPicker = function MonthPicker(_ref4) {
|
|
|
278
314
|
selectedYear = _useState8[0],
|
|
279
315
|
setSelectedYear = _useState8[1];
|
|
280
316
|
|
|
317
|
+
var _ref5 = disabledDays || {},
|
|
318
|
+
after = _ref5.after,
|
|
319
|
+
before = _ref5.before;
|
|
320
|
+
|
|
281
321
|
var getYears = function getYears() {
|
|
282
322
|
var currentYear = new Date().getFullYear();
|
|
283
323
|
|
|
284
|
-
var
|
|
285
|
-
after =
|
|
286
|
-
before =
|
|
324
|
+
var _ref6 = disabledDays || {},
|
|
325
|
+
after = _ref6.after,
|
|
326
|
+
before = _ref6.before;
|
|
287
327
|
|
|
288
|
-
var fromYear = before ? new Date(before).getFullYear()
|
|
328
|
+
var fromYear = before ? new Date(before).getFullYear() : 1939;
|
|
289
329
|
var toYear = after ? new Date(after).getFullYear() : new Date(currentYear + 10, 11).getFullYear();
|
|
290
330
|
var years = []; // eslint-disable-next-line no-plusplus
|
|
291
331
|
|
|
@@ -299,11 +339,19 @@ var MonthPicker = function MonthPicker(_ref4) {
|
|
|
299
339
|
return years;
|
|
300
340
|
};
|
|
301
341
|
|
|
342
|
+
var isDisabledMonth = function isDisabledMonth(month) {
|
|
343
|
+
var monthDate = moment().set({
|
|
344
|
+
year: selectedYear,
|
|
345
|
+
month: month
|
|
346
|
+
}).startOf("month");
|
|
347
|
+
return monthDate < moment(before).startOf("month") || monthDate > moment(after).startOf("month");
|
|
348
|
+
};
|
|
349
|
+
|
|
302
350
|
var months = moment.monthsShort();
|
|
303
351
|
|
|
304
|
-
var DropdownYearOption = function DropdownYearOption(
|
|
305
|
-
var children =
|
|
306
|
-
props = _objectWithoutProperties(
|
|
352
|
+
var DropdownYearOption = function DropdownYearOption(_ref7) {
|
|
353
|
+
var children = _ref7.children,
|
|
354
|
+
props = _objectWithoutProperties(_ref7, _excluded2);
|
|
307
355
|
|
|
308
356
|
return components.Option && /*#__PURE__*/_jsx("div", {
|
|
309
357
|
onMouseDown: function onMouseDown(e) {
|
|
@@ -343,8 +391,9 @@ var MonthPicker = function MonthPicker(_ref4) {
|
|
|
343
391
|
"data-testid": "select-month-".concat(month),
|
|
344
392
|
"data-for": "datepicker-select-month-button",
|
|
345
393
|
$isActive: i === selectedMonth,
|
|
394
|
+
disabled: isDisabledMonth(month),
|
|
346
395
|
onClick: function onClick() {
|
|
347
|
-
setSelectedMonth(i);
|
|
396
|
+
if (!isDisabledMonth(month)) setSelectedMonth(i);
|
|
348
397
|
},
|
|
349
398
|
"aria-label": month,
|
|
350
399
|
text: month
|
|
@@ -391,28 +440,28 @@ var MonthUl = styled.ul.withConfig({
|
|
|
391
440
|
var MonthSelectButton2 = styled(ButtonSecondary).withConfig({
|
|
392
441
|
displayName: "DatePicker__MonthSelectButton2",
|
|
393
442
|
componentId: "sc-ce3xgi-4"
|
|
394
|
-
})(["padding:8px;", ""], function (
|
|
395
|
-
var $isActive =
|
|
443
|
+
})(["padding:8px;", ""], function (_ref8) {
|
|
444
|
+
var $isActive = _ref8.$isActive;
|
|
396
445
|
return $isActive && css(["background-color:", ";p{color:", ";font-weight:bold;}"], lighten(active, 0.9), active);
|
|
397
446
|
});
|
|
398
447
|
var borderRadius = "100px";
|
|
399
448
|
var Wrapper = styled.div.withConfig({
|
|
400
449
|
displayName: "DatePicker__Wrapper",
|
|
401
450
|
componentId: "sc-ce3xgi-5"
|
|
402
|
-
})(["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 (
|
|
403
|
-
var width =
|
|
451
|
+
})(["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 (_ref9) {
|
|
452
|
+
var width = _ref9.width;
|
|
404
453
|
return width || "200px";
|
|
405
|
-
}, shadow500, radius500, function (
|
|
406
|
-
var hasRange = _ref9.hasRange;
|
|
407
|
-
return hasRange && css(["background-color:", ";border-radius:0;&:not(.DayPicker-Day--outside){color:", ";}"], toBgLight(active), gray01);
|
|
408
|
-
}, active, white, function (_ref10) {
|
|
454
|
+
}, shadow500, radius500, function (_ref10) {
|
|
409
455
|
var hasRange = _ref10.hasRange;
|
|
410
|
-
return hasRange && css(["
|
|
411
|
-
}, function (_ref11) {
|
|
456
|
+
return hasRange && css(["background-color:", ";border-radius:0;&:not(.DayPicker-Day--outside){color:", ";}&.DayPicker-Day--outside{color:", ";}"], toBgLight(active), gray01, gray05);
|
|
457
|
+
}, active, white, function (_ref11) {
|
|
412
458
|
var hasRange = _ref11.hasRange;
|
|
413
|
-
return hasRange && css(["::before{content:\"\";position:absolute;background-color:", ";width:10px;height:35px;top:0;
|
|
414
|
-
},
|
|
459
|
+
return hasRange && css(["::before{content:\"\";position:absolute;background-color:", ";width:10px;height:35px;top:0;right:0;z-index:-1;}"], toBgLight(active));
|
|
460
|
+
}, function (_ref12) {
|
|
415
461
|
var hasRange = _ref12.hasRange;
|
|
462
|
+
return hasRange && css(["::before{content:\"\";position:absolute;background-color:", ";width:10px;height:35px;top:0;left:0;z-index:-1;}"], toBgLight(active));
|
|
463
|
+
}, active, white, sansFamily, gray06, black, gray06, active, active, sansFamily, gray01, function (_ref13) {
|
|
464
|
+
var hasRange = _ref13.hasRange;
|
|
416
465
|
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);
|
|
417
466
|
});
|
|
418
467
|
var NavBarContainer = styled.div.withConfig({
|
package/dist/Switch.js
CHANGED
|
@@ -67,7 +67,7 @@ Switch.defaultProps = {
|
|
|
67
67
|
var StyledSwitch = styled.button.withConfig({
|
|
68
68
|
displayName: "Switch__StyledSwitch",
|
|
69
69
|
componentId: "sc-1pn4n4-0"
|
|
70
|
-
})(["all:unset;position:relative;top:0;left:0;right:0;bottom:0;box-sizing:content-box;width:40px;height:20px;background-color:white;border:2px solid ", ";border-radius:13px;transition:0.4s;:before{position:absolute;content:\"\";height:14px;width:14px;left:3px;bottom:3px;border-radius:50%;background-color:", ";transition:0.4s;}&:focus-visible{outline:0;box-shadow:0 0 0 1px ", ";}"], gray08, gray08, active);
|
|
70
|
+
})(["all:unset;position:relative;top:0;left:0;right:0;bottom:0;box-sizing:content-box;width:40px;height:20px;background-color:white;border:2px solid ", ";border-radius:13px;transition:0.4s;:before{position:absolute;content:\"\";height:14px;width:14px;left:3px;bottom:3px;border-radius:50%;background-color:", ";transition:0.4s;}&:focus-visible{outline:0;box-shadow:0 0 0 1px ", ";}&:hover{background-color:transparent;}&:active{background-color:transparent;transform:none;box-shadow:none;}"], gray08, gray08, active);
|
|
71
71
|
var ToggleSwitchWrapper = styled.label.withConfig({
|
|
72
72
|
displayName: "Switch__ToggleSwitchWrapper",
|
|
73
73
|
componentId: "sc-1pn4n4-1"
|
package/dist/messages.js
CHANGED
|
@@ -28,6 +28,10 @@ export default defineMessages({
|
|
|
28
28
|
id: "datePicker.message.invalid.time",
|
|
29
29
|
defaultMessage: "Invalid Time"
|
|
30
30
|
},
|
|
31
|
+
selectDateFormatDescription: {
|
|
32
|
+
id: "datePicker.message.formatDescription",
|
|
33
|
+
defaultMessage: "Provide a date using the format {localeFormat}"
|
|
34
|
+
},
|
|
31
35
|
wrongFormat: {
|
|
32
36
|
id: "datePicker.message.invalid.format",
|
|
33
37
|
defaultMessage: "Invalid Format"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@happeouikit/form-elements",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.13",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "src/index.js",
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"publishConfig": {
|
|
46
46
|
"access": "public"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "cd6efdf57e9a69e8753b249f3c3a10d8d06f1eb2"
|
|
49
49
|
}
|