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.

130 lines (128 loc) 4.58 kB
import * as React from "react"; import styled, { css } from "styled-components"; import { left, rtlSpacing } from "../../utils/rtl"; import Text from "../ItineraryTemporaryText"; import Stack from "../../Stack"; import defaultTheme from "../../defaultTheme"; import { STATUS } from "./consts"; import getSpacingToken from "../../common/getSpacingToken"; import AlertOctagon from "../../icons/AlertOctagon"; import Warning from "../../icons/AlertCircle"; import Info from "../../icons/InformationCircle"; import Check from "../../icons/CheckCircle"; import useTheme from "../../hooks/useTheme"; const resolveColor = (status, isHeader) => ({ theme }) => { const border = { [STATUS.WARNING]: theme.orbit.paletteOrangeNormal, [STATUS.CRITICAL]: theme.orbit.paletteRedNormal, [STATUS.INFO]: theme.orbit.paletteBlueNormal, [STATUS.SUCCESS]: theme.orbit.paletteGreenNormal, [STATUS.NEUTRAL]: theme.orbit.paletteInkDark }; const header = { [STATUS.WARNING]: theme.orbit.paletteOrangeLight, [STATUS.INFO]: theme.orbit.paletteBlueLight, [STATUS.CRITICAL]: theme.orbit.paletteRedLight, [STATUS.SUCCESS]: theme.orbit.paletteGreenLight, [STATUS.NEUTRAL]: theme.orbit.paletteCloudNormal }; if (isHeader) return header[status]; return border[status]; }; const StyledWrapper = styled.div.withConfig({ displayName: "ItineraryStatus__StyledWrapper", componentId: "sc-11w7z41-0" })(["", ""], ({ theme, $type, actionable }) => css(["display:flex;box-sizing:border-box;flex-direction:column;width:100%;border-radius:", ";border-", ":", " solid ", ";box-shadow:", ";margin-bottom:", ";", ""], theme.orbit.borderRadiusLarge, left, theme.orbit.borderRadiusNormal, $type && resolveColor($type), theme.orbit.boxShadowFixed, getSpacingToken, actionable && css(["&:hover{box-shadow:", ";}"], theme.orbit.boxShadowActionActive))); StyledWrapper.defaultProps = { theme: defaultTheme }; const StyledStatusHeader = styled.div.withConfig({ displayName: "ItineraryStatus__StyledStatusHeader", componentId: "sc-11w7z41-1" })(["", ""], ({ theme, $type }) => css(["display:flex;align-items:center;padding:", ";min-height:", ";border-radius:", " ", " 0 0;background:", ";"], rtlSpacing(`0 ${theme.orbit.spaceXSmall}`), theme.orbit.spaceXLarge, theme.orbit.borderRadiusNormal, theme.orbit.borderRadiusLarge, $type && resolveColor($type, true))); StyledStatusHeader.defaultProps = { theme: defaultTheme }; // calculatedOffset + paddings const StyledStatusText = styled.div.withConfig({ displayName: "ItineraryStatus__StyledStatusText", componentId: "sc-11w7z41-2" })(["", ";"], ({ theme, $offset }) => css(["z-index:2;margin-", ":", "px;"], left, parseInt(theme.orbit.spaceSmall, 10) + $offset)); StyledStatusText.defaultProps = { theme: defaultTheme }; // TODO: refactor this after designers will resolve status colors // https://skypicker.slack.com/archives/GSGN9BN6Q/p1674568716519889 const StatusIcon = ({ type }) => { const theme = useTheme(); switch (type) { case "info": return /*#__PURE__*/React.createElement(Info, { size: "small", customColor: theme.orbit.paletteBlueDark }); case "critical": return /*#__PURE__*/React.createElement(AlertOctagon, { size: "small", customColor: theme.orbit.paletteRedDark }); case "success": return /*#__PURE__*/React.createElement(Check, { size: "small", customColor: theme.orbit.paletteGreenDark }); case "neutral": return /*#__PURE__*/React.createElement(Info, { size: "small", customColor: "primary" }); default: return /*#__PURE__*/React.createElement(Warning, { size: "small", customColor: theme.orbit.paletteOrangeDark }); } }; const ItineraryStatus = ({ type, label, spaceAfter = "medium", children, offset = 0, actionable = true }) => { return /*#__PURE__*/React.createElement(StyledWrapper, { $type: type, spaceAfter: spaceAfter, actionable: actionable }, /*#__PURE__*/React.createElement(StyledStatusHeader, { $type: type }, /*#__PURE__*/React.createElement(StyledStatusText, { $offset: offset }, /*#__PURE__*/React.createElement(Stack, { flex: true, spacing: "XSmall", align: "center" }, /*#__PURE__*/React.createElement(StatusIcon, { type: type }), label && /*#__PURE__*/React.createElement(Text, { as: "div", type: type === "neutral" ? "primary" : type, weight: "medium" }, label)))), children); }; export default ItineraryStatus;