This repository was archived by the owner on Jun 3, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 143
/
Copy pathDatePickerSingle.react.js
122 lines (108 loc) · 3.96 KB
/
DatePickerSingle.react.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
import 'react-dates/initialize';
import {SingleDatePicker} from 'react-dates';
import moment from 'moment';
import React, {Component} from 'react';
import {propTypes, defaultProps} from '../components/DatePickerSingle.react';
import convertToMoment, {setLocaleGlobally} from '../utils/convertToMoment';
export default class DatePickerSingle extends Component {
constructor(props) {
super(props);
setLocaleGlobally(this.props.language);
this.isOutsideRange = this.isOutsideRange.bind(this);
this.onDateChange = this.onDateChange.bind(this);
this.state = {focused: false};
}
isOutsideRange(date) {
const {max_date_allowed, min_date_allowed} = convertToMoment(
this.props,
['max_date_allowed', 'min_date_allowed']
);
return (
(min_date_allowed && date.isBefore(min_date_allowed)) ||
(max_date_allowed && date.isAfter(max_date_allowed))
);
}
onDateChange(date) {
const {setProps} = this.props;
const payload = {date: date ? date.format('YYYY-MM-DD') : null};
setProps(payload);
}
render() {
const {focused} = this.state;
const {
calendar_orientation,
clearable,
day_size,
disabled,
display_format,
first_day_of_week,
is_RTL,
month_format,
number_of_months_shown,
placeholder,
reopen_calendar_on_clear,
show_outside_days,
stay_open_on_select,
with_full_screen_portal,
with_portal,
loading_state,
id,
style,
className,
} = this.props;
const {date, initial_visible_month} = convertToMoment(this.props, [
'date',
'initial_visible_month',
]);
const verticalFlag = calendar_orientation !== 'vertical';
const DatePickerWrapperStyles = {
position: 'relative',
display: 'inline-block',
...style,
};
// the height in px of the top part of the calendar (that holds
// the name of the month)
const baselineHeight = 145;
return (
<div
id={id}
style={DatePickerWrapperStyles}
className={className}
data-dash-is-loading={
(loading_state && loading_state.is_loading) || undefined
}
>
<SingleDatePicker
date={date}
onDateChange={this.onDateChange}
focused={focused}
onFocusChange={({focused}) => this.setState({focused})}
initialVisibleMonth={() =>
date || initial_visible_month || moment()
}
isOutsideRange={this.isOutsideRange}
numberOfMonths={number_of_months_shown}
withPortal={with_portal && verticalFlag}
withFullScreenPortal={
with_full_screen_portal && verticalFlag
}
firstDayOfWeek={first_day_of_week}
enableOutsideDays={show_outside_days}
monthFormat={month_format}
displayFormat={display_format}
placeholder={placeholder}
showClearDate={clearable}
disabled={disabled}
keepOpenOnDateSelect={stay_open_on_select}
reopenPickerOnClearDate={reopen_calendar_on_clear}
isRTL={is_RTL}
orientation={calendar_orientation}
daySize={day_size}
verticalHeight={baselineHeight + day_size * 6 + 'px'}
/>
</div>
);
}
}
DatePickerSingle.propTypes = propTypes;
DatePickerSingle.defaultProps = defaultProps;