baseui 0.0.0-next-e8c3307 → 0.0.0-next-6acb60a
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/datepicker/calendar-header.js +227 -95
- package/datepicker/calendar-header.js.flow +270 -139
- package/datepicker/constants.js +4 -2
- package/datepicker/constants.js.flow +2 -0
- package/datepicker/utils/calendar-header-helpers.js +51 -0
- package/datepicker/utils/calendar-header-helpers.js.flow +53 -0
- package/drawer/drawer.js +2 -1
- package/drawer/drawer.js.flow +1 -1
- package/es/datepicker/calendar-header.js +184 -84
- package/es/datepicker/constants.js +2 -1
- package/es/datepicker/utils/calendar-header-helpers.js +34 -0
- package/es/drawer/drawer.js +2 -1
- package/es/popover/stateful-container.js +4 -0
- package/es/snackbar/snackbar-context.js +16 -4
- package/es/themes/dark-theme/color-component-tokens.js +1 -1
- package/es/themes/light-theme/color-component-tokens.js +9 -9
- package/esm/datepicker/calendar-header.js +226 -95
- package/esm/datepicker/constants.js +2 -1
- package/esm/datepicker/utils/calendar-header-helpers.js +45 -0
- package/esm/drawer/drawer.js +2 -1
- package/esm/popover/stateful-container.js +4 -0
- package/esm/snackbar/snackbar-context.js +16 -4
- package/esm/themes/dark-theme/color-component-tokens.js +1 -1
- package/esm/themes/light-theme/color-component-tokens.js +9 -9
- package/package.json +1 -1
- package/popover/stateful-container.js +4 -0
- package/popover/stateful-container.js.flow +3 -0
- package/snackbar/snackbar-context.js +15 -4
- package/snackbar/snackbar-context.js.flow +15 -3
- package/themes/dark-theme/color-component-tokens.js +1 -1
- package/themes/dark-theme/color-component-tokens.js.flow +1 -1
- package/themes/light-theme/color-component-tokens.js +9 -9
- package/themes/light-theme/color-component-tokens.js.flow +9 -9
|
@@ -9,11 +9,12 @@ This source code is licensed under the MIT license found in the
|
|
|
9
9
|
LICENSE file in the root directory of this source tree.
|
|
10
10
|
*/
|
|
11
11
|
import * as React from 'react';
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
12
|
+
import ChevronRight from '../icon/chevron-right.js';
|
|
13
|
+
import ChevronLeft from '../icon/chevron-left.js';
|
|
14
|
+
import ChevronDown from '../icon/chevron-down.js';
|
|
15
15
|
import dateFnsAdapter from './utils/date-fns-adapter.js';
|
|
16
16
|
import DateHelpers from './utils/date-helpers.js';
|
|
17
|
+
import { getFilteredMonthItems } from './utils/calendar-header-helpers.js';
|
|
17
18
|
import { StatefulMenu } from '../menu/index.js';
|
|
18
19
|
import { Popover } from '../popover/index.js';
|
|
19
20
|
import { LocaleContext } from '../locale/index.js';
|
|
@@ -38,10 +39,6 @@ const DIRECTION = {
|
|
|
38
39
|
PREVIOUS: 'previous'
|
|
39
40
|
};
|
|
40
41
|
|
|
41
|
-
function yearMonthToId(year, month) {
|
|
42
|
-
return `${year}-${month}`;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
42
|
function idToYearMonth(id) {
|
|
46
43
|
return id.split('-').map(Number);
|
|
47
44
|
}
|
|
@@ -52,14 +49,13 @@ export default class CalendarHeader extends React.Component {
|
|
|
52
49
|
|
|
53
50
|
_defineProperty(this, "dateHelpers", void 0);
|
|
54
51
|
|
|
55
|
-
_defineProperty(this, "
|
|
52
|
+
_defineProperty(this, "monthItems", void 0);
|
|
56
53
|
|
|
57
|
-
_defineProperty(this, "
|
|
58
|
-
|
|
59
|
-
_defineProperty(this, "maxYear", void 0);
|
|
54
|
+
_defineProperty(this, "yearItems", void 0);
|
|
60
55
|
|
|
61
56
|
_defineProperty(this, "state", {
|
|
62
|
-
|
|
57
|
+
isMonthDropdownOpen: false,
|
|
58
|
+
isYearDropdownOpen: false,
|
|
63
59
|
isFocusVisible: false
|
|
64
60
|
});
|
|
65
61
|
|
|
@@ -67,17 +63,73 @@ export default class CalendarHeader extends React.Component {
|
|
|
67
63
|
return this.props.date || this.dateHelpers.date();
|
|
68
64
|
});
|
|
69
65
|
|
|
70
|
-
_defineProperty(this, "
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
66
|
+
_defineProperty(this, "getYearItems", () => {
|
|
67
|
+
const date = this.getDateProp();
|
|
68
|
+
const maxDate = this.props.maxDate;
|
|
69
|
+
const minDate = this.props.minDate;
|
|
70
|
+
const maxYear = maxDate ? this.dateHelpers.getYear(maxDate) : MAX_YEAR;
|
|
71
|
+
const minYear = minDate ? this.dateHelpers.getYear(minDate) : MIN_YEAR;
|
|
72
|
+
const selectedMonth = this.dateHelpers.getMonth(date); // TODO: this logic can be optimized to only run when minDate / maxDate change
|
|
73
|
+
|
|
74
|
+
this.yearItems = Array.from({
|
|
75
|
+
length: maxYear - minYear + 1
|
|
76
|
+
}, (_, i) => minYear + i).map(year => ({
|
|
77
|
+
id: year.toString(),
|
|
78
|
+
label: year.toString()
|
|
79
|
+
}));
|
|
80
|
+
const monthOfMaxDate = maxDate ? this.dateHelpers.getMonth(maxDate) : MAX_MONTH;
|
|
81
|
+
const monthOfMinDate = minDate ? this.dateHelpers.getMonth(minDate) : MIN_MONTH; // Generates array like [0,1,.... monthOfMaxDate]
|
|
82
|
+
|
|
83
|
+
const maxYearMonths = Array.from({
|
|
84
|
+
length: monthOfMaxDate + 1
|
|
85
|
+
}, (x, i) => i); // Generates array like [monthOfMinDate, ...., 10, 11]
|
|
86
|
+
|
|
87
|
+
const minYearMonths = Array.from({
|
|
88
|
+
length: 12 - monthOfMinDate
|
|
89
|
+
}, (x, i) => i + monthOfMinDate);
|
|
90
|
+
|
|
91
|
+
if (selectedMonth > maxYearMonths[maxYearMonths.length - 1]) {
|
|
92
|
+
const lastIdx = this.yearItems.length - 1;
|
|
93
|
+
this.yearItems[lastIdx] = { ...this.yearItems[lastIdx],
|
|
94
|
+
disabled: true
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (selectedMonth < minYearMonths[0]) {
|
|
99
|
+
this.yearItems[0] = { ...this.yearItems[0],
|
|
100
|
+
disabled: true
|
|
101
|
+
};
|
|
78
102
|
}
|
|
79
103
|
});
|
|
80
104
|
|
|
105
|
+
_defineProperty(this, "getMonthItems", () => {
|
|
106
|
+
const date = this.getDateProp();
|
|
107
|
+
const year = this.dateHelpers.getYear(date);
|
|
108
|
+
const maxDate = this.props.maxDate;
|
|
109
|
+
const minDate = this.props.minDate;
|
|
110
|
+
const maxYear = maxDate ? this.dateHelpers.getYear(maxDate) : MAX_YEAR;
|
|
111
|
+
const minYear = minDate ? this.dateHelpers.getYear(minDate) : MIN_YEAR;
|
|
112
|
+
const monthOfMaxDate = maxDate ? this.dateHelpers.getMonth(maxDate) : MAX_MONTH; // Generates array like [0,1,.... monthOfMaxDate]
|
|
113
|
+
|
|
114
|
+
const maxYearMonths = Array.from({
|
|
115
|
+
length: monthOfMaxDate + 1
|
|
116
|
+
}, (x, i) => i);
|
|
117
|
+
const monthOfMinDate = minDate ? this.dateHelpers.getMonth(minDate) : MIN_MONTH; // Generates array like [monthOfMinDate, ...., 10, 11]
|
|
118
|
+
|
|
119
|
+
const minYearMonths = Array.from({
|
|
120
|
+
length: 12 - monthOfMinDate
|
|
121
|
+
}, (x, i) => i + monthOfMinDate);
|
|
122
|
+
const maxMinYearMonthsIntersection = maxYearMonths.filter(year => minYearMonths.includes(year));
|
|
123
|
+
const filterMonthsList = year === maxYear && year === minYear ? maxMinYearMonthsIntersection : year === maxYear ? maxYearMonths : year === minYear ? minYearMonths : null;
|
|
124
|
+
|
|
125
|
+
const formatMonthLabel = month => this.dateHelpers.getMonthInLocale(month, this.props.locale);
|
|
126
|
+
|
|
127
|
+
this.monthItems = getFilteredMonthItems({
|
|
128
|
+
filterMonthsList,
|
|
129
|
+
formatMonthLabel
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
|
|
81
133
|
_defineProperty(this, "increaseMonth", () => {
|
|
82
134
|
if (this.props.onMonthChange) {
|
|
83
135
|
// $FlowFixMe
|
|
@@ -176,7 +228,7 @@ export default class CalendarHeader extends React.Component {
|
|
|
176
228
|
}
|
|
177
229
|
|
|
178
230
|
const [PrevButton, prevButtonProps] = getOverrides(overrides.PrevButton, StyledPrevButton);
|
|
179
|
-
const [PrevButtonIcon, prevButtonIconProps] = getOverrides(overrides.PrevButtonIcon, theme.direction === 'rtl' ?
|
|
231
|
+
const [PrevButtonIcon, prevButtonIconProps] = getOverrides(overrides.PrevButtonIcon, theme.direction === 'rtl' ? ChevronRight : ChevronLeft);
|
|
180
232
|
let clickHandler = this.decreaseMonth;
|
|
181
233
|
|
|
182
234
|
if (allPrevDaysDisabled) {
|
|
@@ -231,7 +283,7 @@ export default class CalendarHeader extends React.Component {
|
|
|
231
283
|
}
|
|
232
284
|
|
|
233
285
|
const [NextButton, nextButtonProps] = getOverrides(overrides.NextButton, StyledNextButton);
|
|
234
|
-
const [NextButtonIcon, nextButtonIconProps] = getOverrides(overrides.NextButtonIcon, theme.direction === 'rtl' ?
|
|
286
|
+
const [NextButtonIcon, nextButtonIconProps] = getOverrides(overrides.NextButtonIcon, theme.direction === 'rtl' ? ChevronLeft : ChevronRight);
|
|
235
287
|
let clickHandler = this.increaseMonth; // The other option is to always provide a click handler and let customers
|
|
236
288
|
// override its functionality based on the `$allPrevDaysDisabled` prop
|
|
237
289
|
// in a custom NextButton component override
|
|
@@ -262,7 +314,7 @@ export default class CalendarHeader extends React.Component {
|
|
|
262
314
|
});
|
|
263
315
|
|
|
264
316
|
_defineProperty(this, "canArrowsOpenDropdown", event => {
|
|
265
|
-
if (!this.state.
|
|
317
|
+
if (!this.state.isMonthDropdownOpen && !this.state.isYearDropdownOpen) {
|
|
266
318
|
if (event.key === 'ArrowUp' || event.key === 'ArrowDown') {
|
|
267
319
|
return true;
|
|
268
320
|
}
|
|
@@ -273,10 +325,10 @@ export default class CalendarHeader extends React.Component {
|
|
|
273
325
|
|
|
274
326
|
_defineProperty(this, "renderMonthYearDropdown", () => {
|
|
275
327
|
const date = this.getDateProp();
|
|
328
|
+
const month = this.dateHelpers.getMonth(date);
|
|
329
|
+
const year = this.dateHelpers.getYear(date);
|
|
276
330
|
const {
|
|
277
331
|
locale,
|
|
278
|
-
maxDate,
|
|
279
|
-
minDate,
|
|
280
332
|
overrides = {}
|
|
281
333
|
} = this.props;
|
|
282
334
|
const [MonthYearSelectButton, monthYearSelectButtonProps] = getOverrides(overrides.MonthYearSelectButton, StyledMonthYearSelectButton);
|
|
@@ -294,79 +346,38 @@ export default class CalendarHeader extends React.Component {
|
|
|
294
346
|
menuProps && menuProps.overrides); // $FlowFixMe
|
|
295
347
|
|
|
296
348
|
menuProps.overrides = menuOverrides;
|
|
297
|
-
const
|
|
298
|
-
const
|
|
299
|
-
const
|
|
300
|
-
const
|
|
301
|
-
|
|
302
|
-
const maxYearMonths = Array.from({
|
|
303
|
-
length: maxDateMonth + 1
|
|
304
|
-
}, (x, i) => i);
|
|
305
|
-
const minDateMonth = minDate ? this.dateHelpers.getMonth(minDate) : MIN_MONTH; // Generates array like [minDateMonth, ...., 10, 11]
|
|
306
|
-
|
|
307
|
-
const minYearMonths = Array.from({
|
|
308
|
-
length: 12 - minDateMonth
|
|
309
|
-
}, (x, i) => i + minDateMonth);
|
|
310
|
-
|
|
311
|
-
if (this.maxYear !== maxYear || this.minYear !== minYear) {
|
|
312
|
-
this.maxYear = maxYear;
|
|
313
|
-
this.minYear = minYear;
|
|
314
|
-
this.items = [];
|
|
315
|
-
|
|
316
|
-
for (let i = minYear; i <= maxYear; i++) {
|
|
317
|
-
let months;
|
|
318
|
-
|
|
319
|
-
if (i === minYear && i === maxYear) {
|
|
320
|
-
months = maxYearMonths.filter(month => minYearMonths.includes(month));
|
|
321
|
-
} else if (i === minYear) {
|
|
322
|
-
months = minYearMonths;
|
|
323
|
-
} else if (i === maxYear) {
|
|
324
|
-
months = maxYearMonths;
|
|
325
|
-
} else {
|
|
326
|
-
months = defaultMonths;
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
months.forEach(month => {
|
|
330
|
-
this.items.push({
|
|
331
|
-
id: yearMonthToId(i, month),
|
|
332
|
-
label: `${this.dateHelpers.getMonthInLocale(month, locale)} ${i}`
|
|
333
|
-
});
|
|
334
|
-
});
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
const initialIndex = this.items.findIndex(item => {
|
|
339
|
-
return item.id === yearMonthToId(this.dateHelpers.getYear(date), this.dateHelpers.getMonth(date));
|
|
340
|
-
});
|
|
341
|
-
const monthYearTitle = `${this.dateHelpers.getMonthInLocale(this.dateHelpers.getMonth(date), locale)} ${this.dateHelpers.getYear(date)}`;
|
|
342
|
-
return this.isMultiMonthHorizontal() ? /*#__PURE__*/React.createElement("div", null, monthYearTitle) : /*#__PURE__*/React.createElement(OverriddenPopover, _extends({
|
|
349
|
+
const initialMonthIndex = this.monthItems.findIndex(month => month.id === this.dateHelpers.getMonth(date).toString());
|
|
350
|
+
const initialYearIndex = this.yearItems.findIndex(year => year.id === this.dateHelpers.getYear(date).toString());
|
|
351
|
+
const monthTitle = `${this.dateHelpers.getMonthInLocale(this.dateHelpers.getMonth(date), locale)}`;
|
|
352
|
+
const yearTitle = `${this.dateHelpers.getYear(date)}`;
|
|
353
|
+
return this.isMultiMonthHorizontal() ? /*#__PURE__*/React.createElement("div", null, `${monthTitle} ${yearTitle}`) : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(OverriddenPopover, _extends({
|
|
343
354
|
placement: "bottom",
|
|
344
355
|
autoFocus: true,
|
|
345
356
|
focusLock: true,
|
|
346
|
-
isOpen: this.state.
|
|
357
|
+
isOpen: this.state.isMonthDropdownOpen,
|
|
347
358
|
onClick: () => {
|
|
348
359
|
this.setState(prev => ({
|
|
349
|
-
|
|
360
|
+
isMonthDropdownOpen: !prev.isMonthDropdownOpen
|
|
350
361
|
}));
|
|
351
362
|
},
|
|
352
363
|
onClickOutside: () => this.setState({
|
|
353
|
-
|
|
364
|
+
isMonthDropdownOpen: false
|
|
354
365
|
}),
|
|
355
366
|
onEsc: () => this.setState({
|
|
356
|
-
|
|
367
|
+
isMonthDropdownOpen: false
|
|
357
368
|
}),
|
|
358
369
|
content: () => /*#__PURE__*/React.createElement(OverriddenStatefulMenu, _extends({
|
|
359
370
|
initialState: {
|
|
360
|
-
highlightedIndex:
|
|
371
|
+
highlightedIndex: initialMonthIndex,
|
|
361
372
|
isFocused: true
|
|
362
373
|
},
|
|
363
|
-
items: this.
|
|
374
|
+
items: this.monthItems,
|
|
364
375
|
onItemSelect: ({
|
|
365
376
|
item,
|
|
366
377
|
event
|
|
367
378
|
}) => {
|
|
368
379
|
event.preventDefault();
|
|
369
|
-
const
|
|
380
|
+
const month = idToYearMonth(item.id);
|
|
370
381
|
const updatedDate = this.dateHelpers.set(date, {
|
|
371
382
|
year,
|
|
372
383
|
month
|
|
@@ -374,11 +385,79 @@ export default class CalendarHeader extends React.Component {
|
|
|
374
385
|
this.props.onMonthChange && this.props.onMonthChange({
|
|
375
386
|
date: updatedDate
|
|
376
387
|
});
|
|
388
|
+
this.setState({
|
|
389
|
+
isMonthDropdownOpen: false
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
}, menuProps))
|
|
393
|
+
}, popoverProps), /*#__PURE__*/React.createElement(MonthYearSelectButton, _extends({
|
|
394
|
+
"aria-live": "polite",
|
|
395
|
+
type: "button",
|
|
396
|
+
$isFocusVisible: this.state.isFocusVisible,
|
|
397
|
+
onKeyUp: event => {
|
|
398
|
+
if (this.canArrowsOpenDropdown(event)) {
|
|
399
|
+
this.setState({
|
|
400
|
+
isMonthDropdownOpen: true
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
},
|
|
404
|
+
onKeyDown: event => {
|
|
405
|
+
if (this.canArrowsOpenDropdown(event)) {
|
|
406
|
+
// disables page scroll
|
|
407
|
+
event.preventDefault();
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
if (event.key === 'Tab') {
|
|
411
|
+
this.setState({
|
|
412
|
+
isMonthDropdownOpen: false
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}, monthYearSelectButtonProps), monthTitle, /*#__PURE__*/React.createElement(MonthYearSelectIconContainer, monthYearSelectIconContainerProps, /*#__PURE__*/React.createElement(ChevronDown, {
|
|
417
|
+
title: "",
|
|
418
|
+
overrides: {
|
|
419
|
+
Svg: {
|
|
420
|
+
props: {
|
|
421
|
+
role: 'presentation'
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
})))), /*#__PURE__*/React.createElement(OverriddenPopover, _extends({
|
|
426
|
+
placement: "bottom",
|
|
427
|
+
focusLock: true,
|
|
428
|
+
isOpen: this.state.isYearDropdownOpen,
|
|
429
|
+
onClick: () => {
|
|
430
|
+
this.setState(prev => ({
|
|
431
|
+
isYearDropdownOpen: !prev.isYearDropdownOpen
|
|
432
|
+
}));
|
|
433
|
+
},
|
|
434
|
+
onClickOutside: () => this.setState({
|
|
435
|
+
isYearDropdownOpen: false
|
|
436
|
+
}),
|
|
437
|
+
onEsc: () => this.setState({
|
|
438
|
+
isYearDropdownOpen: false
|
|
439
|
+
}),
|
|
440
|
+
content: () => /*#__PURE__*/React.createElement(OverriddenStatefulMenu, _extends({
|
|
441
|
+
initialState: {
|
|
442
|
+
highlightedIndex: initialYearIndex,
|
|
443
|
+
isFocused: true
|
|
444
|
+
},
|
|
445
|
+
items: this.yearItems,
|
|
446
|
+
onItemSelect: ({
|
|
447
|
+
item,
|
|
448
|
+
event
|
|
449
|
+
}) => {
|
|
450
|
+
event.preventDefault();
|
|
451
|
+
const year = idToYearMonth(item.id);
|
|
452
|
+
const updatedDate = this.dateHelpers.set(date, {
|
|
453
|
+
year,
|
|
454
|
+
month
|
|
455
|
+
});
|
|
377
456
|
this.props.onYearChange && this.props.onYearChange({
|
|
378
457
|
date: updatedDate
|
|
379
458
|
});
|
|
380
459
|
this.setState({
|
|
381
|
-
|
|
460
|
+
isYearDropdownOpen: false
|
|
382
461
|
});
|
|
383
462
|
}
|
|
384
463
|
}, menuProps))
|
|
@@ -389,7 +468,7 @@ export default class CalendarHeader extends React.Component {
|
|
|
389
468
|
onKeyUp: event => {
|
|
390
469
|
if (this.canArrowsOpenDropdown(event)) {
|
|
391
470
|
this.setState({
|
|
392
|
-
|
|
471
|
+
isYearDropdownOpen: true
|
|
393
472
|
});
|
|
394
473
|
}
|
|
395
474
|
},
|
|
@@ -401,11 +480,11 @@ export default class CalendarHeader extends React.Component {
|
|
|
401
480
|
|
|
402
481
|
if (event.key === 'Tab') {
|
|
403
482
|
this.setState({
|
|
404
|
-
|
|
483
|
+
isYearDropdownOpen: false
|
|
405
484
|
});
|
|
406
485
|
}
|
|
407
486
|
}
|
|
408
|
-
}, monthYearSelectButtonProps),
|
|
487
|
+
}, monthYearSelectButtonProps), yearTitle, /*#__PURE__*/React.createElement(MonthYearSelectIconContainer, monthYearSelectIconContainerProps, /*#__PURE__*/React.createElement(ChevronDown, {
|
|
409
488
|
title: "",
|
|
410
489
|
overrides: {
|
|
411
490
|
Svg: {
|
|
@@ -414,11 +493,32 @@ export default class CalendarHeader extends React.Component {
|
|
|
414
493
|
}
|
|
415
494
|
}
|
|
416
495
|
}
|
|
417
|
-
}))));
|
|
496
|
+
})))));
|
|
418
497
|
});
|
|
419
498
|
|
|
420
499
|
this.dateHelpers = new DateHelpers(props.adapter);
|
|
421
|
-
this.
|
|
500
|
+
this.monthItems = [];
|
|
501
|
+
this.yearItems = [];
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
componentDidMount() {
|
|
505
|
+
this.getYearItems();
|
|
506
|
+
this.getMonthItems();
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
componentDidUpdate(prevProps) {
|
|
510
|
+
const selectedMonthDidChange = this.dateHelpers.getMonth(this.props.date) !== this.dateHelpers.getMonth(prevProps.date);
|
|
511
|
+
const selectedYearDidChange = this.dateHelpers.getYear(this.props.date) !== this.dateHelpers.getYear(prevProps.date);
|
|
512
|
+
|
|
513
|
+
if (selectedMonthDidChange) {
|
|
514
|
+
// re-calculate yearItems
|
|
515
|
+
this.getYearItems();
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
if (selectedYearDidChange) {
|
|
519
|
+
// re-calculate monthItems
|
|
520
|
+
this.getMonthItems();
|
|
521
|
+
}
|
|
422
522
|
}
|
|
423
523
|
|
|
424
524
|
render() {
|
|
@@ -20,4 +20,5 @@ export const STATE_CHANGE_TYPE = Object.freeze({
|
|
|
20
20
|
mouseOver: 'mouseOver',
|
|
21
21
|
mouseLeave: 'mouseLeave'
|
|
22
22
|
});
|
|
23
|
-
export const WEEKDAYS = [0, 1, 2, 3, 4, 5, 6];
|
|
23
|
+
export const WEEKDAYS = [0, 1, 2, 3, 4, 5, 6];
|
|
24
|
+
export const DEFAULT_MONTHS = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (c) Uber Technologies, Inc.
|
|
3
|
+
|
|
4
|
+
This source code is licensed under the MIT license found in the
|
|
5
|
+
LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import { DEFAULT_MONTHS } from '../constants.js';
|
|
8
|
+
|
|
9
|
+
const getDefaultMonthItems = formatMonthLabel => DEFAULT_MONTHS.map(month => ({
|
|
10
|
+
id: month.toString(),
|
|
11
|
+
label: formatMonthLabel(month)
|
|
12
|
+
}));
|
|
13
|
+
|
|
14
|
+
export const filterMonthItems = (monthItems, filterList) => monthItems.map(month => {
|
|
15
|
+
if (!filterList.includes(Number(month.id))) {
|
|
16
|
+
return { ...month,
|
|
17
|
+
disabled: true
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return month;
|
|
22
|
+
});
|
|
23
|
+
export const getFilteredMonthItems = ({
|
|
24
|
+
filterMonthsList,
|
|
25
|
+
formatMonthLabel
|
|
26
|
+
}) => {
|
|
27
|
+
let monthItems = getDefaultMonthItems(formatMonthLabel);
|
|
28
|
+
|
|
29
|
+
if (filterMonthsList) {
|
|
30
|
+
monthItems = filterMonthItems(monthItems, filterMonthsList);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return monthItems;
|
|
34
|
+
};
|
package/es/drawer/drawer.js
CHANGED
|
@@ -252,7 +252,8 @@ class Drawer extends React.Component {
|
|
|
252
252
|
return /*#__PURE__*/React.createElement(LocaleContext.Consumer, null, locale => {
|
|
253
253
|
return /*#__PURE__*/React.createElement(FocusLock, {
|
|
254
254
|
returnFocus: true,
|
|
255
|
-
autoFocus: autoFocus
|
|
255
|
+
autoFocus: autoFocus,
|
|
256
|
+
noFocusGuards: true
|
|
256
257
|
}, /*#__PURE__*/React.createElement(Root, _extends({
|
|
257
258
|
"data-baseweb": "drawer",
|
|
258
259
|
ref: this.getRef('Root')
|
|
@@ -31,6 +31,15 @@ export function useSnackbar() {
|
|
|
31
31
|
dequeue: context.dequeue
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
|
+
|
|
35
|
+
function usePrevious(value) {
|
|
36
|
+
const ref = React.useRef();
|
|
37
|
+
React.useEffect(() => {
|
|
38
|
+
ref.current = value;
|
|
39
|
+
});
|
|
40
|
+
return ref.current;
|
|
41
|
+
}
|
|
42
|
+
|
|
34
43
|
export default function SnackbarProvider({
|
|
35
44
|
children,
|
|
36
45
|
overrides = {},
|
|
@@ -46,10 +55,6 @@ export default function SnackbarProvider({
|
|
|
46
55
|
|
|
47
56
|
function enqueue(elementProps, duration = defaultDuration) {
|
|
48
57
|
setSnackbars(prev => {
|
|
49
|
-
if (prev.length === 0) {
|
|
50
|
-
enter(duration);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
58
|
return [...prev, {
|
|
54
59
|
elementProps,
|
|
55
60
|
duration
|
|
@@ -57,6 +62,13 @@ export default function SnackbarProvider({
|
|
|
57
62
|
});
|
|
58
63
|
}
|
|
59
64
|
|
|
65
|
+
const prevSnackbars = usePrevious(snackbars) || [];
|
|
66
|
+
React.useEffect(() => {
|
|
67
|
+
if (prevSnackbars.length === 0 && snackbars.length >= 1) {
|
|
68
|
+
enter(snackbars[0].duration);
|
|
69
|
+
}
|
|
70
|
+
}, [snackbars, prevSnackbars]);
|
|
71
|
+
|
|
60
72
|
function dequeue() {
|
|
61
73
|
setContainerHeight(0);
|
|
62
74
|
setSnackbars(prev => {
|
|
@@ -91,7 +91,7 @@ export default ((themePrimitives = colorTokens) => ({
|
|
|
91
91
|
linkActive: themePrimitives.primary300,
|
|
92
92
|
// List
|
|
93
93
|
listHeaderFill: themePrimitives.mono600,
|
|
94
|
-
listBodyFill: themePrimitives.
|
|
94
|
+
listBodyFill: themePrimitives.mono800,
|
|
95
95
|
listIconFill: themePrimitives.mono100,
|
|
96
96
|
listBorder: themePrimitives.mono500,
|
|
97
97
|
// ProgressSteps
|
|
@@ -20,32 +20,32 @@ export default ((themePrimitives = colorTokens) => ({
|
|
|
20
20
|
buttonPrimaryActive: themePrimitives.primary600,
|
|
21
21
|
buttonPrimarySelectedFill: themePrimitives.primary600,
|
|
22
22
|
buttonPrimarySelectedText: themePrimitives.white,
|
|
23
|
-
buttonPrimarySpinnerForeground: themePrimitives.
|
|
24
|
-
buttonPrimarySpinnerBackground: themePrimitives.
|
|
23
|
+
buttonPrimarySpinnerForeground: themePrimitives.accent,
|
|
24
|
+
buttonPrimarySpinnerBackground: themePrimitives.primaryB,
|
|
25
25
|
buttonSecondaryFill: themePrimitives.primary100,
|
|
26
26
|
buttonSecondaryText: themePrimitives.primary,
|
|
27
27
|
buttonSecondaryHover: themePrimitives.primary200,
|
|
28
28
|
buttonSecondaryActive: themePrimitives.primary300,
|
|
29
29
|
buttonSecondarySelectedFill: themePrimitives.primary300,
|
|
30
30
|
buttonSecondarySelectedText: themePrimitives.primary,
|
|
31
|
-
buttonSecondarySpinnerForeground: themePrimitives.
|
|
32
|
-
buttonSecondarySpinnerBackground: themePrimitives.
|
|
31
|
+
buttonSecondarySpinnerForeground: themePrimitives.accent,
|
|
32
|
+
buttonSecondarySpinnerBackground: themePrimitives.primaryB,
|
|
33
33
|
buttonTertiaryFill: 'transparent',
|
|
34
34
|
buttonTertiaryText: themePrimitives.primary,
|
|
35
35
|
buttonTertiaryHover: themePrimitives.primary50,
|
|
36
36
|
buttonTertiaryActive: themePrimitives.primary100,
|
|
37
37
|
buttonTertiarySelectedFill: themePrimitives.primary100,
|
|
38
38
|
buttonTertiarySelectedText: themePrimitives.primary,
|
|
39
|
-
buttonTertiarySpinnerForeground: themePrimitives.
|
|
40
|
-
buttonTertiarySpinnerBackground: themePrimitives.
|
|
39
|
+
buttonTertiarySpinnerForeground: themePrimitives.accent,
|
|
40
|
+
buttonTertiarySpinnerBackground: themePrimitives.primary100,
|
|
41
41
|
buttonMinimalFill: 'transparent',
|
|
42
42
|
buttonMinimalText: themePrimitives.primary,
|
|
43
43
|
buttonMinimalHover: themePrimitives.primary50,
|
|
44
44
|
buttonMinimalActive: themePrimitives.primary100,
|
|
45
45
|
buttonMinimalSelectedFill: themePrimitives.primary100,
|
|
46
46
|
buttonMinimalSelectedText: themePrimitives.primary,
|
|
47
|
-
buttonMinimalSpinnerForeground: themePrimitives.
|
|
48
|
-
buttonMinimalSpinnerBackground: themePrimitives.
|
|
47
|
+
buttonMinimalSpinnerForeground: themePrimitives.accent,
|
|
48
|
+
buttonMinimalSpinnerBackground: themePrimitives.primary100,
|
|
49
49
|
buttonDisabledFill: themePrimitives.mono200,
|
|
50
50
|
buttonDisabledText: themePrimitives.mono600,
|
|
51
51
|
buttonDisabledSpinnerForeground: themePrimitives.mono600,
|
|
@@ -91,7 +91,7 @@ export default ((themePrimitives = colorTokens) => ({
|
|
|
91
91
|
linkActive: themePrimitives.primary500,
|
|
92
92
|
// List
|
|
93
93
|
listHeaderFill: themePrimitives.white,
|
|
94
|
-
listBodyFill: themePrimitives.
|
|
94
|
+
listBodyFill: themePrimitives.white,
|
|
95
95
|
listIconFill: themePrimitives.mono500,
|
|
96
96
|
listBorder: themePrimitives.mono500,
|
|
97
97
|
// ProgressSteps
|