Refocus responsive layouts on compact desktop use
All checks were successful
Deploy Sokko G / deploy (push) Successful in 19s

This commit is contained in:
Shinuwa 2026-10-05 15:47:46 +02:00
parent 96d058293d
commit 0ac1a0974e
27 changed files with 610 additions and 190 deletions

View file

@ -1,18 +1,48 @@
// Rôle : structure le layout global avec sidebar, topbar, navigation et contenu.
import { useEffect, useRef } from "react";
import { Icon } from "./Icon.jsx";
import { ImportButton } from "./ImportButton.jsx";
import { Tooltip } from "./Tooltip.jsx";
export function Shell({ route, content, games, drawerGameId = "", actions, children }) {
export function Shell({ route, content, games, drawerGameId = "", drawerVisible = false, compactGameLayout = false, reducedSidebar = false, actions, children }) {
const gameId = route.split("/")[1] === "games" ? route.split("/")[2] || "" : "";
const game = games.find((item) => item.id === gameId);
const topbarLabel = route === "/design-system" && import.meta.env.DEV ? "Design system" : route.startsWith("/toolbox") ? content.topbar.toolbox : route.startsWith("/games") ? content.topbar.games : route === "/library" ? content.topbar.library : content.topbar.dashboard;
const toolboxOpen = Boolean(game && drawerGameId === game.id);
const toolboxOpen = Boolean(game && drawerGameId === game.id && drawerVisible);
const toolboxLabel = toolboxOpen ? "Masquer la toolbox" : "Afficher la toolbox";
const compactSidebar = Boolean(drawerGameId);
const compactSidebar = Boolean(reducedSidebar || (!compactGameLayout && toolboxOpen));
const compactToolboxVisible = Boolean(compactGameLayout && toolboxOpen);
const guideTabRef = useRef(null);
const toolboxTabRef = useRef(null);
const wideToolboxButtonRef = useRef(null);
const focusedViewControlRef = useRef("");
const previousCompactLayoutRef = useRef(compactGameLayout);
useEffect(() => {
const trackFocus = (event) => {
if (event.target.closest?.(".compact-game-view-switch")) focusedViewControlRef.current = "compact";
else if (event.target.closest?.(".toolbox-button")) focusedViewControlRef.current = "wide";
else focusedViewControlRef.current = "";
};
document.addEventListener("focusin", trackFocus);
return () => document.removeEventListener("focusin", trackFocus);
}, []);
useEffect(() => {
const activeElement = document.activeElement;
const layoutChanged = previousCompactLayoutRef.current !== compactGameLayout;
previousCompactLayoutRef.current = compactGameLayout;
if (layoutChanged && compactGameLayout && focusedViewControlRef.current === "wide") {
(compactToolboxVisible ? toolboxTabRef.current : guideTabRef.current)?.focus();
} else if (compactGameLayout && !compactToolboxVisible && activeElement?.closest?.("#toolbox-drawer")) {
guideTabRef.current?.focus();
} else if (layoutChanged && !compactGameLayout && focusedViewControlRef.current === "compact") {
wideToolboxButtonRef.current?.focus();
}
}, [compactGameLayout, compactToolboxVisible]);
return (
<div className={`app-shell ${compactSidebar ? "sidebar-compact" : ""} ${drawerGameId ? "toolbox-drawer-open" : ""}`}>
<div className={`app-shell ${compactSidebar ? "sidebar-compact" : ""} ${!compactGameLayout && toolboxOpen ? "toolbox-drawer-open" : ""} ${compactToolboxVisible ? "compact-toolbox-visible" : ""}`}>
<aside className="sidebar" data-variant={compactSidebar ? "compact" : undefined}>
<a className="brand" href="#/" aria-label={content.brand.homeAriaLabel}>
<span className="brand-mark" aria-hidden="true" />
@ -47,8 +77,12 @@ export function Shell({ route, content, games, drawerGameId = "", actions, child
<div><strong>{topbarLabel}</strong></div>
{game && (
<div className="topbar-actions">
<button
{compactGameLayout ? <div className="compact-game-view-switch nds-radio-button-group" role="tablist" aria-label={content.topbar.gameViewLabel}>
<button ref={guideTabRef} type="button" role="tab" aria-selected={!compactToolboxVisible} className={!compactToolboxVisible ? "active" : ""} onClick={() => actions.setDrawerGameId("")}>{content.topbar.guideView}</button>
<button ref={toolboxTabRef} type="button" role="tab" aria-selected={compactToolboxVisible} className={compactToolboxVisible ? "active" : ""} onClick={() => actions.setDrawerGameId(game.id)}>{content.topbar.toolboxView}</button>
</div> : <button
className={`drawer-button toolbox-button nds-button ${toolboxOpen ? "active" : ""}`}
ref={wideToolboxButtonRef}
data-size="sm"
data-variant="primary"
onClick={() => actions.setDrawerGameId(toolboxOpen ? "" : game.id)}
@ -58,19 +92,12 @@ export function Shell({ route, content, games, drawerGameId = "", actions, child
>
<img src="/static/icons/toolbox.svg" alt="" aria-hidden="true" />
<span>{toolboxLabel}</span>
</button>
</button>}
</div>
)}
</header>
<main>{children}</main>
</div>
<nav className="mobile-nav" aria-label="Navigation mobile">
<a className={route === "/" ? "active" : ""} href="#/">{content.navigation.home}</a>
<a className={route.startsWith("/toolboxes") || route.startsWith("/toolbox") ? "active" : ""} href="#/toolboxes">{content.navigation.toolboxes}</a>
<button className="nds-button" data-size="sm" data-variant="primary" onClick={() => actions.setCreateModal({})}>+</button>
<a className={route === "/library" ? "active" : ""} href="#/library">{content.navigation.mobileLibrary}</a>
<a className={route.startsWith("/games") ? "active" : ""} href="#/games">{content.navigation.mobileGames}</a>
</nav>
</div>
);
}