@spaced-out/ui-design-system 0.1.109 → 0.1.111
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 +19 -0
- package/lib/components/DateRangePicker/Calendar.js +4 -2
- package/lib/components/DateRangePicker/Calendar.js.flow +11 -6
- package/lib/components/DateRangePicker/DateRangePicker.js +47 -35
- package/lib/components/DateRangePicker/DateRangePicker.js.flow +71 -70
- package/lib/components/DateRangePicker/DateRangeWrapper.js +35 -8
- package/lib/components/DateRangePicker/DateRangeWrapper.js.flow +98 -74
- package/lib/components/DateRangePicker/index.js.flow +0 -1
- package/lib/components/Input/Input.js +15 -2
- package/lib/components/Input/Input.js.flow +20 -0
- package/lib/components/Menu/Menu.js +6 -5
- package/lib/components/Menu/Menu.js.flow +15 -5
- package/lib/components/Menu/Menu.module.css +1 -1
- package/lib/types/date-range-picker.js +3 -0
- package/lib/types/date-range-picker.js.flow +18 -0
- package/lib/types/index.js +11 -0
- package/lib/types/index.js.flow +1 -0
- package/lib/types/menu.js.flow +2 -0
- package/lib/utils/date-range-picker/date-range-picker.js +306 -0
- package/lib/utils/date-range-picker/date-range-picker.js.flow +335 -0
- package/lib/utils/date-range-picker/index.js +27 -0
- package/lib/utils/date-range-picker/index.js.flow +4 -0
- package/lib/utils/index.js +11 -0
- package/lib/utils/index.js.flow +1 -0
- package/package.json +1 -1
- package/lib/components/DateRangePicker/utils.js +0 -236
- package/lib/components/DateRangePicker/utils.js.flow +0 -245
- /package/lib/{components/DateRangePicker → utils/date-range-picker}/timezones.js +0 -0
- /package/lib/{components/DateRangePicker → utils/date-range-picker}/timezones.js.flow +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,25 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [0.1.111](https://github.com/spaced-out/ui-design-system/compare/v0.1.110...v0.1.111) (2024-07-15)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* group title action menu & minDate/maxDate support in DateRangePicker ([#226](https://github.com/spaced-out/ui-design-system/issues/226)) ([cba21e6](https://github.com/spaced-out/ui-design-system/commit/cba21e604a53043a5d17d495346d5e37f3097d81))
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* date range picker default startDate and endDate ([#241](https://github.com/spaced-out/ui-design-system/issues/241)) ([ce3527b](https://github.com/spaced-out/ui-design-system/commit/ce3527bdd41913dc1179632be249ae599005a1d5))
|
|
16
|
+
|
|
17
|
+
### [0.1.110](https://github.com/spaced-out/ui-design-system/compare/v0.1.109...v0.1.110) (2024-07-12)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Bug Fixes
|
|
21
|
+
|
|
22
|
+
* 🔢 prevents users from typing exponent characters in the number input field based on a prop ([#240](https://github.com/spaced-out/ui-design-system/issues/240)) ([db982e2](https://github.com/spaced-out/ui-design-system/commit/db982e2fbf754a57b778ee5b35de1dd39853bcda))
|
|
23
|
+
|
|
5
24
|
### [0.1.109](https://github.com/spaced-out/ui-design-system/compare/v0.1.108...v0.1.109) (2024-07-11)
|
|
6
25
|
|
|
7
26
|
|
|
@@ -6,9 +6,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.Calendar = void 0;
|
|
7
7
|
var React = _interopRequireWildcard(require("react"));
|
|
8
8
|
var _momentTimezone = _interopRequireDefault(require("moment-timezone"));
|
|
9
|
+
var _utils = require("../../utils");
|
|
9
10
|
var _Text = require("../Text");
|
|
10
11
|
var _Day = require("./Day");
|
|
11
|
-
var _utils = require("./utils");
|
|
12
12
|
var _CalendarModule = _interopRequireDefault(require("./Calendar.module.css"));
|
|
13
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
14
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
@@ -32,6 +32,8 @@ const Calendar = _ref => {
|
|
|
32
32
|
let {
|
|
33
33
|
value,
|
|
34
34
|
marker,
|
|
35
|
+
minDate,
|
|
36
|
+
maxDate = (0, _utils.formatIsoDate)(),
|
|
35
37
|
handlers,
|
|
36
38
|
hoverDay,
|
|
37
39
|
dateRange,
|
|
@@ -67,7 +69,7 @@ const Calendar = _ref => {
|
|
|
67
69
|
onClick: () => onDayClick(date),
|
|
68
70
|
onHover: () => onDayHover(date),
|
|
69
71
|
outlined: (0, _momentTimezone.default)(date).isSame((0, _momentTimezone.default)(), 'd'),
|
|
70
|
-
disabled: (0, _momentTimezone.default)(date).
|
|
72
|
+
disabled: minDate && (0, _momentTimezone.default)(date).isBefore(minDate) || (0, _momentTimezone.default)(date).isAfter(maxDate) || !(0, _momentTimezone.default)(date).isSame((0, _momentTimezone.default)(value), 'month'),
|
|
71
73
|
endOfRange: isEnd && !isRangeValid,
|
|
72
74
|
highlighted: highlighted && !isRangeValid,
|
|
73
75
|
startOfRange: isStart && !isRangeValid,
|
|
@@ -4,11 +4,8 @@ import * as React from 'react';
|
|
|
4
4
|
// $FlowFixMe[untyped-import]
|
|
5
5
|
import moment from 'moment-timezone';
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
import {Day} from './Day';
|
|
7
|
+
import type {DateRange} from '../../types';
|
|
10
8
|
import {
|
|
11
|
-
type DateRange,
|
|
12
9
|
formatIsoDate,
|
|
13
10
|
getDaysInMonth,
|
|
14
11
|
inDateRange,
|
|
@@ -18,7 +15,10 @@ import {
|
|
|
18
15
|
MARKERS,
|
|
19
16
|
NAVIGATION_ACTION,
|
|
20
17
|
WEEKDAYS,
|
|
21
|
-
} from '
|
|
18
|
+
} from '../../utils';
|
|
19
|
+
import {BodySmall, SubTitleExtraSmall, TEXT_COLORS} from '../Text';
|
|
20
|
+
|
|
21
|
+
import {Day} from './Day';
|
|
22
22
|
|
|
23
23
|
import css from './Calendar.module.css';
|
|
24
24
|
|
|
@@ -26,6 +26,8 @@ import css from './Calendar.module.css';
|
|
|
26
26
|
type CalendarProps = {
|
|
27
27
|
value: string,
|
|
28
28
|
marker: $Values<typeof MARKERS>,
|
|
29
|
+
minDate?: string,
|
|
30
|
+
maxDate?: string,
|
|
29
31
|
hoverDay: string,
|
|
30
32
|
dateRange: DateRange,
|
|
31
33
|
inHoverRange: (day: string) => boolean,
|
|
@@ -54,6 +56,8 @@ const getFormattedDate = (marker: string, dateRange: DateRange) => {
|
|
|
54
56
|
export const Calendar = ({
|
|
55
57
|
value,
|
|
56
58
|
marker,
|
|
59
|
+
minDate,
|
|
60
|
+
maxDate = formatIsoDate(),
|
|
57
61
|
handlers,
|
|
58
62
|
hoverDay,
|
|
59
63
|
dateRange,
|
|
@@ -98,7 +102,8 @@ export const Calendar = ({
|
|
|
98
102
|
onHover={() => onDayHover(date)}
|
|
99
103
|
outlined={moment(date).isSame(moment(), 'd')}
|
|
100
104
|
disabled={
|
|
101
|
-
moment(date).
|
|
105
|
+
(minDate && moment(date).isBefore(minDate)) ||
|
|
106
|
+
moment(date).isAfter(maxDate) ||
|
|
102
107
|
!moment(date).isSame(moment(value), 'month')
|
|
103
108
|
}
|
|
104
109
|
endOfRange={isEnd && !isRangeValid}
|
|
@@ -6,9 +6,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.DateRangePicker = void 0;
|
|
7
7
|
var React = _interopRequireWildcard(require("react"));
|
|
8
8
|
var _momentTimezone = _interopRequireDefault(require("moment-timezone"));
|
|
9
|
+
var _utils = require("../../utils");
|
|
9
10
|
var _classify = _interopRequireDefault(require("../../utils/classify"));
|
|
10
11
|
var _DateRangeWrapper = require("./DateRangeWrapper");
|
|
11
|
-
var _utils = require("./utils");
|
|
12
12
|
var _DateRangePickerModule = _interopRequireDefault(require("./DateRangePicker.module.css"));
|
|
13
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
14
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
@@ -18,44 +18,61 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
|
18
18
|
|
|
19
19
|
const DateRangePicker = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
20
20
|
let {
|
|
21
|
+
minDate,
|
|
22
|
+
maxDate,
|
|
21
23
|
onApply,
|
|
24
|
+
onError,
|
|
22
25
|
onCancel,
|
|
23
26
|
classNames,
|
|
24
|
-
|
|
25
|
-
|
|
27
|
+
hideTimezone = false,
|
|
28
|
+
selectedDateRange = {}
|
|
26
29
|
} = _ref;
|
|
27
30
|
const today = (0, _utils.formatIsoDate)();
|
|
28
31
|
const {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const [timezone, setTimezone] = React.useState(initialTimezone);
|
|
35
|
-
const [rangeStartMonth, setRangeStartMonth] = React.useState(monthRange.rangeStartMonth);
|
|
36
|
-
const [rangeEndMonth, setRangeEndMonth] = React.useState(monthRange.rangeEndMonth);
|
|
37
|
-
const [hoverDay, setHoverDay] = React.useState('');
|
|
32
|
+
validMinDate,
|
|
33
|
+
validMaxDate,
|
|
34
|
+
validTimezone,
|
|
35
|
+
validDateRange
|
|
36
|
+
} = (0, _utils.getValidDates)(selectedDateRange, minDate, maxDate, onError);
|
|
38
37
|
const {
|
|
39
38
|
startDate,
|
|
40
39
|
endDate
|
|
41
|
-
} =
|
|
40
|
+
} = validDateRange;
|
|
41
|
+
const validRangeEndMonth = endDate ? (0, _utils.getMonthEndDate)(endDate) : (0, _utils.getMonthEndDate)(today);
|
|
42
|
+
const validRangeStartMonth = startDate && !(0, _momentTimezone.default)(startDate).isSame(endDate, 'M') ? (0, _utils.getMonthEndDate)(startDate) : (0, _utils.getMonthEndDate)((0, _utils.getSubtractedDate)(validRangeEndMonth, 1, 'M'));
|
|
43
|
+
const [dateRange, setDateRange] = React.useState(validDateRange);
|
|
44
|
+
const [timezone, setTimezone] = React.useState(validTimezone);
|
|
45
|
+
const [hoverDay, setHoverDay] = React.useState('');
|
|
46
|
+
const [rangeStartMonth, setRangeStartMonth] = React.useState(validRangeStartMonth);
|
|
47
|
+
const [rangeEndMonth, setRangeEndMonth] = React.useState(validRangeEndMonth);
|
|
42
48
|
const setRangeStartMonthValidated = date => {
|
|
43
|
-
if ((0, _momentTimezone.default)(date).
|
|
44
|
-
setRangeStartMonth(
|
|
49
|
+
if ((0, _momentTimezone.default)(date).isSameOrAfter(validMinDate) && (0, _momentTimezone.default)(date).isBefore(rangeEndMonth)) {
|
|
50
|
+
setRangeStartMonth(date);
|
|
45
51
|
} else {
|
|
46
|
-
setRangeStartMonth((0, _utils.
|
|
52
|
+
setRangeStartMonth((0, _utils.getMonthEndDate)(validMinDate));
|
|
47
53
|
}
|
|
48
54
|
};
|
|
49
55
|
const setRangeEndMonthValidated = date => {
|
|
50
|
-
if ((0, _momentTimezone.default)(date).
|
|
51
|
-
setRangeEndMonth(
|
|
52
|
-
} else if ((0, _momentTimezone.default)(date).isAfter(rangeStartMonth)) {
|
|
53
|
-
setRangeEndMonth((0, _utils.getMonthStartDate)(today));
|
|
56
|
+
if ((0, _momentTimezone.default)(date).isSameOrBefore(validMaxDate) && (0, _momentTimezone.default)(date).isAfter(rangeStartMonth)) {
|
|
57
|
+
setRangeEndMonth(date);
|
|
54
58
|
} else {
|
|
55
|
-
setRangeEndMonth((0, _utils.
|
|
59
|
+
setRangeEndMonth((0, _utils.getMonthEndDate)(validMaxDate));
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
const onMonthNavigate = (marker, action) => {
|
|
63
|
+
if (marker === _utils.MARKERS.DATE_RANGE_START) {
|
|
64
|
+
const newMonth = action === _utils.NAVIGATION_ACTION.NEXT ? (0, _utils.getMonthEndDate)((0, _utils.getAddedDate)(rangeStartMonth, 1, 'M')) : (0, _utils.getMonthEndDate)((0, _utils.getSubtractedDate)(rangeStartMonth, 1, 'M'));
|
|
65
|
+
setRangeStartMonthValidated(newMonth);
|
|
66
|
+
} else {
|
|
67
|
+
const newMonth = action === _utils.NAVIGATION_ACTION.NEXT ? (0, _utils.getMonthEndDate)((0, _utils.getAddedDate)(rangeEndMonth, 1, 'M')) : (0, _utils.getMonthEndDate)((0, _utils.getSubtractedDate)(rangeEndMonth, 1, 'M'));
|
|
68
|
+
setRangeEndMonthValidated(newMonth);
|
|
56
69
|
}
|
|
57
70
|
};
|
|
58
71
|
const onDayClick = day => {
|
|
72
|
+
const {
|
|
73
|
+
startDate,
|
|
74
|
+
endDate
|
|
75
|
+
} = dateRange;
|
|
59
76
|
if (startDate && !endDate && (0, _momentTimezone.default)(day).isSameOrAfter(startDate)) {
|
|
60
77
|
setDateRange({
|
|
61
78
|
startDate,
|
|
@@ -68,27 +85,22 @@ const DateRangePicker = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
68
85
|
}
|
|
69
86
|
setHoverDay(day);
|
|
70
87
|
};
|
|
71
|
-
const
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
if (isBeforeCurrentMonth && isValidMonth) {
|
|
78
|
-
isRangeStartMonth ? setRangeStartMonth(newMonth) : setRangeEndMonth(newMonth);
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
const inHoverRange = day => Boolean(startDate && !endDate && hoverDay && (0, _momentTimezone.default)(hoverDay).isAfter((0, _momentTimezone.default)(startDate)) && (0, _momentTimezone.default)(day).isBetween((0, _momentTimezone.default)(startDate), (0, _momentTimezone.default)(hoverDay), null, '[]'));
|
|
82
|
-
const onDayHover = date => {
|
|
83
|
-
setHoverDay(date);
|
|
88
|
+
const inHoverRange = day => {
|
|
89
|
+
const {
|
|
90
|
+
startDate,
|
|
91
|
+
endDate
|
|
92
|
+
} = dateRange;
|
|
93
|
+
return Boolean(startDate && !endDate && hoverDay && (0, _momentTimezone.default)(hoverDay).isAfter((0, _momentTimezone.default)(startDate)) && (0, _momentTimezone.default)(day).isBetween((0, _momentTimezone.default)(startDate), (0, _momentTimezone.default)(hoverDay), null, '[]'));
|
|
84
94
|
};
|
|
85
95
|
const handlers = {
|
|
86
96
|
onDayClick,
|
|
87
|
-
onDayHover,
|
|
97
|
+
onDayHover: setHoverDay,
|
|
88
98
|
onMonthNavigate
|
|
89
99
|
};
|
|
90
100
|
return /*#__PURE__*/React.createElement(_DateRangeWrapper.DateRangeWrapper, {
|
|
91
101
|
ref: ref,
|
|
102
|
+
minDate: validMinDate,
|
|
103
|
+
maxDate: validMaxDate,
|
|
92
104
|
onApply: onApply,
|
|
93
105
|
handlers: handlers,
|
|
94
106
|
hoverDay: hoverDay,
|
|
@@ -4,19 +4,23 @@ import * as React from 'react';
|
|
|
4
4
|
// $FlowFixMe[untyped-import]
|
|
5
5
|
import moment from 'moment-timezone';
|
|
6
6
|
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
import type {
|
|
8
|
+
DateRange,
|
|
9
|
+
DateRangePickerError,
|
|
10
|
+
DateRangeWithTimezone,
|
|
11
|
+
} from '../../types';
|
|
11
12
|
import {
|
|
12
13
|
formatIsoDate,
|
|
13
14
|
getAddedDate,
|
|
14
|
-
|
|
15
|
-
getMonthStartDate,
|
|
15
|
+
getMonthEndDate,
|
|
16
16
|
getSubtractedDate,
|
|
17
|
+
getValidDates,
|
|
17
18
|
MARKERS,
|
|
18
19
|
NAVIGATION_ACTION,
|
|
19
|
-
} from '
|
|
20
|
+
} from '../../utils';
|
|
21
|
+
import classify from '../../utils/classify';
|
|
22
|
+
|
|
23
|
+
import {DateRangeWrapper} from './DateRangeWrapper';
|
|
20
24
|
|
|
21
25
|
import css from './DateRangePicker.module.css';
|
|
22
26
|
|
|
@@ -27,8 +31,11 @@ export type DateRangePickerProps = {
|
|
|
27
31
|
classNames?: ClassNames,
|
|
28
32
|
selectedDateRange?: DateRangeWithTimezone,
|
|
29
33
|
onApply: (datePickerSelectedRange: DateRangeWithTimezone) => void,
|
|
34
|
+
onError?: (DateRangePickerError) => void,
|
|
30
35
|
onCancel: () => void,
|
|
31
36
|
hideTimezone?: boolean,
|
|
37
|
+
minDate?: string,
|
|
38
|
+
maxDate?: string,
|
|
32
39
|
};
|
|
33
40
|
|
|
34
41
|
export const DateRangePicker: React$AbstractComponent<
|
|
@@ -37,63 +44,84 @@ export const DateRangePicker: React$AbstractComponent<
|
|
|
37
44
|
> = React.forwardRef<DateRangePickerProps, HTMLDivElement>(
|
|
38
45
|
(
|
|
39
46
|
{
|
|
47
|
+
minDate,
|
|
48
|
+
maxDate,
|
|
40
49
|
onApply,
|
|
50
|
+
onError,
|
|
41
51
|
onCancel,
|
|
42
52
|
classNames,
|
|
43
|
-
selectedDateRange = {},
|
|
44
53
|
hideTimezone = false,
|
|
54
|
+
selectedDateRange = {},
|
|
45
55
|
}: DateRangePickerProps,
|
|
46
56
|
ref,
|
|
47
57
|
): React.Node => {
|
|
48
58
|
const today = formatIsoDate();
|
|
49
59
|
|
|
50
|
-
const {
|
|
51
|
-
|
|
52
|
-
dateRange: initialRange,
|
|
53
|
-
monthRange,
|
|
54
|
-
} = getInitialDates(selectedDateRange);
|
|
60
|
+
const {validMinDate, validMaxDate, validTimezone, validDateRange} =
|
|
61
|
+
getValidDates(selectedDateRange, minDate, maxDate, onError);
|
|
55
62
|
|
|
56
|
-
const
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const [hoverDay, setHoverDay] = React.useState<string>('');
|
|
63
|
+
const {startDate, endDate} = validDateRange;
|
|
64
|
+
const validRangeEndMonth = endDate
|
|
65
|
+
? getMonthEndDate(endDate)
|
|
66
|
+
: getMonthEndDate(today);
|
|
67
|
+
const validRangeStartMonth =
|
|
68
|
+
startDate && !moment(startDate).isSame(endDate, 'M')
|
|
69
|
+
? getMonthEndDate(startDate)
|
|
70
|
+
: getMonthEndDate(getSubtractedDate(validRangeEndMonth, 1, 'M'));
|
|
65
71
|
|
|
66
|
-
const
|
|
72
|
+
const [dateRange, setDateRange] = React.useState<DateRange>(validDateRange);
|
|
73
|
+
const [timezone, setTimezone] = React.useState<string>(validTimezone);
|
|
74
|
+
const [hoverDay, setHoverDay] = React.useState<string>('');
|
|
75
|
+
const [rangeStartMonth, setRangeStartMonth] =
|
|
76
|
+
React.useState<string>(validRangeStartMonth);
|
|
77
|
+
const [rangeEndMonth, setRangeEndMonth] =
|
|
78
|
+
React.useState<string>(validRangeEndMonth);
|
|
67
79
|
|
|
68
80
|
const setRangeStartMonthValidated = (date: string) => {
|
|
69
81
|
if (
|
|
70
|
-
moment(date).
|
|
71
|
-
moment(date).isBefore(
|
|
82
|
+
moment(date).isSameOrAfter(validMinDate) &&
|
|
83
|
+
moment(date).isBefore(rangeEndMonth)
|
|
72
84
|
) {
|
|
73
|
-
setRangeStartMonth(
|
|
85
|
+
setRangeStartMonth(date);
|
|
74
86
|
} else {
|
|
75
|
-
setRangeStartMonth(
|
|
76
|
-
getMonthStartDate(getSubtractedDate(rangeEndMonth, 1, 'M')),
|
|
77
|
-
);
|
|
87
|
+
setRangeStartMonth(getMonthEndDate(validMinDate));
|
|
78
88
|
}
|
|
79
89
|
};
|
|
80
90
|
|
|
81
91
|
const setRangeEndMonthValidated = (date: string) => {
|
|
82
92
|
if (
|
|
83
|
-
moment(date).
|
|
84
|
-
moment(date).
|
|
93
|
+
moment(date).isSameOrBefore(validMaxDate) &&
|
|
94
|
+
moment(date).isAfter(rangeStartMonth)
|
|
85
95
|
) {
|
|
86
|
-
setRangeEndMonth(
|
|
87
|
-
} else
|
|
88
|
-
setRangeEndMonth(
|
|
96
|
+
setRangeEndMonth(date);
|
|
97
|
+
} else {
|
|
98
|
+
setRangeEndMonth(getMonthEndDate(validMaxDate));
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const onMonthNavigate = (
|
|
103
|
+
marker: $Values<typeof MARKERS>,
|
|
104
|
+
action: $Values<typeof NAVIGATION_ACTION>,
|
|
105
|
+
) => {
|
|
106
|
+
if (marker === MARKERS.DATE_RANGE_START) {
|
|
107
|
+
const newMonth =
|
|
108
|
+
action === NAVIGATION_ACTION.NEXT
|
|
109
|
+
? getMonthEndDate(getAddedDate(rangeStartMonth, 1, 'M'))
|
|
110
|
+
: getMonthEndDate(getSubtractedDate(rangeStartMonth, 1, 'M'));
|
|
111
|
+
|
|
112
|
+
setRangeStartMonthValidated(newMonth);
|
|
89
113
|
} else {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
114
|
+
const newMonth =
|
|
115
|
+
action === NAVIGATION_ACTION.NEXT
|
|
116
|
+
? getMonthEndDate(getAddedDate(rangeEndMonth, 1, 'M'))
|
|
117
|
+
: getMonthEndDate(getSubtractedDate(rangeEndMonth, 1, 'M'));
|
|
118
|
+
|
|
119
|
+
setRangeEndMonthValidated(newMonth);
|
|
93
120
|
}
|
|
94
121
|
};
|
|
95
122
|
|
|
96
123
|
const onDayClick = (day: string) => {
|
|
124
|
+
const {startDate, endDate} = dateRange;
|
|
97
125
|
if (startDate && !endDate && moment(day).isSameOrAfter(startDate)) {
|
|
98
126
|
setDateRange({startDate, endDate: day});
|
|
99
127
|
} else {
|
|
@@ -102,35 +130,9 @@ export const DateRangePicker: React$AbstractComponent<
|
|
|
102
130
|
setHoverDay(day);
|
|
103
131
|
};
|
|
104
132
|
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
) => {
|
|
109
|
-
const [firstMonth, secondMonth] =
|
|
110
|
-
marker === MARKERS.DATE_RANGE_START
|
|
111
|
-
? [rangeStartMonth, rangeEndMonth]
|
|
112
|
-
: [rangeEndMonth, rangeStartMonth];
|
|
113
|
-
|
|
114
|
-
const newMonth =
|
|
115
|
-
action === NAVIGATION_ACTION.NEXT
|
|
116
|
-
? getMonthStartDate(getAddedDate(firstMonth, 1, 'M'))
|
|
117
|
-
: getMonthStartDate(getSubtractedDate(firstMonth, 1, 'M'));
|
|
118
|
-
|
|
119
|
-
const isRangeStartMonth = marker === MARKERS.DATE_RANGE_START;
|
|
120
|
-
const isBeforeCurrentMonth = moment(newMonth).isBefore(moment());
|
|
121
|
-
const isValidMonth = isRangeStartMonth
|
|
122
|
-
? moment(newMonth).isBefore(moment(secondMonth))
|
|
123
|
-
: moment(secondMonth).isBefore(moment(newMonth));
|
|
124
|
-
|
|
125
|
-
if (isBeforeCurrentMonth && isValidMonth) {
|
|
126
|
-
isRangeStartMonth
|
|
127
|
-
? setRangeStartMonth(newMonth)
|
|
128
|
-
: setRangeEndMonth(newMonth);
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
const inHoverRange = (day: string): boolean =>
|
|
133
|
-
Boolean(
|
|
133
|
+
const inHoverRange = (day: string): boolean => {
|
|
134
|
+
const {startDate, endDate} = dateRange;
|
|
135
|
+
return Boolean(
|
|
134
136
|
startDate &&
|
|
135
137
|
!endDate &&
|
|
136
138
|
hoverDay &&
|
|
@@ -142,20 +144,19 @@ export const DateRangePicker: React$AbstractComponent<
|
|
|
142
144
|
'[]',
|
|
143
145
|
),
|
|
144
146
|
);
|
|
145
|
-
|
|
146
|
-
const onDayHover = (date: string) => {
|
|
147
|
-
setHoverDay(date);
|
|
148
147
|
};
|
|
149
148
|
|
|
150
149
|
const handlers = {
|
|
151
150
|
onDayClick,
|
|
152
|
-
onDayHover,
|
|
151
|
+
onDayHover: setHoverDay,
|
|
153
152
|
onMonthNavigate,
|
|
154
153
|
};
|
|
155
154
|
|
|
156
155
|
return (
|
|
157
156
|
<DateRangeWrapper
|
|
158
157
|
ref={ref}
|
|
158
|
+
minDate={validMinDate}
|
|
159
|
+
maxDate={validMaxDate}
|
|
159
160
|
onApply={onApply}
|
|
160
161
|
handlers={handlers}
|
|
161
162
|
hoverDay={hoverDay}
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.DateRangeWrapper = void 0;
|
|
7
7
|
var React = _interopRequireWildcard(require("react"));
|
|
8
8
|
var _momentTimezone = _interopRequireDefault(require("moment-timezone"));
|
|
9
|
+
var _utils = require("../../utils");
|
|
9
10
|
var _classify = _interopRequireDefault(require("../../utils/classify"));
|
|
10
11
|
var _Button = require("../Button");
|
|
11
12
|
var _Card = require("../Card");
|
|
@@ -13,7 +14,6 @@ var _Dropdown = require("../Dropdown");
|
|
|
13
14
|
var _FocusManager = require("../FocusManager");
|
|
14
15
|
var _Icon = require("../Icon");
|
|
15
16
|
var _Calendar = require("./Calendar.js");
|
|
16
|
-
var _utils = require("./utils");
|
|
17
17
|
var _DateRangeWrapperModule = _interopRequireDefault(require("./DateRangeWrapper.module.css"));
|
|
18
18
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
19
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
@@ -23,6 +23,8 @@ const CalendarHeader = _ref => {
|
|
|
23
23
|
let {
|
|
24
24
|
date,
|
|
25
25
|
marker,
|
|
26
|
+
minDate,
|
|
27
|
+
maxDate,
|
|
26
28
|
setMonth,
|
|
27
29
|
rangeStartMonth,
|
|
28
30
|
rangeEndMonth,
|
|
@@ -31,6 +33,20 @@ const CalendarHeader = _ref => {
|
|
|
31
33
|
prevDisabled,
|
|
32
34
|
onClickPrevious
|
|
33
35
|
} = _ref;
|
|
36
|
+
const availableYears = (0, _utils.generateAvailableYears)({
|
|
37
|
+
marker,
|
|
38
|
+
minDate,
|
|
39
|
+
maxDate,
|
|
40
|
+
rangeStartMonth,
|
|
41
|
+
rangeEndMonth
|
|
42
|
+
});
|
|
43
|
+
const availableMonths = (0, _utils.getAvailableMonths)({
|
|
44
|
+
marker,
|
|
45
|
+
minDate,
|
|
46
|
+
maxDate,
|
|
47
|
+
rangeStartMonth,
|
|
48
|
+
rangeEndMonth
|
|
49
|
+
});
|
|
34
50
|
return /*#__PURE__*/React.createElement("div", {
|
|
35
51
|
className: _DateRangeWrapperModule.default.calendarHeader
|
|
36
52
|
}, /*#__PURE__*/React.createElement(_Icon.ClickableIcon, {
|
|
@@ -44,23 +60,25 @@ const CalendarHeader = _ref => {
|
|
|
44
60
|
color: prevDisabled ? 'disabled' : 'secondary'
|
|
45
61
|
}), /*#__PURE__*/React.createElement(_Dropdown.Dropdown, {
|
|
46
62
|
size: "small",
|
|
63
|
+
disabled: !availableMonths.length || (0, _momentTimezone.default)(minDate).isAfter(maxDate),
|
|
47
64
|
menu: {
|
|
48
65
|
selectedKeys: [(0, _momentTimezone.default)(date).month().toString()],
|
|
49
|
-
options:
|
|
66
|
+
options: availableMonths
|
|
50
67
|
},
|
|
51
68
|
onChange: event => {
|
|
52
|
-
setMonth((0, _utils.
|
|
69
|
+
setMonth((0, _utils.getMonthEndDate)((0, _momentTimezone.default)(date).set('M', event.key)));
|
|
53
70
|
},
|
|
54
71
|
dropdownInputText: _utils.MONTHS[(0, _momentTimezone.default)(date).month()].label,
|
|
55
72
|
scrollMenuToBottom: true
|
|
56
73
|
}), /*#__PURE__*/React.createElement(_Dropdown.Dropdown, {
|
|
74
|
+
disabled: !availableYears.length || (0, _momentTimezone.default)(minDate).isAfter(maxDate),
|
|
57
75
|
menu: {
|
|
58
76
|
selectedKeys: [(0, _momentTimezone.default)(date).year().toString()],
|
|
59
|
-
options:
|
|
77
|
+
options: availableYears
|
|
60
78
|
},
|
|
61
79
|
size: "small",
|
|
62
80
|
onChange: event => {
|
|
63
|
-
setMonth((0, _utils.
|
|
81
|
+
setMonth((0, _utils.getMonthEndDate)((0, _momentTimezone.default)(date).set('y', event.key)));
|
|
64
82
|
},
|
|
65
83
|
dropdownInputText: (0, _momentTimezone.default)(date).year(),
|
|
66
84
|
scrollMenuToBottom: true
|
|
@@ -81,6 +99,8 @@ const DateRangeWrapper = /*#__PURE__*/React.forwardRef((_ref2, ref) => {
|
|
|
81
99
|
onCancel,
|
|
82
100
|
handlers,
|
|
83
101
|
hoverDay,
|
|
102
|
+
minDate,
|
|
103
|
+
maxDate,
|
|
84
104
|
timezone,
|
|
85
105
|
dateRange,
|
|
86
106
|
rangeStartMonth,
|
|
@@ -115,7 +135,9 @@ const DateRangeWrapper = /*#__PURE__*/React.forwardRef((_ref2, ref) => {
|
|
|
115
135
|
inHoverRange,
|
|
116
136
|
handlers,
|
|
117
137
|
hoverDay,
|
|
118
|
-
dateRange
|
|
138
|
+
dateRange,
|
|
139
|
+
minDate,
|
|
140
|
+
maxDate
|
|
119
141
|
};
|
|
120
142
|
return /*#__PURE__*/React.createElement(_FocusManager.FocusManager, null, /*#__PURE__*/React.createElement(_Card.Card, {
|
|
121
143
|
classNames: {
|
|
@@ -131,7 +153,9 @@ const DateRangeWrapper = /*#__PURE__*/React.forwardRef((_ref2, ref) => {
|
|
|
131
153
|
date: rangeStartMonth,
|
|
132
154
|
setMonth: setRangeStartMonth,
|
|
133
155
|
nextDisabled: !canNavigateCloser,
|
|
134
|
-
prevDisabled:
|
|
156
|
+
prevDisabled: (0, _momentTimezone.default)(rangeStartMonth).isSameOrBefore(minDate, 'M'),
|
|
157
|
+
minDate: minDate,
|
|
158
|
+
maxDate: maxDate,
|
|
135
159
|
onClickNext: () => onMonthNavigate(_utils.MARKERS.DATE_RANGE_START, _utils.NAVIGATION_ACTION.NEXT),
|
|
136
160
|
onClickPrevious: () => onMonthNavigate(_utils.MARKERS.DATE_RANGE_START, _utils.NAVIGATION_ACTION.PREV)
|
|
137
161
|
}), /*#__PURE__*/React.createElement(CalendarHeader, {
|
|
@@ -140,8 +164,10 @@ const DateRangeWrapper = /*#__PURE__*/React.forwardRef((_ref2, ref) => {
|
|
|
140
164
|
rangeEndMonth: rangeEndMonth,
|
|
141
165
|
date: rangeEndMonth,
|
|
142
166
|
setMonth: setRangeEndMonth,
|
|
143
|
-
nextDisabled: (0, _momentTimezone.default)(
|
|
167
|
+
nextDisabled: (0, _momentTimezone.default)(rangeEndMonth).isSameOrAfter(maxDate, 'M'),
|
|
144
168
|
prevDisabled: !canNavigateCloser,
|
|
169
|
+
minDate: minDate,
|
|
170
|
+
maxDate: maxDate,
|
|
145
171
|
onClickNext: () => onMonthNavigate(_utils.MARKERS.DATE_RANGE_END, _utils.NAVIGATION_ACTION.NEXT),
|
|
146
172
|
onClickPrevious: () => onMonthNavigate(_utils.MARKERS.DATE_RANGE_END, _utils.NAVIGATION_ACTION.PREV)
|
|
147
173
|
})), /*#__PURE__*/React.createElement(_Card.CardContent, {
|
|
@@ -158,6 +184,7 @@ const DateRangeWrapper = /*#__PURE__*/React.forwardRef((_ref2, ref) => {
|
|
|
158
184
|
className: _DateRangeWrapperModule.default.timezoneDropdownContainer
|
|
159
185
|
}, !hideTimezone && /*#__PURE__*/React.createElement(_Dropdown.SimpleDropdown, {
|
|
160
186
|
options: (0, _utils.getTimezones)(),
|
|
187
|
+
disabled: (0, _momentTimezone.default)(minDate).isAfter(maxDate),
|
|
161
188
|
classNames: {
|
|
162
189
|
box: _DateRangeWrapperModule.default.timezoneDropdown
|
|
163
190
|
},
|