@olenbetong/synergi-react 2.5.6 → 2.6.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/es/colorScheme.d.ts +17 -0
- package/es/colorScheme.js +54 -0
- package/es/components/AppMenu/AppMenu.css +480 -92
- package/es/components/AppMenu/AppMenu.d.ts +47 -0
- package/es/components/AppMenu/AppMenu.js +224 -0
- package/es/components/AppMenu/AppMenuColorScheme.d.ts +2 -0
- package/es/components/AppMenu/AppMenuColorScheme.js +18 -0
- package/es/components/AppMenu/AppMenuToggle.d.ts +15 -0
- package/es/components/AppMenu/AppMenuToggle.js +14 -0
- package/es/components/AppMenu/AppMenuUserMenu.d.ts +32 -0
- package/es/components/AppMenu/AppMenuUserMenu.js +110 -0
- package/es/components/AppMenu/developerCategories.d.ts +24 -0
- package/es/components/AppMenu/developerCategories.js +116 -0
- package/es/components/AppMenu/index.d.ts +7 -12
- package/es/components/AppMenu/index.js +6 -85
- package/es/components/AppMenu/types.d.ts +33 -0
- package/es/components/AppMenu/types.js +1 -0
- package/es/components/AppMenu/useRovingTabIndex.d.ts +24 -0
- package/es/components/AppMenu/useRovingTabIndex.js +103 -0
- package/es/components/AppMenu/useServiceWorkerUpdate.d.ts +16 -0
- package/es/components/AppMenu/useServiceWorkerUpdate.js +62 -0
- package/es/components/AppShell/index.js +107 -13
- package/es/components/ImageEditor/ImageEditor.css +22 -11
- package/es/components/ImageEditor/ImageEditor.js +12 -12
- package/es/components/ImageEditor/ResponsiveButton.d.ts +1 -1
- package/es/components/ImageEditor/ResponsiveButton.js +5 -5
- package/es/components/ImageEditor/plugins/cropPlugin/CropOverlay.js +2 -2
- package/es/components/ImageEditor/plugins/cropPlugin/CropToolbar.js +3 -4
- package/es/components/ImageEditor/plugins/cropPlugin/index.js +2 -2
- package/es/components/ImageEditor/plugins/redactPlugin/RedactToolbar.js +3 -5
- package/es/components/ImageEditor/plugins/redactPlugin/index.js +2 -2
- package/es/components/ImageEditor/plugins/rotatePlugin.js +1 -2
- package/es/components/ImageEditor/plugins/zoomPlugin/ZoomControls.js +2 -4
- package/es/components/ImageEditor/useIsSmall.d.ts +5 -0
- package/es/components/ImageEditor/useIsSmall.js +21 -0
- package/es/index.d.ts +2 -1
- package/es/index.js +2 -1
- package/package.json +7 -3
- package/src/colorScheme.ts +81 -0
- package/src/components/AppMenu/AppMenu.css +480 -92
- package/src/components/AppMenu/AppMenu.tsx +478 -0
- package/src/components/AppMenu/AppMenuColorScheme.tsx +41 -0
- package/src/components/AppMenu/AppMenuToggle.tsx +51 -0
- package/src/components/AppMenu/AppMenuUserMenu.tsx +190 -0
- package/src/components/AppMenu/developerCategories.ts +142 -0
- package/src/components/AppMenu/index.ts +12 -0
- package/src/components/AppMenu/types.ts +35 -0
- package/src/components/AppMenu/useRovingTabIndex.ts +118 -0
- package/src/components/AppMenu/useServiceWorkerUpdate.ts +68 -0
- package/src/components/AppShell/index.tsx +140 -14
- package/src/components/ImageEditor/ImageEditor.css +22 -11
- package/src/components/ImageEditor/ImageEditor.tsx +38 -40
- package/src/components/ImageEditor/ResponsiveButton.tsx +8 -10
- package/src/components/ImageEditor/plugins/cropPlugin/CropOverlay.tsx +6 -6
- package/src/components/ImageEditor/plugins/cropPlugin/CropToolbar.tsx +6 -10
- package/src/components/ImageEditor/plugins/cropPlugin/index.ts +2 -2
- package/src/components/ImageEditor/plugins/redactPlugin/RedactToolbar.tsx +8 -17
- package/src/components/ImageEditor/plugins/redactPlugin/index.ts +2 -2
- package/src/components/ImageEditor/plugins/rotatePlugin.ts +1 -2
- package/src/components/ImageEditor/plugins/zoomPlugin/ZoomControls.tsx +4 -6
- package/src/components/ImageEditor/useIsSmall.ts +27 -0
- package/src/index.ts +25 -1
- package/src/components/AppMenu/index.tsx +0 -179
|
@@ -0,0 +1,478 @@
|
|
|
1
|
+
import "./AppMenu.css";
|
|
2
|
+
|
|
3
|
+
import { getLocalizedString } from "@olenbetong/appframe-core";
|
|
4
|
+
import type { DataObject } from "@olenbetong/appframe-data";
|
|
5
|
+
import { useData, useLoading } from "@olenbetong/appframe-react";
|
|
6
|
+
import clsx from "clsx";
|
|
7
|
+
import { Fragment, useEffect, useMemo, useRef, useState } from "react";
|
|
8
|
+
|
|
9
|
+
import { AppMenuColorScheme } from "./AppMenuColorScheme.js";
|
|
10
|
+
import { AppMenuUserMenu, type AppMenuUser } from "./AppMenuUserMenu.js";
|
|
11
|
+
import type { AppMenuCategory, AppMenuLink, AppMenuLinkGroup } from "./types.js";
|
|
12
|
+
import { useRovingTabIndex } from "./useRovingTabIndex.js";
|
|
13
|
+
|
|
14
|
+
export type AppMenuArticle = {
|
|
15
|
+
ArticleId: string;
|
|
16
|
+
Title: string | null;
|
|
17
|
+
MenuGroup: string | null;
|
|
18
|
+
Path: string | null;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/** Sentinel group key for apps that have no MenuGroup set. */
|
|
22
|
+
const UNGROUPED = "\u0000ungrouped";
|
|
23
|
+
|
|
24
|
+
/** Strip version suffixes (`my-app.0000012`) from an ArticleId. */
|
|
25
|
+
function stripVersionSuffix(articleId: string): string {
|
|
26
|
+
return articleId.replace(/\.\d+$/, "");
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
type AppEntry = {
|
|
30
|
+
id: string;
|
|
31
|
+
title: string;
|
|
32
|
+
group: string;
|
|
33
|
+
href: string;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Normalize the raw article rows into a deduplicated, sorted list of apps.
|
|
38
|
+
*
|
|
39
|
+
* `aviw_WebShared_Articles` contains one row per published article version, so
|
|
40
|
+
* the same app can appear dozens of times. Deduplicating on the version-less
|
|
41
|
+
* ArticleId guarantees a single entry per app even if the data object's where
|
|
42
|
+
* clause is relaxed.
|
|
43
|
+
*/
|
|
44
|
+
function toAppEntries(articles: readonly AppMenuArticle[]): AppEntry[] {
|
|
45
|
+
let byId = new Map<string, AppEntry>();
|
|
46
|
+
|
|
47
|
+
for (let article of articles) {
|
|
48
|
+
let id = stripVersionSuffix(article.ArticleId);
|
|
49
|
+
if (byId.has(id)) continue;
|
|
50
|
+
|
|
51
|
+
byId.set(id, {
|
|
52
|
+
id,
|
|
53
|
+
title: article.Title?.trim() || id,
|
|
54
|
+
group: article.MenuGroup?.trim() || UNGROUPED,
|
|
55
|
+
href: `/${article.Path?.trim() || id}`,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return [...byId.values()].sort((a, b) => a.title.localeCompare(b.title));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Group entries by group key. Ungrouped apps are always listed last. */
|
|
63
|
+
function groupEntries(entries: readonly AppEntry[]): [string, AppEntry[]][] {
|
|
64
|
+
let map = new Map<string, AppEntry[]>();
|
|
65
|
+
|
|
66
|
+
for (let entry of entries) {
|
|
67
|
+
let list = map.get(entry.group);
|
|
68
|
+
if (!list) {
|
|
69
|
+
list = [];
|
|
70
|
+
map.set(entry.group, list);
|
|
71
|
+
}
|
|
72
|
+
list.push(entry);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return [...map.entries()].sort(([a], [b]) => {
|
|
76
|
+
if (a === b) return 0;
|
|
77
|
+
if (a === UNGROUPED) return 1;
|
|
78
|
+
if (b === UNGROUPED) return -1;
|
|
79
|
+
return a.localeCompare(b);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Drop entries that don't match the search term, then empty groups. */
|
|
84
|
+
function filterCategory(category: AppMenuCategory, term: string): AppMenuCategory {
|
|
85
|
+
if (!term) return category;
|
|
86
|
+
|
|
87
|
+
let groups = category.groups
|
|
88
|
+
.map((group) => ({ ...group, items: group.items.filter((item) => item.label.toLowerCase().includes(term)) }))
|
|
89
|
+
.filter((group) => group.items.length > 0);
|
|
90
|
+
|
|
91
|
+
return { ...category, groups };
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function countItems(category: AppMenuCategory) {
|
|
95
|
+
return category.groups.reduce((total, group) => total + group.items.length, 0);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Split the categories into their rail sections, preserving the given order. */
|
|
99
|
+
function toRailSections(categories: readonly AppMenuCategory[]): [string, AppMenuCategory[]][] {
|
|
100
|
+
let sections = new Map<string, AppMenuCategory[]>();
|
|
101
|
+
|
|
102
|
+
for (let category of categories) {
|
|
103
|
+
let key = category.section ?? "";
|
|
104
|
+
let list = sections.get(key);
|
|
105
|
+
if (!list) {
|
|
106
|
+
list = [];
|
|
107
|
+
sections.set(key, list);
|
|
108
|
+
}
|
|
109
|
+
list.push(category);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return [...sections.entries()];
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
type Selection = { type: "group"; key: string } | { type: "category"; id: string } | null;
|
|
116
|
+
|
|
117
|
+
export type AppMenuProps = {
|
|
118
|
+
/** Data object returning the articles to list. See `AppMenuArticle` for the required fields. */
|
|
119
|
+
dataObject: DataObject<AppMenuArticle>;
|
|
120
|
+
/** Whether the menu is open. The menu is a controlled component. */
|
|
121
|
+
open: boolean;
|
|
122
|
+
/** Called when the menu requests to be closed (backdrop click, Escape, app selected). */
|
|
123
|
+
onClose: () => void;
|
|
124
|
+
/**
|
|
125
|
+
* Extra categories listed below the app categories in the rail, showing a
|
|
126
|
+
* fixed set of links instead of apps. See `createDeveloperCategories`.
|
|
127
|
+
*/
|
|
128
|
+
categories?: AppMenuCategory[];
|
|
129
|
+
/** Data object over `aviw_General_SidebarUserInfo`. Enables the user menu in the header. */
|
|
130
|
+
userDataObject?: DataObject<AppMenuUser>;
|
|
131
|
+
/** Overrides the default user menu entries. */
|
|
132
|
+
userMenuItems?: AppMenuLink[];
|
|
133
|
+
/** Shown below the user's name. Defaults to `af.userSession.domain`. */
|
|
134
|
+
userSubtitle?: string;
|
|
135
|
+
/**
|
|
136
|
+
* Shows a highlighted "install update" button in the menu header. Pair with
|
|
137
|
+
* `useServiceWorkerUpdate()`.
|
|
138
|
+
*/
|
|
139
|
+
hasUpdate?: boolean;
|
|
140
|
+
/** Called when the install update button is pressed. */
|
|
141
|
+
onInstallUpdate?: () => void;
|
|
142
|
+
id?: string;
|
|
143
|
+
className?: string;
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Two pane application menu. The left rail holds a local search field and the
|
|
148
|
+
* list of app categories (`MenuGroup`); the right pane lists the apps in the
|
|
149
|
+
* selected category, or every app when no category is selected.
|
|
150
|
+
*
|
|
151
|
+
* On narrow viewports only one pane is visible at a time, defaulting to the app
|
|
152
|
+
* list, with a button to switch to the category list.
|
|
153
|
+
*/
|
|
154
|
+
export function AppMenu({
|
|
155
|
+
dataObject,
|
|
156
|
+
open,
|
|
157
|
+
onClose,
|
|
158
|
+
categories = [],
|
|
159
|
+
userDataObject,
|
|
160
|
+
userMenuItems,
|
|
161
|
+
userSubtitle,
|
|
162
|
+
hasUpdate = false,
|
|
163
|
+
onInstallUpdate,
|
|
164
|
+
id,
|
|
165
|
+
className,
|
|
166
|
+
}: AppMenuProps) {
|
|
167
|
+
let dialogRef = useRef<HTMLDialogElement>(null);
|
|
168
|
+
let searchRef = useRef<HTMLInputElement>(null);
|
|
169
|
+
let [search, setSearch] = useState("");
|
|
170
|
+
let [selection, setSelection] = useState<Selection>(null);
|
|
171
|
+
let [mobilePane, setMobilePane] = useState<"apps" | "groups">("apps");
|
|
172
|
+
let [hasLoaded, setHasLoaded] = useState(false);
|
|
173
|
+
|
|
174
|
+
let isLoading = useLoading(dataObject);
|
|
175
|
+
let articles = useData<AppMenuArticle>(dataObject);
|
|
176
|
+
|
|
177
|
+
// Sync the native dialog with the `open` prop. Using showModal() puts the
|
|
178
|
+
// dialog in the top layer so it renders above the toolbar and page content.
|
|
179
|
+
useEffect(() => {
|
|
180
|
+
let dialog = dialogRef.current;
|
|
181
|
+
if (!dialog) return;
|
|
182
|
+
|
|
183
|
+
if (open && !dialog.open) {
|
|
184
|
+
dialog.showModal();
|
|
185
|
+
requestAnimationFrame(() => searchRef.current?.focus());
|
|
186
|
+
} else if (!open && dialog.open) {
|
|
187
|
+
dialog.close();
|
|
188
|
+
}
|
|
189
|
+
}, [open]);
|
|
190
|
+
|
|
191
|
+
// Reset transient state whenever the menu is closed.
|
|
192
|
+
useEffect(() => {
|
|
193
|
+
if (!open) {
|
|
194
|
+
setSearch("");
|
|
195
|
+
setSelection(null);
|
|
196
|
+
setMobilePane("apps");
|
|
197
|
+
}
|
|
198
|
+
}, [open]);
|
|
199
|
+
|
|
200
|
+
// Load the app list the first time the menu is opened.
|
|
201
|
+
useEffect(() => {
|
|
202
|
+
if (open && !hasLoaded) {
|
|
203
|
+
setHasLoaded(true);
|
|
204
|
+
dataObject.refreshDataSource();
|
|
205
|
+
userDataObject?.refreshDataSource();
|
|
206
|
+
}
|
|
207
|
+
}, [open, hasLoaded, dataObject, userDataObject]);
|
|
208
|
+
|
|
209
|
+
let entries = useMemo(() => toAppEntries(articles), [articles]);
|
|
210
|
+
let term = search.trim().toLowerCase();
|
|
211
|
+
|
|
212
|
+
let searchMatches = useMemo(() => {
|
|
213
|
+
if (!term) return entries;
|
|
214
|
+
return entries.filter((entry) => entry.title.toLowerCase().includes(term) || entry.id.toLowerCase().includes(term));
|
|
215
|
+
}, [entries, term]);
|
|
216
|
+
|
|
217
|
+
let groups = useMemo(() => groupEntries(searchMatches), [searchMatches]);
|
|
218
|
+
let visibleCategories = useMemo(
|
|
219
|
+
() => categories.map((category) => filterCategory(category, term)).filter((category) => countItems(category) > 0),
|
|
220
|
+
[categories, term],
|
|
221
|
+
);
|
|
222
|
+
|
|
223
|
+
// A selection that no longer has matches falls back to "all apps" so the pane
|
|
224
|
+
// never ends up empty while results exist elsewhere.
|
|
225
|
+
let activeSelection: Selection = null;
|
|
226
|
+
if (selection?.type === "group" && groups.some(([group]) => group === selection.key)) activeSelection = selection;
|
|
227
|
+
else if (selection?.type === "category" && visibleCategories.some((category) => category.id === selection.id)) {
|
|
228
|
+
activeSelection = selection;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
let activeCategoryId = activeSelection?.type === "category" ? activeSelection.id : null;
|
|
232
|
+
let activeCategory = visibleCategories.find((category) => category.id === activeCategoryId);
|
|
233
|
+
let activeGroupKey = activeSelection?.type === "group" ? activeSelection.key : null;
|
|
234
|
+
|
|
235
|
+
// Everything the right hand pane renders, normalized to titled link groups.
|
|
236
|
+
let paneGroups: AppMenuLinkGroup[] = useMemo(() => {
|
|
237
|
+
if (activeCategory) return activeCategory.groups;
|
|
238
|
+
|
|
239
|
+
return groups
|
|
240
|
+
.filter(([group]) => activeGroupKey === null || group === activeGroupKey)
|
|
241
|
+
.map(([group, items]) => ({
|
|
242
|
+
title: group === UNGROUPED ? getLocalizedString("Other") : group,
|
|
243
|
+
items: items.map((entry) => ({ label: entry.title, href: entry.href })),
|
|
244
|
+
}));
|
|
245
|
+
}, [activeCategory, activeGroupKey, groups]);
|
|
246
|
+
|
|
247
|
+
let paneItemCount = paneGroups.reduce((total, group) => total + group.items.length, 0);
|
|
248
|
+
let hasApps = searchMatches.length > 0;
|
|
249
|
+
|
|
250
|
+
// The rail and the app list are each a single tab stop; arrow keys move
|
|
251
|
+
// focus within them.
|
|
252
|
+
let railSections = useMemo(() => toRailSections(visibleCategories), [visibleCategories]);
|
|
253
|
+
let groupRoving = useRovingTabIndex(groups.length + 1 + visibleCategories.length);
|
|
254
|
+
let appRoving = useRovingTabIndex(paneItemCount, { columns: true });
|
|
255
|
+
let categoryIndex = groups.length;
|
|
256
|
+
let itemIndex = -1;
|
|
257
|
+
|
|
258
|
+
function groupLabel(group: string) {
|
|
259
|
+
return group === UNGROUPED ? getLocalizedString("Other") : group;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function select(next: Selection) {
|
|
263
|
+
setSelection(next);
|
|
264
|
+
setMobilePane("apps");
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
function isSelected(next: NonNullable<Selection>) {
|
|
268
|
+
if (next.type === "group") return activeGroupKey === next.key;
|
|
269
|
+
return activeCategoryId === next.id;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
function renderItem(item: AppMenuLink, index: number) {
|
|
273
|
+
let props = {
|
|
274
|
+
className: "ob-app-menu__link",
|
|
275
|
+
...item.attributes,
|
|
276
|
+
...appRoving.getItemProps(index),
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
function activate() {
|
|
280
|
+
item.onClick?.();
|
|
281
|
+
if (!item.keepOpen) onClose();
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
return item.href ? (
|
|
285
|
+
<a {...props} href={item.href} target={item.target} rel={item.rel} onClick={activate}>
|
|
286
|
+
{item.label}
|
|
287
|
+
</a>
|
|
288
|
+
) : (
|
|
289
|
+
<button {...props} type="button" onClick={activate}>
|
|
290
|
+
{item.label}
|
|
291
|
+
</button>
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
return (
|
|
296
|
+
<dialog
|
|
297
|
+
ref={dialogRef}
|
|
298
|
+
id={id}
|
|
299
|
+
className={clsx("ob-app-menu", className)}
|
|
300
|
+
aria-label={getLocalizedString("Applications")}
|
|
301
|
+
data-pane={mobilePane}
|
|
302
|
+
onCancel={(event) => {
|
|
303
|
+
// Let React own the open state instead of the browser's default close.
|
|
304
|
+
event.preventDefault();
|
|
305
|
+
onClose();
|
|
306
|
+
}}
|
|
307
|
+
onKeyDown={(event) => {
|
|
308
|
+
// A `type="search"` input consumes Escape to clear itself, so the
|
|
309
|
+
// dialog's own cancel event never fires when the search has focus.
|
|
310
|
+
if (event.key === "Escape") {
|
|
311
|
+
event.preventDefault();
|
|
312
|
+
onClose();
|
|
313
|
+
}
|
|
314
|
+
}}
|
|
315
|
+
onClick={(event) => {
|
|
316
|
+
// Clicks on the dialog element itself are backdrop clicks; anything
|
|
317
|
+
// inside the menu is caught by the inner wrapper below.
|
|
318
|
+
if (event.target === dialogRef.current) onClose();
|
|
319
|
+
}}
|
|
320
|
+
>
|
|
321
|
+
<div className="ob-app-menu__panel">
|
|
322
|
+
<div className="ob-app-menu__rail">
|
|
323
|
+
<div className="ds-search ob-app-menu__search" data-size="sm">
|
|
324
|
+
<input
|
|
325
|
+
ref={searchRef}
|
|
326
|
+
className="ds-input"
|
|
327
|
+
type="search"
|
|
328
|
+
value={search}
|
|
329
|
+
onChange={(event) => setSearch(event.target.value)}
|
|
330
|
+
placeholder={getLocalizedString("Search applications")}
|
|
331
|
+
aria-label={getLocalizedString("Search applications")}
|
|
332
|
+
autoComplete="off"
|
|
333
|
+
/>
|
|
334
|
+
</div>
|
|
335
|
+
|
|
336
|
+
<nav
|
|
337
|
+
className="ob-app-menu__groups"
|
|
338
|
+
aria-label={getLocalizedString("Categories")}
|
|
339
|
+
onKeyDown={groupRoving.onKeyDown}
|
|
340
|
+
>
|
|
341
|
+
<button
|
|
342
|
+
type="button"
|
|
343
|
+
className="ob-app-menu__group-button"
|
|
344
|
+
aria-current={activeSelection === null ? "true" : undefined}
|
|
345
|
+
onClick={() => select(null)}
|
|
346
|
+
{...groupRoving.getItemProps(0)}
|
|
347
|
+
>
|
|
348
|
+
<span>{getLocalizedString("All applications")}</span>
|
|
349
|
+
<span className="ob-app-menu__count">{searchMatches.length}</span>
|
|
350
|
+
</button>
|
|
351
|
+
{groups.map(([group, items], index) => (
|
|
352
|
+
<button
|
|
353
|
+
key={group}
|
|
354
|
+
type="button"
|
|
355
|
+
className="ob-app-menu__group-button"
|
|
356
|
+
aria-current={isSelected({ type: "group", key: group }) ? "true" : undefined}
|
|
357
|
+
onClick={() => select({ type: "group", key: group })}
|
|
358
|
+
{...groupRoving.getItemProps(index + 1)}
|
|
359
|
+
>
|
|
360
|
+
<span>{groupLabel(group)}</span>
|
|
361
|
+
<span className="ob-app-menu__count">{items.length}</span>
|
|
362
|
+
</button>
|
|
363
|
+
))}
|
|
364
|
+
|
|
365
|
+
{railSections.map(([section, sectionCategories]) => (
|
|
366
|
+
<Fragment key={section || "\u0000default"}>
|
|
367
|
+
{section && <h2 className="ob-app-menu__rail-heading">{section}</h2>}
|
|
368
|
+
{sectionCategories.map((category) => {
|
|
369
|
+
// The rail tab stops are "All applications", then the app
|
|
370
|
+
// groups, then the categories, in that order.
|
|
371
|
+
categoryIndex += 1;
|
|
372
|
+
let railIndex = categoryIndex;
|
|
373
|
+
return (
|
|
374
|
+
<button
|
|
375
|
+
key={category.id}
|
|
376
|
+
type="button"
|
|
377
|
+
className="ob-app-menu__group-button"
|
|
378
|
+
aria-current={isSelected({ type: "category", id: category.id }) ? "true" : undefined}
|
|
379
|
+
onClick={() => select({ type: "category", id: category.id })}
|
|
380
|
+
{...groupRoving.getItemProps(railIndex)}
|
|
381
|
+
>
|
|
382
|
+
<span>{category.label}</span>
|
|
383
|
+
<span className="ob-app-menu__count">{countItems(category)}</span>
|
|
384
|
+
</button>
|
|
385
|
+
);
|
|
386
|
+
})}
|
|
387
|
+
</Fragment>
|
|
388
|
+
))}
|
|
389
|
+
</nav>
|
|
390
|
+
|
|
391
|
+
<AppMenuColorScheme />
|
|
392
|
+
</div>
|
|
393
|
+
|
|
394
|
+
<div className="ob-app-menu__content">
|
|
395
|
+
{isLoading && !hasApps && !activeCategory && (
|
|
396
|
+
<p className="ob-app-menu__message">{getLocalizedString("Loading...")}</p>
|
|
397
|
+
)}
|
|
398
|
+
|
|
399
|
+
{!isLoading && paneItemCount === 0 && (
|
|
400
|
+
<p className="ob-app-menu__message">{getLocalizedString("No applications found")}</p>
|
|
401
|
+
)}
|
|
402
|
+
|
|
403
|
+
{paneItemCount > 0 && (
|
|
404
|
+
<div className="ob-app-menu__columns" onKeyDown={appRoving.onKeyDown}>
|
|
405
|
+
{paneGroups.map((group, groupIdx) => (
|
|
406
|
+
<section key={group.title ?? groupIdx} className="ob-app-menu__group">
|
|
407
|
+
{group.title && <h2 className="ob-app-menu__group-title">{group.title}</h2>}
|
|
408
|
+
<ul className="ob-app-menu__list">
|
|
409
|
+
{group.items.map((item) => {
|
|
410
|
+
itemIndex += 1;
|
|
411
|
+
return <li key={item.href ?? item.label}>{renderItem(item, itemIndex)}</li>;
|
|
412
|
+
})}
|
|
413
|
+
</ul>
|
|
414
|
+
</section>
|
|
415
|
+
))}
|
|
416
|
+
</div>
|
|
417
|
+
)}
|
|
418
|
+
|
|
419
|
+
{/*
|
|
420
|
+
* Rendered after the app list so it comes last in the tab order, and
|
|
421
|
+
* moved back to the top visually with `order: -1`.
|
|
422
|
+
*/}
|
|
423
|
+
<div className="ob-app-menu__content-header">
|
|
424
|
+
<button
|
|
425
|
+
type="button"
|
|
426
|
+
className="ob-app-menu__pane-toggle"
|
|
427
|
+
onClick={() => setMobilePane(mobilePane === "apps" ? "groups" : "apps")}
|
|
428
|
+
>
|
|
429
|
+
{mobilePane === "apps" ? getLocalizedString("Categories") : getLocalizedString("Applications")}
|
|
430
|
+
</button>
|
|
431
|
+
{hasUpdate && (
|
|
432
|
+
<button
|
|
433
|
+
type="button"
|
|
434
|
+
className="ob-app-menu__update"
|
|
435
|
+
aria-label={getLocalizedString("Install update and reload")}
|
|
436
|
+
onClick={onInstallUpdate}
|
|
437
|
+
>
|
|
438
|
+
<svg
|
|
439
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
440
|
+
viewBox="0 0 24 24"
|
|
441
|
+
fill="currentColor"
|
|
442
|
+
aria-hidden="true"
|
|
443
|
+
focusable="false"
|
|
444
|
+
width="18"
|
|
445
|
+
height="18"
|
|
446
|
+
>
|
|
447
|
+
<path d="M12 4a8 8 0 0 1 7.5 5.2.75.75 0 1 1-1.4.5A6.5 6.5 0 0 0 6.2 9.25H8.5a.75.75 0 0 1 0 1.5H4.75A.75.75 0 0 1 4 10V6.25a.75.75 0 0 1 1.5 0v1.86A8 8 0 0 1 12 4m-7.6 9.55a.75.75 0 0 1 .95.45A6.5 6.5 0 0 0 17.8 14.75H15.5a.75.75 0 0 1 0-1.5h3.75a.75.75 0 0 1 .75.75V17.75a.75.75 0 0 1-1.5 0v-1.86A8 8 0 0 1 4.5 14.5a.75.75 0 0 1 .45-.95z" />
|
|
448
|
+
</svg>
|
|
449
|
+
<span className="ob-app-menu__update-label">{getLocalizedString("Install update and reload")}</span>
|
|
450
|
+
</button>
|
|
451
|
+
)}
|
|
452
|
+
{userDataObject && (
|
|
453
|
+
<AppMenuUserMenu dataObject={userDataObject} items={userMenuItems} subtitle={userSubtitle} />
|
|
454
|
+
)}
|
|
455
|
+
<button
|
|
456
|
+
type="button"
|
|
457
|
+
className="ob-app-menu__close"
|
|
458
|
+
aria-label={getLocalizedString("Close")}
|
|
459
|
+
onClick={onClose}
|
|
460
|
+
>
|
|
461
|
+
<svg
|
|
462
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
463
|
+
viewBox="0 0 24 24"
|
|
464
|
+
fill="currentColor"
|
|
465
|
+
aria-hidden="true"
|
|
466
|
+
focusable="false"
|
|
467
|
+
width="20"
|
|
468
|
+
height="20"
|
|
469
|
+
>
|
|
470
|
+
<path d="M6.53 5.47a.75.75 0 0 0-1.06 1.06L10.94 12l-5.47 5.47a.75.75 0 1 0 1.06 1.06L12 13.06l5.47 5.47a.75.75 0 1 0 1.06-1.06L13.06 12l5.47-5.47a.75.75 0 0 0-1.06-1.06L12 10.94z" />
|
|
471
|
+
</svg>
|
|
472
|
+
</button>
|
|
473
|
+
</div>
|
|
474
|
+
</div>
|
|
475
|
+
</div>
|
|
476
|
+
</dialog>
|
|
477
|
+
);
|
|
478
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ToggleGroup, Tooltip } from "@digdir/designsystemet-react";
|
|
2
|
+
import { MonitorIcon, MoonIcon, SunIcon } from "@navikt/aksel-icons";
|
|
3
|
+
import { getLocalizedString } from "@olenbetong/appframe-core";
|
|
4
|
+
|
|
5
|
+
import { type ColorSchemePreference, useColorSchemePreference } from "../../colorScheme.js";
|
|
6
|
+
|
|
7
|
+
const OPTIONS: Array<{ value: ColorSchemePreference; label: string; Icon: typeof MonitorIcon }> = [
|
|
8
|
+
{ value: "auto", label: "Follow system setting", Icon: MonitorIcon },
|
|
9
|
+
{ value: "light", label: "Light mode", Icon: SunIcon },
|
|
10
|
+
{ value: "dark", label: "Dark mode", Icon: MoonIcon },
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
/** Icon-only color scheme toggle, shown at the bottom of the app menu rail. */
|
|
14
|
+
export function AppMenuColorScheme() {
|
|
15
|
+
let [preference, setPreference] = useColorSchemePreference();
|
|
16
|
+
|
|
17
|
+
return (
|
|
18
|
+
<div className="ob-app-menu__color-scheme">
|
|
19
|
+
<ToggleGroup
|
|
20
|
+
data-size="sm"
|
|
21
|
+
aria-label={getLocalizedString("Theme")}
|
|
22
|
+
value={preference}
|
|
23
|
+
onChange={(value) => setPreference(value as ColorSchemePreference)}
|
|
24
|
+
>
|
|
25
|
+
{OPTIONS.map(({ value, label, Icon }) => {
|
|
26
|
+
let localizedLabel = getLocalizedString(label);
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<Tooltip key={value} content={localizedLabel}>
|
|
30
|
+
<ToggleGroup.Item value={value}>
|
|
31
|
+
<Icon aria-hidden fontSize="1.25rem" />
|
|
32
|
+
{/* The radio takes its accessible name from the label's text content. */}
|
|
33
|
+
<span className="ob-app-menu__color-scheme-label">{localizedLabel}</span>
|
|
34
|
+
</ToggleGroup.Item>
|
|
35
|
+
</Tooltip>
|
|
36
|
+
);
|
|
37
|
+
})}
|
|
38
|
+
</ToggleGroup>
|
|
39
|
+
</div>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import "./AppMenu.css";
|
|
2
|
+
|
|
3
|
+
import { getLocalizedString } from "@olenbetong/appframe-core";
|
|
4
|
+
import clsx from "clsx";
|
|
5
|
+
import type { ButtonHTMLAttributes, Ref } from "react";
|
|
6
|
+
|
|
7
|
+
export type AppMenuToggleProps = Omit<ButtonHTMLAttributes<HTMLButtonElement>, "aria-expanded" | "type"> & {
|
|
8
|
+
/** Whether the app menu is currently open. Controls `aria-expanded`. */
|
|
9
|
+
open: boolean;
|
|
10
|
+
/** Shows a badge on the button, pointing at the install action inside the menu. */
|
|
11
|
+
hasUpdate?: boolean;
|
|
12
|
+
ref?: Ref<HTMLButtonElement>;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Toolbar button that opens the app menu. Rendering the button separately from
|
|
17
|
+
* the menu lets the toolbar place it wherever it needs to, while the menu itself
|
|
18
|
+
* is rendered as a top layer dialog.
|
|
19
|
+
*/
|
|
20
|
+
export function AppMenuToggle({ open, hasUpdate, className, ref, ...props }: AppMenuToggleProps) {
|
|
21
|
+
return (
|
|
22
|
+
<button
|
|
23
|
+
{...props}
|
|
24
|
+
ref={ref}
|
|
25
|
+
type="button"
|
|
26
|
+
className={clsx("ob-app-menu-toggle", className)}
|
|
27
|
+
aria-label={
|
|
28
|
+
hasUpdate
|
|
29
|
+
? `${getLocalizedString("Applications")} (${getLocalizedString("Update available")})`
|
|
30
|
+
: getLocalizedString("Applications")
|
|
31
|
+
}
|
|
32
|
+
aria-haspopup="dialog"
|
|
33
|
+
aria-expanded={open}
|
|
34
|
+
data-update={hasUpdate ? "" : undefined}
|
|
35
|
+
>
|
|
36
|
+
<svg
|
|
37
|
+
className="ob-app-menu-toggle__icon"
|
|
38
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
39
|
+
viewBox="0 0 24 24"
|
|
40
|
+
fill="currentColor"
|
|
41
|
+
aria-hidden="true"
|
|
42
|
+
focusable="false"
|
|
43
|
+
width="24"
|
|
44
|
+
height="24"
|
|
45
|
+
>
|
|
46
|
+
<path d="M4 4h4v4H4zm6 0h4v4h-4zm6 0h4v4h-4zM4 10h4v4H4zm6 0h4v4h-4zm6 0h4v4h-4zM4 16h4v4H4zm6 0h4v4h-4zm6 0h4v4h-4z" />
|
|
47
|
+
</svg>
|
|
48
|
+
{hasUpdate && <span className="ob-app-menu-toggle__badge" aria-hidden="true" />}
|
|
49
|
+
</button>
|
|
50
|
+
);
|
|
51
|
+
}
|