wix-style-react
Version:
wix-style-react
139 lines (121 loc) • 5.4 kB
JavaScript
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; }; }();
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
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; }
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; }
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import FormField from '../FormField';
import Button from '../Button';
import X from '../new-icons/X';
import Check from '../new-icons/Check';
import Input from '../Input';
import styles from './RichTextAreaLinkForm.scss';
var RichTextAreaLinkForm = function (_Component) {
_inherits(RichTextAreaLinkForm, _Component);
function RichTextAreaLinkForm() {
var _ref;
var _temp, _this, _ret;
_classCallCheck(this, RichTextAreaLinkForm);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = RichTextAreaLinkForm.__proto__ || Object.getPrototypeOf(RichTextAreaLinkForm)).call.apply(_ref, [this].concat(args))), _this), _this.state = {
text: _this.props.selection
}, _this.getChangeHandler = function (field) {
return function (_ref2) {
var value = _ref2.target.value;
_this.setState(_defineProperty({}, field, value));
};
}, _this.handleSubmit = function (event) {
event.preventDefault();
var onSubmit = _this.props.onSubmit;
onSubmit && onSubmit(_this.state);
}, _temp), _possibleConstructorReturn(_this, _ret);
}
_createClass(RichTextAreaLinkForm, [{
key: 'render',
value: function render() {
return React.createElement(
'form',
{ onSubmit: this.handleSubmit },
this.renderTextInput(),
React.createElement(
'div',
{ className: styles.input },
React.createElement(
FormField,
null,
React.createElement(Input, {
dataHook: 'rich-text-area-link-url',
onChange: this.getChangeHandler('href'),
placeholder: 'URL this link should go to',
size: 'small',
width: '190px'
})
)
),
React.createElement(
'div',
{ className: styles.buttons },
React.createElement(
'span',
{ className: styles.button },
React.createElement(
Button,
{
theme: 'icon-standardsecondary',
onClick: this.props.onCancel,
height: 'small',
type: 'button'
},
React.createElement(X, null)
)
),
React.createElement(
'span',
{ className: styles.button },
React.createElement(
Button,
{
theme: 'icon-standard',
height: 'small',
type: 'submit',
disabled: !this.state.href
},
React.createElement(Check, null)
)
)
)
);
}
}, {
key: 'renderTextInput',
value: function renderTextInput() {
return React.createElement(
'div',
{ className: styles.input },
React.createElement(
FormField,
null,
React.createElement(Input, {
dataHook: 'rich-text-area-link-text',
defaultValue: this.props.selection,
onChange: this.getChangeHandler('text'),
placeholder: 'Text to display',
size: 'small',
width: '190px'
})
)
);
}
}]);
return RichTextAreaLinkForm;
}(Component);
RichTextAreaLinkForm.propTypes = {
selection: PropTypes.string,
onCancel: PropTypes.func,
onSubmit: PropTypes.func,
isTextInputVisible: PropTypes.bool
};
export default RichTextAreaLinkForm;