@olenbetong/synergi-react 2.8.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/styles/styles.css.map +1 -1
- package/es/chrome/AppShell/index.d.ts +8 -0
- package/es/chrome/AppShell/index.js +10 -130
- package/es/components/ImageEditor/ImageEditor.css +10 -0
- package/es/components/ImageEditor/ImageEditor.d.ts +12 -0
- package/es/components/ImageEditor/ImageEditor.js +27 -6
- package/es/components/ImageEditor/index.d.ts +3 -0
- package/es/components/ImageEditor/index.js +3 -0
- package/es/components/ImageEditor/plugins/cropPlugin/CropOverlay.js +27 -5
- package/es/components/ImageEditor/plugins/cropPlugin/CropToolbar.js +4 -3
- package/es/components/ImageEditor/plugins/cropPlugin/useCropTool.d.ts +20 -3
- package/es/components/ImageEditor/plugins/cropPlugin/useCropTool.js +216 -33
- package/es/components/ImageEditor/plugins/zoomPlugin/ZoomContext.d.ts +5 -0
- package/es/components/ImageEditor/plugins/zoomPlugin/ZoomContext.js +7 -0
- package/es/components/ImageEditor/plugins/zoomPlugin/ZoomControls.js +1 -1
- package/es/components/ImageEditor/useEdgeDetection.d.ts +0 -2
- package/es/components/ImageEditor/useEdgeDetection.js +11 -30
- package/es/components/ImageEditor/useImageHistory.d.ts +6 -1
- package/es/components/ImageEditor/useImageHistory.js +21 -23
- package/es/components/ImageEditor/useOpenCV.d.ts +26 -1
- package/es/components/ImageEditor/useOpenCV.js +108 -42
- package/es/components/SplitContainer/index.js +2 -4
- package/es/elements/ElementDamage/DamageFormButtons.d.ts +2 -3
- package/es/elements/ElementDamage/DamageFormButtons.js +1 -1
- package/es/elements/ElementDamage/TransportElementSelect.d.ts +1 -2
- package/es/elements/index.d.ts +5 -0
- package/es/elements/index.js +5 -0
- package/es/filter/ChipListInput.d.ts +13 -0
- package/es/filter/ChipListInput.js +34 -0
- package/es/filter/FilterBuilder.css +152 -0
- package/es/filter/FilterBuilder.d.ts +115 -0
- package/es/filter/FilterBuilder.js +146 -0
- package/es/filter/FilterBuilder.test.d.ts +1 -0
- package/es/filter/FilterBuilder.test.js +120 -0
- package/es/filter/FilterEditor.css +231 -0
- package/es/filter/FilterEditor.d.ts +17 -0
- package/es/filter/FilterEditor.js +38 -0
- package/es/filter/FilterEditor.test.d.ts +1 -0
- package/es/filter/FilterEditor.test.js +183 -0
- package/es/filter/FilterGroupEditor.d.ts +22 -0
- package/es/filter/FilterGroupEditor.js +34 -0
- package/es/filter/FilterNameDialog.css +22 -0
- package/es/filter/FilterNameDialog.d.ts +18 -0
- package/es/filter/FilterNameDialog.js +32 -0
- package/es/filter/FilterRow.d.ts +14 -0
- package/es/filter/FilterRow.js +32 -0
- package/es/filter/FilterShareDialog.css +28 -0
- package/es/filter/FilterShareDialog.d.ts +23 -0
- package/es/filter/FilterShareDialog.js +63 -0
- package/es/filter/FilterStringField.d.ts +15 -0
- package/es/filter/FilterStringField.js +37 -0
- package/es/filter/FilterValueEditor.d.ts +16 -0
- package/es/filter/FilterValueEditor.js +85 -0
- package/es/filter/SavedFilterTree.css +107 -0
- package/es/filter/SavedFilterTree.d.ts +45 -0
- package/es/filter/SavedFilterTree.js +44 -0
- package/es/filter/SavedFilterTree.test.d.ts +1 -0
- package/es/filter/SavedFilterTree.test.js +75 -0
- package/es/filter/index.d.ts +11 -0
- package/es/filter/index.js +10 -0
- package/es/filter/types.d.ts +34 -0
- package/es/filter/types.js +1 -0
- package/es/index.d.ts +2 -1
- package/es/index.js +6 -1
- package/es/mui/MuiThemeProvider.d.ts +24 -0
- package/es/mui/MuiThemeProvider.js +152 -0
- package/es/mui/index.d.ts +1 -0
- package/es/mui/index.js +1 -0
- package/es/report/ReportLauncher.css +147 -0
- package/es/report/ReportLauncher.d.ts +55 -0
- package/es/report/ReportLauncher.js +142 -0
- package/es/report/ReportLauncher.test.d.ts +1 -0
- package/es/report/ReportLauncher.test.js +231 -0
- package/es/report/ReportParameters.css +29 -0
- package/es/report/ReportParameters.d.ts +46 -0
- package/es/report/ReportParameters.js +65 -0
- package/es/report/ReportParameters.test.d.ts +1 -0
- package/es/report/ReportParameters.test.js +84 -0
- package/es/report/index.d.ts +2 -0
- package/es/report/index.js +2 -0
- package/es/test/setup.d.ts +1 -0
- package/es/test/setup.js +6 -0
- package/package.json +22 -7
- package/src/chrome/AppShell/index.tsx +34 -171
- package/src/components/ImageEditor/ImageEditor.css +10 -0
- package/src/components/ImageEditor/ImageEditor.tsx +40 -5
- package/src/components/ImageEditor/index.ts +1 -0
- package/src/components/ImageEditor/plugins/cropPlugin/CropOverlay.tsx +66 -20
- package/src/components/ImageEditor/plugins/cropPlugin/CropToolbar.tsx +19 -3
- package/src/components/ImageEditor/plugins/cropPlugin/useCropTool.ts +266 -39
- package/src/components/ImageEditor/plugins/zoomPlugin/ZoomContext.tsx +8 -0
- package/src/components/ImageEditor/useEdgeDetection.ts +11 -51
- package/src/components/ImageEditor/useImageHistory.ts +27 -19
- package/src/components/ImageEditor/useOpenCV.ts +112 -62
- package/src/components/LinkedCardList/index.scss +4 -2
- package/src/components/ProgressBar/index.scss +4 -2
- package/src/components/SplitContainer/index.tsx +3 -4
- package/src/filter/ChipListInput.tsx +79 -0
- package/src/filter/FilterBuilder.css +152 -0
- package/src/filter/FilterBuilder.test.tsx +153 -0
- package/src/filter/FilterBuilder.tsx +435 -0
- package/src/filter/FilterEditor.css +231 -0
- package/src/filter/FilterEditor.test.tsx +259 -0
- package/src/filter/FilterEditor.tsx +74 -0
- package/src/filter/FilterGroupEditor.tsx +160 -0
- package/src/filter/FilterNameDialog.css +22 -0
- package/src/filter/FilterNameDialog.tsx +81 -0
- package/src/filter/FilterRow.tsx +117 -0
- package/src/filter/FilterShareDialog.css +28 -0
- package/src/filter/FilterShareDialog.tsx +201 -0
- package/src/filter/FilterStringField.tsx +77 -0
- package/src/filter/FilterValueEditor.tsx +220 -0
- package/src/filter/SavedFilterTree.css +107 -0
- package/src/filter/SavedFilterTree.test.tsx +94 -0
- package/src/filter/SavedFilterTree.tsx +222 -0
- package/src/filter/index.ts +11 -0
- package/src/filter/types.ts +38 -0
- package/src/index.ts +39 -1
- package/src/mui/MuiThemeProvider.tsx +174 -0
- package/src/mui/index.ts +1 -0
- package/src/report/ReportLauncher.css +147 -0
- package/src/report/ReportLauncher.test.tsx +281 -0
- package/src/report/ReportLauncher.tsx +421 -0
- package/src/report/ReportParameters.css +29 -0
- package/src/report/ReportParameters.test.tsx +133 -0
- package/src/report/ReportParameters.tsx +198 -0
- package/src/report/index.ts +2 -0
- package/src/test/setup.ts +8 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Select, Textfield } from "@digdir/designsystemet-react";
|
|
3
|
+
import { PencilIcon } from "@navikt/aksel-icons";
|
|
4
|
+
import { getDynamicValueLabel, getDynamicValuesForField, getLocalizedString, getOperatorArity, getValueType, normalizeOperator, } from "@olenbetong/appframe-core";
|
|
5
|
+
import { Combobox } from "@olenbetong/appframe-ds";
|
|
6
|
+
import { ChipListInput } from "./ChipListInput.js";
|
|
7
|
+
/** The `input` type used for a field's scalar editor. */
|
|
8
|
+
function getInputType(field) {
|
|
9
|
+
switch (field?.type) {
|
|
10
|
+
case "number":
|
|
11
|
+
return "number";
|
|
12
|
+
case "date":
|
|
13
|
+
return "date";
|
|
14
|
+
case "datetime":
|
|
15
|
+
return "datetime-local";
|
|
16
|
+
default:
|
|
17
|
+
return "text";
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function toStringValue(value) {
|
|
21
|
+
if (value === null || value === undefined)
|
|
22
|
+
return "";
|
|
23
|
+
if (value instanceof Date)
|
|
24
|
+
return value.toISOString();
|
|
25
|
+
return String(value);
|
|
26
|
+
}
|
|
27
|
+
function toArrayValue(value, length) {
|
|
28
|
+
let array = Array.isArray(value) ? value.map(toStringValue) : [];
|
|
29
|
+
if (length === undefined)
|
|
30
|
+
return array;
|
|
31
|
+
// Pair editors always render two inputs, even before both are filled in.
|
|
32
|
+
return Array.from({ length }, (_, index) => array[index] ?? "");
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The value part of a filter row. Which editor is rendered depends on the
|
|
36
|
+
* operator's arity, the field's type, and whether the value is a dynamic
|
|
37
|
+
* ("special") value such as `Today` or `CurrentUser`.
|
|
38
|
+
*/
|
|
39
|
+
export function FilterValueEditor({ expression, field, options, onChange, readOnly, "data-size": size = "sm", }) {
|
|
40
|
+
let operator = normalizeOperator(expression.operator);
|
|
41
|
+
let arity = getOperatorArity(operator);
|
|
42
|
+
let isDynamic = expression.valueType === "special";
|
|
43
|
+
let dynamicValues = field ? getDynamicValuesForField(field) : [];
|
|
44
|
+
let inputType = getInputType(field);
|
|
45
|
+
function setValue(value) {
|
|
46
|
+
onChange({ ...expression, value });
|
|
47
|
+
}
|
|
48
|
+
function setDynamic(enabled) {
|
|
49
|
+
if (enabled) {
|
|
50
|
+
onChange({ ...expression, value: dynamicValues[0] ?? null, valueType: "special" });
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
onChange({
|
|
54
|
+
...expression,
|
|
55
|
+
value: arity === "pair" ? ["", ""] : arity === "list" ? [] : "",
|
|
56
|
+
valueType: field ? getValueType(field, operator) : "string",
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (arity === "none")
|
|
61
|
+
return null;
|
|
62
|
+
let editor;
|
|
63
|
+
if (isDynamic) {
|
|
64
|
+
editor = (_jsx(Select, { className: "ObFilterEditor-value", "aria-label": getLocalizedString("Value"), "data-size": size, disabled: readOnly, value: toStringValue(expression.value), onChange: (event) => setValue(event.target.value), children: dynamicValues.map((dynamicValue) => (_jsx(Select.Option, { value: dynamicValue, children: getDynamicValueLabel(dynamicValue) }, dynamicValue))) }));
|
|
65
|
+
}
|
|
66
|
+
else if (arity === "list") {
|
|
67
|
+
editor = options ? (_jsx(Combobox, { className: "ObFilterEditor-value", multiple: true, "data-size": size, readOnly: readOnly, placeholder: getLocalizedString("Select values"), "aria-label": getLocalizedString("Value"), options: options, getOptionLabel: (option) => option.label ?? option.value, isOptionEqualToValue: (a, b) => a.value === b.value, value: toArrayValue(expression.value).map((item) => options.find((option) => option.value === item) ?? { value: item }), onChange: (_event, selected) => setValue(selected.map((option) => option.value)) })) : (_jsx(ChipListInput, { "aria-label": getLocalizedString("Value"), "data-size": size, readOnly: readOnly, type: inputType, value: toArrayValue(expression.value), onChange: setValue }));
|
|
68
|
+
}
|
|
69
|
+
else if (arity === "pair") {
|
|
70
|
+
let [from, to] = toArrayValue(expression.value, 2);
|
|
71
|
+
editor = (_jsxs("div", { className: "ObFilterEditor-pair", children: [_jsx(Textfield, { className: "ObFilterEditor-value", "aria-label": getLocalizedString("From"), "data-size": size, readOnly: readOnly, type: inputType, value: from, onChange: (event) => setValue([event.target.value, to]) }), _jsx("span", { className: "ObFilterEditor-pairSeparator", children: getLocalizedString("and") }), _jsx(Textfield, { className: "ObFilterEditor-value", "aria-label": getLocalizedString("To"), "data-size": size, readOnly: readOnly, type: inputType, value: to, onChange: (event) => setValue([from, event.target.value]) })] }));
|
|
72
|
+
}
|
|
73
|
+
else if (options) {
|
|
74
|
+
let current = toStringValue(expression.value);
|
|
75
|
+
editor = (_jsx(Combobox, { className: "ObFilterEditor-value", "data-size": size, readOnly: readOnly, placeholder: getLocalizedString("Select value"), "aria-label": getLocalizedString("Value"), options: options, getOptionLabel: (option) => option.label ?? option.value, isOptionEqualToValue: (a, b) => a.value === b.value, value: current ? (options.find((option) => option.value === current) ?? { value: current }) : null, onChange: (_event, selected) => setValue(selected?.value ?? "") }));
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
editor = (_jsx(Textfield, { className: "ObFilterEditor-value", "aria-label": getLocalizedString("Value"), "data-size": size, readOnly: readOnly, type: inputType, value: toStringValue(expression.value), onChange: (event) => setValue(event.target.value) }));
|
|
79
|
+
}
|
|
80
|
+
// Dynamic values are resolved server side, so they can only replace the whole
|
|
81
|
+
// value. Pairs would need one toggle per side, which the Windows editor does
|
|
82
|
+
// not offer either.
|
|
83
|
+
let canToggleDynamic = !readOnly && dynamicValues.length > 0 && arity === "single";
|
|
84
|
+
return (_jsxs("div", { className: "ObFilterEditor-valueCell", children: [editor, canToggleDynamic && (_jsx("button", { type: "button", className: "ObFilterEditor-iconButton", "aria-pressed": isDynamic, title: getLocalizedString("Use a relative value"), "aria-label": getLocalizedString("Use a relative value"), onClick: () => setDynamic(!isDynamic), children: _jsx(PencilIcon, { "aria-hidden": true }) }))] }));
|
|
85
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Colours use the contextual `--ds-color-*` aliases so the tree follows the
|
|
3
|
+
* active colour scheme. Never add hex fallbacks — they only encode the light
|
|
4
|
+
* theme and silently mask misspelled tokens.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
.ObSavedFilterTree-root,
|
|
8
|
+
.ObSavedFilterTree-children {
|
|
9
|
+
list-style: none;
|
|
10
|
+
margin: 0;
|
|
11
|
+
padding: 0;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.ObSavedFilterTree-children {
|
|
15
|
+
/*
|
|
16
|
+
* A branch is chevron + icon, a child only an icon, so matching the branch
|
|
17
|
+
* indent would put a child's icon under its parent's icon and make the two
|
|
18
|
+
* levels look like one. Indent past the branch icon instead, so a child's
|
|
19
|
+
* icon starts where its parent's label does.
|
|
20
|
+
*/
|
|
21
|
+
margin-inline-start: calc(var(--ds-size-6) + var(--ds-size-1) + var(--ds-size-6));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.ObSavedFilterTree-item {
|
|
25
|
+
display: flex;
|
|
26
|
+
align-items: center;
|
|
27
|
+
gap: var(--ds-size-1);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.ObSavedFilterTree-node {
|
|
31
|
+
display: flex;
|
|
32
|
+
align-items: center;
|
|
33
|
+
gap: var(--ds-size-1);
|
|
34
|
+
flex: 1;
|
|
35
|
+
min-inline-size: 0;
|
|
36
|
+
padding: var(--ds-size-1) var(--ds-size-2);
|
|
37
|
+
border: none;
|
|
38
|
+
border-radius: var(--ds-border-radius-sm);
|
|
39
|
+
background: none;
|
|
40
|
+
color: var(--ds-color-text-default);
|
|
41
|
+
font: inherit;
|
|
42
|
+
text-align: start;
|
|
43
|
+
cursor: pointer;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.ObSavedFilterTree-node:hover {
|
|
47
|
+
background: var(--ds-color-surface-hover);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.ObSavedFilterTree-node:focus-visible {
|
|
51
|
+
outline: var(--ds-border-width-focus) solid var(--ds-color-focus-outer);
|
|
52
|
+
outline-offset: var(--ds-border-width-focus);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.ObSavedFilterTree-selected {
|
|
56
|
+
background: var(--ds-color-surface-active);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.ObSavedFilterTree-dirty .ObSavedFilterTree-label {
|
|
60
|
+
font-weight: var(--ds-font-weight-semibold);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.ObSavedFilterTree-chevron,
|
|
64
|
+
.ObSavedFilterTree-icon {
|
|
65
|
+
display: inline-flex;
|
|
66
|
+
flex: none;
|
|
67
|
+
align-items: center;
|
|
68
|
+
justify-content: center;
|
|
69
|
+
inline-size: var(--ds-size-6);
|
|
70
|
+
block-size: var(--ds-size-6);
|
|
71
|
+
color: var(--ds-color-text-subtle);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.ObSavedFilterTree-chevron > *,
|
|
75
|
+
.ObSavedFilterTree-icon > * {
|
|
76
|
+
inline-size: 100%;
|
|
77
|
+
block-size: 100%;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.ObSavedFilterTree-label {
|
|
81
|
+
overflow: hidden;
|
|
82
|
+
text-overflow: ellipsis;
|
|
83
|
+
white-space: nowrap;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.ObSavedFilterTree-empty {
|
|
87
|
+
/* Lines up with the child labels, past their icon. */
|
|
88
|
+
padding: var(--ds-size-1) var(--ds-size-2) var(--ds-size-1)
|
|
89
|
+
calc(var(--ds-size-2) + var(--ds-size-6) + var(--ds-size-1));
|
|
90
|
+
color: var(--ds-color-text-subtle);
|
|
91
|
+
font-style: italic;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/*
|
|
95
|
+
* The menu button only appears on hover/focus on pointer devices; on touch it is
|
|
96
|
+
* always visible because there is no hover to reveal it.
|
|
97
|
+
*/
|
|
98
|
+
@media (hover: hover) {
|
|
99
|
+
.ObSavedFilterTree-menuButton {
|
|
100
|
+
visibility: hidden;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
.ObSavedFilterTree-item:hover .ObSavedFilterTree-menuButton,
|
|
104
|
+
.ObSavedFilterTree-item:focus-within .ObSavedFilterTree-menuButton {
|
|
105
|
+
visibility: visible;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { type SavedFilter } from "@olenbetong/appframe-core";
|
|
2
|
+
import "./SavedFilterTree.css";
|
|
3
|
+
/** `null` is the "new filter" node, i.e. no saved filter selected. */
|
|
4
|
+
export type SavedFilterSelection = number | null;
|
|
5
|
+
export type SavedFilterTreeProps = {
|
|
6
|
+
mine: SavedFilter[];
|
|
7
|
+
shared: SavedFilter[];
|
|
8
|
+
/** `FilterID` of the selected filter, or `null` for "new filter". */
|
|
9
|
+
value: SavedFilterSelection;
|
|
10
|
+
onChange: (filterId: SavedFilterSelection) => void;
|
|
11
|
+
/**
|
|
12
|
+
* Marks the selected filter as having unsaved changes; it is then rendered
|
|
13
|
+
* in bold, like the Windows client does.
|
|
14
|
+
*/
|
|
15
|
+
dirty?: boolean;
|
|
16
|
+
onRename?: (filter: SavedFilter) => void;
|
|
17
|
+
onDelete?: (filter: SavedFilter) => void;
|
|
18
|
+
/** Shows an "info" item in the context menu when supplied. */
|
|
19
|
+
onShowInfo?: (filter: SavedFilter) => void;
|
|
20
|
+
loading?: boolean;
|
|
21
|
+
className?: string;
|
|
22
|
+
"data-size"?: "sm" | "md" | "lg";
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* The saved-filter list of the filter builder: a "new filter" entry followed by
|
|
26
|
+
* the user's own filters and the filters shared with them.
|
|
27
|
+
*
|
|
28
|
+
* Which actions a filter offers depends on the access the database resolved for
|
|
29
|
+
* it — renaming and deleting are restricted to filters the user created, even
|
|
30
|
+
* when they manage a filter someone else made.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```jsx
|
|
34
|
+
* let { mine, shared, rename, remove } = useSavedFilters({ dbObjectId: "aviw_Personnel_Persons" });
|
|
35
|
+
*
|
|
36
|
+
* <SavedFilterTree
|
|
37
|
+
* mine={mine}
|
|
38
|
+
* shared={shared}
|
|
39
|
+
* value={selected}
|
|
40
|
+
* onChange={setSelected}
|
|
41
|
+
* onRename={(filter) => rename(filter.filterId, prompt("Name", filter.name))}
|
|
42
|
+
* />
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare function SavedFilterTree({ mine, shared, value, onChange, dirty, onRename, onDelete, onShowInfo, loading, className, "data-size": size, }: SavedFilterTreeProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Dropdown } from "@digdir/designsystemet-react";
|
|
3
|
+
import { canDeleteSavedFilter, canRenameSavedFilter, getLocalizedString, } from "@olenbetong/appframe-core";
|
|
4
|
+
import { ChevronDownIcon, ChevronRightIcon, FilesIcon, FileTextIcon, MenuElipsisVerticalIcon, PadlockLockedIcon, PencilIcon, StarIcon, TrashIcon, } from "@navikt/aksel-icons";
|
|
5
|
+
import clsx from "clsx";
|
|
6
|
+
import { useState } from "react";
|
|
7
|
+
import "./SavedFilterTree.css";
|
|
8
|
+
/**
|
|
9
|
+
* The saved-filter list of the filter builder: a "new filter" entry followed by
|
|
10
|
+
* the user's own filters and the filters shared with them.
|
|
11
|
+
*
|
|
12
|
+
* Which actions a filter offers depends on the access the database resolved for
|
|
13
|
+
* it — renaming and deleting are restricted to filters the user created, even
|
|
14
|
+
* when they manage a filter someone else made.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```jsx
|
|
18
|
+
* let { mine, shared, rename, remove } = useSavedFilters({ dbObjectId: "aviw_Personnel_Persons" });
|
|
19
|
+
*
|
|
20
|
+
* <SavedFilterTree
|
|
21
|
+
* mine={mine}
|
|
22
|
+
* shared={shared}
|
|
23
|
+
* value={selected}
|
|
24
|
+
* onChange={setSelected}
|
|
25
|
+
* onRename={(filter) => rename(filter.filterId, prompt("Name", filter.name))}
|
|
26
|
+
* />
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export function SavedFilterTree({ mine, shared, value, onChange, dirty, onRename, onDelete, onShowInfo, loading, className, "data-size": size = "sm", }) {
|
|
30
|
+
let [expanded, setExpanded] = useState({ mine: true, shared: true });
|
|
31
|
+
function renderBranch(key, label, icon, filters) {
|
|
32
|
+
let isExpanded = expanded[key];
|
|
33
|
+
return (_jsxs("li", { className: "ObSavedFilterTree-branch", children: [_jsxs("button", { type: "button", className: "ObSavedFilterTree-node", "aria-expanded": isExpanded, onClick: () => setExpanded((state) => ({ ...state, [key]: !state[key] })), children: [_jsx("span", { className: "ObSavedFilterTree-chevron", "aria-hidden": true, children: isExpanded ? _jsx(ChevronDownIcon, {}) : _jsx(ChevronRightIcon, {}) }), _jsx("span", { className: "ObSavedFilterTree-icon", "aria-hidden": true, children: icon }), _jsx("span", { className: "ObSavedFilterTree-label", children: label })] }), isExpanded && (_jsxs("ul", { className: "ObSavedFilterTree-children", children: [filters.length === 0 && !loading && (_jsx("li", { className: "ObSavedFilterTree-empty", children: getLocalizedString("No filters") })), filters.map((filter) => (_jsx(SavedFilterNode, { filter: filter, selected: filter.filterId === value, dirty: dirty && filter.filterId === value, onSelect: () => onChange(filter.filterId), onRename: onRename, onDelete: onDelete, onShowInfo: onShowInfo }, filter.filterId)))] }))] }));
|
|
34
|
+
}
|
|
35
|
+
return (_jsxs("ul", { className: clsx("ObSavedFilterTree-root", className), "data-size": size, children: [_jsx("li", { children: _jsxs("button", { type: "button", className: clsx("ObSavedFilterTree-node", value === null && "ObSavedFilterTree-selected"), "aria-current": value === null, onClick: () => onChange(null), children: [_jsx("span", { className: "ObSavedFilterTree-chevron", "aria-hidden": true }), _jsx("span", { className: "ObSavedFilterTree-icon", "aria-hidden": true, children: _jsx(FileTextIcon, {}) }), _jsx("span", { className: "ObSavedFilterTree-label", children: getLocalizedString("New Filter") })] }) }), renderBranch("mine", getLocalizedString("My Filters"), _jsx(StarIcon, {}), mine), renderBranch("shared", getLocalizedString("Shared With Me"), _jsx(FilesIcon, {}), shared)] }));
|
|
36
|
+
}
|
|
37
|
+
function SavedFilterNode({ filter, selected, dirty, onSelect, onRename, onDelete, onShowInfo }) {
|
|
38
|
+
let canRename = Boolean(onRename) && canRenameSavedFilter(filter);
|
|
39
|
+
let canDelete = Boolean(onDelete) && canDeleteSavedFilter(filter);
|
|
40
|
+
let hasMenu = canRename || canDelete || Boolean(onShowInfo);
|
|
41
|
+
// A shared filter the user may not change; the Windows client shows a lock.
|
|
42
|
+
let isReadOnly = !filter.createdByUser && filter.accessLevel === "Reader";
|
|
43
|
+
return (_jsxs("li", { className: "ObSavedFilterTree-item", children: [_jsxs("button", { type: "button", className: clsx("ObSavedFilterTree-node", selected && "ObSavedFilterTree-selected", dirty && "ObSavedFilterTree-dirty"), "aria-current": selected, onClick: onSelect, children: [_jsx("span", { className: "ObSavedFilterTree-icon", "aria-hidden": true, children: isReadOnly ? _jsx(PadlockLockedIcon, {}) : _jsx(FileTextIcon, {}) }), _jsx("span", { className: "ObSavedFilterTree-label", children: filter.name })] }), hasMenu && (_jsxs(Dropdown.TriggerContext, { children: [_jsx(Dropdown.Trigger, { variant: "tertiary", icon: true, className: "ObSavedFilterTree-menuButton", "aria-label": getLocalizedString("Options for {0}").replace("{0}", filter.name), children: _jsx(MenuElipsisVerticalIcon, { "aria-hidden": true }) }), _jsx(Dropdown, { children: _jsxs(Dropdown.List, { children: [canRename && (_jsx(Dropdown.Item, { children: _jsxs(Dropdown.Button, { onClick: () => onRename?.(filter), children: [_jsx(PencilIcon, { "aria-hidden": true }), getLocalizedString("Rename")] }) })), onShowInfo && (_jsx(Dropdown.Item, { children: _jsx(Dropdown.Button, { onClick: () => onShowInfo(filter), children: getLocalizedString("Information") }) })), canDelete && (_jsx(Dropdown.Item, { children: _jsxs(Dropdown.Button, { "data-color": "danger", onClick: () => onDelete?.(filter), children: [_jsx(TrashIcon, { "aria-hidden": true }), getLocalizedString("Delete")] }) }))] }) })] }))] }));
|
|
44
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { render, screen } from "@testing-library/react";
|
|
3
|
+
import userEvent from "@testing-library/user-event";
|
|
4
|
+
import { describe, expect, it, vi } from "vitest";
|
|
5
|
+
import { SavedFilterTree } from "./SavedFilterTree.js";
|
|
6
|
+
function savedFilter(overrides) {
|
|
7
|
+
return {
|
|
8
|
+
primKey: `pk-${overrides.filterId}`,
|
|
9
|
+
criteria: "",
|
|
10
|
+
dbObjectId: "aviw_Test_View",
|
|
11
|
+
accessLevel: "Manager",
|
|
12
|
+
createdByUser: true,
|
|
13
|
+
createdBy: "bvh",
|
|
14
|
+
domain: "OB",
|
|
15
|
+
crossDomain: false,
|
|
16
|
+
isPersonallyShared: false,
|
|
17
|
+
hideCriteria: false,
|
|
18
|
+
headerText: null,
|
|
19
|
+
comment: null,
|
|
20
|
+
parameters: null,
|
|
21
|
+
reportTitle: null,
|
|
22
|
+
created: null,
|
|
23
|
+
updated: null,
|
|
24
|
+
...overrides,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
const MINE = [savedFilter({ filterId: 1, name: "Agder" })];
|
|
28
|
+
const SHARED = [
|
|
29
|
+
savedFilter({ filterId: 2, name: "Alle ledere", createdByUser: false, createdBy: "ola", accessLevel: "Reader" }),
|
|
30
|
+
];
|
|
31
|
+
function renderTree(props = {}) {
|
|
32
|
+
let onChange = vi.fn();
|
|
33
|
+
render(_jsx(SavedFilterTree, { mine: MINE, shared: SHARED, value: null, onChange: onChange, ...props }));
|
|
34
|
+
return { onChange };
|
|
35
|
+
}
|
|
36
|
+
describe("SavedFilterTree", () => {
|
|
37
|
+
it("renders the three fixed nodes and their filters", () => {
|
|
38
|
+
renderTree();
|
|
39
|
+
expect(screen.getByRole("button", { name: "New Filter" })).toBeTruthy();
|
|
40
|
+
expect(screen.getByRole("button", { name: /My Filters/ })).toBeTruthy();
|
|
41
|
+
expect(screen.getByRole("button", { name: /Shared With Me/ })).toBeTruthy();
|
|
42
|
+
expect(screen.getByRole("button", { name: "Agder" })).toBeTruthy();
|
|
43
|
+
expect(screen.getByRole("button", { name: "Alle ledere" })).toBeTruthy();
|
|
44
|
+
});
|
|
45
|
+
it("reports the selected filter id", async () => {
|
|
46
|
+
let { onChange } = renderTree();
|
|
47
|
+
await userEvent.click(screen.getByRole("button", { name: "Agder" }));
|
|
48
|
+
expect(onChange).toHaveBeenCalledWith(1);
|
|
49
|
+
});
|
|
50
|
+
it("reports null when the new filter node is selected", async () => {
|
|
51
|
+
let { onChange } = renderTree({ value: 1 });
|
|
52
|
+
await userEvent.click(screen.getByRole("button", { name: "New Filter" }));
|
|
53
|
+
expect(onChange).toHaveBeenCalledWith(null);
|
|
54
|
+
});
|
|
55
|
+
it("collapses a branch", async () => {
|
|
56
|
+
renderTree();
|
|
57
|
+
await userEvent.click(screen.getByRole("button", { name: /My Filters/ }));
|
|
58
|
+
expect(screen.queryByRole("button", { name: "Agder" })).toBeNull();
|
|
59
|
+
});
|
|
60
|
+
it("offers rename and delete for the user's own filters", async () => {
|
|
61
|
+
let onRename = vi.fn();
|
|
62
|
+
renderTree({ onRename, onDelete: vi.fn() });
|
|
63
|
+
await userEvent.click(screen.getByRole("button", { name: "Options for Agder" }));
|
|
64
|
+
await userEvent.click(screen.getByRole("button", { name: "Rename" }));
|
|
65
|
+
expect(onRename).toHaveBeenCalledWith(MINE[0]);
|
|
66
|
+
});
|
|
67
|
+
it("does not offer rename or delete for filters created by someone else", () => {
|
|
68
|
+
renderTree({ onRename: vi.fn(), onDelete: vi.fn() });
|
|
69
|
+
expect(screen.queryByRole("button", { name: "Options for Alle ledere" })).toBeNull();
|
|
70
|
+
});
|
|
71
|
+
it("still offers info for filters created by someone else", () => {
|
|
72
|
+
renderTree({ onShowInfo: vi.fn() });
|
|
73
|
+
expect(screen.getByRole("button", { name: "Options for Alle ledere" })).toBeTruthy();
|
|
74
|
+
});
|
|
75
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { ChipListInput, type ChipListInputProps } from "./ChipListInput.js";
|
|
2
|
+
export { FilterBuilder, type FilterBuilderProps, type SavedFilterValues } from "./FilterBuilder.js";
|
|
3
|
+
export { FilterEditor } from "./FilterEditor.js";
|
|
4
|
+
export { FilterGroupEditor, type FilterGroupEditorProps } from "./FilterGroupEditor.js";
|
|
5
|
+
export { FilterNameDialog, type FilterNameDialogProps } from "./FilterNameDialog.js";
|
|
6
|
+
export { FilterRow, type FilterRowProps } from "./FilterRow.js";
|
|
7
|
+
export { FilterShareDialog, type FilterShareDialogProps } from "./FilterShareDialog.js";
|
|
8
|
+
export { FilterStringField, type FilterStringFieldProps } from "./FilterStringField.js";
|
|
9
|
+
export { FilterValueEditor, type FilterValueEditorProps } from "./FilterValueEditor.js";
|
|
10
|
+
export { SavedFilterTree, type SavedFilterSelection, type SavedFilterTreeProps } from "./SavedFilterTree.js";
|
|
11
|
+
export type { FilterEditorProps, FilterEditorSize, FilterValueOption, GetFieldOptions } from "./types.js";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { ChipListInput } from "./ChipListInput.js";
|
|
2
|
+
export { FilterBuilder } from "./FilterBuilder.js";
|
|
3
|
+
export { FilterEditor } from "./FilterEditor.js";
|
|
4
|
+
export { FilterGroupEditor } from "./FilterGroupEditor.js";
|
|
5
|
+
export { FilterNameDialog } from "./FilterNameDialog.js";
|
|
6
|
+
export { FilterRow } from "./FilterRow.js";
|
|
7
|
+
export { FilterShareDialog } from "./FilterShareDialog.js";
|
|
8
|
+
export { FilterStringField } from "./FilterStringField.js";
|
|
9
|
+
export { FilterValueEditor } from "./FilterValueEditor.js";
|
|
10
|
+
export { SavedFilterTree } from "./SavedFilterTree.js";
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { FieldMetadata, FilterTree } from "@olenbetong/appframe-core";
|
|
2
|
+
/** A selectable value for a field that has a fixed list of values. */
|
|
3
|
+
export type FilterValueOption = {
|
|
4
|
+
value: string;
|
|
5
|
+
label?: string;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Resolves the list of values offered in the value editor for a field. Return
|
|
9
|
+
* `undefined` to fall back to a free text editor.
|
|
10
|
+
*
|
|
11
|
+
* Lookup fields carry a `valueListRecordSource` in their metadata, but loading
|
|
12
|
+
* that record source needs a data object, which is out of scope for this
|
|
13
|
+
* component. Supply the options from the outside instead.
|
|
14
|
+
*/
|
|
15
|
+
export type GetFieldOptions = (field: FieldMetadata) => FilterValueOption[] | undefined;
|
|
16
|
+
export type FilterEditorSize = "sm" | "md" | "lg";
|
|
17
|
+
export type FilterEditorProps = {
|
|
18
|
+
/** The fields the user can filter on. Fields with `excludeFromFilter` are hidden. */
|
|
19
|
+
fields: FieldMetadata[];
|
|
20
|
+
/** The filter tree. Use together with `onChange` for a controlled component. */
|
|
21
|
+
value?: FilterTree | null;
|
|
22
|
+
/** The initial filter tree when uncontrolled. */
|
|
23
|
+
defaultValue?: FilterTree | null;
|
|
24
|
+
onChange?: (filter: FilterTree) => void;
|
|
25
|
+
/** Renders the tree without any editing affordances. */
|
|
26
|
+
readOnly?: boolean;
|
|
27
|
+
/** Shows the filter string below the tree, editable unless `readOnly`. */
|
|
28
|
+
showFilterString?: boolean;
|
|
29
|
+
/** View the filter applies to. Passed to the conversion endpoint. */
|
|
30
|
+
viewName?: string;
|
|
31
|
+
getFieldOptions?: GetFieldOptions;
|
|
32
|
+
className?: string;
|
|
33
|
+
"data-size"?: FilterEditorSize;
|
|
34
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/es/index.d.ts
CHANGED
|
@@ -6,10 +6,11 @@ export { CardColumn, CardDetail, CardLabel, CardStep, CardStepList, ColorCard }
|
|
|
6
6
|
export { DateNavigator } from "./components/DateNavigator/index.js";
|
|
7
7
|
export * from "./components/FilePond.js";
|
|
8
8
|
export * from "./components/ImageEditor/index.js";
|
|
9
|
+
export { ChipListInput, type ChipListInputProps, FilterBuilder, type FilterBuilderProps, FilterEditor, type FilterEditorProps, type FilterEditorSize, FilterGroupEditor, type FilterGroupEditorProps, FilterNameDialog, type FilterNameDialogProps, FilterRow, type FilterRowProps, FilterShareDialog, type FilterShareDialogProps, FilterStringField, type FilterStringFieldProps, FilterValueEditor, type FilterValueEditorProps, type FilterValueOption, type GetFieldOptions, type SavedFilterSelection, type SavedFilterValues, SavedFilterTree, type SavedFilterTreeProps, } from "./filter/index.js";
|
|
9
10
|
export { Card, LinkedList, LinkedListItem } from "./components/LinkedCardList/index.js";
|
|
10
11
|
export { MergeProgressDialog, type MergeProgressDialogProps } from "./components/MergeProgressDialog/index.js";
|
|
12
|
+
export { ReportLauncher, type ReportLauncherProps, type ReportLauncherTab, ReportParameterField, ReportParameters, type ReportParametersProps, } from "./report/index.js";
|
|
11
13
|
export { BannerImage as PageBannerImage, type BannerImageProps, PageBanner, type PageBannerProps, Tab as PageBannerTab, TabList as PageBannerTabList, type TabListProps as PageBannerTabListProps, type TabProps as PageBannerTabProps, Title as PageBannerTitle, type TitleProps as PageBannerTitleProps, } from "./components/PageBanner/index.js";
|
|
12
|
-
export * from "./components/PdfViewer/index.js";
|
|
13
14
|
export { Portal } from "./components/Portal/index.js";
|
|
14
15
|
export { ToolbarBreadcrumbs, ToolbarPortal, type BreadcrumbItem, type ToolbarBreadcrumbsProps, type ToolbarPortalProps, type ToolbarPortalSlot, } from "./components/Toolbar/index.js";
|
|
15
16
|
export { ProgressBar } from "./components/ProgressBar/index.js";
|
package/es/index.js
CHANGED
|
@@ -6,10 +6,15 @@ export { CardColumn, CardDetail, CardLabel, CardStep, CardStepList, ColorCard }
|
|
|
6
6
|
export { DateNavigator } from "./components/DateNavigator/index.js";
|
|
7
7
|
export * from "./components/FilePond.js";
|
|
8
8
|
export * from "./components/ImageEditor/index.js";
|
|
9
|
+
export { ChipListInput, FilterBuilder, FilterEditor, FilterGroupEditor, FilterNameDialog, FilterRow, FilterShareDialog, FilterStringField, FilterValueEditor, SavedFilterTree, } from "./filter/index.js";
|
|
9
10
|
export { Card, LinkedList, LinkedListItem } from "./components/LinkedCardList/index.js";
|
|
10
11
|
export { MergeProgressDialog } from "./components/MergeProgressDialog/index.js";
|
|
12
|
+
export { ReportLauncher, ReportParameterField, ReportParameters, } from "./report/index.js";
|
|
11
13
|
export { BannerImage as PageBannerImage, PageBanner, Tab as PageBannerTab, TabList as PageBannerTabList, Title as PageBannerTitle, } from "./components/PageBanner/index.js";
|
|
12
|
-
|
|
14
|
+
// PdfViewer is intentionally not re-exported here. It references the pdf.js worker
|
|
15
|
+
// with `new URL(..., import.meta.url)`, which makes bundlers emit the 1.2 MB worker
|
|
16
|
+
// asset for every app that touches this barrel, even when no PDF is ever rendered.
|
|
17
|
+
// Import it from "@olenbetong/synergi-react/pdf" instead.
|
|
13
18
|
export { Portal } from "./components/Portal/index.js";
|
|
14
19
|
export { ToolbarBreadcrumbs, ToolbarPortal, } from "./components/Toolbar/index.js";
|
|
15
20
|
export { ProgressBar } from "./components/ProgressBar/index.js";
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
export type MuiThemeProviderProps = {
|
|
3
|
+
children: ReactNode;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Bridges Designsystemet's colour tokens into a MUI theme, so MUI components
|
|
7
|
+
* (most notably the data grid) follow Designsystemet instead of MUI defaults.
|
|
8
|
+
*
|
|
9
|
+
* This lives in a separate entry point (`@olenbetong/synergi-react/mui`) so apps
|
|
10
|
+
* that have migrated to Designsystemet don't pull ~160 kB of MUI and Emotion
|
|
11
|
+
* into their bundle just by using `AppShell`. Wrap `AppShell` with it in apps
|
|
12
|
+
* that still render MUI components:
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```tsx
|
|
16
|
+
* import { AppShell } from "@olenbetong/synergi-react";
|
|
17
|
+
* import { MuiThemeProvider } from "@olenbetong/synergi-react/mui";
|
|
18
|
+
*
|
|
19
|
+
* <MuiThemeProvider>
|
|
20
|
+
* <AppShell>{children}</AppShell>
|
|
21
|
+
* </MuiThemeProvider>
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function MuiThemeProvider({ children }: MuiThemeProviderProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { StyledEngineProvider, ThemeProvider } from "@mui/material";
|
|
3
|
+
import { createTheme as muiCreateTheme } from "@mui/material/styles";
|
|
4
|
+
import { useEffect, useState } from "react";
|
|
5
|
+
function getColorScheme() {
|
|
6
|
+
let scheme = document.body?.dataset.colorScheme ?? document.documentElement?.dataset.colorScheme ?? "light";
|
|
7
|
+
if (scheme === "auto") {
|
|
8
|
+
return globalThis.matchMedia?.("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
9
|
+
}
|
|
10
|
+
return scheme === "dark" ? "dark" : "light";
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Tracks the color scheme Designsystemet is rendering with. The article template
|
|
14
|
+
* sets `data-color-scheme` on `<body>`, so watch that attribute as well as the
|
|
15
|
+
* OS preference (used when the scheme is `auto`).
|
|
16
|
+
*/
|
|
17
|
+
function useColorScheme() {
|
|
18
|
+
let [scheme, setScheme] = useState(() => getColorScheme());
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
function update() {
|
|
21
|
+
setScheme(getColorScheme());
|
|
22
|
+
}
|
|
23
|
+
update();
|
|
24
|
+
let observer = new MutationObserver(update);
|
|
25
|
+
observer.observe(document.body, { attributes: true, attributeFilter: ["data-color-scheme"] });
|
|
26
|
+
observer.observe(document.documentElement, { attributes: true, attributeFilter: ["data-color-scheme"] });
|
|
27
|
+
let media = globalThis.matchMedia?.("(prefers-color-scheme: dark)");
|
|
28
|
+
media?.addEventListener("change", update);
|
|
29
|
+
return () => {
|
|
30
|
+
observer.disconnect();
|
|
31
|
+
media?.removeEventListener("change", update);
|
|
32
|
+
};
|
|
33
|
+
}, []);
|
|
34
|
+
return scheme;
|
|
35
|
+
}
|
|
36
|
+
function buildMuiTheme(mode) {
|
|
37
|
+
const s = getComputedStyle(document.body);
|
|
38
|
+
const get = (v) => s.getPropertyValue(v).trim();
|
|
39
|
+
const isDark = mode === "dark";
|
|
40
|
+
return muiCreateTheme({
|
|
41
|
+
palette: {
|
|
42
|
+
mode,
|
|
43
|
+
primary: {
|
|
44
|
+
main: get("--ds-color-brand-base-default") || "#116069",
|
|
45
|
+
dark: get("--ds-color-brand-base-hover") || "#0d4b52",
|
|
46
|
+
contrastText: get("--ds-color-brand-base-contrast-default") || "#ffffff",
|
|
47
|
+
},
|
|
48
|
+
secondary: {
|
|
49
|
+
main: get("--ds-color-brand-light-base-default") || "#1a95a2",
|
|
50
|
+
},
|
|
51
|
+
background: {
|
|
52
|
+
default: get("--ds-color-neutral-background-default") || (isDark ? "#17181a" : "#ffffff"),
|
|
53
|
+
paper: get("--ds-color-neutral-background-default") || (isDark ? "#17181a" : "#ffffff"),
|
|
54
|
+
},
|
|
55
|
+
text: {
|
|
56
|
+
primary: get("--ds-color-neutral-text-default") || (isDark ? "#e5e6e7" : "#292c30"),
|
|
57
|
+
secondary: get("--ds-color-neutral-text-subtle") || (isDark ? "#b3b5b7" : "#5b5f64"),
|
|
58
|
+
},
|
|
59
|
+
divider: get("--ds-color-neutral-border-subtle") || (isDark ? "#4e5052" : "#bbbcbd"),
|
|
60
|
+
},
|
|
61
|
+
typography: {
|
|
62
|
+
fontFamily: [
|
|
63
|
+
"-apple-system",
|
|
64
|
+
"BlinkMacSystemFont",
|
|
65
|
+
'"Segoe UI"',
|
|
66
|
+
"Roboto",
|
|
67
|
+
'"Helvetica Neue"',
|
|
68
|
+
"Arial",
|
|
69
|
+
"sans-serif",
|
|
70
|
+
'"Apple Color Emoji"',
|
|
71
|
+
'"Segoe UI Emoji"',
|
|
72
|
+
'"Segoe UI Symbol"',
|
|
73
|
+
].join(","),
|
|
74
|
+
},
|
|
75
|
+
components: {
|
|
76
|
+
MuiTypography: {
|
|
77
|
+
styleOverrides: {
|
|
78
|
+
h1: { fontSize: "2.488rem" },
|
|
79
|
+
h2: { fontSize: "2.074rem" },
|
|
80
|
+
h3: { fontSize: "1.728rem" },
|
|
81
|
+
h4: { fontSize: "1.44rem" },
|
|
82
|
+
h5: { fontSize: "1.2rem" },
|
|
83
|
+
h6: { fontSize: "1rem" },
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
MuiAppBar: {
|
|
87
|
+
styleOverrides: {
|
|
88
|
+
root: {
|
|
89
|
+
"& .MuiTypography-h1": {
|
|
90
|
+
fontSize: "1.25rem",
|
|
91
|
+
fontWeight: "500",
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
MuiButton: {
|
|
97
|
+
styleOverrides: {
|
|
98
|
+
root: { borderRadius: 2 },
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
MuiDialogTitle: {
|
|
102
|
+
styleOverrides: {
|
|
103
|
+
root: {
|
|
104
|
+
fontSize: "1.2rem",
|
|
105
|
+
fontWeight: 500,
|
|
106
|
+
paddingLeft: 16,
|
|
107
|
+
paddingRight: 16,
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
MuiFormLabel: {
|
|
112
|
+
styleOverrides: {
|
|
113
|
+
root: { color: get("--ds-color-neutral-text-subtle") || "rgba(0, 0, 0, 0.72)" },
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
MuiTextField: { defaultProps: { variant: "filled" } },
|
|
117
|
+
MuiSelect: { defaultProps: { variant: "filled" } },
|
|
118
|
+
MuiFormControl: { defaultProps: { variant: "filled" } },
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Bridges Designsystemet's colour tokens into a MUI theme, so MUI components
|
|
124
|
+
* (most notably the data grid) follow Designsystemet instead of MUI defaults.
|
|
125
|
+
*
|
|
126
|
+
* This lives in a separate entry point (`@olenbetong/synergi-react/mui`) so apps
|
|
127
|
+
* that have migrated to Designsystemet don't pull ~160 kB of MUI and Emotion
|
|
128
|
+
* into their bundle just by using `AppShell`. Wrap `AppShell` with it in apps
|
|
129
|
+
* that still render MUI components:
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```tsx
|
|
133
|
+
* import { AppShell } from "@olenbetong/synergi-react";
|
|
134
|
+
* import { MuiThemeProvider } from "@olenbetong/synergi-react/mui";
|
|
135
|
+
*
|
|
136
|
+
* <MuiThemeProvider>
|
|
137
|
+
* <AppShell>{children}</AppShell>
|
|
138
|
+
* </MuiThemeProvider>
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
export function MuiThemeProvider({ children }) {
|
|
142
|
+
const colorScheme = useColorScheme();
|
|
143
|
+
// Rebuilt whenever the color scheme changes so MUI components (notably the
|
|
144
|
+
// data grid) follow Designsystemet instead of staying stuck in light mode.
|
|
145
|
+
// Also re-read after mount, since the stylesheets are imported from JS and
|
|
146
|
+
// the CSS variables aren't necessarily resolved during the first render.
|
|
147
|
+
const [theme, setTheme] = useState(() => buildMuiTheme(colorScheme));
|
|
148
|
+
useEffect(() => {
|
|
149
|
+
setTheme(buildMuiTheme(colorScheme));
|
|
150
|
+
}, [colorScheme]);
|
|
151
|
+
return (_jsx(StyledEngineProvider, { injectFirst: true, children: _jsx(ThemeProvider, { theme: theme, children: children }) }));
|
|
152
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { MuiThemeProvider, type MuiThemeProviderProps } from "./MuiThemeProvider.js";
|
package/es/mui/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { MuiThemeProvider } from "./MuiThemeProvider.js";
|