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.

80 lines (79 loc) 3.18 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default; exports.__esModule = true; exports.default = void 0; var _react = _interopRequireDefault(require("react")); var _BadgePrimitive = _interopRequireDefault(require("../primitives/BadgePrimitive")); var _consts = require("./consts"); var _useTheme = _interopRequireDefault(require("../hooks/useTheme")); const getTypeToken = ({ name, theme, type }) => { const tokens = { [_consts.TOKENS.background]: { [_consts.TYPE_OPTIONS.NEUTRAL]: theme.orbit.paletteCloudLight, [_consts.TYPE_OPTIONS.INFO_SUBTLE]: theme.orbit.paletteBlueLight, [_consts.TYPE_OPTIONS.SUCCESS_SUBTLE]: theme.orbit.paletteGreenLight, [_consts.TYPE_OPTIONS.WARNING_SUBTLE]: theme.orbit.paletteOrangeLight, [_consts.TYPE_OPTIONS.CRITICAL_SUBTLE]: theme.orbit.paletteRedLight, [_consts.TYPE_OPTIONS.DARK]: theme.orbit.paletteInkDark, [_consts.TYPE_OPTIONS.WHITE]: theme.orbit.paletteWhite, [_consts.TYPE_OPTIONS.INFO]: theme.orbit.paletteBlueNormal, [_consts.TYPE_OPTIONS.CRITICAL]: theme.orbit.paletteRedNormal, [_consts.TYPE_OPTIONS.SUCCESS]: theme.orbit.paletteGreenNormal, [_consts.TYPE_OPTIONS.WARNING]: theme.orbit.paletteOrangeNormal, [_consts.TYPE_OPTIONS.BUNDLE_BASIC]: theme.orbit.backgroundBadgeBundleBasic, [_consts.TYPE_OPTIONS.BUNDLE_MEDIUM]: theme.orbit.backgroundBadgeBundleMedium, [_consts.TYPE_OPTIONS.BUNDLE_TOP]: theme.orbit.backgroundBadgeBundleTop }, [_consts.TOKENS.color]: { [_consts.TYPE_OPTIONS.NEUTRAL]: theme.orbit.paletteInkDark, [_consts.TYPE_OPTIONS.INFO_SUBTLE]: theme.orbit.paletteBlueDark, [_consts.TYPE_OPTIONS.SUCCESS_SUBTLE]: theme.orbit.paletteGreenDark, [_consts.TYPE_OPTIONS.WARNING_SUBTLE]: theme.orbit.paletteOrangeDark, [_consts.TYPE_OPTIONS.CRITICAL_SUBTLE]: theme.orbit.paletteRedDark, [_consts.TYPE_OPTIONS.DARK]: theme.orbit.paletteWhite, [_consts.TYPE_OPTIONS.WHITE]: theme.orbit.paletteInkDark, [_consts.TYPE_OPTIONS.INFO]: theme.orbit.paletteWhite, [_consts.TYPE_OPTIONS.CRITICAL]: theme.orbit.paletteWhite, [_consts.TYPE_OPTIONS.SUCCESS]: theme.orbit.paletteWhite, [_consts.TYPE_OPTIONS.WARNING]: theme.orbit.paletteWhite, [_consts.TYPE_OPTIONS.BUNDLE_BASIC]: theme.orbit.paletteWhite, [_consts.TYPE_OPTIONS.BUNDLE_MEDIUM]: theme.orbit.paletteWhite, [_consts.TYPE_OPTIONS.BUNDLE_TOP]: theme.orbit.paletteWhite } }; return tokens[name][type]; }; const Badge = ({ type = _consts.TYPE_OPTIONS.NEUTRAL, icon, children, ariaLabel, dataTest, id, carriers }) => { const theme = (0, _useTheme.default)(); return /*#__PURE__*/_react.default.createElement(_BadgePrimitive.default, { carriers: carriers, background: getTypeToken({ name: _consts.TOKENS.background, theme, type }), foregroundColor: getTypeToken({ name: _consts.TOKENS.color, theme, type }), icon: icon, id: id, ariaLabel: ariaLabel, dataTest: dataTest }, children); }; var _default = Badge; exports.default = _default;