1 | const _excluded = ["focusedItem", "disabled", "onChange", "value", "localizer", "min", "max"];
|
2 |
|
3 | function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
4 |
|
5 | function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
6 |
|
7 | import React, { useMemo } from 'react';
|
8 | import CalendarView from './CalendarView';
|
9 | import { chunk } from './_';
|
10 | import dates from './dates';
|
11 |
|
12 | function DecadeView(_ref) {
|
13 | let {
|
14 | focusedItem,
|
15 | disabled,
|
16 | onChange,
|
17 | value,
|
18 | localizer,
|
19 | min,
|
20 | max
|
21 | } = _ref,
|
22 | props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
23 |
|
24 | const chunks = useMemo(() => chunk(getDecadeYears(focusedItem), 4), [focusedItem]);
|
25 | return React.createElement(CalendarView, _extends({}, props, {
|
26 | focusedItem: focusedItem
|
27 | }), React.createElement(CalendarView.Body, null, chunks.map((row, rowIdx) => React.createElement(CalendarView.Row, {
|
28 | key: rowIdx
|
29 | }, row.map((date, colIdx) => {
|
30 | let label = localizer.formatDate(date, 'year');
|
31 | return React.createElement(CalendarView.Cell, {
|
32 | key: colIdx,
|
33 | unit: "year",
|
34 | viewUnit: "decade",
|
35 | label: label,
|
36 | date: date,
|
37 | min: min,
|
38 | max: max,
|
39 | onChange: onChange,
|
40 | focusedItem: focusedItem,
|
41 | selected: value,
|
42 | disabled: disabled
|
43 | }, label);
|
44 | })))));
|
45 | }
|
46 |
|
47 | function getDecadeYears(_date) {
|
48 | let days = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
|
49 | let date = dates.add(dates.startOf(_date, 'decade'), -2, 'year');
|
50 | return days.map(() => date = dates.add(date, 1, 'year'));
|
51 | }
|
52 |
|
53 | export default DecadeView; |
\ | No newline at end of file |