baseui 10.5.0 → 10.6.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/button/styled-components.js +1 -1
- package/button/styled-components.js.flow +4 -1
- 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/day.js +1 -0
- package/datepicker/day.js.flow +1 -0
- package/datepicker/index.d.ts +1 -0
- package/datepicker/types.js.flow +1 -0
- package/datepicker/utils/calendar-header-helpers.js +51 -0
- package/datepicker/utils/calendar-header-helpers.js.flow +53 -0
- package/dnd-list/index.js.flow +2 -1
- package/drawer/drawer.js +2 -1
- package/drawer/drawer.js.flow +1 -1
- package/es/button/styled-components.js +1 -1
- package/es/datepicker/calendar-header.js +184 -84
- package/es/datepicker/constants.js +2 -1
- package/es/datepicker/day.js +1 -0
- package/es/datepicker/utils/calendar-header-helpers.js +34 -0
- package/es/dnd-list/index.js +2 -1
- package/es/drawer/drawer.js +2 -1
- package/es/popover/stateful-container.js +4 -0
- package/es/rating/emoticon-rating.js +3 -1
- package/es/rating/star-rating.js +3 -1
- package/es/select/select-component.js +4 -5
- package/es/select/styled-components.js +34 -4
- package/es/snackbar/snackbar-context.js +16 -4
- package/es/table-semantic/styled-components.js +6 -4
- package/es/table-semantic/table-builder.js +3 -0
- package/es/themes/dark-theme/color-component-tokens.js +1 -1
- package/es/themes/light-theme/color-component-tokens.js +9 -9
- package/es/tooltip/styled-components.js +8 -0
- package/esm/button/styled-components.js +1 -1
- package/esm/datepicker/calendar-header.js +226 -95
- package/esm/datepicker/constants.js +2 -1
- package/esm/datepicker/day.js +1 -0
- package/esm/datepicker/utils/calendar-header-helpers.js +45 -0
- package/esm/dnd-list/index.js +2 -1
- package/esm/drawer/drawer.js +2 -1
- package/esm/popover/stateful-container.js +4 -0
- package/esm/rating/emoticon-rating.js +2 -2
- package/esm/rating/star-rating.js +2 -2
- package/esm/select/select-component.js +4 -5
- package/esm/select/styled-components.js +28 -4
- package/esm/snackbar/snackbar-context.js +16 -4
- package/esm/table-semantic/styled-components.js +6 -4
- package/esm/table-semantic/table-builder.js +3 -0
- package/esm/themes/dark-theme/color-component-tokens.js +1 -1
- package/esm/themes/light-theme/color-component-tokens.js +9 -9
- package/esm/tooltip/styled-components.js +8 -0
- package/link/index.d.ts +1 -0
- package/menu/index.d.ts +7 -0
- package/menu/types.js.flow +12 -0
- package/package.json +2 -2
- package/popover/stateful-container.js +4 -0
- package/popover/stateful-container.js.flow +3 -0
- package/rating/emoticon-rating.js +2 -2
- package/rating/emoticon-rating.js.flow +4 -1
- package/rating/star-rating.js +2 -2
- package/rating/star-rating.js.flow +4 -1
- package/select/select-component.js +4 -5
- package/select/select-component.js.flow +4 -5
- package/select/styled-components.js +28 -4
- package/select/styled-components.js.flow +30 -2
- package/snackbar/snackbar-context.js +15 -4
- package/snackbar/snackbar-context.js.flow +15 -3
- package/table-semantic/styled-components.js +6 -4
- package/table-semantic/styled-components.js.flow +6 -4
- package/table-semantic/table-builder.js +3 -0
- package/table-semantic/table-builder.js.flow +3 -0
- 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
- package/tooltip/styled-components.js +8 -0
- package/tooltip/styled-components.js.flow +8 -0
|
@@ -6,11 +6,12 @@ LICENSE file in the root directory of this source tree.
|
|
|
6
6
|
*/
|
|
7
7
|
// @flow
|
|
8
8
|
import * as React from 'react';
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
9
|
+
import ChevronRight from '../icon/chevron-right.js';
|
|
10
|
+
import ChevronLeft from '../icon/chevron-left.js';
|
|
11
|
+
import ChevronDown from '../icon/chevron-down.js';
|
|
12
12
|
import dateFnsAdapter from './utils/date-fns-adapter.js';
|
|
13
13
|
import DateHelpers from './utils/date-helpers.js';
|
|
14
|
+
import {getFilteredMonthItems} from './utils/calendar-header-helpers.js';
|
|
14
15
|
import {StatefulMenu} from '../menu/index.js';
|
|
15
16
|
import {Popover} from '../popover/index.js';
|
|
16
17
|
import {LocaleContext} from '../locale/index.js';
|
|
@@ -45,17 +46,17 @@ const DIRECTION = {
|
|
|
45
46
|
PREVIOUS: 'previous',
|
|
46
47
|
};
|
|
47
48
|
|
|
48
|
-
function yearMonthToId(year, month) {
|
|
49
|
-
return `${year}-${month}`;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
49
|
function idToYearMonth(id) {
|
|
53
50
|
return id.split('-').map(Number);
|
|
54
51
|
}
|
|
55
52
|
|
|
56
53
|
export default class CalendarHeader<T = Date> extends React.Component<
|
|
57
54
|
HeaderPropsT<T>,
|
|
58
|
-
{
|
|
55
|
+
{
|
|
56
|
+
isMonthDropdownOpen: boolean,
|
|
57
|
+
isYearDropdownOpen: boolean,
|
|
58
|
+
isFocusVisible: boolean,
|
|
59
|
+
},
|
|
59
60
|
> {
|
|
60
61
|
static defaultProps = {
|
|
61
62
|
adapter: dateFnsAdapter,
|
|
@@ -67,34 +68,134 @@ export default class CalendarHeader<T = Date> extends React.Component<
|
|
|
67
68
|
};
|
|
68
69
|
|
|
69
70
|
dateHelpers: DateHelpers<T>;
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
maxYear: number;
|
|
71
|
+
monthItems: Array<{id: string, label: string, disabled?: boolean}>;
|
|
72
|
+
yearItems: Array<{id: string, label: string, disabled?: boolean}>;
|
|
73
73
|
|
|
74
74
|
constructor(props: HeaderPropsT<T>) {
|
|
75
75
|
super(props);
|
|
76
76
|
this.dateHelpers = new DateHelpers(props.adapter);
|
|
77
|
-
this.
|
|
77
|
+
this.monthItems = [];
|
|
78
|
+
this.yearItems = [];
|
|
78
79
|
}
|
|
79
80
|
|
|
80
81
|
state = {
|
|
81
|
-
|
|
82
|
+
isMonthDropdownOpen: false,
|
|
83
|
+
isYearDropdownOpen: false,
|
|
82
84
|
isFocusVisible: false,
|
|
83
85
|
};
|
|
84
86
|
|
|
87
|
+
componentDidMount() {
|
|
88
|
+
this.getYearItems();
|
|
89
|
+
this.getMonthItems();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
componentDidUpdate(prevProps: HeaderPropsT<T>) {
|
|
93
|
+
const selectedMonthDidChange =
|
|
94
|
+
this.dateHelpers.getMonth(this.props.date) !==
|
|
95
|
+
this.dateHelpers.getMonth(prevProps.date);
|
|
96
|
+
|
|
97
|
+
const selectedYearDidChange =
|
|
98
|
+
this.dateHelpers.getYear(this.props.date) !==
|
|
99
|
+
this.dateHelpers.getYear(prevProps.date);
|
|
100
|
+
|
|
101
|
+
if (selectedMonthDidChange) {
|
|
102
|
+
// re-calculate yearItems
|
|
103
|
+
this.getYearItems();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (selectedYearDidChange) {
|
|
107
|
+
// re-calculate monthItems
|
|
108
|
+
this.getMonthItems();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
85
112
|
getDateProp: () => T = () => {
|
|
86
113
|
return this.props.date || this.dateHelpers.date();
|
|
87
114
|
};
|
|
88
115
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
116
|
+
getYearItems = () => {
|
|
117
|
+
const date = this.getDateProp();
|
|
118
|
+
const maxDate = this.props.maxDate;
|
|
119
|
+
const minDate = this.props.minDate;
|
|
120
|
+
const maxYear = maxDate ? this.dateHelpers.getYear(maxDate) : MAX_YEAR;
|
|
121
|
+
const minYear = minDate ? this.dateHelpers.getYear(minDate) : MIN_YEAR;
|
|
122
|
+
const selectedMonth = this.dateHelpers.getMonth(date);
|
|
123
|
+
|
|
124
|
+
// TODO: this logic can be optimized to only run when minDate / maxDate change
|
|
125
|
+
this.yearItems = Array.from(
|
|
126
|
+
{length: maxYear - minYear + 1},
|
|
127
|
+
(_, i) => minYear + i,
|
|
128
|
+
).map(year => ({id: year.toString(), label: year.toString()}));
|
|
129
|
+
const monthOfMaxDate = maxDate
|
|
130
|
+
? this.dateHelpers.getMonth(maxDate)
|
|
131
|
+
: MAX_MONTH;
|
|
132
|
+
const monthOfMinDate = minDate
|
|
133
|
+
? this.dateHelpers.getMonth(minDate)
|
|
134
|
+
: MIN_MONTH;
|
|
135
|
+
// Generates array like [0,1,.... monthOfMaxDate]
|
|
136
|
+
const maxYearMonths = Array.from({length: monthOfMaxDate + 1}, (x, i) => i);
|
|
137
|
+
// Generates array like [monthOfMinDate, ...., 10, 11]
|
|
138
|
+
const minYearMonths = Array.from(
|
|
139
|
+
{length: 12 - monthOfMinDate},
|
|
140
|
+
(x, i) => i + monthOfMinDate,
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
if (selectedMonth > maxYearMonths[maxYearMonths.length - 1]) {
|
|
144
|
+
const lastIdx = this.yearItems.length - 1;
|
|
145
|
+
this.yearItems[lastIdx] = {...this.yearItems[lastIdx], disabled: true};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (selectedMonth < minYearMonths[0]) {
|
|
149
|
+
this.yearItems[0] = {...this.yearItems[0], disabled: true};
|
|
95
150
|
}
|
|
96
151
|
};
|
|
97
152
|
|
|
153
|
+
getMonthItems = () => {
|
|
154
|
+
const date = this.getDateProp();
|
|
155
|
+
const year = this.dateHelpers.getYear(date);
|
|
156
|
+
const maxDate = this.props.maxDate;
|
|
157
|
+
const minDate = this.props.minDate;
|
|
158
|
+
const maxYear = maxDate ? this.dateHelpers.getYear(maxDate) : MAX_YEAR;
|
|
159
|
+
const minYear = minDate ? this.dateHelpers.getYear(minDate) : MIN_YEAR;
|
|
160
|
+
|
|
161
|
+
const monthOfMaxDate = maxDate
|
|
162
|
+
? this.dateHelpers.getMonth(maxDate)
|
|
163
|
+
: MAX_MONTH;
|
|
164
|
+
// Generates array like [0,1,.... monthOfMaxDate]
|
|
165
|
+
const maxYearMonths = Array.from({length: monthOfMaxDate + 1}, (x, i) => i);
|
|
166
|
+
|
|
167
|
+
const monthOfMinDate = minDate
|
|
168
|
+
? this.dateHelpers.getMonth(minDate)
|
|
169
|
+
: MIN_MONTH;
|
|
170
|
+
|
|
171
|
+
// Generates array like [monthOfMinDate, ...., 10, 11]
|
|
172
|
+
const minYearMonths = Array.from(
|
|
173
|
+
{length: 12 - monthOfMinDate},
|
|
174
|
+
(x, i) => i + monthOfMinDate,
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
const maxMinYearMonthsIntersection = maxYearMonths.filter(year =>
|
|
178
|
+
minYearMonths.includes(year),
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
const filterMonthsList =
|
|
182
|
+
year === maxYear && year === minYear
|
|
183
|
+
? maxMinYearMonthsIntersection
|
|
184
|
+
: year === maxYear
|
|
185
|
+
? maxYearMonths
|
|
186
|
+
: year === minYear
|
|
187
|
+
? minYearMonths
|
|
188
|
+
: null;
|
|
189
|
+
|
|
190
|
+
const formatMonthLabel = month =>
|
|
191
|
+
this.dateHelpers.getMonthInLocale(month, this.props.locale);
|
|
192
|
+
|
|
193
|
+
this.monthItems = getFilteredMonthItems({
|
|
194
|
+
filterMonthsList,
|
|
195
|
+
formatMonthLabel,
|
|
196
|
+
});
|
|
197
|
+
};
|
|
198
|
+
|
|
98
199
|
increaseMonth = () => {
|
|
99
200
|
if (this.props.onMonthChange) {
|
|
100
201
|
// $FlowFixMe
|
|
@@ -194,7 +295,7 @@ export default class CalendarHeader<T = Date> extends React.Component<
|
|
|
194
295
|
);
|
|
195
296
|
const [PrevButtonIcon, prevButtonIconProps] = getOverrides(
|
|
196
297
|
overrides.PrevButtonIcon,
|
|
197
|
-
theme.direction === 'rtl' ?
|
|
298
|
+
theme.direction === 'rtl' ? ChevronRight : ChevronLeft,
|
|
198
299
|
);
|
|
199
300
|
let clickHandler = this.decreaseMonth;
|
|
200
301
|
if (allPrevDaysDisabled) {
|
|
@@ -260,7 +361,7 @@ export default class CalendarHeader<T = Date> extends React.Component<
|
|
|
260
361
|
);
|
|
261
362
|
const [NextButtonIcon, nextButtonIconProps] = getOverrides(
|
|
262
363
|
overrides.NextButtonIcon,
|
|
263
|
-
theme.direction === 'rtl' ?
|
|
364
|
+
theme.direction === 'rtl' ? ChevronLeft : ChevronRight,
|
|
264
365
|
);
|
|
265
366
|
|
|
266
367
|
let clickHandler = this.increaseMonth;
|
|
@@ -297,7 +398,7 @@ export default class CalendarHeader<T = Date> extends React.Component<
|
|
|
297
398
|
};
|
|
298
399
|
|
|
299
400
|
canArrowsOpenDropdown = (event: KeyboardEvent) => {
|
|
300
|
-
if (!this.state.
|
|
401
|
+
if (!this.state.isMonthDropdownOpen && !this.state.isYearDropdownOpen) {
|
|
301
402
|
if (event.key === 'ArrowUp' || event.key === 'ArrowDown') {
|
|
302
403
|
return true;
|
|
303
404
|
}
|
|
@@ -307,7 +408,10 @@ export default class CalendarHeader<T = Date> extends React.Component<
|
|
|
307
408
|
|
|
308
409
|
renderMonthYearDropdown = () => {
|
|
309
410
|
const date = this.getDateProp();
|
|
310
|
-
const
|
|
411
|
+
const month = this.dateHelpers.getMonth(date);
|
|
412
|
+
const year = this.dateHelpers.getYear(date);
|
|
413
|
+
|
|
414
|
+
const {locale, overrides = {}} = this.props;
|
|
311
415
|
const [MonthYearSelectButton, monthYearSelectButtonProps] = getOverrides(
|
|
312
416
|
overrides.MonthYearSelectButton,
|
|
313
417
|
StyledMonthYearSelectButton,
|
|
@@ -335,133 +439,160 @@ export default class CalendarHeader<T = Date> extends React.Component<
|
|
|
335
439
|
// $FlowFixMe
|
|
336
440
|
menuProps.overrides = menuOverrides;
|
|
337
441
|
|
|
338
|
-
const
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
const
|
|
342
|
-
|
|
343
|
-
: MAX_MONTH;
|
|
344
|
-
// Generates array like [0,1,.... maxDateMonth]
|
|
345
|
-
const maxYearMonths = Array.from({length: maxDateMonth + 1}, (x, i) => i);
|
|
346
|
-
|
|
347
|
-
const minDateMonth = minDate
|
|
348
|
-
? this.dateHelpers.getMonth(minDate)
|
|
349
|
-
: MIN_MONTH;
|
|
350
|
-
// Generates array like [minDateMonth, ...., 10, 11]
|
|
351
|
-
const minYearMonths = Array.from(
|
|
352
|
-
{length: 12 - minDateMonth},
|
|
353
|
-
(x, i) => i + minDateMonth,
|
|
442
|
+
const initialMonthIndex = this.monthItems.findIndex(
|
|
443
|
+
month => month.id === this.dateHelpers.getMonth(date).toString(),
|
|
444
|
+
);
|
|
445
|
+
const initialYearIndex = this.yearItems.findIndex(
|
|
446
|
+
year => year.id === this.dateHelpers.getYear(date).toString(),
|
|
354
447
|
);
|
|
355
448
|
|
|
356
|
-
|
|
357
|
-
this.maxYear = maxYear;
|
|
358
|
-
this.minYear = minYear;
|
|
359
|
-
this.items = [];
|
|
360
|
-
for (let i = minYear; i <= maxYear; i++) {
|
|
361
|
-
let months;
|
|
362
|
-
if (i === minYear && i === maxYear) {
|
|
363
|
-
months = maxYearMonths.filter(month => minYearMonths.includes(month));
|
|
364
|
-
} else if (i === minYear) {
|
|
365
|
-
months = minYearMonths;
|
|
366
|
-
} else if (i === maxYear) {
|
|
367
|
-
months = maxYearMonths;
|
|
368
|
-
} else {
|
|
369
|
-
months = defaultMonths;
|
|
370
|
-
}
|
|
371
|
-
months.forEach(month => {
|
|
372
|
-
this.items.push({
|
|
373
|
-
id: yearMonthToId(i, month),
|
|
374
|
-
label: `${this.dateHelpers.getMonthInLocale(month, locale)} ${i}`,
|
|
375
|
-
});
|
|
376
|
-
});
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
const initialIndex = this.items.findIndex(item => {
|
|
381
|
-
return (
|
|
382
|
-
item.id ===
|
|
383
|
-
yearMonthToId(
|
|
384
|
-
this.dateHelpers.getYear(date),
|
|
385
|
-
this.dateHelpers.getMonth(date),
|
|
386
|
-
)
|
|
387
|
-
);
|
|
388
|
-
});
|
|
389
|
-
|
|
390
|
-
const monthYearTitle = `${this.dateHelpers.getMonthInLocale(
|
|
449
|
+
const monthTitle = `${this.dateHelpers.getMonthInLocale(
|
|
391
450
|
this.dateHelpers.getMonth(date),
|
|
392
451
|
locale,
|
|
393
|
-
)}
|
|
452
|
+
)}`;
|
|
453
|
+
const yearTitle = `${this.dateHelpers.getYear(date)}`;
|
|
394
454
|
|
|
395
455
|
return this.isMultiMonthHorizontal() ? (
|
|
396
|
-
<div>{
|
|
456
|
+
<div>{`${monthTitle} ${yearTitle}`}</div>
|
|
397
457
|
) : (
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
this.
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
458
|
+
<>
|
|
459
|
+
{/* Month Selection */}
|
|
460
|
+
<OverriddenPopover
|
|
461
|
+
placement="bottom"
|
|
462
|
+
autoFocus={true}
|
|
463
|
+
focusLock={true}
|
|
464
|
+
isOpen={this.state.isMonthDropdownOpen}
|
|
465
|
+
onClick={() => {
|
|
466
|
+
this.setState(prev => ({
|
|
467
|
+
isMonthDropdownOpen: !prev.isMonthDropdownOpen,
|
|
468
|
+
}));
|
|
469
|
+
}}
|
|
470
|
+
onClickOutside={() => this.setState({isMonthDropdownOpen: false})}
|
|
471
|
+
onEsc={() => this.setState({isMonthDropdownOpen: false})}
|
|
472
|
+
content={() => (
|
|
473
|
+
<OverriddenStatefulMenu
|
|
474
|
+
initialState={{
|
|
475
|
+
highlightedIndex: initialMonthIndex,
|
|
476
|
+
isFocused: true,
|
|
477
|
+
}}
|
|
478
|
+
items={this.monthItems}
|
|
479
|
+
onItemSelect={({item, event}) => {
|
|
480
|
+
event.preventDefault();
|
|
481
|
+
const month = idToYearMonth(item.id);
|
|
482
|
+
const updatedDate = this.dateHelpers.set(date, {
|
|
483
|
+
year,
|
|
484
|
+
month,
|
|
485
|
+
});
|
|
486
|
+
this.props.onMonthChange &&
|
|
487
|
+
this.props.onMonthChange({date: updatedDate});
|
|
488
|
+
this.setState({isMonthDropdownOpen: false});
|
|
489
|
+
}}
|
|
490
|
+
{...menuProps}
|
|
491
|
+
/>
|
|
492
|
+
)}
|
|
493
|
+
{...popoverProps}
|
|
494
|
+
>
|
|
495
|
+
<MonthYearSelectButton
|
|
496
|
+
aria-live="polite"
|
|
497
|
+
type="button"
|
|
498
|
+
$isFocusVisible={this.state.isFocusVisible}
|
|
499
|
+
onKeyUp={event => {
|
|
500
|
+
if (this.canArrowsOpenDropdown(event)) {
|
|
501
|
+
this.setState({isMonthDropdownOpen: true});
|
|
502
|
+
}
|
|
415
503
|
}}
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
this.props.onMonthChange({date: updatedDate});
|
|
426
|
-
this.props.onYearChange &&
|
|
427
|
-
this.props.onYearChange({date: updatedDate});
|
|
428
|
-
this.setState({isMonthYearDropdownOpen: false});
|
|
504
|
+
onKeyDown={event => {
|
|
505
|
+
if (this.canArrowsOpenDropdown(event)) {
|
|
506
|
+
// disables page scroll
|
|
507
|
+
event.preventDefault();
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
if (event.key === 'Tab') {
|
|
511
|
+
this.setState({isMonthDropdownOpen: false});
|
|
512
|
+
}
|
|
429
513
|
}}
|
|
430
|
-
{...
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
}
|
|
514
|
+
{...monthYearSelectButtonProps}
|
|
515
|
+
>
|
|
516
|
+
{monthTitle}
|
|
517
|
+
<MonthYearSelectIconContainer
|
|
518
|
+
{...monthYearSelectIconContainerProps}
|
|
519
|
+
>
|
|
520
|
+
<ChevronDown
|
|
521
|
+
title=""
|
|
522
|
+
overrides={{Svg: {props: {role: 'presentation'}}}}
|
|
523
|
+
/>
|
|
524
|
+
</MonthYearSelectIconContainer>
|
|
525
|
+
</MonthYearSelectButton>
|
|
526
|
+
</OverriddenPopover>
|
|
527
|
+
|
|
528
|
+
{/* Year Selection */}
|
|
529
|
+
<OverriddenPopover
|
|
530
|
+
placement="bottom"
|
|
531
|
+
focusLock={true}
|
|
532
|
+
isOpen={this.state.isYearDropdownOpen}
|
|
533
|
+
onClick={() => {
|
|
534
|
+
this.setState(prev => ({
|
|
535
|
+
isYearDropdownOpen: !prev.isYearDropdownOpen,
|
|
536
|
+
}));
|
|
453
537
|
}}
|
|
454
|
-
{
|
|
455
|
-
|
|
456
|
-
{
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
538
|
+
onClickOutside={() => this.setState({isYearDropdownOpen: false})}
|
|
539
|
+
onEsc={() => this.setState({isYearDropdownOpen: false})}
|
|
540
|
+
content={() => (
|
|
541
|
+
<OverriddenStatefulMenu
|
|
542
|
+
initialState={{
|
|
543
|
+
highlightedIndex: initialYearIndex,
|
|
544
|
+
isFocused: true,
|
|
545
|
+
}}
|
|
546
|
+
items={this.yearItems}
|
|
547
|
+
onItemSelect={({item, event}) => {
|
|
548
|
+
event.preventDefault();
|
|
549
|
+
const year = idToYearMonth(item.id);
|
|
550
|
+
const updatedDate = this.dateHelpers.set(date, {
|
|
551
|
+
year,
|
|
552
|
+
month,
|
|
553
|
+
});
|
|
554
|
+
this.props.onYearChange &&
|
|
555
|
+
this.props.onYearChange({date: updatedDate});
|
|
556
|
+
this.setState({isYearDropdownOpen: false});
|
|
557
|
+
}}
|
|
558
|
+
{...menuProps}
|
|
461
559
|
/>
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
560
|
+
)}
|
|
561
|
+
{...popoverProps}
|
|
562
|
+
>
|
|
563
|
+
<MonthYearSelectButton
|
|
564
|
+
aria-live="polite"
|
|
565
|
+
type="button"
|
|
566
|
+
$isFocusVisible={this.state.isFocusVisible}
|
|
567
|
+
onKeyUp={event => {
|
|
568
|
+
if (this.canArrowsOpenDropdown(event)) {
|
|
569
|
+
this.setState({isYearDropdownOpen: true});
|
|
570
|
+
}
|
|
571
|
+
}}
|
|
572
|
+
onKeyDown={event => {
|
|
573
|
+
if (this.canArrowsOpenDropdown(event)) {
|
|
574
|
+
// disables page scroll
|
|
575
|
+
event.preventDefault();
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
if (event.key === 'Tab') {
|
|
579
|
+
this.setState({isYearDropdownOpen: false});
|
|
580
|
+
}
|
|
581
|
+
}}
|
|
582
|
+
{...monthYearSelectButtonProps}
|
|
583
|
+
>
|
|
584
|
+
{yearTitle}
|
|
585
|
+
<MonthYearSelectIconContainer
|
|
586
|
+
{...monthYearSelectIconContainerProps}
|
|
587
|
+
>
|
|
588
|
+
<ChevronDown
|
|
589
|
+
title=""
|
|
590
|
+
overrides={{Svg: {props: {role: 'presentation'}}}}
|
|
591
|
+
/>
|
|
592
|
+
</MonthYearSelectIconContainer>
|
|
593
|
+
</MonthYearSelectButton>
|
|
594
|
+
</OverriddenPopover>
|
|
595
|
+
</>
|
|
465
596
|
);
|
|
466
597
|
};
|
|
467
598
|
|
package/datepicker/constants.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.WEEKDAYS = exports.STATE_CHANGE_TYPE = exports.ORIENTATION = exports.ISO_MONTH_FORMAT = exports.ISO_FORMAT = exports.DISPLAY_FORMAT = void 0;
|
|
6
|
+
exports.DEFAULT_MONTHS = exports.WEEKDAYS = exports.STATE_CHANGE_TYPE = exports.ORIENTATION = exports.ISO_MONTH_FORMAT = exports.ISO_FORMAT = exports.DISPLAY_FORMAT = void 0;
|
|
7
7
|
|
|
8
8
|
/*
|
|
9
9
|
Copyright (c) Uber Technologies, Inc.
|
|
@@ -33,4 +33,6 @@ var STATE_CHANGE_TYPE = Object.freeze({
|
|
|
33
33
|
});
|
|
34
34
|
exports.STATE_CHANGE_TYPE = STATE_CHANGE_TYPE;
|
|
35
35
|
var WEEKDAYS = [0, 1, 2, 3, 4, 5, 6];
|
|
36
|
-
exports.WEEKDAYS = WEEKDAYS;
|
|
36
|
+
exports.WEEKDAYS = WEEKDAYS;
|
|
37
|
+
var DEFAULT_MONTHS = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
|
|
38
|
+
exports.DEFAULT_MONTHS = DEFAULT_MONTHS;
|
|
@@ -26,6 +26,8 @@ export const STATE_CHANGE_TYPE = Object.freeze({
|
|
|
26
26
|
|
|
27
27
|
export const WEEKDAYS = [0, 1, 2, 3, 4, 5, 6];
|
|
28
28
|
|
|
29
|
+
export const DEFAULT_MONTHS = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
|
|
30
|
+
|
|
29
31
|
declare var __DEV__: boolean;
|
|
30
32
|
declare var __NODE__: boolean;
|
|
31
33
|
declare var __BROWSER__: boolean;
|
package/datepicker/day.js
CHANGED
|
@@ -357,6 +357,7 @@ var Day = /*#__PURE__*/function (_React$Component) {
|
|
|
357
357
|
$isFocusVisible: this.state.isFocusVisible,
|
|
358
358
|
$startOfMonth: this.dateHelpers.isStartOfMonth(date),
|
|
359
359
|
$endOfMonth: this.dateHelpers.isEndOfMonth(date),
|
|
360
|
+
$month: this.getMonthProp(),
|
|
360
361
|
$outsideMonth: $outsideMonth,
|
|
361
362
|
$outsideMonthWithinRange: $outsideMonthWithinRange,
|
|
362
363
|
$peekNextMonth: this.props.peekNextMonth,
|
package/datepicker/day.js.flow
CHANGED
|
@@ -313,6 +313,7 @@ export default class Day<T = Date> extends React.Component<
|
|
|
313
313
|
$isFocusVisible: this.state.isFocusVisible,
|
|
314
314
|
$startOfMonth: this.dateHelpers.isStartOfMonth(date),
|
|
315
315
|
$endOfMonth: this.dateHelpers.isEndOfMonth(date),
|
|
316
|
+
$month: this.getMonthProp(),
|
|
316
317
|
$outsideMonth,
|
|
317
318
|
$outsideMonthWithinRange,
|
|
318
319
|
$peekNextMonth: this.props.peekNextMonth,
|
package/datepicker/index.d.ts
CHANGED
package/datepicker/types.js.flow
CHANGED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getFilteredMonthItems = exports.filterMonthItems = void 0;
|
|
7
|
+
|
|
8
|
+
var _constants = require("../constants.js");
|
|
9
|
+
|
|
10
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
|
11
|
+
|
|
12
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
13
|
+
|
|
14
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
15
|
+
|
|
16
|
+
var getDefaultMonthItems = function getDefaultMonthItems(formatMonthLabel) {
|
|
17
|
+
return _constants.DEFAULT_MONTHS.map(function (month) {
|
|
18
|
+
return {
|
|
19
|
+
id: month.toString(),
|
|
20
|
+
label: formatMonthLabel(month)
|
|
21
|
+
};
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
var filterMonthItems = function filterMonthItems(monthItems, filterList) {
|
|
26
|
+
return monthItems.map(function (month) {
|
|
27
|
+
if (!filterList.includes(Number(month.id))) {
|
|
28
|
+
return _objectSpread(_objectSpread({}, month), {}, {
|
|
29
|
+
disabled: true
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return month;
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
exports.filterMonthItems = filterMonthItems;
|
|
38
|
+
|
|
39
|
+
var getFilteredMonthItems = function getFilteredMonthItems(_ref) {
|
|
40
|
+
var filterMonthsList = _ref.filterMonthsList,
|
|
41
|
+
formatMonthLabel = _ref.formatMonthLabel;
|
|
42
|
+
var monthItems = getDefaultMonthItems(formatMonthLabel);
|
|
43
|
+
|
|
44
|
+
if (filterMonthsList) {
|
|
45
|
+
monthItems = filterMonthItems(monthItems, filterMonthsList);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return monthItems;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
exports.getFilteredMonthItems = getFilteredMonthItems;
|
|
@@ -0,0 +1,53 @@
|
|
|
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
|
+
// @flow
|
|
8
|
+
import {DEFAULT_MONTHS} from '../constants.js';
|
|
9
|
+
|
|
10
|
+
export type OptionT = {
|
|
11
|
+
id: string,
|
|
12
|
+
label: string,
|
|
13
|
+
disabled?: boolean,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
type GetMonthItemsArgsT = {
|
|
17
|
+
filterMonthsList: number[] | null,
|
|
18
|
+
formatMonthLabel: number => string,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const getDefaultMonthItems = (formatMonthLabel: number => string) =>
|
|
22
|
+
DEFAULT_MONTHS.map<OptionT>(month => ({
|
|
23
|
+
id: month.toString(),
|
|
24
|
+
label: formatMonthLabel(month),
|
|
25
|
+
}));
|
|
26
|
+
|
|
27
|
+
export const filterMonthItems = (monthItems: OptionT[], filterList: number[]) =>
|
|
28
|
+
monthItems.map<OptionT>(month => {
|
|
29
|
+
if (!filterList.includes(Number(month.id))) {
|
|
30
|
+
return {
|
|
31
|
+
...month,
|
|
32
|
+
disabled: true,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
return month;
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
export const getFilteredMonthItems = ({
|
|
39
|
+
filterMonthsList,
|
|
40
|
+
formatMonthLabel,
|
|
41
|
+
}: GetMonthItemsArgsT) => {
|
|
42
|
+
let monthItems = getDefaultMonthItems(formatMonthLabel);
|
|
43
|
+
|
|
44
|
+
if (filterMonthsList) {
|
|
45
|
+
monthItems = filterMonthItems(monthItems, filterMonthsList);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return monthItems;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
declare var __DEV__: boolean;
|
|
52
|
+
declare var __NODE__: boolean;
|
|
53
|
+
declare var __BROWSER__: boolean;
|
package/dnd-list/index.js.flow
CHANGED
|
@@ -5,7 +5,8 @@ This source code is licensed under the MIT license found in the
|
|
|
5
5
|
LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
// @flow
|
|
8
|
-
|
|
8
|
+
import {arrayMove, arrayRemove} from 'react-movable';
|
|
9
|
+
export {arrayMove, arrayRemove};
|
|
9
10
|
export {default as StatefulList} from './stateful-list.js';
|
|
10
11
|
export {default as StatefulListContainer} from './stateful-list-container.js';
|
|
11
12
|
export {default as List} from './list.js';
|