-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
Week.js
131 lines (106 loc) · 3.29 KB
/
Week.js
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
import PropTypes from 'prop-types'
import React from 'react'
import { navigate } from './utils/constants'
import { DayLayoutAlgorithmPropType } from './utils/propTypes'
import TimeGrid from './TimeGrid'
class Week extends React.Component {
render() {
/**
* This allows us to default min, max, and scrollToTime
* using our localizer. This is necessary until such time
* as TimeGrid is converted to a functional component.
*/
let {
date,
localizer,
min = localizer.startOf(new Date(), 'day'),
max = localizer.endOf(new Date(), 'day'),
scrollToTime = localizer.startOf(new Date(), 'day'),
enableAutoScroll = true,
...props
} = this.props
let range = Week.range(date, this.props)
return (
<TimeGrid
{...props}
range={range}
eventOffset={15}
localizer={localizer}
min={min}
max={max}
scrollToTime={scrollToTime}
enableAutoScroll={enableAutoScroll}
/>
)
}
}
Week.propTypes = {
date: PropTypes.instanceOf(Date).isRequired,
events: PropTypes.array.isRequired,
backgroundEvents: PropTypes.array.isRequired,
resources: PropTypes.array,
step: PropTypes.number,
timeslots: PropTypes.number,
range: PropTypes.arrayOf(PropTypes.instanceOf(Date)),
min: PropTypes.instanceOf(Date),
max: PropTypes.instanceOf(Date),
getNow: PropTypes.func.isRequired,
scrollToTime: PropTypes.instanceOf(Date),
enableAutoScroll: PropTypes.bool,
showMultiDayTimes: PropTypes.bool,
rtl: PropTypes.bool,
resizable: PropTypes.bool,
width: PropTypes.number,
accessors: PropTypes.object.isRequired,
components: PropTypes.object.isRequired,
getters: PropTypes.object.isRequired,
localizer: PropTypes.object.isRequired,
allDayMaxRows: PropTypes.number,
selected: PropTypes.object,
selectable: PropTypes.oneOf([true, false, 'ignoreEvents']),
longPressThreshold: PropTypes.number,
onNavigate: PropTypes.func,
onSelectSlot: PropTypes.func,
onSelectEnd: PropTypes.func,
onSelectStart: PropTypes.func,
onSelectEvent: PropTypes.func,
onDoubleClickEvent: PropTypes.func,
onKeyPressEvent: PropTypes.func,
onShowMore: PropTypes.func,
onDrillDown: PropTypes.func,
getDrilldownView: PropTypes.func.isRequired,
dayLayoutAlgorithm: DayLayoutAlgorithmPropType,
showAllEvents: PropTypes.bool,
doShowMoreDrillDown: PropTypes.bool,
popup: PropTypes.bool,
handleDragStart: PropTypes.func,
popupOffset: PropTypes.oneOfType([
PropTypes.number,
PropTypes.shape({
x: PropTypes.number,
y: PropTypes.number,
}),
]),
}
Week.defaultProps = TimeGrid.defaultProps
Week.navigate = (date, action, { localizer }) => {
switch (action) {
case navigate.PREVIOUS:
return localizer.add(date, -1, 'week')
case navigate.NEXT:
return localizer.add(date, 1, 'week')
default:
return date
}
}
Week.range = (date, { localizer }) => {
let firstOfWeek = localizer.startOfWeek()
let start = localizer.startOf(date, 'week', firstOfWeek)
let end = localizer.endOf(date, 'week', firstOfWeek)
return localizer.range(start, end)
}
Week.title = (date, { localizer }) => {
let [start, ...rest] = Week.range(date, { localizer })
return localizer.format({ start, end: rest.pop() }, 'dayRangeHeaderFormat')
}
export default Week