UNPKG

@braineet/ui

Version:

Braineet design system

84 lines (80 loc) 3.22 kB
var _excluded = ["as", "color", "isSolid", "size", "children", "ellipsis", "onClickIcon", "iconBefore", "iconAfter"]; function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } import React from 'react'; import { useTheme } from 'styled-components'; import Box from '../box'; import Icon from '../icon'; import styles, { StyledBadge, StyledText } from './styles'; /** The `Badge` component. */ import { jsx as _jsx } from "react/jsx-runtime"; import { jsxs as _jsxs } from "react/jsx-runtime"; var Badge = /*#__PURE__*/React.forwardRef(function (_ref, ref) { var as = _ref.as, color = _ref.color, isSolid = _ref.isSolid, size = _ref.size, children = _ref.children, ellipsis = _ref.ellipsis, onClickIcon = _ref.onClickIcon, iconBefore = _ref.iconBefore, iconAfter = _ref.iconAfter, restProps = _objectWithoutPropertiesLoose(_ref, _excluded); var theme = useTheme(); // Define if badge is solid or subtle var appearance = isSolid ? 'solid' : 'subtle'; // Get text color and background color of badge var _theme$helpers$getFil = theme.helpers.getFills({ appearance: appearance, color: color }), textColor = _theme$helpers$getFil.color, backgroundColor = _theme$helpers$getFil.backgroundColor; // Define the badge size var globalSize = ['small', 'big'].includes(size) ? size : 'big'; return /*#__PURE__*/_jsxs(StyledBadge, _extends({ forwardedAs: as, ref: ref, textColor: textColor, backgroundColor: backgroundColor, isSolid: isSolid, size: globalSize, reverse: iconAfter !== null }, restProps, { children: [(iconBefore || iconAfter) && /*#__PURE__*/_jsx(Box, { onClick: onClickIcon, cursor: onClickIcon ? 'pointer' : null, flexShrink: "0", width: styles.sizes[globalSize].icon, height: styles.sizes[globalSize].icon, children: /*#__PURE__*/_jsx(Icon, { color: textColor, name: iconBefore || iconAfter, size: styles.sizes[globalSize].icon }) }), /*#__PURE__*/_jsx(StyledText, { fontFamily: "display", color: textColor, ellipsis: ellipsis, margin: globalSize === 'small' ? "0 " + theme.spaces.sm : theme.spaces.xs + " " + theme.spaces.md, fontWeight: 700, size: styles.sizes[globalSize].text, lineHeight: styles.sizes[globalSize].lineHeight, children: children })] })); }); Badge.defaultProps = { children: '', iconBefore: null, iconAfter: null, isSolid: false, color: 'black', size: 'big', ellipsis: false, onClickIcon: null }; Badge.displayName = 'Badge'; export default Badge;