wix-style-react
Version:
wix-style-react
39 lines • 1.96 kB
JavaScript
import React from 'react';
import RichTextInputAreaForm from './RichTextInputAreaForm';
import { RichTextInputAreaContext } from '../RichTextInputAreaContext';
import Box from '../../Box';
import Input from '../../Input';
class RichTextInputAreaLinkForm extends React.Component {
constructor(props) {
super(props);
this.state = {
text: '',
url: '',
};
this._onSubmit = event => {
// Prevents form submission, but still enables submission when clicking `Enter`
event.preventDefault();
const { onSubmit } = this.props;
const { text, url } = this.state;
onSubmit && onSubmit(event, { text, url });
};
const { text = '', url = '' } = props.data;
this.state = {
text,
url,
};
}
render() {
const { dataHook, onCancel } = this.props;
return (React.createElement(RichTextInputAreaContext.Consumer, null, ({ texts }) => (React.createElement(RichTextInputAreaForm, { dataHook: dataHook, onSubmit: this._onSubmit, onCancel: onCancel, isDisabled: this.state.url.length === 0 },
React.createElement(Box, { marginBottom: 2, direction: "vertical" },
React.createElement(Input, { dataHook: "richtextarea-form-link-text", placeholder: texts.insertionForm.link.textInputPlaceholder, size: "small", value: this.state.text, onChange: event => this._setInputValue(event, 'text') })),
React.createElement(Input, { dataHook: "richtextarea-form-link-url", placeholder: texts.insertionForm.link.urlInputPlaceholder, size: "small", value: this.state.url, onChange: event => this._setInputValue(event, 'url') })))));
}
_setInputValue(event, key) {
const { target: { value }, } = event;
this.setState({ [key]: value });
}
}
export default RichTextInputAreaLinkForm;
//# sourceMappingURL=RichTextInputAreaLinkForm.js.map