@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.
182 lines (165 loc) • 8.1 kB
JavaScript
import * as React from "react";
import styled, { css } from "styled-components";
import transition from "../../utils/transition";
import Text from "../../Text";
import { getHeadingToken } from "../../Heading";
import { TOKENS, TYPE_OPTIONS } from "../../Heading/consts";
import defaultTheme from "../../defaultTheme";
import media from "../../utils/mediaQuery";
import { StyledModalSection } from "../ModalSection";
import { left, right, rtlSpacing } from "../../utils/rtl";
import { ModalContext } from "../ModalContext";
import useModalContextFunctions from "../helpers/useModalContextFunctions";
var getModalHeading = function getModalHeading(type, token) {
return function (_ref) {
var theme = _ref.theme;
return getHeadingToken(token)({
theme: theme,
type: type
});
};
};
export var ModalHeading = styled.div.withConfig({
displayName: "ModalHeader__ModalHeading",
componentId: "sc-13vyf6i-0"
})(["font-size:", ";font-weight:", ";line-height:", ";color:", ";", ";"], getModalHeading(TYPE_OPTIONS.TITLE2, TOKENS.sizeHeading), getModalHeading(TYPE_OPTIONS.TITLE2, TOKENS.weightHeading), getModalHeading(TYPE_OPTIONS.TITLE2, TOKENS.lineHeight), function (_ref2) {
var theme = _ref2.theme;
return theme.orbit.colorHeading;
}, media.largeMobile(css(["font-size:", ";font-weight:", ";line-height:", ";"], getModalHeading(TYPE_OPTIONS.TITLE1, TOKENS.sizeHeading), getModalHeading(TYPE_OPTIONS.TITLE1, TOKENS.weightHeading), getModalHeading(TYPE_OPTIONS.TITLE1, TOKENS.lineHeight)))); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198
ModalHeading.defaultProps = {
theme: defaultTheme
};
var ModalTitle = styled.div.withConfig({
displayName: "ModalHeader__ModalTitle",
componentId: "sc-13vyf6i-1"
})(["margin-top:", ";", "{padding-", ":", ";}", ";"], function (_ref3) {
var theme = _ref3.theme,
illustration = _ref3.illustration;
return illustration && theme.orbit.spaceXSmall;
}, ModalHeading, right, function (_ref4) {
var theme = _ref4.theme;
return theme.orbit.spaceXLarge;
}, media.desktop(css(["", "{padding:0;}"], ModalHeading))); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198
ModalTitle.defaultProps = {
theme: defaultTheme
};
var ModalDescription = styled.div.withConfig({
displayName: "ModalHeader__ModalDescription",
componentId: "sc-13vyf6i-2"
})(["margin-top:", ";"], function (_ref5) {
var theme = _ref5.theme;
return theme.orbit.spaceXSmall;
}); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198
ModalDescription.defaultProps = {
theme: defaultTheme
};
var getModalHeaderPadding = function getModalHeaderPadding() {
var desktop = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
return function (_ref6) {
var theme = _ref6.theme,
suppressed = _ref6.suppressed;
if (desktop) {
if (suppressed) {
return theme.orbit.spaceXXLarge;
}
return "".concat(theme.orbit.spaceXXLarge, " ").concat(theme.orbit.spaceXXLarge, " 0 ").concat(theme.orbit.spaceXXLarge);
}
if (suppressed) {
return "".concat(theme.orbit.spaceXXLarge, " ").concat(theme.orbit.spaceMedium);
}
return "".concat(theme.orbit.spaceLarge, " ").concat(theme.orbit.spaceMedium, " 0 ").concat(theme.orbit.spaceMedium);
};
};
export var StyledModalHeader = styled.div.withConfig({
displayName: "ModalHeader__StyledModalHeader",
componentId: "sc-13vyf6i-3"
})(["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 (props) {
return rtlSpacing(getModalHeaderPadding()(props));
}, function (_ref7) {
var isMobileFullPage = _ref7.isMobileFullPage;
return !isMobileFullPage && "12px";
}, function (_ref8) {
var isMobileFullPage = _ref8.isMobileFullPage;
return !isMobileFullPage && "12px";
}, function (_ref9) {
var suppressed = _ref9.suppressed,
theme = _ref9.theme;
return suppressed ? theme.orbit.paletteCloudLight : theme.orbit.paletteWhite;
}, StyledModalSection, function (_ref10) {
var suppressed = _ref10.suppressed,
theme = _ref10.theme;
return suppressed && "1px solid ".concat(theme.orbit.paletteCloudNormal);
}, function (_ref11) {
var suppressed = _ref11.suppressed;
return suppressed && "0!important";
}, media.largeMobile(css(["padding:", ";& ~ ", ":first-of-type{border-top-left-radius:0;border-top-right-radius:0;}"], function (props) {
return rtlSpacing(getModalHeaderPadding(true)(props));
}, StyledModalSection))); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198
StyledModalHeader.defaultProps = {
theme: defaultTheme
};
export var MobileHeader = styled.div.withConfig({
displayName: "ModalHeader__MobileHeader",
componentId: "sc-13vyf6i-4"
})(["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:", ";z-index:800;", ";"], function (_ref12) {
var isMobileFullPage = _ref12.isMobileFullPage;
return isMobileFullPage ? "0" : "16px";
}, right, left, function (_ref13) {
var theme = _ref13.theme;
return theme.orbit.fontFamily;
}, function (_ref14) {
var theme = _ref14.theme;
return theme.orbit.fontWeightHeadingDisplay;
}, function (_ref15) {
var theme = _ref15.theme;
return theme.orbit.colorHeading;
}, function (_ref16) {
var theme = _ref16.theme;
return rtlSpacing("0 0 0 ".concat(theme.orbit.spaceLarge));
}, transition(["top", "opacity", "visibility"], "fast", "ease-in-out"), media.largeMobile(css(["left:auto;right:auto;padding:0;"]))); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198
MobileHeader.defaultProps = {
theme: defaultTheme
};
var StyledModalHeaderContent = styled.div.withConfig({
displayName: "ModalHeader__StyledModalHeaderContent",
componentId: "sc-13vyf6i-5"
})(["margin-top:", ";"], function (_ref17) {
var description = _ref17.description;
return description ? "32px" : "16px";
});
var ModalHeader = function ModalHeader(_ref18) {
var illustration = _ref18.illustration,
suppressed = _ref18.suppressed,
children = _ref18.children,
description = _ref18.description,
title = _ref18.title,
dataTest = _ref18.dataTest;
var _React$useContext = React.useContext(ModalContext),
setHasModalTitle = _React$useContext.setHasModalTitle,
hasMobileHeader = _React$useContext.hasMobileHeader,
isMobileFullPage = _React$useContext.isMobileFullPage;
useModalContextFunctions();
React.useEffect(function () {
if (title) setHasModalTitle === null || setHasModalTitle === void 0 ? void 0 : setHasModalTitle(true);
return function () {
setHasModalTitle === null || setHasModalTitle === void 0 ? void 0 : setHasModalTitle(false);
};
}, [title, setHasModalTitle]);
var hasHeader = title || description;
return /*#__PURE__*/React.createElement(StyledModalHeader, {
illustration: !!illustration,
suppressed: suppressed,
"data-test": dataTest,
isMobileFullPage: isMobileFullPage
}, illustration, hasHeader && /*#__PURE__*/React.createElement(ModalTitle, {
illustration: !!illustration
}, title && /*#__PURE__*/React.createElement(ModalHeading, null, title), description && /*#__PURE__*/React.createElement(ModalDescription, null, /*#__PURE__*/React.createElement(Text, {
size: "large",
as: "div"
}, description))), children && /*#__PURE__*/React.createElement(StyledModalHeaderContent, {
description: !!description
}, children), title && hasMobileHeader && /*#__PURE__*/React.createElement(MobileHeader, {
isMobileFullPage: isMobileFullPage
}, title));
};
export default ModalHeader;