@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.
63 lines (51 loc) • 5.6 kB
JavaScript
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var React = _interopRequireWildcard(require("react"));
var _BadgePrimitive = _interopRequireDefault(require("../primitives/BadgePrimitive"));
var _consts = require("./consts");
var _useTheme = _interopRequireDefault(require("../hooks/useTheme"));
var getTypeToken = function getTypeToken(_ref) {
var _TOKENS$background, _TOKENS$color, _TOKENS$border, _tokens;
var name = _ref.name,
theme = _ref.theme,
type = _ref.type;
var tokens = (_tokens = {}, (0, _defineProperty2.default)(_tokens, _consts.TOKENS.background, (_TOKENS$background = {}, (0, _defineProperty2.default)(_TOKENS$background, _consts.TYPE_OPTIONS.NEUTRAL, theme.orbit.paletteCloudLight), (0, _defineProperty2.default)(_TOKENS$background, _consts.TYPE_OPTIONS.INFO, theme.orbit.paletteBlueLight), (0, _defineProperty2.default)(_TOKENS$background, _consts.TYPE_OPTIONS.SUCCESS, theme.orbit.paletteGreenLight), (0, _defineProperty2.default)(_TOKENS$background, _consts.TYPE_OPTIONS.WARNING, theme.orbit.paletteOrangeLight), (0, _defineProperty2.default)(_TOKENS$background, _consts.TYPE_OPTIONS.CRITICAL, theme.orbit.paletteRedLight), (0, _defineProperty2.default)(_TOKENS$background, _consts.TYPE_OPTIONS.DARK, theme.orbit.paletteInkNormal), (0, _defineProperty2.default)(_TOKENS$background, _consts.TYPE_OPTIONS.WHITE, theme.orbit.paletteWhite), (0, _defineProperty2.default)(_TOKENS$background, _consts.TYPE_OPTIONS.INFO_INVERTED, theme.orbit.paletteBlueNormal), (0, _defineProperty2.default)(_TOKENS$background, _consts.TYPE_OPTIONS.CRITICAL_INVERTED, theme.orbit.paletteRedNormal), (0, _defineProperty2.default)(_TOKENS$background, _consts.TYPE_OPTIONS.SUCCESS_INVERTED, theme.orbit.paletteGreenNormal), (0, _defineProperty2.default)(_TOKENS$background, _consts.TYPE_OPTIONS.WARNING_INVERTED, theme.orbit.paletteOrangeNormal), _TOKENS$background)), (0, _defineProperty2.default)(_tokens, _consts.TOKENS.color, (_TOKENS$color = {}, (0, _defineProperty2.default)(_TOKENS$color, _consts.TYPE_OPTIONS.NEUTRAL, theme.orbit.paletteInkNormal), (0, _defineProperty2.default)(_TOKENS$color, _consts.TYPE_OPTIONS.INFO, theme.orbit.paletteBlueDark), (0, _defineProperty2.default)(_TOKENS$color, _consts.TYPE_OPTIONS.SUCCESS, theme.orbit.paletteGreenDark), (0, _defineProperty2.default)(_TOKENS$color, _consts.TYPE_OPTIONS.WARNING, theme.orbit.paletteOrangeDark), (0, _defineProperty2.default)(_TOKENS$color, _consts.TYPE_OPTIONS.CRITICAL, theme.orbit.paletteRedDark), (0, _defineProperty2.default)(_TOKENS$color, _consts.TYPE_OPTIONS.DARK, theme.orbit.paletteWhite), (0, _defineProperty2.default)(_TOKENS$color, _consts.TYPE_OPTIONS.WHITE, theme.orbit.paletteInkNormal), (0, _defineProperty2.default)(_TOKENS$color, _consts.TYPE_OPTIONS.INFO_INVERTED, theme.orbit.paletteWhite), (0, _defineProperty2.default)(_TOKENS$color, _consts.TYPE_OPTIONS.CRITICAL_INVERTED, theme.orbit.paletteWhite), (0, _defineProperty2.default)(_TOKENS$color, _consts.TYPE_OPTIONS.SUCCESS_INVERTED, theme.orbit.paletteWhite), (0, _defineProperty2.default)(_TOKENS$color, _consts.TYPE_OPTIONS.WARNING_INVERTED, theme.orbit.paletteWhite), _TOKENS$color)), (0, _defineProperty2.default)(_tokens, _consts.TOKENS.border, (_TOKENS$border = {}, (0, _defineProperty2.default)(_TOKENS$border, _consts.TYPE_OPTIONS.NEUTRAL, theme.orbit.paletteCloudDark), (0, _defineProperty2.default)(_TOKENS$border, _consts.TYPE_OPTIONS.INFO, theme.orbit.paletteBlueLightHover), (0, _defineProperty2.default)(_TOKENS$border, _consts.TYPE_OPTIONS.SUCCESS, theme.orbit.paletteGreenLightHover), (0, _defineProperty2.default)(_TOKENS$border, _consts.TYPE_OPTIONS.WARNING, theme.orbit.paletteOrangeLightHover), (0, _defineProperty2.default)(_TOKENS$border, _consts.TYPE_OPTIONS.CRITICAL, theme.orbit.paletteRedLightHover), (0, _defineProperty2.default)(_TOKENS$border, _consts.TYPE_OPTIONS.DARK, null), (0, _defineProperty2.default)(_TOKENS$border, _consts.TYPE_OPTIONS.WHITE, theme.orbit.paletteCloudDark), (0, _defineProperty2.default)(_TOKENS$border, _consts.TYPE_OPTIONS.INFO_INVERTED, null), (0, _defineProperty2.default)(_TOKENS$border, _consts.TYPE_OPTIONS.CRITICAL_INVERTED, null), (0, _defineProperty2.default)(_TOKENS$border, _consts.TYPE_OPTIONS.SUCCESS_INVERTED, null), (0, _defineProperty2.default)(_TOKENS$border, _consts.TYPE_OPTIONS.WARNING_INVERTED, null), _TOKENS$border)), _tokens);
return tokens[name][type];
};
var Badge = function Badge(props) {
var theme = (0, _useTheme.default)();
var _props$type = props.type,
type = _props$type === void 0 ? _consts.TYPE_OPTIONS.NEUTRAL : _props$type,
icon = props.icon,
children = props.children,
ariaLabel = props.ariaLabel,
dataTest = props.dataTest;
return /*#__PURE__*/React.createElement(_BadgePrimitive.default, {
background: getTypeToken({
name: _consts.TOKENS.background,
theme: theme,
type: type
}),
foregroundColor: getTypeToken({
name: _consts.TOKENS.color,
theme: theme,
type: type
}),
borderColor: getTypeToken({
name: _consts.TOKENS.border,
theme: theme,
type: type
}),
icon: icon,
ariaLabel: ariaLabel,
dataTest: dataTest
}, children);
};
var _default = Badge;
exports.default = _default;