@olenbetong/synergi-react 4.3.0 → 5.0.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 (81) hide show
  1. package/dist/styles/styles.css +1 -1
  2. package/dist/styles/styles.css.map +1 -1
  3. package/es/components/CodeEditor/CodeEditor.css +6 -6
  4. package/es/components/MergeProgressDialog/MergeProgressDialogDs.d.ts +7 -0
  5. package/es/components/MergeProgressDialog/MergeProgressDialogDs.js +20 -0
  6. package/es/components/MergeProgressDialog/index.d.ts +3 -8
  7. package/es/components/MergeProgressDialog/index.js +4 -113
  8. package/es/components/MergeProgressDialog/useMergeJob.d.ts +36 -0
  9. package/es/components/MergeProgressDialog/useMergeJob.js +141 -0
  10. package/es/components/ProgressBar/index.css +1 -1
  11. package/es/components/Toolbar/Toolbar.css +137 -137
  12. package/es/elements/ElementLookupDialog/BarcodeScanner/BarcodeScanner.css +81 -0
  13. package/es/elements/ElementLookupDialog/BarcodeScanner/DeadIcon.d.ts +2 -2
  14. package/es/elements/ElementLookupDialog/BarcodeScanner/DeadIcon.js +1 -2
  15. package/es/elements/ElementLookupDialog/BarcodeScanner/Error.js +3 -29
  16. package/es/elements/ElementLookupDialog/BarcodeScanner/index.d.ts +1 -0
  17. package/es/elements/ElementLookupDialog/BarcodeScanner/index.js +3 -28
  18. package/es/index.css +1 -1
  19. package/es/index.d.ts +2 -1
  20. package/es/index.js +2 -1
  21. package/es/mui/index.d.ts +1 -0
  22. package/es/mui/index.js +1 -0
  23. package/es/test/setup.d.ts +5 -0
  24. package/package.json +21 -14
  25. package/src/chrome/AppShell/index.tsx +29 -29
  26. package/src/chrome/openReport.ts +34 -34
  27. package/src/colorScheme.ts +125 -125
  28. package/src/components/CodeEditor/CodeEditor.css +6 -6
  29. package/src/components/CodeEditor/CodeEditor.tsx +173 -173
  30. package/src/components/CodeEditor/index.ts +1 -1
  31. package/src/components/DateNavigator/index.tsx +186 -186
  32. package/src/components/FilePond.tsx +312 -312
  33. package/src/components/ImageEditor/ImageEditor.tsx +348 -348
  34. package/src/components/ImageEditor/index.ts +9 -9
  35. package/src/components/ImageEditor/plugins/cropPlugin/CropOverlay.tsx +165 -165
  36. package/src/components/ImageEditor/plugins/cropPlugin/CropToolbar.tsx +48 -48
  37. package/src/components/ImageEditor/plugins/cropPlugin/useCropTool.ts +405 -405
  38. package/src/components/ImageEditor/plugins/redactPlugin/RedactToolbar.tsx +47 -47
  39. package/src/components/ImageEditor/plugins/zoomPlugin/ZoomContext.tsx +23 -23
  40. package/src/components/ImageEditor/plugins/zoomPlugin/ZoomControls.tsx +40 -40
  41. package/src/components/ImageEditor/useActiveTool.ts +21 -21
  42. package/src/components/ImageEditor/useEdgeDetection.ts +319 -319
  43. package/src/components/ImageEditor/useImageHistory.ts +197 -197
  44. package/src/components/ImageEditor/useOpenCV.ts +184 -184
  45. package/src/components/LinkedCardList/index.scss +95 -95
  46. package/src/components/MergeProgressDialog/MergeProgressDialogDs.tsx +91 -0
  47. package/src/components/MergeProgressDialog/index.tsx +5 -136
  48. package/src/components/MergeProgressDialog/useMergeJob.ts +169 -0
  49. package/src/components/PageBanner/index.tsx +80 -80
  50. package/src/components/PdfViewer/PdfViewer.tsx +158 -158
  51. package/src/components/ProgressBar/index.scss +23 -54
  52. package/src/components/SplitContainer/index.tsx +333 -333
  53. package/src/components/Toolbar/Toolbar.css +137 -137
  54. package/src/components/Toolbar/index.tsx +265 -265
  55. package/src/designsystemet-web-types.d.ts +24 -24
  56. package/src/elements/ElementDamage/DamageFormButtons.tsx +35 -35
  57. package/src/elements/ElementDamage/DescriptionInput.tsx +120 -120
  58. package/src/elements/ElementDamage/DuplicateDamage/DesktopView.tsx +82 -82
  59. package/src/elements/ElementDamage/DuplicateDamage/DublicateElementDamageDialog.tsx +67 -67
  60. package/src/elements/ElementDamage/DuplicateDamage/PhoneView.tsx +45 -45
  61. package/src/elements/ElementDamage/ElementNumberTextField.tsx +41 -41
  62. package/src/elements/ElementDamage/RegisterFix.tsx +100 -100
  63. package/src/elements/ElementDamage/SubmitButtons.tsx +40 -40
  64. package/src/elements/ElementDamage/TransportElementSelect.tsx +52 -52
  65. package/src/elements/ElementLookup.tsx +123 -123
  66. package/src/elements/ElementLookupDialog/BarcodeScanner/BarcodeScanner.css +81 -0
  67. package/src/elements/ElementLookupDialog/BarcodeScanner/DeadIcon.tsx +4 -4
  68. package/src/elements/ElementLookupDialog/BarcodeScanner/Error.tsx +7 -36
  69. package/src/elements/ElementLookupDialog/BarcodeScanner/index.tsx +20 -49
  70. package/src/elements/ElementLookupDialog/HIDScanner/index.tsx +67 -67
  71. package/src/elements/ElementLookupDialog/Manual/ManualForm.tsx +141 -141
  72. package/src/elements/ElementLookupDialog/index.tsx +226 -226
  73. package/src/elements/ElementLookupDialog/utils/Giai.ts +209 -209
  74. package/src/elements/ProjectSelect.tsx +130 -130
  75. package/src/elements/index.ts +15 -15
  76. package/src/filter/index.ts +34 -34
  77. package/src/i18n.ts +13 -13
  78. package/src/index.ts +5 -1
  79. package/src/mui/MuiThemeProvider.tsx +135 -135
  80. package/src/mui/index.ts +1 -0
  81. package/src/test/setup.ts +23 -8
@@ -1,265 +1,265 @@
1
- import "./Toolbar.css";
2
-
3
- import { MenuHamburgerIcon } from "@navikt/aksel-icons";
4
- import { useEffect, useId, useLayoutEffect, useRef, useState } from "react";
5
- import { createPortal } from "react-dom";
6
- import { Link, type To } from "react-router";
7
- import { getLocalizedString } from "../../i18n.js";
8
-
9
- /*
10
- * The site template (`ob.2026.application`) renders the toolbar and leaves two regions to the
11
- * app. Both are filled through portals, so the app's React tree (router, contexts, state) is
12
- * preserved inside them:
13
- *
14
- * - the app region (`#ob-toolbar-app`): breadcrumbs first, then any per-app controls;
15
- * - the drawer slot (`#ob-toolbar-drawer`) at the far left of the toolbar, reserved for the
16
- * toggle of the app's navigation drawer — the same edge the drawer slides in from.
17
- *
18
- * Everything else in the toolbar (brand, Apps button, user menu) is the site's, rendered by the
19
- * chrome bundle. The phase 1 template rendered separate slots instead; those ids are kept as
20
- * fallbacks until every site runs the current template.
21
- */
22
-
23
- const APP_REGION_IDS = ["ob-toolbar-app", "ob-toolbar-breadcrumbs"];
24
- const DRAWER_SLOT_IDS = ["ob-toolbar-drawer", "ob-toolbar-menu-toggle"];
25
-
26
- function findTarget(ids: string[]) {
27
- if (typeof document === "undefined") return null;
28
- for (let id of ids) {
29
- let element = document.getElementById(id);
30
- if (element) return element;
31
- }
32
- return null;
33
- }
34
-
35
- /**
36
- * The 2026 template reserves the drawer slot only for articles whose deploy wrote the
37
- * `ToolbarDrawer` block (the build detects `ToolbarDrawerToggle` in the app). An app with a
38
- * drawer that has not been deployed since renders on a toolbar without the slot: create it in
39
- * front of the app region and drop the no-drawer layout class, so the toggle still mounts. The
40
- * toolbar shifts once when that happens, which the block avoids on the next deploy.
41
- */
42
- function createDrawerSlot() {
43
- let toolbar = document.querySelector<HTMLElement>(".ob-toolbar");
44
- let lead = toolbar?.querySelector<HTMLElement>(".ob-toolbar__lead");
45
- if (!toolbar || !lead) return null;
46
-
47
- let slot = document.createElement("div");
48
- slot.id = DRAWER_SLOT_IDS[0];
49
- slot.className = "ob-toolbar__drawer";
50
- lead.prepend(slot);
51
- toolbar.classList.remove("ob-toolbar--no-drawer");
52
- return slot;
53
- }
54
-
55
- export type ToolbarPortalProps = {
56
- children: React.ReactNode;
57
- };
58
-
59
- /**
60
- * Renders its children into the toolbar's app region. Render `ToolbarBreadcrumbs` before any
61
- * other `ToolbarPortal`, since the region lays its children out in mount order with the first
62
- * one taking the free space. Renders nothing on a template without a toolbar.
63
- */
64
- export function ToolbarPortal({ children }: ToolbarPortalProps) {
65
- let target = findTarget(APP_REGION_IDS);
66
- if (!target) return null;
67
- return createPortal(children, target);
68
- }
69
-
70
- export type ToolbarDrawerToggleProps = {
71
- /** Whether the drawer is open; sets `aria-expanded`. */
72
- open: boolean;
73
- onToggle: () => void;
74
- /** Accessible name. Defaults to the localized "Toggle menu". */
75
- label?: string;
76
- };
77
-
78
- /**
79
- * The hamburger button for the app's navigation drawer, rendered into the toolbar's drawer slot.
80
- * Styled by the site stylesheet (`.ob-toolbar__icon-button`) so it inherits the toolbar's
81
- * contrast colour on every brand. Renders nothing on a template without a toolbar.
82
- */
83
- export function ToolbarDrawerToggle({ open, onToggle, label }: ToolbarDrawerToggleProps) {
84
- let target = findTarget(DRAWER_SLOT_IDS) ?? createDrawerSlot();
85
- if (!target) return null;
86
-
87
- return createPortal(
88
- <button
89
- type="button"
90
- className="ob-toolbar__icon-button"
91
- aria-label={label ?? getLocalizedString("Toggle menu")}
92
- aria-expanded={open}
93
- onClick={onToggle}
94
- >
95
- <MenuHamburgerIcon aria-hidden fontSize="1.5rem" />
96
- </button>,
97
- target,
98
- );
99
- }
100
-
101
- export type BreadcrumbItem = {
102
- label: string;
103
- /**
104
- * A route inside the app, followed without reloading the page. Resolved through the router, so
105
- * it is relative to the app's basename — the article root is `"/"`, not `"/my-article"`.
106
- *
107
- * Requires the breadcrumbs to be rendered inside a router, which the portal preserves.
108
- */
109
- to?: To;
110
- /**
111
- * A plain URL, followed with a full page load. Use it to leave the app — the front page, or
112
- * another article. `to` wins when both are given.
113
- */
114
- href?: string;
115
- };
116
-
117
- /**
118
- * A crumb the user can follow. `to` goes through the router; `href` is an ordinary link.
119
- *
120
- * Either way it renders a real anchor with a real `href`, so ctrl-click, middle-click, "open in
121
- * new tab" and the status bar all keep working — `Link` only intercepts a plain left click.
122
- */
123
- function BreadcrumbLink({ item }: { item: BreadcrumbItem }) {
124
- if (item.to != null) return <Link to={item.to}>{item.label}</Link>;
125
- if (item.href) return <a href={item.href}>{item.label}</a>;
126
-
127
- return <span>{item.label}</span>;
128
- }
129
-
130
- export type ToolbarBreadcrumbsProps = {
131
- items: BreadcrumbItem[];
132
- };
133
-
134
- function BreadcrumbsInner({ items }: ToolbarBreadcrumbsProps) {
135
- let [firstVisible, setFirstVisible] = useState(0);
136
- let [menuOpen, setMenuOpen] = useState(false);
137
- let navRef = useRef<HTMLElement>(null);
138
- let listRef = useRef<HTMLOListElement>(null);
139
- let buttonRef = useRef<HTMLButtonElement>(null);
140
- let menuRef = useRef<HTMLUListElement>(null);
141
- let menuId = useId();
142
-
143
- // A new trail (the user navigated) is measured from scratch. Adjusted during render, so
144
- // the previous page's collapse never paints on the new one.
145
- let trail = items.map((item) => item.label).join("\n");
146
- let [measuredTrail, setMeasuredTrail] = useState(trail);
147
- if (measuredTrail !== trail) {
148
- setMeasuredTrail(trail);
149
- setFirstVisible(0);
150
- }
151
-
152
- // Detect overflow: increment firstVisible until the list fits within the nav.
153
- // Runs after every render so it keeps pushing items into overflow until the
154
- // list stops overflowing or only the last item (current page) remains.
155
- useLayoutEffect(() => {
156
- let list = listRef.current;
157
- if (!list) return;
158
-
159
- // Against the list's own box, not the nav's: the nav also holds the separator the site
160
- // stylesheet draws between the brand and the trail.
161
- if (list.scrollWidth > list.clientWidth + 1 && firstVisible < items.length - 1) {
162
- setFirstVisible((prev) => prev + 1);
163
- }
164
- });
165
-
166
- // ResizeObserver resets firstVisible to 0 on container resize so that the
167
- // overflow calculation starts fresh at the new container width.
168
- useEffect(() => {
169
- let nav = navRef.current;
170
- if (!nav) return;
171
-
172
- let width = nav.clientWidth;
173
- let observer = new ResizeObserver(() => {
174
- // The first callback reports the size the trail was just measured at.
175
- if (nav.clientWidth === width) return;
176
- width = nav.clientWidth;
177
- setFirstVisible(0);
178
- });
179
-
180
- observer.observe(nav);
181
- return () => observer.disconnect();
182
- }, []);
183
-
184
- /*
185
- * The menu is a popover: it renders in the top layer, so the toolbar and the trail, which
186
- * both clip their overflow, cannot cut it off, and the browser closes it on Escape and on a
187
- * click outside. The top layer has no positioned ancestor, so it is placed under the button
188
- * by hand, and pulled back in when it would run past the edge of a narrow screen.
189
- */
190
- function placeMenu() {
191
- let button = buttonRef.current;
192
- let menu = menuRef.current;
193
- if (!button || !menu) return;
194
-
195
- let rect = button.getBoundingClientRect();
196
- let margin = 8;
197
- let left = Math.min(rect.left, window.innerWidth - menu.offsetWidth - margin);
198
- menu.style.top = `${rect.bottom + 4}px`;
199
- menu.style.left = `${Math.max(left, margin)}px`;
200
- }
201
-
202
- let hiddenItems = items.slice(0, firstVisible);
203
- let visibleItems = items.slice(firstVisible);
204
-
205
- return (
206
- <nav className="ob-breadcrumbs" aria-label="Breadcrumb" ref={navRef}>
207
- <ol className="ob-breadcrumbs__list" ref={listRef}>
208
- {firstVisible > 0 && (
209
- <li className="ob-breadcrumbs__item ob-breadcrumbs__overflow">
210
- <button
211
- ref={buttonRef}
212
- type="button"
213
- aria-label={getLocalizedString("Show hidden breadcrumbs")}
214
- aria-expanded={menuOpen}
215
- popoverTarget={menuId}
216
- >
217
- &hellip;
218
- </button>
219
- <ul
220
- ref={menuRef}
221
- id={menuId}
222
- popover="auto"
223
- className="ob-breadcrumbs__overflow-menu"
224
- // Placed before it shows, so it never paints in the popover's default
225
- // spot, and again once it has a width to keep it on the screen.
226
- onBeforeToggle={(event) => {
227
- if (event.newState === "open") placeMenu();
228
- }}
229
- onToggle={(event) => {
230
- let open = event.newState === "open";
231
- setMenuOpen(open);
232
- if (open) placeMenu();
233
- }}
234
- >
235
- {hiddenItems.map((item, index) => (
236
- // oxlint-disable-next-line react/no-array-index-key -- stable list with no reordering
237
- <li key={index} onClick={() => menuRef.current?.hidePopover()}>
238
- <BreadcrumbLink item={item} />
239
- </li>
240
- ))}
241
- </ul>
242
- </li>
243
- )}
244
- {visibleItems.map((item, index) => {
245
- let actualIndex = firstVisible + index;
246
- let isCurrent = actualIndex === items.length - 1;
247
- return (
248
- <li key={actualIndex} className="ob-breadcrumbs__item">
249
- {isCurrent ? <span aria-current="page">{item.label}</span> : <BreadcrumbLink item={item} />}
250
- </li>
251
- );
252
- })}
253
- </ol>
254
- </nav>
255
- );
256
- }
257
-
258
- /** The app's breadcrumb trail, rendered into the toolbar's app region. The last item is the current page. */
259
- export function ToolbarBreadcrumbs({ items }: ToolbarBreadcrumbsProps) {
260
- return (
261
- <ToolbarPortal>
262
- <BreadcrumbsInner items={items} />
263
- </ToolbarPortal>
264
- );
265
- }
1
+ import "./Toolbar.css";
2
+
3
+ import { MenuHamburgerIcon } from "@navikt/aksel-icons";
4
+ import { useEffect, useId, useLayoutEffect, useRef, useState } from "react";
5
+ import { createPortal } from "react-dom";
6
+ import { Link, type To } from "react-router";
7
+ import { getLocalizedString } from "../../i18n.js";
8
+
9
+ /*
10
+ * The site template (`ob.2026.application`) renders the toolbar and leaves two regions to the
11
+ * app. Both are filled through portals, so the app's React tree (router, contexts, state) is
12
+ * preserved inside them:
13
+ *
14
+ * - the app region (`#ob-toolbar-app`): breadcrumbs first, then any per-app controls;
15
+ * - the drawer slot (`#ob-toolbar-drawer`) at the far left of the toolbar, reserved for the
16
+ * toggle of the app's navigation drawer — the same edge the drawer slides in from.
17
+ *
18
+ * Everything else in the toolbar (brand, Apps button, user menu) is the site's, rendered by the
19
+ * chrome bundle. The phase 1 template rendered separate slots instead; those ids are kept as
20
+ * fallbacks until every site runs the current template.
21
+ */
22
+
23
+ const APP_REGION_IDS = ["ob-toolbar-app", "ob-toolbar-breadcrumbs"];
24
+ const DRAWER_SLOT_IDS = ["ob-toolbar-drawer", "ob-toolbar-menu-toggle"];
25
+
26
+ function findTarget(ids: string[]) {
27
+ if (typeof document === "undefined") return null;
28
+ for (let id of ids) {
29
+ let element = document.getElementById(id);
30
+ if (element) return element;
31
+ }
32
+ return null;
33
+ }
34
+
35
+ /**
36
+ * The 2026 template reserves the drawer slot only for articles whose deploy wrote the
37
+ * `ToolbarDrawer` block (the build detects `ToolbarDrawerToggle` in the app). An app with a
38
+ * drawer that has not been deployed since renders on a toolbar without the slot: create it in
39
+ * front of the app region and drop the no-drawer layout class, so the toggle still mounts. The
40
+ * toolbar shifts once when that happens, which the block avoids on the next deploy.
41
+ */
42
+ function createDrawerSlot() {
43
+ let toolbar = document.querySelector<HTMLElement>(".ob-toolbar");
44
+ let lead = toolbar?.querySelector<HTMLElement>(".ob-toolbar__lead");
45
+ if (!toolbar || !lead) return null;
46
+
47
+ let slot = document.createElement("div");
48
+ slot.id = DRAWER_SLOT_IDS[0];
49
+ slot.className = "ob-toolbar__drawer";
50
+ lead.prepend(slot);
51
+ toolbar.classList.remove("ob-toolbar--no-drawer");
52
+ return slot;
53
+ }
54
+
55
+ export type ToolbarPortalProps = {
56
+ children: React.ReactNode;
57
+ };
58
+
59
+ /**
60
+ * Renders its children into the toolbar's app region. Render `ToolbarBreadcrumbs` before any
61
+ * other `ToolbarPortal`, since the region lays its children out in mount order with the first
62
+ * one taking the free space. Renders nothing on a template without a toolbar.
63
+ */
64
+ export function ToolbarPortal({ children }: ToolbarPortalProps) {
65
+ let target = findTarget(APP_REGION_IDS);
66
+ if (!target) return null;
67
+ return createPortal(children, target);
68
+ }
69
+
70
+ export type ToolbarDrawerToggleProps = {
71
+ /** Whether the drawer is open; sets `aria-expanded`. */
72
+ open: boolean;
73
+ onToggle: () => void;
74
+ /** Accessible name. Defaults to the localized "Toggle menu". */
75
+ label?: string;
76
+ };
77
+
78
+ /**
79
+ * The hamburger button for the app's navigation drawer, rendered into the toolbar's drawer slot.
80
+ * Styled by the site stylesheet (`.ob-toolbar__icon-button`) so it inherits the toolbar's
81
+ * contrast colour on every brand. Renders nothing on a template without a toolbar.
82
+ */
83
+ export function ToolbarDrawerToggle({ open, onToggle, label }: ToolbarDrawerToggleProps) {
84
+ let target = findTarget(DRAWER_SLOT_IDS) ?? createDrawerSlot();
85
+ if (!target) return null;
86
+
87
+ return createPortal(
88
+ <button
89
+ type="button"
90
+ className="ob-toolbar__icon-button"
91
+ aria-label={label ?? getLocalizedString("Toggle menu")}
92
+ aria-expanded={open}
93
+ onClick={onToggle}
94
+ >
95
+ <MenuHamburgerIcon aria-hidden fontSize="1.5rem" />
96
+ </button>,
97
+ target,
98
+ );
99
+ }
100
+
101
+ export type BreadcrumbItem = {
102
+ label: string;
103
+ /**
104
+ * A route inside the app, followed without reloading the page. Resolved through the router, so
105
+ * it is relative to the app's basename — the article root is `"/"`, not `"/my-article"`.
106
+ *
107
+ * Requires the breadcrumbs to be rendered inside a router, which the portal preserves.
108
+ */
109
+ to?: To;
110
+ /**
111
+ * A plain URL, followed with a full page load. Use it to leave the app — the front page, or
112
+ * another article. `to` wins when both are given.
113
+ */
114
+ href?: string;
115
+ };
116
+
117
+ /**
118
+ * A crumb the user can follow. `to` goes through the router; `href` is an ordinary link.
119
+ *
120
+ * Either way it renders a real anchor with a real `href`, so ctrl-click, middle-click, "open in
121
+ * new tab" and the status bar all keep working — `Link` only intercepts a plain left click.
122
+ */
123
+ function BreadcrumbLink({ item }: { item: BreadcrumbItem }) {
124
+ if (item.to != null) return <Link to={item.to}>{item.label}</Link>;
125
+ if (item.href) return <a href={item.href}>{item.label}</a>;
126
+
127
+ return <span>{item.label}</span>;
128
+ }
129
+
130
+ export type ToolbarBreadcrumbsProps = {
131
+ items: BreadcrumbItem[];
132
+ };
133
+
134
+ function BreadcrumbsInner({ items }: ToolbarBreadcrumbsProps) {
135
+ let [firstVisible, setFirstVisible] = useState(0);
136
+ let [menuOpen, setMenuOpen] = useState(false);
137
+ let navRef = useRef<HTMLElement>(null);
138
+ let listRef = useRef<HTMLOListElement>(null);
139
+ let buttonRef = useRef<HTMLButtonElement>(null);
140
+ let menuRef = useRef<HTMLUListElement>(null);
141
+ let menuId = useId();
142
+
143
+ // A new trail (the user navigated) is measured from scratch. Adjusted during render, so
144
+ // the previous page's collapse never paints on the new one.
145
+ let trail = items.map((item) => item.label).join("\n");
146
+ let [measuredTrail, setMeasuredTrail] = useState(trail);
147
+ if (measuredTrail !== trail) {
148
+ setMeasuredTrail(trail);
149
+ setFirstVisible(0);
150
+ }
151
+
152
+ // Detect overflow: increment firstVisible until the list fits within the nav.
153
+ // Runs after every render so it keeps pushing items into overflow until the
154
+ // list stops overflowing or only the last item (current page) remains.
155
+ useLayoutEffect(() => {
156
+ let list = listRef.current;
157
+ if (!list) return;
158
+
159
+ // Against the list's own box, not the nav's: the nav also holds the separator the site
160
+ // stylesheet draws between the brand and the trail.
161
+ if (list.scrollWidth > list.clientWidth + 1 && firstVisible < items.length - 1) {
162
+ setFirstVisible((prev) => prev + 1);
163
+ }
164
+ });
165
+
166
+ // ResizeObserver resets firstVisible to 0 on container resize so that the
167
+ // overflow calculation starts fresh at the new container width.
168
+ useEffect(() => {
169
+ let nav = navRef.current;
170
+ if (!nav) return;
171
+
172
+ let width = nav.clientWidth;
173
+ let observer = new ResizeObserver(() => {
174
+ // The first callback reports the size the trail was just measured at.
175
+ if (nav.clientWidth === width) return;
176
+ width = nav.clientWidth;
177
+ setFirstVisible(0);
178
+ });
179
+
180
+ observer.observe(nav);
181
+ return () => observer.disconnect();
182
+ }, []);
183
+
184
+ /*
185
+ * The menu is a popover: it renders in the top layer, so the toolbar and the trail, which
186
+ * both clip their overflow, cannot cut it off, and the browser closes it on Escape and on a
187
+ * click outside. The top layer has no positioned ancestor, so it is placed under the button
188
+ * by hand, and pulled back in when it would run past the edge of a narrow screen.
189
+ */
190
+ function placeMenu() {
191
+ let button = buttonRef.current;
192
+ let menu = menuRef.current;
193
+ if (!button || !menu) return;
194
+
195
+ let rect = button.getBoundingClientRect();
196
+ let margin = 8;
197
+ let left = Math.min(rect.left, window.innerWidth - menu.offsetWidth - margin);
198
+ menu.style.top = `${rect.bottom + 4}px`;
199
+ menu.style.left = `${Math.max(left, margin)}px`;
200
+ }
201
+
202
+ let hiddenItems = items.slice(0, firstVisible);
203
+ let visibleItems = items.slice(firstVisible);
204
+
205
+ return (
206
+ <nav className="ob-breadcrumbs" aria-label="Breadcrumb" ref={navRef}>
207
+ <ol className="ob-breadcrumbs__list" ref={listRef}>
208
+ {firstVisible > 0 && (
209
+ <li className="ob-breadcrumbs__item ob-breadcrumbs__overflow">
210
+ <button
211
+ ref={buttonRef}
212
+ type="button"
213
+ aria-label={getLocalizedString("Show hidden breadcrumbs")}
214
+ aria-expanded={menuOpen}
215
+ popoverTarget={menuId}
216
+ >
217
+ &hellip;
218
+ </button>
219
+ <ul
220
+ ref={menuRef}
221
+ id={menuId}
222
+ popover="auto"
223
+ className="ob-breadcrumbs__overflow-menu"
224
+ // Placed before it shows, so it never paints in the popover's default
225
+ // spot, and again once it has a width to keep it on the screen.
226
+ onBeforeToggle={(event) => {
227
+ if (event.newState === "open") placeMenu();
228
+ }}
229
+ onToggle={(event) => {
230
+ let open = event.newState === "open";
231
+ setMenuOpen(open);
232
+ if (open) placeMenu();
233
+ }}
234
+ >
235
+ {hiddenItems.map((item, index) => (
236
+ // oxlint-disable-next-line react/no-array-index-key -- stable list with no reordering
237
+ <li key={index} onClick={() => menuRef.current?.hidePopover()}>
238
+ <BreadcrumbLink item={item} />
239
+ </li>
240
+ ))}
241
+ </ul>
242
+ </li>
243
+ )}
244
+ {visibleItems.map((item, index) => {
245
+ let actualIndex = firstVisible + index;
246
+ let isCurrent = actualIndex === items.length - 1;
247
+ return (
248
+ <li key={actualIndex} className="ob-breadcrumbs__item">
249
+ {isCurrent ? <span aria-current="page">{item.label}</span> : <BreadcrumbLink item={item} />}
250
+ </li>
251
+ );
252
+ })}
253
+ </ol>
254
+ </nav>
255
+ );
256
+ }
257
+
258
+ /** The app's breadcrumb trail, rendered into the toolbar's app region. The last item is the current page. */
259
+ export function ToolbarBreadcrumbs({ items }: ToolbarBreadcrumbsProps) {
260
+ return (
261
+ <ToolbarPortal>
262
+ <BreadcrumbsInner items={items} />
263
+ </ToolbarPortal>
264
+ );
265
+ }
@@ -1,24 +1,24 @@
1
- import type * as ReactModule from "react";
2
-
3
- /**
4
- * `@digdir/designsystemet-web` registers its custom elements (`ds-tabs`,
5
- * `ds-field`, …) in `React.JSX.IntrinsicElements` and types them with
6
- * `ReactTypes.*` — but its bundled `index.d.ts` lost the matching
7
- * `import type * as ReactTypes from "react"`. Those entries therefore resolve
8
- * to an error type, which `skipLibCheck` hides while `React.ElementType`
9
- * (a mapped type over `keyof JSX.IntrinsicElements`) silently degrades.
10
- *
11
- * The fallout lands on MUI, which is only pulled into the same program here:
12
- * `<Box component="…" />` stops accepting the element's own props, and MUI
13
- * callback parameters (`sx` theme, `onClick` event, `Tabs onChange`) turn into
14
- * implicit `any`.
15
- *
16
- * Declaring the `ReactTypes` namespace globally gives that file what it is
17
- * missing. Remove this once Designsystemet ships the import in its `.d.ts`.
18
- */
19
- declare global {
20
- namespace ReactTypes {
21
- type HTMLAttributes<T> = ReactModule.HTMLAttributes<T>;
22
- type DetailedHTMLProps<E extends ReactModule.HTMLAttributes<T>, T> = ReactModule.DetailedHTMLProps<E, T>;
23
- }
24
- }
1
+ import type * as ReactModule from "react";
2
+
3
+ /**
4
+ * `@digdir/designsystemet-web` registers its custom elements (`ds-tabs`,
5
+ * `ds-field`, …) in `React.JSX.IntrinsicElements` and types them with
6
+ * `ReactTypes.*` — but its bundled `index.d.ts` lost the matching
7
+ * `import type * as ReactTypes from "react"`. Those entries therefore resolve
8
+ * to an error type, which `skipLibCheck` hides while `React.ElementType`
9
+ * (a mapped type over `keyof JSX.IntrinsicElements`) silently degrades.
10
+ *
11
+ * The fallout lands on MUI, which is only pulled into the same program here:
12
+ * `<Box component="…" />` stops accepting the element's own props, and MUI
13
+ * callback parameters (`sx` theme, `onClick` event, `Tabs onChange`) turn into
14
+ * implicit `any`.
15
+ *
16
+ * Declaring the `ReactTypes` namespace globally gives that file what it is
17
+ * missing. Remove this once Designsystemet ships the import in its `.d.ts`.
18
+ */
19
+ declare global {
20
+ namespace ReactTypes {
21
+ type HTMLAttributes<T> = ReactModule.HTMLAttributes<T>;
22
+ type DetailedHTMLProps<E extends ReactModule.HTMLAttributes<T>, T> = ReactModule.DetailedHTMLProps<E, T>;
23
+ }
24
+ }
@@ -1,35 +1,35 @@
1
- import Add from "@mui/icons-material/Add";
2
- import { Button } from "@mui/material";
3
- import { getLocalizedString } from "../../i18n.js";
4
-
5
- export type DamageFormButtonsProps = {
6
- isEdit: boolean;
7
- loading: boolean;
8
- uploadingFile: boolean;
9
- handleDelete: () => void;
10
- handleCancel: () => void;
11
- };
12
-
13
- export function DamageFormButtons({
14
- isEdit,
15
- loading,
16
- uploadingFile,
17
- handleDelete,
18
- handleCancel,
19
- }: DamageFormButtonsProps) {
20
- return (
21
- <>
22
- {isEdit && <Button onClick={handleDelete}>{getLocalizedString("Delete")}</Button>}
23
- <Button onClick={handleCancel}>{getLocalizedString("Cancel")}</Button>
24
- <Button
25
- loading={loading || uploadingFile}
26
- loadingPosition="start"
27
- startIcon={<Add />}
28
- type="submit"
29
- variant="contained"
30
- >
31
- {isEdit ? getLocalizedString("Save changes") : getLocalizedString("Register damage")}
32
- </Button>
33
- </>
34
- );
35
- }
1
+ import Add from "@mui/icons-material/Add";
2
+ import { Button } from "@mui/material";
3
+ import { getLocalizedString } from "../../i18n.js";
4
+
5
+ export type DamageFormButtonsProps = {
6
+ isEdit: boolean;
7
+ loading: boolean;
8
+ uploadingFile: boolean;
9
+ handleDelete: () => void;
10
+ handleCancel: () => void;
11
+ };
12
+
13
+ export function DamageFormButtons({
14
+ isEdit,
15
+ loading,
16
+ uploadingFile,
17
+ handleDelete,
18
+ handleCancel,
19
+ }: DamageFormButtonsProps) {
20
+ return (
21
+ <>
22
+ {isEdit && <Button onClick={handleDelete}>{getLocalizedString("Delete")}</Button>}
23
+ <Button onClick={handleCancel}>{getLocalizedString("Cancel")}</Button>
24
+ <Button
25
+ loading={loading || uploadingFile}
26
+ loadingPosition="start"
27
+ startIcon={<Add />}
28
+ type="submit"
29
+ variant="contained"
30
+ >
31
+ {isEdit ? getLocalizedString("Save changes") : getLocalizedString("Register damage")}
32
+ </Button>
33
+ </>
34
+ );
35
+ }