UNPKG

1.21 kBTypeScriptView Raw
1import React, { Component } from 'react'
2import { List, DatePicker } from '@sishuguojixuefu/antd-mobile-rn'
3import { SsDateProps } from '../utils/PropTypes'
4import ErrorTip from './helper/ErrorTip'
5import getFieldDecorator from '../utils/getFieldDecorator'
6import Label from './helper/Label'
7
8export default class SsDate extends Component<SsDateProps, any> {
9 private fieldDecorator: any
10 static defaultProps = {
11 required: false,
12 }
13
14 componentWillMount() {
15 const { form, id, initialValue, rules } = this.props
16 this.fieldDecorator = getFieldDecorator(form, id, initialValue, rules)
17 }
18
19 private _onChange = (value: Date) => {
20 const { onChange } = this.props
21 onChange && onChange(value)
22 }
23
24 render() {
25 const { label, required, form, id, placeholder, type } = this.props
26 return (
27 <ErrorTip error={form.getFieldError(id)}>
28 {this.fieldDecorator(
29 <DatePicker {...this.props} mode={type} onChange={this._onChange} extra={placeholder}>
30 <List.Item arrow="horizontal" style={{ paddingLeft: 0 }} last>
31 <Label required={required} label={label} />
32 </List.Item>
33 </DatePicker>
34 )}
35 </ErrorTip>
36 )
37 }
38}