wix-style-react
Version:
wix-style-react
132 lines (114 loc) • 5.42 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 from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import WixComponent from '../BaseComponents/WixComponent';
import RichTextAreaButton from './RichTextAreaButton';
import RichTextAreaLinkButton from './RichTextAreaLinkButton';
import styles from './RichTextAreaToolbar.scss';
var RichTextAreaToolbar = function (_WixComponent) {
_inherits(RichTextAreaToolbar, _WixComponent);
function RichTextAreaToolbar() {
_classCallCheck(this, RichTextAreaToolbar);
return _possibleConstructorReturn(this, (RichTextAreaToolbar.__proto__ || Object.getPrototypeOf(RichTextAreaToolbar)).apply(this, arguments));
}
_createClass(RichTextAreaToolbar, [{
key: 'render',
value: function render() {
return React.createElement(
'div',
{ className: styles.container },
this.renderButton('mark', 'bold'),
this.renderButton('mark', 'italic'),
this.renderButton('mark', 'underline'),
this.renderLinkButton(),
this.renderButton('block', 'unordered-list'),
this.renderButton('block', 'ordered-list'),
this.props.onImageButtonClick ? this.renderImageButton() : null
);
}
}, {
key: 'renderButton',
value: function renderButton(action, type) {
var _props = this.props,
_onClick = _props.onClick,
hasMark = _props.hasMark,
hasListBlock = _props.hasListBlock,
disabled = _props.disabled;
var isActive = action === 'mark' ? hasMark : hasListBlock;
return React.createElement(
'div',
{
className: classNames(styles.button, _defineProperty({}, styles.disabled, disabled))
},
React.createElement(RichTextAreaButton, {
disabled: disabled,
onClick: function onClick() {
return _onClick(action, type);
},
type: type,
isActive: isActive(type)
})
);
}
}, {
key: 'renderLinkButton',
value: function renderLinkButton() {
var _props2 = this.props,
onLinkButtonClick = _props2.onLinkButtonClick,
hasLink = _props2.hasLink,
disabled = _props2.disabled,
isSelectionExpanded = _props2.isSelectionExpanded;
return React.createElement(
'div',
{
className: classNames(styles.button, _defineProperty({}, styles.disabled, disabled))
},
React.createElement(RichTextAreaLinkButton, {
selection: this.props.selection,
disabled: disabled,
onClick: onLinkButtonClick,
type: 'link',
isActive: hasLink(),
isSelectionExpanded: !isSelectionExpanded
})
);
}
}, {
key: 'renderImageButton',
value: function renderImageButton() {
var _props3 = this.props,
onImageButtonClick = _props3.onImageButtonClick,
disabled = _props3.disabled;
return React.createElement(
'div',
{
className: classNames(styles.button, _defineProperty({}, styles.disabled, disabled))
},
React.createElement(RichTextAreaButton, {
disabled: disabled,
onClick: onImageButtonClick,
type: 'image',
isActive: false
})
);
}
}]);
return RichTextAreaToolbar;
}(WixComponent);
RichTextAreaToolbar.propTypes = {
selection: PropTypes.string,
onClick: PropTypes.func,
onLinkButtonClick: PropTypes.func,
onImageButtonClick: PropTypes.func,
hasMark: PropTypes.func.isRequired,
hasListBlock: PropTypes.func.isRequired,
hasLink: PropTypes.func.isRequired,
disabled: PropTypes.bool,
isSelectionExpanded: PropTypes.bool
};
export default RichTextAreaToolbar;