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.

82 lines (78 loc) 3.11 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"; var ChevronIcon = styled(ChevronDown).withConfig({ displayName: "Header__ChevronIcon", componentId: "sc-14vrb8n-0" })(["transform:", ";transition:", ";"], function (_ref) { var expanded = _ref.expanded; return 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 }; var StyledCloseContainer = styled.div.withConfig({ displayName: "Header__StyledCloseContainer", componentId: "sc-14vrb8n-1" })(["position:absolute;top:0;", ":0;z-index:1;"], right); var CardCloseButton = function CardCloseButton(_ref2) { var onClick = _ref2.onClick; var translate = useTranslate(); return /*#__PURE__*/React.createElement(ButtonLink, { type: "secondary", size: "small", iconLeft: /*#__PURE__*/React.createElement(Close, null), onClick: onClick, title: translate("button_close") }); }; var Header = function Header(_ref3) { var description = _ref3.description, icon = _ref3.icon, title = _ref3.title, titleAs = _ref3.titleAs, isSection = _ref3.isSection, actions = _ref3.actions, dataA11ySection = _ref3.dataA11ySection, onClose = _ref3.onClose, header = _ref3.header, expandable = _ref3.expandable, expanded = _ref3.expanded; return /*#__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, null, description)), header && icon, header, expandable && !actions && /*#__PURE__*/React.createElement(ChevronIcon, { expanded: expanded, color: "secondary" }), 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;