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.

1 lines 1.56 kB
{"version":3,"file":"User.cjs","sources":["../../../src/components/internal/User.tsx"],"sourcesContent":["\"use client\";\n\nimport { useUser } from \"@liveblocks/react\";\nimport type { ComponentProps } from \"react\";\nimport { useMemo } from \"react\";\n\nimport { useOverrides } from \"../../overrides\";\nimport { useCurrentUserId } from \"../../shared\";\nimport { cn } from \"../../utils/cn\";\n\nexport interface UserProps extends ComponentProps<\"span\"> {\n /**\n * The user ID to display the user name for.\n */\n userId: string;\n\n /**\n * Whether to replace the user name with \"you\" ($.USER_SELF) for the current user.\n */\n replaceSelf?: boolean;\n}\n\nexport function User({\n userId,\n replaceSelf,\n className,\n children,\n ...props\n}: UserProps) {\n const currentId = useCurrentUserId();\n const { user, isLoading } = useUser(userId);\n const $ = useOverrides();\n const resolvedUserName = useMemo(() => {\n return replaceSelf && currentId === userId\n ? $.USER_SELF\n : (user?.name ?? $.USER_UNKNOWN);\n }, [replaceSelf, currentId, userId, $.USER_SELF, $.USER_UNKNOWN, user?.name]);\n\n return (\n <span\n className={cn(\"lb-name lb-user\", className)}\n data-loading={isLoading ? \"\" : undefined}\n {...props}\n >\n {isLoading ? null : resolvedUserName}\n {children}\n </span>\n );\n}\n"],"names":[],"mappings":";;;;;;;;;;;AAsBO;AAAc;AACnB;AACA;AACA;AACA;AAEF;AACE;AACA;AACA;AACA;AACE;AAEqB;AAGvB;AACE;AAAC;AAAA;AAC2C;AACX;AAC3B;AAEH;AAAmB;AACnB;AAAA;AAAA;AAGP;;"}