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.

54 lines (50 loc) 2.94 kB
import * as React from "react"; import styled, { css } from "styled-components"; import defaultTheme from "../../defaultTheme"; import media from "../../utils/mediaQuery"; import { StyledModalFooter } from "../ModalFooter"; import { ModalContext } from "../ModalContext"; import useModalContextFunctions from "../helpers/useModalContextFunctions"; export const StyledModalSection = styled.section.withConfig({ displayName: "ModalSection__StyledModalSection", componentId: "sc-emwfdx-0" })(["", ""], ({ theme, suppressed, closable, isMobileFullPage }) => css(["width:100%;padding:", ";background-color:", ";border-bottom:1px solid ", ";box-sizing:border-box;&:first-of-type{border-top:", ";border-top-left-radius:", ";border-top-right-radius:", ";margin-top:", ";}&:last-of-type{border-bottom:", ";border-bottom-left-radius:", ";border-bottom-right-radius:", ";& ~ ", "{margin-top:", ";}&:not(:last-child){border-bottom-left-radius:0;border-bottom-right-radius:0;}}", ";"], `${theme.orbit.spaceLarge} ${theme.orbit.spaceMedium}`, suppressed ? theme.orbit.paletteCloudLight : theme.orbit.paletteWhite, theme.orbit.paletteCloudNormal, suppressed && `1px solid ${theme.orbit.paletteCloudNormal}`, !isMobileFullPage && "12px", !isMobileFullPage && "12px", suppressed && closable && theme.orbit.spaceLarge, suppressed ? `1px solid ${theme.orbit.paletteCloudNormal}` : "0", !isMobileFullPage && "12px", !isMobileFullPage && "12px", StyledModalFooter, suppressed && theme.orbit.spaceMedium, media.largeMobile(css(["padding:", ";&:first-of-type{margin-top:", ";border-top-left-radius:", ";border-top-right-radius:", ";}&:last-of-type{border-bottom-left-radius:", ";border-bottom-right-radius:", ";& ~ ", "{padding-top:", ";margin-top:0;}}"], theme.orbit.spaceXLarge, (suppressed && closable || suppressed) && theme.orbit.spaceXXLarge, !isMobileFullPage && "9px", !isMobileFullPage && "9px", !isMobileFullPage && "9px", !isMobileFullPage && "9px", StyledModalFooter, !suppressed && "0")))); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198 StyledModalSection.defaultProps = { theme: defaultTheme }; const ModalSection = ({ children, suppressed, dataTest }) => { const { removeHasModalSection, setHasModalSection, isMobileFullPage, closable } = React.useContext(ModalContext); useModalContextFunctions(); /* Run on every re-render to prevent setting hasModalSection to false when there's more sections */ React.useEffect(() => { if (setHasModalSection) setHasModalSection(); }); React.useEffect(() => { return () => { if (removeHasModalSection) removeHasModalSection(); }; }, [removeHasModalSection]); return /*#__PURE__*/React.createElement(StyledModalSection, { suppressed: suppressed, "data-test": dataTest, closable: closable, isMobileFullPage: isMobileFullPage }, children); }; export default ModalSection;