@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.
145 lines (131 loc) • 6.55 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";
const getModalHeading = (type, token) => ({
theme
}) => {
return getHeadingToken(token, type)({
theme
});
};
export const ModalHeading = styled.h2.withConfig({
displayName: "ModalHeader__ModalHeading",
componentId: "sc-1wm3wwv-0"
})(["", ""], ({
theme
}) => css(["margin: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), 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
};
const ModalTitle = styled.div.withConfig({
displayName: "ModalHeader__ModalTitle",
componentId: "sc-1wm3wwv-1"
})(["", ""], ({
theme,
illustration
}) => css(["margin-top:", ";", "{padding-", ":", ";}", ";"], illustration && theme.orbit.spaceMedium, ModalHeading, right, 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
};
const ModalDescription = styled.div.withConfig({
displayName: "ModalHeader__ModalDescription",
componentId: "sc-1wm3wwv-2"
})(["margin-top:", ";"], ({
theme
}) => theme.orbit.spaceXSmall); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198
ModalDescription.defaultProps = {
theme: defaultTheme
};
const getModalHeaderPadding = (desktop = false) => ({
theme,
suppressed
}) => {
if (desktop) {
if (suppressed) {
return theme.orbit.spaceXLarge;
}
return `${theme.orbit.spaceXLarge} ${theme.orbit.spaceXLarge} 0 ${theme.orbit.spaceXLarge}`;
}
if (suppressed) {
return `${theme.orbit.spaceXLarge} ${theme.orbit.spaceMedium}`;
}
return `${theme.orbit.spaceLarge} ${theme.orbit.spaceMedium} 0 ${theme.orbit.spaceMedium}`;
};
export const StyledModalHeader = styled.div.withConfig({
displayName: "ModalHeader__StyledModalHeader",
componentId: "sc-1wm3wwv-3"
})(["", ""], ({
theme,
suppressed,
isMobileFullPage
}) => css(["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:", ";}", ";"], props => rtlSpacing(getModalHeaderPadding()(props)), !isMobileFullPage && "12px", !isMobileFullPage && "12px", suppressed ? theme.orbit.paletteCloudLight : theme.orbit.paletteWhite, StyledModalSection, suppressed && `1px solid ${theme.orbit.paletteCloudNormal}`, suppressed && "0!important", media.largeMobile(css(["padding:", ";& ~ ", ":first-of-type{border-top-left-radius:0;border-top-right-radius:0;}"], props => rtlSpacing(getModalHeaderPadding(true)(props)), StyledModalSection)))); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198
StyledModalHeader.defaultProps = {
theme: defaultTheme
};
export const MobileHeader = styled.div.withConfig({
displayName: "ModalHeader__MobileHeader",
componentId: "sc-1wm3wwv-4"
})(["", ""], ({
theme,
isMobileFullPage
}) => css(["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;", ";"], isMobileFullPage ? "0" : "16px", right, left, theme.orbit.fontFamily, theme.orbit.fontWeightHeadingDisplay, theme.orbit.colorHeading, rtlSpacing(`0 0 0 ${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
};
const StyledModalHeaderContent = styled.div.withConfig({
displayName: "ModalHeader__StyledModalHeaderContent",
componentId: "sc-1wm3wwv-5"
})(["margin-top:", ";"], ({
description
}) => description ? "32px" : "16px");
const ModalHeader = ({
illustration,
suppressed,
children,
description,
title,
dataTest
}) => {
const {
setHasModalTitle,
hasMobileHeader,
isMobileFullPage,
titleID
} = React.useContext(ModalContext);
useModalContextFunctions();
React.useEffect(() => {
if (title) setHasModalTitle == null ? void 0 : setHasModalTitle(true);
return () => {
setHasModalTitle == null ? void 0 : setHasModalTitle(false);
};
}, [title, setHasModalTitle]);
const 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, {
id: titleID
}, 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, {
role: "presentation",
isMobileFullPage: isMobileFullPage
}, title));
};
export default ModalHeader;