@olenbetong/synergi-react 2.7.0 → 2.8.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.
Files changed (72) hide show
  1. package/{src/components → es/chrome}/AppMenu/AppMenu.css +648 -648
  2. package/es/{components → chrome}/AppMenu/AppMenu.d.ts +17 -8
  3. package/es/chrome/AppMenu/AppMenu.js +145 -0
  4. package/es/chrome/AppMenu/AppMenuColorScheme.d.ts +2 -0
  5. package/es/chrome/AppMenu/AppMenuColorScheme.js +18 -0
  6. package/es/chrome/AppMenu/AppMenuFavoriteButton.d.ts +18 -0
  7. package/es/chrome/AppMenu/AppMenuFavoriteButton.js +11 -0
  8. package/es/chrome/AppMenu/AppMenuHeader.d.ts +24 -0
  9. package/es/chrome/AppMenu/AppMenuHeader.js +18 -0
  10. package/es/chrome/AppMenu/AppMenuList.d.ts +18 -0
  11. package/es/chrome/AppMenu/AppMenuList.js +39 -0
  12. package/es/chrome/AppMenu/AppMenuRail.d.ts +26 -0
  13. package/es/chrome/AppMenu/AppMenuRail.js +30 -0
  14. package/es/chrome/AppMenu/icons.d.ts +15 -0
  15. package/es/chrome/AppMenu/icons.js +13 -0
  16. package/es/chrome/AppMenu/index.d.ts +12 -0
  17. package/es/{components → chrome}/AppMenu/index.js +5 -0
  18. package/es/chrome/AppMenu/menuEntries.d.ts +51 -0
  19. package/es/chrome/AppMenu/menuEntries.js +93 -0
  20. package/es/{components → chrome}/AppMenu/types.d.ts +10 -0
  21. package/es/chrome/AppMenu/useFavorites.d.ts +13 -0
  22. package/es/chrome/AppMenu/useFavorites.js +28 -0
  23. package/es/{components → chrome}/AppMenu/useRovingTabIndex.d.ts +4 -0
  24. package/es/{components → chrome}/AppMenu/useRovingTabIndex.js +12 -1
  25. package/es/{components → chrome}/AppShell/index.js +23 -2
  26. package/es/colorScheme.d.ts +17 -0
  27. package/es/colorScheme.js +54 -0
  28. package/es/components/PageBanner/index.d.ts +1 -1
  29. package/es/index.d.ts +3 -2
  30. package/es/index.js +3 -2
  31. package/package.json +2 -2
  32. package/{es/components → src/chrome}/AppMenu/AppMenu.css +129 -2
  33. package/src/{components → chrome}/AppMenu/AppMenu.tsx +285 -285
  34. package/src/{components → chrome}/AppMenu/AppMenuColorScheme.tsx +42 -41
  35. package/src/{components → chrome}/AppMenu/AppMenuFavoriteButton.tsx +47 -47
  36. package/src/{components → chrome}/AppMenu/AppMenuHeader.tsx +79 -79
  37. package/src/{components → chrome}/AppMenu/AppMenuList.tsx +89 -89
  38. package/src/{components → chrome}/AppMenu/AppMenuRail.tsx +117 -117
  39. package/src/{components → chrome}/AppMenu/icons.tsx +76 -76
  40. package/src/{components → chrome}/AppMenu/index.ts +17 -17
  41. package/src/{components → chrome}/AppMenu/menuEntries.ts +128 -128
  42. package/src/{components → chrome}/AppMenu/types.ts +45 -45
  43. package/src/{components → chrome}/AppMenu/useFavorites.ts +40 -40
  44. package/src/{components → chrome}/AppMenu/useRovingTabIndex.ts +130 -130
  45. package/src/{components → chrome}/AppShell/index.tsx +287 -287
  46. package/src/colorScheme.ts +81 -81
  47. package/src/components/ImageEditor/ImageEditor.tsx +1 -1
  48. package/src/components/ImageEditor/index.ts +2 -0
  49. package/src/components/ImageEditor/plugins/zoomPlugin/ZoomControls.tsx +7 -8
  50. package/src/components/LinkedCardList/index.scss +93 -93
  51. package/src/components/PageBanner/index.tsx +5 -4
  52. package/src/components/ProgressBar/index.scss +94 -94
  53. package/src/elements/ElementDamage/DamageFormButtons.tsx +2 -2
  54. package/src/elements/ElementDamage/TransportElementSelect.tsx +1 -1
  55. package/src/elements/index.ts +5 -0
  56. package/src/index.ts +70 -61
  57. package/es/components/AppMenu/AppMenu.js +0 -223
  58. package/es/components/AppMenu/index.d.ts +0 -6
  59. /package/es/{components → chrome}/AppMenu/AppMenuToggle.d.ts +0 -0
  60. /package/es/{components → chrome}/AppMenu/AppMenuToggle.js +0 -0
  61. /package/es/{components → chrome}/AppMenu/AppMenuUserMenu.d.ts +0 -0
  62. /package/es/{components → chrome}/AppMenu/AppMenuUserMenu.js +0 -0
  63. /package/es/{components → chrome}/AppMenu/developerCategories.d.ts +0 -0
  64. /package/es/{components → chrome}/AppMenu/developerCategories.js +0 -0
  65. /package/es/{components → chrome}/AppMenu/types.js +0 -0
  66. /package/es/{components → chrome}/AppMenu/useServiceWorkerUpdate.d.ts +0 -0
  67. /package/es/{components → chrome}/AppMenu/useServiceWorkerUpdate.js +0 -0
  68. /package/es/{components → chrome}/AppShell/index.d.ts +0 -0
  69. /package/src/{components → chrome}/AppMenu/AppMenuToggle.tsx +0 -0
  70. /package/src/{components → chrome}/AppMenu/AppMenuUserMenu.tsx +0 -0
  71. /package/src/{components → chrome}/AppMenu/developerCategories.ts +0 -0
  72. /package/src/{components → chrome}/AppMenu/useServiceWorkerUpdate.ts +0 -0
@@ -1,285 +1,285 @@
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 { useEffect, useMemo, useRef, useState } from "react";
8
-
9
- import { AppMenuHeader } from "./AppMenuHeader.js";
10
- import { AppMenuList } from "./AppMenuList.js";
11
- import { AppMenuRail } from "./AppMenuRail.js";
12
- import type { AppMenuUser } from "./AppMenuUserMenu.js";
13
- import {
14
- type AppMenuArticle,
15
- countItems,
16
- FAVORITES,
17
- filterCategory,
18
- groupEntries,
19
- groupLabel,
20
- type Selection,
21
- toAppEntries,
22
- } from "./menuEntries.js";
23
- import type { AppMenuCategory, AppMenuLink, AppMenuLinkGroup } from "./types.js";
24
- import { useFavorites } from "./useFavorites.js";
25
-
26
- export type { AppMenuArticle } from "./menuEntries.js";
27
-
28
- export type AppMenuProps = {
29
- /** Data object returning the articles to list. See `AppMenuArticle` for the required fields. */
30
- dataObject: DataObject<AppMenuArticle>;
31
- /** Whether the menu is open. The menu is a controlled component. */
32
- open: boolean;
33
- /** Called when the menu requests to be closed (backdrop click, Escape, app selected). */
34
- onClose: () => void;
35
- /**
36
- * Extra categories listed below the app categories in the rail, showing a
37
- * fixed set of links instead of apps. See `createDeveloperCategories`.
38
- */
39
- categories?: AppMenuCategory[];
40
- /** Data object over `aviw_General_SidebarUserInfo`. Enables the user menu in the header. */
41
- userDataObject?: DataObject<AppMenuUser>;
42
- /** Overrides the default user menu entries. */
43
- userMenuItems?: AppMenuLink[];
44
- /**
45
- * Called when the favorite toggle next to an app is activated. Without this
46
- * handler no favorite toggles are rendered.
47
- *
48
- * `id` is the version-less ArticleId. The menu updates its own state
49
- * optimistically and rolls back if the promise rejects.
50
- */
51
- onToggleFavorite?: (id: string, favorite: boolean) => void | Promise<unknown>;
52
- /**
53
- * Link shown at the start of the content header, e.g. the portal/front page,
54
- * which isn't part of the app list. Omit it when already on that page.
55
- */
56
- homeLink?: AppMenuLink;
57
- /** Shown below the user's name. Defaults to `af.userSession.domain`. */
58
- userSubtitle?: string;
59
- /**
60
- * Shows a highlighted "install update" button in the menu header. Pair with
61
- * `useServiceWorkerUpdate()`.
62
- */
63
- hasUpdate?: boolean;
64
- /** Called when the install update button is pressed. */
65
- onInstallUpdate?: () => void;
66
- id?: string;
67
- className?: string;
68
- };
69
-
70
- /**
71
- * Two pane application menu. The left rail holds a local search field and the
72
- * list of app categories (`MenuGroup`); the right pane lists the apps in the
73
- * selected category, or every app when no category is selected.
74
- *
75
- * On narrow viewports only one pane is visible at a time, defaulting to the app
76
- * list, with a button to switch to the category list.
77
- */
78
- export function AppMenu({
79
- dataObject,
80
- open,
81
- onClose,
82
- categories = [],
83
- userDataObject,
84
- userMenuItems,
85
- userSubtitle,
86
- onToggleFavorite,
87
- homeLink,
88
- hasUpdate = false,
89
- onInstallUpdate,
90
- id,
91
- className,
92
- }: AppMenuProps) {
93
- let dialogRef = useRef<HTMLDialogElement>(null);
94
- let searchRef = useRef<HTMLInputElement>(null);
95
- let [search, setSearch] = useState("");
96
- let [selection, setSelection] = useState<Selection>(null);
97
- let [mobilePane, setMobilePane] = useState<"apps" | "groups">("apps");
98
- let [hasLoaded, setHasLoaded] = useState(false);
99
- /*
100
- * True once the initial category has been decided, either by the menu picking
101
- * the favorites when the apps arrive, or by the user picking one themselves.
102
- * Without it the menu would jump to the favorites group the moment the first
103
- * favorite is added.
104
- */
105
- let [hasResolvedSelection, setHasResolvedSelection] = useState(false);
106
-
107
- let isLoading = useLoading(dataObject);
108
- let articles = useData<AppMenuArticle>(dataObject);
109
- let { applyOverrides, toggleFavorite } = useFavorites(onToggleFavorite);
110
-
111
- // Sync the native dialog with the `open` prop. Using showModal() puts the
112
- // dialog in the top layer so it renders above the toolbar and page content.
113
- useEffect(() => {
114
- let dialog = dialogRef.current;
115
- if (!dialog) return;
116
-
117
- if (open && !dialog.open) {
118
- dialog.showModal();
119
- requestAnimationFrame(() => searchRef.current?.focus());
120
- } else if (!open && dialog.open) {
121
- dialog.close();
122
- }
123
- }, [open]);
124
-
125
- // Reset transient state whenever the menu is closed.
126
- useEffect(() => {
127
- if (!open) {
128
- setSearch("");
129
- setSelection(null);
130
- setMobilePane("apps");
131
- setHasResolvedSelection(false);
132
- }
133
- }, [open]);
134
-
135
- // Load the app list the first time the menu is opened.
136
- useEffect(() => {
137
- if (open && !hasLoaded) {
138
- setHasLoaded(true);
139
- dataObject.refreshDataSource();
140
- userDataObject?.refreshDataSource();
141
- }
142
- }, [open, hasLoaded, dataObject, userDataObject]);
143
-
144
- let entries = useMemo(() => applyOverrides(toAppEntries(articles)), [articles, applyOverrides]);
145
- let term = search.trim().toLowerCase();
146
-
147
- let searchMatches = useMemo(() => {
148
- if (!term) return entries;
149
- return entries.filter((entry) => entry.title.toLowerCase().includes(term) || entry.id.toLowerCase().includes(term));
150
- }, [entries, term]);
151
-
152
- let groups = useMemo(() => groupEntries(searchMatches), [searchMatches]);
153
- let visibleCategories = useMemo(
154
- () => categories.map((category) => filterCategory(category, term)).filter((category) => countItems(category) > 0),
155
- [categories, term],
156
- );
157
-
158
- let hasFavorites = groups.length > 0 && groups[0][0] === FAVORITES;
159
-
160
- /*
161
- * The favorites are the most likely target, so select them by default. The
162
- * article list loads asynchronously, so this can't be done when opening the
163
- * menu — it has to wait until the apps have arrived. It only ever runs once
164
- * per open, so favoriting an app doesn't move the user to another group.
165
- */
166
- useEffect(() => {
167
- if (!open || hasResolvedSelection || entries.length === 0) return;
168
-
169
- setHasResolvedSelection(true);
170
- if (hasFavorites) setSelection({ type: "group", key: FAVORITES });
171
- }, [open, hasResolvedSelection, entries.length, hasFavorites]);
172
-
173
- // A selection that no longer has matches falls back to "all apps" so the pane
174
- // never ends up empty while results exist elsewhere.
175
- let activeSelection: Selection = null;
176
- if (selection?.type === "group" && groups.some(([group]) => group === selection.key)) activeSelection = selection;
177
- else if (selection?.type === "category" && visibleCategories.some((category) => category.id === selection.id)) {
178
- activeSelection = selection;
179
- }
180
-
181
- let activeCategoryId = activeSelection?.type === "category" ? activeSelection.id : null;
182
- let activeCategory = visibleCategories.find((category) => category.id === activeCategoryId);
183
- let activeGroupKey = activeSelection?.type === "group" ? activeSelection.key : null;
184
-
185
- // Everything the right hand pane renders, normalized to titled link groups.
186
- // The favorites are left out of the "all apps" pane, since those apps are
187
- // already listed in their own group.
188
- let paneGroups: AppMenuLinkGroup[] = useMemo(() => {
189
- if (activeCategory) return activeCategory.groups;
190
-
191
- return groups
192
- .filter(([group]) => (activeGroupKey === null ? group !== FAVORITES : group === activeGroupKey))
193
- .map(([group, items]) => ({
194
- title: groupLabel(group),
195
- items: items.map((entry) => ({
196
- id: entry.id,
197
- label: entry.title,
198
- href: entry.href,
199
- isFavorite: entry.isFavorite,
200
- })),
201
- }));
202
- }, [activeCategory, activeGroupKey, groups]);
203
-
204
- let paneItemCount = paneGroups.reduce((total, group) => total + group.items.length, 0);
205
- let hasApps = searchMatches.length > 0;
206
- let railGroups = groups.map(([key, items]) => ({ key, count: items.length }));
207
-
208
- function select(next: Selection) {
209
- setSelection(next);
210
- setHasResolvedSelection(true);
211
- setMobilePane("apps");
212
- }
213
-
214
- return (
215
- <dialog
216
- ref={dialogRef}
217
- id={id}
218
- className={clsx("ob-app-menu", className)}
219
- aria-label={getLocalizedString("Applications")}
220
- data-pane={mobilePane}
221
- onCancel={(event) => {
222
- // Let React own the open state instead of the browser's default close.
223
- event.preventDefault();
224
- onClose();
225
- }}
226
- onKeyDown={(event) => {
227
- // A `type="search"` input consumes Escape to clear itself, so the
228
- // dialog's own cancel event never fires when the search has focus.
229
- if (event.key === "Escape") {
230
- event.preventDefault();
231
- onClose();
232
- }
233
- }}
234
- onClick={(event) => {
235
- // Clicks on the dialog element itself are backdrop clicks; anything
236
- // inside the menu is caught by the inner wrapper below.
237
- if (event.target === dialogRef.current) onClose();
238
- }}
239
- >
240
- <div className="ob-app-menu__panel">
241
- <AppMenuRail
242
- searchRef={searchRef}
243
- search={search}
244
- onSearchChange={setSearch}
245
- groups={railGroups}
246
- appCount={searchMatches.length}
247
- categories={visibleCategories}
248
- selection={activeSelection}
249
- onSelect={select}
250
- />
251
-
252
- <div className="ob-app-menu__content">
253
- {isLoading && !hasApps && !activeCategory && (
254
- <p className="ob-app-menu__message">{getLocalizedString("Loading...")}</p>
255
- )}
256
-
257
- {!isLoading && paneItemCount === 0 && (
258
- <p className="ob-app-menu__message">{getLocalizedString("No applications found")}</p>
259
- )}
260
-
261
- {paneItemCount > 0 && (
262
- <AppMenuList
263
- groups={paneGroups}
264
- itemCount={paneItemCount}
265
- onClose={onClose}
266
- onToggleFavorite={toggleFavorite}
267
- />
268
- )}
269
-
270
- <AppMenuHeader
271
- homeLink={homeLink}
272
- mobilePane={mobilePane}
273
- onToggleMobilePane={() => setMobilePane(mobilePane === "apps" ? "groups" : "apps")}
274
- hasUpdate={hasUpdate}
275
- onInstallUpdate={onInstallUpdate}
276
- userDataObject={userDataObject}
277
- userMenuItems={userMenuItems}
278
- userSubtitle={userSubtitle}
279
- onClose={onClose}
280
- />
281
- </div>
282
- </div>
283
- </dialog>
284
- );
285
- }
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 { useEffect, useMemo, useRef, useState } from "react";
8
+
9
+ import { AppMenuHeader } from "./AppMenuHeader.js";
10
+ import { AppMenuList } from "./AppMenuList.js";
11
+ import { AppMenuRail } from "./AppMenuRail.js";
12
+ import type { AppMenuUser } from "./AppMenuUserMenu.js";
13
+ import {
14
+ type AppMenuArticle,
15
+ countItems,
16
+ FAVORITES,
17
+ filterCategory,
18
+ groupEntries,
19
+ groupLabel,
20
+ type Selection,
21
+ toAppEntries,
22
+ } from "./menuEntries.js";
23
+ import type { AppMenuCategory, AppMenuLink, AppMenuLinkGroup } from "./types.js";
24
+ import { useFavorites } from "./useFavorites.js";
25
+
26
+ export type { AppMenuArticle } from "./menuEntries.js";
27
+
28
+ export type AppMenuProps = {
29
+ /** Data object returning the articles to list. See `AppMenuArticle` for the required fields. */
30
+ dataObject: DataObject<AppMenuArticle>;
31
+ /** Whether the menu is open. The menu is a controlled component. */
32
+ open: boolean;
33
+ /** Called when the menu requests to be closed (backdrop click, Escape, app selected). */
34
+ onClose: () => void;
35
+ /**
36
+ * Extra categories listed below the app categories in the rail, showing a
37
+ * fixed set of links instead of apps. See `createDeveloperCategories`.
38
+ */
39
+ categories?: AppMenuCategory[];
40
+ /** Data object over `aviw_General_SidebarUserInfo`. Enables the user menu in the header. */
41
+ userDataObject?: DataObject<AppMenuUser>;
42
+ /** Overrides the default user menu entries. */
43
+ userMenuItems?: AppMenuLink[];
44
+ /**
45
+ * Called when the favorite toggle next to an app is activated. Without this
46
+ * handler no favorite toggles are rendered.
47
+ *
48
+ * `id` is the version-less ArticleId. The menu updates its own state
49
+ * optimistically and rolls back if the promise rejects.
50
+ */
51
+ onToggleFavorite?: (id: string, favorite: boolean) => void | Promise<unknown>;
52
+ /**
53
+ * Link shown at the start of the content header, e.g. the portal/front page,
54
+ * which isn't part of the app list. Omit it when already on that page.
55
+ */
56
+ homeLink?: AppMenuLink;
57
+ /** Shown below the user's name. Defaults to `af.userSession.domain`. */
58
+ userSubtitle?: string;
59
+ /**
60
+ * Shows a highlighted "install update" button in the menu header. Pair with
61
+ * `useServiceWorkerUpdate()`.
62
+ */
63
+ hasUpdate?: boolean;
64
+ /** Called when the install update button is pressed. */
65
+ onInstallUpdate?: () => void;
66
+ id?: string;
67
+ className?: string;
68
+ };
69
+
70
+ /**
71
+ * Two pane application menu. The left rail holds a local search field and the
72
+ * list of app categories (`MenuGroup`); the right pane lists the apps in the
73
+ * selected category, or every app when no category is selected.
74
+ *
75
+ * On narrow viewports only one pane is visible at a time, defaulting to the app
76
+ * list, with a button to switch to the category list.
77
+ */
78
+ export function AppMenu({
79
+ dataObject,
80
+ open,
81
+ onClose,
82
+ categories = [],
83
+ userDataObject,
84
+ userMenuItems,
85
+ userSubtitle,
86
+ onToggleFavorite,
87
+ homeLink,
88
+ hasUpdate = false,
89
+ onInstallUpdate,
90
+ id,
91
+ className,
92
+ }: AppMenuProps) {
93
+ let dialogRef = useRef<HTMLDialogElement>(null);
94
+ let searchRef = useRef<HTMLInputElement>(null);
95
+ let [search, setSearch] = useState("");
96
+ let [selection, setSelection] = useState<Selection>(null);
97
+ let [mobilePane, setMobilePane] = useState<"apps" | "groups">("apps");
98
+ let [hasLoaded, setHasLoaded] = useState(false);
99
+ /*
100
+ * True once the initial category has been decided, either by the menu picking
101
+ * the favorites when the apps arrive, or by the user picking one themselves.
102
+ * Without it the menu would jump to the favorites group the moment the first
103
+ * favorite is added.
104
+ */
105
+ let [hasResolvedSelection, setHasResolvedSelection] = useState(false);
106
+
107
+ let isLoading = useLoading(dataObject);
108
+ let articles = useData<AppMenuArticle>(dataObject);
109
+ let { applyOverrides, toggleFavorite } = useFavorites(onToggleFavorite);
110
+
111
+ // Sync the native dialog with the `open` prop. Using showModal() puts the
112
+ // dialog in the top layer so it renders above the toolbar and page content.
113
+ useEffect(() => {
114
+ let dialog = dialogRef.current;
115
+ if (!dialog) return;
116
+
117
+ if (open && !dialog.open) {
118
+ dialog.showModal();
119
+ requestAnimationFrame(() => searchRef.current?.focus());
120
+ } else if (!open && dialog.open) {
121
+ dialog.close();
122
+ }
123
+ }, [open]);
124
+
125
+ // Reset transient state whenever the menu is closed.
126
+ useEffect(() => {
127
+ if (!open) {
128
+ setSearch("");
129
+ setSelection(null);
130
+ setMobilePane("apps");
131
+ setHasResolvedSelection(false);
132
+ }
133
+ }, [open]);
134
+
135
+ // Load the app list the first time the menu is opened.
136
+ useEffect(() => {
137
+ if (open && !hasLoaded) {
138
+ setHasLoaded(true);
139
+ dataObject.refreshDataSource();
140
+ userDataObject?.refreshDataSource();
141
+ }
142
+ }, [open, hasLoaded, dataObject, userDataObject]);
143
+
144
+ let entries = useMemo(() => applyOverrides(toAppEntries(articles)), [articles, applyOverrides]);
145
+ let term = search.trim().toLowerCase();
146
+
147
+ let searchMatches = useMemo(() => {
148
+ if (!term) return entries;
149
+ return entries.filter((entry) => entry.title.toLowerCase().includes(term) || entry.id.toLowerCase().includes(term));
150
+ }, [entries, term]);
151
+
152
+ let groups = useMemo(() => groupEntries(searchMatches), [searchMatches]);
153
+ let visibleCategories = useMemo(
154
+ () => categories.map((category) => filterCategory(category, term)).filter((category) => countItems(category) > 0),
155
+ [categories, term],
156
+ );
157
+
158
+ let hasFavorites = groups.length > 0 && groups[0][0] === FAVORITES;
159
+
160
+ /*
161
+ * The favorites are the most likely target, so select them by default. The
162
+ * article list loads asynchronously, so this can't be done when opening the
163
+ * menu — it has to wait until the apps have arrived. It only ever runs once
164
+ * per open, so favoriting an app doesn't move the user to another group.
165
+ */
166
+ useEffect(() => {
167
+ if (!open || hasResolvedSelection || entries.length === 0) return;
168
+
169
+ setHasResolvedSelection(true);
170
+ if (hasFavorites) setSelection({ type: "group", key: FAVORITES });
171
+ }, [open, hasResolvedSelection, entries.length, hasFavorites]);
172
+
173
+ // A selection that no longer has matches falls back to "all apps" so the pane
174
+ // never ends up empty while results exist elsewhere.
175
+ let activeSelection: Selection = null;
176
+ if (selection?.type === "group" && groups.some(([group]) => group === selection.key)) activeSelection = selection;
177
+ else if (selection?.type === "category" && visibleCategories.some((category) => category.id === selection.id)) {
178
+ activeSelection = selection;
179
+ }
180
+
181
+ let activeCategoryId = activeSelection?.type === "category" ? activeSelection.id : null;
182
+ let activeCategory = visibleCategories.find((category) => category.id === activeCategoryId);
183
+ let activeGroupKey = activeSelection?.type === "group" ? activeSelection.key : null;
184
+
185
+ // Everything the right hand pane renders, normalized to titled link groups.
186
+ // The favorites are left out of the "all apps" pane, since those apps are
187
+ // already listed in their own group.
188
+ let paneGroups: AppMenuLinkGroup[] = useMemo(() => {
189
+ if (activeCategory) return activeCategory.groups;
190
+
191
+ return groups
192
+ .filter(([group]) => (activeGroupKey === null ? group !== FAVORITES : group === activeGroupKey))
193
+ .map(([group, items]) => ({
194
+ title: groupLabel(group),
195
+ items: items.map((entry) => ({
196
+ id: entry.id,
197
+ label: entry.title,
198
+ href: entry.href,
199
+ isFavorite: entry.isFavorite,
200
+ })),
201
+ }));
202
+ }, [activeCategory, activeGroupKey, groups]);
203
+
204
+ let paneItemCount = paneGroups.reduce((total, group) => total + group.items.length, 0);
205
+ let hasApps = searchMatches.length > 0;
206
+ let railGroups = groups.map(([key, items]) => ({ key, count: items.length }));
207
+
208
+ function select(next: Selection) {
209
+ setSelection(next);
210
+ setHasResolvedSelection(true);
211
+ setMobilePane("apps");
212
+ }
213
+
214
+ return (
215
+ <dialog
216
+ ref={dialogRef}
217
+ id={id}
218
+ className={clsx("ob-app-menu", className)}
219
+ aria-label={getLocalizedString("Applications")}
220
+ data-pane={mobilePane}
221
+ onCancel={(event) => {
222
+ // Let React own the open state instead of the browser's default close.
223
+ event.preventDefault();
224
+ onClose();
225
+ }}
226
+ onKeyDown={(event) => {
227
+ // A `type="search"` input consumes Escape to clear itself, so the
228
+ // dialog's own cancel event never fires when the search has focus.
229
+ if (event.key === "Escape") {
230
+ event.preventDefault();
231
+ onClose();
232
+ }
233
+ }}
234
+ onClick={(event) => {
235
+ // Clicks on the dialog element itself are backdrop clicks; anything
236
+ // inside the menu is caught by the inner wrapper below.
237
+ if (event.target === dialogRef.current) onClose();
238
+ }}
239
+ >
240
+ <div className="ob-app-menu__panel">
241
+ <AppMenuRail
242
+ searchRef={searchRef}
243
+ search={search}
244
+ onSearchChange={setSearch}
245
+ groups={railGroups}
246
+ appCount={searchMatches.length}
247
+ categories={visibleCategories}
248
+ selection={activeSelection}
249
+ onSelect={select}
250
+ />
251
+
252
+ <div className="ob-app-menu__content">
253
+ {isLoading && !hasApps && !activeCategory && (
254
+ <p className="ob-app-menu__message">{getLocalizedString("Loading...")}</p>
255
+ )}
256
+
257
+ {!isLoading && paneItemCount === 0 && (
258
+ <p className="ob-app-menu__message">{getLocalizedString("No applications found")}</p>
259
+ )}
260
+
261
+ {paneItemCount > 0 && (
262
+ <AppMenuList
263
+ groups={paneGroups}
264
+ itemCount={paneItemCount}
265
+ onClose={onClose}
266
+ onToggleFavorite={toggleFavorite}
267
+ />
268
+ )}
269
+
270
+ <AppMenuHeader
271
+ homeLink={homeLink}
272
+ mobilePane={mobilePane}
273
+ onToggleMobilePane={() => setMobilePane(mobilePane === "apps" ? "groups" : "apps")}
274
+ hasUpdate={hasUpdate}
275
+ onInstallUpdate={onInstallUpdate}
276
+ userDataObject={userDataObject}
277
+ userMenuItems={userMenuItems}
278
+ userSubtitle={userSubtitle}
279
+ onClose={onClose}
280
+ />
281
+ </div>
282
+ </div>
283
+ </dialog>
284
+ );
285
+ }
@@ -1,41 +1,42 @@
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
- }
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
+ data-toggle-group={getLocalizedString("Theme")}
22
+ aria-label={getLocalizedString("Theme")}
23
+ value={preference}
24
+ onChange={(value) => setPreference(value as ColorSchemePreference)}
25
+ >
26
+ {OPTIONS.map(({ value, label, Icon }) => {
27
+ let localizedLabel = getLocalizedString(label);
28
+
29
+ return (
30
+ <Tooltip key={value} content={localizedLabel}>
31
+ <ToggleGroup.Item value={value}>
32
+ <Icon aria-hidden fontSize="1.25rem" />
33
+ {/* The radio takes its accessible name from the label's text content. */}
34
+ <span className="ob-app-menu__color-scheme-label">{localizedLabel}</span>
35
+ </ToggleGroup.Item>
36
+ </Tooltip>
37
+ );
38
+ })}
39
+ </ToggleGroup>
40
+ </div>
41
+ );
42
+ }