@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.
80 lines (72 loc) • 3.24 kB
JavaScript
import * as React from "react";
import styled, { css } from "styled-components";
import Text, { StyledText } from "../../Text";
import TYPE_OPTIONS from "../consts";
import defaultTheme from "../../defaultTheme";
import { ICON_COLORS } from "../../Icon/consts";
import { StyledTooltipChildren } from "../../primitives/TooltipPrimitive";
import { right } from "../../utils/rtl";
const getBackground = ({
theme,
$type
}) => {
const tokens = {
[TYPE_OPTIONS.NEUTRAL]: theme.orbit.paletteCloudLight,
[TYPE_OPTIONS.INFO]: theme.orbit.paletteBlueLight,
[TYPE_OPTIONS.SUCCESS]: theme.orbit.paletteGreenLight,
[TYPE_OPTIONS.WARNING]: theme.orbit.paletteOrangeLight,
[TYPE_OPTIONS.CRITICAL]: theme.orbit.paletteRedLight
};
return tokens[$type];
};
const getIconColor = type => {
if (type === TYPE_OPTIONS.NEUTRAL) return ICON_COLORS.SECONDARY;
return type;
};
const StyledBadgeListItem = styled.li.withConfig({
displayName: "BadgeListItem__StyledBadgeListItem",
componentId: "sc-1et93id-0"
})(["", ";"], ({
theme
}) => css(["display:flex;flex-direction:row;width:100%;& + &{margin-top:", ";}"], theme.orbit.spaceXXSmall)); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198
StyledBadgeListItem.defaultProps = {
theme: defaultTheme
};
const StyledVerticalBadge = styled.div.withConfig({
displayName: "BadgeListItem__StyledVerticalBadge",
componentId: "sc-1et93id-1"
})(["", ";"], ({
theme
}) => css(["background:", ";display:flex;align-items:center;justify-content:center;margin-", ":", ";flex-shrink:0;height:", ";width:", ";border-radius:", ";svg{height:", ";width:", ";}"], getBackground, right, theme.orbit.spaceXSmall, theme.orbit.heightIconMedium, theme.orbit.widthIconMedium, theme.orbit.borderRadiusCircle, theme.orbit.heightIconSmall, theme.orbit.widthIconSmall)); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198
StyledVerticalBadge.defaultProps = {
theme: defaultTheme
};
const StyledVerticalBadgeContent = styled.div.withConfig({
displayName: "BadgeListItem__StyledVerticalBadgeContent",
componentId: "sc-1et93id-2"
})(["", ";"], ({
theme
}) => css(["display:inline-flex;align-items:center;&,", "{font-size:", ";line-height:", ";}", " ", "{font-weight:", ";}"], StyledText, theme.orbit.fontSizeTextSmall, theme.orbit.lineHeightTextSmall, StyledTooltipChildren, StyledText, theme.orbit.fontWeightMedium)); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198
StyledVerticalBadgeContent.defaultProps = {
theme: defaultTheme
};
const BadgeListItem = ({
icon,
type = TYPE_OPTIONS.NEUTRAL,
dataTest,
children
}) => {
return /*#__PURE__*/React.createElement(StyledBadgeListItem, {
"data-test": dataTest
}, /*#__PURE__*/React.createElement(StyledVerticalBadge, {
$type: type,
"aria-hidden": true
}, /*#__PURE__*/React.isValidElement(icon) && /*#__PURE__*/React.cloneElement(icon, {
color: getIconColor(type)
})), /*#__PURE__*/React.createElement(StyledVerticalBadgeContent, null, /*#__PURE__*/React.createElement(Text, {
type: "secondary",
size: "small",
as: "span"
}, children)));
};
export default BadgeListItem;