@spaced-out/ui-design-system 0.1.93 → 0.1.94-beta.0
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 +7 -0
- 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/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/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/package.json +3 -2
|
@@ -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;
|
|
@@ -14,32 +14,29 @@ import {TIMEZONES} from './timezones';
|
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
export type TimeUnit = 'years' | 'months' | 'days' | 'd' | 'M' | 'y';
|
|
17
|
-
|
|
18
|
-
export type
|
|
19
|
-
|
|
20
|
-
endDate?: string,
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export type DatePickerSelectedRange = {
|
|
24
|
-
startDate?: string,
|
|
25
|
-
endDate?: string,
|
|
17
|
+
export type DateRange = {startDate?: string, endDate?: string};
|
|
18
|
+
export type DateRangeWithTimezone = {|
|
|
19
|
+
...DateRange,
|
|
26
20
|
startDateUTC?: string,
|
|
27
21
|
endDateUTC?: string,
|
|
28
22
|
timeZone?: string,
|
|
23
|
+
|};
|
|
24
|
+
|
|
25
|
+
type MonthRange = {rangeStartMonth: string, rangeEndMonth: string};
|
|
26
|
+
type InitialDateRanges = {
|
|
27
|
+
dateRange: DateRange,
|
|
28
|
+
monthRange: MonthRange,
|
|
29
29
|
};
|
|
30
30
|
|
|
31
31
|
export const NAVIGATION_ACTION = Object.freeze({
|
|
32
32
|
NEXT: 'next',
|
|
33
33
|
PREV: 'prev',
|
|
34
34
|
});
|
|
35
|
-
|
|
36
35
|
export const MARKERS = Object.freeze({
|
|
37
36
|
DATE_RANGE_START: 'FIRST',
|
|
38
37
|
DATE_RANGE_END: 'SECOND',
|
|
39
38
|
});
|
|
40
|
-
|
|
41
39
|
export const WEEKDAYS = ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'];
|
|
42
|
-
|
|
43
40
|
export const MONTHS = [
|
|
44
41
|
{key: '0', label: 'Jan'},
|
|
45
42
|
{key: '1', label: 'Feb'},
|
|
@@ -55,6 +52,54 @@ export const MONTHS = [
|
|
|
55
52
|
{key: '11', label: 'Dec'},
|
|
56
53
|
];
|
|
57
54
|
|
|
55
|
+
export const wrangleMoment = (date?: string | Date): Date => {
|
|
56
|
+
if (date instanceof Date) {
|
|
57
|
+
return date;
|
|
58
|
+
} else if (!date) {
|
|
59
|
+
return new Date();
|
|
60
|
+
}
|
|
61
|
+
return date instanceof moment ? date.toDate() : parseISO(date);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export const formatIsoDate = (date?: string | Date): string =>
|
|
65
|
+
formatISO(wrangleMoment(date), {
|
|
66
|
+
representation: 'date',
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
export const isStartOfRange = ({startDate}: DateRange, date: string): boolean =>
|
|
70
|
+
Boolean(startDate) && moment(date).isSame(moment(startDate), 'd');
|
|
71
|
+
|
|
72
|
+
export const isEndOfRange = ({endDate}: DateRange, date: string): boolean =>
|
|
73
|
+
Boolean(endDate) && moment(date).isSame(moment(endDate), 'd');
|
|
74
|
+
|
|
75
|
+
export const inDateRange = (
|
|
76
|
+
{startDate, endDate}: DateRange,
|
|
77
|
+
date: string,
|
|
78
|
+
): boolean => {
|
|
79
|
+
if (startDate && endDate) {
|
|
80
|
+
const momentDay = moment(date);
|
|
81
|
+
const momentStartDate = moment(startDate);
|
|
82
|
+
const momentEndDate = moment(endDate);
|
|
83
|
+
return momentDay.isBetween(momentStartDate, momentEndDate, null, '[]');
|
|
84
|
+
}
|
|
85
|
+
return false;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export const isStartDateEndDateSame = ({
|
|
89
|
+
startDate,
|
|
90
|
+
endDate,
|
|
91
|
+
}: DateRange): boolean => {
|
|
92
|
+
if (startDate && endDate) {
|
|
93
|
+
return moment(startDate).isSame(moment(endDate), 'd');
|
|
94
|
+
}
|
|
95
|
+
return false;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const getMonthAndYear = (date) => {
|
|
99
|
+
const momentDate = date ? moment(date) : moment();
|
|
100
|
+
return [momentDate.month(), momentDate.year()];
|
|
101
|
+
};
|
|
102
|
+
|
|
58
103
|
export const getDaysInMonth = (date: string): Array<Array<string>> => {
|
|
59
104
|
const startWeek = moment(date).startOf('month').startOf('week');
|
|
60
105
|
const endWeek = moment(date).endOf('month').endOf('week');
|
|
@@ -81,38 +126,32 @@ export const getDaysInMonth = (date: string): Array<Array<string>> => {
|
|
|
81
126
|
return daysInChunks;
|
|
82
127
|
};
|
|
83
128
|
|
|
84
|
-
export const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
129
|
+
export const getAddedDate = (
|
|
130
|
+
date: string,
|
|
131
|
+
addCount: number,
|
|
132
|
+
timeUnit: TimeUnit,
|
|
133
|
+
): string => formatIsoDate(moment(date).add(addCount, timeUnit));
|
|
89
134
|
|
|
90
|
-
export const
|
|
91
|
-
{startDate, endDate}: DateRange,
|
|
135
|
+
export const getSubtractedDate = (
|
|
92
136
|
date: string,
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const momentStartDate = moment(startDate);
|
|
97
|
-
const momentEndDate = moment(endDate);
|
|
98
|
-
return (
|
|
99
|
-
momentDay.isBetween(momentStartDate, momentEndDate) ||
|
|
100
|
-
momentDay.isSame(momentStartDate, 'd') ||
|
|
101
|
-
momentDay.isSame(momentEndDate, 'd')
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
return false;
|
|
105
|
-
};
|
|
137
|
+
subtractCount: number,
|
|
138
|
+
timeUnit: TimeUnit,
|
|
139
|
+
): string => formatIsoDate(moment(date).subtract(subtractCount, timeUnit));
|
|
106
140
|
|
|
107
|
-
export const
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
141
|
+
export const getMonthStartDate = (date: string): string =>
|
|
142
|
+
formatIsoDate(moment(date).startOf('M'));
|
|
143
|
+
|
|
144
|
+
export const addTimeZone = (date: string, timeZone: string): string =>
|
|
145
|
+
moment.tz(date, timeZone).startOf('d').utc().toISOString();
|
|
146
|
+
|
|
147
|
+
export const getTimeZones = (): Array<MenuOption> =>
|
|
148
|
+
Object.keys(TIMEZONES).reduce((menuOptions, key) => {
|
|
149
|
+
menuOptions.push({
|
|
150
|
+
key,
|
|
151
|
+
label: TIMEZONES[key],
|
|
152
|
+
});
|
|
153
|
+
return menuOptions;
|
|
154
|
+
}, []);
|
|
116
155
|
|
|
117
156
|
export const generateAvailableYears = (
|
|
118
157
|
count: number,
|
|
@@ -121,8 +160,8 @@ export const generateAvailableYears = (
|
|
|
121
160
|
marker: $Values<typeof MARKERS>,
|
|
122
161
|
): Array<MenuOption> => {
|
|
123
162
|
const startYear = moment().year() - count + 1;
|
|
124
|
-
const firstCalendarYear = moment(firstCalendarDate).year();
|
|
125
|
-
const secondCalendarYear = moment(secondCalendarDate).year();
|
|
163
|
+
const firstCalendarYear = moment(firstCalendarDate).add(1, 'M').year();
|
|
164
|
+
const secondCalendarYear = moment(secondCalendarDate).subtract(1, 'M').year();
|
|
126
165
|
|
|
127
166
|
const isWithinRange = (year: number) =>
|
|
128
167
|
marker === MARKERS.DATE_RANGE_START
|
|
@@ -139,11 +178,6 @@ export const generateAvailableYears = (
|
|
|
139
178
|
}).filter(({disabled}) => !disabled);
|
|
140
179
|
};
|
|
141
180
|
|
|
142
|
-
const getMonthAndYear = (date) => {
|
|
143
|
-
const momentDate = date ? moment(date) : moment();
|
|
144
|
-
return [momentDate.month(), momentDate.year()];
|
|
145
|
-
};
|
|
146
|
-
|
|
147
181
|
export const getAvailableMonths = (
|
|
148
182
|
Months: Array<MenuOption>,
|
|
149
183
|
first: string,
|
|
@@ -171,61 +205,35 @@ export const getAvailableMonths = (
|
|
|
171
205
|
});
|
|
172
206
|
};
|
|
173
207
|
|
|
174
|
-
export const
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
208
|
+
export const getInitialDates = (
|
|
209
|
+
initialDateRange: DateRange,
|
|
210
|
+
): InitialDateRanges => {
|
|
211
|
+
const today = formatIsoDate();
|
|
212
|
+
const {startDate, endDate} = initialDateRange;
|
|
213
|
+
|
|
214
|
+
const isStartDateValid = moment(startDate).isSameOrBefore(today);
|
|
215
|
+
const isEndDateValid = moment(endDate).isSameOrBefore(today);
|
|
216
|
+
|
|
217
|
+
const dateRange =
|
|
218
|
+
startDate &&
|
|
219
|
+
endDate &&
|
|
220
|
+
isStartDateValid &&
|
|
221
|
+
isEndDateValid &&
|
|
222
|
+
moment(endDate).isSameOrAfter(startDate)
|
|
223
|
+
? {startDate, endDate}
|
|
224
|
+
: {startDate: undefined, endDate: undefined};
|
|
225
|
+
|
|
226
|
+
let startMonth = dateRange.startDate
|
|
227
|
+
? getMonthStartDate(dateRange.startDate)
|
|
228
|
+
: getMonthStartDate(getSubtractedDate(today, 1, 'M'));
|
|
229
|
+
const endMonth = dateRange.endDate
|
|
230
|
+
? getMonthStartDate(dateRange.endDate)
|
|
231
|
+
: getMonthStartDate(today);
|
|
232
|
+
|
|
233
|
+
if (moment(startMonth).isSame(moment(endMonth), 'M')) {
|
|
234
|
+
startMonth = getSubtractedDate(endMonth, 1, 'M');
|
|
200
235
|
}
|
|
201
|
-
return date instanceof moment ? date.toDate() : parseISO(date);
|
|
202
|
-
}
|
|
203
236
|
|
|
204
|
-
|
|
205
|
-
{
|
|
206
|
-
minDate: string,
|
|
207
|
-
maxDate: string,
|
|
208
|
-
): Array<?string> => {
|
|
209
|
-
if (startDate && endDate) {
|
|
210
|
-
const newStart = moment.max(moment(startDate), moment(minDate)); // TODO Figure out the validated date
|
|
211
|
-
const newEnd = moment.min(moment(endDate), moment(maxDate));
|
|
212
|
-
|
|
213
|
-
return [
|
|
214
|
-
formatIsoDate(newStart),
|
|
215
|
-
newStart.isSame(newEnd, 'M')
|
|
216
|
-
? getAddedDate(newEnd, 1, 'M')
|
|
217
|
-
: formatIsoDate(newEnd),
|
|
218
|
-
];
|
|
219
|
-
} else {
|
|
220
|
-
return [startDate, endDate];
|
|
221
|
-
}
|
|
237
|
+
const monthRange = {rangeStartMonth: startMonth, rangeEndMonth: endMonth};
|
|
238
|
+
return {dateRange, monthRange};
|
|
222
239
|
};
|
|
223
|
-
|
|
224
|
-
export const getTimeZones = (): Array<MenuOption> =>
|
|
225
|
-
Object.keys(TIMEZONES).reduce((menuOptions, key) => {
|
|
226
|
-
menuOptions.push({
|
|
227
|
-
key,
|
|
228
|
-
label: TIMEZONES[key],
|
|
229
|
-
});
|
|
230
|
-
return menuOptions;
|
|
231
|
-
}, []);
|
|
@@ -64,6 +64,12 @@ const Dropdown = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
64
64
|
className: (0, _classify.classify)(_DropdownModule.default.dropdownContainer, classNames?.wrapper),
|
|
65
65
|
ref: dropdownRef
|
|
66
66
|
}, /*#__PURE__*/React.createElement(_Input.Input, _extends({}, inputProps, {
|
|
67
|
+
onKeyDown: e => {
|
|
68
|
+
if (e.keyCode === 32) {
|
|
69
|
+
e.preventDefault();
|
|
70
|
+
onOpen();
|
|
71
|
+
}
|
|
72
|
+
},
|
|
67
73
|
boxRef: refs.setReference,
|
|
68
74
|
size: size,
|
|
69
75
|
placeholder: placeholder,
|
|
@@ -84,6 +84,12 @@ export const Dropdown: React$AbstractComponent<
|
|
|
84
84
|
>
|
|
85
85
|
<Input
|
|
86
86
|
{...inputProps}
|
|
87
|
+
onKeyDown={(e) => {
|
|
88
|
+
if (e.keyCode === 32) {
|
|
89
|
+
e.preventDefault();
|
|
90
|
+
onOpen();
|
|
91
|
+
}
|
|
92
|
+
}}
|
|
87
93
|
boxRef={refs.setReference}
|
|
88
94
|
size={size}
|
|
89
95
|
placeholder={placeholder}
|
|
@@ -23,6 +23,7 @@ const SimpleDropdownBase = (props, ref) => {
|
|
|
23
23
|
onMenuOpen,
|
|
24
24
|
onMenuClose,
|
|
25
25
|
resolveLabel,
|
|
26
|
+
menuVirtualization,
|
|
26
27
|
resolveSecondaryLabel,
|
|
27
28
|
isMenuFluid = true,
|
|
28
29
|
...inputProps
|
|
@@ -67,6 +68,7 @@ const SimpleDropdownBase = (props, ref) => {
|
|
|
67
68
|
allowSearch,
|
|
68
69
|
resolveLabel,
|
|
69
70
|
resolveSecondaryLabel,
|
|
71
|
+
virtualization: menuVirtualization,
|
|
70
72
|
size,
|
|
71
73
|
isFluid: isMenuFluid
|
|
72
74
|
}
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
getTextLabelFromSelectedKeys,
|
|
8
8
|
} from '../../utils/menu';
|
|
9
9
|
import type {InputProps} from '../Input';
|
|
10
|
-
import type {MenuOption, MenuOptionsVariant} from '../Menu';
|
|
10
|
+
import type {MenuOption, MenuOptionsVariant, Virtualization} from '../Menu';
|
|
11
11
|
|
|
12
12
|
import {Dropdown} from './Dropdown';
|
|
13
13
|
|
|
@@ -34,6 +34,7 @@ export type SimpleDropdownProps = {
|
|
|
34
34
|
allowSearch?: boolean,
|
|
35
35
|
selectedKeys?: Array<string>,
|
|
36
36
|
isMenuFluid?: boolean,
|
|
37
|
+
menuVirtualization?: Virtualization,
|
|
37
38
|
|
|
38
39
|
// events
|
|
39
40
|
onChange?: (option: MenuOption, ?SyntheticEvent<HTMLElement>) => mixed,
|
|
@@ -59,6 +60,7 @@ const SimpleDropdownBase = (props: SimpleDropdownProps, ref) => {
|
|
|
59
60
|
onMenuOpen,
|
|
60
61
|
onMenuClose,
|
|
61
62
|
resolveLabel,
|
|
63
|
+
menuVirtualization,
|
|
62
64
|
resolveSecondaryLabel,
|
|
63
65
|
isMenuFluid = true,
|
|
64
66
|
...inputProps
|
|
@@ -122,6 +124,7 @@ const SimpleDropdownBase = (props: SimpleDropdownProps, ref) => {
|
|
|
122
124
|
allowSearch,
|
|
123
125
|
resolveLabel,
|
|
124
126
|
resolveSecondaryLabel,
|
|
127
|
+
virtualization: menuVirtualization,
|
|
125
128
|
size,
|
|
126
129
|
isFluid: isMenuFluid,
|
|
127
130
|
}}
|