UNPKG

wix-style-react

Version:
148 lines (128 loc) • 6.04 kB
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; 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 classNames from 'classnames'; import Tooltip from '../Tooltip'; import TextAreaBold from '../new-icons/system/TextAreaBold'; import TextAreaItalic from '../new-icons/system/TextAreaItalic'; import TextAreaUnderline from '../new-icons/system/TextAreaUnderline'; import TextAreaBulletList from '../new-icons/system/TextAreaBulletList'; import TextAreaNumberedList from '../new-icons/system/TextAreaNumberedList'; import TextAreaLink from '../new-icons/system/TextAreaLink'; import TextAreaImage from '../new-icons/system/TextAreaImage'; import styles from './RichTextAreaButton.scss'; import { withFocusable, focusableStates } from '../common/Focusable'; var buttons = { bold: { icon: TextAreaBold, tooltipText: 'Bold' }, italic: { icon: TextAreaItalic, tooltipText: 'Italic' }, underline: { icon: TextAreaUnderline, tooltipText: 'Underline' }, 'unordered-list': { icon: TextAreaBulletList, tooltipText: 'Bulletted list' }, 'ordered-list': { icon: TextAreaNumberedList, tooltipText: 'Numbered list' }, link: { icon: TextAreaLink, tooltipText: 'Link' }, image: { icon: TextAreaImage, tooltipText: 'Image' } }; var RichTextAreaButton = function (_Component) { _inherits(RichTextAreaButton, _Component); function RichTextAreaButton() { var _ref; var _temp, _this, _ret; _classCallCheck(this, RichTextAreaButton); for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = RichTextAreaButton.__proto__ || Object.getPrototypeOf(RichTextAreaButton)).call.apply(_ref, [this].concat(args))), _this), _this.handleMouseDown = function (event) { event.preventDefault(); if (!_this.props.disabled) { _this.props.onClick(); } }, _temp), _possibleConstructorReturn(_this, _ret); } _createClass(RichTextAreaButton, [{ key: 'render', value: function render() { var _classNames; var _props = this.props, type = _props.type, isActive = _props.isActive, isTooltipDisabled = _props.isTooltipDisabled, disabled = _props.disabled; var tooltipContent = React.createElement( 'p', { className: styles.tooltipContent }, buttons[type].tooltipText ); var className = classNames(styles.button, (_classNames = {}, _defineProperty(_classNames, styles.isActive, isActive), _defineProperty(_classNames, styles.disabled, disabled), _classNames)); return React.createElement( Tooltip, { appendToParent: true, content: tooltipContent, overlay: '', theme: 'dark', alignment: 'center', moveBy: { x: 2, y: 2 }, hideDelay: 0, disabled: isTooltipDisabled }, React.createElement( 'button', _extends({ type: 'button', className: className, 'data-hook': 'rich-text-area-button-' + type }, focusableStates(this.props), { onFocus: this.props.focusableOnFocus // eslint-disable-line react/prop-types , onBlur: this.props.focusableOnBlur // eslint-disable-line react/prop-types , onMouseDown: this.handleMouseDown }), React.createElement( 'span', { className: styles.wrapper }, this.renderIcon() ) ) ); } }, { key: 'renderIcon', value: function renderIcon() { var Icon = buttons[this.props.type].icon; return React.createElement(Icon, null); } }]); return RichTextAreaButton; }(Component); RichTextAreaButton.propTypes = { type: PropTypes.string.isRequired, onClick: PropTypes.func.isRequired, isActive: PropTypes.bool, isTooltipDisabled: PropTypes.bool, disabled: PropTypes.bool }; export default withFocusable(RichTextAreaButton);