-
Notifications
You must be signed in to change notification settings - Fork 431
/
date-editor.js
45 lines (41 loc) · 1021 Bytes
/
date-editor.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
/* eslint no-return-assign: 0 */
import React, { Component } from 'react';
import cs from 'classnames';
import PropTypes from 'prop-types';
class DateEditor extends Component {
componentDidMount() {
const { defaultValue, didMount } = this.props;
this.date.valueAsDate = new Date(defaultValue);
this.date.focus();
if (didMount) didMount();
}
getValue() {
return this.date.value;
}
render() {
const { defaultValue, didMount, className, ...rest } = this.props;
const editorClass = cs('form-control editor edit-date', className);
return (
<input
ref={ node => this.date = node }
type="date"
className={ editorClass }
{ ...rest }
/>
);
}
}
DateEditor.propTypes = {
className: PropTypes.oneOfType([
PropTypes.string,
PropTypes.object
]),
defaultValue: PropTypes.string,
didMount: PropTypes.func
};
DateEditor.defaultProps = {
className: '',
defaultValue: '',
didMount: undefined
};
export default DateEditor;