@spaced-out/ui-design-system 0.1.93 → 0.1.94-beta.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 +14 -0
- package/lib/components/ChartWrapper/ChartWrapper.js +8 -2
- package/lib/components/ChartWrapper/ChartWrapper.js.flow +31 -15
- package/lib/components/ChartWrapper/ChartWrapper.module.css +8 -1
- package/lib/components/Charts/index.js +11 -0
- package/lib/components/Charts/index.js.flow +1 -0
- package/lib/components/ColumnChart/ColumnChart.js +2 -0
- package/lib/components/ColumnChart/ColumnChart.js.flow +9 -6
- package/lib/components/DateRangePicker/Calendar.js +7 -3
- package/lib/components/DateRangePicker/Calendar.js.flow +5 -3
- package/lib/components/DateRangePicker/DateRangePicker.js +23 -37
- package/lib/components/DateRangePicker/DateRangePicker.js.flow +53 -55
- package/lib/components/DateRangePicker/DateRangeWrapper.js +15 -10
- package/lib/components/DateRangePicker/DateRangeWrapper.js.flow +20 -16
- package/lib/components/DateRangePicker/Day.js +5 -7
- package/lib/components/DateRangePicker/Day.js.flow +4 -10
- package/lib/components/DateRangePicker/Day.module.css +7 -20
- package/lib/components/DateRangePicker/index.js.flow +1 -0
- package/lib/components/DateRangePicker/utils.js +87 -72
- package/lib/components/DateRangePicker/utils.js.flow +111 -103
- package/lib/components/DonutChart/DonutChart.js +5 -3
- package/lib/components/DonutChart/DonutChart.js.flow +6 -6
- package/lib/components/Dropdown/Dropdown.js +6 -0
- package/lib/components/Dropdown/Dropdown.js.flow +6 -0
- package/lib/components/Dropdown/SimpleDropdown.js +2 -0
- package/lib/components/Dropdown/SimpleDropdown.js.flow +4 -1
- package/lib/components/LineChart/LineChart.js +2 -0
- package/lib/components/LineChart/LineChart.js.flow +7 -4
- package/lib/components/Menu/Menu.js +48 -4
- package/lib/components/Menu/Menu.js.flow +79 -13
- package/lib/components/Menu/MenuOptionButton.js +3 -1
- package/lib/components/Menu/MenuOptionButton.js.flow +3 -0
- package/lib/components/SpiderChart/SpiderChart.js +2 -0
- package/lib/components/SpiderChart/SpiderChart.js.flow +5 -14
- package/lib/components/StickyBar/StickyBar.module.css +2 -2
- package/lib/types/charts.js.flow +47 -2
- package/lib/utils/charts/charts.js +8 -3
- package/lib/utils/charts/charts.js.flow +8 -3
- package/lib/utils/charts/donutChart.js +2 -7
- package/lib/utils/charts/donutChart.js.flow +2 -21
- package/package.json +3 -2
|
@@ -23,7 +23,7 @@ const CalendarHeader = _ref => {
|
|
|
23
23
|
let {
|
|
24
24
|
date,
|
|
25
25
|
marker,
|
|
26
|
-
|
|
26
|
+
setMonth,
|
|
27
27
|
rangeStartMonth,
|
|
28
28
|
rangeEndMonth,
|
|
29
29
|
onClickNext,
|
|
@@ -34,6 +34,7 @@ const CalendarHeader = _ref => {
|
|
|
34
34
|
return /*#__PURE__*/React.createElement("div", {
|
|
35
35
|
className: _DateRangeWrapperModule.default.calendarHeader
|
|
36
36
|
}, /*#__PURE__*/React.createElement(_Icon.ClickableIcon, {
|
|
37
|
+
ariaLabel: "Select Previous Month",
|
|
37
38
|
size: "small",
|
|
38
39
|
name: "chevron-left",
|
|
39
40
|
className: (0, _classify.default)(_DateRangeWrapperModule.default.headerIcon, {
|
|
@@ -44,14 +45,14 @@ const CalendarHeader = _ref => {
|
|
|
44
45
|
}), /*#__PURE__*/React.createElement(_Dropdown.Dropdown, {
|
|
45
46
|
size: "small",
|
|
46
47
|
menu: {
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
selectedKeys: [(0, _momentTimezone.default)(date).month().toString()],
|
|
49
|
+
options: (0, _utils.getAvailableMonths)(_utils.MONTHS, rangeStartMonth, rangeEndMonth, marker)
|
|
49
50
|
},
|
|
50
51
|
onChange: event => {
|
|
51
|
-
|
|
52
|
+
setMonth((0, _utils.getMonthStartDate)((0, _momentTimezone.default)(date).set('M', event.key)));
|
|
52
53
|
},
|
|
53
54
|
dropdownInputText: _utils.MONTHS[(0, _momentTimezone.default)(date).month()].label,
|
|
54
|
-
|
|
55
|
+
scrollMenuToBottom: true
|
|
55
56
|
}), /*#__PURE__*/React.createElement(_Dropdown.Dropdown, {
|
|
56
57
|
menu: {
|
|
57
58
|
selectedKeys: [(0, _momentTimezone.default)(date).year().toString()],
|
|
@@ -59,12 +60,13 @@ const CalendarHeader = _ref => {
|
|
|
59
60
|
},
|
|
60
61
|
size: "small",
|
|
61
62
|
onChange: event => {
|
|
62
|
-
|
|
63
|
+
setMonth((0, _utils.getMonthStartDate)((0, _momentTimezone.default)(date).set('y', event.key)));
|
|
63
64
|
},
|
|
64
65
|
dropdownInputText: (0, _momentTimezone.default)(date).year(),
|
|
65
|
-
|
|
66
|
+
scrollMenuToBottom: true
|
|
66
67
|
}), /*#__PURE__*/React.createElement(_Icon.ClickableIcon, {
|
|
67
68
|
size: "small",
|
|
69
|
+
ariaLabel: "Select Next Month",
|
|
68
70
|
name: "chevron-right",
|
|
69
71
|
className: (0, _classify.default)(_DateRangeWrapperModule.default.headerIcon, {
|
|
70
72
|
[_DateRangeWrapperModule.default.disabledIcon]: nextDisabled
|
|
@@ -126,7 +128,7 @@ const DateRangeWrapper = /*#__PURE__*/React.forwardRef((_ref2, ref) => {
|
|
|
126
128
|
rangeStartMonth: rangeStartMonth,
|
|
127
129
|
rangeEndMonth: rangeEndMonth,
|
|
128
130
|
date: rangeStartMonth,
|
|
129
|
-
|
|
131
|
+
setMonth: setRangeStartMonth,
|
|
130
132
|
nextDisabled: !canNavigateCloser,
|
|
131
133
|
prevDisabled: false,
|
|
132
134
|
onClickNext: () => onMonthNavigate(_utils.MARKERS.DATE_RANGE_START, _utils.NAVIGATION_ACTION.NEXT),
|
|
@@ -136,8 +138,8 @@ const DateRangeWrapper = /*#__PURE__*/React.forwardRef((_ref2, ref) => {
|
|
|
136
138
|
rangeStartMonth: rangeStartMonth,
|
|
137
139
|
rangeEndMonth: rangeEndMonth,
|
|
138
140
|
date: rangeEndMonth,
|
|
139
|
-
|
|
140
|
-
nextDisabled: (0, _momentTimezone.default)((0, _utils.getAddedDate)(rangeEndMonth, 1, 'M')).
|
|
141
|
+
setMonth: setRangeEndMonth,
|
|
142
|
+
nextDisabled: (0, _momentTimezone.default)((0, _utils.getAddedDate)(rangeEndMonth, 1, 'M')).isSameOrAfter((0, _momentTimezone.default)()),
|
|
141
143
|
prevDisabled: !canNavigateCloser,
|
|
142
144
|
onClickNext: () => onMonthNavigate(_utils.MARKERS.DATE_RANGE_END, _utils.NAVIGATION_ACTION.NEXT),
|
|
143
145
|
onClickPrevious: () => onMonthNavigate(_utils.MARKERS.DATE_RANGE_END, _utils.NAVIGATION_ACTION.PREV)
|
|
@@ -161,6 +163,9 @@ const DateRangeWrapper = /*#__PURE__*/React.forwardRef((_ref2, ref) => {
|
|
|
161
163
|
selectedKeys: [timeZone],
|
|
162
164
|
onChange: event => setTimeZone(event.key),
|
|
163
165
|
size: "small",
|
|
166
|
+
menuVirtualization: {
|
|
167
|
+
enable: true
|
|
168
|
+
},
|
|
164
169
|
allowSearch: true
|
|
165
170
|
})), /*#__PURE__*/React.createElement(_Card.CardActions, null, /*#__PURE__*/React.createElement(_Button.Button, {
|
|
166
171
|
type: "ghost",
|
|
@@ -19,14 +19,13 @@ import {FocusManager} from '../FocusManager';
|
|
|
19
19
|
import {ClickableIcon} from '../Icon';
|
|
20
20
|
|
|
21
21
|
import {Calendar} from './Calendar.js';
|
|
22
|
+
import type {DateRange, DateRangeWithTimezone} from './utils';
|
|
22
23
|
import {
|
|
23
|
-
type DatePickerSelectedRange,
|
|
24
|
-
type DateRange,
|
|
25
24
|
addTimeZone,
|
|
26
|
-
formatIsoDate,
|
|
27
25
|
generateAvailableYears,
|
|
28
26
|
getAddedDate,
|
|
29
27
|
getAvailableMonths,
|
|
28
|
+
getMonthStartDate,
|
|
30
29
|
getTimeZones,
|
|
31
30
|
MARKERS,
|
|
32
31
|
MONTHS,
|
|
@@ -45,7 +44,7 @@ type HeaderProps = {
|
|
|
45
44
|
onClickNext: () => void,
|
|
46
45
|
onClickPrevious: () => void,
|
|
47
46
|
marker: $Values<typeof MARKERS>,
|
|
48
|
-
|
|
47
|
+
setMonth: (date: string) => void,
|
|
49
48
|
};
|
|
50
49
|
|
|
51
50
|
type DateRangeWrapperProps = {
|
|
@@ -58,7 +57,7 @@ type DateRangeWrapperProps = {
|
|
|
58
57
|
setRangeEndMonth: (string) => void,
|
|
59
58
|
setTimeZone: (string) => void,
|
|
60
59
|
timeZone: string,
|
|
61
|
-
onApply: (datePickerSelectedRange:
|
|
60
|
+
onApply: (datePickerSelectedRange: DateRangeWithTimezone) => void,
|
|
62
61
|
onCancel: () => void,
|
|
63
62
|
inHoverRange: (day: string) => boolean,
|
|
64
63
|
handlers: {
|
|
@@ -74,7 +73,7 @@ type DateRangeWrapperProps = {
|
|
|
74
73
|
const CalendarHeader = ({
|
|
75
74
|
date,
|
|
76
75
|
marker,
|
|
77
|
-
|
|
76
|
+
setMonth,
|
|
78
77
|
rangeStartMonth,
|
|
79
78
|
rangeEndMonth,
|
|
80
79
|
onClickNext,
|
|
@@ -84,6 +83,7 @@ const CalendarHeader = ({
|
|
|
84
83
|
}: HeaderProps): React.Node => (
|
|
85
84
|
<div className={css.calendarHeader}>
|
|
86
85
|
<ClickableIcon
|
|
86
|
+
ariaLabel="Select Previous Month"
|
|
87
87
|
size="small"
|
|
88
88
|
name="chevron-left"
|
|
89
89
|
className={classify(css.headerIcon, {
|
|
@@ -95,19 +95,19 @@ const CalendarHeader = ({
|
|
|
95
95
|
<Dropdown
|
|
96
96
|
size="small"
|
|
97
97
|
menu={{
|
|
98
|
+
selectedKeys: [moment(date).month().toString()],
|
|
98
99
|
options: getAvailableMonths(
|
|
99
100
|
MONTHS,
|
|
100
101
|
rangeStartMonth,
|
|
101
102
|
rangeEndMonth,
|
|
102
103
|
marker,
|
|
103
104
|
),
|
|
104
|
-
selectedKeys: [moment(date).month().toString()],
|
|
105
105
|
}}
|
|
106
106
|
onChange={(event) => {
|
|
107
|
-
|
|
107
|
+
setMonth(getMonthStartDate(moment(date).set('M', event.key)));
|
|
108
108
|
}}
|
|
109
109
|
dropdownInputText={MONTHS[moment(date).month()].label}
|
|
110
|
-
|
|
110
|
+
scrollMenuToBottom
|
|
111
111
|
/>
|
|
112
112
|
<Dropdown
|
|
113
113
|
menu={{
|
|
@@ -121,13 +121,14 @@ const CalendarHeader = ({
|
|
|
121
121
|
}}
|
|
122
122
|
size="small"
|
|
123
123
|
onChange={(event) => {
|
|
124
|
-
|
|
124
|
+
setMonth(getMonthStartDate(moment(date).set('y', event.key)));
|
|
125
125
|
}}
|
|
126
126
|
dropdownInputText={moment(date).year()}
|
|
127
|
-
|
|
127
|
+
scrollMenuToBottom
|
|
128
128
|
/>
|
|
129
129
|
<ClickableIcon
|
|
130
130
|
size="small"
|
|
131
|
+
ariaLabel="Select Next Month"
|
|
131
132
|
name="chevron-right"
|
|
132
133
|
className={classify(css.headerIcon, {
|
|
133
134
|
[css.disabledIcon]: nextDisabled,
|
|
@@ -202,7 +203,7 @@ export const DateRangeWrapper: React$AbstractComponent<
|
|
|
202
203
|
rangeStartMonth={rangeStartMonth}
|
|
203
204
|
rangeEndMonth={rangeEndMonth}
|
|
204
205
|
date={rangeStartMonth}
|
|
205
|
-
|
|
206
|
+
setMonth={setRangeStartMonth}
|
|
206
207
|
nextDisabled={!canNavigateCloser}
|
|
207
208
|
prevDisabled={false}
|
|
208
209
|
onClickNext={() =>
|
|
@@ -223,10 +224,10 @@ export const DateRangeWrapper: React$AbstractComponent<
|
|
|
223
224
|
rangeStartMonth={rangeStartMonth}
|
|
224
225
|
rangeEndMonth={rangeEndMonth}
|
|
225
226
|
date={rangeEndMonth}
|
|
226
|
-
|
|
227
|
-
nextDisabled={moment(
|
|
228
|
-
|
|
229
|
-
)}
|
|
227
|
+
setMonth={setRangeEndMonth}
|
|
228
|
+
nextDisabled={moment(
|
|
229
|
+
getAddedDate(rangeEndMonth, 1, 'M'),
|
|
230
|
+
).isSameOrAfter(moment())}
|
|
230
231
|
prevDisabled={!canNavigateCloser}
|
|
231
232
|
onClickNext={() =>
|
|
232
233
|
onMonthNavigate(MARKERS.DATE_RANGE_END, NAVIGATION_ACTION.NEXT)
|
|
@@ -259,6 +260,9 @@ export const DateRangeWrapper: React$AbstractComponent<
|
|
|
259
260
|
selectedKeys={[timeZone]}
|
|
260
261
|
onChange={(event) => setTimeZone(event.key)}
|
|
261
262
|
size="small"
|
|
263
|
+
menuVirtualization={{
|
|
264
|
+
enable: true,
|
|
265
|
+
}}
|
|
262
266
|
allowSearch
|
|
263
267
|
/>
|
|
264
268
|
</CardTitle>
|
|
@@ -16,6 +16,8 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
|
16
16
|
|
|
17
17
|
// $FlowFixMe[untyped-import]
|
|
18
18
|
|
|
19
|
+
// $FlowFixMe[untyped-import]
|
|
20
|
+
|
|
19
21
|
const getTextColor = (disabled, filled) => {
|
|
20
22
|
if (disabled) {
|
|
21
23
|
return _Text.TEXT_COLORS.disabled;
|
|
@@ -43,9 +45,7 @@ const Day = _ref => {
|
|
|
43
45
|
tabIndex: disabled ? -1 : 0,
|
|
44
46
|
className: (0, _classify.default)(_DayModule.default.calendarItemButton, {
|
|
45
47
|
[_DayModule.default.calendarRowItemDisabled]: disabled,
|
|
46
|
-
[_DayModule.default.
|
|
47
|
-
[_DayModule.default.calendarRowItemBorderRight]: !disabled && !(0, _momentTimezone.default)(date).isSame((0, _momentTimezone.default)(hoverDay)) && (filled || highlighted) && startOfRange,
|
|
48
|
-
[_DayModule.default.calendarRowItemHighlighted]: !disabled && !filled && highlighted
|
|
48
|
+
[_DayModule.default.calendarRowItemHighlighted]: !disabled && (highlighted || startOfRange || endOfRange)
|
|
49
49
|
}),
|
|
50
50
|
onMouseOver: onHover,
|
|
51
51
|
onClick: onClick,
|
|
@@ -54,12 +54,10 @@ const Day = _ref => {
|
|
|
54
54
|
type: "ghost",
|
|
55
55
|
color: getTextColor(disabled, filled),
|
|
56
56
|
className: (0, _classify.default)(_DayModule.default.calendarRowItem, {
|
|
57
|
-
[_DayModule.default.calendarRowItemHover]: !disabled &&
|
|
57
|
+
[_DayModule.default.calendarRowItemHover]: !disabled && (0, _momentTimezone.default)(date).isSame(hoverDay),
|
|
58
58
|
[_DayModule.default.calendarRowItemFilled]: !disabled && filled,
|
|
59
59
|
[_DayModule.default.calendarRowItemOutlined]: !disabled && outlined
|
|
60
|
-
})
|
|
61
|
-
onMouseOver: onHover,
|
|
62
|
-
onClick: onClick
|
|
60
|
+
})
|
|
63
61
|
}, value));
|
|
64
62
|
};
|
|
65
63
|
exports.Day = Day;
|
|
@@ -3,6 +3,7 @@ import * as React from 'react';
|
|
|
3
3
|
// $FlowFixMe[untyped-import]
|
|
4
4
|
import moment from 'moment-timezone';
|
|
5
5
|
|
|
6
|
+
// $FlowFixMe[untyped-import]
|
|
6
7
|
import classify from '../../utils/classify';
|
|
7
8
|
import {UnstyledButton} from '../Button';
|
|
8
9
|
import {BodyMedium, TEXT_COLORS} from '../Text';
|
|
@@ -51,13 +52,8 @@ export const Day = ({
|
|
|
51
52
|
tabIndex={disabled ? -1 : 0}
|
|
52
53
|
className={classify(css.calendarItemButton, {
|
|
53
54
|
[css.calendarRowItemDisabled]: disabled,
|
|
54
|
-
[css.
|
|
55
|
-
|
|
56
|
-
!disabled &&
|
|
57
|
-
!moment(date).isSame(moment(hoverDay)) &&
|
|
58
|
-
(filled || highlighted) &&
|
|
59
|
-
startOfRange,
|
|
60
|
-
[css.calendarRowItemHighlighted]: !disabled && !filled && highlighted,
|
|
55
|
+
[css.calendarRowItemHighlighted]:
|
|
56
|
+
!disabled && (highlighted || startOfRange || endOfRange),
|
|
61
57
|
})}
|
|
62
58
|
onMouseOver={onHover}
|
|
63
59
|
onClick={onClick}
|
|
@@ -67,12 +63,10 @@ export const Day = ({
|
|
|
67
63
|
type="ghost"
|
|
68
64
|
color={getTextColor(disabled, filled)}
|
|
69
65
|
className={classify(css.calendarRowItem, {
|
|
70
|
-
[css.calendarRowItemHover]: !disabled &&
|
|
66
|
+
[css.calendarRowItemHover]: !disabled && moment(date).isSame(hoverDay),
|
|
71
67
|
[css.calendarRowItemFilled]: !disabled && filled,
|
|
72
68
|
[css.calendarRowItemOutlined]: !disabled && outlined,
|
|
73
69
|
})}
|
|
74
|
-
onMouseOver={onHover}
|
|
75
|
-
onClick={onClick}
|
|
76
70
|
>
|
|
77
71
|
{value}
|
|
78
72
|
</BodyMedium>
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
size2,
|
|
3
3
|
size4,
|
|
4
4
|
size5,
|
|
5
|
+
size26,
|
|
5
6
|
size30
|
|
6
7
|
) from '../../styles/variables/_size.css';
|
|
7
8
|
@value (
|
|
@@ -28,13 +29,15 @@
|
|
|
28
29
|
) from '../../styles/variables/_border.css';
|
|
29
30
|
|
|
30
31
|
.calendarItemButton {
|
|
32
|
+
display: flex;
|
|
33
|
+
align-items: center;
|
|
34
|
+
justify-content: center;
|
|
31
35
|
height: calc(size30 + size2);
|
|
32
36
|
}
|
|
33
37
|
|
|
34
38
|
.calendarItemButton:focus {
|
|
35
39
|
box-shadow: inset borderWidthNone borderWidthNone borderWidthNone
|
|
36
40
|
borderWidthTertiary colorFocusPrimary;
|
|
37
|
-
border-radius: borderRadiusSmall;
|
|
38
41
|
}
|
|
39
42
|
|
|
40
43
|
.calendarRowItem {
|
|
@@ -45,12 +48,12 @@
|
|
|
45
48
|
cursor: pointer;
|
|
46
49
|
border-radius: borderRadiusCircle;
|
|
47
50
|
box-sizing: border-box;
|
|
48
|
-
width:
|
|
49
|
-
height:
|
|
51
|
+
width: size26;
|
|
52
|
+
height: size26;
|
|
50
53
|
outline: none;
|
|
51
54
|
}
|
|
52
55
|
|
|
53
|
-
.calendarRowItemHover
|
|
56
|
+
.calendarRowItemHover {
|
|
54
57
|
background-color: colorButtonFillGhostHovered;
|
|
55
58
|
}
|
|
56
59
|
|
|
@@ -73,19 +76,3 @@
|
|
|
73
76
|
border-radius: borderRadiusNone;
|
|
74
77
|
background-color: colorBackgroundSecondary;
|
|
75
78
|
}
|
|
76
|
-
|
|
77
|
-
.calendarRowItemBorderLeft {
|
|
78
|
-
background-image: linear-gradient(
|
|
79
|
-
to left,
|
|
80
|
-
colorBackgroundTertiary spaceHalfFluid,
|
|
81
|
-
colorBackgroundSecondary spaceHalfFluid
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
.calendarRowItemBorderRight {
|
|
86
|
-
background-image: linear-gradient(
|
|
87
|
-
to right,
|
|
88
|
-
colorBackgroundTertiary spaceHalfFluid,
|
|
89
|
-
colorBackgroundSecondary spaceHalfFluid
|
|
90
|
-
);
|
|
91
|
-
}
|
|
@@ -3,10 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.addTimeZone = exports.WEEKDAYS = exports.NAVIGATION_ACTION = exports.MONTHS = exports.MARKERS = void 0;
|
|
7
|
-
exports.formatIsoDate = formatIsoDate;
|
|
8
|
-
exports.isStartOfRange = exports.isStartDateEndDateSame = exports.isEndOfRange = exports.inDateRange = exports.getValidatedMonths = exports.getTimeZones = exports.getSubtractedDate = exports.getDaysInMonth = exports.getAvailableMonths = exports.getAddedDate = exports.generateAvailableYears = void 0;
|
|
9
|
-
exports.wrangleMoment = wrangleMoment;
|
|
6
|
+
exports.wrangleMoment = exports.isStartOfRange = exports.isStartDateEndDateSame = exports.isEndOfRange = exports.inDateRange = exports.getTimeZones = exports.getSubtractedDate = exports.getMonthStartDate = exports.getInitialDates = exports.getDaysInMonth = exports.getAvailableMonths = exports.getAddedDate = exports.generateAvailableYears = exports.formatIsoDate = exports.addTimeZone = exports.WEEKDAYS = exports.NAVIGATION_ACTION = exports.MONTHS = exports.MARKERS = void 0;
|
|
10
7
|
var _formatISO = _interopRequireDefault(require("date-fns/formatISO"));
|
|
11
8
|
var _parseISO = _interopRequireDefault(require("date-fns/parseISO"));
|
|
12
9
|
var _lodash = _interopRequireDefault(require("lodash"));
|
|
@@ -70,42 +67,31 @@ const MONTHS = [{
|
|
|
70
67
|
label: 'Dec'
|
|
71
68
|
}];
|
|
72
69
|
exports.MONTHS = MONTHS;
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
while (current.isBefore(endWeek)) {
|
|
79
|
-
days.push(current.clone().format('YYYY-MM-DD'));
|
|
80
|
-
current.add(1, 'd');
|
|
81
|
-
}
|
|
82
|
-
const daysInChunks = _lodash.default.chunk(days, 7);
|
|
83
|
-
|
|
84
|
-
// if total rows in calendar are 5 add one more week to the calendar
|
|
85
|
-
if (daysInChunks.length === 5) {
|
|
86
|
-
const nextWeek = getAddedDate(endWeek, WEEKDAYS.length, 'd');
|
|
87
|
-
const extraDays = [];
|
|
88
|
-
while (current.isSameOrBefore(nextWeek)) {
|
|
89
|
-
extraDays.push(current.clone().format('YYYY-MM-DD'));
|
|
90
|
-
current.add(1, 'd');
|
|
91
|
-
}
|
|
92
|
-
daysInChunks.push(extraDays);
|
|
70
|
+
const wrangleMoment = date => {
|
|
71
|
+
if (date instanceof Date) {
|
|
72
|
+
return date;
|
|
73
|
+
} else if (!date) {
|
|
74
|
+
return new Date();
|
|
93
75
|
}
|
|
94
|
-
return
|
|
76
|
+
return date instanceof _moment.default ? date.toDate() : (0, _parseISO.default)(date);
|
|
95
77
|
};
|
|
96
|
-
exports.
|
|
78
|
+
exports.wrangleMoment = wrangleMoment;
|
|
79
|
+
const formatIsoDate = date => (0, _formatISO.default)(wrangleMoment(date), {
|
|
80
|
+
representation: 'date'
|
|
81
|
+
});
|
|
82
|
+
exports.formatIsoDate = formatIsoDate;
|
|
97
83
|
const isStartOfRange = (_ref, date) => {
|
|
98
84
|
let {
|
|
99
85
|
startDate
|
|
100
86
|
} = _ref;
|
|
101
|
-
return
|
|
87
|
+
return Boolean(startDate) && (0, _moment.default)(date).isSame((0, _moment.default)(startDate), 'd');
|
|
102
88
|
};
|
|
103
89
|
exports.isStartOfRange = isStartOfRange;
|
|
104
90
|
const isEndOfRange = (_ref2, date) => {
|
|
105
91
|
let {
|
|
106
92
|
endDate
|
|
107
93
|
} = _ref2;
|
|
108
|
-
return
|
|
94
|
+
return Boolean(endDate) && (0, _moment.default)(date).isSame((0, _moment.default)(endDate), 'd');
|
|
109
95
|
};
|
|
110
96
|
exports.isEndOfRange = isEndOfRange;
|
|
111
97
|
const inDateRange = (_ref3, date) => {
|
|
@@ -117,7 +103,7 @@ const inDateRange = (_ref3, date) => {
|
|
|
117
103
|
const momentDay = (0, _moment.default)(date);
|
|
118
104
|
const momentStartDate = (0, _moment.default)(startDate);
|
|
119
105
|
const momentEndDate = (0, _moment.default)(endDate);
|
|
120
|
-
return momentDay.isBetween(momentStartDate, momentEndDate
|
|
106
|
+
return momentDay.isBetween(momentStartDate, momentEndDate, null, '[]');
|
|
121
107
|
}
|
|
122
108
|
return false;
|
|
123
109
|
};
|
|
@@ -133,10 +119,54 @@ const isStartDateEndDateSame = _ref4 => {
|
|
|
133
119
|
return false;
|
|
134
120
|
};
|
|
135
121
|
exports.isStartDateEndDateSame = isStartDateEndDateSame;
|
|
122
|
+
const getMonthAndYear = date => {
|
|
123
|
+
const momentDate = date ? (0, _moment.default)(date) : (0, _moment.default)();
|
|
124
|
+
return [momentDate.month(), momentDate.year()];
|
|
125
|
+
};
|
|
126
|
+
const getDaysInMonth = date => {
|
|
127
|
+
const startWeek = (0, _moment.default)(date).startOf('month').startOf('week');
|
|
128
|
+
const endWeek = (0, _moment.default)(date).endOf('month').endOf('week');
|
|
129
|
+
const days = [],
|
|
130
|
+
current = startWeek;
|
|
131
|
+
while (current.isBefore(endWeek)) {
|
|
132
|
+
days.push(current.clone().format('YYYY-MM-DD'));
|
|
133
|
+
current.add(1, 'd');
|
|
134
|
+
}
|
|
135
|
+
const daysInChunks = _lodash.default.chunk(days, 7);
|
|
136
|
+
|
|
137
|
+
// if total rows in calendar are 5 add one more week to the calendar
|
|
138
|
+
if (daysInChunks.length === 5) {
|
|
139
|
+
const nextWeek = getAddedDate(endWeek, WEEKDAYS.length, 'd');
|
|
140
|
+
const extraDays = [];
|
|
141
|
+
while (current.isSameOrBefore(nextWeek)) {
|
|
142
|
+
extraDays.push(current.clone().format('YYYY-MM-DD'));
|
|
143
|
+
current.add(1, 'd');
|
|
144
|
+
}
|
|
145
|
+
daysInChunks.push(extraDays);
|
|
146
|
+
}
|
|
147
|
+
return daysInChunks;
|
|
148
|
+
};
|
|
149
|
+
exports.getDaysInMonth = getDaysInMonth;
|
|
150
|
+
const getAddedDate = (date, addCount, timeUnit) => formatIsoDate((0, _moment.default)(date).add(addCount, timeUnit));
|
|
151
|
+
exports.getAddedDate = getAddedDate;
|
|
152
|
+
const getSubtractedDate = (date, subtractCount, timeUnit) => formatIsoDate((0, _moment.default)(date).subtract(subtractCount, timeUnit));
|
|
153
|
+
exports.getSubtractedDate = getSubtractedDate;
|
|
154
|
+
const getMonthStartDate = date => formatIsoDate((0, _moment.default)(date).startOf('M'));
|
|
155
|
+
exports.getMonthStartDate = getMonthStartDate;
|
|
156
|
+
const addTimeZone = (date, timeZone) => _moment.default.tz(date, timeZone).startOf('d').utc().toISOString();
|
|
157
|
+
exports.addTimeZone = addTimeZone;
|
|
158
|
+
const getTimeZones = () => Object.keys(_timezones.TIMEZONES).reduce((menuOptions, key) => {
|
|
159
|
+
menuOptions.push({
|
|
160
|
+
key,
|
|
161
|
+
label: _timezones.TIMEZONES[key]
|
|
162
|
+
});
|
|
163
|
+
return menuOptions;
|
|
164
|
+
}, []);
|
|
165
|
+
exports.getTimeZones = getTimeZones;
|
|
136
166
|
const generateAvailableYears = (count, firstCalendarDate, secondCalendarDate, marker) => {
|
|
137
167
|
const startYear = (0, _moment.default)().year() - count + 1;
|
|
138
|
-
const firstCalendarYear = (0, _moment.default)(firstCalendarDate).year();
|
|
139
|
-
const secondCalendarYear = (0, _moment.default)(secondCalendarDate).year();
|
|
168
|
+
const firstCalendarYear = (0, _moment.default)(firstCalendarDate).add(1, 'M').year();
|
|
169
|
+
const secondCalendarYear = (0, _moment.default)(secondCalendarDate).subtract(1, 'M').year();
|
|
140
170
|
const isWithinRange = year => marker === MARKERS.DATE_RANGE_START ? year <= secondCalendarYear : year >= firstCalendarYear;
|
|
141
171
|
return Array.from({
|
|
142
172
|
length: count
|
|
@@ -155,10 +185,6 @@ const generateAvailableYears = (count, firstCalendarDate, secondCalendarDate, ma
|
|
|
155
185
|
});
|
|
156
186
|
};
|
|
157
187
|
exports.generateAvailableYears = generateAvailableYears;
|
|
158
|
-
const getMonthAndYear = date => {
|
|
159
|
-
const momentDate = date ? (0, _moment.default)(date) : (0, _moment.default)();
|
|
160
|
-
return [momentDate.month(), momentDate.year()];
|
|
161
|
-
};
|
|
162
188
|
const getAvailableMonths = (Months, first, second, marker) => {
|
|
163
189
|
const [firstMonth, firstYear] = getMonthAndYear(first);
|
|
164
190
|
const [secondMonth, secondYear] = getMonthAndYear(second);
|
|
@@ -175,44 +201,33 @@ const getAvailableMonths = (Months, first, second, marker) => {
|
|
|
175
201
|
});
|
|
176
202
|
};
|
|
177
203
|
exports.getAvailableMonths = getAvailableMonths;
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
const
|
|
181
|
-
exports.getSubtractedDate = getSubtractedDate;
|
|
182
|
-
const getAddedDate = (date, addCount, timeUnit) => formatIsoDate((0, _moment.default)(date).add(addCount, timeUnit));
|
|
183
|
-
exports.getAddedDate = getAddedDate;
|
|
184
|
-
function formatIsoDate(date) {
|
|
185
|
-
return (0, _formatISO.default)(wrangleMoment(date), {
|
|
186
|
-
representation: 'date'
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
function wrangleMoment(date) {
|
|
190
|
-
if (date instanceof Date) {
|
|
191
|
-
return date;
|
|
192
|
-
} else if (!date) {
|
|
193
|
-
return new Date();
|
|
194
|
-
}
|
|
195
|
-
return date instanceof _moment.default ? date.toDate() : (0, _parseISO.default)(date);
|
|
196
|
-
}
|
|
197
|
-
const getValidatedMonths = (_ref6, minDate, maxDate) => {
|
|
198
|
-
let {
|
|
204
|
+
const getInitialDates = initialDateRange => {
|
|
205
|
+
const today = formatIsoDate();
|
|
206
|
+
const {
|
|
199
207
|
startDate,
|
|
200
208
|
endDate
|
|
201
|
-
} =
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
209
|
+
} = initialDateRange;
|
|
210
|
+
const isStartDateValid = (0, _moment.default)(startDate).isSameOrBefore(today);
|
|
211
|
+
const isEndDateValid = (0, _moment.default)(endDate).isSameOrBefore(today);
|
|
212
|
+
const dateRange = startDate && endDate && isStartDateValid && isEndDateValid && (0, _moment.default)(endDate).isSameOrAfter(startDate) ? {
|
|
213
|
+
startDate,
|
|
214
|
+
endDate
|
|
215
|
+
} : {
|
|
216
|
+
startDate: undefined,
|
|
217
|
+
endDate: undefined
|
|
218
|
+
};
|
|
219
|
+
let startMonth = dateRange.startDate ? getMonthStartDate(dateRange.startDate) : getMonthStartDate(getSubtractedDate(today, 1, 'M'));
|
|
220
|
+
const endMonth = dateRange.endDate ? getMonthStartDate(dateRange.endDate) : getMonthStartDate(today);
|
|
221
|
+
if ((0, _moment.default)(startMonth).isSame((0, _moment.default)(endMonth), 'M')) {
|
|
222
|
+
startMonth = getSubtractedDate(endMonth, 1, 'M');
|
|
208
223
|
}
|
|
224
|
+
const monthRange = {
|
|
225
|
+
rangeStartMonth: startMonth,
|
|
226
|
+
rangeEndMonth: endMonth
|
|
227
|
+
};
|
|
228
|
+
return {
|
|
229
|
+
dateRange,
|
|
230
|
+
monthRange
|
|
231
|
+
};
|
|
209
232
|
};
|
|
210
|
-
exports.
|
|
211
|
-
const getTimeZones = () => Object.keys(_timezones.TIMEZONES).reduce((menuOptions, key) => {
|
|
212
|
-
menuOptions.push({
|
|
213
|
-
key,
|
|
214
|
-
label: _timezones.TIMEZONES[key]
|
|
215
|
-
});
|
|
216
|
-
return menuOptions;
|
|
217
|
-
}, []);
|
|
218
|
-
exports.getTimeZones = getTimeZones;
|
|
233
|
+
exports.getInitialDates = getInitialDates;
|