mirror of
https://github.com/bitbaum/accountkit.git
synced 2026-12-04 05:37:35 +01:00
Each product wrote its own account menu, and each learned half of what
the other had:
Loki AccountMenu OrangeCat UserProfileDropdown
initials from the name only never rebuilds a name from the email
custom rows (Appearance) photo with a fallback, arrow keys
36px trigger 44px trigger
name falls back to the —
email local-part
and Loki's public pages had no menu at all, so a signed-in person could
not find sign-out (loki#870 papered over that by reusing the app's menu).
This is the one menu with both halves. It knows nothing about how a
product signs people in — NextAuth, Supabase, better-auth all pass the
person, the places, and a sign-out function — and keeps routing with a
renderLink seam (Next <Link>; a plain <a> by default).
Shared and not configurable, because each shipped broken somewhere:
- the name is never built from the email (OrangeCat's rule; Loki broke it)
- initials only from the name; else a person glyph
- a broken photo falls back to initials
- 44px trigger and rows; the panel never runs off a 390px screen
- Escape closes and returns focus wherever focus was
- sign-out says it is happening, and says when it FAILED (menu stays open)
The real-browser check caught a bug before release: Escape did nothing
after a MOUSE open, because the handler sat on the panel and focus was
on the trigger. It is now a document listener while open.
Styled from @bitbaum/design-tokens through --acct-* variables at zero
specificity (chatkit's pattern), so an app's own :root wins and an OKLCH
app maps its tokens once.
dist/ is committed so `github:bitbaum/accountkit#v0.1.0` installs with no
build and no allowBuilds entry; CI fails if it drifts from the source.
verify: format, lint, types, build, 13 unit+render tests, browser checks
at 390px light and dark. Proved by mutation — letting the name fall back
to the email local-part fails "a name is NEVER reconstructed from the
email address".
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
68 lines
2.5 KiB
JavaScript
68 lines
2.5 KiB
JavaScript
// The identity rules, pure. Each is a mistake one of the two source apps made.
|
|
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import {
|
|
displayNameFor,
|
|
initialsFor,
|
|
nextMenuIndex,
|
|
secondaryLineFor,
|
|
PLACEHOLDER_NAME,
|
|
} from "../dist/index.js";
|
|
|
|
test("the display name is the name the person chose", () => {
|
|
assert.equal(
|
|
displayNameFor({ name: "Cato", email: "butaeff@gmail.com" }),
|
|
"Cato",
|
|
);
|
|
});
|
|
|
|
test("no name: the handle, written as @handle", () => {
|
|
assert.equal(displayNameFor({ handle: "cato" }), "@cato");
|
|
assert.equal(displayNameFor({ handle: "@cato" }), "@cato", "never @@");
|
|
});
|
|
|
|
// OrangeCat's rule. `firstname.lastname@…` once came out as "Firstname
|
|
// Lastname" — a real name rebuilt from an address the person never displayed.
|
|
test("a name is NEVER reconstructed from the email address", () => {
|
|
const shown = displayNameFor({ email: "firstname.lastname@example.com" });
|
|
assert.equal(shown, PLACEHOLDER_NAME);
|
|
assert.ok(!/firstname|lastname/i.test(shown));
|
|
});
|
|
|
|
// Loki's rule. "butaeff" → "B" tells the person nothing.
|
|
test("initials come from the name only — never from the email", () => {
|
|
assert.equal(initialsFor({ name: "George Botsmann" }), "GB");
|
|
assert.equal(initialsFor({ name: "Cato" }), "C");
|
|
assert.equal(
|
|
initialsFor({ email: "butaeff@gmail.com" }),
|
|
null,
|
|
"glyph, not a letter",
|
|
);
|
|
assert.equal(initialsFor({ name: " " }), null);
|
|
});
|
|
|
|
test("initials take at most two words and survive non-Latin first letters", () => {
|
|
assert.equal(initialsFor({ name: "Ana María García López" }), "AM");
|
|
assert.equal(initialsFor({ name: "Émile Zola" }), "ÉZ");
|
|
});
|
|
|
|
test("the second identity line: @handle beside a name, else the email", () => {
|
|
assert.equal(secondaryLineFor({ name: "Cato", handle: "cato" }), "@cato");
|
|
assert.equal(secondaryLineFor({ name: "Cato", email: "c@x.ch" }), "c@x.ch");
|
|
assert.equal(secondaryLineFor({ name: "Cato" }), null);
|
|
});
|
|
|
|
test("arrow keys wrap; Home and End jump; nothing to focus is -1", () => {
|
|
assert.equal(
|
|
nextMenuIndex(-1, "ArrowDown", 3),
|
|
0,
|
|
"first press lands on the first item",
|
|
);
|
|
assert.equal(nextMenuIndex(2, "ArrowDown", 3), 0, "wraps past the last");
|
|
assert.equal(nextMenuIndex(0, "ArrowUp", 3), 2, "wraps past the first");
|
|
assert.equal(nextMenuIndex(-1, "ArrowUp", 3), 2);
|
|
assert.equal(nextMenuIndex(1, "Home", 3), 0);
|
|
assert.equal(nextMenuIndex(1, "End", 3), 2);
|
|
assert.equal(nextMenuIndex(0, "ArrowDown", 0), -1);
|
|
});
|