@spaced-out/ui-design-system
Version:
Sense UI components library
101 lines (100 loc) • 3.74 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.IconBadge = exports.Badge = exports.BADGE_COLOR = void 0;
var React = _interopRequireWildcard(require("react"));
var _color = require("../../styles/variables/_color");
var _classify = _interopRequireDefault(require("../../utils/classify"));
var _qa = require("../../utils/qa");
var _Icon = require("../Icon");
var _Text = require("../Text");
var _BadgeModule = _interopRequireDefault(require("./Badge.module.css"));
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
const BADGE_COLOR = exports.BADGE_COLOR = Object.freeze({
gray: _color.colorGrayLightest,
red: _color.colorDangerLightest,
redDark: _color.colorDanger,
orange: _color.colorWarningLightest,
orangeDark: _color.colorWarning,
green: _color.colorSuccessLightest,
greenDark: _color.colorSuccess,
blue: _color.colorInformationLightest,
blueDark: _color.colorInformation,
indigo: _color.colorNeutralLightest,
indigoDark: _color.colorNeutral
});
const Badge = exports.Badge = /*#__PURE__*/React.forwardRef((_ref, ref) => {
let {
classNames,
text,
fill = 'gray',
testId
} = _ref;
const isDark = fill.includes('Dark');
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
"data-testid": (0, _qa.generateTestId)({
base: testId,
slot: 'root'
}),
style: {
'--wrapperBgColor': BADGE_COLOR[fill]
},
className: (0, _classify.default)(_BadgeModule.default.badgeWrapper, {
[_BadgeModule.default.fixedWidth]: text.length <= 2
}, classNames?.wrapper),
ref: ref,
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Text.ButtonTextSmall, {
className: (0, _classify.default)({
[_BadgeModule.default.dark]: isDark,
[_BadgeModule.default.light]: !isDark
}, classNames?.text),
testId: (0, _qa.generateTestId)({
base: testId,
slot: 'text'
}),
children: text
})
});
});
const IconBadge = exports.IconBadge = /*#__PURE__*/React.forwardRef((_ref2, ref) => {
let {
classNames,
fill = 'gray',
iconName,
iconSize = 'small',
iconType = 'solid',
ariaLabel,
onClick,
testId
} = _ref2;
const isDark = fill.includes('Dark');
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
"data-testid": (0, _qa.generateTestId)({
base: testId,
slot: 'root'
}),
style: {
'--wrapperBgColor': BADGE_COLOR[fill]
},
className: (0, _classify.default)(_BadgeModule.default.badgeWrapper, _BadgeModule.default.iconContainer, classNames?.wrapper),
ref: ref,
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Icon.Icon, {
name: iconName,
type: iconType,
size: iconSize,
ariaLabel: ariaLabel,
onClick: onClick,
className: (0, _classify.default)({
[_BadgeModule.default.dark]: isDark,
[_BadgeModule.default.light]: !isDark
}, classNames?.icon),
testId: (0, _qa.generateTestId)({
base: testId,
slot: 'icon'
})
})
});
});