@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.
97 lines (94 loc) • 3.51 kB
JavaScript
import * as React from "react";
import BadgePrimitive from "../primitives/BadgePrimitive";
import { TYPE_OPTIONS, TOKENS } from "./consts";
import useTheme from "../hooks/useTheme";
const getTypeToken = ({
name,
theme,
type
}) => {
const tokens = {
[]: {
[]: theme.orbit.paletteCloudLight,
[]: theme.orbit.paletteBlueLight,
[]: theme.orbit.paletteGreenLight,
[]: theme.orbit.paletteOrangeLight,
[]: theme.orbit.paletteRedLight,
[]: theme.orbit.paletteInkNormal,
[]: theme.orbit.paletteWhite,
[]: theme.orbit.paletteBlueNormal,
[]: theme.orbit.paletteRedNormal,
[]: theme.orbit.paletteGreenNormal,
[]: theme.orbit.paletteOrangeNormal,
[]: theme.orbit.backgroundBadgeBundleBasic,
[]: theme.orbit.backgroundBadgeBundleMedium,
[]: theme.orbit.backgroundBadgeBundleTop
},
[]: {
[]: theme.orbit.paletteInkNormal,
[]: theme.orbit.paletteBlueDark,
[]: theme.orbit.paletteGreenDark,
[]: theme.orbit.paletteOrangeDark,
[]: theme.orbit.paletteRedDark,
[]: theme.orbit.paletteWhite,
[]: theme.orbit.paletteInkNormal,
[]: theme.orbit.paletteWhite,
[]: theme.orbit.paletteWhite,
[]: theme.orbit.paletteWhite,
[]: theme.orbit.paletteWhite,
[]: theme.orbit.paletteWhite,
[]: theme.orbit.paletteWhite,
[]: theme.orbit.paletteWhite
},
[]: {
[]: theme.orbit.paletteCloudDark,
[]: theme.orbit.paletteBlueLightHover,
[]: theme.orbit.paletteGreenLightHover,
[]: theme.orbit.paletteOrangeLightHover,
[]: theme.orbit.paletteRedLightHover,
[]: null,
[]: theme.orbit.paletteCloudDark,
[]: null,
[]: null,
[]: null,
[]: null,
[]: null,
[]: null,
[]: null
}
};
return tokens[name][type];
};
const Badge = ({
type = TYPE_OPTIONS.NEUTRAL,
border = true,
icon,
children,
ariaLabel,
dataTest,
carriers
}) => {
const theme = useTheme();
return /*#__PURE__*/React.createElement(BadgePrimitive, {
carriers: carriers,
background: getTypeToken({
name: TOKENS.background,
theme,
type
}),
foregroundColor: getTypeToken({
name: TOKENS.color,
theme,
type
}),
borderColor: border ? getTypeToken({
name: TOKENS.border,
theme,
type
}) : "transparent",
icon: icon,
ariaLabel: ariaLabel,
dataTest: dataTest
}, children);
};
export default Badge;