forked from Hacker0x01/react-datepicker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday.jsx
166 lines (140 loc) · 4.66 KB
/
day.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import moment from 'moment'
import React from 'react'
import classnames from 'classnames'
import { isSameDay, isDayDisabled, isDayInRange } from './date_utils'
var Day = React.createClass({
displayName: 'Day',
propTypes: {
day: React.PropTypes.object.isRequired,
endDate: React.PropTypes.object,
highlightDates: React.PropTypes.array,
inline: React.PropTypes.bool,
month: React.PropTypes.number,
onClick: React.PropTypes.func,
onMouseEnter: React.PropTypes.func,
preSelection: React.PropTypes.object,
selected: React.PropTypes.object,
selectingDate: React.PropTypes.object,
selectsEnd: React.PropTypes.bool,
selectsStart: React.PropTypes.bool,
startDate: React.PropTypes.object,
utcOffset: React.PropTypes.number
},
getDefaultProps () {
return {
utcOffset: moment.utc().utcOffset()
}
},
handleClick (event) {
if (!this.isDisabled() && this.props.onClick) {
this.props.onClick(event)
}
},
handleMouseEnter (event) {
if (!this.isDisabled() && this.props.onMouseEnter) {
this.props.onMouseEnter(event)
}
},
isSameDay (other) {
return isSameDay(this.props.day, other)
},
isKeyboardSelected () {
return !this.props.inline && !this.isSameDay(this.props.selected) && this.isSameDay(this.props.preSelection)
},
isDisabled () {
return isDayDisabled(this.props.day, this.props)
},
isHighlighted () {
const { day, highlightDates } = this.props
if (!highlightDates) return false
return highlightDates.some((testDay) => { return isSameDay(day, testDay) })
},
isInRange () {
const { day, startDate, endDate } = this.props
if (!startDate || !endDate) return false
return isDayInRange(day, startDate, endDate)
},
isInSelectingRange () {
const { day, selectsStart, selectsEnd, selectingDate, startDate, endDate } = this.props
if (!(selectsStart || selectsEnd) || !selectingDate || this.isDisabled()) {
return false
}
if (selectsStart && endDate && selectingDate.isSameOrBefore(endDate)) {
return isDayInRange(day, selectingDate, endDate)
}
if (selectsEnd && startDate && selectingDate.isSameOrAfter(startDate)) {
return isDayInRange(day, startDate, selectingDate)
}
return false
},
isSelectingRangeStart () {
if (!this.isInSelectingRange()) {
return false
}
const { day, selectingDate, startDate, selectsStart } = this.props
if (selectsStart) {
return isSameDay(day, selectingDate)
} else {
return isSameDay(day, startDate)
}
},
isSelectingRangeEnd () {
if (!this.isInSelectingRange()) {
return false
}
const { day, selectingDate, endDate, selectsEnd } = this.props
if (selectsEnd) {
return isSameDay(day, selectingDate)
} else {
return isSameDay(day, endDate)
}
},
isRangeStart () {
const { day, startDate, endDate } = this.props
if (!startDate || !endDate) return false
return isSameDay(startDate, day)
},
isRangeEnd () {
const { day, startDate, endDate } = this.props
if (!startDate || !endDate) return false
return isSameDay(endDate, day)
},
isWeekend () {
const weekday = this.props.day.day()
return weekday === 0 || weekday === 6
},
isOutsideMonth () {
return this.props.month !== undefined &&
this.props.month !== this.props.day.month()
},
getClassNames () {
return classnames('react-datepicker__day', {
'react-datepicker__day--disabled': this.isDisabled(),
'react-datepicker__day--selected': this.isSameDay(this.props.selected),
'react-datepicker__day--keyboard-selected': this.isKeyboardSelected(),
'react-datepicker__day--highlighted': this.isHighlighted(),
'react-datepicker__day--range-start': this.isRangeStart(),
'react-datepicker__day--range-end': this.isRangeEnd(),
'react-datepicker__day--in-range': this.isInRange(),
'react-datepicker__day--in-selecting-range': this.isInSelectingRange(),
'react-datepicker__day--selecting-range-start': this.isSelectingRangeStart(),
'react-datepicker__day--selecting-range-end': this.isSelectingRangeEnd(),
'react-datepicker__day--today': this.isSameDay(moment.utc().utcOffset(this.props.utcOffset)),
'react-datepicker__day--weekend': this.isWeekend(),
'react-datepicker__day--outside-month': this.isOutsideMonth()
})
},
render () {
return (
<div
className={this.getClassNames()}
onClick={this.handleClick}
onMouseEnter={this.handleMouseEnter}
aria-label={`day-${this.props.day.date()}`}
role="option">
{this.props.day.date()}
</div>
)
}
})
module.exports = Day