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.
Files changed (77) hide show
  1. package/button/styled-components.js +1 -1
  2. package/button/styled-components.js.flow +4 -1
  3. package/datepicker/calendar-header.js +227 -95
  4. package/datepicker/calendar-header.js.flow +270 -139
  5. package/datepicker/constants.js +4 -2
  6. package/datepicker/constants.js.flow +2 -0
  7. package/datepicker/day.js +1 -0
  8. package/datepicker/day.js.flow +1 -0
  9. package/datepicker/index.d.ts +1 -0
  10. package/datepicker/types.js.flow +1 -0
  11. package/datepicker/utils/calendar-header-helpers.js +51 -0
  12. package/datepicker/utils/calendar-header-helpers.js.flow +53 -0
  13. package/dnd-list/index.js.flow +2 -1
  14. package/drawer/drawer.js +2 -1
  15. package/drawer/drawer.js.flow +1 -1
  16. package/es/button/styled-components.js +1 -1
  17. package/es/datepicker/calendar-header.js +184 -84
  18. package/es/datepicker/constants.js +2 -1
  19. package/es/datepicker/day.js +1 -0
  20. package/es/datepicker/utils/calendar-header-helpers.js +34 -0
  21. package/es/dnd-list/index.js +2 -1
  22. package/es/drawer/drawer.js +2 -1
  23. package/es/popover/stateful-container.js +4 -0
  24. package/es/rating/emoticon-rating.js +3 -1
  25. package/es/rating/star-rating.js +3 -1
  26. package/es/select/select-component.js +4 -5
  27. package/es/select/styled-components.js +34 -4
  28. package/es/snackbar/snackbar-context.js +16 -4
  29. package/es/table-semantic/styled-components.js +6 -4
  30. package/es/table-semantic/table-builder.js +3 -0
  31. package/es/themes/dark-theme/color-component-tokens.js +1 -1
  32. package/es/themes/light-theme/color-component-tokens.js +9 -9
  33. package/es/tooltip/styled-components.js +8 -0
  34. package/esm/button/styled-components.js +1 -1
  35. package/esm/datepicker/calendar-header.js +226 -95
  36. package/esm/datepicker/constants.js +2 -1
  37. package/esm/datepicker/day.js +1 -0
  38. package/esm/datepicker/utils/calendar-header-helpers.js +45 -0
  39. package/esm/dnd-list/index.js +2 -1
  40. package/esm/drawer/drawer.js +2 -1
  41. package/esm/popover/stateful-container.js +4 -0
  42. package/esm/rating/emoticon-rating.js +2 -2
  43. package/esm/rating/star-rating.js +2 -2
  44. package/esm/select/select-component.js +4 -5
  45. package/esm/select/styled-components.js +28 -4
  46. package/esm/snackbar/snackbar-context.js +16 -4
  47. package/esm/table-semantic/styled-components.js +6 -4
  48. package/esm/table-semantic/table-builder.js +3 -0
  49. package/esm/themes/dark-theme/color-component-tokens.js +1 -1
  50. package/esm/themes/light-theme/color-component-tokens.js +9 -9
  51. package/esm/tooltip/styled-components.js +8 -0
  52. package/link/index.d.ts +1 -0
  53. package/menu/index.d.ts +7 -0
  54. package/menu/types.js.flow +12 -0
  55. package/package.json +2 -2
  56. package/popover/stateful-container.js +4 -0
  57. package/popover/stateful-container.js.flow +3 -0
  58. package/rating/emoticon-rating.js +2 -2
  59. package/rating/emoticon-rating.js.flow +4 -1
  60. package/rating/star-rating.js +2 -2
  61. package/rating/star-rating.js.flow +4 -1
  62. package/select/select-component.js +4 -5
  63. package/select/select-component.js.flow +4 -5
  64. package/select/styled-components.js +28 -4
  65. package/select/styled-components.js.flow +30 -2
  66. package/snackbar/snackbar-context.js +15 -4
  67. package/snackbar/snackbar-context.js.flow +15 -3
  68. package/table-semantic/styled-components.js +6 -4
  69. package/table-semantic/styled-components.js.flow +6 -4
  70. package/table-semantic/table-builder.js +3 -0
  71. package/table-semantic/table-builder.js.flow +3 -0
  72. package/themes/dark-theme/color-component-tokens.js +1 -1
  73. package/themes/dark-theme/color-component-tokens.js.flow +1 -1
  74. package/themes/light-theme/color-component-tokens.js +9 -9
  75. package/themes/light-theme/color-component-tokens.js.flow +9 -9
  76. package/tooltip/styled-components.js +8 -0
  77. 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 ArrowRight from '../icon/arrow-right.js';
10
- import ArrowLeft from '../icon/arrow-left.js';
11
- import TriangleDown from '../icon/triangle-down.js';
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
- {isMonthYearDropdownOpen: boolean, isFocusVisible: boolean},
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
- items: Array<{id: string, label: string}>;
71
- minYear: number;
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.items = [];
77
+ this.monthItems = [];
78
+ this.yearItems = [];
78
79
  }
79
80
 
80
81
  state = {
81
- isMonthYearDropdownOpen: false,
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
- handleYearChange = ({value}: {value: Array<{id: number}>}) => {
90
- if (this.props.onYearChange) {
91
- // $FlowFixMe
92
- this.props.onYearChange({
93
- date: this.dateHelpers.setYear(this.getDateProp(), value[0].id),
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' ? ArrowRight : ArrowLeft,
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' ? ArrowLeft : ArrowRight,
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.isMonthYearDropdownOpen) {
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 {locale, maxDate, minDate, overrides = {}} = this.props;
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 defaultMonths = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
339
- const maxYear = maxDate ? this.dateHelpers.getYear(maxDate) : MAX_YEAR;
340
- const minYear = minDate ? this.dateHelpers.getYear(minDate) : MIN_YEAR;
341
- const maxDateMonth = maxDate
342
- ? this.dateHelpers.getMonth(maxDate)
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
- if (this.maxYear !== maxYear || this.minYear !== minYear) {
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
- )} ${this.dateHelpers.getYear(date)}`;
452
+ )}`;
453
+ const yearTitle = `${this.dateHelpers.getYear(date)}`;
394
454
 
395
455
  return this.isMultiMonthHorizontal() ? (
396
- <div>{monthYearTitle}</div>
456
+ <div>{`${monthTitle} ${yearTitle}`}</div>
397
457
  ) : (
398
- <OverriddenPopover
399
- placement="bottom"
400
- autoFocus={true}
401
- focusLock={true}
402
- isOpen={this.state.isMonthYearDropdownOpen}
403
- onClick={() => {
404
- this.setState(prev => ({
405
- isMonthYearDropdownOpen: !prev.isMonthYearDropdownOpen,
406
- }));
407
- }}
408
- onClickOutside={() => this.setState({isMonthYearDropdownOpen: false})}
409
- onEsc={() => this.setState({isMonthYearDropdownOpen: false})}
410
- content={() => (
411
- <OverriddenStatefulMenu
412
- initialState={{
413
- highlightedIndex: initialIndex,
414
- isFocused: true,
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
- items={this.items}
417
- onItemSelect={({item, event}) => {
418
- event.preventDefault();
419
- const [year, month] = idToYearMonth(item.id);
420
- const updatedDate = this.dateHelpers.set(date, {
421
- year,
422
- month,
423
- });
424
- this.props.onMonthChange &&
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
- {...menuProps}
431
- />
432
- )}
433
- {...popoverProps}
434
- >
435
- <MonthYearSelectButton
436
- aria-live="polite"
437
- type="button"
438
- $isFocusVisible={this.state.isFocusVisible}
439
- onKeyUp={event => {
440
- if (this.canArrowsOpenDropdown(event)) {
441
- this.setState({isMonthYearDropdownOpen: true});
442
- }
443
- }}
444
- onKeyDown={event => {
445
- if (this.canArrowsOpenDropdown(event)) {
446
- // disables page scroll
447
- event.preventDefault();
448
- }
449
-
450
- if (event.key === 'Tab') {
451
- this.setState({isMonthYearDropdownOpen: false});
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
- {...monthYearSelectButtonProps}
455
- >
456
- {monthYearTitle}
457
- <MonthYearSelectIconContainer {...monthYearSelectIconContainerProps}>
458
- <TriangleDown
459
- title=""
460
- overrides={{Svg: {props: {role: 'presentation'}}}}
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
- </MonthYearSelectIconContainer>
463
- </MonthYearSelectButton>
464
- </OverriddenPopover>
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
 
@@ -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,
@@ -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,
@@ -242,6 +242,7 @@ export type SharedStylePropsT = {
242
242
  $isHeader: boolean;
243
243
  $isHighlighted: boolean;
244
244
  $isHovered: boolean;
245
+ $month: number;
245
246
  $outsideMonth: boolean;
246
247
  $pseudoHighlighted: boolean;
247
248
  $pseudoSelected: boolean;
@@ -231,6 +231,7 @@ export type SharedStylePropsT = {
231
231
  $isHighlighted: ?boolean,
232
232
  $isHovered: ?boolean,
233
233
  $isFocusVisible: ?boolean,
234
+ $month: ?number,
234
235
  $outsideMonth: ?boolean,
235
236
  $outsideMonthWithinRange: ?boolean,
236
237
  $peekNextMonth: ?boolean,
@@ -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;
@@ -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
- export {arrayMove, arrayRemove} from 'react-movable';
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';