@olenbetong/synergi-react 4.2.5 → 4.2.7

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 (59) hide show
  1. package/es/components/Toolbar/Toolbar.css +34 -21
  2. package/es/components/Toolbar/index.js +50 -18
  3. package/package.json +6 -6
  4. package/src/chrome/AppShell/index.tsx +29 -29
  5. package/src/chrome/openReport.ts +34 -34
  6. package/src/colorScheme.ts +81 -81
  7. package/src/components/DateNavigator/index.tsx +186 -186
  8. package/src/components/FilePond.tsx +312 -312
  9. package/src/components/ImageEditor/ImageEditor.tsx +348 -348
  10. package/src/components/ImageEditor/index.ts +9 -9
  11. package/src/components/ImageEditor/plugins/cropPlugin/CropOverlay.tsx +165 -165
  12. package/src/components/ImageEditor/plugins/cropPlugin/CropToolbar.tsx +48 -48
  13. package/src/components/ImageEditor/plugins/cropPlugin/useCropTool.ts +405 -405
  14. package/src/components/ImageEditor/plugins/redactPlugin/RedactToolbar.tsx +47 -47
  15. package/src/components/ImageEditor/plugins/zoomPlugin/ZoomContext.tsx +23 -23
  16. package/src/components/ImageEditor/plugins/zoomPlugin/ZoomControls.tsx +40 -40
  17. package/src/components/ImageEditor/useActiveTool.ts +21 -21
  18. package/src/components/ImageEditor/useEdgeDetection.ts +319 -319
  19. package/src/components/ImageEditor/useImageHistory.ts +197 -197
  20. package/src/components/ImageEditor/useOpenCV.ts +184 -184
  21. package/src/components/LinkedCardList/index.scss +95 -95
  22. package/src/components/MergeProgressDialog/index.tsx +249 -249
  23. package/src/components/PageBanner/index.tsx +80 -80
  24. package/src/components/PdfViewer/PdfViewer.tsx +158 -158
  25. package/src/components/ProgressBar/index.scss +96 -96
  26. package/src/components/SplitContainer/index.tsx +333 -333
  27. package/src/components/Toolbar/Toolbar.css +34 -21
  28. package/src/components/Toolbar/index.tsx +265 -232
  29. package/src/designsystemet-web-types.d.ts +24 -24
  30. package/src/elements/ElementDamage/DamageFormButtons.tsx +35 -35
  31. package/src/elements/ElementDamage/DescriptionInput.tsx +120 -120
  32. package/src/elements/ElementDamage/DuplicateDamage/DesktopView.tsx +82 -82
  33. package/src/elements/ElementDamage/DuplicateDamage/DublicateElementDamageDialog.tsx +67 -67
  34. package/src/elements/ElementDamage/DuplicateDamage/PhoneView.tsx +45 -45
  35. package/src/elements/ElementDamage/ElementNumberTextField.tsx +41 -41
  36. package/src/elements/ElementDamage/RegisterFix.tsx +100 -100
  37. package/src/elements/ElementDamage/SubmitButtons.tsx +40 -40
  38. package/src/elements/ElementDamage/TransportElementSelect.tsx +52 -52
  39. package/src/elements/ElementLookup.tsx +123 -123
  40. package/src/elements/ElementLookupDialog/BarcodeScanner/decoder.ts +32 -32
  41. package/src/elements/ElementLookupDialog/BarcodeScanner/decoders/dbr.ts +118 -118
  42. package/src/elements/ElementLookupDialog/BarcodeScanner/decoders/native.ts +103 -103
  43. package/src/elements/ElementLookupDialog/BarcodeScanner/decoders/zxing.ts +95 -95
  44. package/src/elements/ElementLookupDialog/BarcodeScanner/decoders.test.ts +118 -118
  45. package/src/elements/ElementLookupDialog/BarcodeScanner/duplicateFilter.ts +21 -21
  46. package/src/elements/ElementLookupDialog/BarcodeScanner/index.tsx +90 -90
  47. package/src/elements/ElementLookupDialog/BarcodeScanner/useScanner.ts +280 -280
  48. package/src/elements/ElementLookupDialog/HIDScanner/index.tsx +67 -67
  49. package/src/elements/ElementLookupDialog/Manual/ManualForm.tsx +141 -141
  50. package/src/elements/ElementLookupDialog/index.tsx +226 -226
  51. package/src/elements/ElementLookupDialog/utils/Giai.ts +209 -209
  52. package/src/elements/ProjectSelect.tsx +130 -130
  53. package/src/elements/index.ts +15 -15
  54. package/src/filter/index.ts +34 -34
  55. package/src/i18n.ts +13 -13
  56. package/src/index.ts +77 -77
  57. package/src/mui/MuiThemeProvider.tsx +174 -174
  58. package/src/mui/index.ts +1 -1
  59. package/src/test/setup.ts +8 -8
@@ -19,6 +19,7 @@
19
19
 
20
20
  .ob-breadcrumbs__item {
21
21
  display: flex;
22
+ flex: 0 0 auto;
22
23
  align-items: center;
23
24
  font-size: var(--ds-font-size-100, 0.875rem);
24
25
  white-space: nowrap;
@@ -54,8 +55,6 @@
54
55
  }
55
56
 
56
57
  .ob-breadcrumbs__overflow {
57
- position: relative;
58
-
59
58
  button {
60
59
  background: none;
61
60
  border: 1px solid transparent;
@@ -86,39 +85,53 @@
86
85
  }
87
86
  }
88
87
 
88
+ /*
89
+ * The crumbs there is no room for, behind the "…" button. A popover, so it sits in the top
90
+ * layer where the toolbar cannot clip it; placed under the button by the component. The
91
+ * toolbar's contrast colour is inherited through the DOM even there, so the menu sets its own.
92
+ */
89
93
  .ob-breadcrumbs__overflow-menu {
90
- background: var(--ds-surface-overlay, #fff);
91
- border: 1px solid var(--ds-border-default, currentColor);
92
- border-radius: var(--ds-border-radius-100, 4px);
93
- box-shadow: var(--ds-shadow-overlay, 0 4px 8px rgba(0, 0, 0, 0.16));
94
- left: 0;
95
- list-style: none;
96
- margin: var(--ds-space-050, 0.25rem) 0 0;
94
+ position: fixed;
95
+ inset: auto;
96
+ box-sizing: border-box;
97
97
  min-width: 10rem;
98
- padding: var(--ds-space-100, 0.25rem) 0;
99
- position: absolute;
100
- top: 100%;
101
- z-index: var(--ds-z-index-modal, 400);
98
+ max-width: calc(100vw - 1rem);
99
+ margin: 0;
100
+ padding: var(--ds-size-1, 0.25rem) 0;
101
+ list-style: none;
102
+ border: 1px solid var(--ds-color-neutral-border-subtle, #cbd0d6);
103
+ border-radius: var(--ds-border-radius-md, 4px);
104
+ background: var(--ds-color-neutral-background-default, #fff);
105
+ color: var(--ds-color-neutral-text-default, #1e2b3c);
106
+ box-shadow: var(--ds-shadow-md, 0 4px 8px rgb(0 0 0 / 16%));
107
+ font-size: var(--ds-body-sm-font-size, 0.875rem);
102
108
 
103
109
  li {
104
110
  a,
105
111
  span {
106
- color: var(--ds-text, inherit);
107
112
  display: block;
108
- font-size: var(--ds-font-size-100, 0.875rem);
109
- padding: var(--ds-space-100, 0.25rem) var(--ds-space-200, 0.5rem);
113
+ padding: var(--ds-size-2, 0.5rem) var(--ds-size-4, 1rem);
114
+ overflow: hidden;
115
+ color: inherit;
110
116
  text-decoration: none;
117
+ text-overflow: ellipsis;
111
118
  white-space: nowrap;
119
+ }
112
120
 
113
- &:hover {
114
- background: var(--ds-background-neutral-default, rgba(0, 0, 0, 0.06));
115
- color: var(--ds-text, inherit);
116
- }
121
+ a:hover {
122
+ background: var(--ds-color-neutral-surface-hover, rgb(0 0 0 / 6%));
117
123
  }
118
124
 
119
125
  a:focus-visible {
120
- outline: 2px solid var(--ds-border-focused, currentColor);
126
+ outline: 2px solid var(--ds-color-focus-outer, currentColor);
121
127
  outline-offset: -2px;
122
128
  }
123
129
  }
130
+
131
+ /* Touch sized rows where there is no pointer to aim with. */
132
+ @media (pointer: coarse) {
133
+ li :is(a, span) {
134
+ padding-block: var(--ds-size-3, 0.75rem);
135
+ }
136
+ }
124
137
  }
@@ -1,232 +1,265 @@
1
- import "./Toolbar.css";
2
-
3
- import { MenuHamburgerIcon } from "@navikt/aksel-icons";
4
- import { useEffect, 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 [overflowOpen, setOverflowOpen] = useState(false);
137
- let navRef = useRef<HTMLElement>(null);
138
- let listRef = useRef<HTMLOListElement>(null);
139
- let overflowItemRef = useRef<HTMLLIElement>(null);
140
-
141
- // Detect overflow: increment firstVisible until the list fits within the nav.
142
- // Runs after every render so it keeps pushing items into overflow until the
143
- // list stops overflowing or only the last item (current page) remains.
144
- useLayoutEffect(() => {
145
- let nav = navRef.current;
146
- let list = listRef.current;
147
- if (!nav || !list) return;
148
-
149
- if (list.scrollWidth > nav.clientWidth && firstVisible < items.length - 1) {
150
- setFirstVisible((prev) => prev + 1);
151
- }
152
- });
153
-
154
- // ResizeObserver resets firstVisible to 0 on container resize so that the
155
- // overflow calculation starts fresh at the new container width.
156
- useEffect(() => {
157
- let nav = navRef.current;
158
- if (!nav) return;
159
-
160
- let observer = new ResizeObserver(() => {
161
- setFirstVisible(0);
162
- });
163
-
164
- observer.observe(nav);
165
- return () => observer.disconnect();
166
- }, []);
167
-
168
- // Close the overflow dropdown when the user clicks outside of it.
169
- useEffect(() => {
170
- if (!overflowOpen) return;
171
-
172
- function handleClickOutside(event: MouseEvent) {
173
- if (overflowItemRef.current && !overflowItemRef.current.contains(event.target as Node)) {
174
- setOverflowOpen(false);
175
- }
176
- }
177
-
178
- document.addEventListener("mousedown", handleClickOutside);
179
- return () => document.removeEventListener("mousedown", handleClickOutside);
180
- }, [overflowOpen]);
181
-
182
- let hiddenItems = items.slice(0, firstVisible);
183
- let visibleItems = items.slice(firstVisible);
184
-
185
- return (
186
- <nav className="ob-breadcrumbs" aria-label="Breadcrumb" ref={navRef}>
187
- <ol className="ob-breadcrumbs__list" ref={listRef}>
188
- {firstVisible > 0 && (
189
- <li className="ob-breadcrumbs__item ob-breadcrumbs__overflow" ref={overflowItemRef}>
190
- <button
191
- type="button"
192
- aria-label="Show hidden breadcrumbs"
193
- aria-expanded={overflowOpen}
194
- aria-haspopup="true"
195
- onClick={() => setOverflowOpen((prev) => !prev)}
196
- >
197
- &hellip;
198
- </button>
199
- {overflowOpen && (
200
- <ul className="ob-breadcrumbs__overflow-menu" role="menu">
201
- {hiddenItems.map((item, index) => (
202
- // oxlint-disable-next-line react/no-array-index-key -- stable list with no reordering
203
- <li key={index} role="menuitem">
204
- <BreadcrumbLink item={item} />
205
- </li>
206
- ))}
207
- </ul>
208
- )}
209
- </li>
210
- )}
211
- {visibleItems.map((item, index) => {
212
- let actualIndex = firstVisible + index;
213
- let isCurrent = actualIndex === items.length - 1;
214
- return (
215
- <li key={actualIndex} className="ob-breadcrumbs__item">
216
- {isCurrent ? <span aria-current="page">{item.label}</span> : <BreadcrumbLink item={item} />}
217
- </li>
218
- );
219
- })}
220
- </ol>
221
- </nav>
222
- );
223
- }
224
-
225
- /** The app's breadcrumb trail, rendered into the toolbar's app region. The last item is the current page. */
226
- export function ToolbarBreadcrumbs({ items }: ToolbarBreadcrumbsProps) {
227
- return (
228
- <ToolbarPortal>
229
- <BreadcrumbsInner items={items} />
230
- </ToolbarPortal>
231
- );
232
- }
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
+ }