PhoneView.tsx 901 Bytes
Newer Older
陈帅's avatar
陈帅 committed
1 2
import React, { Fragment, PureComponent } from 'react';
import { Input } from 'antd';
3
import styles from './PhoneView.less';
陈帅's avatar
陈帅 committed
4

陈帅's avatar
陈帅 committed
5 6 7 8 9 10
interface PhoneViewProps {
  value?: string;
  onChange?: (value: string) => void;
}

class PhoneView extends PureComponent<PhoneViewProps> {
陈帅's avatar
陈帅 committed
11 12 13 14 15 16 17 18 19
  render() {
    const { value, onChange } = this.props;
    let values = ['', ''];
    if (value) {
      values = value.split('-');
    }
    return (
      <Fragment>
        <Input
20
          className={styles.area_code}
陈帅's avatar
陈帅 committed
21
          value={values[0]}
jim's avatar
jim committed
22
          onChange={e => {
陈帅's avatar
陈帅 committed
23
            onChange && onChange(`${e.target.value}-${values[1]}`);
陈帅's avatar
陈帅 committed
24 25 26
          }}
        />
        <Input
27
          className={styles.phone_number}
jim's avatar
jim committed
28
          onChange={e => {
陈帅's avatar
陈帅 committed
29
            onChange && onChange(`${values[0]}-${e.target.value}`);
陈帅's avatar
陈帅 committed
30 31 32 33 34 35 36 37 38
          }}
          value={values[1]}
        />
      </Fragment>
    );
  }
}

export default PhoneView;