UNPKG

@lobehub/ui

Version:

Lobe UI is an open-source UI component library for building AIGC web apps

73 lines (72 loc) • 2.09 kB
"use client"; import { pillSize, statusColor, styles } from "./style.mjs"; import { memo } from "react"; import { jsx, jsxs } from "react/jsx-runtime"; import { cx } from "antd-style"; //#region src/base-ui/Badge/Badge.tsx const Badge = memo(({ children, className, color, count, dot = false, offset, overflowCount = 99, ref, showZero = false, size = "default", status, style, text, ...rest }) => { if (children == null && (status !== void 0 || text !== void 0)) { const dotColor = color ?? statusColor[status ?? "default"]; return /* @__PURE__ */ jsxs("span", { className: cx(styles.statusRoot, className), ref, style, ...rest, children: [/* @__PURE__ */ jsx("span", { className: cx(styles.statusDot, status === "processing" && styles.statusDotProcessing), style: { background: dotColor, color: dotColor } }), text && /* @__PURE__ */ jsx("span", { className: styles.statusText, children: text })] }); } let content = null; let renderPill = dot; if (!dot) { if (typeof count === "number") { if (count !== 0 || showZero) { renderPill = true; content = count > overflowCount ? `${overflowCount}+` : count; } } else if (count != null) { renderPill = true; content = count; } } const pillStyle = { background: color, transform: offset ? `translate(${offset[0]}px, ${offset[1]}px)` : void 0 }; if (children == null) { if (!renderPill) return null; return /* @__PURE__ */ jsx("span", { className: cx(pillSize({ size }), dot && styles.pillDot, className), ref, style: { ...pillStyle, ...style }, ...rest, children: !dot && content }); } return /* @__PURE__ */ jsxs("span", { className: cx(styles.wrapper, className), ref, style, ...rest, children: [children, renderPill && /* @__PURE__ */ jsx("span", { className: cx(pillSize({ size }), styles.pillAbsolute, dot && styles.pillDot), style: pillStyle, children: !dot && content })] }); }); Badge.displayName = "Badge"; //#endregion export { Badge as default }; //# sourceMappingURL=Badge.mjs.map