forked from mui/material-ui
-
Notifications
You must be signed in to change notification settings - Fork 2
/
DateTimePickerModal.tsx
181 lines (174 loc) · 5.25 KB
/
DateTimePickerModal.tsx
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import * as PropTypes from 'prop-types';
import * as React from 'react';
import { Omit } from '@material-ui/core';
import BasePicker, { BasePickerProps } from '../_shared/BasePicker';
import DomainPropTypes from '../constants/prop-types';
import ModalWrapper, { ModalWrapperProps } from '../wrappers/ModalWrapper';
import DateTimePicker, { BaseDateTimePickerProps } from './DateTimePicker';
export interface DateTimePickerModalProps
extends BasePickerProps,
BaseDateTimePickerProps,
Omit<ModalWrapperProps, 'onChange' | 'value'> {}
export const DateTimePickerModal: React.SFC<
DateTimePickerModalProps
> = props => {
const {
value,
format,
autoOk,
openTo,
minDate,
maxDate,
initialFocusedDate,
showTabs,
autoSubmit,
disablePast,
disableFuture,
leftArrowIcon,
rightArrowIcon,
dateRangeIcon,
timeIcon,
renderDay,
ampm,
shouldDisableDate,
animateYearScrolling,
forwardedRef,
allowKeyboardControl,
...other
} = props;
// do not show tabs for small screens
const toShowTabs =
showTabs && typeof window !== 'undefined' && window.innerHeight > 667;
return (
<BasePicker {...props}>
{({
date,
utils,
handleAccept,
handleChange,
handleClear,
handleDismiss,
handleSetTodayDate,
handleTextFieldChange,
isAccepted,
pick12hOr24hFormat,
}) => (
<ModalWrapper
showTabs={toShowTabs}
ref={forwardedRef}
disableFuture={disableFuture}
disablePast={disablePast}
maxDate={maxDate}
minDate={minDate}
onAccept={handleAccept}
onChange={handleTextFieldChange}
onClear={handleClear}
onDismiss={handleDismiss}
onSetToday={handleSetTodayDate}
value={value}
isAccepted={isAccepted}
format={pick12hOr24hFormat(
utils.dateTime12hFormat,
utils.dateTime24hFormat
)}
{...other}
>
<DateTimePicker
allowKeyboardControl={allowKeyboardControl}
ampm={ampm}
animateYearScrolling={animateYearScrolling}
autoSubmit={autoSubmit}
date={date}
dateRangeIcon={dateRangeIcon}
disableFuture={disableFuture}
disablePast={disablePast}
leftArrowIcon={leftArrowIcon}
maxDate={maxDate}
minDate={minDate}
onChange={handleChange}
openTo={openTo}
renderDay={renderDay}
rightArrowIcon={rightArrowIcon}
shouldDisableDate={shouldDisableDate}
showTabs={toShowTabs}
timeIcon={timeIcon}
/>
</ModalWrapper>
)}
</BasePicker>
);
};
(DateTimePickerModal as any).propTypes = {
/** Date-time picker value */
value: DomainPropTypes.date,
/** Date format string for input */
format: PropTypes.string,
/** Callback firing when date accepted [(date: Date) => void] */
onChange: PropTypes.func.isRequired,
/** Auto accept date on minute selection */
autoOk: PropTypes.bool,
/** Move to the next part of date on select (year -> date -> hour -> minute) */
autoSubmit: PropTypes.bool,
/** Disable future dates */
disableFuture: PropTypes.bool,
/** Disable past dates */
disablePast: PropTypes.bool,
/** Min selectable date */
minDate: DomainPropTypes.date,
/** Max selectable date */
maxDate: DomainPropTypes.date,
/** Initial focused date when calendar opens, if no value is provided */
initialFocusedDate: DomainPropTypes.date,
/** Show date/time tabs */
showTabs: PropTypes.bool,
/** Left arrow icon */
leftArrowIcon: PropTypes.node,
/** Right arrow icon */
rightArrowIcon: PropTypes.node,
/** Date tab icon */
dateRangeIcon: PropTypes.node,
/** Time tab icon */
timeIcon: PropTypes.node,
/**
* Custom renderer for day
* [(date: Date, nowSelectedDate: Date, isInCurrentMonth: boolean) => ReactElement]
*/
renderDay: PropTypes.func,
/** 12h/24h view for hour selection clock */
ampm: PropTypes.bool,
/** Disable specific date [(date: Date) => boolean] */
shouldDisableDate: PropTypes.func,
/** Enable animated scrolling to current year */
animateYearScrolling: PropTypes.bool,
/** Open directly to particular view */
openTo: PropTypes.oneOf(['year', 'date', 'hour', 'minutes']),
/** Enables keyboard listener for moving between days in calendar */
allowKeyboardControl: PropTypes.bool,
forwardedRef: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
};
DateTimePickerModal.defaultProps = {
value: new Date(),
format: undefined,
autoOk: false,
autoSubmit: true,
openTo: 'date',
disableFuture: false,
disablePast: false,
minDate: '1900-01-01',
maxDate: '2100-01-01',
initialFocusedDate: undefined,
showTabs: true,
leftArrowIcon: 'keyboard_arrow_left',
rightArrowIcon: 'keyboard_arrow_right',
dateRangeIcon: 'date_range',
timeIcon: 'access_time',
renderDay: undefined,
ampm: true,
shouldDisableDate: undefined,
animateYearScrolling: false,
forwardedRef: undefined,
allowKeyboardControl: true,
};
export default React.forwardRef((props: DateTimePickerModalProps, ref) => (
<DateTimePickerModal {...props} forwardedRef={ref} />
));