UNPKG

@liveblocks/react-ui

Version:

A set of React pre-built components for the Liveblocks products. Liveblocks is the all-in-one toolkit to build collaborative products like Figma, Notion, and more.

47 lines (43 loc) 1.55 kB
"use client"; import { jsxs, jsx } from 'react/jsx-runtime'; import { useUser } from '@liveblocks/react'; import { useMemo } from 'react'; import { classNames } from '../../utils/class-names.js'; import { getInitials } from '../../utils/get-initials.js'; function Avatar({ userId, className, ...props }) { const { user, isLoading } = useUser(userId); const resolvedUserName = useMemo(() => user?.name, [user]); const resolvedUserAvatar = useMemo(() => user?.avatar, [user]); const resolvedUserInitials = useMemo( () => resolvedUserName ? getInitials(resolvedUserName) : void 0, [resolvedUserName] ); const resolvedUserIdInitials = useMemo( () => !isLoading && !user ? getInitials(userId) : void 0, [isLoading, user, userId] ); return /* @__PURE__ */ jsxs("div", { className: classNames("lb-avatar", className), "data-loading": isLoading ? "" : void 0, ...props, children: [ resolvedUserAvatar && /* @__PURE__ */ jsx("img", { className: "lb-avatar-image", src: resolvedUserAvatar, alt: resolvedUserName }), resolvedUserInitials ? /* @__PURE__ */ jsx("span", { className: "lb-avatar-fallback", "aria-hidden": true, children: resolvedUserInitials }) : resolvedUserIdInitials ? /* @__PURE__ */ jsx("span", { className: "lb-avatar-fallback", "aria-label": userId, title: userId, children: resolvedUserIdInitials }) : null ] }); } export { Avatar }; //# sourceMappingURL=Avatar.js.map