@spaced-out/ui-design-system 0.1.92 → 0.1.93-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/.cspell/custom-words.txt +41 -0
- package/CHANGELOG.md +12 -0
- package/lib/components/DateRangePicker/Calendar.js +75 -0
- package/lib/components/DateRangePicker/Calendar.js.flow +113 -0
- package/lib/components/DateRangePicker/Calendar.module.css +49 -0
- package/lib/components/DateRangePicker/DateRangePicker.js +120 -0
- package/lib/components/DateRangePicker/DateRangePicker.js.flow +173 -0
- package/lib/components/DateRangePicker/DateRangePicker.module.css +8 -0
- package/lib/components/DateRangePicker/DateRangeWrapper.js +175 -0
- package/lib/components/DateRangePicker/DateRangeWrapper.js.flow +282 -0
- package/lib/components/DateRangePicker/DateRangeWrapper.module.css +64 -0
- package/lib/components/DateRangePicker/Day.js +65 -0
- package/lib/components/DateRangePicker/Day.js.flow +80 -0
- package/lib/components/DateRangePicker/Day.module.css +91 -0
- package/lib/components/DateRangePicker/index.js +16 -0
- package/lib/components/DateRangePicker/index.js.flow +3 -0
- package/lib/components/DateRangePicker/timezones.js +262 -0
- package/lib/components/DateRangePicker/timezones.js.flow +256 -0
- package/lib/components/DateRangePicker/utils.js +218 -0
- package/lib/components/DateRangePicker/utils.js.flow +231 -0
- package/lib/components/Dropdown/Dropdown.js +7 -1
- package/lib/components/Dropdown/Dropdown.js.flow +7 -0
- package/lib/components/SpiderChart/SpiderChart.js +1 -20
- package/lib/components/SpiderChart/SpiderChart.js.flow +0 -20
- package/lib/components/index.js +11 -0
- package/lib/components/index.js.flow +1 -0
- package/lib/types/charts.js.flow +1 -0
- package/lib/utils/charts/charts.js +3 -0
- package/lib/utils/charts/charts.js.flow +3 -0
- package/lib/utils/charts/columnChart.js +1 -0
- package/lib/utils/charts/columnChart.js.flow +1 -0
- package/lib/utils/charts/lineChart.js +1 -0
- package/lib/utils/charts/lineChart.js.flow +1 -0
- package/lib/utils/charts/spiderChart.js +3 -1
- package/lib/utils/charts/spiderChart.js.flow +4 -17
- package/lib/utils/charts/typography.js +2 -3
- package/lib/utils/charts/typography.js.flow +1 -3
- package/package.json +2 -1
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
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;
|
|
10
|
+
var _formatISO = _interopRequireDefault(require("date-fns/formatISO"));
|
|
11
|
+
var _parseISO = _interopRequireDefault(require("date-fns/parseISO"));
|
|
12
|
+
var _lodash = _interopRequireDefault(require("lodash"));
|
|
13
|
+
var _moment = _interopRequireDefault(require("moment"));
|
|
14
|
+
var _timezones = require("./timezones");
|
|
15
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
|
+
|
|
17
|
+
// $FlowFixMe - strict types for date-fns
|
|
18
|
+
|
|
19
|
+
// $FlowFixMe - strict types for date-fns
|
|
20
|
+
|
|
21
|
+
// $FlowFixMe[untyped-import]
|
|
22
|
+
|
|
23
|
+
const NAVIGATION_ACTION = Object.freeze({
|
|
24
|
+
NEXT: 'next',
|
|
25
|
+
PREV: 'prev'
|
|
26
|
+
});
|
|
27
|
+
exports.NAVIGATION_ACTION = NAVIGATION_ACTION;
|
|
28
|
+
const MARKERS = Object.freeze({
|
|
29
|
+
DATE_RANGE_START: 'FIRST',
|
|
30
|
+
DATE_RANGE_END: 'SECOND'
|
|
31
|
+
});
|
|
32
|
+
exports.MARKERS = MARKERS;
|
|
33
|
+
const WEEKDAYS = ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'];
|
|
34
|
+
exports.WEEKDAYS = WEEKDAYS;
|
|
35
|
+
const MONTHS = [{
|
|
36
|
+
key: '0',
|
|
37
|
+
label: 'Jan'
|
|
38
|
+
}, {
|
|
39
|
+
key: '1',
|
|
40
|
+
label: 'Feb'
|
|
41
|
+
}, {
|
|
42
|
+
key: '2',
|
|
43
|
+
label: 'Mar'
|
|
44
|
+
}, {
|
|
45
|
+
key: '3',
|
|
46
|
+
label: 'Apr'
|
|
47
|
+
}, {
|
|
48
|
+
key: '4',
|
|
49
|
+
label: 'May'
|
|
50
|
+
}, {
|
|
51
|
+
key: '5',
|
|
52
|
+
label: 'Jun'
|
|
53
|
+
}, {
|
|
54
|
+
key: '6',
|
|
55
|
+
label: 'Jul'
|
|
56
|
+
}, {
|
|
57
|
+
key: '7',
|
|
58
|
+
label: 'Aug'
|
|
59
|
+
}, {
|
|
60
|
+
key: '8',
|
|
61
|
+
label: 'Sep'
|
|
62
|
+
}, {
|
|
63
|
+
key: '9',
|
|
64
|
+
label: 'Oct'
|
|
65
|
+
}, {
|
|
66
|
+
key: '10',
|
|
67
|
+
label: 'Nov'
|
|
68
|
+
}, {
|
|
69
|
+
key: '11',
|
|
70
|
+
label: 'Dec'
|
|
71
|
+
}];
|
|
72
|
+
exports.MONTHS = MONTHS;
|
|
73
|
+
const getDaysInMonth = date => {
|
|
74
|
+
const startWeek = (0, _moment.default)(date).startOf('month').startOf('week');
|
|
75
|
+
const endWeek = (0, _moment.default)(date).endOf('month').endOf('week');
|
|
76
|
+
const days = [],
|
|
77
|
+
current = startWeek;
|
|
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);
|
|
93
|
+
}
|
|
94
|
+
return daysInChunks;
|
|
95
|
+
};
|
|
96
|
+
exports.getDaysInMonth = getDaysInMonth;
|
|
97
|
+
const isStartOfRange = (_ref, date) => {
|
|
98
|
+
let {
|
|
99
|
+
startDate
|
|
100
|
+
} = _ref;
|
|
101
|
+
return !!startDate && (0, _moment.default)(date).isSame(startDate, 'd');
|
|
102
|
+
};
|
|
103
|
+
exports.isStartOfRange = isStartOfRange;
|
|
104
|
+
const isEndOfRange = (_ref2, date) => {
|
|
105
|
+
let {
|
|
106
|
+
endDate
|
|
107
|
+
} = _ref2;
|
|
108
|
+
return !!endDate && (0, _moment.default)(date).isSame(endDate, 'd');
|
|
109
|
+
};
|
|
110
|
+
exports.isEndOfRange = isEndOfRange;
|
|
111
|
+
const inDateRange = (_ref3, date) => {
|
|
112
|
+
let {
|
|
113
|
+
startDate,
|
|
114
|
+
endDate
|
|
115
|
+
} = _ref3;
|
|
116
|
+
if (startDate && endDate) {
|
|
117
|
+
const momentDay = (0, _moment.default)(date);
|
|
118
|
+
const momentStartDate = (0, _moment.default)(startDate);
|
|
119
|
+
const momentEndDate = (0, _moment.default)(endDate);
|
|
120
|
+
return momentDay.isBetween(momentStartDate, momentEndDate) || momentDay.isSame(momentStartDate, 'd') || momentDay.isSame(momentEndDate, 'd');
|
|
121
|
+
}
|
|
122
|
+
return false;
|
|
123
|
+
};
|
|
124
|
+
exports.inDateRange = inDateRange;
|
|
125
|
+
const isStartDateEndDateSame = _ref4 => {
|
|
126
|
+
let {
|
|
127
|
+
startDate,
|
|
128
|
+
endDate
|
|
129
|
+
} = _ref4;
|
|
130
|
+
if (startDate && endDate) {
|
|
131
|
+
return (0, _moment.default)(startDate).isSame((0, _moment.default)(endDate), 'd');
|
|
132
|
+
}
|
|
133
|
+
return false;
|
|
134
|
+
};
|
|
135
|
+
exports.isStartDateEndDateSame = isStartDateEndDateSame;
|
|
136
|
+
const generateAvailableYears = (count, firstCalendarDate, secondCalendarDate, marker) => {
|
|
137
|
+
const startYear = (0, _moment.default)().year() - count + 1;
|
|
138
|
+
const firstCalendarYear = (0, _moment.default)(firstCalendarDate).year();
|
|
139
|
+
const secondCalendarYear = (0, _moment.default)(secondCalendarDate).year();
|
|
140
|
+
const isWithinRange = year => marker === MARKERS.DATE_RANGE_START ? year <= secondCalendarYear : year >= firstCalendarYear;
|
|
141
|
+
return Array.from({
|
|
142
|
+
length: count
|
|
143
|
+
}, (_, index) => {
|
|
144
|
+
const year = startYear + index;
|
|
145
|
+
return {
|
|
146
|
+
key: year.toString(),
|
|
147
|
+
label: year.toString(),
|
|
148
|
+
disabled: !isWithinRange(year)
|
|
149
|
+
};
|
|
150
|
+
}).filter(_ref5 => {
|
|
151
|
+
let {
|
|
152
|
+
disabled
|
|
153
|
+
} = _ref5;
|
|
154
|
+
return !disabled;
|
|
155
|
+
});
|
|
156
|
+
};
|
|
157
|
+
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
|
+
const getAvailableMonths = (Months, first, second, marker) => {
|
|
163
|
+
const [firstMonth, firstYear] = getMonthAndYear(first);
|
|
164
|
+
const [secondMonth, secondYear] = getMonthAndYear(second);
|
|
165
|
+
const [currentMonth, currentYear] = getMonthAndYear();
|
|
166
|
+
return Months.filter(month => {
|
|
167
|
+
const isSameYear = firstYear === secondYear;
|
|
168
|
+
const isMonthBeforeFirstMonth = month.key <= firstMonth;
|
|
169
|
+
const isMonthAfterCurrentMonth = currentYear === secondYear && month.key > currentMonth;
|
|
170
|
+
if (marker === MARKERS.DATE_RANGE_START) {
|
|
171
|
+
return !(isSameYear && month.key >= secondMonth);
|
|
172
|
+
} else {
|
|
173
|
+
return !(isSameYear && isMonthBeforeFirstMonth || isMonthAfterCurrentMonth);
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
};
|
|
177
|
+
exports.getAvailableMonths = getAvailableMonths;
|
|
178
|
+
const addTimeZone = (date, timeZone) => _moment.default.tz(date, timeZone).startOf('d').utc().toISOString();
|
|
179
|
+
exports.addTimeZone = addTimeZone;
|
|
180
|
+
const getSubtractedDate = (date, subtractCount, timeUnit) => formatIsoDate((0, _moment.default)(date).subtract(subtractCount, timeUnit));
|
|
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 {
|
|
199
|
+
startDate,
|
|
200
|
+
endDate
|
|
201
|
+
} = _ref6;
|
|
202
|
+
if (startDate && endDate) {
|
|
203
|
+
const newStart = _moment.default.max((0, _moment.default)(startDate), (0, _moment.default)(minDate)); // TODO Figure out the validated date
|
|
204
|
+
const newEnd = _moment.default.min((0, _moment.default)(endDate), (0, _moment.default)(maxDate));
|
|
205
|
+
return [formatIsoDate(newStart), newStart.isSame(newEnd, 'M') ? getAddedDate(newEnd, 1, 'M') : formatIsoDate(newEnd)];
|
|
206
|
+
} else {
|
|
207
|
+
return [startDate, endDate];
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
exports.getValidatedMonths = getValidatedMonths;
|
|
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;
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
// @flow strict
|
|
2
|
+
|
|
3
|
+
// $FlowFixMe - strict types for date-fns
|
|
4
|
+
import formatISO from 'date-fns/formatISO';
|
|
5
|
+
// $FlowFixMe - strict types for date-fns
|
|
6
|
+
import parseISO from 'date-fns/parseISO';
|
|
7
|
+
import lodash from 'lodash';
|
|
8
|
+
// $FlowFixMe[untyped-import]
|
|
9
|
+
import moment from 'moment';
|
|
10
|
+
|
|
11
|
+
import type {MenuOption} from '../Menu';
|
|
12
|
+
|
|
13
|
+
import {TIMEZONES} from './timezones';
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
export type TimeUnit = 'years' | 'months' | 'days' | 'd' | 'M' | 'y';
|
|
17
|
+
|
|
18
|
+
export type DateRange = {
|
|
19
|
+
startDate?: string,
|
|
20
|
+
endDate?: string,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export type DatePickerSelectedRange = {
|
|
24
|
+
startDate?: string,
|
|
25
|
+
endDate?: string,
|
|
26
|
+
startDateUTC?: string,
|
|
27
|
+
endDateUTC?: string,
|
|
28
|
+
timeZone?: string,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const NAVIGATION_ACTION = Object.freeze({
|
|
32
|
+
NEXT: 'next',
|
|
33
|
+
PREV: 'prev',
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
export const MARKERS = Object.freeze({
|
|
37
|
+
DATE_RANGE_START: 'FIRST',
|
|
38
|
+
DATE_RANGE_END: 'SECOND',
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
export const WEEKDAYS = ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'];
|
|
42
|
+
|
|
43
|
+
export const MONTHS = [
|
|
44
|
+
{key: '0', label: 'Jan'},
|
|
45
|
+
{key: '1', label: 'Feb'},
|
|
46
|
+
{key: '2', label: 'Mar'},
|
|
47
|
+
{key: '3', label: 'Apr'},
|
|
48
|
+
{key: '4', label: 'May'},
|
|
49
|
+
{key: '5', label: 'Jun'},
|
|
50
|
+
{key: '6', label: 'Jul'},
|
|
51
|
+
{key: '7', label: 'Aug'},
|
|
52
|
+
{key: '8', label: 'Sep'},
|
|
53
|
+
{key: '9', label: 'Oct'},
|
|
54
|
+
{key: '10', label: 'Nov'},
|
|
55
|
+
{key: '11', label: 'Dec'},
|
|
56
|
+
];
|
|
57
|
+
|
|
58
|
+
export const getDaysInMonth = (date: string): Array<Array<string>> => {
|
|
59
|
+
const startWeek = moment(date).startOf('month').startOf('week');
|
|
60
|
+
const endWeek = moment(date).endOf('month').endOf('week');
|
|
61
|
+
const days = [],
|
|
62
|
+
current = startWeek;
|
|
63
|
+
|
|
64
|
+
while (current.isBefore(endWeek)) {
|
|
65
|
+
days.push(current.clone().format('YYYY-MM-DD'));
|
|
66
|
+
current.add(1, 'd');
|
|
67
|
+
}
|
|
68
|
+
const daysInChunks = lodash.chunk(days, 7);
|
|
69
|
+
|
|
70
|
+
// if total rows in calendar are 5 add one more week to the calendar
|
|
71
|
+
if (daysInChunks.length === 5) {
|
|
72
|
+
const nextWeek = getAddedDate(endWeek, WEEKDAYS.length, 'd');
|
|
73
|
+
const extraDays = [];
|
|
74
|
+
while (current.isSameOrBefore(nextWeek)) {
|
|
75
|
+
extraDays.push(current.clone().format('YYYY-MM-DD'));
|
|
76
|
+
current.add(1, 'd');
|
|
77
|
+
}
|
|
78
|
+
daysInChunks.push(extraDays);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return daysInChunks;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export const isStartOfRange = ({startDate}: DateRange, date: string): boolean =>
|
|
85
|
+
!!startDate && moment(date).isSame(startDate, 'd');
|
|
86
|
+
|
|
87
|
+
export const isEndOfRange = ({endDate}: DateRange, date: string): boolean =>
|
|
88
|
+
!!endDate && moment(date).isSame(endDate, 'd');
|
|
89
|
+
|
|
90
|
+
export const inDateRange = (
|
|
91
|
+
{startDate, endDate}: DateRange,
|
|
92
|
+
date: string,
|
|
93
|
+
): boolean => {
|
|
94
|
+
if (startDate && endDate) {
|
|
95
|
+
const momentDay = moment(date);
|
|
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
|
+
};
|
|
106
|
+
|
|
107
|
+
export const isStartDateEndDateSame = ({
|
|
108
|
+
startDate,
|
|
109
|
+
endDate,
|
|
110
|
+
}: DateRange): boolean => {
|
|
111
|
+
if (startDate && endDate) {
|
|
112
|
+
return moment(startDate).isSame(moment(endDate), 'd');
|
|
113
|
+
}
|
|
114
|
+
return false;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
export const generateAvailableYears = (
|
|
118
|
+
count: number,
|
|
119
|
+
firstCalendarDate: string,
|
|
120
|
+
secondCalendarDate: string,
|
|
121
|
+
marker: $Values<typeof MARKERS>,
|
|
122
|
+
): Array<MenuOption> => {
|
|
123
|
+
const startYear = moment().year() - count + 1;
|
|
124
|
+
const firstCalendarYear = moment(firstCalendarDate).year();
|
|
125
|
+
const secondCalendarYear = moment(secondCalendarDate).year();
|
|
126
|
+
|
|
127
|
+
const isWithinRange = (year: number) =>
|
|
128
|
+
marker === MARKERS.DATE_RANGE_START
|
|
129
|
+
? year <= secondCalendarYear
|
|
130
|
+
: year >= firstCalendarYear;
|
|
131
|
+
|
|
132
|
+
return Array.from({length: count}, (_, index) => {
|
|
133
|
+
const year = startYear + index;
|
|
134
|
+
return {
|
|
135
|
+
key: year.toString(),
|
|
136
|
+
label: year.toString(),
|
|
137
|
+
disabled: !isWithinRange(year),
|
|
138
|
+
};
|
|
139
|
+
}).filter(({disabled}) => !disabled);
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
const getMonthAndYear = (date) => {
|
|
143
|
+
const momentDate = date ? moment(date) : moment();
|
|
144
|
+
return [momentDate.month(), momentDate.year()];
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
export const getAvailableMonths = (
|
|
148
|
+
Months: Array<MenuOption>,
|
|
149
|
+
first: string,
|
|
150
|
+
second: string,
|
|
151
|
+
marker: $Values<typeof MARKERS>,
|
|
152
|
+
): Array<MenuOption> => {
|
|
153
|
+
const [firstMonth, firstYear] = getMonthAndYear(first);
|
|
154
|
+
const [secondMonth, secondYear] = getMonthAndYear(second);
|
|
155
|
+
const [currentMonth, currentYear] = getMonthAndYear();
|
|
156
|
+
|
|
157
|
+
return Months.filter((month: MenuOption) => {
|
|
158
|
+
const isSameYear = firstYear === secondYear;
|
|
159
|
+
const isMonthBeforeFirstMonth = month.key <= firstMonth;
|
|
160
|
+
const isMonthAfterCurrentMonth =
|
|
161
|
+
currentYear === secondYear && month.key > currentMonth;
|
|
162
|
+
|
|
163
|
+
if (marker === MARKERS.DATE_RANGE_START) {
|
|
164
|
+
return !(isSameYear && month.key >= secondMonth);
|
|
165
|
+
} else {
|
|
166
|
+
return !(
|
|
167
|
+
(isSameYear && isMonthBeforeFirstMonth) ||
|
|
168
|
+
isMonthAfterCurrentMonth
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
export const addTimeZone = (date: string, timeZone: string): string =>
|
|
175
|
+
moment.tz(date, timeZone).startOf('d').utc().toISOString();
|
|
176
|
+
|
|
177
|
+
export const getSubtractedDate = (
|
|
178
|
+
date: string,
|
|
179
|
+
subtractCount: number,
|
|
180
|
+
timeUnit: TimeUnit,
|
|
181
|
+
): string => formatIsoDate(moment(date).subtract(subtractCount, timeUnit));
|
|
182
|
+
|
|
183
|
+
export const getAddedDate = (
|
|
184
|
+
date: string,
|
|
185
|
+
addCount: number,
|
|
186
|
+
timeUnit: TimeUnit,
|
|
187
|
+
): string => formatIsoDate(moment(date).add(addCount, timeUnit));
|
|
188
|
+
|
|
189
|
+
export function formatIsoDate(date?: string | Date): string {
|
|
190
|
+
return formatISO(wrangleMoment(date), {
|
|
191
|
+
representation: 'date',
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export function wrangleMoment(date?: string | Date): Date {
|
|
196
|
+
if (date instanceof Date) {
|
|
197
|
+
return date;
|
|
198
|
+
} else if (!date) {
|
|
199
|
+
return new Date();
|
|
200
|
+
}
|
|
201
|
+
return date instanceof moment ? date.toDate() : parseISO(date);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export const getValidatedMonths = (
|
|
205
|
+
{startDate, endDate}: DateRange,
|
|
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
|
+
}
|
|
222
|
+
};
|
|
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
|
+
}, []);
|
|
@@ -26,10 +26,12 @@ const Dropdown = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
26
26
|
menu,
|
|
27
27
|
onMenuOpen,
|
|
28
28
|
onMenuClose,
|
|
29
|
+
scrollMenuToBottom = false,
|
|
29
30
|
dropdownInputText = '',
|
|
30
31
|
...inputProps
|
|
31
32
|
} = _ref;
|
|
32
33
|
const dropdownRef = React.useRef();
|
|
34
|
+
const menuRef = React.useRef();
|
|
33
35
|
const {
|
|
34
36
|
x,
|
|
35
37
|
y,
|
|
@@ -44,6 +46,9 @@ const Dropdown = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
44
46
|
});
|
|
45
47
|
const onMenuToggle = isOpen => {
|
|
46
48
|
isOpen ? onMenuOpen && onMenuOpen() : onMenuClose && onMenuClose();
|
|
49
|
+
if (scrollMenuToBottom && menuRef.current && isOpen) {
|
|
50
|
+
menuRef.current.scrollTop = isOpen ? menuRef.current.scrollHeight : 0;
|
|
51
|
+
}
|
|
47
52
|
};
|
|
48
53
|
return /*#__PURE__*/React.createElement(_clickAway.ClickAway, {
|
|
49
54
|
onChange: onMenuToggle
|
|
@@ -90,7 +95,8 @@ const Dropdown = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
90
95
|
}
|
|
91
96
|
},
|
|
92
97
|
size: menu.size || size,
|
|
93
|
-
onTabOut: clickAway
|
|
98
|
+
onTabOut: clickAway,
|
|
99
|
+
ref: menuRef
|
|
94
100
|
}))));
|
|
95
101
|
});
|
|
96
102
|
});
|
|
@@ -32,6 +32,7 @@ export type DropdownProps = {
|
|
|
32
32
|
onChange?: (option: MenuOption, ?SyntheticEvent<HTMLElement>) => mixed,
|
|
33
33
|
onMenuOpen?: () => mixed,
|
|
34
34
|
onMenuClose?: () => mixed,
|
|
35
|
+
scrollMenuToBottom?: boolean,
|
|
35
36
|
dropdownInputText?: string,
|
|
36
37
|
menu?: MenuProps,
|
|
37
38
|
...
|
|
@@ -50,12 +51,14 @@ export const Dropdown: React$AbstractComponent<
|
|
|
50
51
|
menu,
|
|
51
52
|
onMenuOpen,
|
|
52
53
|
onMenuClose,
|
|
54
|
+
scrollMenuToBottom = false,
|
|
53
55
|
dropdownInputText = '',
|
|
54
56
|
...inputProps
|
|
55
57
|
}: DropdownProps,
|
|
56
58
|
ref,
|
|
57
59
|
): React.Node => {
|
|
58
60
|
const dropdownRef = React.useRef();
|
|
61
|
+
const menuRef = React.useRef();
|
|
59
62
|
const {x, y, refs, strategy} = useFloating({
|
|
60
63
|
open: true,
|
|
61
64
|
strategy: 'absolute',
|
|
@@ -66,6 +69,9 @@ export const Dropdown: React$AbstractComponent<
|
|
|
66
69
|
|
|
67
70
|
const onMenuToggle = (isOpen: boolean) => {
|
|
68
71
|
isOpen ? onMenuOpen && onMenuOpen() : onMenuClose && onMenuClose();
|
|
72
|
+
if (scrollMenuToBottom && menuRef.current && isOpen) {
|
|
73
|
+
menuRef.current.scrollTop = isOpen ? menuRef.current.scrollHeight : 0;
|
|
74
|
+
}
|
|
69
75
|
};
|
|
70
76
|
|
|
71
77
|
return (
|
|
@@ -116,6 +122,7 @@ export const Dropdown: React$AbstractComponent<
|
|
|
116
122
|
}}
|
|
117
123
|
size={menu.size || size}
|
|
118
124
|
onTabOut={clickAway}
|
|
125
|
+
ref={menuRef}
|
|
119
126
|
/>
|
|
120
127
|
</div>
|
|
121
128
|
)}
|
|
@@ -31,27 +31,10 @@ const SpiderChart = _ref => {
|
|
|
31
31
|
cardTitle,
|
|
32
32
|
customExportOptions,
|
|
33
33
|
headerActions,
|
|
34
|
-
legend,
|
|
35
34
|
series,
|
|
36
|
-
xAxis: {
|
|
37
|
-
categories,
|
|
38
|
-
tickmarkPlacement = 'on',
|
|
39
|
-
lineWidth: xAxisLineWidth = 0,
|
|
40
|
-
...xAxisProps
|
|
41
|
-
} = {},
|
|
42
|
-
yAxis: {
|
|
43
|
-
gridLineInterpolation = 'polygon',
|
|
44
|
-
lineWidth: yAxisLineWidth = 0,
|
|
45
|
-
min: yAxisMin = 0,
|
|
46
|
-
...yAxisProps
|
|
47
|
-
} = {},
|
|
48
35
|
...userOptions
|
|
49
36
|
} = _ref;
|
|
50
37
|
const chartRef = React.useRef(null);
|
|
51
|
-
const [chartWidth, setChartWidth] = React.useState(0);
|
|
52
|
-
React.useLayoutEffect(() => {
|
|
53
|
-
setChartWidth(chartRef.current?.chart.plotWidth);
|
|
54
|
-
}, []);
|
|
55
38
|
const spiderSeries = series.map((seriesItem, index) => ({
|
|
56
39
|
...seriesItem,
|
|
57
40
|
name: seriesItem.name,
|
|
@@ -71,9 +54,7 @@ const SpiderChart = _ref => {
|
|
|
71
54
|
...wrapperClassNames
|
|
72
55
|
} = classNames || {};
|
|
73
56
|
return /*#__PURE__*/React.createElement(_ChartWrapper.ChartWrapper, {
|
|
74
|
-
title: cardTitle
|
|
75
|
-
//$FlowFixMe[incompatible-type]
|
|
76
|
-
,
|
|
57
|
+
title: cardTitle,
|
|
77
58
|
ref: chartRef,
|
|
78
59
|
customExportOptions: customExportOptions,
|
|
79
60
|
classNames: wrapperClassNames,
|
|
@@ -66,29 +66,10 @@ export const SpiderChart = ({
|
|
|
66
66
|
cardTitle,
|
|
67
67
|
customExportOptions,
|
|
68
68
|
headerActions,
|
|
69
|
-
legend,
|
|
70
69
|
series,
|
|
71
|
-
xAxis: {
|
|
72
|
-
categories,
|
|
73
|
-
tickmarkPlacement = 'on',
|
|
74
|
-
lineWidth: xAxisLineWidth = 0,
|
|
75
|
-
...xAxisProps
|
|
76
|
-
} = {},
|
|
77
|
-
yAxis: {
|
|
78
|
-
gridLineInterpolation = 'polygon',
|
|
79
|
-
lineWidth: yAxisLineWidth = 0,
|
|
80
|
-
min: yAxisMin = 0,
|
|
81
|
-
...yAxisProps
|
|
82
|
-
} = {},
|
|
83
|
-
|
|
84
70
|
...userOptions
|
|
85
71
|
}: SpiderChartProps): React.Node => {
|
|
86
72
|
const chartRef = React.useRef(null);
|
|
87
|
-
const [chartWidth, setChartWidth] = React.useState(0);
|
|
88
|
-
|
|
89
|
-
React.useLayoutEffect(() => {
|
|
90
|
-
setChartWidth(chartRef.current?.chart.plotWidth);
|
|
91
|
-
}, []);
|
|
92
73
|
|
|
93
74
|
const spiderSeries = series.map((seriesItem, index) => ({
|
|
94
75
|
...seriesItem,
|
|
@@ -111,7 +92,6 @@ export const SpiderChart = ({
|
|
|
111
92
|
return (
|
|
112
93
|
<ChartWrapper
|
|
113
94
|
title={cardTitle}
|
|
114
|
-
//$FlowFixMe[incompatible-type]
|
|
115
95
|
ref={chartRef}
|
|
116
96
|
customExportOptions={customExportOptions}
|
|
117
97
|
classNames={wrapperClassNames}
|
package/lib/components/index.js
CHANGED
|
@@ -168,6 +168,17 @@ Object.keys(_ConditionalWrapper).forEach(function (key) {
|
|
|
168
168
|
}
|
|
169
169
|
});
|
|
170
170
|
});
|
|
171
|
+
var _DateRangePicker = require("./DateRangePicker");
|
|
172
|
+
Object.keys(_DateRangePicker).forEach(function (key) {
|
|
173
|
+
if (key === "default" || key === "__esModule") return;
|
|
174
|
+
if (key in exports && exports[key] === _DateRangePicker[key]) return;
|
|
175
|
+
Object.defineProperty(exports, key, {
|
|
176
|
+
enumerable: true,
|
|
177
|
+
get: function () {
|
|
178
|
+
return _DateRangePicker[key];
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
});
|
|
171
182
|
var _Dialog = require("./Dialog");
|
|
172
183
|
Object.keys(_Dialog).forEach(function (key) {
|
|
173
184
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -15,6 +15,7 @@ export * from './Chip';
|
|
|
15
15
|
export * from './CircularLoader';
|
|
16
16
|
export * from './CollapsibleCard';
|
|
17
17
|
export * from './ConditionalWrapper';
|
|
18
|
+
export * from './DateRangePicker';
|
|
18
19
|
export * from './Dialog';
|
|
19
20
|
export * from './Dropdown';
|
|
20
21
|
export * from './EmptyState';
|
package/lib/types/charts.js.flow
CHANGED