Add four-icon mobile bottom Dock with recent sections
This commit is contained in:
1 parent
c3257a0f4d
commit
03c590e172
20 files changed
+547
-5
No files matched your search
@@ -43,7 +43,10 @@ export function mountAccountSubmenu(parent) {
|
||||
ox = window.visualViewport?.offsetLeft || 0;
|
||||
if (parent.matches(":popover-open") && vw < 508) {
|
||||
parent.style.width = Math.max(100, Math.floor((vw - 36) / 2)) + "px";
|
||||
parent.style.left = ox + 12 + "px";
|
||||
parent.style.left =
|
||||
(parent.closest("[data-mobile-account]")
|
||||
? ox + vw - Math.max(100, Math.floor((vw - 36) / 2)) - 12
|
||||
: ox + 12) + "px";
|
||||
} else {
|
||||
parent.style.width = original.width;
|
||||
parent.style.left = original.left;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { mobileDockQuery } from "./mobile-dock.js";
|
||||
/** One document-wide Dock shell. The host owns routes and active nav items. */
|
||||
export function mountDock({
|
||||
navigation,
|
||||
@@ -77,6 +78,7 @@ export function mountDock({
|
||||
clearTimeout(timer);
|
||||
if (
|
||||
e.pointerType === "mouse" &&
|
||||
!matchMedia(mobileDockQuery).matches &&
|
||||
matchMedia("(hover:hover) and (pointer:fine)").matches
|
||||
)
|
||||
setOpen(true);
|
||||
|
||||
@@ -109,6 +109,8 @@ export async function exportSystem(
|
||||
"components/copy-field.js",
|
||||
"components/error-page.js",
|
||||
"components/account-submenu.js",
|
||||
"components/mobile-dock.js",
|
||||
"components/mobile-dock.css",
|
||||
"components/theme-control.js",
|
||||
"components/search-select.js",
|
||||
"components/workspaces.css",
|
||||
|
||||
@@ -0,0 +1,264 @@
|
||||
.mobile-recent,
|
||||
.mobile-menu-icon {
|
||||
display: none;
|
||||
}
|
||||
@media (max-width: 600px),
|
||||
(max-width: 900px) and (hover: none) and (pointer: coarse) {
|
||||
body[data-concept="dock"] .shell:has(> .navigation[data-mobile-dock]) {
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
gap: 0;
|
||||
padding: 6px calc(6px + env(safe-area-inset-right, 0px))
|
||||
calc(88px + env(safe-area-inset-bottom, 0px))
|
||||
calc(6px + env(safe-area-inset-left, 0px));
|
||||
}
|
||||
body[data-concept="dock"]
|
||||
.shell:has(> .navigation[data-mobile-dock])
|
||||
> .main-column {
|
||||
grid-column: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
body[data-concept="dock"]
|
||||
.shell:has(> .navigation[data-mobile-dock])
|
||||
.mobile-menu {
|
||||
display: none;
|
||||
}
|
||||
body[data-concept="dock"] .shell > .navigation[data-mobile-dock] {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, minmax(0, 1fr));
|
||||
grid-template-rows: 1fr;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
position: fixed;
|
||||
top: auto;
|
||||
left: calc(8px + env(safe-area-inset-left, 0px));
|
||||
right: calc(8px + env(safe-area-inset-right, 0px));
|
||||
bottom: calc(8px + env(safe-area-inset-bottom, 0px));
|
||||
width: calc(
|
||||
100% - 16px - env(safe-area-inset-left, 0px) -
|
||||
env(safe-area-inset-right, 0px)
|
||||
);
|
||||
max-width: none;
|
||||
height: 64px;
|
||||
padding: 6px;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 18px;
|
||||
overflow: visible;
|
||||
box-shadow: 0 6px 24px #07181f24;
|
||||
}
|
||||
body[data-concept="dock"]
|
||||
.shell
|
||||
> .navigation[data-mobile-dock]
|
||||
> .mobile-recent {
|
||||
display: grid;
|
||||
place-items: center;
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
height: 50px;
|
||||
min-height: 44px;
|
||||
padding: 10px;
|
||||
border: 0;
|
||||
border-radius: 12px;
|
||||
background: transparent;
|
||||
color: var(--color-text);
|
||||
grid-row: 1;
|
||||
}
|
||||
body[data-concept="dock"]
|
||||
.shell
|
||||
> .navigation[data-mobile-dock]
|
||||
> .mobile-recent-current {
|
||||
grid-column: 1;
|
||||
background: var(--color-row-active);
|
||||
color: var(--color-accent);
|
||||
}
|
||||
body[data-concept="dock"]
|
||||
.shell
|
||||
> .navigation[data-mobile-dock]
|
||||
> .mobile-recent-previous {
|
||||
grid-column: 2;
|
||||
}
|
||||
body[data-concept="dock"]
|
||||
.shell
|
||||
> .navigation[data-mobile-dock]
|
||||
> .mobile-recent:disabled {
|
||||
background: transparent;
|
||||
opacity: 0.35;
|
||||
}
|
||||
body[data-concept="dock"]
|
||||
.shell
|
||||
> .navigation[data-mobile-dock]
|
||||
> .dock-brand {
|
||||
grid-column: 3;
|
||||
grid-row: 1;
|
||||
display: grid;
|
||||
grid-template-columns: 1fr;
|
||||
place-items: center;
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
height: 50px;
|
||||
padding: 10px;
|
||||
gap: 0;
|
||||
border-radius: 12px;
|
||||
color: var(--color-text);
|
||||
}
|
||||
body[data-concept="dock"]
|
||||
.shell
|
||||
> .navigation[data-mobile-dock]
|
||||
> .dock-brand
|
||||
> :not(.mobile-menu-icon) {
|
||||
display: none;
|
||||
}
|
||||
body[data-concept="dock"]
|
||||
.shell
|
||||
> .navigation[data-mobile-dock]
|
||||
> .dock-brand
|
||||
> .mobile-menu-icon {
|
||||
display: grid;
|
||||
place-items: center;
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
opacity: 1;
|
||||
}
|
||||
body[data-concept="dock"]
|
||||
.shell
|
||||
> .navigation[data-mobile-dock]
|
||||
> .dock-brand
|
||||
> .mobile-menu-icon
|
||||
svg {
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
transform: none;
|
||||
}
|
||||
body[data-concept="dock"]
|
||||
.shell
|
||||
> .navigation[data-mobile-dock]
|
||||
> .dock-brand[aria-expanded="true"] {
|
||||
background: var(--color-row-active);
|
||||
color: var(--color-accent);
|
||||
}
|
||||
body[data-concept="dock"]
|
||||
.shell
|
||||
> .navigation[data-mobile-dock]
|
||||
> .dock-account-area {
|
||||
grid-column: 4;
|
||||
grid-row: 1;
|
||||
width: 100%;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
min-width: 0;
|
||||
}
|
||||
body[data-concept="dock"]
|
||||
.shell
|
||||
> .navigation[data-mobile-dock]
|
||||
.dock-account {
|
||||
display: grid;
|
||||
place-items: center;
|
||||
width: 100%;
|
||||
height: 50px;
|
||||
min-height: 44px;
|
||||
padding: 8px;
|
||||
gap: 0;
|
||||
border-radius: 12px;
|
||||
}
|
||||
body[data-concept="dock"]
|
||||
.shell
|
||||
> .navigation[data-mobile-dock]
|
||||
.dock-account
|
||||
> .avatar {
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
margin: 0;
|
||||
}
|
||||
body[data-concept="dock"]
|
||||
.shell
|
||||
> .navigation[data-mobile-dock]
|
||||
:is(.account-identity, .account-more),
|
||||
body[data-concept="dock"]
|
||||
.shell
|
||||
> .navigation[data-mobile-dock]
|
||||
> :is(.workspace-label, .nav-bottom) {
|
||||
display: none;
|
||||
}
|
||||
body[data-concept="dock"]
|
||||
.shell
|
||||
> .navigation[data-mobile-dock]
|
||||
> .nav-links {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: calc(100% + 10px);
|
||||
width: 100%;
|
||||
max-height: min(
|
||||
68dvh,
|
||||
calc(100dvh - 112px - env(safe-area-inset-bottom, 0px))
|
||||
);
|
||||
padding: 10px;
|
||||
margin: 0;
|
||||
background: var(--color-surface);
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 18px;
|
||||
box-shadow: 0 -8px 32px #07181f24;
|
||||
overflow-y: auto;
|
||||
overscroll-behavior: contain;
|
||||
scrollbar-width: thin;
|
||||
}
|
||||
body[data-concept="dock"]:not(.dock-open)
|
||||
.shell
|
||||
> .navigation[data-mobile-dock]
|
||||
> .nav-links {
|
||||
display: none;
|
||||
}
|
||||
body[data-concept="dock"].dock-open
|
||||
.shell
|
||||
> .navigation[data-mobile-dock]
|
||||
> .nav-links {
|
||||
display: flex;
|
||||
}
|
||||
body[data-concept="dock"]
|
||||
.shell
|
||||
> .navigation[data-mobile-dock]
|
||||
> .nav-links::before {
|
||||
content: attr(data-mobile-menu-label);
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: var(--color-muted);
|
||||
padding: 4px 12px 10px;
|
||||
}
|
||||
body[data-concept="dock"]
|
||||
.shell
|
||||
> .navigation[data-mobile-dock]
|
||||
> .nav-links
|
||||
button {
|
||||
grid-template-columns: 40px minmax(0, 1fr);
|
||||
gap: 8px;
|
||||
min-height: 46px;
|
||||
white-space: normal;
|
||||
text-align: left;
|
||||
}
|
||||
body[data-concept="dock"]
|
||||
.shell
|
||||
> .navigation[data-mobile-dock]
|
||||
> .nav-links
|
||||
button
|
||||
> span {
|
||||
opacity: 1;
|
||||
}
|
||||
body[data-concept="dock"]
|
||||
.shell
|
||||
> .navigation[data-mobile-dock]
|
||||
:is(.mobile-recent, .dock-brand, .dock-account):active {
|
||||
transform: none;
|
||||
}
|
||||
body[data-concept="dock"]
|
||||
.shell
|
||||
> .navigation[data-mobile-dock]
|
||||
.account-menu {
|
||||
bottom: calc(82px + env(safe-area-inset-bottom, 0px));
|
||||
left: auto;
|
||||
right: calc(8px + env(safe-area-inset-right, 0px));
|
||||
}
|
||||
body[data-session="authenticated"]:has(.navigation[data-mobile-dock])
|
||||
:is(#toast, .anidev-toast) {
|
||||
bottom: calc(88px + env(safe-area-inset-bottom, 0px));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
import { iconSvg, iconNames } from "../icons/icons.js";
|
||||
/** Host may retain this across shell re-renders. Never persist across sign-out. */
|
||||
export const createMobileHistory = () => ({
|
||||
current: null,
|
||||
previous: null,
|
||||
context: null,
|
||||
});
|
||||
export const mobileDockQuery =
|
||||
"(max-width:600px), (max-width:900px) and (hover:none) and (pointer:coarse)";
|
||||
export function mountMobileDock(
|
||||
navigation,
|
||||
{
|
||||
trigger,
|
||||
getPage,
|
||||
onNavigate,
|
||||
onCloseMenu,
|
||||
t = (ru) => ru,
|
||||
history = createMobileHistory(),
|
||||
} = {},
|
||||
) {
|
||||
navigation.dataset.mobileDock = "";
|
||||
const abort = new AbortController(),
|
||||
{ signal } = abort,
|
||||
media = matchMedia(mobileDockQuery);
|
||||
const current = document.createElement("button"),
|
||||
previous = document.createElement("button"),
|
||||
menuIcon = document.createElement("span");
|
||||
current.type = previous.type = "button";
|
||||
current.className = "mobile-recent mobile-recent-current";
|
||||
previous.className = "mobile-recent mobile-recent-previous";
|
||||
current.setAttribute("aria-current", "page");
|
||||
menuIcon.className = "mobile-menu-icon";
|
||||
menuIcon.setAttribute("aria-hidden", "true");
|
||||
navigation.prepend(current, previous);
|
||||
trigger.append(menuIcon);
|
||||
const links = navigation.querySelector(".nav-links"),
|
||||
account = navigation.querySelector(".dock-account-area");
|
||||
const controls = trigger.getAttribute("aria-controls");
|
||||
if (links) {
|
||||
links.id ||= (navigation.id || "anidev-navigation") + "-sections";
|
||||
links.dataset.mobileMenuLabel = t("Полное меню", "All sections");
|
||||
}
|
||||
function paint(button, page, fallback) {
|
||||
button.disabled = !page;
|
||||
button.innerHTML = iconSvg(
|
||||
page && iconNames.includes(page.icon) ? page.icon : fallback,
|
||||
{ size: 24 },
|
||||
);
|
||||
button.setAttribute(
|
||||
"aria-label",
|
||||
page
|
||||
? `${button === current ? t("Текущий раздел", "Current section") : t("Предыдущий раздел", "Previous section")}: ${page.label}`
|
||||
: button === current
|
||||
? t("Нет текущего раздела", "No current section")
|
||||
: t("Предыдущего раздела пока нет", "No previous section yet"),
|
||||
);
|
||||
button.title = button.getAttribute("aria-label");
|
||||
}
|
||||
function sync() {
|
||||
const mobile = media.matches,
|
||||
open = document.body.classList.contains("dock-open");
|
||||
if (account) {
|
||||
if (mobile) account.dataset.mobileAccount = "";
|
||||
else delete account.dataset.mobileAccount;
|
||||
}
|
||||
menuIcon.innerHTML = iconSvg(open ? "close" : "menu", { size: 24 });
|
||||
if (mobile) {
|
||||
trigger.setAttribute(
|
||||
"aria-label",
|
||||
open
|
||||
? t("Закрыть полное меню", "Close all sections")
|
||||
: t("Полное меню", "All sections"),
|
||||
);
|
||||
trigger.setAttribute("aria-controls", links?.id || navigation.id);
|
||||
} else {
|
||||
trigger.setAttribute(
|
||||
"aria-label",
|
||||
open
|
||||
? t("Свернуть меню", "Collapse navigation")
|
||||
: t("Развернуть меню", "Expand navigation"),
|
||||
);
|
||||
if (controls) trigger.setAttribute("aria-controls", controls);
|
||||
}
|
||||
}
|
||||
function update(id, context = "default") {
|
||||
if (history.context !== context) {
|
||||
history.current = null;
|
||||
history.previous = null;
|
||||
history.context = context;
|
||||
}
|
||||
const page = id ? getPage(id) : null;
|
||||
if (!page) {
|
||||
history.current = null;
|
||||
history.previous = null;
|
||||
} else if (history.current?.id !== page.id) {
|
||||
history.previous = history.current;
|
||||
history.current = { ...page };
|
||||
} else history.current = { ...page };
|
||||
if (history.previous)
|
||||
history.previous = getPage(history.previous.id) || null;
|
||||
paint(current, history.current, "dashboard");
|
||||
paint(previous, history.previous, "arrow-left");
|
||||
sync();
|
||||
}
|
||||
previous.addEventListener(
|
||||
"click",
|
||||
() => {
|
||||
const page = history.previous && getPage(history.previous.id);
|
||||
if (page) {
|
||||
onCloseMenu?.();
|
||||
onNavigate(page.id);
|
||||
}
|
||||
},
|
||||
{ signal },
|
||||
);
|
||||
navigation.addEventListener(
|
||||
"click",
|
||||
(event) => {
|
||||
if (
|
||||
media.matches &&
|
||||
event.target.closest("[data-page],[data-nav-id],[data-account-page]")
|
||||
)
|
||||
onCloseMenu?.();
|
||||
},
|
||||
{ signal },
|
||||
);
|
||||
media.addEventListener(
|
||||
"change",
|
||||
() => {
|
||||
onCloseMenu?.();
|
||||
sync();
|
||||
},
|
||||
{ signal },
|
||||
);
|
||||
const observer = new MutationObserver(sync);
|
||||
observer.observe(document.body, {
|
||||
attributes: true,
|
||||
attributeFilter: ["class"],
|
||||
});
|
||||
sync();
|
||||
paint(current, null, "dashboard");
|
||||
paint(previous, null, "arrow-left");
|
||||
return {
|
||||
update,
|
||||
reset() {
|
||||
history.current = null;
|
||||
history.previous = null;
|
||||
history.context = null;
|
||||
paint(current, null, "dashboard");
|
||||
paint(previous, null, "arrow-left");
|
||||
},
|
||||
dispose() {
|
||||
abort.abort();
|
||||
observer.disconnect();
|
||||
current.remove();
|
||||
previous.remove();
|
||||
menuIcon.remove();
|
||||
delete navigation.dataset.mobileDock;
|
||||
if (account) delete account.dataset.mobileAccount;
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
@import url("./workspaces.css");
|
||||
@import url("./mobile-dock.css");
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user