1 | import React, { Component } from 'react'
|
2 | import { TextareaItem } from '@sishuguojixuefu/antd-mobile-rn'
|
3 | import omit from 'lodash.omit'
|
4 | import { TextareaPropsType } from '../utils/PropTypes'
|
5 | import getFieldDecorator from '../utils/getFieldDecorator'
|
6 | import TextareaWrap from './helper/TextareaWrap'
|
7 |
|
8 | export default class Textarea extends Component<TextareaPropsType, {}> {
|
9 | private fieldDecorator: any
|
10 | private inputed = 0
|
11 | static defaultProps = {
|
12 | required: false,
|
13 | placeholder: '请输入',
|
14 | count: 0,
|
15 | last: false,
|
16 | }
|
17 |
|
18 | componentWillMount() {
|
19 | const { form, id, initialValue, rules } = this.props
|
20 | this.inputed = initialValue ? initialValue.length : 0
|
21 | this.fieldDecorator = getFieldDecorator(form, id, initialValue, rules)
|
22 | }
|
23 |
|
24 | private _onChange = (value?: string) => {
|
25 | const { onChange } = this.props
|
26 | this.inputed = value ? value.length : 0
|
27 | onChange && onChange(value)
|
28 | }
|
29 |
|
30 | render() {
|
31 | const { placeholder, label, required, form, id, count, last } = this.props
|
32 | const omitProps = omit(this.props, ['error', 'labelNumber'])
|
33 | return (
|
34 | <TextareaWrap
|
35 | error={form.getFieldError(id)}
|
36 | label={label}
|
37 | required={required}
|
38 | count={count}
|
39 | inputed={this.inputed || (form.getFieldValue(id) && form.getFieldValue(id).length) || 0}
|
40 | last={last}
|
41 | >
|
42 | {this.fieldDecorator(
|
43 | <TextareaItem
|
44 | {...omitProps}
|
45 | last
|
46 | clear
|
47 | autoHeight
|
48 | style={{ marginHorizontal: 15, paddingHorizontal: 0 }}
|
49 | count={count}
|
50 | placeholder={placeholder}
|
51 | onChange={this._onChange}
|
52 | />
|
53 | )}
|
54 | </TextareaWrap>
|
55 | )
|
56 | }
|
57 | }
|