wix-style-react
Version:
170 lines (155 loc) • 8.26 kB
JavaScript
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
import _inherits from "@babel/runtime/helpers/inherits";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import Heading from '../../Heading';
import Text from '../../Text';
import TextButton from '../../TextButton';
import CloseButton from '../../CloseButton';
import Button from '../../Button';
import styles from './MessageBoxMarketerialLayout.scss';
import deprecationLog from '../../utils/deprecationLog';
var buttonSkinByTheme = {
blue: 'standard',
purple: 'premium',
white: 'dark'
};
var MessageBoxMarketerialLayout = /*#__PURE__*/function (_React$PureComponent) {
_inherits(MessageBoxMarketerialLayout, _React$PureComponent);
var _super = _createSuper(MessageBoxMarketerialLayout);
function MessageBoxMarketerialLayout(props) {
var _this;
_classCallCheck(this, MessageBoxMarketerialLayout);
_this = _super.call(this, props);
_defineProperty(_assertThisInitialized(_this), "_renderButtons", function () {
var _this$props = _this.props,
primaryButtonLabel = _this$props.primaryButtonLabel,
primaryButtonTheme = _this$props.primaryButtonTheme,
primaryButtonNode = _this$props.primaryButtonNode,
theme = _this$props.theme,
onPrimaryButtonClick = _this$props.onPrimaryButtonClick,
primaryButtonDisabled = _this$props.primaryButtonDisabled,
secondaryButtonLabel = _this$props.secondaryButtonLabel,
footerBottomChildren = _this$props.footerBottomChildren,
onSecondaryButtonClick = _this$props.onSecondaryButtonClick;
return /*#__PURE__*/React.createElement("div", {
className: styles.buttonsContainer
}, !!primaryButtonNode && /*#__PURE__*/React.createElement("div", {
"data-hook": "primary-button-node"
}, primaryButtonNode), !primaryButtonNode && primaryButtonLabel && /*#__PURE__*/React.createElement(Button, {
skin: buttonSkinByTheme[primaryButtonTheme || theme],
priority: !primaryButtonTheme && theme === 'white' ? 'secondary' : 'primary',
onClick: onPrimaryButtonClick,
dataHook: "primary-button",
disabled: primaryButtonDisabled
}, primaryButtonLabel), secondaryButtonLabel && !footerBottomChildren && /*#__PURE__*/React.createElement("div", {
className: styles.secondaryButtonContainer
}, /*#__PURE__*/React.createElement(TextButton, {
size: "small",
onClick: onSecondaryButtonClick,
dataHook: "secondary-button"
}, secondaryButtonLabel)));
});
deprecationLog('<MessageBoxMarketerialLayout/> - Component is deprecated and will be removed as part of the next major version, please use <AnnouncementModalLayout /> instead.');
return _this;
}
_createClass(MessageBoxMarketerialLayout, [{
key: "render",
value: function render() {
var _classNames;
var _this$props2 = this.props,
dataHook = _this$props2.dataHook,
title = _this$props2.title,
content = _this$props2.content,
primaryButtonLabel = _this$props2.primaryButtonLabel,
secondaryButtonLabel = _this$props2.secondaryButtonLabel,
imageUrl = _this$props2.imageUrl,
onClose = _this$props2.onClose,
theme = _this$props2.theme,
imageComponent = _this$props2.imageComponent,
footerBottomChildren = _this$props2.footerBottomChildren,
removeButtonsPadding = _this$props2.removeButtonsPadding,
width = _this$props2.width,
noBodyPadding = _this$props2.noBodyPadding;
var headerClasses = classNames((_classNames = {}, _defineProperty(_classNames, styles.headerBase, true), _defineProperty(_classNames, styles.header, !!imageComponent || !!imageUrl), _defineProperty(_classNames, styles["header-".concat(theme)], true), _classNames)); // instead of introducing a breaking change for padding removal for non buttons existence, we add this prop
var shouldRemoveButtonsPadding = removeButtonsPadding && !primaryButtonLabel && !secondaryButtonLabel;
var shouldDisplayBodyPadding = !noBodyPadding;
return /*#__PURE__*/React.createElement("div", {
className: styles.root,
style: {
width: width
},
"data-hook": dataHook
}, /*#__PURE__*/React.createElement("div", {
className: headerClasses
}, /*#__PURE__*/React.createElement("div", {
className: styles.close
}, /*#__PURE__*/React.createElement(CloseButton, {
dataHook: "close-button",
size: "medium",
onClick: onClose,
skin: theme === 'white' ? 'dark' : 'lightFilled'
})), imageComponent ? /*#__PURE__*/React.createElement("div", {
className: styles.headerImageComponent
}, imageComponent) : imageUrl ? /*#__PURE__*/React.createElement("div", {
className: styles.headerImage
}, /*#__PURE__*/React.createElement("img", {
src: imageUrl,
"data-hook": "header-image"
})) : null), /*#__PURE__*/React.createElement("div", {
className: classNames(styles.title, _defineProperty({}, styles.bodyPadding, shouldDisplayBodyPadding)),
"data-hook": "message-box-title"
}, /*#__PURE__*/React.createElement(Heading, {
appearance: "H1"
}, title)), /*#__PURE__*/React.createElement("div", {
className: classNames(styles.content, _defineProperty({}, styles.bodyPadding, shouldDisplayBodyPadding))
}, /*#__PURE__*/React.createElement(Text, {
size: "medium",
weight: "thin"
}, content)), shouldRemoveButtonsPadding ? /*#__PURE__*/React.createElement("div", {
className: styles.emptyButtonsContainer
}) : this._renderButtons(), footerBottomChildren ? /*#__PURE__*/React.createElement("div", {
"data-hook": "footer-layout-bottom-children",
className: styles.bottomChildren,
children: footerBottomChildren
}) : null);
}
}]);
return MessageBoxMarketerialLayout;
}(React.PureComponent);
MessageBoxMarketerialLayout.propTypes = {
/** applied as data-hook HTML attribute that can be used to create driver in testing */
dataHook: PropTypes.string,
title: PropTypes.node.isRequired,
content: PropTypes.node.isRequired,
primaryButtonLabel: PropTypes.string,
primaryButtonDisabled: PropTypes.bool,
primaryButtonNode: PropTypes.node,
secondaryButtonLabel: PropTypes.string,
onPrimaryButtonClick: PropTypes.func,
onSecondaryButtonClick: PropTypes.func,
imageUrl: PropTypes.string,
onClose: PropTypes.func.isRequired,
imageComponent: PropTypes.node,
footerBottomChildren: PropTypes.node,
theme: PropTypes.oneOf(['blue', 'purple', 'white']),
primaryButtonTheme: PropTypes.oneOf(['blue', 'purple']),
removeButtonsPadding: PropTypes.bool,
width: PropTypes.string,
noBodyPadding: PropTypes.bool
};
MessageBoxMarketerialLayout.defaultProps = {
theme: 'blue',
removeButtonsPadding: false,
width: '600px',
noBodyPadding: false
};
export default MessageBoxMarketerialLayout;