@olenbetong/synergi-react 4.2.3 → 4.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +7 -7
- package/src/chrome/AppShell/index.tsx +29 -29
- package/src/chrome/openReport.ts +34 -34
- package/src/colorScheme.ts +81 -81
- package/src/components/DateNavigator/index.tsx +186 -186
- package/src/components/FilePond.tsx +312 -312
- package/src/components/ImageEditor/ImageEditor.tsx +348 -348
- package/src/components/ImageEditor/index.ts +9 -9
- package/src/components/ImageEditor/plugins/cropPlugin/CropOverlay.tsx +165 -165
- package/src/components/ImageEditor/plugins/cropPlugin/CropToolbar.tsx +48 -48
- package/src/components/ImageEditor/plugins/cropPlugin/useCropTool.ts +405 -405
- package/src/components/ImageEditor/plugins/redactPlugin/RedactToolbar.tsx +47 -47
- package/src/components/ImageEditor/plugins/zoomPlugin/ZoomContext.tsx +23 -23
- package/src/components/ImageEditor/plugins/zoomPlugin/ZoomControls.tsx +40 -40
- package/src/components/ImageEditor/useActiveTool.ts +21 -21
- package/src/components/ImageEditor/useEdgeDetection.ts +319 -319
- package/src/components/ImageEditor/useImageHistory.ts +197 -197
- package/src/components/ImageEditor/useOpenCV.ts +184 -184
- package/src/components/LinkedCardList/index.scss +95 -95
- package/src/components/MergeProgressDialog/index.tsx +249 -249
- package/src/components/PageBanner/index.tsx +80 -80
- package/src/components/PdfViewer/PdfViewer.tsx +158 -158
- package/src/components/ProgressBar/index.scss +96 -96
- package/src/components/SplitContainer/index.tsx +333 -333
- package/src/components/Toolbar/index.tsx +232 -232
- package/src/designsystemet-web-types.d.ts +24 -24
- package/src/elements/ElementDamage/DamageFormButtons.tsx +35 -35
- package/src/elements/ElementDamage/DescriptionInput.tsx +120 -120
- package/src/elements/ElementDamage/DuplicateDamage/DesktopView.tsx +82 -82
- package/src/elements/ElementDamage/DuplicateDamage/DublicateElementDamageDialog.tsx +67 -67
- package/src/elements/ElementDamage/DuplicateDamage/PhoneView.tsx +45 -45
- package/src/elements/ElementDamage/ElementNumberTextField.tsx +41 -41
- package/src/elements/ElementDamage/RegisterFix.tsx +100 -100
- package/src/elements/ElementDamage/SubmitButtons.tsx +40 -40
- package/src/elements/ElementDamage/TransportElementSelect.tsx +52 -52
- package/src/elements/ElementLookup.tsx +123 -123
- package/src/elements/ElementLookupDialog/BarcodeScanner/decoder.ts +32 -32
- package/src/elements/ElementLookupDialog/BarcodeScanner/decoders/dbr.ts +118 -118
- package/src/elements/ElementLookupDialog/BarcodeScanner/decoders/native.ts +103 -103
- package/src/elements/ElementLookupDialog/BarcodeScanner/decoders/zxing.ts +95 -95
- package/src/elements/ElementLookupDialog/BarcodeScanner/decoders.test.ts +118 -118
- package/src/elements/ElementLookupDialog/BarcodeScanner/duplicateFilter.ts +21 -21
- package/src/elements/ElementLookupDialog/BarcodeScanner/index.tsx +90 -90
- package/src/elements/ElementLookupDialog/BarcodeScanner/useScanner.ts +280 -280
- package/src/elements/ElementLookupDialog/HIDScanner/index.tsx +67 -67
- package/src/elements/ElementLookupDialog/Manual/ManualForm.tsx +141 -141
- package/src/elements/ElementLookupDialog/index.tsx +226 -226
- package/src/elements/ElementLookupDialog/utils/Giai.ts +209 -209
- package/src/elements/ProjectSelect.tsx +130 -130
- package/src/elements/index.ts +15 -15
- package/src/filter/index.ts +34 -34
- package/src/i18n.ts +13 -13
- package/src/index.ts +77 -77
- package/src/mui/MuiThemeProvider.tsx +174 -174
- package/src/mui/index.ts +1 -1
- package/src/test/setup.ts +8 -8
|
@@ -1,232 +1,232 @@
|
|
|
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
|
-
…
|
|
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, 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
|
+
…
|
|
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,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
|
+
}
|