@scalio-cloud/ui 0.98.3 → 0.99.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/nav.css +1 -0
- package/package.json +1 -1
- package/react/actions.js +62 -3
- package/react/index.js +31 -13
- package/react/labels.js +4 -0
- package/react/nav.js +10 -4
- package/shell.css +0 -1
package/nav.css
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
}
|
|
14
14
|
.scalio-sidebar-desktop { display: none; }
|
|
15
15
|
@media (min-width: 768px) { .scalio-sidebar-desktop { display: flex; } }
|
|
16
|
+
.scalio-sidebar-desktop.is-collapsed, .scalio-sidebar-desktop[hidden] { display: none; }
|
|
16
17
|
.scalio-sidebar-drawer { display: flex; width: 100%; height: 100%; border-right: 0; }
|
|
17
18
|
.scalio-sidebar-top { padding: 0.75rem 0.75rem 0; }
|
|
18
19
|
.scalio-sidebar-scroll { flex: 1 1 auto; overflow-y: auto; padding: 0.5rem 0 0.75rem; }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scalio-cloud/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.99.0",
|
|
4
4
|
"description": "Scalio Control Room design tokens, Tailwind preset, self-hosted fonts, the shared app header, sign-in layout, sidebar and page blocks",
|
|
5
5
|
"license": "SEE LICENSE IN README.md",
|
|
6
6
|
"private": false,
|
package/react/actions.js
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
// - Main action (from 0.55.0, Markus 2026-11-10): the one blue button above Übersicht in the sidebar is always the
|
|
4
4
|
// main action of the page you are on («+ Kunde», «+ Umgebung», «Export hochladen», «+ Benutzer hinzufügen»). A
|
|
5
5
|
// page declares it with <MainAction label icon to|onSelect />; without one the sidebar shows the app's
|
|
6
|
-
// primaryAction (the main action of the start page). On phones (no sidebar)
|
|
7
|
-
// place. A page never shows its main action a second time.
|
|
6
|
+
// primaryAction (the main action of the start page). On phones (no sidebar) and while the person has hidden the
|
|
7
|
+
// sidebar (burger, 0.99.0) MainAction renders a blue button in place. A page never shows its main action a second time.
|
|
8
8
|
// - Further actions (Feststellungen, Versionen vergleichen, Zurück) stay in the page header, never blue.
|
|
9
9
|
// <PageActions> renders them in place; ActionSlot renders nothing (0.18.0 to 0.53.x moved them into the sidebar).
|
|
10
10
|
const React = require("react");
|
|
@@ -92,6 +92,62 @@ function useSidebarHost(on) {
|
|
|
92
92
|
};
|
|
93
93
|
}, [on]);
|
|
94
94
|
}
|
|
95
|
+
// Desktop sidebar hidden by the person (burger in the header, Ctrl/⌘+B; Markus 2026-11-29). Kept per browser in
|
|
96
|
+
// localStorage; without storage it simply starts shown. The drawer below 768px is not affected.
|
|
97
|
+
const NAV_KEY = "scalio.nav.collapsed";
|
|
98
|
+
function readCollapsed() {
|
|
99
|
+
try {
|
|
100
|
+
return typeof window !== "undefined" && !!window.localStorage && window.localStorage.getItem(NAV_KEY) === "1";
|
|
101
|
+
} catch (e) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
let navCollapsed = readCollapsed();
|
|
106
|
+
const navListeners = new Set();
|
|
107
|
+
function subscribeNav(fn) {
|
|
108
|
+
navListeners.add(fn);
|
|
109
|
+
return () => navListeners.delete(fn);
|
|
110
|
+
}
|
|
111
|
+
function setNavCollapsed(on) {
|
|
112
|
+
const next = !!on;
|
|
113
|
+
if (next === navCollapsed) return;
|
|
114
|
+
navCollapsed = next;
|
|
115
|
+
try {
|
|
116
|
+
if (typeof window !== "undefined" && window.localStorage) {
|
|
117
|
+
if (next) window.localStorage.setItem(NAV_KEY, "1");
|
|
118
|
+
else window.localStorage.removeItem(NAV_KEY);
|
|
119
|
+
}
|
|
120
|
+
} catch (e) {
|
|
121
|
+
// storage blocked: the state still holds for this page
|
|
122
|
+
}
|
|
123
|
+
navListeners.forEach((fn) => fn());
|
|
124
|
+
}
|
|
125
|
+
function toggleNavCollapsed() {
|
|
126
|
+
setNavCollapsed(!navCollapsed);
|
|
127
|
+
}
|
|
128
|
+
function useNavCollapsed() {
|
|
129
|
+
return React.useSyncExternalStore(subscribeNav, () => navCollapsed, () => false);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Ctrl/⌘+B toggles the sidebar. One listener for the page, however many sidebars are mounted (else two would cancel).
|
|
133
|
+
function onNavKey(e) {
|
|
134
|
+
if (!(e.ctrlKey || e.metaKey) || e.altKey || e.shiftKey || String(e.key).toLowerCase() !== "b") return;
|
|
135
|
+
const t = e.target;
|
|
136
|
+
if (t && (t.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName || ""))) return;
|
|
137
|
+
e.preventDefault();
|
|
138
|
+
toggleNavCollapsed();
|
|
139
|
+
}
|
|
140
|
+
let navKeyUsers = 0;
|
|
141
|
+
function useNavShortcut(on) {
|
|
142
|
+
React.useEffect(() => {
|
|
143
|
+
if (!on || typeof document === "undefined") return undefined;
|
|
144
|
+
if (navKeyUsers++ === 0) document.addEventListener("keydown", onNavKey);
|
|
145
|
+
return () => {
|
|
146
|
+
if (--navKeyUsers === 0) document.removeEventListener("keydown", onNavKey);
|
|
147
|
+
};
|
|
148
|
+
}, [on]);
|
|
149
|
+
}
|
|
150
|
+
|
|
95
151
|
function useHasSidebar() {
|
|
96
152
|
return React.useSyncExternalStore(subscribeSidebars, () => sidebars > 0, () => false);
|
|
97
153
|
}
|
|
@@ -137,4 +193,7 @@ function PageActions({ children }) {
|
|
|
137
193
|
return h(React.Fragment, null, children);
|
|
138
194
|
}
|
|
139
195
|
|
|
140
|
-
module.exports = {
|
|
196
|
+
module.exports = {
|
|
197
|
+
PageActions, ActionSlot, useActionSlot, useDesktop, setActionSlot, MainAction, useMainAction, useSidebarHost,
|
|
198
|
+
useNavCollapsed, setNavCollapsed, toggleNavCollapsed, useNavShortcut,
|
|
199
|
+
};
|
package/react/index.js
CHANGED
|
@@ -5,6 +5,7 @@ const React = require("react");
|
|
|
5
5
|
const h = React.createElement;
|
|
6
6
|
const Icons = require("./icons");
|
|
7
7
|
const { LABELS, labelsFor } = require("./labels");
|
|
8
|
+
const { useDesktop, useNavCollapsed, toggleNavCollapsed } = require("./actions");
|
|
8
9
|
|
|
9
10
|
const TEST_IDS = {
|
|
10
11
|
menu: "mobile-menu-btn",
|
|
@@ -298,25 +299,42 @@ function Brand({ brand, lang, labels }) {
|
|
|
298
299
|
|
|
299
300
|
// Header: [menu] brand, left slot ... app actions, status, language, theme, manual, support, avatar.
|
|
300
301
|
// The part from status to avatar has the same order in every app.
|
|
302
|
+
// Burger left of the logo (Markus 2026-11-29): from 768px it hides and shows the sidebar (also Ctrl/⌘+B), below it
|
|
303
|
+
// opens the drawer (onMenu).
|
|
304
|
+
function menuShortcut(lang) {
|
|
305
|
+
const n = typeof navigator !== "undefined" ? navigator : undefined;
|
|
306
|
+
const platform = n ? (n.userAgentData && n.userAgentData.platform) || n.platform || n.userAgent || "" : "";
|
|
307
|
+
if (/mac|iphone|ipad|ipod/i.test(platform)) return "⌘B";
|
|
308
|
+
return lang === "en" ? "Ctrl+B" : "Strg+B";
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function MenuToggle({ onMenu, labels, lang, testId }) {
|
|
312
|
+
const desktop = useDesktop();
|
|
313
|
+
const collapsed = useNavCollapsed();
|
|
314
|
+
const label = desktop ? (collapsed ? labels.showMenu : labels.hideMenu) : labels.menu;
|
|
315
|
+
return h(
|
|
316
|
+
"button",
|
|
317
|
+
{
|
|
318
|
+
type: "button",
|
|
319
|
+
className: "scalio-btn scalio-btn-icon scalio-menu-toggle",
|
|
320
|
+
"aria-label": label,
|
|
321
|
+
title: desktop ? `${label} (${menuShortcut(lang)})` : undefined,
|
|
322
|
+
"aria-expanded": desktop ? !collapsed : undefined,
|
|
323
|
+
"aria-controls": desktop ? "scalio-sidebar" : undefined,
|
|
324
|
+
"data-testid": testId,
|
|
325
|
+
onClick: () => (desktop ? toggleNavCollapsed() : onMenu()),
|
|
326
|
+
},
|
|
327
|
+
h(Icons.Menu, { className: "scalio-icon" })
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
|
|
301
331
|
function AppHeader(props) {
|
|
302
332
|
const L = labelsFor(props.lang, props.labels);
|
|
303
333
|
const T = Object.assign({}, TEST_IDS, props.testIds);
|
|
304
334
|
return h(
|
|
305
335
|
"header",
|
|
306
336
|
{ className: cx("scalio-header", props.className), "data-testid": props.testId || "app-header" },
|
|
307
|
-
props.onMenu
|
|
308
|
-
? h(
|
|
309
|
-
"button",
|
|
310
|
-
{
|
|
311
|
-
type: "button",
|
|
312
|
-
className: "scalio-btn scalio-btn-icon scalio-menu-toggle",
|
|
313
|
-
"aria-label": L.menu,
|
|
314
|
-
"data-testid": T.menu,
|
|
315
|
-
onClick: props.onMenu,
|
|
316
|
-
},
|
|
317
|
-
h(Icons.Menu, { className: "scalio-icon" })
|
|
318
|
-
)
|
|
319
|
-
: null,
|
|
337
|
+
props.onMenu ? h(MenuToggle, { onMenu: props.onMenu, labels: L, lang: props.lang, testId: T.menu }) : null,
|
|
320
338
|
h(Brand, { brand: props.brand, lang: props.lang, labels: props.labels }),
|
|
321
339
|
props.left ? h("div", { className: "scalio-header-left" }, props.left) : null,
|
|
322
340
|
h("div", { className: "scalio-header-spacer" }),
|
package/react/labels.js
CHANGED
|
@@ -109,6 +109,8 @@ const LABELS = {
|
|
|
109
109
|
search: "Suchen",
|
|
110
110
|
navigation: "Navigation",
|
|
111
111
|
closeMenu: "Menü schliessen",
|
|
112
|
+
hideMenu: "Menü ausblenden",
|
|
113
|
+
showMenu: "Menü einblenden",
|
|
112
114
|
// Command palette (⌘K)
|
|
113
115
|
paletteTitle: "Suche",
|
|
114
116
|
palettePlaceholder: "Seite oder Befehl suchen …",
|
|
@@ -717,6 +719,8 @@ const LABELS = {
|
|
|
717
719
|
search: "Search",
|
|
718
720
|
navigation: "Navigation",
|
|
719
721
|
closeMenu: "Close menu",
|
|
722
|
+
hideMenu: "Hide menu",
|
|
723
|
+
showMenu: "Show menu",
|
|
720
724
|
// Command palette (⌘K)
|
|
721
725
|
paletteTitle: "Search",
|
|
722
726
|
palettePlaceholder: "Find a page or command …",
|
package/react/nav.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
const React = require("react");
|
|
6
6
|
const h = React.createElement;
|
|
7
7
|
const Icons = require("./icons");
|
|
8
|
-
const { useMainAction, useSidebarHost } = require("./actions");
|
|
8
|
+
const { useMainAction, useSidebarHost, useNavCollapsed, useNavShortcut } = require("./actions");
|
|
9
9
|
const { labelsFor } = require("./labels");
|
|
10
10
|
const { LegalLink, legalUrl: legalHref } = require("./legal");
|
|
11
11
|
|
|
@@ -102,7 +102,8 @@ function SearchButton({ search, lang, labels, testIdPrefix, onNavigate }) {
|
|
|
102
102
|
);
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
// Sidebar. variant "desktop" shows from 768px, "drawer" is the same
|
|
105
|
+
// Sidebar. variant "desktop" shows from 768px (unless hidden with the burger, useNavCollapsed), "drawer" is the same
|
|
106
|
+
// content inside NavDrawer.
|
|
106
107
|
// link: the router's NavLink (gets to, end, className(fn), onClick); without it plain <a> + activePath.
|
|
107
108
|
// One button in the sidebar, above Übersicht: the main action of the current page (<MainAction>, react/actions.js),
|
|
108
109
|
// else primaryAction, the main action of the start page (Markus 2026-11-10). No buttons below Übersicht.
|
|
@@ -117,7 +118,10 @@ function Sidebar(props) {
|
|
|
117
118
|
const sections = visibleSections(nav);
|
|
118
119
|
const rest = sections;
|
|
119
120
|
const pageMain = useMainAction();
|
|
120
|
-
|
|
121
|
+
const desktopVariant = variant !== "drawer";
|
|
122
|
+
const collapsed = useNavCollapsed() && desktopVariant;
|
|
123
|
+
useSidebarHost(desktopVariant && !collapsed);
|
|
124
|
+
useNavShortcut(desktopVariant);
|
|
121
125
|
const section = (sec, i) =>
|
|
122
126
|
h(
|
|
123
127
|
"div",
|
|
@@ -128,7 +132,9 @@ function Sidebar(props) {
|
|
|
128
132
|
return h(
|
|
129
133
|
"nav",
|
|
130
134
|
{
|
|
131
|
-
className: cx("scalio-sidebar", variant === "drawer" ? "scalio-sidebar-drawer" : "scalio-sidebar-desktop"),
|
|
135
|
+
className: cx("scalio-sidebar", variant === "drawer" ? "scalio-sidebar-drawer" : "scalio-sidebar-desktop", collapsed && "is-collapsed"),
|
|
136
|
+
id: desktopVariant ? "scalio-sidebar" : undefined,
|
|
137
|
+
hidden: collapsed || undefined,
|
|
132
138
|
"aria-label": L.navigation,
|
|
133
139
|
"data-testid": testId || `${prefix}sidebar-nav`,
|
|
134
140
|
},
|
package/shell.css
CHANGED
|
@@ -70,7 +70,6 @@ a.scalio-btn { text-decoration: none; }
|
|
|
70
70
|
.scalio-hide-sm { display: none; }
|
|
71
71
|
@media (min-width: 640px) { .scalio-hide-sm { display: inline; } }
|
|
72
72
|
.scalio-menu-toggle { display: inline-flex; }
|
|
73
|
-
@media (min-width: 768px) { .scalio-menu-toggle { display: none; } }
|
|
74
73
|
|
|
75
74
|
.scalio-avatar {
|
|
76
75
|
width: 2.25rem; height: 2.25rem; flex-shrink: 0; border: 0; border-radius: 2px; cursor: pointer;
|