@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.
79 lines • 2.86 kB
JavaScript
import * as React from "react";
import styled, { css } from "styled-components";
import CarrierLogo, { StyledCarrierLogo } from "../../CarrierLogo";
import defaultTheme from "../../defaultTheme";
import { rtlSpacing, left } from "../../utils/rtl";
export const StyledBadge = styled(({
className,
children,
dataTest,
ariaLabel,
id
}) => /*#__PURE__*/React.createElement("div", {
className: className,
id: id,
"data-test": dataTest,
"aria-label": ariaLabel
}, children)).withConfig({
displayName: "BadgePrimitive__StyledBadge",
componentId: "sc-1aa3b9c-0"
})(["", ""], ({
theme,
background,
foregroundColor
}) => css(["position:relative;font-family:", ";display:inline-flex;flex:0 0 auto;box-sizing:border-box;justify-content:center;align-items:center;min-height:", ";line-height:14px;font-size:", ";font-weight:", ";background:", ";color:", ";border-radius:", ";padding:", ";", "{position:absolute;", ":0px;}"], theme.orbit.fontFamily, theme.orbit.heightBadge, theme.orbit.fontSizeTextSmall, theme.orbit.fontWeightMedium, background, foregroundColor, theme.orbit.borderRadiusBadge, theme.orbit.paddingBadge, StyledCarrierLogo, left));
StyledBadge.defaultProps = {
theme: defaultTheme
};
const IconContainer = styled(({
className,
children
}) => /*#__PURE__*/React.createElement("div", {
className: className
}, children)).withConfig({
displayName: "BadgePrimitive__IconContainer",
componentId: "sc-1aa3b9c-1"
})(["", ""], ({
theme,
hasContent
}) => css(["display:flex;flex-shrink:0;margin:", ";svg{height:", ";width:", ";}"], hasContent && rtlSpacing(theme.orbit.marginBadgeIcon), theme.orbit.widthIconSmall, theme.orbit.heightIconSmall));
IconContainer.defaultProps = {
theme: defaultTheme
};
const StyledBadgeContent = styled.div.withConfig({
displayName: "BadgePrimitive__StyledBadgeContent",
componentId: "sc-1aa3b9c-2"
})(["", ""], ({
theme,
$isCarrier
}) => css(["padding:", " 0;line-height:1;margin-", ":", "px;"], theme.orbit.spaceXXSmall, left, $isCarrier && parseInt(theme.orbit.widthIconMedium, 10) - parseInt(theme.orbit.spaceXXSmall, 10)));
StyledBadgeContent.defaultProps = {
theme: defaultTheme
};
const BadgePrimitive = ({
icon,
children,
ariaLabel,
dataTest,
id,
background,
foregroundColor,
carriers
}) => {
return /*#__PURE__*/React.createElement(StyledBadge, {
background: background,
foregroundColor: foregroundColor,
id: id,
dataTest: dataTest,
ariaLabel: ariaLabel
}, carriers && /*#__PURE__*/React.createElement(CarrierLogo, {
carriers: carriers,
rounded: true,
size: "medium"
}), icon && /*#__PURE__*/React.createElement(IconContainer, {
hasContent: !!children
}, icon), /*#__PURE__*/React.createElement(StyledBadgeContent, {
$isCarrier: carriers && carriers.length > 0
}, children));
};
export default BadgePrimitive;