UNPKG

wix-style-react

Version:
134 lines (108 loc) 5.09 kB
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 Text from '../Text'; import Button from '../Button'; import CloseButton from '../CloseButton'; import styles from './styles.scss'; export var HELPER_APPEARANCE = { warning: styles.warning, standard: styles.standard, danger: styles.danger, success: styles.success, premium: styles.premium }; /** * Used in pages where you need to explain or mention things about the content or actions */ var SectionHelper = function (_WixComponent) { _inherits(SectionHelper, _WixComponent); function SectionHelper() { _classCallCheck(this, SectionHelper); return _possibleConstructorReturn(this, (SectionHelper.__proto__ || Object.getPrototypeOf(SectionHelper)).apply(this, arguments)); } _createClass(SectionHelper, [{ key: 'render', value: function render() { var _props = this.props, showCloseButton = _props.showCloseButton, onClose = _props.onClose; return React.createElement( 'div', { className: classnames(styles.root, HELPER_APPEARANCE[this.props.appearance]) }, showCloseButton && onClose && React.createElement( 'div', { className: classnames(styles.close, _defineProperty({}, styles.closeWithTitle, this.props.title)) }, React.createElement(CloseButton, { dataHook: 'sectionhelper-close-btn', size: 'medium', skin: 'dark', onClick: this.props.onClose }) ), this.props.title && React.createElement( 'div', { className: styles.title }, React.createElement( Text, { dataHook: 'sectionhelper-title', size: 'small', weight: 'normal' }, this.props.title ) ), React.createElement( 'div', { className: styles.content }, React.createElement( Text, { size: 'small' }, this.props.children ) ), this.props.onAction && this.props.actionText && React.createElement( 'div', { className: styles.action }, React.createElement(Button, { height: 'small', theme: 'outlined', onClick: this.props.onAction, dataHook: 'sectionhelper-action-btn', children: this.props.actionText }) ) ); } }]); return SectionHelper; }(WixComponent); SectionHelper.displayName = 'SectionHelper'; SectionHelper.propTypes = { /** Sets the look and feel of the component */ appearance: PropTypes.oneOf(Object.keys(HELPER_APPEARANCE)), /** Adds text as the title */ title: PropTypes.node, /** decide if to show the close button */ showCloseButton: PropTypes.bool, /** When provided, will make a close button appear and invoke it upon click */ onClose: PropTypes.func, /** When provided, will make an action button appear and invoke it upon click */ onAction: PropTypes.func, /** Text label for the action button */ actionText: PropTypes.string, /** Children to render */ children: PropTypes.node }; SectionHelper.defaultProps = { showCloseButton: true, appearance: 'warning' }; export default SectionHelper;