@happeouikit/form-elements 2.3.9 → 2.3.14
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 +22 -0
- package/dist/DatePicker.js +74 -31
- package/dist/Switch.js +1 -1
- package/messages.json +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,8 +1,30 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 2.3.14
|
|
4
|
+
|
|
5
|
+
- [Added] Changed DatePicker placeholder
|
|
6
|
+
|
|
7
|
+
## 2.3.13
|
|
8
|
+
|
|
9
|
+
- [Added] Handle css states of Switch
|
|
10
|
+
|
|
11
|
+
## 2.3.12
|
|
12
|
+
|
|
13
|
+
- [Fixed] publish datepicker new version
|
|
14
|
+
|
|
15
|
+
## 2.3.11
|
|
16
|
+
|
|
17
|
+
- [Fixed] publish new version
|
|
18
|
+
|
|
19
|
+
## 2.3.10
|
|
20
|
+
|
|
21
|
+
- [Fixed] DatePicker doesn't propagate disabled dates correctly
|
|
22
|
+
- [Added] DatePicker styles for disabled buttons
|
|
23
|
+
|
|
3
24
|
## 2.3.9
|
|
4
25
|
|
|
5
26
|
- [Added] DatePicker. Added accessible description for DatePicker input
|
|
27
|
+
|
|
6
28
|
## 2.3.8
|
|
7
29
|
|
|
8
30
|
- [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";
|
|
@@ -100,6 +100,23 @@ var DatePicker = function DatePicker(_ref) {
|
|
|
100
100
|
setMonth(new Date(year, month));
|
|
101
101
|
};
|
|
102
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]);
|
|
103
120
|
return /*#__PURE__*/_jsxs(Wrapper, {
|
|
104
121
|
width: width,
|
|
105
122
|
hasRange: isRangeMode,
|
|
@@ -119,14 +136,12 @@ var DatePicker = function DatePicker(_ref) {
|
|
|
119
136
|
value: formattedValue,
|
|
120
137
|
formatDate: formatDate,
|
|
121
138
|
parseDate: parseDate,
|
|
122
|
-
placeholder:
|
|
139
|
+
placeholder: localeFormat,
|
|
123
140
|
dayPickerProps: _objectSpread({
|
|
124
141
|
locale: locale,
|
|
125
142
|
localeUtils: MomentLocaleUtils,
|
|
126
143
|
className: "Range",
|
|
127
|
-
disabledDays:
|
|
128
|
-
before: from
|
|
129
|
-
} : disabledDays,
|
|
144
|
+
disabledDays: pickerDisabledDays,
|
|
130
145
|
modifiers: {
|
|
131
146
|
before: from,
|
|
132
147
|
after: to
|
|
@@ -137,7 +152,7 @@ var DatePicker = function DatePicker(_ref) {
|
|
|
137
152
|
} : undefined,
|
|
138
153
|
navbarElement: /*#__PURE__*/_jsx(CustomNavbar, {
|
|
139
154
|
onChangeMonthYear: onChangeMonthYear,
|
|
140
|
-
disabledDays:
|
|
155
|
+
disabledDays: pickerDisabledDays
|
|
141
156
|
}),
|
|
142
157
|
showOutsideDays: true,
|
|
143
158
|
month: month
|
|
@@ -205,6 +220,8 @@ DatePicker.propTypes = {
|
|
|
205
220
|
|
|
206
221
|
var CustomNavbar = function CustomNavbar(_ref3) {
|
|
207
222
|
var month = _ref3.month,
|
|
223
|
+
previousMonth = _ref3.previousMonth,
|
|
224
|
+
nextMonth = _ref3.nextMonth,
|
|
208
225
|
onPreviousClick = _ref3.onPreviousClick,
|
|
209
226
|
onNextClick = _ref3.onNextClick,
|
|
210
227
|
onChangeMonthYear = _ref3.onChangeMonthYear,
|
|
@@ -214,17 +231,29 @@ var CustomNavbar = function CustomNavbar(_ref3) {
|
|
|
214
231
|
var _useState3 = useState(false),
|
|
215
232
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
216
233
|
showYearMonthPicker = _useState4[0],
|
|
217
|
-
setShowYearMonthPicker = _useState4[1];
|
|
218
|
-
|
|
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
|
+
};
|
|
219
247
|
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
220
248
|
children: [/*#__PURE__*/_jsxs(NavBarContainer, {
|
|
221
249
|
children: [/*#__PURE__*/_jsx(IconButton, {
|
|
222
250
|
icon: IconChevronLeft,
|
|
223
251
|
isActionIcon: true,
|
|
224
252
|
onClick: function onClick() {
|
|
225
|
-
return onPreviousClick();
|
|
253
|
+
return enabledPreviousArrow && onPreviousClick();
|
|
226
254
|
},
|
|
227
255
|
"aria-label": intl.formatMessage(messages.pickerPrevMonth),
|
|
256
|
+
style: !enabledPreviousArrow && disabledStyle || {},
|
|
228
257
|
"data-tip": true,
|
|
229
258
|
"data-for": "datepicker-prev-month",
|
|
230
259
|
"data-testid": "datepicker-select-prev-month"
|
|
@@ -241,9 +270,10 @@ var CustomNavbar = function CustomNavbar(_ref3) {
|
|
|
241
270
|
icon: IconChevronRight,
|
|
242
271
|
isActionIcon: true,
|
|
243
272
|
onClick: function onClick() {
|
|
244
|
-
return onNextClick();
|
|
273
|
+
return enabledNextArrow && onNextClick();
|
|
245
274
|
},
|
|
246
275
|
"aria-label": intl.formatMessage(messages.pickerNextMonth),
|
|
276
|
+
style: !enabledNextArrow && disabledStyle || {},
|
|
247
277
|
"data-tip": true,
|
|
248
278
|
"data-for": "datepicker-next-month",
|
|
249
279
|
"data-testid": "datepicker-select-next-month"
|
|
@@ -284,14 +314,18 @@ var MonthPicker = function MonthPicker(_ref4) {
|
|
|
284
314
|
selectedYear = _useState8[0],
|
|
285
315
|
setSelectedYear = _useState8[1];
|
|
286
316
|
|
|
317
|
+
var _ref5 = disabledDays || {},
|
|
318
|
+
after = _ref5.after,
|
|
319
|
+
before = _ref5.before;
|
|
320
|
+
|
|
287
321
|
var getYears = function getYears() {
|
|
288
322
|
var currentYear = new Date().getFullYear();
|
|
289
323
|
|
|
290
|
-
var
|
|
291
|
-
after =
|
|
292
|
-
before =
|
|
324
|
+
var _ref6 = disabledDays || {},
|
|
325
|
+
after = _ref6.after,
|
|
326
|
+
before = _ref6.before;
|
|
293
327
|
|
|
294
|
-
var fromYear = before ? new Date(before).getFullYear()
|
|
328
|
+
var fromYear = before ? new Date(before).getFullYear() : 1939;
|
|
295
329
|
var toYear = after ? new Date(after).getFullYear() : new Date(currentYear + 10, 11).getFullYear();
|
|
296
330
|
var years = []; // eslint-disable-next-line no-plusplus
|
|
297
331
|
|
|
@@ -305,11 +339,19 @@ var MonthPicker = function MonthPicker(_ref4) {
|
|
|
305
339
|
return years;
|
|
306
340
|
};
|
|
307
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
|
+
|
|
308
350
|
var months = moment.monthsShort();
|
|
309
351
|
|
|
310
|
-
var DropdownYearOption = function DropdownYearOption(
|
|
311
|
-
var children =
|
|
312
|
-
props = _objectWithoutProperties(
|
|
352
|
+
var DropdownYearOption = function DropdownYearOption(_ref7) {
|
|
353
|
+
var children = _ref7.children,
|
|
354
|
+
props = _objectWithoutProperties(_ref7, _excluded2);
|
|
313
355
|
|
|
314
356
|
return components.Option && /*#__PURE__*/_jsx("div", {
|
|
315
357
|
onMouseDown: function onMouseDown(e) {
|
|
@@ -349,8 +391,9 @@ var MonthPicker = function MonthPicker(_ref4) {
|
|
|
349
391
|
"data-testid": "select-month-".concat(month),
|
|
350
392
|
"data-for": "datepicker-select-month-button",
|
|
351
393
|
$isActive: i === selectedMonth,
|
|
394
|
+
disabled: isDisabledMonth(month),
|
|
352
395
|
onClick: function onClick() {
|
|
353
|
-
setSelectedMonth(i);
|
|
396
|
+
if (!isDisabledMonth(month)) setSelectedMonth(i);
|
|
354
397
|
},
|
|
355
398
|
"aria-label": month,
|
|
356
399
|
text: month
|
|
@@ -397,28 +440,28 @@ var MonthUl = styled.ul.withConfig({
|
|
|
397
440
|
var MonthSelectButton2 = styled(ButtonSecondary).withConfig({
|
|
398
441
|
displayName: "DatePicker__MonthSelectButton2",
|
|
399
442
|
componentId: "sc-ce3xgi-4"
|
|
400
|
-
})(["padding:8px;", ""], function (
|
|
401
|
-
var $isActive =
|
|
443
|
+
})(["padding:8px;", ""], function (_ref8) {
|
|
444
|
+
var $isActive = _ref8.$isActive;
|
|
402
445
|
return $isActive && css(["background-color:", ";p{color:", ";font-weight:bold;}"], lighten(active, 0.9), active);
|
|
403
446
|
});
|
|
404
447
|
var borderRadius = "100px";
|
|
405
448
|
var Wrapper = styled.div.withConfig({
|
|
406
449
|
displayName: "DatePicker__Wrapper",
|
|
407
450
|
componentId: "sc-ce3xgi-5"
|
|
408
|
-
})(["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 (
|
|
409
|
-
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;
|
|
410
453
|
return width || "200px";
|
|
411
|
-
}, shadow500, radius500, function (
|
|
412
|
-
var hasRange = _ref9.hasRange;
|
|
413
|
-
return hasRange && css(["background-color:", ";border-radius:0;&:not(.DayPicker-Day--outside){color:", ";}"], toBgLight(active), gray01);
|
|
414
|
-
}, active, white, function (_ref10) {
|
|
454
|
+
}, shadow500, radius500, function (_ref10) {
|
|
415
455
|
var hasRange = _ref10.hasRange;
|
|
416
|
-
return hasRange && css(["
|
|
417
|
-
}, 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) {
|
|
418
458
|
var hasRange = _ref11.hasRange;
|
|
419
|
-
return hasRange && css(["::before{content:\"\";position:absolute;background-color:", ";width:10px;height:35px;top:0;
|
|
420
|
-
},
|
|
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) {
|
|
421
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;
|
|
422
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);
|
|
423
466
|
});
|
|
424
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/messages.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
[{"id":"datePicker.label.date.time.picker","defaultMessage":"Select date"},{"id":"datePicker.label.am","defaultMessage":"AM"},{"id":"datePicker.label.pm","defaultMessage":"PM"},{"id":"datePicker.label.24h","defaultMessage":"24h"},{"id":"datePicker.placeholder.time","defaultMessage":"hh:mm"},{"id":"datePicker.label.time","defaultMessage":"Time"},{"id":"datePicker.message.invalid.time","defaultMessage":"Invalid Time"},{"id":"datePicker.message.invalid.format","defaultMessage":"Invalid Format"},{"id":"datePicker.message.invalid.not.number","defaultMessage":"Given time is not a number"},{"id":"datePicker.button.prevMonth","defaultMessage":"Previous month"},{"id":"datePicker.button.nextMonth","defaultMessage":"Next month"},{"id":"datePicker.button.selectYear","defaultMessage":"Select year and month"},{"id":"datePicker.dropdown.selectYear","defaultMessage":"Select year"},{"id":"datePicker.button.closeYearMonthPicker","defaultMessage":"Done"}]
|
|
1
|
+
[{"id":"datePicker.label.date.time.picker","defaultMessage":"Select date"},{"id":"datePicker.label.am","defaultMessage":"AM"},{"id":"datePicker.label.pm","defaultMessage":"PM"},{"id":"datePicker.label.24h","defaultMessage":"24h"},{"id":"datePicker.placeholder.time","defaultMessage":"hh:mm"},{"id":"datePicker.label.time","defaultMessage":"Time"},{"id":"datePicker.message.invalid.time","defaultMessage":"Invalid Time"},{"id":"datePicker.message.formatDescription","defaultMessage":"Provide a date using the format {localeFormat}"},{"id":"datePicker.message.invalid.format","defaultMessage":"Invalid Format"},{"id":"datePicker.message.invalid.not.number","defaultMessage":"Given time is not a number"},{"id":"datePicker.button.prevMonth","defaultMessage":"Previous month"},{"id":"datePicker.button.nextMonth","defaultMessage":"Next month"},{"id":"datePicker.button.selectYear","defaultMessage":"Select year and month"},{"id":"datePicker.dropdown.selectYear","defaultMessage":"Select year"},{"id":"datePicker.button.closeYearMonthPicker","defaultMessage":"Done"}]
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@happeouikit/form-elements",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.14",
|
|
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": "268293baa140aba308ba9ecce9dd2f4758ed7a00"
|
|
49
49
|
}
|