UNPKG

@kiwicom/orbit-components

Version:

Orbit-components is a React component library which provides developers with the easiest possible way of building Kiwi.com’s products.

207 lines (161 loc) 8.97 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = exports.StyledModalFooter = void 0; var React = _interopRequireWildcard(require("react")); var _styledComponents = _interopRequireWildcard(require("styled-components")); var _mediaQuery = _interopRequireWildcard(require("../../utils/mediaQuery")); var _defaultTheme = _interopRequireDefault(require("../../defaultTheme")); var _Button = require("../../Button"); var _rtl = require("../../utils/rtl"); var _ButtonLink = require("../../ButtonLink"); var _ModalContext = require("../ModalContext"); var _consts = require("../../utils/mediaQuery/consts"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a 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); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } 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; } var StyledChild = _styledComponents.default.div.withConfig({ displayName: "ModalFooter__StyledChild", componentId: "sc-17ld6v4-0" })(["flex:", ";box-sizing:border-box;padding:", ";", ";"], function (_ref) { var flex = _ref.flex; return flex; }, function (_ref2) { var theme = _ref2.theme; return (0, _rtl.rtlSpacing)("0 ".concat(theme.orbit.spaceMedium, " 0 0")); }, _mediaQuery.default.largeMobile((0, _styledComponents.css)(["flex:none;"]))); StyledChild.defaultProps = { theme: _defaultTheme.default }; var StyledModalFooter = _styledComponents.default.div.withConfig({ displayName: "ModalFooter__StyledModalFooter", componentId: "sc-17ld6v4-1" })(["display:flex;z-index:800;width:100%;background-color:", ";padding:", ";box-sizing:border-box;transition:box-shadow ", " ease-in-out;@media (max-width:", "px){", ",", "{font-size:", ";height:", ";}}", ";", ":last-of-type{padding:0;}"], function (_ref3) { var theme = _ref3.theme; return theme.orbit.paletteWhite; }, function (_ref4) { var theme = _ref4.theme; return (0, _rtl.rtlSpacing)("0 ".concat(theme.orbit.spaceMedium, " ").concat(theme.orbit.spaceMedium)); }, function (_ref5) { var theme = _ref5.theme; return theme.orbit.durationFast; }, function (_ref6) { var theme = _ref6.theme; return +(0, _mediaQuery.getBreakpointWidth)(_consts.QUERIES.LARGEMOBILE, theme, true) - 1; }, _Button.StyledButton, _ButtonLink.StyledButtonLink, function (_ref7) { var theme = _ref7.theme; return theme.orbit.fontSizeButtonNormal; }, function (_ref8) { var theme = _ref8.theme; return theme.orbit.heightButtonNormal; }, _mediaQuery.default.largeMobile((0, _styledComponents.css)(["justify-content:", ";border-bottom-left-radius:", ";border-bottom-right-radius:", ";"], function (_ref9) { var children = _ref9.children; return children.length > 1 ? "space-between" : "flex-end"; }, function (_ref10) { var isMobileFullPage = _ref10.isMobileFullPage; return !isMobileFullPage && "9px"; }, function (_ref11) { var isMobileFullPage = _ref11.isMobileFullPage; return !isMobileFullPage && "9px"; })), StyledChild); exports.StyledModalFooter = StyledModalFooter; StyledModalFooter.defaultProps = { theme: _defaultTheme.default }; var ModalFooter = /*#__PURE__*/ function (_React$PureComponent) { _inherits(ModalFooter, _React$PureComponent); function ModalFooter() { var _getPrototypeOf2; var _this; _classCallCheck(this, ModalFooter); for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } _this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(ModalFooter)).call.apply(_getPrototypeOf2, [this].concat(args))); _defineProperty(_assertThisInitialized(_this), "callContextFunctions", function () { var _this$props = _this.props, setDimensions = _this$props.setDimensions, decideFixedFooter = _this$props.decideFixedFooter; if (setDimensions) { setDimensions(); } if (decideFixedFooter) { decideFixedFooter(); } }); _defineProperty(_assertThisInitialized(_this), "renderWrappedChildren", function () { var _this$props2 = _this.props, children = _this$props2.children, _this$props2$flex = _this$props2.flex, flex = _this$props2$flex === void 0 ? "0 1 auto" : _this$props2$flex; var getChildFlex = function getChildFlex(key) { return Array.isArray(flex) && flex.length !== 1 ? flex[key] || flex[0] : flex; }; return React.Children.map(children, function (child, key) { if (child) { return React.createElement(StyledChild, { flex: getChildFlex(key) }, React.cloneElement(child, { ref: function ref(node) { // Call the original ref, if any var ref = child.ref; if (typeof ref === "function") { ref(node); } else if (ref !== null) { ref.current = node; } } })); } return null; }); }); return _this; } _createClass(ModalFooter, [{ key: "componentDidMount", value: function componentDidMount() { this.callContextFunctions(); } }, { key: "componentDidUpdate", value: function componentDidUpdate(prevProps) { if (prevProps !== this.props) { this.callContextFunctions(); var manageFocus = this.props.manageFocus; if (manageFocus) { manageFocus(); } } } }, { key: "render", value: function render() { var _this$props3 = this.props, children = _this$props3.children, dataTest = _this$props3.dataTest, isMobileFullPage = _this$props3.isMobileFullPage; return React.createElement(StyledModalFooter, { "data-test": dataTest, isMobileFullPage: isMobileFullPage }, Array.isArray(children) ? this.renderWrappedChildren() : children); } }]); return ModalFooter; }(React.PureComponent); var DecoratedComponent = (0, _ModalContext.withModalContext)(ModalFooter); // $FlowFixMe flow doesn't recognize displayName for functions DecoratedComponent.displayName = "ModalFooter"; var _default = DecoratedComponent; exports.default = _default;