UNPKG

wix-style-react

Version:
226 lines (181 loc) • 8.86 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties")); var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")); var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); var _react = _interopRequireDefault(require("react")); var _propTypes = _interopRequireDefault(require("prop-types")); var _isEmpty = _interopRequireDefault(require("lodash/isEmpty")); var _Text = _interopRequireDefault(require("../Text")); var _TextButton = _interopRequireDefault(require("../TextButton")); var _Button = _interopRequireDefault(require("../Button")); var _CloseButton = _interopRequireDefault(require("../CloseButton/CloseButton")); var _constants = require("./constants"); var _FloatingNotificationSt = require("./FloatingNotification.st.css"); var _excluded = ["label"], _excluded2 = ["label"]; function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(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; } } var buttonPropTypes = _propTypes["default"].shape({ label: _propTypes["default"].node, as: _propTypes["default"].node, href: _propTypes["default"].string, onClick: _propTypes["default"].func }); /** * Displays simple and temporary messages or destructive events */ var FloatingNotification = /*#__PURE__*/function (_React$PureComponent) { (0, _inherits2["default"])(FloatingNotification, _React$PureComponent); var _super = _createSuper(FloatingNotification); function FloatingNotification() { (0, _classCallCheck2["default"])(this, FloatingNotification); return _super.apply(this, arguments); } (0, _createClass2["default"])(FloatingNotification, [{ key: "render", value: function render() { var _this$props = this.props, type = _this$props.type, className = _this$props.className, dataHook = _this$props.dataHook, width = _this$props.width, fullWidth = _this$props.fullWidth; var icon = this._getIcon(); var content = this._getContent(); var textButton = this._getTextButton(); var button = this._getButton(); var close = this._getClose(); var style = { width: width }; width && (style.maxWidth = width); return /*#__PURE__*/_react["default"].createElement("div", { "data-hook": dataHook, className: (0, _FloatingNotificationSt.st)(_FloatingNotificationSt.classes.root, { fullWidth: fullWidth, type: type }, className), style: style }, icon, content, textButton, button, /*#__PURE__*/_react["default"].createElement("div", { className: _FloatingNotificationSt.classes.gap }), close); } }, { key: "_getIcon", value: function _getIcon() { var _this$props2 = this.props, prefixIcon = _this$props2.prefixIcon, type = _this$props2.type; return prefixIcon ? /*#__PURE__*/_react["default"].createElement("div", { className: (0, _FloatingNotificationSt.st)(_FloatingNotificationSt.classes.icon, { type: type }) }, prefixIcon) : null; } }, { key: "_getContent", value: function _getContent() { var _this$props3 = this.props, text = _this$props3.text, type = _this$props3.type; return /*#__PURE__*/_react["default"].createElement(_Text["default"], { size: "small", ellipsis: true, light: type === _constants.TYPES.dark, dataHook: _constants.dataHooks.notificationText, className: _FloatingNotificationSt.classes.text }, text); } }, { key: "_getTextButton", value: function _getTextButton() { var _this$props4 = this.props, textButtonProps = _this$props4.textButtonProps, type = _this$props4.type; var label = textButtonProps.label, rest = (0, _objectWithoutProperties2["default"])(textButtonProps, _excluded); return !(0, _isEmpty["default"])(textButtonProps) ? /*#__PURE__*/_react["default"].createElement(_TextButton["default"], (0, _extends2["default"])({}, rest, { underline: "always", skin: type !== _constants.TYPES.dark ? 'dark' : 'light', size: "small", className: _FloatingNotificationSt.classes.textButton, dataHook: _constants.dataHooks.textButton }), label) : null; } }, { key: "_getButton", value: function _getButton() { var _this$props5 = this.props, buttonProps = _this$props5.buttonProps, type = _this$props5.type; var label = buttonProps.label, rest = (0, _objectWithoutProperties2["default"])(buttonProps, _excluded2); return !(0, _isEmpty["default"])(buttonProps) ? /*#__PURE__*/_react["default"].createElement(_Button["default"], (0, _extends2["default"])({}, rest, { className: _FloatingNotificationSt.classes.button, size: "tiny", priority: type !== _constants.TYPES.dark ? 'secondary' : 'primary', skin: type !== _constants.TYPES.dark ? 'dark' : 'standard', dataHook: _constants.dataHooks.button }), label) : null; } }, { key: "_getClose", value: function _getClose() { var _this$props6 = this.props, showCloseButton = _this$props6.showCloseButton, onClose = _this$props6.onClose, type = _this$props6.type; return showCloseButton ? /*#__PURE__*/_react["default"].createElement(_CloseButton["default"], { size: "medium", skin: type !== _constants.TYPES.dark ? 'dark' : 'light', className: _FloatingNotificationSt.classes.close, dataHook: _constants.dataHooks.closeButton, onClick: onClose }) : null; } }]); return FloatingNotification; }(_react["default"].PureComponent); (0, _defineProperty2["default"])(FloatingNotification, "displayName", 'FloatingNotification'); (0, _defineProperty2["default"])(FloatingNotification, "propTypes", { /** Applied as data-hook HTML attribute that can be used in the tests */ dataHook: _propTypes["default"].string, /** A css class to be applied to the component's root element */ className: _propTypes["default"].string, /** the type of notification */ type: _propTypes["default"].oneOf(['standard', 'success', 'destructive', 'warning', 'premium', 'preview', 'dark']), /** decides if to show the close button */ showCloseButton: _propTypes["default"].bool, /** close button on click handler */ onClose: _propTypes["default"].func, /** props to pass to textButton - renders the TextButton when not empty*/ textButtonProps: buttonPropTypes, /** props to pass to button - renders the Button when not empty */ buttonProps: buttonPropTypes, /** An icon element to appear before content */ prefixIcon: _propTypes["default"].element, /** The text content of the notification */ text: _propTypes["default"].node, /** The width of the content container of the notification */ width: _propTypes["default"].string, /** Is notification full width (removes left and right border, border radius, more height and bigger paddings) */ fullWidth: _propTypes["default"].bool }); (0, _defineProperty2["default"])(FloatingNotification, "defaultProps", { type: 'standard', buttonProps: {}, textButtonProps: {}, showCloseButton: true }); var _default = FloatingNotification; exports["default"] = _default;