@wordpress/components
Version:
UI components for WordPress.
54 lines (53 loc) • 1.58 kB
JavaScript
import clsx from "clsx";
import { caution, error, info, published } from "@wordpress/icons";
import deprecated from "@wordpress/deprecated";
import Icon from "../icon/index.mjs";
import { jsx, jsxs } from "react/jsx-runtime";
// packages/components/src/badge/index.tsx
/**
* Returns an icon based on the badge context.
*
* @return The corresponding icon for the provided context.
*/
function contextBasedIcon(intent = "default") {
switch (intent) {
case "info": return info;
case "success": return published;
case "warning": return caution;
case "error": return error;
default: return null;
}
}
/**
* @deprecated Use `Badge` from `@wordpress/ui` instead.
*/
function Badge({ className, intent = "default", children, ...props }) {
deprecated("wp.components.privateApis.Badge", {
since: "7.2",
alternative: "Badge from @wordpress/ui",
hint: "This private API will be completely removed within a few Gutenberg plugin releases."
});
const icon = contextBasedIcon(intent);
const hasIcon = !!icon;
return /* @__PURE__ */ jsx("span", {
className: clsx("components-badge", className, {
[`is-${intent}`]: intent,
"has-icon": hasIcon
}),
...props,
children: /* @__PURE__ */ jsxs("span", {
className: "components-badge__flex-wrapper",
children: [hasIcon && /* @__PURE__ */ jsx(Icon, {
icon,
size: 16,
fill: "currentColor",
className: "components-badge__icon"
}), /* @__PURE__ */ jsx("span", {
className: "components-badge__content",
children
})]
})
});
}
export { Badge as default };
//# sourceMappingURL=index.mjs.map