frontend: one header menu for the links, user, settings and alerts popovers
Part of the unification order in the UI sweep issue (step c). The four header menus each kept their own open state, dismiss hook and a copy of the popover CSS, and the copies had drifted (offset, padding, fade-in). A shared HeaderMenu now owns the state, the dismiss rules and the popover look; each menu supplies its button and its rows. The settings popover moves 0.15em lower and the settings and alerts popovers gain the fade-in.
This commit is contained in:
parent
25965341e0
commit
6f73bf0c55
2 changed files with 310 additions and 365 deletions
|
|
@ -1,14 +1,7 @@
|
|||
@import "../icon-button/IconButton.css";
|
||||
/* <UserMenu> (@hive/shared) — same header icon-button + popover chrome as
|
||||
`LinksMenu`/`SettingsMenu`, except the trigger is a round, accent-
|
||||
coloured initials avatar rather than a glyph-on-transparent button —
|
||||
this is the "who is this" affordance, the other two are quiet chrome.
|
||||
Kept as its own stylesheet for the same reason `SettingsMenu.css`
|
||||
gives: three small, independently-evolving popovers that happen to
|
||||
look alike today, not one component with three skins. */
|
||||
.user-menu {
|
||||
position: relative;
|
||||
}
|
||||
@import "../header-menu/HeaderMenu.css";
|
||||
/* <UserMenu> (@hive/shared) — a `HeaderMenu` whose trigger is a round, accent-
|
||||
coloured initials avatar rather than a glyph on a transparent button: this is
|
||||
the "who is this" affordance, the other menus are quiet chrome. */
|
||||
/* The round shape and the open outline are the shared icon button's; the fill is
|
||||
the accent inline on the element. */
|
||||
.ui-icon-button.user-menu-button {
|
||||
|
|
@ -20,45 +13,6 @@
|
|||
.ui-icon-button.user-menu-button[aria-expanded="true"] {
|
||||
outline: 1px solid var(--fg);
|
||||
}
|
||||
.user-menu-popover {
|
||||
position: absolute;
|
||||
top: calc(100% + 0.4em);
|
||||
right: 0;
|
||||
z-index: var(--z-popover);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-width: 12em;
|
||||
padding: 0.4em;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius-md);
|
||||
background: var(--bg-elev);
|
||||
box-shadow: var(--shadow-pop);
|
||||
animation: user-menu-popover-enter 140ms ease;
|
||||
}
|
||||
/* Mount-triggered, same shape as `LinksMenu.css`'s own version — see
|
||||
its comment for why a keyframe (not a transition) is the right tool
|
||||
here. */
|
||||
@keyframes user-menu-popover-enter {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(-0.25em) scale(0.98);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: none;
|
||||
}
|
||||
}
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.user-menu-popover {
|
||||
animation: none;
|
||||
}
|
||||
}
|
||||
:root[data-motion="reduce"] .user-menu-popover {
|
||||
animation: none;
|
||||
}
|
||||
:root[data-motion="allow"] .user-menu-popover {
|
||||
animation: user-menu-popover-enter 140ms ease;
|
||||
}
|
||||
.user-menu-name {
|
||||
padding: 0.4em 0.6em 0.5em;
|
||||
border-bottom: 1px solid var(--border);
|
||||
|
|
@ -69,16 +23,3 @@
|
|||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.user-menu-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
min-height: 2.75em;
|
||||
padding: 0.4em 0.6em;
|
||||
border-radius: var(--radius-sm);
|
||||
color: var(--fg);
|
||||
text-decoration: none;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.user-menu-item:hover {
|
||||
background: var(--bg);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,9 +15,8 @@
|
|||
// Styles live in `@hive/shared/user-menu.css`, which the mounting page
|
||||
// imports or `@import`s itself: the dashboard's JS bundle loads `.css`
|
||||
// imports as text, so a component that imported it would not style there.
|
||||
import { useDismiss } from "../use-dismiss.js";
|
||||
import { useEffect, useRef, useState } from "preact/hooks";
|
||||
import { IconButton } from "../icon-button/IconButton.js";
|
||||
import { useEffect, useState } from "preact/hooks";
|
||||
import { HeaderMenu } from "../header-menu/HeaderMenu.js";
|
||||
import {
|
||||
accountLinks,
|
||||
initialOf,
|
||||
|
|
@ -42,8 +41,6 @@ export function UserMenu({
|
|||
onLogout?: () => void;
|
||||
}) {
|
||||
const [who, setWho] = useState<WhoAmI | null>(null);
|
||||
const [open, setOpen] = useState(false);
|
||||
const rootRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
|
|
@ -62,56 +59,46 @@ export function UserMenu({
|
|||
};
|
||||
}, [whoamiUrl]);
|
||||
|
||||
// A press outside or Escape closes it; Escape puts the focus back on the button.
|
||||
useDismiss({
|
||||
open,
|
||||
onDismiss: () => setOpen(false),
|
||||
inside: [rootRef],
|
||||
focusOnEscape: () => rootRef.current?.querySelector("button") ?? null,
|
||||
});
|
||||
|
||||
const label = labelOf(who);
|
||||
const links = accountLinks(autheliaUrl);
|
||||
|
||||
return (
|
||||
<div class="user-menu" ref={rootRef}>
|
||||
<IconButton
|
||||
class="user-menu-button"
|
||||
style={{ background: pickAccent(label ?? "operator") }}
|
||||
label={label ? `signed in as ${label}` : "account"}
|
||||
onClick={() => setOpen((v) => !v)}
|
||||
expanded={open}
|
||||
>
|
||||
{initialOf(label)}
|
||||
</IconButton>
|
||||
{open ? (
|
||||
<div class="user-menu-popover" role="group" aria-label="account">
|
||||
<HeaderMenu
|
||||
class="user-menu"
|
||||
triggerClass="user-menu-button"
|
||||
triggerStyle={{ background: pickAccent(label ?? "operator") }}
|
||||
label={label ? `signed in as ${label}` : "account"}
|
||||
popoverLabel="account"
|
||||
trigger={initialOf(label)}
|
||||
>
|
||||
{(close) => (
|
||||
<>
|
||||
{label ? <div class="user-menu-name">{label}</div> : null}
|
||||
{links ? (
|
||||
<>
|
||||
<a
|
||||
class="user-menu-item"
|
||||
class="header-menu-item"
|
||||
href={links.settings}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
onClick={() => setOpen(false)}
|
||||
onClick={close}
|
||||
>
|
||||
authelia settings
|
||||
</a>
|
||||
<a
|
||||
class="user-menu-item"
|
||||
class="header-menu-item"
|
||||
href={links.logout}
|
||||
onClick={() => {
|
||||
onLogout?.();
|
||||
setOpen(false);
|
||||
close();
|
||||
}}
|
||||
>
|
||||
log out
|
||||
</a>
|
||||
</>
|
||||
) : null}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</HeaderMenu>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue