UNPKG

wix-style-react

Version:
189 lines (162 loc) • 8.05 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 HeaderLayout from './HeaderLayout'; import FooterLayout from './FooterLayout'; import WixComponent from '../BaseComponents/WixComponent'; import classNames from 'classnames'; import throttle from 'lodash/throttle'; import styles from './MessageBoxFunctionalLayout.scss'; var MessageBoxFunctionalLayout = function (_WixComponent) { _inherits(MessageBoxFunctionalLayout, _WixComponent); function MessageBoxFunctionalLayout(props) { _classCallCheck(this, MessageBoxFunctionalLayout); var _this = _possibleConstructorReturn(this, (MessageBoxFunctionalLayout.__proto__ || Object.getPrototypeOf(MessageBoxFunctionalLayout)).call(this, props)); _this._initializeMessageBoxRef = function (el) { if (el && el.scrollHeight > el.clientHeight) { _this.setState({ hasScroll: true }); _this.messageBoxRef = el; _this.messageBoxRef.addEventListener('scroll', _this._handleMessageBoxScroll); } }; _this._handleMessageBoxScroll = throttle(function () { var scrolledToBottom = _this.messageBoxRef.scrollTop + _this.messageBoxRef.clientHeight === _this.messageBoxRef.scrollHeight; if (scrolledToBottom !== _this.state.scrolledToBottom) { _this.setState({ scrolledToBottom: scrolledToBottom }); } }, 16); _this.state = { hasScroll: false, scrolledToBottom: false }; _this.messageBoxRef = null; return _this; } _createClass(MessageBoxFunctionalLayout, [{ key: 'componentWillUnmount', value: function componentWillUnmount() { if (this.state.hasScroll) { this.messageBoxRef.removeEventListener('scroll', this._handleMessageBoxScroll); } } }, { key: 'render', value: function render() { var _classNames, _classNames3; var _props = this.props, title = _props.title, onCancel = _props.onCancel, onOk = _props.onOk, onClose = _props.onClose, confirmText = _props.confirmText, cancelText = _props.cancelText, children = _props.children, buttonsHeight = _props.buttonsHeight, hideFooter = _props.hideFooter, footerBottomChildren = _props.footerBottomChildren, theme = _props.theme, closeButton = _props.closeButton, disableConfirmation = _props.disableConfirmation, disableCancel = _props.disableCancel, width = _props.width, noBodyPadding = _props.noBodyPadding, maxHeight = _props.maxHeight, fullscreen = _props.fullscreen, withEmptyState = _props.withEmptyState, sideActions = _props.sideActions, image = _props.image; var _state = this.state, hasScroll = _state.hasScroll, scrolledToBottom = _state.scrolledToBottom; var messageBoxBodyClassNames = classNames(styles.body, (_classNames = {}, _defineProperty(_classNames, styles.scrollable, typeof maxHeight !== 'undefined'), _defineProperty(_classNames, styles.noPadding, noBodyPadding), _defineProperty(_classNames, styles.fullscreenBody, fullscreen), _defineProperty(_classNames, styles.noFooter, hideFooter), _defineProperty(_classNames, styles.footerBorder, hasScroll && !scrolledToBottom), _defineProperty(_classNames, styles.withEmptyState, withEmptyState), _classNames)); var messageBoxBodyStyle = { maxHeight: maxHeight }; var contentClassName = classNames(styles.content, _defineProperty({}, styles.fullscreenContent, fullscreen)); var imageClassName = classNames(styles.image, (_classNames3 = {}, _defineProperty(_classNames3, styles.withFooterAction, sideActions), _defineProperty(_classNames3, styles.noPadding, noBodyPadding), _classNames3)); return React.createElement( 'div', { className: contentClassName, style: { width: width } }, React.createElement(HeaderLayout, { title: title, onCancel: onClose ? onClose : onCancel, theme: theme, closeButton: closeButton }), image && !withEmptyState ? React.createElement( 'div', { className: styles.messageWithImage }, React.createElement('div', { className: imageClassName, children: image }), React.createElement( 'div', { 'data-hook': 'message-box-body', className: messageBoxBodyClassNames, style: messageBoxBodyStyle, ref: this._initializeMessageBoxRef }, children ) ) : React.createElement( 'div', { 'data-hook': 'message-box-body', className: messageBoxBodyClassNames, style: messageBoxBodyStyle, ref: this._initializeMessageBoxRef }, children ), !hideFooter ? React.createElement(FooterLayout, { bottomChildren: footerBottomChildren, enableCancel: !disableCancel, enableOk: !disableConfirmation, buttonsHeight: buttonsHeight, confirmText: confirmText, cancelText: cancelText, onCancel: onCancel, onOk: onOk, theme: theme, sideActions: sideActions }) : null ); } }]); return MessageBoxFunctionalLayout; }(WixComponent); MessageBoxFunctionalLayout.propTypes = { hideFooter: PropTypes.bool, confirmText: PropTypes.node, cancelText: PropTypes.node, theme: PropTypes.string, onOk: PropTypes.func, onCancel: PropTypes.func, onClose: PropTypes.func, width: PropTypes.string, title: PropTypes.node, children: PropTypes.any, maxHeight: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), buttonsHeight: PropTypes.string, closeButton: PropTypes.bool, disableCancel: PropTypes.bool, disableConfirmation: PropTypes.bool, noBodyPadding: PropTypes.bool, footerBottomChildren: PropTypes.node, fullscreen: PropTypes.bool, withEmptyState: PropTypes.bool, sideActions: PropTypes.node, image: PropTypes.node }; MessageBoxFunctionalLayout.defaultProps = { buttonsHeight: 'small', disableCancel: false, disableConfirmation: false, noBodyPadding: false, fullscreen: false, withEmptyState: false }; export default MessageBoxFunctionalLayout;