@open-elements/ui 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/README.md +1 -0
  2. package/dist/components/markdown-editor.d.ts +3 -0
  3. package/dist/components/markdown-editor.d.ts.map +1 -0
  4. package/dist/components/markdown-editor.js +77 -0
  5. package/dist/components/markdown-editor.js.map +1 -0
  6. package/dist/components/markdown-view.d.ts +3 -0
  7. package/dist/components/markdown-view.d.ts.map +1 -0
  8. package/dist/components/markdown-view.js +46 -0
  9. package/dist/components/markdown-view.js.map +1 -0
  10. package/dist/components/user-avatar.d.ts +3 -0
  11. package/dist/components/user-avatar.d.ts.map +1 -0
  12. package/dist/components/user-avatar.js +38 -0
  13. package/dist/components/user-avatar.js.map +1 -0
  14. package/dist/components/user-multi-select.d.ts +3 -0
  15. package/dist/components/user-multi-select.d.ts.map +1 -0
  16. package/dist/components/user-multi-select.js +46 -0
  17. package/dist/components/user-multi-select.js.map +1 -0
  18. package/dist/index.d.ts +5 -0
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +6 -0
  21. package/dist/index.js.map +1 -1
  22. package/dist/tsconfig.build.tsbuildinfo +1 -1
  23. package/dist/types/index.d.ts +30 -0
  24. package/dist/types/index.d.ts.map +1 -1
  25. package/package.json +15 -3
  26. package/src/components/__tests__/markdown-editor.test.tsx +35 -0
  27. package/src/components/__tests__/markdown-view.test.tsx +32 -0
  28. package/src/components/__tests__/user-avatar.test.tsx +68 -0
  29. package/src/components/__tests__/user-multi-select.test.tsx +97 -0
  30. package/src/components/markdown-editor.tsx +143 -0
  31. package/src/components/markdown-view.tsx +49 -0
  32. package/src/components/user-avatar.tsx +60 -0
  33. package/src/components/user-multi-select.tsx +134 -0
  34. package/src/index.ts +16 -0
  35. package/src/types/index.ts +36 -0
@@ -24,4 +24,34 @@ export interface TagMultiSelectProps {
24
24
  readonly loadTags: () => Promise<TagOption[]>;
25
25
  readonly translations: TagMultiSelectTranslations;
26
26
  }
27
+ export interface UserOption {
28
+ readonly id: string;
29
+ readonly name: string;
30
+ readonly email: string;
31
+ readonly avatarUrl?: string | null;
32
+ }
33
+ export interface UserAvatarProps {
34
+ readonly user: UserOption;
35
+ readonly size?: "sm" | "md";
36
+ }
37
+ export interface UserMultiSelectTranslations {
38
+ readonly placeholder: string;
39
+ readonly searchPlaceholder: string;
40
+ readonly empty: string;
41
+ }
42
+ export interface UserMultiSelectProps {
43
+ readonly users: readonly UserOption[];
44
+ readonly selectedIds: readonly string[];
45
+ readonly onChange: (ids: string[]) => void;
46
+ readonly disabledIds?: readonly string[];
47
+ readonly translations: UserMultiSelectTranslations;
48
+ }
49
+ export interface MarkdownEditorProps {
50
+ readonly value: string;
51
+ readonly onChange: (value: string) => void;
52
+ readonly placeholder?: string;
53
+ }
54
+ export interface MarkdownViewProps {
55
+ readonly content: string;
56
+ }
27
57
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,MAAM;IACrB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IACrC,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IACrC,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CACnC;AAED,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ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WAAW,mBAAmB;IAClC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3C,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-elements/ui",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Shared UI component library for Open Elements applications",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -35,7 +35,13 @@
35
35
  "clsx": "^2.1.0",
36
36
  "tailwind-merge": "^3.0.0",
37
37
  "react-day-picker": "^9.14.0",
38
- "date-fns": "^4.1.0"
38
+ "date-fns": "^4.1.0",
39
+ "@tiptap/core": "^3.22.0",
40
+ "@tiptap/react": "^3.22.0",
41
+ "@tiptap/starter-kit": "^3.22.0",
42
+ "@tiptap/extension-link": "^3.22.0",
43
+ "@tiptap/extension-placeholder": "^3.22.0",
44
+ "tiptap-markdown": "^0.9.0"
39
45
  },
40
46
  "devDependencies": {
41
47
  "@types/react": "^19.0.0",
@@ -59,7 +65,13 @@
59
65
  "clsx": "^2.1.0",
60
66
  "tailwind-merge": "^3.0.0",
61
67
  "react-day-picker": "^9.14.0",
62
- "date-fns": "^4.1.0"
68
+ "date-fns": "^4.1.0",
69
+ "@tiptap/core": "^3.22.0",
70
+ "@tiptap/react": "^3.22.0",
71
+ "@tiptap/starter-kit": "^3.22.0",
72
+ "@tiptap/extension-link": "^3.22.0",
73
+ "@tiptap/extension-placeholder": "^3.22.0",
74
+ "tiptap-markdown": "^0.9.0"
63
75
  },
64
76
  "scripts": {
65
77
  "build": "tsc -p tsconfig.build.json && pnpm run build:css",
@@ -0,0 +1,35 @@
1
+ import { describe, it, expect, vi, afterEach } from "vitest";
2
+ import { render, cleanup } from "@testing-library/react";
3
+
4
+ // Mock TipTap before importing the component
5
+ vi.mock("@tiptap/react", () => ({
6
+ useEditor: () => null,
7
+ EditorContent: () => <div data-testid="editor-content" />,
8
+ }));
9
+ vi.mock("@tiptap/starter-kit", () => ({ default: { configure: () => ({}) } }));
10
+ vi.mock("@tiptap/extension-link", () => ({ default: { configure: () => ({}) } }));
11
+ vi.mock("@tiptap/extension-placeholder", () => ({ default: { configure: () => ({}) } }));
12
+ vi.mock("tiptap-markdown", () => ({ Markdown: {} }));
13
+
14
+ import { MarkdownEditor } from "../markdown-editor.tsx";
15
+
16
+ afterEach(cleanup);
17
+
18
+ describe("MarkdownEditor", () => {
19
+ it("mounts without error", () => {
20
+ const { container } = render(<MarkdownEditor value="" onChange={() => {}} />);
21
+ expect(container).toBeTruthy();
22
+ });
23
+
24
+ it("renders editor content area", () => {
25
+ const { container } = render(<MarkdownEditor value="" onChange={() => {}} />);
26
+ expect(container.querySelector("[data-testid='editor-content']")).toBeTruthy();
27
+ });
28
+
29
+ it("accepts placeholder prop without error", () => {
30
+ const { container } = render(
31
+ <MarkdownEditor value="" onChange={() => {}} placeholder="Type here..." />,
32
+ );
33
+ expect(container).toBeTruthy();
34
+ });
35
+ });
@@ -0,0 +1,32 @@
1
+ import { describe, it, expect, vi, afterEach } from "vitest";
2
+ import { render, cleanup } from "@testing-library/react";
3
+
4
+ // Mock TipTap before importing the component
5
+ vi.mock("@tiptap/react", () => ({
6
+ useEditor: () => null,
7
+ EditorContent: () => <div data-testid="editor-content" />,
8
+ }));
9
+ vi.mock("@tiptap/starter-kit", () => ({ default: { configure: () => ({}) } }));
10
+ vi.mock("@tiptap/extension-link", () => ({ default: { configure: () => ({}) } }));
11
+ vi.mock("tiptap-markdown", () => ({ Markdown: {} }));
12
+
13
+ import { MarkdownView } from "../markdown-view.tsx";
14
+
15
+ afterEach(cleanup);
16
+
17
+ describe("MarkdownView", () => {
18
+ it("mounts without error", () => {
19
+ const { container } = render(<MarkdownView content="" />);
20
+ expect(container).toBeTruthy();
21
+ });
22
+
23
+ it("renders editor content area", () => {
24
+ const { container } = render(<MarkdownView content="Hello world" />);
25
+ expect(container.querySelector("[data-testid='editor-content']")).toBeTruthy();
26
+ });
27
+
28
+ it("accepts markdown content without error", () => {
29
+ const { container } = render(<MarkdownView content="Hello **bold** and *italic*" />);
30
+ expect(container).toBeTruthy();
31
+ });
32
+ });
@@ -0,0 +1,68 @@
1
+ import { describe, it, expect, afterEach } from "vitest";
2
+ import { render, cleanup } from "@testing-library/react";
3
+ import { UserAvatar } from "../user-avatar.tsx";
4
+ import type { UserOption } from "../../types/index.ts";
5
+
6
+ afterEach(cleanup);
7
+
8
+ const userWithAvatar: UserOption = {
9
+ id: "user-1",
10
+ name: "Hendrik Ebbers",
11
+ email: "hendrik@example.com",
12
+ avatarUrl: "https://example.com/avatar.jpg",
13
+ };
14
+
15
+ const userWithoutAvatar: UserOption = {
16
+ id: "user-2",
17
+ name: "Hendrik Ebbers",
18
+ email: "hendrik@example.com",
19
+ };
20
+
21
+ const singleNameUser: UserOption = {
22
+ id: "user-3",
23
+ name: "Admin",
24
+ email: "admin@example.com",
25
+ };
26
+
27
+ describe("UserAvatar", () => {
28
+ it("renders initials when no avatar URL", () => {
29
+ const { container } = render(<UserAvatar user={userWithoutAvatar} />);
30
+ expect(container.querySelector("span")?.textContent).toBe("HE");
31
+ });
32
+
33
+ it("renders single initial for single-name user", () => {
34
+ const { container } = render(<UserAvatar user={singleNameUser} />);
35
+ expect(container.querySelector("span")?.textContent).toBe("A");
36
+ });
37
+
38
+ it("renders avatar image when URL is provided", () => {
39
+ const { container } = render(<UserAvatar user={userWithAvatar} />);
40
+ const img = container.querySelector("img");
41
+ expect(img).not.toBeNull();
42
+ expect(img?.getAttribute("src")).toBe("https://example.com/avatar.jpg");
43
+ expect(img?.getAttribute("alt")).toBe("Hendrik Ebbers");
44
+ });
45
+
46
+ it("renders small size by default", () => {
47
+ const { container } = render(<UserAvatar user={userWithoutAvatar} size="sm" />);
48
+ const el = container.querySelector("span");
49
+ expect(el?.className).toContain("h-6");
50
+ expect(el?.className).toContain("w-6");
51
+ });
52
+
53
+ it("renders medium size when specified", () => {
54
+ const { container } = render(<UserAvatar user={userWithoutAvatar} size="md" />);
55
+ const el = container.querySelector("span");
56
+ expect(el?.className).toContain("h-8");
57
+ expect(el?.className).toContain("w-8");
58
+ });
59
+
60
+ it("assigns deterministic color based on user id", () => {
61
+ const { container: c1 } = render(<UserAvatar user={userWithoutAvatar} />);
62
+ const class1 = c1.querySelector("span")?.className;
63
+ cleanup();
64
+ const { container: c2 } = render(<UserAvatar user={userWithoutAvatar} />);
65
+ const class2 = c2.querySelector("span")?.className;
66
+ expect(class1).toBe(class2);
67
+ });
68
+ });
@@ -0,0 +1,97 @@
1
+ import { describe, it, expect, vi } from "vitest";
2
+ import { render } from "@testing-library/react";
3
+ import { UserMultiSelect } from "../user-multi-select.tsx";
4
+ import type { UserOption, UserMultiSelectTranslations } from "../../types/index.ts";
5
+
6
+ const mockTranslations: UserMultiSelectTranslations = {
7
+ placeholder: "Select members...",
8
+ searchPlaceholder: "Search...",
9
+ empty: "No users found",
10
+ };
11
+
12
+ const mockUsers: UserOption[] = [
13
+ { id: "1", name: "Alice Adams", email: "alice@example.com" },
14
+ { id: "2", name: "Bob Baker", email: "bob@example.com" },
15
+ { id: "3", name: "Charlie Clark", email: "charlie@example.com" },
16
+ ];
17
+
18
+ describe("UserMultiSelect", () => {
19
+ it("renders with empty user list showing placeholder", () => {
20
+ const { getByText } = render(
21
+ <UserMultiSelect
22
+ users={[]}
23
+ selectedIds={[]}
24
+ onChange={() => {}}
25
+ translations={mockTranslations}
26
+ />,
27
+ );
28
+
29
+ expect(getByText("Select members...")).toBeInTheDocument();
30
+ });
31
+
32
+ it("shows selected user chips", () => {
33
+ const { getAllByText } = render(
34
+ <UserMultiSelect
35
+ users={mockUsers}
36
+ selectedIds={["1", "2"]}
37
+ onChange={() => {}}
38
+ translations={mockTranslations}
39
+ />,
40
+ );
41
+
42
+ expect(getAllByText("Alice Adams").length).toBeGreaterThanOrEqual(1);
43
+ expect(getAllByText("Bob Baker").length).toBeGreaterThanOrEqual(1);
44
+ });
45
+
46
+ it("does not show remove button for disabled users in chips", () => {
47
+ const { container } = render(
48
+ <UserMultiSelect
49
+ users={mockUsers}
50
+ selectedIds={["1"]}
51
+ onChange={() => {}}
52
+ disabledIds={["1"]}
53
+ translations={mockTranslations}
54
+ />,
55
+ );
56
+
57
+ // The trigger button contains chips; disabled user chips should not have a role="button" remove element
58
+ const trigger = container.querySelector("[data-slot='popover-trigger']");
59
+ const removeBtn = trigger?.querySelector("[role='button']");
60
+ expect(removeBtn).toBeNull();
61
+ });
62
+
63
+ it("uses placeholder from translations", () => {
64
+ const deTranslations: UserMultiSelectTranslations = {
65
+ placeholder: "Mitglieder auswählen...",
66
+ searchPlaceholder: "Suchen...",
67
+ empty: "Keine Benutzer gefunden",
68
+ };
69
+
70
+ const { getByText } = render(
71
+ <UserMultiSelect
72
+ users={[]}
73
+ selectedIds={[]}
74
+ onChange={() => {}}
75
+ translations={deTranslations}
76
+ />,
77
+ );
78
+
79
+ expect(getByText("Mitglieder auswählen...")).toBeInTheDocument();
80
+ });
81
+
82
+ it("calls onChange is provided as callback prop", () => {
83
+ const onChange = vi.fn();
84
+
85
+ const { container } = render(
86
+ <UserMultiSelect
87
+ users={mockUsers}
88
+ selectedIds={["1"]}
89
+ onChange={onChange}
90
+ translations={mockTranslations}
91
+ />,
92
+ );
93
+
94
+ // Verify component renders with the callback without crashing
95
+ expect(container).toBeTruthy();
96
+ });
97
+ });
@@ -0,0 +1,143 @@
1
+ "use client";
2
+
3
+ import { useEditor, EditorContent, type Editor } from "@tiptap/react";
4
+ import StarterKit from "@tiptap/starter-kit";
5
+ import Link from "@tiptap/extension-link";
6
+ import Placeholder from "@tiptap/extension-placeholder";
7
+ import { Markdown } from "tiptap-markdown";
8
+ import { Bold, Italic, Strikethrough, Link as LinkIcon, Unlink } from "lucide-react";
9
+ import { useEffect, useCallback } from "react";
10
+ import { cn } from "../lib/utils.ts";
11
+ import type { MarkdownEditorProps } from "../types/index.ts";
12
+
13
+ function ToolbarButton({
14
+ active,
15
+ disabled,
16
+ onClick,
17
+ children,
18
+ title,
19
+ }: {
20
+ readonly active?: boolean;
21
+ readonly disabled?: boolean;
22
+ readonly onClick: () => void;
23
+ readonly children: React.ReactNode;
24
+ readonly title: string;
25
+ }) {
26
+ return (
27
+ <button
28
+ type="button"
29
+ title={title}
30
+ disabled={disabled}
31
+ onClick={onClick}
32
+ className={cn(
33
+ "rounded p-1.5 transition-colors",
34
+ active
35
+ ? "bg-oe-dark/10 text-oe-dark"
36
+ : "text-muted-foreground hover:bg-muted hover:text-foreground",
37
+ disabled && "cursor-not-allowed opacity-40",
38
+ )}
39
+ >
40
+ {children}
41
+ </button>
42
+ );
43
+ }
44
+
45
+ function Toolbar({ editor }: { readonly editor: Editor | null }) {
46
+ const setLink = useCallback(() => {
47
+ if (!editor) return;
48
+ const previousUrl = editor.getAttributes("link").href ?? "";
49
+ const url = window.prompt("URL", previousUrl);
50
+ if (url === null) return;
51
+ if (url === "") {
52
+ editor.chain().focus().extendMarkRange("link").unsetLink().run();
53
+ return;
54
+ }
55
+ editor.chain().focus().extendMarkRange("link").setLink({ href: url }).run();
56
+ }, [editor]);
57
+
58
+ if (!editor) return null;
59
+
60
+ return (
61
+ <div className="flex items-center gap-0.5 border-b px-2 py-1.5">
62
+ <ToolbarButton
63
+ title="Bold"
64
+ active={editor.isActive("bold")}
65
+ onClick={() => editor.chain().focus().toggleBold().run()}
66
+ >
67
+ <Bold className="h-4 w-4" />
68
+ </ToolbarButton>
69
+ <ToolbarButton
70
+ title="Italic"
71
+ active={editor.isActive("italic")}
72
+ onClick={() => editor.chain().focus().toggleItalic().run()}
73
+ >
74
+ <Italic className="h-4 w-4" />
75
+ </ToolbarButton>
76
+ <ToolbarButton
77
+ title="Strikethrough"
78
+ active={editor.isActive("strike")}
79
+ onClick={() => editor.chain().focus().toggleStrike().run()}
80
+ >
81
+ <Strikethrough className="h-4 w-4" />
82
+ </ToolbarButton>
83
+ <div className="bg-border mx-1 h-5 w-px" />
84
+ <ToolbarButton title="Link" active={editor.isActive("link")} onClick={setLink}>
85
+ <LinkIcon className="h-4 w-4" />
86
+ </ToolbarButton>
87
+ {editor.isActive("link") && (
88
+ <ToolbarButton title="Remove link" onClick={() => editor.chain().focus().unsetLink().run()}>
89
+ <Unlink className="h-4 w-4" />
90
+ </ToolbarButton>
91
+ )}
92
+ </div>
93
+ );
94
+ }
95
+
96
+ export function MarkdownEditor({ value, onChange, placeholder }: MarkdownEditorProps) {
97
+ const editor = useEditor({
98
+ extensions: [
99
+ StarterKit.configure({
100
+ heading: false,
101
+ codeBlock: false,
102
+ blockquote: false,
103
+ horizontalRule: false,
104
+ bulletList: false,
105
+ orderedList: false,
106
+ listItem: false,
107
+ }),
108
+ Link.configure({
109
+ openOnClick: false,
110
+ HTMLAttributes: { class: "text-blue-600 underline" },
111
+ }),
112
+ Placeholder.configure({ placeholder: placeholder ?? "" }),
113
+ Markdown,
114
+ ],
115
+ content: value,
116
+ immediatelyRender: false,
117
+ onUpdate: ({ editor: ed }) => {
118
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
119
+ onChange((ed.storage as any).markdown.getMarkdown());
120
+ },
121
+ editorProps: {
122
+ attributes: {
123
+ class: "prose prose-sm max-w-none px-3 py-2 min-h-[120px] outline-none",
124
+ },
125
+ },
126
+ });
127
+
128
+ useEffect(() => {
129
+ if (!editor) return;
130
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
131
+ const currentMarkdown = (editor.storage as any).markdown.getMarkdown();
132
+ if (value !== currentMarkdown) {
133
+ editor.commands.setContent(value);
134
+ }
135
+ }, [value, editor]);
136
+
137
+ return (
138
+ <div className="bg-background rounded-md border">
139
+ <Toolbar editor={editor} />
140
+ <EditorContent editor={editor} />
141
+ </div>
142
+ );
143
+ }
@@ -0,0 +1,49 @@
1
+ "use client";
2
+
3
+ import { useEffect } from "react";
4
+ import { useEditor, EditorContent } from "@tiptap/react";
5
+ import StarterKit from "@tiptap/starter-kit";
6
+ import Link from "@tiptap/extension-link";
7
+ import { Markdown } from "tiptap-markdown";
8
+ import type { MarkdownViewProps } from "../types/index.ts";
9
+
10
+ export function MarkdownView({ content }: MarkdownViewProps) {
11
+ const editor = useEditor({
12
+ extensions: [
13
+ StarterKit.configure({
14
+ heading: false,
15
+ codeBlock: false,
16
+ blockquote: false,
17
+ horizontalRule: false,
18
+ bulletList: false,
19
+ orderedList: false,
20
+ listItem: false,
21
+ }),
22
+ Link.configure({
23
+ openOnClick: true,
24
+ HTMLAttributes: {
25
+ class: "text-blue-600 underline",
26
+ target: "_blank",
27
+ rel: "noopener noreferrer",
28
+ },
29
+ }),
30
+ Markdown,
31
+ ],
32
+ content,
33
+ immediatelyRender: false,
34
+ editable: false,
35
+ editorProps: {
36
+ attributes: {
37
+ class: "prose prose-sm max-w-none",
38
+ },
39
+ },
40
+ });
41
+
42
+ useEffect(() => {
43
+ if (editor) {
44
+ editor.commands.setContent(content);
45
+ }
46
+ }, [content, editor]);
47
+
48
+ return <EditorContent editor={editor} />;
49
+ }
@@ -0,0 +1,60 @@
1
+ "use client";
2
+
3
+ import { cn } from "../lib/utils.ts";
4
+ import type { UserAvatarProps } from "../types/index.ts";
5
+
6
+ function getInitials(name: string): string {
7
+ return name
8
+ .split(" ")
9
+ .map((part) => part[0])
10
+ .filter(Boolean)
11
+ .slice(0, 2)
12
+ .join("")
13
+ .toUpperCase();
14
+ }
15
+
16
+ const AVATAR_COLORS = [
17
+ "bg-blue-500",
18
+ "bg-green-500",
19
+ "bg-purple-500",
20
+ "bg-orange-500",
21
+ "bg-pink-500",
22
+ "bg-teal-500",
23
+ "bg-indigo-500",
24
+ "bg-red-500",
25
+ ];
26
+
27
+ function getColorForUser(id: string): string {
28
+ let hash = 0;
29
+ for (let i = 0; i < id.length; i++) {
30
+ hash = id.charCodeAt(i) + ((hash << 5) - hash);
31
+ }
32
+ return AVATAR_COLORS[Math.abs(hash) % AVATAR_COLORS.length];
33
+ }
34
+
35
+ export function UserAvatar({ user, size = "sm" }: UserAvatarProps) {
36
+ const sizeClasses = size === "sm" ? "h-6 w-6 text-[10px]" : "h-8 w-8 text-xs";
37
+ const imgSizeClasses = size === "sm" ? "h-6 w-6" : "h-8 w-8";
38
+
39
+ if (user.avatarUrl) {
40
+ return (
41
+ <img
42
+ src={user.avatarUrl}
43
+ alt={user.name}
44
+ className={cn("shrink-0 rounded-full object-cover", imgSizeClasses)}
45
+ />
46
+ );
47
+ }
48
+
49
+ return (
50
+ <span
51
+ className={cn(
52
+ "inline-flex shrink-0 items-center justify-center rounded-full font-medium text-white",
53
+ getColorForUser(user.id),
54
+ sizeClasses,
55
+ )}
56
+ >
57
+ {getInitials(user.name)}
58
+ </span>
59
+ );
60
+ }