mirror of
https://github.com/bitbaum/accountkit.git
synced 2026-12-04 04:57:12 +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>
178 lines
4.4 KiB
CSS
178 lines
4.4 KiB
CSS
/*
|
||
* @bitbaum/accountkit — the look of the one account menu.
|
||
*
|
||
* Every colour, radius and face is an --acct-* variable. By default they read
|
||
* @bitbaum/design-tokens' HSL-triplet variables, so apps on those tokens match
|
||
* without doing anything. An app whose variables are full colours (loki's are
|
||
* OKLCH under the same names) maps them once — `:root { --acct-panel:
|
||
* var(--surface-overlay); … }` — exactly as it does for chatkit's --ck-*.
|
||
* The BEHAVIOUR is shared and is not configurable.
|
||
*
|
||
* Non-negotiable, and why:
|
||
* - 44px touch targets on the trigger and every row (WCAG 2.5.8). Loki's
|
||
* trigger was 36px.
|
||
* - The panel never runs off a 320–390px screen: its width is capped by the
|
||
* viewport, and it aligns to the trigger's inside edge.
|
||
* - Sign-out is the last row and is never hidden behind a scroll.
|
||
*/
|
||
|
||
:where(:root) {
|
||
/* Zero specificity: an app's own :root rule setting --acct-* always wins. */
|
||
--acct-panel: hsl(var(--surface-overlay, 0 0% 100%));
|
||
--acct-hover: hsl(var(--surface-hover, 0 0% 95%));
|
||
--acct-trigger-bg: hsl(var(--surface-raised, 0 0% 96%));
|
||
--acct-fg: hsl(var(--text-primary, 0 0% 10%));
|
||
--acct-fg-2: hsl(var(--text-secondary, 0 0% 30%));
|
||
--acct-fg-3: hsl(var(--text-tertiary, 0 0% 42%));
|
||
--acct-line: hsl(var(--border-subtle, 0 0% 90%));
|
||
--acct-line-2: hsl(var(--border-default, 0 0% 82%));
|
||
--acct-focus: var(--accent-primary, #ff5c00);
|
||
--acct-danger: hsl(var(--status-negative, 0 65% 50%));
|
||
--acct-radius: var(--radius-surface, 0.75rem);
|
||
--acct-radius-sm: var(--radius-control, 0.5rem);
|
||
--acct-font: var(
|
||
--font-sans,
|
||
system-ui,
|
||
-apple-system,
|
||
"Segoe UI",
|
||
sans-serif
|
||
);
|
||
--acct-target: 2.75rem;
|
||
--acct-shadow:
|
||
0 12px 32px -12px rgb(0 0 0 / 0.28), 0 2px 6px -2px rgb(0 0 0 / 0.12);
|
||
--acct-z: 50;
|
||
}
|
||
|
||
.acct {
|
||
position: relative;
|
||
display: inline-flex;
|
||
font-family: var(--acct-font);
|
||
}
|
||
|
||
.acct-trigger {
|
||
display: inline-flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
inline-size: var(--acct-target);
|
||
block-size: var(--acct-target);
|
||
min-inline-size: var(--acct-target);
|
||
padding: 0;
|
||
border: 1px solid var(--acct-line);
|
||
border-radius: 999px;
|
||
background: var(--acct-trigger-bg);
|
||
color: var(--acct-fg-2);
|
||
cursor: pointer;
|
||
overflow: hidden;
|
||
}
|
||
.acct-trigger:hover {
|
||
border-color: var(--acct-line-2);
|
||
color: var(--acct-fg);
|
||
}
|
||
.acct-trigger:focus-visible,
|
||
.acct-row:focus-visible {
|
||
outline: 2px solid var(--acct-focus);
|
||
outline-offset: 2px;
|
||
}
|
||
|
||
.acct-avatar {
|
||
inline-size: 100%;
|
||
block-size: 100%;
|
||
object-fit: cover;
|
||
}
|
||
.acct-initials {
|
||
font-size: 0.8125rem;
|
||
font-weight: 600;
|
||
letter-spacing: 0.02em;
|
||
}
|
||
|
||
.acct-panel {
|
||
position: absolute;
|
||
inset-block-start: calc(100% + 0.5rem);
|
||
z-index: var(--acct-z);
|
||
inline-size: min(18rem, calc(100vw - 2rem));
|
||
padding: 0.375rem;
|
||
border: 1px solid var(--acct-line);
|
||
border-radius: var(--acct-radius);
|
||
background: var(--acct-panel);
|
||
color: var(--acct-fg);
|
||
box-shadow: var(--acct-shadow);
|
||
}
|
||
.acct[data-align="end"] .acct-panel {
|
||
inset-inline-end: 0;
|
||
}
|
||
.acct[data-align="start"] .acct-panel {
|
||
inset-inline-start: 0;
|
||
}
|
||
|
||
.acct-identity {
|
||
padding: 0.625rem 0.75rem 0.75rem;
|
||
border-block-end: 1px solid var(--acct-line);
|
||
min-inline-size: 0;
|
||
}
|
||
.acct-name,
|
||
.acct-secondary {
|
||
margin: 0;
|
||
overflow: hidden;
|
||
text-overflow: ellipsis;
|
||
white-space: nowrap;
|
||
}
|
||
.acct-name {
|
||
font-size: 0.9375rem;
|
||
font-weight: 600;
|
||
}
|
||
.acct-secondary {
|
||
margin-block-start: 0.125rem;
|
||
font-size: 0.8125rem;
|
||
color: var(--acct-fg-3);
|
||
}
|
||
|
||
.acct-group {
|
||
padding-block: 0.25rem;
|
||
}
|
||
.acct-group + .acct-group {
|
||
border-block-start: 1px solid var(--acct-line);
|
||
}
|
||
|
||
.acct-row {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 0.625rem;
|
||
inline-size: 100%;
|
||
min-block-size: var(--acct-target);
|
||
padding: 0 0.75rem;
|
||
border: 0;
|
||
border-radius: var(--acct-radius-sm);
|
||
background: transparent;
|
||
color: var(--acct-fg);
|
||
font: inherit;
|
||
font-size: 0.9375rem;
|
||
text-align: start;
|
||
text-decoration: none;
|
||
cursor: pointer;
|
||
box-sizing: border-box;
|
||
}
|
||
.acct-row:hover,
|
||
.acct-row:focus-visible {
|
||
background: var(--acct-hover);
|
||
}
|
||
.acct-row[disabled] {
|
||
cursor: progress;
|
||
opacity: 0.7;
|
||
}
|
||
.acct-icon {
|
||
display: inline-flex;
|
||
flex-shrink: 0;
|
||
color: var(--acct-fg-2);
|
||
}
|
||
|
||
.acct-extra {
|
||
padding-inline: 0.75rem;
|
||
font-size: 0.9375rem;
|
||
}
|
||
|
||
.acct-error {
|
||
margin: 0.25rem 0.75rem 0.375rem;
|
||
font-size: 0.8125rem;
|
||
color: var(--acct-danger);
|
||
}
|