@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.
248 lines (202 loc) • 12 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = exports.MobileHeader = exports.StyledModalHeader = void 0;
var React = _interopRequireWildcard(require("react"));
var _styledComponents = _interopRequireWildcard(require("styled-components"));
var _Text = _interopRequireDefault(require("../../Text"));
var _Heading = _interopRequireWildcard(require("../../Heading"));
var _defaultTheme = _interopRequireDefault(require("../../defaultTheme"));
var _mediaQuery = _interopRequireDefault(require("../../utils/mediaQuery"));
var _ModalSection = require("../ModalSection");
var _rtl = require("../../utils/rtl");
var _ModalContext = require("../ModalContext");
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 ModalTitle = _styledComponents.default.div.withConfig({
displayName: "ModalHeader__ModalTitle",
componentId: "sc-13vyf6i-0"
})(["margin-top:", ";", "{padding-", ":", ";}", ";"], function (_ref) {
var theme = _ref.theme,
illustration = _ref.illustration;
return illustration && theme.orbit.spaceXSmall;
}, _Heading.StyledHeading, _rtl.right, function (_ref2) {
var theme = _ref2.theme;
return theme.orbit.spaceXLarge;
}, _mediaQuery.default.desktop((0, _styledComponents.css)(["", "{padding:0;}"], _Heading.StyledHeading)));
ModalTitle.defaultProps = {
theme: _defaultTheme.default
};
var ModalDescription = _styledComponents.default.div.withConfig({
displayName: "ModalHeader__ModalDescription",
componentId: "sc-13vyf6i-1"
})(["margin-top:", ";"], function (_ref3) {
var theme = _ref3.theme;
return theme.orbit.spaceXSmall;
});
ModalDescription.defaultProps = {
theme: _defaultTheme.default
};
var StyledModalHeader = _styledComponents.default.div.withConfig({
displayName: "ModalHeader__StyledModalHeader",
componentId: "sc-13vyf6i-2"
})(["width:100%;display:block;padding:", ";border-top-left-radius:", ";border-top-right-radius:", ";box-sizing:border-box;background-color:", ";& ~ ", ":first-of-type{border-top:", ";border-top-left-radius:0;border-top-right-radius:0;margin-top:", ";}", ";"], function (_ref4) {
var theme = _ref4.theme,
illustration = _ref4.illustration,
suppressed = _ref4.suppressed;
return (0, _rtl.rtlSpacing)(illustration && suppressed && "".concat(theme.orbit.spaceXLarge, " ").concat(theme.orbit.spaceMedium, " ").concat(theme.orbit.spaceLarge, " ").concat(theme.orbit.spaceMedium) || illustration && !suppressed && "".concat(theme.orbit.spaceXLarge, " ").concat(theme.orbit.spaceMedium, " 0 ").concat(theme.orbit.spaceMedium) || !illustration && suppressed && "".concat(theme.orbit.spaceLarge, " ").concat(theme.orbit.spaceMedium, " ").concat(theme.orbit.spaceLarge, " ").concat(theme.orbit.spaceMedium) || "".concat(theme.orbit.spaceLarge, " ").concat(theme.orbit.spaceMedium, " 0 ").concat(theme.orbit.spaceMedium));
}, function (_ref5) {
var isMobileFullPage = _ref5.isMobileFullPage;
return !isMobileFullPage && "9px";
}, function (_ref6) {
var isMobileFullPage = _ref6.isMobileFullPage;
return !isMobileFullPage && "9px";
}, function (_ref7) {
var suppressed = _ref7.suppressed,
theme = _ref7.theme;
return suppressed ? theme.orbit.paletteCloudLight : theme.orbit.paletteWhite;
}, _ModalSection.StyledModalSection, function (_ref8) {
var suppressed = _ref8.suppressed,
theme = _ref8.theme;
return suppressed && "1px solid ".concat(theme.orbit.paletteCloudNormal);
}, function (_ref9) {
var suppressed = _ref9.suppressed;
return suppressed && "0!important";
}, _mediaQuery.default.largeMobile((0, _styledComponents.css)(["padding:", ";& ~ ", ":first-of-type{border-top-left-radius:0;border-top-right-radius:0;}"], function (_ref10) {
var theme = _ref10.theme,
illustration = _ref10.illustration,
suppressed = _ref10.suppressed;
return (0, _rtl.rtlSpacing)(illustration ? "".concat(theme.orbit.spaceXLarge, " ").concat(theme.orbit.spaceXXLarge, " ").concat(suppressed ? theme.orbit.spaceXXLarge : "0", " ").concat(theme.orbit.spaceXXLarge) : "".concat(theme.orbit.spaceXXLarge, " ").concat(theme.orbit.spaceXXLarge, " ").concat(suppressed ? theme.orbit.spaceXXLarge : "0", " ").concat(theme.orbit.spaceXXLarge));
}, _ModalSection.StyledModalSection)));
exports.StyledModalHeader = StyledModalHeader;
StyledModalHeader.defaultProps = {
theme: _defaultTheme.default
};
var MobileHeader = _styledComponents.default.div.withConfig({
displayName: "ModalHeader__MobileHeader",
componentId: "sc-13vyf6i-3"
})(["display:inline-block;position:fixed;visibility:hidden;height:52px;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;top:", ";", ":48px;", ":0;font-family:", ";font-weight:", ";font-size:18px;color:", ";line-height:52px;box-sizing:border-box;padding:", ";opacity:0;transition:top ", " ease-in-out,opacity ", " ease-in-out,visibility ", " ease-in-out;z-index:800;", ";"], function (_ref11) {
var isMobileFullPage = _ref11.isMobileFullPage;
return isMobileFullPage ? "0" : "16px";
}, _rtl.right, _rtl.left, function (_ref12) {
var theme = _ref12.theme;
return theme.orbit.fontFamily;
}, function (_ref13) {
var theme = _ref13.theme;
return theme.orbit.fontWeightHeadingDisplay;
}, function (_ref14) {
var theme = _ref14.theme;
return theme.orbit.colorHeading;
}, function (_ref15) {
var theme = _ref15.theme;
return (0, _rtl.rtlSpacing)("0 0 0 ".concat(theme.orbit.spaceLarge));
}, function (_ref16) {
var theme = _ref16.theme;
return theme.orbit.durationFast;
}, function (_ref17) {
var theme = _ref17.theme;
return theme.orbit.durationFast;
}, function (_ref18) {
var theme = _ref18.theme;
return theme.orbit.durationFast;
}, _mediaQuery.default.largeMobile((0, _styledComponents.css)(["left:auto;right:auto;padding:0;"])));
exports.MobileHeader = MobileHeader;
MobileHeader.defaultProps = {
theme: _defaultTheme.default
};
var StyledModalHeaderContent = _styledComponents.default.div.withConfig({
displayName: "ModalHeader__StyledModalHeaderContent",
componentId: "sc-13vyf6i-4"
})(["margin-top:", ";"], function (_ref19) {
var description = _ref19.description;
return description ? "32px" : "16px";
});
var ModalHeader =
/*#__PURE__*/
function (_React$PureComponent) {
_inherits(ModalHeader, _React$PureComponent);
function ModalHeader() {
var _getPrototypeOf2;
var _this;
_classCallCheck(this, ModalHeader);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(ModalHeader)).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();
}
});
return _this;
}
_createClass(ModalHeader, [{
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$props2 = this.props,
title = _this$props2.title,
illustration = _this$props2.illustration,
description = _this$props2.description,
children = _this$props2.children,
suppressed = _this$props2.suppressed,
dataTest = _this$props2.dataTest,
isMobileFullPage = _this$props2.isMobileFullPage;
var hasHeader = title || description;
return React.createElement(StyledModalHeader, {
illustration: !!illustration,
suppressed: suppressed,
"data-test": dataTest,
isMobileFullPage: isMobileFullPage
}, illustration, hasHeader && React.createElement(ModalTitle, {
illustration: !!illustration
}, title && React.createElement(_Heading.default, {
type: "title1"
}, title), description && React.createElement(ModalDescription, null, React.createElement(_Text.default, {
size: "large",
element: "div"
}, description))), children && React.createElement(StyledModalHeaderContent, {
description: !!description
}, children), title && React.createElement(MobileHeader, {
isMobileFullPage: isMobileFullPage
}, title));
}
}]);
return ModalHeader;
}(React.PureComponent);
var DecoratedComponent = (0, _ModalContext.withModalContext)(ModalHeader); // $FlowFixMe flow doesn't recognize displayName for functions
DecoratedComponent.displayName = "ModalHeader";
var _default = DecoratedComponent;
exports.default = _default;