import React, { Component } from 'react';
import { Input, Upload, Button } from 'antd';
import { getText } from 'utils/file';
import PropTypes from 'prop-types';
export default class index extends Component {
static propTypes = {
value: PropTypes.string,
placeholder: PropTypes.string,
accept: PropTypes.any,
onChange: PropTypes.func,
};
static defaultProps = {
value: '',
placeholder: t('Please input'),
accept: '',
onChange: (values) => {
console.log(values);
},
};
onChange = (value) => {
const { onChange } = this.props;
onChange && onChange(value);
};
handleUpload = async (file) => {
const value = await getText(file);
this.onChange(value);
return false;
};
onChangeInput = (value) => {
this.onChange(value);
};
render() {
const { value, placeholder, accept, ...rest } = this.props;
return (
<>
<Input.TextArea
placeholder={placeholder}
value={value}
onChange={this.onChange}
style={{
fontFamily:
'"Menlo", "Liberation Mono", "Consolas", "DejaVu Sans Mono", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace',
}}
{...rest}
/>
<Upload
beforeUpload={this.handleUpload}
showUploadList={false}
accept={accept}
>
<Button type="link">{t('Load from local files')}</Button>
</Upload>
</>
);
}
}