forked from gpbl/react-day-picker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWeekdays.js
More file actions
67 lines (62 loc) · 1.79 KB
/
Copy pathWeekdays.js
File metadata and controls
67 lines (62 loc) · 1.79 KB
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
import React, { Component } from 'react';
import PropTypes from 'prop-types';
export default class Weekdays extends Component {
static propTypes = {
classNames: PropTypes.shape({
weekday: PropTypes.string.isRequired,
weekdays: PropTypes.string.isRequired,
weekdaysRow: PropTypes.string.isRequired,
}).isRequired,
firstDayOfWeek: PropTypes.number.isRequired,
weekdaysLong: PropTypes.arrayOf(PropTypes.string),
weekdaysShort: PropTypes.arrayOf(PropTypes.string),
showWeekNumbers: PropTypes.bool,
locale: PropTypes.string.isRequired,
localeUtils: PropTypes.object.isRequired,
weekdayElement: PropTypes.oneOfType([
PropTypes.element,
PropTypes.func,
PropTypes.instanceOf(React.Component),
]),
};
shouldComponentUpdate(nextProps) {
return this.props !== nextProps;
}
render() {
const {
classNames,
firstDayOfWeek,
showWeekNumbers,
weekdaysLong,
weekdaysShort,
locale,
localeUtils,
weekdayElement,
} = this.props;
const days = [];
for (let i = 0; i < 7; i += 1) {
const weekday = (i + firstDayOfWeek) % 7;
const elementProps = {
key: i,
className: classNames.weekday,
weekday,
weekdaysLong,
weekdaysShort,
localeUtils,
locale,
};
const element = React.isValidElement(weekdayElement)
? React.cloneElement(weekdayElement, elementProps)
: React.createElement(weekdayElement, elementProps);
days.push(element);
}
return (
<div className={classNames.weekdays} role="rowgroup">
<div className={classNames.weekdaysRow} role="row">
{showWeekNumbers && <div className={classNames.weekday} />}
{days}
</div>
</div>
);
}
}