-
Notifications
You must be signed in to change notification settings - Fork 295
/
TinyDatePicker.tsx
116 lines (110 loc) · 2.99 KB
/
TinyDatePicker.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
// @flow
import React, { Component } from 'react';
import type { Element } from 'react';
import Datetime from 'react-datetime';
import { intlShape } from 'react-intl';
import moment from 'moment';
import { PopOver } from 'react-polymorph/lib/components/PopOver';
import globalMessages from '../../../i18n/global-messages';
import TinyButton from './TinyButton';
import TinyInput from './TinyInput';
import styles from './TinyDatePicker.scss';
type PickerPanelPosition = 'left' | 'right';
type Props = $Exact<{
onBlur?: Function,
onChange?: Function,
onReset?: Function,
onClick?: Function,
onFocus?: Function,
onKeyDown?: Function,
isValidDate?: Function,
locale?: string,
dateFormat: string,
disablePaste?: boolean,
value: string,
label?: string | Element<any>,
placeholder?: string,
innerLabelPrefix: string,
innerValue: string | Element<any>,
pickerPanelPosition: PickerPanelPosition,
useReadMode?: boolean,
error?: string | Element<any>,
}>;
export default class TinyDatePicker extends Component<Props> {
static contextTypes = {
intl: intlShape.isRequired,
};
static defaultProps = {
onReset: () => null,
onChange: () => null,
locale: 'en-us',
};
render() {
const {
onReset,
onChange,
isValidDate,
dateFormat,
disablePaste,
value,
label,
placeholder,
innerLabelPrefix,
innerValue,
pickerPanelPosition,
useReadMode,
error,
...rest
} = this.props;
/* eslint-disable */
return (
<PopOver
interactive
arrow={false}
placement="auto"
duration={0}
trigger="click"
content={
<div className={styles.datePicker}>
<Datetime
open
input={false}
dateFormat={dateFormat}
timeFormat={false}
value={value ? moment(value).toDate() : null}
isValidDate={isValidDate}
onChange={(selectedDate) => {
if (typeof selectedDate === 'string') {
if (!selectedDate) {
onChange && onChange(selectedDate);
}
} else {
onChange && onChange(selectedDate.format('YYYY-MM-DD'));
}
}}
{...rest}
/>
<TinyButton
containerClassName={styles.resetButton}
onClick={onReset}
label={this.context.intl.formatMessage(globalMessages.reset)}
disabled={value == null || value === ''}
/>
</div>
}
>
<TinyInput
autoFocus={false}
value={value ? moment(value).format(dateFormat) : ''}
label={label}
placeholder={placeholder}
innerLabelPrefix={innerLabelPrefix}
onChange={(value, evt) => console.log(evt)}
useReadMode={useReadMode}
innerValue={innerValue}
error={error}
/>
</PopOver>
);
}
}