Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(themes): let --avatar-radius shape every avatar (MUL-9055) (#10695)
Jiayuan Zhang677084d9e4e1
diff --git a/packages/ui/components/common/__tests__/actor-avatar.test.tsx b/packages/ui/components/common/__tests__/actor-avatar.test.tsxnew file mode 100644index 0000000000..b8992b68a9--- /dev/null+++ b/packages/ui/components/common/__tests__/actor-avatar.test.tsx@@ -0,0 +1,33 @@+import { cleanup, render } from "@testing-library/react";+import { afterEach, describe, expect, it } from "vitest";+import { ActorAvatar } from "../actor-avatar";++afterEach(cleanup);++function avatarOf(ui: React.ReactElement) {+ const { container } = render(ui);+ return container.querySelector<HTMLElement>('[data-slot="avatar"]')!;+}++describe("ActorAvatar shape", () => {+ it("takes the theme's avatar radius", () => {+ const avatar = avatarOf(<ActorAvatar name="Ada" initials="A" />);+ expect(avatar.classList).toContain("rounded-avatar");+ expect(avatar.classList).not.toContain("rounded-full");+ });++ it("ignores a call-site radius", () => {+ const avatar = avatarOf(+ <ActorAvatar name="Ada" initials="A" className="rounded-md rounded-full" />,+ );+ expect(avatar.classList).toContain("rounded-avatar");+ expect(avatar.classList).not.toContain("rounded-md");+ expect(avatar.classList).not.toContain("rounded-full");+ });++ it("fills a system avatar with the mark's tile colour", () => {+ const avatar = avatarOf(<ActorAvatar name="Multica" initials="M" isSystem />);+ expect(avatar.classList).toContain("bg-multica-ink");+ expect(avatar.classList).not.toContain("bg-muted");+ });+});diff --git a/packages/ui/components/common/actor-avatar.tsx b/packages/ui/components/common/actor-avatar.tsxindex d2601284bd..0d08ee318f 100644--- a/packages/ui/components/common/actor-avatar.tsx+++ b/packages/ui/components/common/actor-avatar.tsx@@ -40,14 +40,16 @@ function ActorAvatar({const diameter = `var(--avatar-slot-size, ${AVATAR_SIZE_PX[size]}px)`;const scaled = (ratio: number) => `calc(${diameter} * ${ratio})`;const emoji = parseAvatarEmoji(avatarUrl);+ const showsSystemMark = isSystem && !emoji && (!avatarUrl || imgError);useEffect(() => {setImgError(false);}, [avatarUrl]);- // Every actor — member, agent, squad, or system — renders as a circle. This- // is the single source of truth for avatar shape; the upload editors mirror- // it (packages/views/common/avatar-upload-control.tsx).+ // Every actor — member, agent, squad, or system — takes the same shape:+ // `--avatar-radius`, a circle unless a theme sets it. This is the single+ // source of truth for avatar shape; the upload editors mirror it+ // (packages/views/common/avatar-upload-control.tsx, avatar-crop-dialog.tsx).return (<divdata-slot="avatar"@@ -55,11 +57,15 @@ function ActorAvatar({data-type={isSystem ? "system" : isAgent ? "agent" : isSquad ? "squad" : "member"}className={cn("inline-flex shrink-0 items-center justify-center font-medium overflow-hidden",- (!avatarUrl || emoji || imgError) && "bg-muted text-muted-foreground",+ // The system mark draws a round tile; filling the box with the tile+ // colour keeps it whole when a theme squares the avatar.+ showsSystemMark+ ? "bg-multica-ink dark:bg-multica-paper"+ : (!avatarUrl || emoji || imgError) && "bg-muted text-muted-foreground",className,- // rounded-full stays last so a call-site `className` can never override- // the circle — avatar shape is a hard invariant, not a per-site choice.- "rounded-full"+ // rounded-avatar stays last so a call-site `className` can never+ // override the shape — it is the theme's choice, not a per-site one.+ "rounded-avatar")}style={{ width: diameter, height: diameter, fontSize: scaled(0.45) }}>diff --git a/packages/views/common/avatar-crop-dialog.tsx b/packages/views/common/avatar-crop-dialog.tsxindex 52e08da1f3..d25c49db9f 100644--- a/packages/views/common/avatar-crop-dialog.tsx+++ b/packages/views/common/avatar-crop-dialog.tsx@@ -37,10 +37,10 @@ interface AvatarCropDialogProps {}/**- * Avatar cropper. The image pans/zooms/rotates beneath a fixed round crop- * window; everything outside the window is dimmed. Output is a square {@link- * AVATAR_OUTPUT_SIZE}px image — the round mask is display-only, never baked- * into the pixels.+ * Avatar cropper. The image pans/zooms/rotates beneath a fixed crop window in+ * the avatar shape (`--avatar-radius`, a circle by default); everything+ * outside the window is dimmed. Output is a square {@link AVATAR_OUTPUT_SIZE}px+ * image — the mask is display-only, never baked into the pixels.** Interaction (drag / zoom / rotate + the dim overlay) is delegated to* react-easy-crop; this component owns the chrome (header, zoom slider, rotate@@ -147,8 +147,9 @@ export function AvatarCropDialog({aspect={1}minZoom={MIN_ZOOM}maxZoom={MAX_ZOOM}- cropShape="round"+ cropShape="rect"showGrid={false}+ classes={{ cropAreaClassName: "rounded-avatar" }}style={{containerStyle: { pointerEvents: pending ? "none" : undefined },}}diff --git a/packages/views/common/avatar-upload-control.tsx b/packages/views/common/avatar-upload-control.tsxindex 88a1cf5970..ffb89f102f 100644--- a/packages/views/common/avatar-upload-control.tsx+++ b/packages/views/common/avatar-upload-control.tsx@@ -40,7 +40,7 @@ interface AvatarUploadControlProps {variant: AvatarUploadVariant;/** Name used for initials / first-letter fallback and the image alt. */name?: string;- /** Pixel diameter of the circle. Defaults to 64. */+ /** Pixel width and height of the avatar. Defaults to 64. */size?: number;disabled?: boolean;/**@@ -247,8 +247,7 @@ export function AvatarUploadControl({"flex items-center justify-center","focus-visible:ring-2 focus-visible:ring-ring","disabled:cursor-not-allowed disabled:opacity-60",- // eslint-disable-next-line no-restricted-syntax -- avatar: the control is the avatar itself- "rounded-full",+ "rounded-avatar",className,)}style={{ width: size, height: size }}diff --git a/packages/views/invitations/invitations-page.tsx b/packages/views/invitations/invitations-page.tsxindex e856c0d7c2..1033fad8b5 100644--- a/packages/views/invitations/invitations-page.tsx+++ b/packages/views/invitations/invitations-page.tsx@@ -233,7 +233,7 @@ function InvitationRow({highlighted ? "border-brand/50 bg-brand/5" : "border-border bg-card",)}>- <WorkspaceAvatar name={name} size="lg" className="rounded-md" />+ <WorkspaceAvatar name={name} size="lg" radius="md" /><div className="min-w-0 flex-1 space-y-1"><div className="truncate font-medium">{name}</div><div className="truncate text-caption text-muted-foreground">diff --git a/packages/views/layout/rail-workspaces.tsx b/packages/views/layout/rail-workspaces.tsxindex 5ec4af9c67..bd9a27fa73 100644--- a/packages/views/layout/rail-workspaces.tsx+++ b/packages/views/layout/rail-workspaces.tsx@@ -173,12 +173,13 @@ export function RailWorkspaces() {<DropdownMenuTriggeraria-label={label}onContextMenu={tileMenu.openAtPointer}- className="relative inline-flex size-[34px] shrink-0 cursor-pointer items-center justify-center rounded-lg outline-none focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring"+ className="relative inline-flex size-[34px] shrink-0 cursor-pointer items-center justify-center rounded-[var(--avatar-radius,var(--radius-lg))] outline-none focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring"><WorkspaceAvatarname={current.name}avatarUrl={current.avatar_url}- className="h-[34px] w-[34px] rounded-lg border-surface-border bg-surface-raised text-body text-foreground shadow-[var(--surface-shadow)]"+ radius="lg"+ className="h-[34px] w-[34px] border-surface-border bg-surface-raised text-body text-foreground shadow-[var(--surface-shadow)]"/>{(otherUnread || invitations.length > 0) && (<UnreadDot className="absolute -top-0.5 -right-0.5 ring-2 ring-app-shell" />diff --git a/packages/views/settings/components/settings-layout.tsx b/packages/views/settings/components/settings-layout.tsxindex 8a45c056d8..abe9e0f74f 100644--- a/packages/views/settings/components/settings-layout.tsx+++ b/packages/views/settings/components/settings-layout.tsx@@ -82,7 +82,8 @@ function WorkspaceScopeBadge({<WorkspaceAvatarname={name}avatarUrl={workspace.avatar_url}- className="size-3 rounded-xs border-0"+ radius="xs"+ className="size-3 border-0"/>) : (<Building2 aria-hidden="true" className="size-3" />diff --git a/packages/views/workspace/workspace-avatar.test.tsx b/packages/views/workspace/workspace-avatar.test.tsxnew file mode 100644index 0000000000..9564afcd12--- /dev/null+++ b/packages/views/workspace/workspace-avatar.test.tsx@@ -0,0 +1,39 @@+import { cleanup, render } from "@testing-library/react";+import { afterEach, describe, expect, it, vi } from "vitest";+import { WorkspaceAvatar } from "./workspace-avatar";++vi.mock("@multica/core/api", () => ({+ api: { getBaseUrl: () => "http://127.0.0.1:8080" },+}));++afterEach(cleanup);++const LOGO = "https://cdn.example.com/logo.png";++function avatarOf(ui: React.ReactElement) {+ return render(ui).container.firstElementChild as HTMLElement;+}++describe("WorkspaceAvatar shape", () => {+ for (const [path, avatarUrl] of [["logo", LOGO], ["letter", null]] as const) {+ it(`takes the theme's avatar radius (${path})`, () => {+ const avatar = avatarOf(<WorkspaceAvatar name="Acme" avatarUrl={avatarUrl} />);+ expect(avatar.classList).toContain("rounded-avatar");+ expect(avatar.classList).not.toContain("rounded-full");+ });++ it(`keeps a fallback radius under the theme's (${path})`, () => {+ const avatar = avatarOf(<WorkspaceAvatar name="Acme" avatarUrl={avatarUrl} radius="lg" />);+ expect(avatar.classList).toContain("rounded-[var(--avatar-radius,var(--radius-lg))]");+ expect(avatar.classList).not.toContain("rounded-avatar");+ });++ it(`ignores a call-site radius (${path})`, () => {+ const avatar = avatarOf(+ <WorkspaceAvatar name="Acme" avatarUrl={avatarUrl} className="rounded-md" />,+ );+ expect(avatar.classList).toContain("rounded-avatar");+ expect(avatar.classList).not.toContain("rounded-md");+ });+ }+});diff --git a/packages/views/workspace/workspace-avatar.tsx b/packages/views/workspace/workspace-avatar.tsxindex f98281f583..8771a9b02d 100644--- a/packages/views/workspace/workspace-avatar.tsx+++ b/packages/views/workspace/workspace-avatar.tsx@@ -2,26 +2,40 @@ import { resolvePublicFileUrl } from "@multica/core/workspace/avatar-url";import { cn } from "@multica/ui/lib/utils";const sizeMap = {- sm: "h-5 w-5 text-caption rounded-full",- md: "h-7 w-7 text-caption rounded-full",- lg: "h-9 w-9 text-body rounded-full",+ sm: "h-5 w-5 text-caption",+ md: "h-7 w-7 text-caption",+ lg: "h-9 w-9 text-body",+} as const;++/**+ * The shape when no theme sets `--avatar-radius`. A theme's value wins+ * everywhere, so every workspace avatar takes the theme's avatar shape.+ */+const radiusMap = {+ circle: "rounded-avatar",+ lg: "rounded-[var(--avatar-radius,var(--radius-lg))]",+ md: "rounded-[var(--avatar-radius,var(--radius-md))]",+ xs: "rounded-[var(--avatar-radius,var(--radius-xs))]",} as const;interface WorkspaceAvatarProps {name: string;avatarUrl?: string | null;size?: keyof typeof sizeMap;+ radius?: keyof typeof radiusMap;className?: string;}-function WorkspaceAvatar({ name, avatarUrl, size = "sm", className }: WorkspaceAvatarProps) {+function WorkspaceAvatar({ name, avatarUrl, size = "sm", radius = "circle", className }: WorkspaceAvatarProps) {const resolvedUrl = resolvePublicFileUrl(avatarUrl);+ // The radius goes last so a call-site `className` can't override the shape;+ // pick a fallback with `radius` instead.if (resolvedUrl) {return (<imgsrc={resolvedUrl}alt={name}- className={cn("inline-block shrink-0 border object-cover", sizeMap[size], className)}+ className={cn("inline-block shrink-0 border object-cover", sizeMap[size], className, radiusMap[radius])}/>);}@@ -30,7 +44,8 @@ function WorkspaceAvatar({ name, avatarUrl, size = "sm", className }: WorkspaceAclassName={cn("inline-flex shrink-0 items-center justify-center border bg-muted font-semibold text-muted-foreground",sizeMap[size],- className+ className,+ radiusMap[radius])}>{name.charAt(0).toUpperCase()}diff --git a/scripts/theme-preview.test.mjs b/scripts/theme-preview.test.mjsindex 584ba3e86d..d8b496ed73 100644--- a/scripts/theme-preview.test.mjs+++ b/scripts/theme-preview.test.mjs@@ -160,6 +160,12 @@ const EXPECTED = [],source: "packages/ui/components/ui/switch.tsx",},+ {+ what: "the avatars",+ find: (els) => els.filter((el) => el.attrs["data-slot"] === "avatar"),+ classes: ["rounded-avatar"],+ source: "packages/ui/components/common/actor-avatar.tsx",+ },...[["open", "git-pull-request-arrow"],["merged", "git-merge"],@@ -199,7 +205,6 @@ const NOT_DRAWN = {tooltip: "no tooltip is open",input: "the page has no text input",button: "only small buttons are on the page",- avatar: "actor avatars are round (rounded-full) in the app","board-column": "the page shows the list, not the board","board-card": "the page shows the list, not the board",},diff --git a/scripts/theme-preview/fixture.html b/scripts/theme-preview/fixture.htmlindex ee618952ec..85199983da 100644--- a/scripts/theme-preview/fixture.html+++ b/scripts/theme-preview/fixture.html@@ -157,7 +157,7 @@<div class="my-6 border-t"></div><h2 class="text-title-sm font-semibold">Activity</h2><div class="mt-4 flex flex-col gap-3 px-4 pb-3">- <div class="flex items-center text-label text-muted-foreground"><div class="mr-2 flex w-4 shrink-0 justify-center"><span data-slot="avatar" class="inline-flex size-4 shrink-0 items-center justify-center overflow-hidden rounded-full bg-muted text-[9px] font-medium text-muted-foreground">A</span></div><div class="flex min-w-0 flex-1 items-center gap-1"><span class="shrink-0 font-medium">Ada</span><span class="truncate">created this issue</span><span class="ml-auto shrink-0">3h ago</span></div></div>+ <div class="flex items-center text-label text-muted-foreground"><div class="mr-2 flex w-4 shrink-0 justify-center"><span data-slot="avatar" class="inline-flex size-4 shrink-0 items-center justify-center overflow-hidden rounded-avatar bg-muted text-[9px] font-medium text-muted-foreground">A</span></div><div class="flex min-w-0 flex-1 items-center gap-1"><span class="shrink-0 font-medium">Ada</span><span class="truncate">created this issue</span><span class="ml-auto shrink-0">3h ago</span></div></div></div><div class="mb-2 flex flex-col"><div class="flex min-h-8 items-center gap-2 px-2 text-label"><span class="min-w-0 flex-1 truncate">Wake Lambda when the PR merges</span><span role="switch" aria-checked="true" data-slot="switch" data-size="sm" data-checked="" class="peer group/switch relative inline-flex shrink-0 items-center rounded-full border border-switch-border transition-all outline-none data-[size=default]:h-[18.4px] data-[size=default]:w-[32px] data-[size=sm]:h-[14px] data-[size=sm]:w-[24px] data-checked:bg-switch-checked data-unchecked:bg-switch-unchecked dark:data-unchecked:bg-switch-unchecked-dark"><span data-slot="switch-thumb" data-checked="" class="pointer-events-none block rounded-full ring-0 transition-transform group-data-[size=default]/switch:size-4 group-data-[size=sm]/switch:size-3 group-data-[size=default]/switch:data-checked:translate-x-[calc(100%-2px)] group-data-[size=sm]/switch:data-checked:translate-x-[calc(100%-2px)] data-checked:bg-switch-checked-thumb dark:data-checked:bg-switch-checked-thumb-dark group-data-[size=default]/switch:data-unchecked:translate-x-0 group-data-[size=sm]/switch:data-unchecked:translate-x-0 data-unchecked:bg-switch-unchecked-thumb dark:data-unchecked:bg-switch-unchecked-thumb-dark"></span></span></div>@@ -165,14 +165,14 @@</div><div data-slot="card" data-size="default" data-mc="comment" data-author-type="agent" class="flex flex-col overflow-clip rounded-card border border-surface-border bg-surface text-body text-surface-foreground shadow-[var(--surface-shadow)]"><div class="mb-1 bg-card px-4 pt-3 pb-1">- <div class="flex items-center gap-2.5"><span data-slot="avatar" class="inline-flex size-[22px] shrink-0 items-center justify-center overflow-hidden rounded-full bg-muted text-micro font-medium text-muted-foreground">L</span><span class="shrink-0 text-body font-medium">Lambda</span><span class="shrink-0 text-label text-muted-foreground">2h ago</span></div>+ <div class="flex items-center gap-2.5"><span data-slot="avatar" class="inline-flex size-[22px] shrink-0 items-center justify-center overflow-hidden rounded-avatar bg-muted text-micro font-medium text-muted-foreground">L</span><span class="shrink-0 text-body font-medium">Lambda</span><span class="shrink-0 text-label text-muted-foreground">2h ago</span></div></div><div class="px-4 pb-3"><div class="pl-8 text-body leading-relaxed text-foreground"><div data-mc="content" data-density="document" class="rich-text-editor readonly text-body"><p>Opened a draft PR with the checklist and its empty state.</p></div></div></div><div data-mc="comment-reply" data-author-type="member" class="border-t border-border/50"><div class="px-4 pt-3 pb-1">- <div class="flex items-center gap-2.5"><span data-slot="avatar" class="inline-flex size-[22px] shrink-0 items-center justify-center overflow-hidden rounded-full bg-muted text-micro font-medium text-muted-foreground">A</span><span class="shrink-0 text-body font-medium">Ada</span><span class="shrink-0 text-label text-muted-foreground">1h ago</span></div>+ <div class="flex items-center gap-2.5"><span data-slot="avatar" class="inline-flex size-[22px] shrink-0 items-center justify-center overflow-hidden rounded-avatar bg-muted text-micro font-medium text-muted-foreground">A</span><span class="shrink-0 text-body font-medium">Ada</span><span class="shrink-0 text-label text-muted-foreground">1h ago</span></div></div><div class="px-4 pb-3"><div class="pl-8 text-body leading-relaxed text-foreground"><div data-mc="content" data-density="document" class="rich-text-editor readonly text-body"><p>Looks good, ship it.</p></div></div>