DatePicker
This commit is contained in:
parent
e2b2e38431
commit
d609e836bf
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
|
@ -59,6 +59,7 @@
|
|||
"dist"
|
||||
],
|
||||
"dependencies": {
|
||||
"moment": "^2.24.0",
|
||||
"react-toastify": "^4.5.2"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import React, {Component} from 'react';
|
||||
import moment from 'moment';
|
||||
import {FormConsumer} from "./FormContext";
|
||||
import FormItemError from "./FormItemError";
|
||||
|
||||
|
@ -15,19 +16,30 @@ export default class DatePicker extends Component
|
|||
|
||||
renderDatePicker(data)
|
||||
{
|
||||
const value = this.props.value
|
||||
let props = {...this.props}
|
||||
if (props.children) delete props.children
|
||||
if (props.value) delete props.value
|
||||
if (props.onChangeValue) delete props.onChangeValue
|
||||
return (
|
||||
<div className="form-group">
|
||||
{this.renderLabel(data)}
|
||||
<input onChange={(e) => this.props.onChangeValue(e.target.value)} {...props} />
|
||||
<input
|
||||
value={this.parseValue(value)}
|
||||
onChange={(e) => this.props.onChangeValue(moment(e.target.value))} {...props} />
|
||||
<p className="text-muted">DatePicker {this.props.type}</p>
|
||||
<FormItemError name={this.props.name} data={data} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
parseValue(value)
|
||||
{
|
||||
if (this.props.type == 'date') return moment(value).format('YYYY-MM-DD')
|
||||
if (this.props.type == 'time') return moment(value).format('HH:mm:ss')
|
||||
return moment(value).format('YYYY-MM-DDTHH:mm')
|
||||
}
|
||||
|
||||
renderLabel(data)
|
||||
{
|
||||
if (this.props.label) {
|
||||
|
@ -43,5 +55,6 @@ DatePicker.defaultProps = {
|
|||
id: 'input',
|
||||
className: 'form-control',
|
||||
type: 'datetime-local',
|
||||
value: null,
|
||||
onChangeValue: (text) => {}
|
||||
}
|
||||
|
|
|
@ -66,5 +66,6 @@ FilePicker.defaultProps = {
|
|||
name: 'file-picker',
|
||||
id: 'file-picker',
|
||||
className: 'form-control',
|
||||
value: null,
|
||||
onChangeValue: (file) => {}
|
||||
}
|
||||
|
|
|
@ -5981,6 +5981,10 @@ mkdirp@0.5.1, mkdirp@0.5.x, mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0, mkdirp@
|
|||
dependencies:
|
||||
minimist "0.0.8"
|
||||
|
||||
moment@^2.24.0:
|
||||
version "2.24.0"
|
||||
resolved "https://registry.yarnpkg.com/moment/-/moment-2.24.0.tgz#0d055d53f5052aa653c9f6eb68bb5d12bf5c2b5b"
|
||||
|
||||
ms@2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"
|
||||
|
|
Loading…
Reference in New Issue