-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDayFromTo.jsx
123 lines (110 loc) · 3.53 KB
/
DayFromTo.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
import React from 'react';
import 'react-day-picker/lib/style.css';
export default class DayFromTo extends React.Component {
static defaultProps = {
numberOfMonths: 2,
};
constructor(props) {
super(props);
this.handleDayClick = this.handleDayClick.bind(this);
this.handleResetClick = this.handleResetClick.bind(this);
this.state = this.getInitialState();
}
getInitialState() {
return {
from: undefined,
to: undefined,
};
}
componentDidUpdate(prevProps, prevState) {
if(prevState.from === undefined && this.state.from != undefined) this.props.handleDayClick(this.state.from, 'fromValue')
if(prevState.to === undefined && this.state.to != undefined) this.props.handleDayClick(this.state.to, 'toValue')
if(prevState.from != undefined && this.state.from != prevState.from) this.props.handleDayClick(this.state.from, 'fromValue')
if(prevState.to != undefined && this.state.to != prevState.to) this.props.handleDayClick(this.state.to, 'toValue')
if(prevProps.days.from != this.props.days.from) {
const d = this.props.days.from.toString()
console.log(d.length)
const date = new Date(this.props.days.from)
if(d.length > 5) {
if(!isNaN(date.getMonth())) {
console.log(date.getDate())
if(date.getDate() == "") console.log("nincs")
if(d.length == 10) this.setState({ from: date})
else this.setState({ from: undefined})
}
}
}
if(prevProps.days.to != this.props.days.to) {
const d = this.props.days.to.toString()
console.log(d.length)
const date = new Date(this.props.days.to)
if(d.length > 5) {
if(!isNaN(date.getMonth())) {
console.log(date.getDate())
if(date.getDate() == "") console.log("nincs")
if(d.length == 10) this.setState({ to: date})
else this.setState({ to: undefined})
}
}
}
}
handleDayClick(day) {
const range = this.props.DateUtils.addDayToRange(day, this.state);
this.setState(range);
}
handleResetClick() {
this.setState(this.getInitialState());
}
render() {
const { from, to } = this.state;
const modifiers = { start: from, end: to, weekend: { daysOfWeek: [0,6] }, today: new Date() };
const DayPicker = this.props.DayPicker
const MONTHS = [
'Január',
'Február',
'Március',
'Április',
'Május',
'Június',
'Július',
'Augusztus',
'Szeptember',
'Október',
'November',
'December',
];
const WEEKDAYS_LONG = [
'Vasárnap',
'Hétfő',
'Kedd',
'Szerda',
'Csütörtök',
'Péntek',
'Szombat',
];
const WEEKDAYS_SHORT = ['Vas', 'Hét', 'Kedd', 'Sze', 'Csüt', 'Pén', 'Szo'];
const number = 1;
const modifiersStyles = {
today: {
color: '#0170f3'
}
};
return (
<div className="RangeExample">
<DayPicker
className="Selectable"
numberOfMonths={this.props.numberOfMonths}
selectedDays={[from, { from, to }]}
firstDayOfWeek={number}
modifiers={modifiers}
modifiersStyles={modifiersStyles}
locale="hu"
months={MONTHS}
weekdaysLong={WEEKDAYS_LONG}
weekdaysShort={WEEKDAYS_SHORT}
onDayClick={this.handleDayClick}
/>
</div>
);
}
}