1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 |
|
7 | var _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; }; }();
|
8 |
|
9 | var _react = require('react');
|
10 |
|
11 | var _react2 = _interopRequireDefault(_react);
|
12 |
|
13 | var _propTypes = require('prop-types');
|
14 |
|
15 | var _propTypes2 = _interopRequireDefault(_propTypes);
|
16 |
|
17 | var _bind = require('classnames/bind');
|
18 |
|
19 | var _bind2 = _interopRequireDefault(_bind);
|
20 |
|
21 | var _style = require('./style.scss');
|
22 |
|
23 | var _style2 = _interopRequireDefault(_style);
|
24 |
|
25 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
26 |
|
27 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
28 |
|
29 | function _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; }
|
30 |
|
31 | function _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; }
|
32 |
|
33 |
|
34 |
|
35 |
|
36 | var Textarea = function (_React$Component) {
|
37 | _inherits(Textarea, _React$Component);
|
38 |
|
39 | function Textarea(props) {
|
40 | _classCallCheck(this, Textarea);
|
41 |
|
42 | var _this = _possibleConstructorReturn(this, (Textarea.__proto__ || Object.getPrototypeOf(Textarea)).call(this, props));
|
43 |
|
44 | _this.state = {
|
45 | value: _this.props.value
|
46 | };
|
47 |
|
48 | _this.UNSAFE_componentWillReceiveProps = function (nextProps) {
|
49 | if (nextProps.value !== _this.props.value) {
|
50 | _this.setState({ value: nextProps.value });
|
51 | }
|
52 | };
|
53 |
|
54 | _this.handleChange = function (event) {
|
55 | event.persist();
|
56 |
|
57 | _this.setState({ value: event.target.value }, function () {
|
58 | if (typeof _this.props.changeCallback === 'function') {
|
59 | _this.props.changeCallback({
|
60 | target: {
|
61 | name: _this.props.name,
|
62 | value: event.target.value
|
63 | }
|
64 | });
|
65 | }
|
66 | });
|
67 | };
|
68 |
|
69 | _this.handleFocus = function (event) {
|
70 | if (typeof _this.props.focusCallback === 'function') {
|
71 | _this.props.focusCallback(event);
|
72 | }
|
73 | };
|
74 |
|
75 | _this.handleBlur = function (event) {
|
76 | if (typeof _this.props.blurCallback === 'function') {
|
77 | _this.props.blurCallback(event);
|
78 | }
|
79 | };
|
80 |
|
81 | return _this;
|
82 | }
|
83 |
|
84 | _createClass(Textarea, [{
|
85 | key: 'render',
|
86 | value: function render() {
|
87 | var _props = this.props,
|
88 | disabled = _props.disabled,
|
89 | label = _props.label,
|
90 | optClass = _props.optClass,
|
91 | className = _props.className,
|
92 | height = _props.height,
|
93 | readOnly = _props.readOnly,
|
94 | placeholder = _props.placeholder;
|
95 |
|
96 |
|
97 | var cx = _bind2.default.bind(_style2.default);
|
98 | var heightStyle = height ? { height: height } : null;
|
99 | var disabledClass = disabled ? _style2.default['textarea-disabled'] : '';
|
100 | var textareaClass = cx(_style2.default['textarea-component'], optClass, className, disabledClass);
|
101 |
|
102 | return _react2.default.createElement(
|
103 | 'div',
|
104 | { className: textareaClass },
|
105 | label ? _react2.default.createElement(
|
106 | 'label',
|
107 | null,
|
108 | label
|
109 | ) : null,
|
110 | _react2.default.createElement('textarea', {
|
111 | value: this.state.value,
|
112 | onFocus: this.handleFocus,
|
113 | onChange: this.handleChange,
|
114 | onBlur: this.handleBlur,
|
115 | disabled: disabled,
|
116 | readOnly: readOnly,
|
117 | placeholder: placeholder,
|
118 | style: heightStyle
|
119 | })
|
120 | );
|
121 | }
|
122 | }]);
|
123 |
|
124 | return Textarea;
|
125 | }(_react2.default.Component);
|
126 |
|
127 | Textarea.defaultProps = {
|
128 | disabled: false,
|
129 | value: ''
|
130 | };
|
131 | Textarea.propTypes = {
|
132 | |
133 |
|
134 |
|
135 | className: _propTypes2.default.string,
|
136 | |
137 |
|
138 |
|
139 | name: _propTypes2.default.string,
|
140 | |
141 |
|
142 |
|
143 | disabled: _propTypes2.default.bool,
|
144 | |
145 |
|
146 |
|
147 | readOnly: _propTypes2.default.bool,
|
148 | |
149 |
|
150 |
|
151 | label: _propTypes2.default.string,
|
152 | |
153 |
|
154 |
|
155 | value: _propTypes2.default.string,
|
156 | |
157 |
|
158 |
|
159 | placeholder: _propTypes2.default.string,
|
160 | |
161 |
|
162 |
|
163 | optClass: _propTypes2.default.string,
|
164 | |
165 |
|
166 |
|
167 | changeCallback: _propTypes2.default.func,
|
168 | |
169 |
|
170 |
|
171 | focusCallback: _propTypes2.default.func,
|
172 | |
173 |
|
174 |
|
175 | blurCallback: _propTypes2.default.func,
|
176 | |
177 |
|
178 |
|
179 | height: _propTypes2.default.string
|
180 | };
|
181 | exports.default = Textarea; |
\ | No newline at end of file |