@olenbetong/synergi-react 2.5.7 → 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.
Files changed (63) hide show
  1. package/es/colorScheme.d.ts +17 -0
  2. package/es/colorScheme.js +54 -0
  3. package/es/components/AppMenu/AppMenu.css +480 -92
  4. package/es/components/AppMenu/AppMenu.d.ts +47 -0
  5. package/es/components/AppMenu/AppMenu.js +224 -0
  6. package/es/components/AppMenu/AppMenuColorScheme.d.ts +2 -0
  7. package/es/components/AppMenu/AppMenuColorScheme.js +18 -0
  8. package/es/components/AppMenu/AppMenuToggle.d.ts +15 -0
  9. package/es/components/AppMenu/AppMenuToggle.js +14 -0
  10. package/es/components/AppMenu/AppMenuUserMenu.d.ts +32 -0
  11. package/es/components/AppMenu/AppMenuUserMenu.js +110 -0
  12. package/es/components/AppMenu/developerCategories.d.ts +24 -0
  13. package/es/components/AppMenu/developerCategories.js +116 -0
  14. package/es/components/AppMenu/index.d.ts +7 -12
  15. package/es/components/AppMenu/index.js +6 -85
  16. package/es/components/AppMenu/types.d.ts +33 -0
  17. package/es/components/AppMenu/types.js +1 -0
  18. package/es/components/AppMenu/useRovingTabIndex.d.ts +24 -0
  19. package/es/components/AppMenu/useRovingTabIndex.js +103 -0
  20. package/es/components/AppMenu/useServiceWorkerUpdate.d.ts +16 -0
  21. package/es/components/AppMenu/useServiceWorkerUpdate.js +62 -0
  22. package/es/components/AppShell/index.js +107 -13
  23. package/es/components/ImageEditor/ImageEditor.css +22 -11
  24. package/es/components/ImageEditor/ImageEditor.js +12 -12
  25. package/es/components/ImageEditor/ResponsiveButton.d.ts +1 -1
  26. package/es/components/ImageEditor/ResponsiveButton.js +5 -5
  27. package/es/components/ImageEditor/plugins/cropPlugin/CropOverlay.js +2 -2
  28. package/es/components/ImageEditor/plugins/cropPlugin/CropToolbar.js +3 -4
  29. package/es/components/ImageEditor/plugins/cropPlugin/index.js +2 -2
  30. package/es/components/ImageEditor/plugins/redactPlugin/RedactToolbar.js +3 -5
  31. package/es/components/ImageEditor/plugins/redactPlugin/index.js +2 -2
  32. package/es/components/ImageEditor/plugins/rotatePlugin.js +1 -2
  33. package/es/components/ImageEditor/plugins/zoomPlugin/ZoomControls.js +2 -4
  34. package/es/components/ImageEditor/useIsSmall.d.ts +5 -0
  35. package/es/components/ImageEditor/useIsSmall.js +21 -0
  36. package/es/index.d.ts +2 -1
  37. package/es/index.js +2 -1
  38. package/package.json +7 -3
  39. package/src/colorScheme.ts +81 -0
  40. package/src/components/AppMenu/AppMenu.css +480 -92
  41. package/src/components/AppMenu/AppMenu.tsx +478 -0
  42. package/src/components/AppMenu/AppMenuColorScheme.tsx +41 -0
  43. package/src/components/AppMenu/AppMenuToggle.tsx +51 -0
  44. package/src/components/AppMenu/AppMenuUserMenu.tsx +190 -0
  45. package/src/components/AppMenu/developerCategories.ts +142 -0
  46. package/src/components/AppMenu/index.ts +12 -0
  47. package/src/components/AppMenu/types.ts +35 -0
  48. package/src/components/AppMenu/useRovingTabIndex.ts +118 -0
  49. package/src/components/AppMenu/useServiceWorkerUpdate.ts +68 -0
  50. package/src/components/AppShell/index.tsx +140 -14
  51. package/src/components/ImageEditor/ImageEditor.css +22 -11
  52. package/src/components/ImageEditor/ImageEditor.tsx +38 -40
  53. package/src/components/ImageEditor/ResponsiveButton.tsx +8 -10
  54. package/src/components/ImageEditor/plugins/cropPlugin/CropOverlay.tsx +6 -6
  55. package/src/components/ImageEditor/plugins/cropPlugin/CropToolbar.tsx +6 -10
  56. package/src/components/ImageEditor/plugins/cropPlugin/index.ts +2 -2
  57. package/src/components/ImageEditor/plugins/redactPlugin/RedactToolbar.tsx +8 -17
  58. package/src/components/ImageEditor/plugins/redactPlugin/index.ts +2 -2
  59. package/src/components/ImageEditor/plugins/rotatePlugin.ts +1 -2
  60. package/src/components/ImageEditor/plugins/zoomPlugin/ZoomControls.tsx +4 -6
  61. package/src/components/ImageEditor/useIsSmall.ts +27 -0
  62. package/src/index.ts +25 -1
  63. package/src/components/AppMenu/index.tsx +0 -179
@@ -1,6 +1,4 @@
1
- import ZoomInIcon from "@mui/icons-material/ZoomIn";
2
- import ZoomInMapIcon from "@mui/icons-material/ZoomInMap";
3
- import ZoomOutIcon from "@mui/icons-material/ZoomOut";
1
+ import { ShrinkIcon, ZoomMinusIcon, ZoomPlusIcon } from "@navikt/aksel-icons";
4
2
  import { getLocalizedString } from "@olenbetong/appframe-core";
5
3
  import { ResponsiveButton } from "../../ResponsiveButton.js";
6
4
  import { useZoom } from "./ZoomContext.js";
@@ -16,7 +14,7 @@ export function ZoomControls({ disabled, isSmall = false }: Props) {
16
14
  return (
17
15
  <>
18
16
  <ResponsiveButton
19
- icon={<ZoomOutIcon />}
17
+ icon={<ZoomMinusIcon aria-hidden />}
20
18
  label={getLocalizedString("Zoom out")}
21
19
  onClick={zoomOut}
22
20
  disabled={disabled || !canZoomOut}
@@ -24,7 +22,7 @@ export function ZoomControls({ disabled, isSmall = false }: Props) {
24
22
  />
25
23
  <span className="image-editor__zoom-level">{Math.round(zoom * 100)}%</span>
26
24
  <ResponsiveButton
27
- icon={<ZoomInIcon />}
25
+ icon={<ZoomPlusIcon aria-hidden />}
28
26
  label={getLocalizedString("Zoom in")}
29
27
  onClick={zoomIn}
30
28
  disabled={disabled || !canZoomIn}
@@ -32,7 +30,7 @@ export function ZoomControls({ disabled, isSmall = false }: Props) {
32
30
  />
33
31
  {isZoomed && (
34
32
  <ResponsiveButton
35
- icon={<ZoomInMapIcon />}
33
+ icon={<ShrinkIcon aria-hidden />}
36
34
  label={getLocalizedString("Reset zoom")}
37
35
  onClick={resetZoom}
38
36
  isSmall={isSmall}
@@ -0,0 +1,27 @@
1
+ import { useEffect, useState } from "react";
2
+
3
+ const SMALL_SCREEN_QUERY = "(max-width: 600px)";
4
+
5
+ /**
6
+ * Matches the breakpoint where the image editor collapses button labels into
7
+ * icon-only buttons.
8
+ */
9
+ export function useIsSmall() {
10
+ let [isSmall, setIsSmall] = useState(() => globalThis.matchMedia?.(SMALL_SCREEN_QUERY).matches ?? false);
11
+
12
+ useEffect(() => {
13
+ let media = globalThis.matchMedia?.(SMALL_SCREEN_QUERY);
14
+ if (!media) return;
15
+
16
+ function update() {
17
+ setIsSmall(media?.matches ?? false);
18
+ }
19
+
20
+ update();
21
+ media.addEventListener("change", update);
22
+
23
+ return () => media.removeEventListener("change", update);
24
+ }, []);
25
+
26
+ return isSmall;
27
+ }
package/src/index.ts CHANGED
@@ -1,6 +1,30 @@
1
- export { AppMenu, type AppMenuArticle, type AppMenuProps } from "./components/AppMenu/index.js";
1
+ export {
2
+ AppMenu,
3
+ type AppMenuArticle,
4
+ type AppMenuCategory,
5
+ AppMenuColorScheme,
6
+ type AppMenuLink,
7
+ type AppMenuLinkGroup,
8
+ type AppMenuProps,
9
+ AppMenuToggle,
10
+ type AppMenuToggleProps,
11
+ type AppMenuUser,
12
+ AppMenuUserMenu,
13
+ type AppMenuUserMenuProps,
14
+ createDeveloperCategories,
15
+ defaultUserMenuItems,
16
+ type DeveloperCategoryOptions,
17
+ useServiceWorkerUpdate,
18
+ } from "./components/AppMenu/index.js";
2
19
  export { AppShell, type AppShellProps } from "./components/AppShell/index.js";
3
20
  export { Checkbox, type CheckboxProps } from "./components/Checkbox/index.js";
21
+ export {
22
+ COLOR_SCHEME_CHANGE_EVENT,
23
+ type ColorSchemePreference,
24
+ getColorSchemePreference,
25
+ setColorSchemePreference,
26
+ useColorSchemePreference,
27
+ } from "./colorScheme.js";
4
28
  export { CardColumn, CardDetail, CardLabel, CardStep, CardStepList, ColorCard } from "./components/ColorCard/index.js";
5
29
  export { DateNavigator } from "./components/DateNavigator/index.js";
6
30
  export * from "./components/FilePond.js";
@@ -1,179 +0,0 @@
1
- import "./AppMenu.css";
2
-
3
- import type { DataObject } from "@olenbetong/appframe-data";
4
- import { useData, useLoading } from "@olenbetong/appframe-react";
5
- import { useEffect, useMemo, useRef, useState } from "react";
6
-
7
- export type AppMenuArticle = {
8
- ArticleId: string;
9
- Title: string | null;
10
- MenuGroup: string | null;
11
- Path: string | null;
12
- };
13
-
14
- /** Strip version suffixes from ArticleId for building hrefs. */
15
- function stripVersionSuffix(articleId: string): string {
16
- if (articleId.length > 9 && articleId[articleId.length - 8] === ".") {
17
- return articleId.slice(0, -8);
18
- }
19
- if (articleId.length > 5 && articleId[articleId.length - 4] === ".") {
20
- return articleId.slice(0, -4);
21
- }
22
- return articleId;
23
- }
24
-
25
- /** Group records by MenuGroup, returning an ordered list of [group, items] pairs. */
26
- function groupByMenuGroup<T extends { MenuGroup: string | null; Title: string | null }>(
27
- items: readonly T[],
28
- ): [string, T[]][] {
29
- let map = new Map<string, T[]>();
30
- for (let item of items) {
31
- let key = item.MenuGroup ?? "";
32
- let list = map.get(key);
33
- if (!list) {
34
- list = [];
35
- map.set(key, list);
36
- }
37
- list.push(item);
38
- }
39
- return [...map.entries()];
40
- }
41
-
42
- export type AppMenuProps = {
43
- dataObject: DataObject<AppMenuArticle>;
44
- };
45
-
46
- export function AppMenu({ dataObject }: AppMenuProps) {
47
- let dialogRef = useRef<HTMLDialogElement>(null);
48
- let searchRef = useRef<HTMLInputElement>(null);
49
- let [search, setSearch] = useState("");
50
- let [isOpen, setIsOpen] = useState(false);
51
-
52
- let isLoading = useLoading(dataObject);
53
- let allArticles = useData<AppMenuArticle>(dataObject);
54
-
55
- // Refresh data when opened for the first time
56
- useEffect(() => {
57
- if (isOpen && allArticles.length === 0 && !isLoading) {
58
- dataObject.refreshDataSource();
59
- }
60
- }, [isOpen, allArticles.length, isLoading, dataObject]);
61
-
62
- let filtered = useMemo(() => {
63
- if (!search.trim()) return allArticles;
64
- let lower = search.toLowerCase();
65
- return allArticles.filter((a) => (a.Title ?? "").toLowerCase().includes(lower));
66
- }, [allArticles, search]);
67
-
68
- let groups = useMemo(() => groupByMenuGroup(filtered), [filtered]);
69
-
70
- function openDialog() {
71
- let dialog = dialogRef.current;
72
- if (!dialog) return;
73
- setIsOpen(true);
74
- dialog.showModal();
75
- // Focus search after dialog opens
76
- requestAnimationFrame(() => searchRef.current?.focus());
77
- }
78
-
79
- function closeDialog() {
80
- let dialog = dialogRef.current;
81
- if (!dialog) return;
82
- setSearch("");
83
- setIsOpen(false);
84
- dialog.close();
85
- }
86
-
87
- function handleBackdropClick(e: React.MouseEvent<HTMLDialogElement>) {
88
- // Close when clicking outside the dialog content (on the backdrop)
89
- let rect = dialogRef.current?.getBoundingClientRect();
90
- if (!rect) return;
91
- let { clientX, clientY } = e;
92
- if (clientX < rect.left || clientX > rect.right || clientY < rect.top || clientY > rect.bottom) {
93
- closeDialog();
94
- }
95
- }
96
-
97
- // Native <dialog> handles Escape automatically — just sync state
98
- function handleCancel() {
99
- setSearch("");
100
- setIsOpen(false);
101
- }
102
-
103
- return (
104
- <>
105
- <button
106
- type="button"
107
- className="app-menu-trigger"
108
- aria-label="Open app menu"
109
- aria-haspopup="dialog"
110
- aria-expanded={isOpen}
111
- onClick={openDialog}
112
- >
113
- <svg
114
- className="app-menu-icon"
115
- xmlns="http://www.w3.org/2000/svg"
116
- viewBox="0 0 24 24"
117
- fill="currentColor"
118
- aria-hidden="true"
119
- focusable="false"
120
- width="24"
121
- height="24"
122
- >
123
- <path d="M4 6h4V4H4v2zm0 5h4V9H4v2zm0 5h4v-2H4v2zM10 4v2h10V4H10zm0 7h10V9H10v2zm0 5h10v-2H10v2z" />
124
- </svg>
125
- </button>
126
-
127
- {/* oxlint-disable-next-line jsx-a11y/click-events-have-key-events -- backdrop click handled via mouse coords */}
128
- <dialog
129
- ref={dialogRef}
130
- className="app-menu-dialog"
131
- aria-label="App menu"
132
- onClick={handleBackdropClick}
133
- onCancel={handleCancel}
134
- >
135
- <div className="app-menu-dialog-inner">
136
- <div className="app-menu-search-row">
137
- <label htmlFor="app-menu-search" className="visually-hidden">
138
- Search apps
139
- </label>
140
- <input
141
- ref={searchRef}
142
- id="app-menu-search"
143
- type="search"
144
- className="app-menu-search"
145
- placeholder="Search apps…"
146
- value={search}
147
- onChange={(e) => setSearch(e.target.value)}
148
- autoComplete="off"
149
- />
150
- </div>
151
-
152
- {isLoading && <p className="app-menu-loading">Loading…</p>}
153
-
154
- {!isLoading && groups.length === 0 && <p className="app-menu-empty">No apps found.</p>}
155
-
156
- <div className="app-menu-groups">
157
- {groups.map(([group, items]) => (
158
- <section key={group} className="app-menu-group">
159
- {group && <h2 className="app-menu-group-title">{group}</h2>}
160
- <ul className="app-menu-list">
161
- {items.map((article) => {
162
- let href = `/${stripVersionSuffix(article.ArticleId)}`;
163
- return (
164
- <li key={article.ArticleId} className="app-menu-item">
165
- <a href={href} className="app-menu-link" onClick={closeDialog}>
166
- {article.Title ?? article.ArticleId}
167
- </a>
168
- </li>
169
- );
170
- })}
171
- </ul>
172
- </section>
173
- ))}
174
- </div>
175
- </div>
176
- </dialog>
177
- </>
178
- );
179
- }