|
| 1 | +import React, {Component, Fragment} from 'react'; |
| 2 | +import PropTypes from 'prop-types'; |
| 3 | +import {DatePicker} from '@blueprintjs/datetime'; |
| 4 | +import '@blueprintjs/datetime/lib/css/blueprint-datetime.css'; |
| 5 | +import '@blueprintjs/core/lib/css/blueprint.css'; |
| 6 | +import '@blueprintjs/icons/lib/css/blueprint-icons.css'; |
| 7 | +import TextInput from './TextInput'; |
| 8 | + |
| 9 | +export default class DateTimePicker extends Component { |
| 10 | + constructor(props) { |
| 11 | + super(props); |
| 12 | + |
| 13 | + this.state = { |
| 14 | + value: props.fullValue, |
| 15 | + expanded: false, |
| 16 | + }; |
| 17 | + |
| 18 | + this.onChange = this.onChange.bind(this); |
| 19 | + } |
| 20 | + |
| 21 | + componentWillReceiveProps(nextProps) { |
| 22 | + // Reset the value to the graph's actual value |
| 23 | + if (nextProps.value !== this.state.value) { |
| 24 | + this.setState({ |
| 25 | + value: nextProps.value, |
| 26 | + }); |
| 27 | + } |
| 28 | + } |
| 29 | + |
| 30 | + onChange(e) { |
| 31 | + const newValue = e.target.value; |
| 32 | + this.setState({value: newValue}); |
| 33 | + this.props.onChange(newValue); |
| 34 | + } |
| 35 | + |
| 36 | + render() { |
| 37 | + return ( |
| 38 | + <Fragment> |
| 39 | + <TextInput value={this.state.value} /> |
| 40 | + <span |
| 41 | + style={{width: '10px', backgroundColor: 'blue', color: '#fff'}} |
| 42 | + onClick={() => { |
| 43 | + this.setState({expanded: !this.state.expanded}); |
| 44 | + }} |
| 45 | + > |
| 46 | + X |
| 47 | + </span> |
| 48 | + {this.state.expanded ? <DatePicker timePrecision={'millisecond'} /> : null} |
| 49 | + </Fragment> |
| 50 | + ); |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +DateTimePicker.propTypes = { |
| 55 | + value: PropTypes.string.isRequired, |
| 56 | + onChange: PropTypes.func.isRequired, |
| 57 | + placeholder: PropTypes.string.isRequired, |
| 58 | +}; |
0 commit comments