UNPKG

wix-style-react

Version:
110 lines (94 loc) 4.44 kB
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized"; import _inherits from "@babel/runtime/helpers/inherits"; import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } import React from 'react'; import RichTextInputAreaForm from './RichTextInputAreaForm'; import { RichTextInputAreaContext } from '../RichTextInputAreaContext'; import Box from '../../Box'; import Input from '../../Input'; var RichTextInputAreaLinkForm = /*#__PURE__*/function (_React$Component) { _inherits(RichTextInputAreaLinkForm, _React$Component); var _super = _createSuper(RichTextInputAreaLinkForm); function RichTextInputAreaLinkForm(props) { var _this; _classCallCheck(this, RichTextInputAreaLinkForm); _this = _super.call(this, props); _defineProperty(_assertThisInitialized(_this), "state", { text: '', url: '' }); _defineProperty(_assertThisInitialized(_this), "_onSubmit", function (event) { // Prevents form submission, but still enables submission when clicking `Enter` event.preventDefault(); var onSubmit = _this.props.onSubmit; var _this$state = _this.state, text = _this$state.text, url = _this$state.url; onSubmit && onSubmit(event, { text: text, url: url }); }); var _props$data = props.data, _props$data$text = _props$data.text, _text = _props$data$text === void 0 ? '' : _props$data$text, _props$data$url = _props$data.url, _url = _props$data$url === void 0 ? '' : _props$data$url; _this.state = { text: _text, url: _url }; return _this; } _createClass(RichTextInputAreaLinkForm, [{ key: "render", value: function render() { var _this2 = this; var _this$props = this.props, dataHook = _this$props.dataHook, onCancel = _this$props.onCancel; return /*#__PURE__*/React.createElement(RichTextInputAreaContext.Consumer, null, function (_ref) { var texts = _ref.texts; return /*#__PURE__*/React.createElement(RichTextInputAreaForm, { dataHook: dataHook, onSubmit: _this2._onSubmit, onCancel: onCancel, isDisabled: _this2.state.url.length === 0 }, /*#__PURE__*/React.createElement(Box, { marginBottom: 2, direction: "vertical" }, /*#__PURE__*/React.createElement(Input, { dataHook: "richtextarea-form-link-text", placeholder: texts.insertionForm.link.textInputPlaceholder, size: "small", value: _this2.state.text, onChange: function onChange(event) { return _this2._setInputValue(event, 'text'); } })), /*#__PURE__*/React.createElement(Input, { dataHook: "richtextarea-form-link-url", placeholder: texts.insertionForm.link.urlInputPlaceholder, size: "small", value: _this2.state.url, onChange: function onChange(event) { return _this2._setInputValue(event, 'url'); } })); }); } }, { key: "_setInputValue", value: function _setInputValue(event, key) { var value = event.target.value; this.setState(_defineProperty({}, key, value)); } }]); return RichTextInputAreaLinkForm; }(React.Component); export default RichTextInputAreaLinkForm;