@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.
98 lines (94 loc) • 3.04 kB
JavaScript
import * as React from "react";
import styled from "styled-components";
import defaultTokens from "../defaultTokens";
import { TYPE_OPTIONS, TOKENS } from "./consts";
const getTypeToken = name => ({
theme,
type
}) => {
const tokens = {
[TOKENS.background]: {
[TYPE_OPTIONS.NEUTRAL]: theme.orbit.backgroundBadgeNeutral,
[TYPE_OPTIONS.INFO]: theme.orbit.backgroundBadgeInfo,
[TYPE_OPTIONS.SUCCESS]: theme.orbit.backgroundBadgeSuccess,
[TYPE_OPTIONS.WARNING]: theme.orbit.backgroundBadgeWarning,
[TYPE_OPTIONS.CRITICAL]: theme.orbit.backgroundBadgeCritical,
[TYPE_OPTIONS.DARK]: theme.orbit.backgroundBadgeDark,
[TYPE_OPTIONS.WHITE]: theme.orbit.backgroundBadgeWhite
},
[TOKENS.color]: {
[TYPE_OPTIONS.NEUTRAL]: theme.orbit.colorTextBadgeNeutral,
[TYPE_OPTIONS.INFO]: theme.orbit.colorTextBadgeInfo,
[TYPE_OPTIONS.SUCCESS]: theme.orbit.colorTextBadgeSuccess,
[TYPE_OPTIONS.WARNING]: theme.orbit.colorTextBadgeWarning,
[TYPE_OPTIONS.CRITICAL]: theme.orbit.colorTextBadgeCritical,
[TYPE_OPTIONS.DARK]: theme.orbit.colorTextBadgeDark,
[TYPE_OPTIONS.WHITE]: theme.orbit.colorTextBadgeWhite
}
};
return tokens[name][type];
};
const StyledBadge = styled(({
className,
children,
dataTest
}) => React.createElement("div", {
className: className,
"data-test": dataTest
}, children)).withConfig({
displayName: "Badge__StyledBadge",
componentId: "sc-1y6i8f0-0"
})(["font-family:", ";display:inline-flex;box-sizing:border-box;justify-content:center;align-items:center;height:", ";line-height:", ";width:", ";font-size:", ";font-weight:", ";background-color:", ";color:", ";border-radius:", ";padding:0 8px;"], ({
theme
}) => theme.orbit.fontFamily, ({
theme
}) => theme.orbit.heightBadge, ({
theme
}) => theme.orbit.heightBadge, ({
circled,
theme
}) => circled && theme.orbit.widthBadgeCircled, ({
theme
}) => theme.orbit.fontSizeTextSmall, ({
theme
}) => theme.orbit.fontWeightMedium, getTypeToken(TOKENS.background), getTypeToken(TOKENS.color), ({
theme
}) => theme.orbit.borderRadiusBadge);
StyledBadge.defaultProps = {
theme: defaultTokens
};
const IconContainer = styled(({
className,
children
}) => React.createElement("div", {
className: className
}, children)).withConfig({
displayName: "Badge__IconContainer",
componentId: "sc-1y6i8f0-1"
})(["display:flex;margin-right:", ";svg{height:", ";width:", ";color:", ";}"], ({
theme
}) => theme.orbit.marginRightBadgeIcon, ({
theme
}) => theme.orbit.widthIconSmall, ({
theme
}) => theme.orbit.heightIconSmall, getTypeToken(TOKENS.color));
IconContainer.defaultProps = {
theme: defaultTokens
};
const Badge = props => {
const {
type = TYPE_OPTIONS.NEUTRAL,
icon,
children,
circled,
dataTest
} = props;
return React.createElement(StyledBadge, {
type: type,
circled: circled,
dataTest: dataTest
}, icon && React.createElement(IconContainer, {
type: type
}, icon), children);
};
export default Badge;