@wordpress/editor
Version:
Enhanced block editor for WordPress posts.
90 lines (89 loc) • 3.6 kB
JavaScript
// packages/editor/src/components/collaborators-presence/list.tsx
import { __ } from "@wordpress/i18n";
import { Popover, Button } from "@wordpress/components";
import { closeSmall } from "@wordpress/icons";
import { speak } from "@wordpress/a11y";
import Avatar from "./avatar/index.mjs";
import { getAvatarUrl } from "../collaborators-overlay/get-avatar-url.mjs";
import { getAvatarBorderColor } from "../collab-sidebar/utils.mjs";
import { jsx, jsxs } from "react/jsx-runtime";
function CollaboratorsList({
activeCollaborators,
popoverAnchor,
setIsPopoverVisible,
cursorRegistry
}) {
const handleCollaboratorClick = (clientId) => {
const success = cursorRegistry.scrollToCursor(clientId, {
behavior: "smooth",
block: "center",
highlightDuration: 2e3
});
if (success) {
speak(__("Scrolled to cursor"), "polite");
setIsPopoverVisible(false);
}
};
return /* @__PURE__ */ jsx(
Popover,
{
anchor: popoverAnchor,
placement: "bottom",
offset: 8,
className: "editor-collaborators-presence__list",
onClose: () => setIsPopoverVisible(false),
children: /* @__PURE__ */ jsxs("div", { className: "editor-collaborators-presence__list-content", children: [
/* @__PURE__ */ jsxs("div", { className: "editor-collaborators-presence__list-header", children: [
/* @__PURE__ */ jsxs("div", { className: "editor-collaborators-presence__list-header-title", children: [
__("Collaborators"),
/* @__PURE__ */ jsx("span", { children: activeCollaborators.length })
] }),
/* @__PURE__ */ jsx("div", { className: "editor-collaborators-presence__list-header-action", children: /* @__PURE__ */ jsx(
Button,
{
__next40pxDefaultSize: true,
icon: closeSmall,
iconSize: 24,
label: __("Close Collaborators List"),
onClick: () => setIsPopoverVisible(false)
}
) })
] }),
/* @__PURE__ */ jsx("div", { className: "editor-collaborators-presence__list-items", children: activeCollaborators.map((collaboratorState) => {
const isCurrentUser = collaboratorState.isMe;
return /* @__PURE__ */ jsxs(
"button",
{
className: "editor-collaborators-presence__list-item",
disabled: isCurrentUser,
onClick: () => handleCollaboratorClick(
collaboratorState.clientId
),
children: [
/* @__PURE__ */ jsx(
Avatar,
{
src: getAvatarUrl(
collaboratorState.collaboratorInfo.avatar_urls
),
name: collaboratorState.collaboratorInfo.name,
borderColor: isCurrentUser ? "var(--wp-admin-theme-color)" : getAvatarBorderColor(
collaboratorState.collaboratorInfo.id
),
dimmed: !collaboratorState.isConnected
}
),
/* @__PURE__ */ jsx("div", { className: "editor-collaborators-presence__list-item-info", children: /* @__PURE__ */ jsx("div", { className: "editor-collaborators-presence__list-item-name", children: isCurrentUser ? __("You") : collaboratorState.collaboratorInfo.name }) })
]
},
collaboratorState.clientId
);
}) })
] })
}
);
}
export {
CollaboratorsList
};
//# sourceMappingURL=list.mjs.map