1 | import React, { Component } from 'react';
|
2 | import PropTypes from 'prop-types';
|
3 |
|
4 | import { Button, TextAreaStyled } from './index';
|
5 |
|
6 | export default class TextAreaRedux extends Component {
|
7 | constructor(props) {
|
8 | super(props);
|
9 | this.state = { textareaVal: '' };
|
10 | }
|
11 | render() {
|
12 | return (
|
13 | <TextAreaStyled
|
14 | isValid={this.props.isValid}
|
15 | isInvalid={this.props.isInvalid}
|
16 | textSize={this.props.textSize}
|
17 | >
|
18 | <Button
|
19 | buttonLink
|
20 | success
|
21 | inline
|
22 | small
|
23 | onClick={() => {
|
24 | const textVal = this.textAreaRedux;
|
25 | const cursorStart = textVal.selectionStart;
|
26 | const cursorEnd = textVal.selectionEnd;
|
27 | const text = this.state.textareaVal;
|
28 | this.setState({
|
29 | textareaVal: `${text.substr(0, cursorStart)}***${text.substr(
|
30 | cursorStart,
|
31 | cursorEnd - cursorStart,
|
32 | )}***${text.substr(cursorEnd)}`,
|
33 | });
|
34 | }}
|
35 | >
|
36 | Bold
|
37 | </Button>
|
38 | <label htmlFor={this.props.input.name}>
|
39 | {this.props.label}
|
40 | </label>
|
41 | <textarea
|
42 | {...this.props.input}
|
43 | ref={(c) => {
|
44 | this.textAreaRedux = c;
|
45 | }}
|
46 | value={this.state.textareaVal}
|
47 | onChange={(event) => {
|
48 | this.setState({
|
49 | textareaVal: event.target.value,
|
50 | });
|
51 | }}
|
52 | />
|
53 | </TextAreaStyled>
|
54 | );
|
55 | }
|
56 | }
|
57 |
|
58 | TextAreaRedux.defaultProps = {
|
59 | name: '',
|
60 | label: '',
|
61 | input: {},
|
62 | isValid: false,
|
63 | isInvalid: false,
|
64 | textSize: '16px',
|
65 | };
|
66 |
|
67 | TextAreaRedux.propTypes = {
|
68 | name: PropTypes.string,
|
69 | label: PropTypes.string,
|
70 | input: PropTypes.object,
|
71 | isValid: PropTypes.bool,
|
72 | isInvalid: PropTypes.bool,
|
73 | textSize: PropTypes.string,
|
74 | };
|