Skip to content

armgit / memos

Public Imported from GitHub
0

Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.

chore: tweak user default avatar display

boojack88f13675d8ce
diff --git a/web/src/components/UserAvatar.tsx b/web/src/components/UserAvatar.tsx
index 00bfabc38..4bd35173c 100644
--- a/web/src/components/UserAvatar.tsx
+++ b/web/src/components/UserAvatar.tsx
@@ -1,3 +1,4 @@
+import { UserRoundIcon } from "lucide-react";
import type { CSSProperties } from "react";
import { cn } from "@/lib/utils";
@@ -21,14 +22,23 @@ const UserAvatar = (props: Props) => {
avatarUrl
? "border border-border"
: title
- ? "bg-[oklch(0.82_0.09_var(--avatar-hue))] [[data-theme=default-dark]_&]:bg-[oklch(0.42_0.09_var(--avatar-hue))]"
- : "bg-muted",
+ ? "bg-[oklch(0.82_0.09_var(--avatar-hue))] text-[oklch(0.5_0.1_var(--avatar-hue))] [[data-theme=default-dark]_&]:bg-[oklch(0.42_0.09_var(--avatar-hue))] [[data-theme=default-dark]_&]:text-[oklch(0.85_0.06_var(--avatar-hue))]"
+ : "bg-muted text-muted-foreground",
className,
)}
style={style}
aria-hidden="true"
>
- {avatarUrl && <img className="size-full object-cover" src={avatarUrl} decoding="async" loading="lazy" alt="" />}
+ {avatarUrl ? (
+ <img className="size-full object-cover" src={avatarUrl} decoding="async" loading="lazy" alt="" />
+ ) : (
+ // Lower the portrait to crop the body, widen it, and leave a small gap below the head.
+ <UserRoundIcon
+ className="size-full translate-y-[12.5%] [&_circle]:-translate-y-px [&_path]:origin-center [&_path]:scale-x-110"
+ fill="currentColor"
+ strokeWidth={0}
+ />
+ )}
</div>
);
};
diff --git a/web/tests/user-avatar.test.tsx b/web/tests/user-avatar.test.tsx
index d811f6577..d86b467eb 100644
--- a/web/tests/user-avatar.test.tsx
+++ b/web/tests/user-avatar.test.tsx
@@ -3,28 +3,30 @@ import { describe, expect, it } from "vitest";
import UserAvatar from "@/components/UserAvatar";
describe("UserAvatar", () => {
- it("uses the display title for a stable solid color", () => {
+ it("uses the display title for a stable color behind the decorative silhouette", () => {
const { container, rerender } = render(<UserAvatar name="Steven" />);
const avatar = container.firstElementChild as HTMLElement;
expect(avatar.style.getPropertyValue("--avatar-hue")).toMatch(/^\d+deg$/);
- expect(avatar.children).toHaveLength(0);
+ expect(avatar).toHaveAttribute("aria-hidden", "true");
+ expect(avatar.querySelector("svg")).toHaveAttribute("fill", "currentColor");
const hue = avatar.style.getPropertyValue("--avatar-hue");
rerender(<UserAvatar name="steven" />);
expect(avatar.style.getPropertyValue("--avatar-hue")).toBe(hue);
rerender(<UserAvatar name="Alice" />);
expect(avatar.style.getPropertyValue("--avatar-hue")).not.toBe(hue);
- expect(avatar.children).toHaveLength(0);
+ expect(avatar.querySelector("svg")).toBeInTheDocument();
});
it("keeps a supplied image and uses a neutral fallback without a title", () => {
const { container, rerender } = render(<UserAvatar avatarUrl="/avatar.png" name="Steven" />);
expect(container.querySelector("img")).toHaveAttribute("src", "/avatar.png");
+ expect(container.querySelector("svg")).toBeNull();
expect(container.firstElementChild).not.toHaveAttribute("style");
rerender(<UserAvatar />);
expect(container.querySelector("img")).toBeNull();
- expect(container.firstElementChild?.children).toHaveLength(0);
+ expect(container.querySelector("svg")).toBeInTheDocument();
expect(container.firstElementChild).toHaveClass("bg-muted");
});
});