@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.
- package/es/components/Toolbar/Toolbar.css +34 -21
- package/es/components/Toolbar/index.js +50 -18
- package/package.json +6 -6
- 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/Toolbar.css +34 -21
- package/src/components/Toolbar/index.tsx +265 -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
package/src/elements/index.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
export * from "./data/index.js";
|
|
2
|
-
export * from "./ElementDamage/DamageFormButtons.js";
|
|
3
|
-
export * from "./ElementDamage/DescriptionInput.js";
|
|
4
|
-
export * from "./ElementDamage/DuplicateDamage/index.js";
|
|
5
|
-
export * from "./ElementDamage/ElementNumberTextField.js";
|
|
6
|
-
export * from "./ElementDamage/HiddenDamageFields.js";
|
|
7
|
-
export * from "./ElementDamage/RegisterFix.js";
|
|
8
|
-
export * from "./ElementDamage/SubmitButtons.js";
|
|
9
|
-
export * from "./ElementDamage/TransportElementSelect.js";
|
|
10
|
-
export * from "./ElementLookup.js";
|
|
11
|
-
export * from "./ElementLookupDialog/BarcodeScanner/index.js";
|
|
12
|
-
export * from "./ElementLookupDialog/HIDScanner/index.js";
|
|
13
|
-
export * from "./ElementLookupDialog/index.js";
|
|
14
|
-
export * from "./ElementLookupDialog/Manual/ManualForm.js";
|
|
15
|
-
export * from "./ProjectSelect.js";
|
|
1
|
+
export * from "./data/index.js";
|
|
2
|
+
export * from "./ElementDamage/DamageFormButtons.js";
|
|
3
|
+
export * from "./ElementDamage/DescriptionInput.js";
|
|
4
|
+
export * from "./ElementDamage/DuplicateDamage/index.js";
|
|
5
|
+
export * from "./ElementDamage/ElementNumberTextField.js";
|
|
6
|
+
export * from "./ElementDamage/HiddenDamageFields.js";
|
|
7
|
+
export * from "./ElementDamage/RegisterFix.js";
|
|
8
|
+
export * from "./ElementDamage/SubmitButtons.js";
|
|
9
|
+
export * from "./ElementDamage/TransportElementSelect.js";
|
|
10
|
+
export * from "./ElementLookup.js";
|
|
11
|
+
export * from "./ElementLookupDialog/BarcodeScanner/index.js";
|
|
12
|
+
export * from "./ElementLookupDialog/HIDScanner/index.js";
|
|
13
|
+
export * from "./ElementLookupDialog/index.js";
|
|
14
|
+
export * from "./ElementLookupDialog/Manual/ManualForm.js";
|
|
15
|
+
export * from "./ProjectSelect.js";
|
package/src/filter/index.ts
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The filter builder now lives in `@olenbetong/appframe-ds`, which is where the
|
|
3
|
-
* Designsystemet components it is built from live. Re-exported here so existing
|
|
4
|
-
* imports from `@olenbetong/synergi-react` keep working.
|
|
5
|
-
*
|
|
6
|
-
* @deprecated Import from `@olenbetong/appframe-ds` instead.
|
|
7
|
-
*/
|
|
8
|
-
export {
|
|
9
|
-
ChipListInput,
|
|
10
|
-
type ChipListInputProps,
|
|
11
|
-
FilterBuilder,
|
|
12
|
-
type FilterBuilderProps,
|
|
13
|
-
FilterEditor,
|
|
14
|
-
type FilterEditorProps,
|
|
15
|
-
type FilterEditorSize,
|
|
16
|
-
FilterGroupEditor,
|
|
17
|
-
type FilterGroupEditorProps,
|
|
18
|
-
FilterNameDialog,
|
|
19
|
-
type FilterNameDialogProps,
|
|
20
|
-
FilterRow,
|
|
21
|
-
type FilterRowProps,
|
|
22
|
-
FilterShareDialog,
|
|
23
|
-
type FilterShareDialogProps,
|
|
24
|
-
FilterStringField,
|
|
25
|
-
type FilterStringFieldProps,
|
|
26
|
-
FilterValueEditor,
|
|
27
|
-
type FilterValueEditorProps,
|
|
28
|
-
type FilterValueOption,
|
|
29
|
-
type GetFieldOptions,
|
|
30
|
-
type SavedFilterSelection,
|
|
31
|
-
SavedFilterTree,
|
|
32
|
-
type SavedFilterTreeProps,
|
|
33
|
-
type SavedFilterValues,
|
|
34
|
-
} from "@olenbetong/appframe-ds";
|
|
1
|
+
/**
|
|
2
|
+
* The filter builder now lives in `@olenbetong/appframe-ds`, which is where the
|
|
3
|
+
* Designsystemet components it is built from live. Re-exported here so existing
|
|
4
|
+
* imports from `@olenbetong/synergi-react` keep working.
|
|
5
|
+
*
|
|
6
|
+
* @deprecated Import from `@olenbetong/appframe-ds` instead.
|
|
7
|
+
*/
|
|
8
|
+
export {
|
|
9
|
+
ChipListInput,
|
|
10
|
+
type ChipListInputProps,
|
|
11
|
+
FilterBuilder,
|
|
12
|
+
type FilterBuilderProps,
|
|
13
|
+
FilterEditor,
|
|
14
|
+
type FilterEditorProps,
|
|
15
|
+
type FilterEditorSize,
|
|
16
|
+
FilterGroupEditor,
|
|
17
|
+
type FilterGroupEditorProps,
|
|
18
|
+
FilterNameDialog,
|
|
19
|
+
type FilterNameDialogProps,
|
|
20
|
+
FilterRow,
|
|
21
|
+
type FilterRowProps,
|
|
22
|
+
FilterShareDialog,
|
|
23
|
+
type FilterShareDialogProps,
|
|
24
|
+
FilterStringField,
|
|
25
|
+
type FilterStringFieldProps,
|
|
26
|
+
FilterValueEditor,
|
|
27
|
+
type FilterValueEditorProps,
|
|
28
|
+
type FilterValueOption,
|
|
29
|
+
type GetFieldOptions,
|
|
30
|
+
type SavedFilterSelection,
|
|
31
|
+
SavedFilterTree,
|
|
32
|
+
type SavedFilterTreeProps,
|
|
33
|
+
type SavedFilterValues,
|
|
34
|
+
} from "@olenbetong/appframe-ds";
|
package/src/i18n.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* The package's strings live in their own globalization project, `synergi-react`, so one
|
|
3
|
-
* translation covers every app and the package can word a term its own way. The templates
|
|
4
|
-
* render the dictionary as af.i18n["synergi-react"]; on a page that does not (a legacy
|
|
5
|
-
* template) the localizer falls back to the article's strings, exactly as before. See
|
|
6
|
-
* `createLocalizer` in @olenbetong/appframe-core.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { createLocalizer } from "@olenbetong/appframe-core";
|
|
10
|
-
|
|
11
|
-
export const PROJECT = "synergi-react";
|
|
12
|
-
|
|
13
|
-
export const { getLocalizedString, localize } = createLocalizer(PROJECT);
|
|
1
|
+
/*
|
|
2
|
+
* The package's strings live in their own globalization project, `synergi-react`, so one
|
|
3
|
+
* translation covers every app and the package can word a term its own way. The templates
|
|
4
|
+
* render the dictionary as af.i18n["synergi-react"]; on a page that does not (a legacy
|
|
5
|
+
* template) the localizer falls back to the article's strings, exactly as before. See
|
|
6
|
+
* `createLocalizer` in @olenbetong/appframe-core.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { createLocalizer } from "@olenbetong/appframe-core";
|
|
10
|
+
|
|
11
|
+
export const PROJECT = "synergi-react";
|
|
12
|
+
|
|
13
|
+
export const { getLocalizedString, localize } = createLocalizer(PROJECT);
|
package/src/index.ts
CHANGED
|
@@ -1,77 +1,77 @@
|
|
|
1
|
-
// The app menu and the rest of the site chrome live in @olenbetong/synergi-chrome,
|
|
2
|
-
// loaded once per page by the site template rather than bundled into every app.
|
|
3
|
-
export { AppShell, type AppShellProps, hasSiteChrome } from "./chrome/AppShell/index.js";
|
|
4
|
-
export { Checkbox, type CheckboxProps } from "./components/Checkbox/index.js";
|
|
5
|
-
export {
|
|
6
|
-
COLOR_SCHEME_CHANGE_EVENT,
|
|
7
|
-
type ColorSchemePreference,
|
|
8
|
-
getColorSchemePreference,
|
|
9
|
-
setColorSchemePreference,
|
|
10
|
-
useColorSchemePreference,
|
|
11
|
-
} from "./colorScheme.js";
|
|
12
|
-
export { CardColumn, CardDetail, CardLabel, CardStep, CardStepList, ColorCard } from "./components/ColorCard/index.js";
|
|
13
|
-
export { DateNavigator } from "./components/DateNavigator/index.js";
|
|
14
|
-
export * from "./components/FilePond.js";
|
|
15
|
-
export * from "./components/ImageEditor/index.js";
|
|
16
|
-
export {
|
|
17
|
-
ChipListInput,
|
|
18
|
-
type ChipListInputProps,
|
|
19
|
-
FilterBuilder,
|
|
20
|
-
type FilterBuilderProps,
|
|
21
|
-
FilterEditor,
|
|
22
|
-
type FilterEditorProps,
|
|
23
|
-
type FilterEditorSize,
|
|
24
|
-
FilterGroupEditor,
|
|
25
|
-
type FilterGroupEditorProps,
|
|
26
|
-
FilterNameDialog,
|
|
27
|
-
type FilterNameDialogProps,
|
|
28
|
-
FilterRow,
|
|
29
|
-
type FilterRowProps,
|
|
30
|
-
FilterShareDialog,
|
|
31
|
-
type FilterShareDialogProps,
|
|
32
|
-
FilterStringField,
|
|
33
|
-
type FilterStringFieldProps,
|
|
34
|
-
FilterValueEditor,
|
|
35
|
-
type FilterValueEditorProps,
|
|
36
|
-
type FilterValueOption,
|
|
37
|
-
type GetFieldOptions,
|
|
38
|
-
type SavedFilterSelection,
|
|
39
|
-
type SavedFilterValues,
|
|
40
|
-
SavedFilterTree,
|
|
41
|
-
type SavedFilterTreeProps,
|
|
42
|
-
} from "./filter/index.js";
|
|
43
|
-
export { Card, LinkedList, LinkedListItem } from "./components/LinkedCardList/index.js";
|
|
44
|
-
export { MergeProgressDialog, type MergeProgressDialogProps } from "./components/MergeProgressDialog/index.js";
|
|
45
|
-
export { type OpenReportOptions, openReport } from "./chrome/openReport.js";
|
|
46
|
-
export {
|
|
47
|
-
BannerImage as PageBannerImage,
|
|
48
|
-
type BannerImageProps,
|
|
49
|
-
PageBanner,
|
|
50
|
-
type PageBannerProps,
|
|
51
|
-
Tab as PageBannerTab,
|
|
52
|
-
TabList as PageBannerTabList,
|
|
53
|
-
type TabListProps as PageBannerTabListProps,
|
|
54
|
-
type TabProps as PageBannerTabProps,
|
|
55
|
-
Title as PageBannerTitle,
|
|
56
|
-
type TitleProps as PageBannerTitleProps,
|
|
57
|
-
} from "./components/PageBanner/index.js";
|
|
58
|
-
// PdfViewer is intentionally not re-exported here. It references the pdf.js worker
|
|
59
|
-
// with `new URL(..., import.meta.url)`, which makes bundlers emit the 1.2 MB worker
|
|
60
|
-
// asset for every app that touches this barrel, even when no PDF is ever rendered.
|
|
61
|
-
// Import it from "@olenbetong/synergi-react/pdf" instead.
|
|
62
|
-
export { Portal } from "./components/Portal/index.js";
|
|
63
|
-
export {
|
|
64
|
-
ToolbarBreadcrumbs,
|
|
65
|
-
ToolbarDrawerToggle,
|
|
66
|
-
ToolbarPortal,
|
|
67
|
-
type BreadcrumbItem,
|
|
68
|
-
type ToolbarBreadcrumbsProps,
|
|
69
|
-
type ToolbarDrawerToggleProps,
|
|
70
|
-
type ToolbarPortalProps,
|
|
71
|
-
} from "./components/Toolbar/index.js";
|
|
72
|
-
export { ProgressBar } from "./components/ProgressBar/index.js";
|
|
73
|
-
export { Sidebar, type SidebarProps } from "./components/Sidebar/index.js";
|
|
74
|
-
export { Spinner, type SpinnerProps } from "./components/Spinner/index.js";
|
|
75
|
-
export { SplitContainer, type SplitContainerProps } from "./components/SplitContainer/index.js";
|
|
76
|
-
export { ValueToggleGroup, type ValueToggleGroupProps } from "./components/ValueToggleGroup/index.js";
|
|
77
|
-
export { useTranslation } from "./useTranslation/index.js";
|
|
1
|
+
// The app menu and the rest of the site chrome live in @olenbetong/synergi-chrome,
|
|
2
|
+
// loaded once per page by the site template rather than bundled into every app.
|
|
3
|
+
export { AppShell, type AppShellProps, hasSiteChrome } from "./chrome/AppShell/index.js";
|
|
4
|
+
export { Checkbox, type CheckboxProps } from "./components/Checkbox/index.js";
|
|
5
|
+
export {
|
|
6
|
+
COLOR_SCHEME_CHANGE_EVENT,
|
|
7
|
+
type ColorSchemePreference,
|
|
8
|
+
getColorSchemePreference,
|
|
9
|
+
setColorSchemePreference,
|
|
10
|
+
useColorSchemePreference,
|
|
11
|
+
} from "./colorScheme.js";
|
|
12
|
+
export { CardColumn, CardDetail, CardLabel, CardStep, CardStepList, ColorCard } from "./components/ColorCard/index.js";
|
|
13
|
+
export { DateNavigator } from "./components/DateNavigator/index.js";
|
|
14
|
+
export * from "./components/FilePond.js";
|
|
15
|
+
export * from "./components/ImageEditor/index.js";
|
|
16
|
+
export {
|
|
17
|
+
ChipListInput,
|
|
18
|
+
type ChipListInputProps,
|
|
19
|
+
FilterBuilder,
|
|
20
|
+
type FilterBuilderProps,
|
|
21
|
+
FilterEditor,
|
|
22
|
+
type FilterEditorProps,
|
|
23
|
+
type FilterEditorSize,
|
|
24
|
+
FilterGroupEditor,
|
|
25
|
+
type FilterGroupEditorProps,
|
|
26
|
+
FilterNameDialog,
|
|
27
|
+
type FilterNameDialogProps,
|
|
28
|
+
FilterRow,
|
|
29
|
+
type FilterRowProps,
|
|
30
|
+
FilterShareDialog,
|
|
31
|
+
type FilterShareDialogProps,
|
|
32
|
+
FilterStringField,
|
|
33
|
+
type FilterStringFieldProps,
|
|
34
|
+
FilterValueEditor,
|
|
35
|
+
type FilterValueEditorProps,
|
|
36
|
+
type FilterValueOption,
|
|
37
|
+
type GetFieldOptions,
|
|
38
|
+
type SavedFilterSelection,
|
|
39
|
+
type SavedFilterValues,
|
|
40
|
+
SavedFilterTree,
|
|
41
|
+
type SavedFilterTreeProps,
|
|
42
|
+
} from "./filter/index.js";
|
|
43
|
+
export { Card, LinkedList, LinkedListItem } from "./components/LinkedCardList/index.js";
|
|
44
|
+
export { MergeProgressDialog, type MergeProgressDialogProps } from "./components/MergeProgressDialog/index.js";
|
|
45
|
+
export { type OpenReportOptions, openReport } from "./chrome/openReport.js";
|
|
46
|
+
export {
|
|
47
|
+
BannerImage as PageBannerImage,
|
|
48
|
+
type BannerImageProps,
|
|
49
|
+
PageBanner,
|
|
50
|
+
type PageBannerProps,
|
|
51
|
+
Tab as PageBannerTab,
|
|
52
|
+
TabList as PageBannerTabList,
|
|
53
|
+
type TabListProps as PageBannerTabListProps,
|
|
54
|
+
type TabProps as PageBannerTabProps,
|
|
55
|
+
Title as PageBannerTitle,
|
|
56
|
+
type TitleProps as PageBannerTitleProps,
|
|
57
|
+
} from "./components/PageBanner/index.js";
|
|
58
|
+
// PdfViewer is intentionally not re-exported here. It references the pdf.js worker
|
|
59
|
+
// with `new URL(..., import.meta.url)`, which makes bundlers emit the 1.2 MB worker
|
|
60
|
+
// asset for every app that touches this barrel, even when no PDF is ever rendered.
|
|
61
|
+
// Import it from "@olenbetong/synergi-react/pdf" instead.
|
|
62
|
+
export { Portal } from "./components/Portal/index.js";
|
|
63
|
+
export {
|
|
64
|
+
ToolbarBreadcrumbs,
|
|
65
|
+
ToolbarDrawerToggle,
|
|
66
|
+
ToolbarPortal,
|
|
67
|
+
type BreadcrumbItem,
|
|
68
|
+
type ToolbarBreadcrumbsProps,
|
|
69
|
+
type ToolbarDrawerToggleProps,
|
|
70
|
+
type ToolbarPortalProps,
|
|
71
|
+
} from "./components/Toolbar/index.js";
|
|
72
|
+
export { ProgressBar } from "./components/ProgressBar/index.js";
|
|
73
|
+
export { Sidebar, type SidebarProps } from "./components/Sidebar/index.js";
|
|
74
|
+
export { Spinner, type SpinnerProps } from "./components/Spinner/index.js";
|
|
75
|
+
export { SplitContainer, type SplitContainerProps } from "./components/SplitContainer/index.js";
|
|
76
|
+
export { ValueToggleGroup, type ValueToggleGroupProps } from "./components/ValueToggleGroup/index.js";
|
|
77
|
+
export { useTranslation } from "./useTranslation/index.js";
|
|
@@ -1,174 +1,174 @@
|
|
|
1
|
-
import { StyledEngineProvider, ThemeProvider } from "@mui/material";
|
|
2
|
-
import { createTheme as muiCreateTheme } from "@mui/material/styles";
|
|
3
|
-
import { type ReactNode, useEffect, useState } from "react";
|
|
4
|
-
|
|
5
|
-
function getColorScheme(): "light" | "dark" {
|
|
6
|
-
let scheme = document.body?.dataset.colorScheme ?? document.documentElement?.dataset.colorScheme ?? "light";
|
|
7
|
-
|
|
8
|
-
if (scheme === "auto") {
|
|
9
|
-
return globalThis.matchMedia?.("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
return scheme === "dark" ? "dark" : "light";
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Tracks the color scheme Designsystemet is rendering with. The article template
|
|
17
|
-
* sets `data-color-scheme` on `<body>`, so watch that attribute as well as the
|
|
18
|
-
* OS preference (used when the scheme is `auto`).
|
|
19
|
-
*/
|
|
20
|
-
function useColorScheme() {
|
|
21
|
-
let [scheme, setScheme] = useState<"light" | "dark">(() => getColorScheme());
|
|
22
|
-
|
|
23
|
-
useEffect(() => {
|
|
24
|
-
function update() {
|
|
25
|
-
setScheme(getColorScheme());
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
update();
|
|
29
|
-
|
|
30
|
-
let observer = new MutationObserver(update);
|
|
31
|
-
observer.observe(document.body, { attributes: true, attributeFilter: ["data-color-scheme"] });
|
|
32
|
-
observer.observe(document.documentElement, { attributes: true, attributeFilter: ["data-color-scheme"] });
|
|
33
|
-
|
|
34
|
-
let media = globalThis.matchMedia?.("(prefers-color-scheme: dark)");
|
|
35
|
-
media?.addEventListener("change", update);
|
|
36
|
-
|
|
37
|
-
return () => {
|
|
38
|
-
observer.disconnect();
|
|
39
|
-
media?.removeEventListener("change", update);
|
|
40
|
-
};
|
|
41
|
-
}, []);
|
|
42
|
-
|
|
43
|
-
return scheme;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function buildMuiTheme(mode: "light" | "dark") {
|
|
47
|
-
const s = getComputedStyle(document.body);
|
|
48
|
-
const get = (v: string) => s.getPropertyValue(v).trim();
|
|
49
|
-
const isDark = mode === "dark";
|
|
50
|
-
|
|
51
|
-
return muiCreateTheme({
|
|
52
|
-
palette: {
|
|
53
|
-
mode,
|
|
54
|
-
primary: {
|
|
55
|
-
main: get("--ds-color-brand-base-default") || "#116069",
|
|
56
|
-
dark: get("--ds-color-brand-base-hover") || "#0d4b52",
|
|
57
|
-
contrastText: get("--ds-color-brand-base-contrast-default") || "#ffffff",
|
|
58
|
-
},
|
|
59
|
-
secondary: {
|
|
60
|
-
main: get("--ds-color-brand-light-base-default") || "#1a95a2",
|
|
61
|
-
},
|
|
62
|
-
background: {
|
|
63
|
-
default: get("--ds-color-neutral-background-default") || (isDark ? "#17181a" : "#ffffff"),
|
|
64
|
-
paper: get("--ds-color-neutral-background-default") || (isDark ? "#17181a" : "#ffffff"),
|
|
65
|
-
},
|
|
66
|
-
text: {
|
|
67
|
-
primary: get("--ds-color-neutral-text-default") || (isDark ? "#e5e6e7" : "#292c30"),
|
|
68
|
-
secondary: get("--ds-color-neutral-text-subtle") || (isDark ? "#b3b5b7" : "#5b5f64"),
|
|
69
|
-
},
|
|
70
|
-
divider: get("--ds-color-neutral-border-subtle") || (isDark ? "#4e5052" : "#bbbcbd"),
|
|
71
|
-
},
|
|
72
|
-
typography: {
|
|
73
|
-
fontFamily: [
|
|
74
|
-
"-apple-system",
|
|
75
|
-
"BlinkMacSystemFont",
|
|
76
|
-
'"Segoe UI"',
|
|
77
|
-
"Roboto",
|
|
78
|
-
'"Helvetica Neue"',
|
|
79
|
-
"Arial",
|
|
80
|
-
"sans-serif",
|
|
81
|
-
'"Apple Color Emoji"',
|
|
82
|
-
'"Segoe UI Emoji"',
|
|
83
|
-
'"Segoe UI Symbol"',
|
|
84
|
-
].join(","),
|
|
85
|
-
},
|
|
86
|
-
components: {
|
|
87
|
-
MuiTypography: {
|
|
88
|
-
styleOverrides: {
|
|
89
|
-
h1: { fontSize: "2.488rem" },
|
|
90
|
-
h2: { fontSize: "2.074rem" },
|
|
91
|
-
h3: { fontSize: "1.728rem" },
|
|
92
|
-
h4: { fontSize: "1.44rem" },
|
|
93
|
-
h5: { fontSize: "1.2rem" },
|
|
94
|
-
h6: { fontSize: "1rem" },
|
|
95
|
-
},
|
|
96
|
-
},
|
|
97
|
-
MuiAppBar: {
|
|
98
|
-
styleOverrides: {
|
|
99
|
-
root: {
|
|
100
|
-
"& .MuiTypography-h1": {
|
|
101
|
-
fontSize: "1.25rem",
|
|
102
|
-
fontWeight: "500",
|
|
103
|
-
},
|
|
104
|
-
},
|
|
105
|
-
},
|
|
106
|
-
},
|
|
107
|
-
MuiButton: {
|
|
108
|
-
styleOverrides: {
|
|
109
|
-
root: { borderRadius: 2 },
|
|
110
|
-
},
|
|
111
|
-
},
|
|
112
|
-
MuiDialogTitle: {
|
|
113
|
-
styleOverrides: {
|
|
114
|
-
root: {
|
|
115
|
-
fontSize: "1.2rem",
|
|
116
|
-
fontWeight: 500,
|
|
117
|
-
paddingLeft: 16,
|
|
118
|
-
paddingRight: 16,
|
|
119
|
-
},
|
|
120
|
-
},
|
|
121
|
-
},
|
|
122
|
-
MuiFormLabel: {
|
|
123
|
-
styleOverrides: {
|
|
124
|
-
root: { color: get("--ds-color-neutral-text-subtle") || "rgba(0, 0, 0, 0.72)" },
|
|
125
|
-
},
|
|
126
|
-
},
|
|
127
|
-
MuiTextField: { defaultProps: { variant: "filled" } },
|
|
128
|
-
MuiSelect: { defaultProps: { variant: "filled" } },
|
|
129
|
-
MuiFormControl: { defaultProps: { variant: "filled" } },
|
|
130
|
-
},
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
export type MuiThemeProviderProps = {
|
|
135
|
-
children: ReactNode;
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Bridges Designsystemet's colour tokens into a MUI theme, so MUI components
|
|
140
|
-
* (most notably the data grid) follow Designsystemet instead of MUI defaults.
|
|
141
|
-
*
|
|
142
|
-
* This lives in a separate entry point (`@olenbetong/synergi-react/mui`) so apps
|
|
143
|
-
* that have migrated to Designsystemet don't pull ~160 kB of MUI and Emotion
|
|
144
|
-
* into their bundle just by using `AppShell`. Wrap `AppShell` with it in apps
|
|
145
|
-
* that still render MUI components:
|
|
146
|
-
*
|
|
147
|
-
* @example
|
|
148
|
-
* ```tsx
|
|
149
|
-
* import { AppShell } from "@olenbetong/synergi-react";
|
|
150
|
-
* import { MuiThemeProvider } from "@olenbetong/synergi-react/mui";
|
|
151
|
-
*
|
|
152
|
-
* <MuiThemeProvider>
|
|
153
|
-
* <AppShell>{children}</AppShell>
|
|
154
|
-
* </MuiThemeProvider>
|
|
155
|
-
* ```
|
|
156
|
-
*/
|
|
157
|
-
export function MuiThemeProvider({ children }: MuiThemeProviderProps) {
|
|
158
|
-
const colorScheme = useColorScheme();
|
|
159
|
-
|
|
160
|
-
// Rebuilt whenever the color scheme changes so MUI components (notably the
|
|
161
|
-
// data grid) follow Designsystemet instead of staying stuck in light mode.
|
|
162
|
-
// Also re-read after mount, since the stylesheets are imported from JS and
|
|
163
|
-
// the CSS variables aren't necessarily resolved during the first render.
|
|
164
|
-
const [theme, setTheme] = useState(() => buildMuiTheme(colorScheme));
|
|
165
|
-
useEffect(() => {
|
|
166
|
-
setTheme(buildMuiTheme(colorScheme));
|
|
167
|
-
}, [colorScheme]);
|
|
168
|
-
|
|
169
|
-
return (
|
|
170
|
-
<StyledEngineProvider injectFirst>
|
|
171
|
-
<ThemeProvider theme={theme}>{children}</ThemeProvider>
|
|
172
|
-
</StyledEngineProvider>
|
|
173
|
-
);
|
|
174
|
-
}
|
|
1
|
+
import { StyledEngineProvider, ThemeProvider } from "@mui/material";
|
|
2
|
+
import { createTheme as muiCreateTheme } from "@mui/material/styles";
|
|
3
|
+
import { type ReactNode, useEffect, useState } from "react";
|
|
4
|
+
|
|
5
|
+
function getColorScheme(): "light" | "dark" {
|
|
6
|
+
let scheme = document.body?.dataset.colorScheme ?? document.documentElement?.dataset.colorScheme ?? "light";
|
|
7
|
+
|
|
8
|
+
if (scheme === "auto") {
|
|
9
|
+
return globalThis.matchMedia?.("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return scheme === "dark" ? "dark" : "light";
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Tracks the color scheme Designsystemet is rendering with. The article template
|
|
17
|
+
* sets `data-color-scheme` on `<body>`, so watch that attribute as well as the
|
|
18
|
+
* OS preference (used when the scheme is `auto`).
|
|
19
|
+
*/
|
|
20
|
+
function useColorScheme() {
|
|
21
|
+
let [scheme, setScheme] = useState<"light" | "dark">(() => getColorScheme());
|
|
22
|
+
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
function update() {
|
|
25
|
+
setScheme(getColorScheme());
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
update();
|
|
29
|
+
|
|
30
|
+
let observer = new MutationObserver(update);
|
|
31
|
+
observer.observe(document.body, { attributes: true, attributeFilter: ["data-color-scheme"] });
|
|
32
|
+
observer.observe(document.documentElement, { attributes: true, attributeFilter: ["data-color-scheme"] });
|
|
33
|
+
|
|
34
|
+
let media = globalThis.matchMedia?.("(prefers-color-scheme: dark)");
|
|
35
|
+
media?.addEventListener("change", update);
|
|
36
|
+
|
|
37
|
+
return () => {
|
|
38
|
+
observer.disconnect();
|
|
39
|
+
media?.removeEventListener("change", update);
|
|
40
|
+
};
|
|
41
|
+
}, []);
|
|
42
|
+
|
|
43
|
+
return scheme;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function buildMuiTheme(mode: "light" | "dark") {
|
|
47
|
+
const s = getComputedStyle(document.body);
|
|
48
|
+
const get = (v: string) => s.getPropertyValue(v).trim();
|
|
49
|
+
const isDark = mode === "dark";
|
|
50
|
+
|
|
51
|
+
return muiCreateTheme({
|
|
52
|
+
palette: {
|
|
53
|
+
mode,
|
|
54
|
+
primary: {
|
|
55
|
+
main: get("--ds-color-brand-base-default") || "#116069",
|
|
56
|
+
dark: get("--ds-color-brand-base-hover") || "#0d4b52",
|
|
57
|
+
contrastText: get("--ds-color-brand-base-contrast-default") || "#ffffff",
|
|
58
|
+
},
|
|
59
|
+
secondary: {
|
|
60
|
+
main: get("--ds-color-brand-light-base-default") || "#1a95a2",
|
|
61
|
+
},
|
|
62
|
+
background: {
|
|
63
|
+
default: get("--ds-color-neutral-background-default") || (isDark ? "#17181a" : "#ffffff"),
|
|
64
|
+
paper: get("--ds-color-neutral-background-default") || (isDark ? "#17181a" : "#ffffff"),
|
|
65
|
+
},
|
|
66
|
+
text: {
|
|
67
|
+
primary: get("--ds-color-neutral-text-default") || (isDark ? "#e5e6e7" : "#292c30"),
|
|
68
|
+
secondary: get("--ds-color-neutral-text-subtle") || (isDark ? "#b3b5b7" : "#5b5f64"),
|
|
69
|
+
},
|
|
70
|
+
divider: get("--ds-color-neutral-border-subtle") || (isDark ? "#4e5052" : "#bbbcbd"),
|
|
71
|
+
},
|
|
72
|
+
typography: {
|
|
73
|
+
fontFamily: [
|
|
74
|
+
"-apple-system",
|
|
75
|
+
"BlinkMacSystemFont",
|
|
76
|
+
'"Segoe UI"',
|
|
77
|
+
"Roboto",
|
|
78
|
+
'"Helvetica Neue"',
|
|
79
|
+
"Arial",
|
|
80
|
+
"sans-serif",
|
|
81
|
+
'"Apple Color Emoji"',
|
|
82
|
+
'"Segoe UI Emoji"',
|
|
83
|
+
'"Segoe UI Symbol"',
|
|
84
|
+
].join(","),
|
|
85
|
+
},
|
|
86
|
+
components: {
|
|
87
|
+
MuiTypography: {
|
|
88
|
+
styleOverrides: {
|
|
89
|
+
h1: { fontSize: "2.488rem" },
|
|
90
|
+
h2: { fontSize: "2.074rem" },
|
|
91
|
+
h3: { fontSize: "1.728rem" },
|
|
92
|
+
h4: { fontSize: "1.44rem" },
|
|
93
|
+
h5: { fontSize: "1.2rem" },
|
|
94
|
+
h6: { fontSize: "1rem" },
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
MuiAppBar: {
|
|
98
|
+
styleOverrides: {
|
|
99
|
+
root: {
|
|
100
|
+
"& .MuiTypography-h1": {
|
|
101
|
+
fontSize: "1.25rem",
|
|
102
|
+
fontWeight: "500",
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
MuiButton: {
|
|
108
|
+
styleOverrides: {
|
|
109
|
+
root: { borderRadius: 2 },
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
MuiDialogTitle: {
|
|
113
|
+
styleOverrides: {
|
|
114
|
+
root: {
|
|
115
|
+
fontSize: "1.2rem",
|
|
116
|
+
fontWeight: 500,
|
|
117
|
+
paddingLeft: 16,
|
|
118
|
+
paddingRight: 16,
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
MuiFormLabel: {
|
|
123
|
+
styleOverrides: {
|
|
124
|
+
root: { color: get("--ds-color-neutral-text-subtle") || "rgba(0, 0, 0, 0.72)" },
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
MuiTextField: { defaultProps: { variant: "filled" } },
|
|
128
|
+
MuiSelect: { defaultProps: { variant: "filled" } },
|
|
129
|
+
MuiFormControl: { defaultProps: { variant: "filled" } },
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export type MuiThemeProviderProps = {
|
|
135
|
+
children: ReactNode;
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Bridges Designsystemet's colour tokens into a MUI theme, so MUI components
|
|
140
|
+
* (most notably the data grid) follow Designsystemet instead of MUI defaults.
|
|
141
|
+
*
|
|
142
|
+
* This lives in a separate entry point (`@olenbetong/synergi-react/mui`) so apps
|
|
143
|
+
* that have migrated to Designsystemet don't pull ~160 kB of MUI and Emotion
|
|
144
|
+
* into their bundle just by using `AppShell`. Wrap `AppShell` with it in apps
|
|
145
|
+
* that still render MUI components:
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```tsx
|
|
149
|
+
* import { AppShell } from "@olenbetong/synergi-react";
|
|
150
|
+
* import { MuiThemeProvider } from "@olenbetong/synergi-react/mui";
|
|
151
|
+
*
|
|
152
|
+
* <MuiThemeProvider>
|
|
153
|
+
* <AppShell>{children}</AppShell>
|
|
154
|
+
* </MuiThemeProvider>
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
export function MuiThemeProvider({ children }: MuiThemeProviderProps) {
|
|
158
|
+
const colorScheme = useColorScheme();
|
|
159
|
+
|
|
160
|
+
// Rebuilt whenever the color scheme changes so MUI components (notably the
|
|
161
|
+
// data grid) follow Designsystemet instead of staying stuck in light mode.
|
|
162
|
+
// Also re-read after mount, since the stylesheets are imported from JS and
|
|
163
|
+
// the CSS variables aren't necessarily resolved during the first render.
|
|
164
|
+
const [theme, setTheme] = useState(() => buildMuiTheme(colorScheme));
|
|
165
|
+
useEffect(() => {
|
|
166
|
+
setTheme(buildMuiTheme(colorScheme));
|
|
167
|
+
}, [colorScheme]);
|
|
168
|
+
|
|
169
|
+
return (
|
|
170
|
+
<StyledEngineProvider injectFirst>
|
|
171
|
+
<ThemeProvider theme={theme}>{children}</ThemeProvider>
|
|
172
|
+
</StyledEngineProvider>
|
|
173
|
+
);
|
|
174
|
+
}
|
package/src/mui/index.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { MuiThemeProvider, type MuiThemeProviderProps } from "./MuiThemeProvider.js";
|
|
1
|
+
export { MuiThemeProvider, type MuiThemeProviderProps } from "./MuiThemeProvider.js";
|
package/src/test/setup.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import "@testing-library/jest-dom/vitest";
|
|
2
|
-
|
|
3
|
-
import { cleanup } from "@testing-library/react";
|
|
4
|
-
import { afterEach } from "vitest";
|
|
5
|
-
|
|
6
|
-
afterEach(() => {
|
|
7
|
-
cleanup();
|
|
8
|
-
});
|
|
1
|
+
import "@testing-library/jest-dom/vitest";
|
|
2
|
+
|
|
3
|
+
import { cleanup } from "@testing-library/react";
|
|
4
|
+
import { afterEach } from "vitest";
|
|
5
|
+
|
|
6
|
+
afterEach(() => {
|
|
7
|
+
cleanup();
|
|
8
|
+
});
|