-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTileGroup.jsx
100 lines (84 loc) · 1.9 KB
/
TileGroup.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import React from 'react';
import PropTypes from 'prop-types';
import Flex from './Flex';
import { getTileClasses, isCurrentDate } from './shared/utils';
import { tileGroupProps } from './shared/propTypes';
export default function TileGroup({
className,
count,
dateTransform,
dateType,
end,
hover,
offset,
start,
step,
tile: Tile,
value,
valueType,
itemVisibilityClass,
...tileProps
}) {
const tiles = [];
let countDays = 1;
let weekIndex = 0;
let displayWeekIndex = 0;
const numberDaysOfOneRow = 7;
for (let point = start; point <= end; point += step) {
const date = dateTransform(point);
if (countDays % numberDaysOfOneRow === 0) {
weekIndex += 1;
}
if (isCurrentDate(date, dateType)) {
displayWeekIndex = weekIndex;
break;
}
countDays += 1;
}
let countDays1 = 0;
for (let point = start; point <= end; point += step) {
const date = dateTransform(point);
const itemClasses = getTileClasses({
value, valueType, date, dateType, hover, weekIndex,
});
if (Math.floor(countDays1 / numberDaysOfOneRow) !== displayWeekIndex) {
itemClasses.push(itemVisibilityClass || '');
} else {
itemClasses.push('current-date-row');
}
tiles.push(
<Tile
key={date.getTime()}
classes={itemClasses}
date={date}
point={point}
{...tileProps}
/>,
);
countDays1 += 1;
}
return (
<Flex
className={className}
count={count}
offset={offset}
wrap
>
{tiles}
</Flex>
);
}
TileGroup.propTypes = {
...tileGroupProps,
activeStartDate: PropTypes.instanceOf(Date),
count: PropTypes.number,
dateTransform: PropTypes.func.isRequired,
itemVisibilityClass: PropTypes.string,
offset: PropTypes.number,
step: PropTypes.number,
tile: PropTypes.func.isRequired,
};
TileGroup.defaultProps = {
count: 3,
step: 1,
};