|
@@ -1,53 +1,68 @@
|
|
|
import React, { Component } from 'react'
|
|
|
import PropTypes from 'prop-types'
|
|
|
-import classNames from 'classnames'
|
|
|
import Styles from './picker.css'
|
|
|
import { getDateFormatFromSepecificDate } from '../../utils'
|
|
|
+import Modal from './Modal'
|
|
|
|
|
|
class DatePicker extends Component {
|
|
|
constructor(props) {
|
|
|
super(props)
|
|
|
+ const { defaultDate } = this.props
|
|
|
this.state = {
|
|
|
- inputFocus: false,
|
|
|
+ value: defaultDate,
|
|
|
+ showModal: false,
|
|
|
}
|
|
|
|
|
|
- this.onInputFocus = this.onInputFocus.bind(this)
|
|
|
- this.onInputBlur = this.onInputBlur.bind(this)
|
|
|
+ this.onModalOpen = this.onModalOpen.bind(this)
|
|
|
this.onInputChange = this.onInputChange.bind(this)
|
|
|
+ this.onInputClear = this.onInputClear.bind(this)
|
|
|
+ this.onModalClose = this.onModalClose.bind(this)
|
|
|
}
|
|
|
|
|
|
- onInputFocus() {
|
|
|
- this.setState({ inputFocus: true })
|
|
|
+ onModalOpen() {
|
|
|
+ this.setState({ showModal: true })
|
|
|
+ }
|
|
|
+
|
|
|
+ onModalClose() {
|
|
|
+ this.setState({ showModal: false })
|
|
|
}
|
|
|
|
|
|
onInputChange() {
|
|
|
- console.log('change')
|
|
|
+ console.log('onInputChange')
|
|
|
}
|
|
|
|
|
|
- onInputBlur() {
|
|
|
- this.setState({ inputFocus: false })
|
|
|
+ onInputClear() {
|
|
|
+ this.setState({ value: '', showModal: false })
|
|
|
}
|
|
|
|
|
|
render() {
|
|
|
- const { inline, defaultDate } = this.props
|
|
|
- const { inputFocus } = this.state
|
|
|
+ const { inline } = this.props
|
|
|
+ const { value, showModal } = this.state
|
|
|
|
|
|
return (
|
|
|
- <div
|
|
|
- className={Styles.container}
|
|
|
- style={inline ? { display: 'inline-block' } : {}}
|
|
|
- >
|
|
|
- <input
|
|
|
- type="text"
|
|
|
- className={Styles.input}
|
|
|
- value={defaultDate}
|
|
|
- onFocus={this.onInputFocus}
|
|
|
- onBlur={this.onInputBlur}
|
|
|
- onChange={this.onInputChange}
|
|
|
- />
|
|
|
- <i className={Styles.calendar} />
|
|
|
- <i className={Styles.close} />
|
|
|
- <div className={classNames(Styles.line, { [Styles.inputFocus]: inputFocus })} />
|
|
|
+ <div className={Styles.wrapper}>
|
|
|
+ <div
|
|
|
+ className={Styles.container}
|
|
|
+ style={inline ? { display: 'inline-block' } : {}}
|
|
|
+ >
|
|
|
+ <input
|
|
|
+ type="text"
|
|
|
+ placeholder="选择日期"
|
|
|
+ className={Styles.input}
|
|
|
+ value={value}
|
|
|
+ onChange={this.onInputChange}
|
|
|
+ onFocus={this.onModalOpen}
|
|
|
+ onBlur={this.onModalClose}
|
|
|
+ />
|
|
|
+ <i className={Styles.calendar} />
|
|
|
+ <i
|
|
|
+ className={Styles.close}
|
|
|
+ onClick={this.onInputClear}
|
|
|
+ role="presentation"
|
|
|
+ />
|
|
|
+ <div className={Styles.line} />
|
|
|
+ </div>
|
|
|
+ <Modal isMounted={showModal} delayTime={200} />
|
|
|
</div>
|
|
|
)
|
|
|
}
|