UNPKG

4.41 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6
7var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
8
9var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
10
11var _react = require('react');
12
13var _react2 = _interopRequireDefault(_react);
14
15var _propTypes = require('prop-types');
16
17var _propTypes2 = _interopRequireDefault(_propTypes);
18
19var _index = require('./index');
20
21function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
22
23function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
24
25function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
26
27function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
28
29var TextArea = function (_Component) {
30 _inherits(TextArea, _Component);
31
32 function TextArea(props) {
33 _classCallCheck(this, TextArea);
34
35 var _this = _possibleConstructorReturn(this, (TextArea.__proto__ || Object.getPrototypeOf(TextArea)).call(this, props));
36
37 _this.state = { textareaVal: '' };
38 return _this;
39 }
40
41 _createClass(TextArea, [{
42 key: 'render',
43 value: function render() {
44 var _this2 = this;
45
46 return _react2.default.createElement(
47 _index.TextAreaStyled,
48 {
49 isValid: this.props.isValid,
50 isInvalid: this.props.isInvalid,
51 textSize: this.props.textSize
52 },
53 _react2.default.createElement(
54 _index.Button,
55 {
56 buttonLink: true,
57 success: true,
58 inline: true,
59 small: true,
60 onClick: function onClick() {
61 var textVal = _this2.textArea;
62 var cursorStart = textVal.selectionStart;
63 var cursorEnd = textVal.selectionEnd;
64 var text = _this2.state.textareaVal;
65 _this2.setState({
66 textareaVal: text.substr(0, cursorStart) + '***' + text.substr(cursorStart, cursorEnd - cursorStart) + '***' + text.substr(cursorEnd)
67 });
68 }
69 },
70 'Bold'
71 ),
72 _react2.default.createElement(
73 'label',
74 { htmlFor: this.props.name },
75 this.props.children
76 ),
77 _react2.default.createElement('textarea', _extends({}, this.props, {
78 name: this.props.name,
79 ref: function ref(c) {
80 _this2.textArea = c;
81 },
82 value: this.state.textareaVal,
83 onChange: function onChange(event) {
84 _this2.setState({
85 textareaVal: event.target.value
86 });
87 }
88 }))
89 );
90 }
91 }]);
92
93 return TextArea;
94}(_react.Component);
95
96exports.default = TextArea;
97
98
99TextArea.defaultProps = {
100 children: '',
101 name: '',
102 isValid: false,
103 isInvalid: false,
104 textSize: '16px'
105};
106
107TextArea.propTypes = {
108 children: _propTypes2.default.node.isRequired,
109 name: _propTypes2.default.string,
110 isValid: _propTypes2.default.bool,
111 isInvalid: _propTypes2.default.bool,
112 textSize: _propTypes2.default.string
113};
\No newline at end of file