Move appearance into compact account theme controls
This commit is contained in:
1 parent
5852bf1897
commit
c3257a0f4d
13 files changed
+136
-12
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import { iconSvg } from "../icons/icons.js";
|
||||
import { themeControlMarkup, mountThemeControl } from "./theme-control.js";
|
||||
import {
|
||||
accountSubmenuMarkup,
|
||||
mountAccountSubmenu,
|
||||
@@ -7,7 +8,15 @@ let sequence = 0;
|
||||
/** Fixed account controls live outside the API-driven service navigation. */
|
||||
export function mountAccountMenu(
|
||||
root,
|
||||
{ onNavigate, t = (ru) => ru, name = "", email = "", items } = {},
|
||||
{
|
||||
onNavigate,
|
||||
t = (ru) => ru,
|
||||
name = "",
|
||||
email = "",
|
||||
items,
|
||||
theme = "light",
|
||||
onThemeChange,
|
||||
} = {},
|
||||
) {
|
||||
if (typeof onNavigate !== "function")
|
||||
throw new TypeError("Account menu needs onNavigate");
|
||||
@@ -28,16 +37,17 @@ export function mountAccountMenu(
|
||||
label: t("Устройства и сеансы", "Devices and sessions"),
|
||||
icon: "sessions",
|
||||
},
|
||||
{
|
||||
id: "account-settings",
|
||||
label: t("Настройки", "Settings"),
|
||||
icon: "settings",
|
||||
},
|
||||
];
|
||||
root.innerHTML = `<div id="${id}" class="account-menu" popover="auto" role="menu" aria-label="${t("Меню аккаунта", "Account menu")}">${accountSubmenuMarkup({ id: id + "-sections", items, t })}</div><button type="button" class="dock-account" popovertarget="${id}" aria-haspopup="menu" aria-expanded="false" aria-controls="${id}" aria-label="${t("Открыть меню аккаунта", "Open account menu")}"><span class="avatar">${iconSvg("profile", { size: 20 })}</span><span class="account-identity"><b></b><small></small></span><span class="account-more" aria-hidden="true">···</span></button>`;
|
||||
const popup = root.querySelector(".account-menu"),
|
||||
trigger = root.querySelector(".dock-account");
|
||||
const sections = mountAccountSubmenu(popup);
|
||||
if (onThemeChange)
|
||||
popup.insertAdjacentHTML("beforeend", themeControlMarkup({ theme, t }));
|
||||
const themeControl = mountThemeControl(popup, {
|
||||
theme,
|
||||
onChange: onThemeChange,
|
||||
});
|
||||
function update(identity = {}) {
|
||||
root.querySelector(".account-identity b").textContent =
|
||||
identity.name || t("Аккаунт", "Account");
|
||||
@@ -123,6 +133,7 @@ export function mountAccountMenu(
|
||||
);
|
||||
return {
|
||||
update,
|
||||
setTheme: themeControl.update,
|
||||
close,
|
||||
setActive(id) {
|
||||
popup.querySelectorAll("[data-account-page]").forEach((button) => {
|
||||
@@ -136,6 +147,7 @@ export function mountAccountMenu(
|
||||
close();
|
||||
abort.abort();
|
||||
sections.dispose();
|
||||
themeControl.dispose();
|
||||
trigger.removeAttribute("popovertarget");
|
||||
},
|
||||
};
|
||||
|
||||
@@ -109,6 +109,7 @@ export async function exportSystem(
|
||||
"components/copy-field.js",
|
||||
"components/error-page.js",
|
||||
"components/account-submenu.js",
|
||||
"components/theme-control.js",
|
||||
"components/search-select.js",
|
||||
"components/workspaces.css",
|
||||
"components/ssh-console.js",
|
||||
|
||||
@@ -3118,6 +3118,42 @@ body[data-concept="dock"] .copy-input .input-copy-action:active {
|
||||
transform: none;
|
||||
}
|
||||
|
||||
.account-theme-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
padding: 10px 6px 3px;
|
||||
margin-top: 6px;
|
||||
border-top: 1px solid var(--color-border);
|
||||
font-size: 12px;
|
||||
color: var(--color-muted);
|
||||
}
|
||||
.account-theme-options {
|
||||
display: flex;
|
||||
gap: 3px;
|
||||
padding: 3px;
|
||||
border-radius: 999px;
|
||||
background: var(--color-bg);
|
||||
}
|
||||
.account-menu .account-theme-options button {
|
||||
display: grid;
|
||||
place-items: center;
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
min-height: 32px;
|
||||
padding: 8px;
|
||||
border-radius: 50%;
|
||||
color: var(--color-muted);
|
||||
}
|
||||
.account-menu .account-theme-options button[aria-pressed="true"] {
|
||||
background: var(--color-row-active);
|
||||
color: var(--color-accent);
|
||||
}
|
||||
.account-menu .account-theme-options button:focus-visible {
|
||||
outline: 2px solid var(--color-accent);
|
||||
outline-offset: -2px;
|
||||
}
|
||||
.account-menu .account-parent {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1fr) 32px;
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
import { iconSvg } from "../icons/icons.js";
|
||||
export function themeControlMarkup({ theme = "light", t = (ru) => ru } = {}) {
|
||||
return `<div class="account-theme-row"><span>${t("Тема", "Theme")}</span><div class="account-theme-options" role="group" aria-label="${t("Цветовая тема", "Color theme")}">${["light", "dark"].map((mode) => `<button type="button" data-account-theme="${mode}" aria-pressed="${mode === theme}" aria-label="${mode === "light" ? t("Светлая тема", "Light theme") : t("Тёмная тема", "Dark theme")}" title="${mode === "light" ? t("Светлая тема", "Light theme") : t("Тёмная тема", "Dark theme")}">${iconSvg(mode === "light" ? "sun" : "moon", { size: 16 })}</button>`).join("")}</div></div>`;
|
||||
}
|
||||
export function mountThemeControl(root, { theme = "light", onChange } = {}) {
|
||||
const abort = new AbortController();
|
||||
function update(mode) {
|
||||
root
|
||||
.querySelectorAll("[data-account-theme]")
|
||||
.forEach((button) =>
|
||||
button.setAttribute(
|
||||
"aria-pressed",
|
||||
String(button.dataset.accountTheme === mode),
|
||||
),
|
||||
);
|
||||
}
|
||||
root.addEventListener(
|
||||
"click",
|
||||
(event) => {
|
||||
const button = event.target.closest("[data-account-theme]");
|
||||
if (!button) return;
|
||||
event.stopPropagation();
|
||||
update(button.dataset.accountTheme);
|
||||
onChange?.(button.dataset.accountTheme);
|
||||
},
|
||||
{ signal: abort.signal },
|
||||
);
|
||||
update(theme);
|
||||
return { update, dispose: () => abort.abort() };
|
||||
}
|
||||
Reference in new issue
Block a user