@wordpress/editor
Version:
Enhanced block editor for WordPress posts.
122 lines (120 loc) • 4.63 kB
JavaScript
;
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// packages/editor/src/components/collaborators-presence/avatar/component.tsx
var component_exports = {};
__export(component_exports, {
default: () => component_default
});
module.exports = __toCommonJS(component_exports);
var import_clsx = __toESM(require("clsx"));
var import_colord = require("colord");
var import_a11y = __toESM(require("colord/plugins/a11y"));
var import_components = require("@wordpress/components");
var import_element = require("@wordpress/element");
var import_use_image_loading_status = require("./use-image-loading-status.cjs");
var import_jsx_runtime = require("react/jsx-runtime");
(0, import_colord.extend)([import_a11y.default]);
var GRAY_900 = "#1e1e1e";
var WHITE = "#fff";
function Avatar({
className,
src,
name,
label,
variant,
size = "default",
borderColor,
dimmed = false,
statusIndicator,
style,
...props
}) {
const {
status: imageStatus,
handleLoad,
handleError
} = (0, import_use_image_loading_status.useImageLoadingStatus)(src);
const imageLoaded = imageStatus === "loaded";
const showBadge = variant === "badge" && !!name;
const initials = name ? name.split(/\s+/).slice(0, 2).map((word) => word[0]).join("").toUpperCase() : void 0;
const nameColor = (0, import_element.useMemo)(
() => borderColor && (0, import_colord.colord)(borderColor).isReadable(GRAY_900, {
level: "AA",
size: "normal"
}) ? GRAY_900 : WHITE,
[borderColor]
);
const customProperties = {
...style,
...borderColor ? {
"--editor-avatar-outline-color": borderColor,
"--editor-avatar-name-color": nameColor
} : {}
};
const avatar = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
"div",
{
className: (0, import_clsx.default)("editor-avatar", className, {
"has-avatar-border-color": !!borderColor,
"has-src": imageLoaded,
"is-badge": showBadge,
"is-small": size === "small",
"is-dimmed": dimmed
}),
style: customProperties,
role: name ? "img" : void 0,
"aria-label": name || void 0,
...props,
children: [
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "editor-avatar__image", children: [
src && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
"img",
{
src,
alt: "",
crossOrigin: "anonymous",
className: "editor-avatar__img",
onLoad: handleLoad,
onError: handleError
}
),
!imageLoaded && initials
] }),
dimmed && !!statusIndicator && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "editor-avatar__status-indicator", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Icon, { icon: statusIndicator }) }),
showBadge && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "editor-avatar__name", children: label || name })
]
}
);
if (name && (!showBadge || label)) {
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Tooltip, { text: name, children: avatar });
}
return avatar;
}
var component_default = Avatar;
//# sourceMappingURL=component.cjs.map