@olenbetong/synergi-react 2.5.6 → 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.
- package/es/colorScheme.d.ts +17 -0
- package/es/colorScheme.js +54 -0
- package/es/components/AppMenu/AppMenu.css +480 -92
- package/es/components/AppMenu/AppMenu.d.ts +47 -0
- package/es/components/AppMenu/AppMenu.js +224 -0
- package/es/components/AppMenu/AppMenuColorScheme.d.ts +2 -0
- package/es/components/AppMenu/AppMenuColorScheme.js +18 -0
- package/es/components/AppMenu/AppMenuToggle.d.ts +15 -0
- package/es/components/AppMenu/AppMenuToggle.js +14 -0
- package/es/components/AppMenu/AppMenuUserMenu.d.ts +32 -0
- package/es/components/AppMenu/AppMenuUserMenu.js +110 -0
- package/es/components/AppMenu/developerCategories.d.ts +24 -0
- package/es/components/AppMenu/developerCategories.js +116 -0
- package/es/components/AppMenu/index.d.ts +7 -12
- package/es/components/AppMenu/index.js +6 -85
- package/es/components/AppMenu/types.d.ts +33 -0
- package/es/components/AppMenu/types.js +1 -0
- package/es/components/AppMenu/useRovingTabIndex.d.ts +24 -0
- package/es/components/AppMenu/useRovingTabIndex.js +103 -0
- package/es/components/AppMenu/useServiceWorkerUpdate.d.ts +16 -0
- package/es/components/AppMenu/useServiceWorkerUpdate.js +62 -0
- package/es/components/AppShell/index.js +107 -13
- package/es/components/ImageEditor/ImageEditor.css +22 -11
- package/es/components/ImageEditor/ImageEditor.js +12 -12
- package/es/components/ImageEditor/ResponsiveButton.d.ts +1 -1
- package/es/components/ImageEditor/ResponsiveButton.js +5 -5
- package/es/components/ImageEditor/plugins/cropPlugin/CropOverlay.js +2 -2
- package/es/components/ImageEditor/plugins/cropPlugin/CropToolbar.js +3 -4
- package/es/components/ImageEditor/plugins/cropPlugin/index.js +2 -2
- package/es/components/ImageEditor/plugins/redactPlugin/RedactToolbar.js +3 -5
- package/es/components/ImageEditor/plugins/redactPlugin/index.js +2 -2
- package/es/components/ImageEditor/plugins/rotatePlugin.js +1 -2
- package/es/components/ImageEditor/plugins/zoomPlugin/ZoomControls.js +2 -4
- package/es/components/ImageEditor/useIsSmall.d.ts +5 -0
- package/es/components/ImageEditor/useIsSmall.js +21 -0
- package/es/index.d.ts +2 -1
- package/es/index.js +2 -1
- package/package.json +7 -3
- package/src/colorScheme.ts +81 -0
- package/src/components/AppMenu/AppMenu.css +480 -92
- package/src/components/AppMenu/AppMenu.tsx +478 -0
- package/src/components/AppMenu/AppMenuColorScheme.tsx +41 -0
- package/src/components/AppMenu/AppMenuToggle.tsx +51 -0
- package/src/components/AppMenu/AppMenuUserMenu.tsx +190 -0
- package/src/components/AppMenu/developerCategories.ts +142 -0
- package/src/components/AppMenu/index.ts +12 -0
- package/src/components/AppMenu/types.ts +35 -0
- package/src/components/AppMenu/useRovingTabIndex.ts +118 -0
- package/src/components/AppMenu/useServiceWorkerUpdate.ts +68 -0
- package/src/components/AppShell/index.tsx +140 -14
- package/src/components/ImageEditor/ImageEditor.css +22 -11
- package/src/components/ImageEditor/ImageEditor.tsx +38 -40
- package/src/components/ImageEditor/ResponsiveButton.tsx +8 -10
- package/src/components/ImageEditor/plugins/cropPlugin/CropOverlay.tsx +6 -6
- package/src/components/ImageEditor/plugins/cropPlugin/CropToolbar.tsx +6 -10
- package/src/components/ImageEditor/plugins/cropPlugin/index.ts +2 -2
- package/src/components/ImageEditor/plugins/redactPlugin/RedactToolbar.tsx +8 -17
- package/src/components/ImageEditor/plugins/redactPlugin/index.ts +2 -2
- package/src/components/ImageEditor/plugins/rotatePlugin.ts +1 -2
- package/src/components/ImageEditor/plugins/zoomPlugin/ZoomControls.tsx +4 -6
- package/src/components/ImageEditor/useIsSmall.ts +27 -0
- package/src/index.ts +25 -1
- package/src/components/AppMenu/index.tsx +0 -179
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import RedoIcon from "@mui/icons-material/Redo";
|
|
5
|
-
import RestartAltIcon from "@mui/icons-material/RestartAlt";
|
|
6
|
-
import UndoIcon from "@mui/icons-material/Undo";
|
|
7
|
-
import { Button, CircularProgress, Fab, IconButton, Tooltip, useMediaQuery } from "@mui/material";
|
|
2
|
+
import { Button, Spinner, Tooltip } from "@digdir/designsystemet-react";
|
|
3
|
+
import { ArrowCirclepathIcon, ArrowLeftIcon, ArrowRedoIcon, ArrowUndoIcon, CheckmarkIcon } from "@navikt/aksel-icons";
|
|
8
4
|
import { getLocalizedString } from "@olenbetong/appframe-core";
|
|
9
5
|
import { forwardRef, useImperativeHandle, useMemo, useState } from "react";
|
|
10
6
|
import "./ImageEditor.css";
|
|
11
7
|
import { ResponsiveButton } from "./ResponsiveButton.js";
|
|
12
8
|
import { useActiveTool } from "./useActiveTool.js";
|
|
13
9
|
import { useImageHistory } from "./useImageHistory.js";
|
|
10
|
+
import { useIsSmall } from "./useIsSmall.js";
|
|
14
11
|
/**
|
|
15
12
|
* Full-screen image editor shell.
|
|
16
13
|
* Does not know about specific tools — behaviour is entirely driven by the `plugins` prop.
|
|
@@ -23,7 +20,7 @@ export const ImageEditor = forwardRef(function ImageEditor({ imageUrl, onConfirm
|
|
|
23
20
|
let { activePlugin, activateTool, deactivateTool } = useActiveTool(plugins);
|
|
24
21
|
let [busy, setBusy] = useState(false);
|
|
25
22
|
let disabled = busy || history.replaying;
|
|
26
|
-
let isSmall =
|
|
23
|
+
let isSmall = useIsSmall();
|
|
27
24
|
useImperativeHandle(ref, () => ({
|
|
28
25
|
getCurrentBlob: () => history.currentBlob,
|
|
29
26
|
}));
|
|
@@ -55,7 +52,7 @@ export const ImageEditor = forwardRef(function ImageEditor({ imageUrl, onConfirm
|
|
|
55
52
|
}
|
|
56
53
|
let CanvasWrapper = viewPlugin?.CanvasWrapper;
|
|
57
54
|
let TopBarControls = viewPlugin?.TopBarControls;
|
|
58
|
-
let inner = (_jsxs("div", { className: "image-editor", children: [_jsxs("div", { className: "image-editor__topbar", children: [_jsxs("div", { className: "image-editor__toolbar-group", children: [onCancel && (_jsxs(_Fragment, { children: [_jsx(ResponsiveButton, { icon: _jsx(
|
|
55
|
+
let inner = (_jsxs("div", { className: "image-editor", "data-color-scheme": "dark", children: [_jsxs("div", { className: "image-editor__topbar", children: [_jsxs("div", { className: "image-editor__toolbar-group", children: [onCancel && (_jsxs(_Fragment, { children: [_jsx(ResponsiveButton, { icon: _jsx(ArrowLeftIcon, { "aria-hidden": true }), label: getLocalizedString("Back"), onClick: onCancel, isSmall: isSmall }), _jsx("span", { className: "image-editor__topbar-divider", "aria-hidden": true })] })), _jsx(ResponsiveButton, { icon: _jsx(ArrowUndoIcon, { "aria-hidden": true }), label: getLocalizedString("Undo"), onClick: history.undo, disabled: disabled || !history.canUndo || !!activePlugin, isSmall: isSmall }), _jsx(ResponsiveButton, { icon: _jsx(ArrowRedoIcon, { "aria-hidden": true }), label: getLocalizedString("Redo"), onClick: history.redo, disabled: disabled || !history.canRedo || !!activePlugin, isSmall: isSmall }), _jsx(ResponsiveButton, { icon: _jsx(ArrowCirclepathIcon, { "aria-hidden": true }), label: getLocalizedString("Reset"), onClick: history.reset, disabled: disabled || !history.canUndo || !!activePlugin, isSmall: isSmall })] }), TopBarControls && (_jsx("div", { className: "image-editor__toolbar-group", children: _jsx(TopBarControls, { disabled: disabled, isSmall: isSmall }) }))] }), _jsxs("div", { className: "image-editor__canvas", children: [CanvasWrapper ? (_jsx(CanvasWrapper, { panEnabled: !activePlugin, children: activePlugin ? (_jsx(ActiveOverlay, { plugin: activePlugin })) : (_jsx("img", { src: history.currentImageUrl, alt: getLocalizedString("Image to edit"), className: "image-editor__img" })) })) : activePlugin ? (_jsx(ActiveOverlay, { plugin: activePlugin })) : (_jsx("img", { src: history.currentImageUrl, alt: getLocalizedString("Image to edit"), className: "image-editor__img" })), !activePlugin && onConfirm && (_jsxs(Button, { className: "image-editor__done", variant: "primary", icon: isSmall, "aria-label": isSmall ? getLocalizedString("Done") : undefined, onClick: confirm, disabled: disabled, children: [_jsx(CheckmarkIcon, { "aria-hidden": true }), !isSmall && getLocalizedString("Done")] })), history.replaying && (_jsx("div", { className: "image-editor__replay-overlay", children: _jsx(Spinner, { "aria-label": getLocalizedString("Loading") }) }))] }), _jsx("div", { className: "image-editor__toolbar", children: activePlugin ? (_jsx(ActiveToolbar, { plugin: activePlugin })) : (_jsx("div", { className: "image-editor__toolbar-group", children: plugins.map((p) => p.type === "tool" ? (_jsx(ToolButton, { plugin: p, busy: disabled, onActivate: () => activateTool(p.id), isSmall: isSmall }, p.id)) : (_jsx(ActionButton, { plugin: p, busy: disabled, onExecute: () => executeAction(p), isSmall: isSmall }, p.id))) })) })] }));
|
|
59
56
|
// Wrap with the active tool's provider so Overlay and Toolbar share context.
|
|
60
57
|
if (activePlugin) {
|
|
61
58
|
let ActiveProvider = activePlugin.Provider;
|
|
@@ -70,17 +67,20 @@ export const ImageEditor = forwardRef(function ImageEditor({ imageUrl, onConfirm
|
|
|
70
67
|
});
|
|
71
68
|
function ToolButton({ plugin, busy, onActivate, isSmall, }) {
|
|
72
69
|
let Icon = plugin.Icon;
|
|
70
|
+
let label = getLocalizedString(plugin.label);
|
|
73
71
|
if (isSmall) {
|
|
74
|
-
return (_jsx(Tooltip, {
|
|
72
|
+
return (_jsx(Tooltip, { content: label, children: _jsx(Button, { icon: true, variant: "tertiary", "data-size": "sm", "aria-label": label, onClick: onActivate, disabled: busy, children: _jsx(Icon, {}) }) }));
|
|
75
73
|
}
|
|
76
|
-
return (
|
|
74
|
+
return (_jsxs(Button, { variant: "secondary", "data-size": "sm", onClick: onActivate, disabled: busy, children: [_jsx(Icon, {}), label] }));
|
|
77
75
|
}
|
|
78
76
|
function ActionButton({ plugin, busy, onExecute, isSmall, }) {
|
|
79
77
|
let Icon = plugin.Icon;
|
|
78
|
+
let label = getLocalizedString(plugin.label);
|
|
79
|
+
let icon = busy ? _jsx(Spinner, { "aria-hidden": true, "data-size": "xs" }) : _jsx(Icon, {});
|
|
80
80
|
if (isSmall) {
|
|
81
|
-
return (_jsx(Tooltip, {
|
|
81
|
+
return (_jsx(Tooltip, { content: label, children: _jsx(Button, { icon: true, variant: "tertiary", "data-size": "sm", "aria-label": label, onClick: onExecute, disabled: busy, children: icon }) }));
|
|
82
82
|
}
|
|
83
|
-
return (
|
|
83
|
+
return (_jsxs(Button, { variant: "tertiary", "data-size": "sm", onClick: onExecute, disabled: busy, children: [icon, label] }));
|
|
84
84
|
}
|
|
85
85
|
function ActiveOverlay({ plugin }) {
|
|
86
86
|
let Overlay = plugin.Overlay;
|
|
@@ -6,6 +6,6 @@ interface Props {
|
|
|
6
6
|
disabled?: boolean;
|
|
7
7
|
isSmall: boolean;
|
|
8
8
|
}
|
|
9
|
-
/** Renders a labelled
|
|
9
|
+
/** Renders a labelled button on large screens and a tooltipped icon button on small ones. */
|
|
10
10
|
export declare function ResponsiveButton({ icon, label, onClick, disabled, isSmall }: Props): import("react").JSX.Element;
|
|
11
11
|
export {};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { Button,
|
|
3
|
-
/** Renders a labelled
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Button, Tooltip } from "@digdir/designsystemet-react";
|
|
3
|
+
/** Renders a labelled button on large screens and a tooltipped icon button on small ones. */
|
|
4
4
|
export function ResponsiveButton({ icon, label, onClick, disabled, isSmall }) {
|
|
5
5
|
if (isSmall) {
|
|
6
|
-
return (_jsx(Tooltip, {
|
|
6
|
+
return (_jsx(Tooltip, { content: label, children: _jsx(Button, { icon: true, variant: "tertiary", "data-size": "sm", "aria-label": label, onClick: onClick, disabled: disabled, children: icon }) }));
|
|
7
7
|
}
|
|
8
|
-
return (
|
|
8
|
+
return (_jsxs(Button, { variant: "tertiary", "data-size": "sm", onClick: onClick, disabled: disabled, children: [icon, label] }));
|
|
9
9
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { Alert,
|
|
2
|
+
import { Alert, Paragraph, Spinner } from "@digdir/designsystemet-react";
|
|
3
3
|
import { getLocalizedString } from "@olenbetong/appframe-core";
|
|
4
4
|
import { CropCanvas } from "../../CropCanvas.js";
|
|
5
5
|
import { DragHandle } from "../../DragHandle.js";
|
|
@@ -26,5 +26,5 @@ export function CropOverlay() {
|
|
|
26
26
|
updateCorner(3, bl.x * s + dx, bl.y * s + dy);
|
|
27
27
|
updateCorner(0, tl.x * s + dx, tl.y * s + dy);
|
|
28
28
|
} })] }));
|
|
29
|
-
})()] }), !cvReady && !cvError && (_jsxs("div", { className: "crop-loading", children: [_jsx(
|
|
29
|
+
})()] }), !cvReady && !cvError && (_jsxs("div", { className: "crop-loading", children: [_jsx(Spinner, { "aria-hidden": true, "data-size": "xs" }), _jsx(Paragraph, { "data-size": "sm", children: getLocalizedString("Loading OpenCV…") })] })), cvError && (_jsx("div", { className: "crop-loading", children: _jsx(Alert, { "data-color": "danger", "data-size": "sm", children: getLocalizedString("Crop tool failed to load") }) })), (error || cropping) && (_jsx("div", { className: "crop-loading", children: cropping ? (_jsx(Spinner, { "aria-hidden": true, "data-size": "xs" })) : (_jsx(Alert, { "data-color": "danger", "data-size": "sm", children: error })) }))] }));
|
|
30
30
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { Button, CircularProgress } from "@mui/material";
|
|
2
|
+
import { Button, Spinner } from "@digdir/designsystemet-react";
|
|
3
|
+
import { CheckmarkIcon, XMarkIcon } from "@navikt/aksel-icons";
|
|
5
4
|
import { getLocalizedString } from "@olenbetong/appframe-core";
|
|
6
5
|
import { useCropContext } from "./CropContext.js";
|
|
7
6
|
/** Toolbar shown while the crop tool is active. Reads state from CropContext. */
|
|
@@ -12,5 +11,5 @@ export function CropToolbar() {
|
|
|
12
11
|
if (result)
|
|
13
12
|
onApply(result.blob, result.actions);
|
|
14
13
|
}
|
|
15
|
-
return (_jsxs(_Fragment, { children: [_jsx("div", { className: "image-editor__toolbar-group", children:
|
|
14
|
+
return (_jsxs(_Fragment, { children: [_jsx("div", { className: "image-editor__toolbar-group", children: _jsxs(Button, { variant: "tertiary", "data-size": "sm", onClick: onCancel, disabled: cropping, children: [_jsx(XMarkIcon, { "aria-hidden": true }), getLocalizedString("Cancel")] }) }), _jsx("div", { className: "image-editor__toolbar-group", children: _jsxs(Button, { variant: "primary", "data-size": "sm", onClick: handleApply, disabled: cropping || !cvReady || !!cvError, children: [cropping ? _jsx(Spinner, { "aria-hidden": true, "data-size": "xs" }) : _jsx(CheckmarkIcon, { "aria-hidden": true }), getLocalizedString("Apply crop")] }) })] }));
|
|
16
15
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ExpandIcon } from "@navikt/aksel-icons";
|
|
2
2
|
import { CropProvider } from "./CropContext.js";
|
|
3
3
|
import { CropOverlay } from "./CropOverlay.js";
|
|
4
4
|
import { CropToolbar } from "./CropToolbar.js";
|
|
@@ -8,7 +8,7 @@ export const cropPlugin = {
|
|
|
8
8
|
type: "tool",
|
|
9
9
|
id: "crop",
|
|
10
10
|
label: "Crop",
|
|
11
|
-
Icon:
|
|
11
|
+
Icon: ExpandIcon,
|
|
12
12
|
Provider: CropProvider,
|
|
13
13
|
Overlay: CropOverlay,
|
|
14
14
|
Toolbar: CropToolbar,
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import DeleteSweepIcon from "@mui/icons-material/DeleteSweep";
|
|
5
|
-
import { Button, CircularProgress } from "@mui/material";
|
|
2
|
+
import { Button, Spinner } from "@digdir/designsystemet-react";
|
|
3
|
+
import { CheckmarkIcon, EraserIcon, XMarkIcon } from "@navikt/aksel-icons";
|
|
6
4
|
import { getLocalizedString } from "@olenbetong/appframe-core";
|
|
7
5
|
import { useState } from "react";
|
|
8
6
|
import { useRedactContext } from "./RedactContext.js";
|
|
@@ -25,5 +23,5 @@ export function RedactToolbar() {
|
|
|
25
23
|
setApplying(false);
|
|
26
24
|
}
|
|
27
25
|
}
|
|
28
|
-
return (_jsxs(_Fragment, { children: [_jsxs("div", { className: "image-editor__toolbar-group", children: [
|
|
26
|
+
return (_jsxs(_Fragment, { children: [_jsxs("div", { className: "image-editor__toolbar-group", children: [_jsxs(Button, { variant: "tertiary", "data-size": "sm", onClick: onCancel, disabled: applying, children: [_jsx(XMarkIcon, { "aria-hidden": true }), getLocalizedString("Cancel")] }), _jsxs(Button, { variant: "tertiary", "data-size": "sm", onClick: clearAll, disabled: applying || rects.length === 0, children: [_jsx(EraserIcon, { "aria-hidden": true }), getLocalizedString("Clear all")] })] }), _jsx("div", { className: "image-editor__toolbar-group", children: _jsxs(Button, { variant: "primary", "data-size": "sm", onClick: handleApply, disabled: applying, children: [applying ? _jsx(Spinner, { "aria-hidden": true, "data-size": "xs" }) : _jsx(CheckmarkIcon, { "aria-hidden": true }), rects.length === 0 ? getLocalizedString("Done") : getLocalizedString("Apply redact")] }) })] }));
|
|
29
27
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { EyeObfuscatedIcon } from "@navikt/aksel-icons";
|
|
2
2
|
import { RedactProvider } from "./RedactContext.js";
|
|
3
3
|
import { RedactOverlay } from "./RedactOverlay.js";
|
|
4
4
|
import { RedactToolbar } from "./RedactToolbar.js";
|
|
@@ -8,7 +8,7 @@ export const redactPlugin = {
|
|
|
8
8
|
type: "tool",
|
|
9
9
|
id: "redact",
|
|
10
10
|
label: "Redact",
|
|
11
|
-
Icon:
|
|
11
|
+
Icon: EyeObfuscatedIcon,
|
|
12
12
|
Provider: RedactProvider,
|
|
13
13
|
Overlay: RedactOverlay,
|
|
14
14
|
Toolbar: RedactToolbar,
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import RotateLeftIcon from "@
|
|
2
|
-
import RotateRightIcon from "@mui/icons-material/RotateRight";
|
|
1
|
+
import { RotateLeftIcon, RotateRightIcon } from "@navikt/aksel-icons";
|
|
3
2
|
function rotateBlob(imageUrl, direction) {
|
|
4
3
|
return new Promise((resolve, reject) => {
|
|
5
4
|
let img = new Image();
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import
|
|
3
|
-
import ZoomInMapIcon from "@mui/icons-material/ZoomInMap";
|
|
4
|
-
import ZoomOutIcon from "@mui/icons-material/ZoomOut";
|
|
2
|
+
import { ShrinkIcon, ZoomMinusIcon, ZoomPlusIcon } from "@navikt/aksel-icons";
|
|
5
3
|
import { getLocalizedString } from "@olenbetong/appframe-core";
|
|
6
4
|
import { ResponsiveButton } from "../../ResponsiveButton.js";
|
|
7
5
|
import { useZoom } from "./ZoomContext.js";
|
|
8
6
|
export function ZoomControls({ disabled, isSmall = false }) {
|
|
9
7
|
let { zoom, zoomIn, zoomOut, resetZoom, canZoomIn, canZoomOut, isZoomed } = useZoom();
|
|
10
|
-
return (_jsxs(_Fragment, { children: [_jsx(ResponsiveButton, { icon: _jsx(
|
|
8
|
+
return (_jsxs(_Fragment, { children: [_jsx(ResponsiveButton, { icon: _jsx(ZoomMinusIcon, { "aria-hidden": true }), label: getLocalizedString("Zoom out"), onClick: zoomOut, disabled: disabled || !canZoomOut, isSmall: isSmall }), _jsxs("span", { className: "image-editor__zoom-level", children: [Math.round(zoom * 100), "%"] }), _jsx(ResponsiveButton, { icon: _jsx(ZoomPlusIcon, { "aria-hidden": true }), label: getLocalizedString("Zoom in"), onClick: zoomIn, disabled: disabled || !canZoomIn, isSmall: isSmall }), isZoomed && (_jsx(ResponsiveButton, { icon: _jsx(ShrinkIcon, { "aria-hidden": true }), label: getLocalizedString("Reset zoom"), onClick: resetZoom, isSmall: isSmall }))] }));
|
|
11
9
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
const SMALL_SCREEN_QUERY = "(max-width: 600px)";
|
|
3
|
+
/**
|
|
4
|
+
* Matches the breakpoint where the image editor collapses button labels into
|
|
5
|
+
* icon-only buttons.
|
|
6
|
+
*/
|
|
7
|
+
export function useIsSmall() {
|
|
8
|
+
let [isSmall, setIsSmall] = useState(() => globalThis.matchMedia?.(SMALL_SCREEN_QUERY).matches ?? false);
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
let media = globalThis.matchMedia?.(SMALL_SCREEN_QUERY);
|
|
11
|
+
if (!media)
|
|
12
|
+
return;
|
|
13
|
+
function update() {
|
|
14
|
+
setIsSmall(media?.matches ?? false);
|
|
15
|
+
}
|
|
16
|
+
update();
|
|
17
|
+
media.addEventListener("change", update);
|
|
18
|
+
return () => media.removeEventListener("change", update);
|
|
19
|
+
}, []);
|
|
20
|
+
return isSmall;
|
|
21
|
+
}
|
package/es/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
export { AppMenu, type AppMenuArticle, type AppMenuProps } from "./components/AppMenu/index.js";
|
|
1
|
+
export { AppMenu, type AppMenuArticle, type AppMenuCategory, AppMenuColorScheme, type AppMenuLink, type AppMenuLinkGroup, type AppMenuProps, AppMenuToggle, type AppMenuToggleProps, type AppMenuUser, AppMenuUserMenu, type AppMenuUserMenuProps, createDeveloperCategories, defaultUserMenuItems, type DeveloperCategoryOptions, useServiceWorkerUpdate, } from "./components/AppMenu/index.js";
|
|
2
2
|
export { AppShell, type AppShellProps } from "./components/AppShell/index.js";
|
|
3
3
|
export { Checkbox, type CheckboxProps } from "./components/Checkbox/index.js";
|
|
4
|
+
export { COLOR_SCHEME_CHANGE_EVENT, type ColorSchemePreference, getColorSchemePreference, setColorSchemePreference, useColorSchemePreference, } from "./colorScheme.js";
|
|
4
5
|
export { CardColumn, CardDetail, CardLabel, CardStep, CardStepList, ColorCard } from "./components/ColorCard/index.js";
|
|
5
6
|
export { DateNavigator } from "./components/DateNavigator/index.js";
|
|
6
7
|
export * from "./components/FilePond.js";
|
package/es/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
export { AppMenu } from "./components/AppMenu/index.js";
|
|
1
|
+
export { AppMenu, AppMenuColorScheme, AppMenuToggle, AppMenuUserMenu, createDeveloperCategories, defaultUserMenuItems, useServiceWorkerUpdate, } from "./components/AppMenu/index.js";
|
|
2
2
|
export { AppShell } from "./components/AppShell/index.js";
|
|
3
3
|
export { Checkbox } from "./components/Checkbox/index.js";
|
|
4
|
+
export { COLOR_SCHEME_CHANGE_EVENT, getColorSchemePreference, setColorSchemePreference, useColorSchemePreference, } from "./colorScheme.js";
|
|
4
5
|
export { CardColumn, CardDetail, CardLabel, CardStep, CardStepList, ColorCard } from "./components/ColorCard/index.js";
|
|
5
6
|
export { DateNavigator } from "./components/DateNavigator/index.js";
|
|
6
7
|
export * from "./components/FilePond.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@olenbetong/synergi-react",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.0",
|
|
4
4
|
"description": "Standalone React component for SynergiWeb and Partner Portal",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -22,7 +22,9 @@
|
|
|
22
22
|
"author": "Bjørnar Vister Hansen <bvh@olenbetong.no>",
|
|
23
23
|
"license": "MIT",
|
|
24
24
|
"peerDependencies": {
|
|
25
|
+
"@digdir/designsystemet-react": ">=1.18.0",
|
|
25
26
|
"@mui/material": ">=9.0.0",
|
|
27
|
+
"@navikt/aksel-icons": ">=8.16.1",
|
|
26
28
|
"react": ">=19.2.8",
|
|
27
29
|
"react-dom": ">=19.2.8"
|
|
28
30
|
},
|
|
@@ -43,9 +45,9 @@
|
|
|
43
45
|
"pdfjs-dist": "5.7.284",
|
|
44
46
|
"react-pdf": "^10.4.1",
|
|
45
47
|
"@olenbetong/appframe-core": "2.11.10",
|
|
48
|
+
"@olenbetong/appframe-mui": "6.6.0",
|
|
46
49
|
"@olenbetong/appframe-data": "1.5.0",
|
|
47
|
-
"@olenbetong/appframe-react": "
|
|
48
|
-
"@olenbetong/appframe-mui": "6.5.2"
|
|
50
|
+
"@olenbetong/appframe-react": "2.0.0"
|
|
49
51
|
},
|
|
50
52
|
"repository": {
|
|
51
53
|
"type": "git",
|
|
@@ -59,6 +61,8 @@
|
|
|
59
61
|
]
|
|
60
62
|
},
|
|
61
63
|
"devDependencies": {
|
|
64
|
+
"@digdir/designsystemet-react": "1.18.0",
|
|
65
|
+
"@navikt/aksel-icons": "8.16.1",
|
|
62
66
|
"react": "19.2.8",
|
|
63
67
|
"react-dom": "19.2.8",
|
|
64
68
|
"replace-in-files": "^3.0.0"
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { useCallback, useEffect, useState } from "react";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Color scheme preference (system / light / dark).
|
|
5
|
+
*
|
|
6
|
+
* The preference lives in the `ob-color-scheme` cookie so the article template
|
|
7
|
+
* can read it server side and render `data-color-scheme` on `<html>` and
|
|
8
|
+
* `<body>` before the first paint. The site script for the 2026 template
|
|
9
|
+
* (`ob.2026.application.min.js`) owns the same cookie for the toolbar user menu
|
|
10
|
+
* toggle, so both write the cookie, apply the attributes, and dispatch
|
|
11
|
+
* `COLOR_SCHEME_CHANGE_EVENT` to keep every toggle on the page in sync.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export type ColorSchemePreference = "auto" | "light" | "dark";
|
|
15
|
+
|
|
16
|
+
const COOKIE_NAME = "ob-color-scheme";
|
|
17
|
+
const COOKIE_MAX_AGE = 60 * 60 * 24 * 365;
|
|
18
|
+
const DEFAULT_PREFERENCE: ColorSchemePreference = "auto";
|
|
19
|
+
const PREFERENCES: ColorSchemePreference[] = ["auto", "light", "dark"];
|
|
20
|
+
|
|
21
|
+
/** Dispatched on `window` whenever the preference changes. */
|
|
22
|
+
export const COLOR_SCHEME_CHANGE_EVENT = "ob:colorschemechange";
|
|
23
|
+
|
|
24
|
+
function isColorSchemePreference(value: unknown): value is ColorSchemePreference {
|
|
25
|
+
return typeof value === "string" && PREFERENCES.includes(value as ColorSchemePreference);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function getColorSchemePreference(): ColorSchemePreference {
|
|
29
|
+
if (typeof document === "undefined") return DEFAULT_PREFERENCE;
|
|
30
|
+
|
|
31
|
+
let match = document.cookie.match(new RegExp(`(?:^|;\\s*)${COOKIE_NAME}=([^;]*)`));
|
|
32
|
+
let value = match ? decodeURIComponent(match[1]) : null;
|
|
33
|
+
|
|
34
|
+
return isColorSchemePreference(value) ? value : DEFAULT_PREFERENCE;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function setColorSchemePreference(preference: ColorSchemePreference) {
|
|
38
|
+
if (typeof document === "undefined" || !isColorSchemePreference(preference)) return;
|
|
39
|
+
|
|
40
|
+
let secure = window.location.protocol === "https:" ? ";secure" : "";
|
|
41
|
+
document.cookie = `${COOKIE_NAME}=${preference};path=/;max-age=${COOKIE_MAX_AGE};samesite=lax${secure}`;
|
|
42
|
+
|
|
43
|
+
/*
|
|
44
|
+
* Both elements are updated: `<html>` so the browser applies `color-scheme`
|
|
45
|
+
* to scrollbars and native controls, `<body>` because Designsystemet declares
|
|
46
|
+
* the light tokens on `:root` as well (`:root, [data-color-scheme="light"]`).
|
|
47
|
+
*/
|
|
48
|
+
document.documentElement.dataset.colorScheme = preference;
|
|
49
|
+
if (document.body) document.body.dataset.colorScheme = preference;
|
|
50
|
+
|
|
51
|
+
window.dispatchEvent(new CustomEvent(COLOR_SCHEME_CHANGE_EVENT, { detail: preference }));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Reads the stored preference and keeps it in sync with other toggles on the page. */
|
|
55
|
+
export function useColorSchemePreference(): [ColorSchemePreference, (value: ColorSchemePreference) => void] {
|
|
56
|
+
let [preference, setPreference] = useState<ColorSchemePreference>(() => getColorSchemePreference());
|
|
57
|
+
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
function update() {
|
|
60
|
+
setPreference(getColorSchemePreference());
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
update();
|
|
64
|
+
|
|
65
|
+
window.addEventListener(COLOR_SCHEME_CHANGE_EVENT, update);
|
|
66
|
+
// Cookies fire no change event, so also pick up changes made in another tab.
|
|
67
|
+
document.addEventListener("visibilitychange", update);
|
|
68
|
+
|
|
69
|
+
return () => {
|
|
70
|
+
window.removeEventListener(COLOR_SCHEME_CHANGE_EVENT, update);
|
|
71
|
+
document.removeEventListener("visibilitychange", update);
|
|
72
|
+
};
|
|
73
|
+
}, []);
|
|
74
|
+
|
|
75
|
+
let setValue = useCallback((value: ColorSchemePreference) => {
|
|
76
|
+
setColorSchemePreference(value);
|
|
77
|
+
setPreference(value);
|
|
78
|
+
}, []);
|
|
79
|
+
|
|
80
|
+
return [preference, setValue];
|
|
81
|
+
}
|