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.

83 lines (79 loc) 2.73 kB
import * as React from "react"; import styled from "styled-components"; import transition from "../../../utils/transition"; import { right } from "../../../utils/rtl"; import defaultTheme from "../../../defaultTheme"; import ChevronDown from "../../../icons/ChevronDown"; import Stack from "../../../Stack"; import Heading from "../../../Heading"; import Text from "../../../Text"; import Close from "../../../icons/Close"; import useTranslate from "../../../hooks/useTranslate"; import ButtonLink from "../../../ButtonLink"; const ChevronIcon = styled(ChevronDown).withConfig({ displayName: "Header__ChevronIcon", componentId: "sc-179eter-0" })(["transform:", ";transition:", ";"], ({ expanded }) => expanded && "rotate(-180deg)", transition(["transform"], "fast", "ease-in-out")); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198 ChevronIcon.defaultProps = { theme: defaultTheme }; const StyledCloseContainer = styled.div.withConfig({ displayName: "Header__StyledCloseContainer", componentId: "sc-179eter-1" })(["position:absolute;top:0;", ":0;z-index:1;"], right); const CardCloseButton = ({ onClick }) => { const translate = useTranslate(); return /*#__PURE__*/React.createElement(ButtonLink, { type: "secondary", size: "small", iconLeft: /*#__PURE__*/React.createElement(Close, null), onClick: onClick, title: translate("button_close") }); }; const Header = ({ description, icon, title, titleAs, isSection, actions, dataA11ySection, onClose, header, expandable, expanded }) => /*#__PURE__*/React.createElement(Stack, { align: actions && !header ? "start" : "center", spacing: header ? "small" : "none" }, (title || description || icon) && !header && /*#__PURE__*/React.createElement(Stack, { flex: true, shrink: !!actions || expandable, align: "stretch", direction: "column", spacing: isSection ? "none" : "XXSmall" }, /*#__PURE__*/React.createElement(Stack, { inline: true, spacing: "small", align: "center" }, icon, title && /*#__PURE__*/React.createElement(Heading, { type: isSection ? "title4" : "title3", as: titleAs, dataA11ySection: dataA11ySection }, title)), description && /*#__PURE__*/React.createElement(Text, { as: "div" }, description)), header && icon, header, expandable && !actions && /*#__PURE__*/React.createElement(ChevronIcon, { color: "secondary", expanded: expanded }), actions && /*#__PURE__*/React.createElement(Stack, { inline: true, grow: false, justify: "end" }, actions), onClose && !actions && /*#__PURE__*/React.createElement(StyledCloseContainer, null, /*#__PURE__*/React.createElement(CardCloseButton, { onClick: onClose }))); export default Header;