@olenbetong/appframe-ds 1.5.0 → 1.6.1
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/CHANGELOG.md +22 -0
- package/package.json +17 -16
- package/scripts/copyAssets.mjs +27 -27
- package/src/AfLookup/Lookup.css +147 -130
- package/src/AfLookup/Lookup.tsx +186 -186
- package/src/AfLookup/LookupCombobox.css +69 -72
- package/src/AfLookup/LookupCombobox.tsx +273 -237
- package/src/AfLookup/LookupEdit.tsx +130 -130
- package/src/AfLookup/LookupGrid.css +145 -52
- package/src/AfLookup/LookupGrid.test.tsx +142 -0
- package/src/AfLookup/LookupGrid.tsx +324 -124
- package/src/AfLookup/index.ts +5 -5
- package/src/autocomplete/Autocomplete.css +253 -256
- package/src/autocomplete/Autocomplete.tsx +320 -320
- package/src/autocomplete/AutocompleteFrame.tsx +168 -168
- package/src/autocomplete/Combobox.tsx +286 -286
- package/src/autocomplete/index.ts +4 -4
- package/src/autocomplete/types.ts +204 -204
- package/src/autocomplete/utils.ts +183 -183
- package/src/binding/BoundNumberInput.tsx +42 -0
- package/src/binding/BoundNumericTextField.tsx +102 -102
- package/src/binding/BoundTextField.tsx +49 -49
- package/src/binding/CancelButton.tsx +30 -30
- package/src/binding/CancelIconButton.tsx +30 -30
- package/src/binding/DataEditToolbar.css +23 -23
- package/src/binding/DataEditToolbar.tsx +84 -84
- package/src/binding/DeleteButton.tsx +35 -35
- package/src/binding/DeleteIconButton.tsx +35 -35
- package/src/binding/RefreshButton.tsx +31 -31
- package/src/binding/RefreshIconButton.tsx +33 -33
- package/src/binding/RefreshRowIconButton.tsx +33 -33
- package/src/binding/SaveButton.tsx +37 -37
- package/src/binding/SaveIconButton.tsx +38 -38
- package/src/binding/index.ts +20 -19
- package/src/container/Container.tsx +50 -50
- package/src/container/index.ts +1 -1
- package/src/cutoff/CutOffPicker.css +12 -12
- package/src/cutoff/CutOffPicker.tsx +165 -165
- package/src/cutoff/context.tsx +194 -194
- package/src/cutoff/dsCutOffDates.ts +21 -21
- package/src/cutoff/index.ts +4 -4
- package/src/cutoff/utils.test.ts +59 -59
- package/src/cutoff/utils.ts +276 -276
- package/src/filter/ChipListInput.tsx +79 -79
- package/src/filter/FieldFilterPanel.css +150 -150
- package/src/filter/FieldFilterPanel.tsx +309 -309
- package/src/filter/FilterBuilder.css +152 -152
- package/src/filter/FilterBuilder.test.tsx +153 -153
- package/src/filter/FilterBuilder.tsx +435 -435
- package/src/filter/FilterEditor.css +231 -231
- package/src/filter/FilterEditor.test.tsx +285 -285
- package/src/filter/FilterEditor.tsx +75 -75
- package/src/filter/FilterGroupEditor.tsx +160 -160
- package/src/filter/FilterNameDialog.css +22 -22
- package/src/filter/FilterNameDialog.tsx +81 -81
- package/src/filter/FilterRow.tsx +117 -117
- package/src/filter/FilterShareDialog.css +28 -28
- package/src/filter/FilterShareDialog.tsx +201 -201
- package/src/filter/FilterStringField.tsx +78 -78
- package/src/filter/FilterValueEditor.tsx +239 -239
- package/src/filter/SavedFilterTree.css +107 -107
- package/src/filter/SavedFilterTree.test.tsx +94 -94
- package/src/filter/SavedFilterTree.tsx +218 -218
- package/src/filter/fieldFilter.test.ts +158 -158
- package/src/filter/fieldFilter.ts +139 -139
- package/src/filter/index.ts +27 -27
- package/src/filter/types.ts +38 -38
- package/src/filter/useDistinctValues.test.ts +102 -102
- package/src/filter/useDistinctValues.ts +230 -230
- package/src/global.d.ts +11 -11
- package/src/grid/formatters.ts +23 -0
- package/src/grid/useAfColumns.tsx +28 -4
- package/src/grid/utcDate.test.ts +25 -0
- package/src/grid/utcDate.ts +28 -0
- package/src/grid/utcDateEditing.tsx +11 -0
- package/src/i18n.ts +13 -13
- package/src/index.ts +14 -14
- package/src/input/InputAdornments.css +80 -84
- package/src/input/InputAdornments.tsx +102 -102
- package/src/input/NumberInput.css +9 -0
- package/src/input/NumberInput.test.tsx +212 -0
- package/src/input/NumberInput.tsx +268 -0
- package/src/input/index.ts +3 -1
- package/src/input/numberFormat.test.ts +79 -0
- package/src/input/numberFormat.ts +94 -0
- package/src/layout/AppMenu.tsx +74 -74
- package/src/layout/AppMenuDrawer.css +71 -71
- package/src/layout/AppMenuDrawer.tsx +122 -122
- package/src/layout/DialogMotion.css +79 -79
- package/src/layout/ErrorBoundary.tsx +162 -162
- package/src/layout/PageContainer.css +48 -48
- package/src/layout/PageContainer.tsx +41 -41
- package/src/layout/ResponsiveDialog.css +86 -86
- package/src/layout/ResponsiveDialog.tsx +55 -55
- package/src/layout/index.tsx +70 -70
- package/src/link/Link.tsx +23 -23
- package/src/link/index.ts +1 -1
- package/src/mdi/Mdi.css +138 -138
- package/src/mdi/Mdi.test.tsx +91 -91
- package/src/mdi/Mdi.tsx +141 -141
- package/src/mdi/MdiConfirmCloseDialog.tsx +47 -47
- package/src/mdi/MdiContext.tsx +59 -59
- package/src/mdi/MdiDocumentContext.tsx +60 -60
- package/src/mdi/MdiPanel.tsx +61 -61
- package/src/mdi/MdiRestore.test.tsx +86 -86
- package/src/mdi/MdiTab.tsx +30 -30
- package/src/mdi/controller.test.ts +382 -382
- package/src/mdi/controller.ts +656 -656
- package/src/mdi/dockviewHost.ts +132 -132
- package/src/mdi/fakeHost.ts +200 -200
- package/src/mdi/host.ts +44 -44
- package/src/mdi/ids.test.ts +20 -20
- package/src/mdi/ids.ts +18 -18
- package/src/mdi/index.ts +31 -31
- package/src/mdi/layoutRestore.test.ts +156 -156
- package/src/mdi/layoutRestore.ts +311 -311
- package/src/mdi/layoutSpec.test.ts +143 -143
- package/src/mdi/layoutSpec.ts +214 -214
- package/src/mdi/layoutStore.test.ts +93 -93
- package/src/mdi/layoutStore.ts +99 -99
- package/src/mdi/memorySettingsStore.ts +21 -21
- package/src/mdi/registry.ts +34 -34
- package/src/mdi/testTypes.ts +37 -37
- package/src/mdi/theme.ts +22 -22
- package/src/mdi/types.ts +214 -214
- package/src/page/Page.css +57 -57
- package/src/page/PageBlock.css +64 -64
- package/src/page/PageBlock.tsx +93 -93
- package/src/page/PageHeader.css +88 -88
- package/src/page/PageHeader.tsx +115 -115
- package/src/page/PageTitle.css +5 -5
- package/src/page/PageTitle.tsx +21 -21
- package/src/page/index.ts +4 -4
- package/src/paper/Paper.tsx +52 -52
- package/src/progress/LinearProgress.css +121 -93
- package/src/progress/LinearProgress.tsx +106 -104
- package/src/progress/index.ts +1 -1
- package/src/report-downloader/ReportDownloader.css +67 -67
- package/src/report-downloader/components/StatusItem.tsx +87 -87
- package/src/report-downloader/components/StatusList.tsx +28 -28
- package/src/report-downloader/index.ts +41 -41
- package/src/report-downloader/status.tsx +92 -92
- package/src/sortable/DropIndicator.css +51 -51
- package/src/sortable/DropIndicator.tsx +27 -27
- package/src/sortable/SortableItemList.css +21 -21
- package/src/sortable/SortableItemList.tsx +264 -264
- package/src/sortable/index.ts +8 -8
- package/src/sortable/reorderSortOrder.ts +126 -126
- package/src/sortable/sortOrder.ts +101 -101
- package/src/sortable/types.ts +9 -9
- package/src/sortable/useSortableContainer.ts +53 -53
- package/src/sortable/useSortableItem.ts +95 -95
- package/src/sortable/useSortableList.ts +117 -117
- package/src/test/happy-dom-document-class.ts +24 -24
- package/src/test/setup.ts +27 -12
- package/src/theme/useDsColorScheme.ts +53 -53
- package/tsconfig.build.json +9 -9
- package/tsconfig.json +8 -8
- package/vitest.config.ts +10 -10
|
@@ -1,130 +1,130 @@
|
|
|
1
|
-
import "./Lookup.css";
|
|
2
|
-
|
|
3
|
-
import { Button, Textfield, type TextfieldProps } from "@digdir/designsystemet-react";
|
|
4
|
-
import { MagnifyingGlassIcon, XMarkIcon } from "@navikt/aksel-icons";
|
|
5
|
-
import type { DistributiveOmit } from "@olenbetong/appframe-react";
|
|
6
|
-
|
|
7
|
-
import clsx from "clsx";
|
|
8
|
-
import type React from "react";
|
|
9
|
-
|
|
10
|
-
import type { LookupComboboxProps } from "./LookupCombobox.js";
|
|
11
|
-
import { useLookup } from "./Lookup.js";
|
|
12
|
-
import { getLocalizedString } from "../i18n.js";
|
|
13
|
-
|
|
14
|
-
export type AfLookupEditProps<T extends Record<string, unknown>> = DistributiveOmit<
|
|
15
|
-
LookupComboboxProps<T>,
|
|
16
|
-
"value" | "onChange"
|
|
17
|
-
> & {
|
|
18
|
-
/**
|
|
19
|
-
* Allows the user to enter a value manually that might not be in the list.
|
|
20
|
-
*/
|
|
21
|
-
editable?: boolean;
|
|
22
|
-
fullWidth?: boolean;
|
|
23
|
-
label?: string;
|
|
24
|
-
value?: string | null;
|
|
25
|
-
lookupField: keyof T;
|
|
26
|
-
onChange?: (evt: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => void;
|
|
27
|
-
slotProps?: {
|
|
28
|
-
dialog?: Partial<React.HTMLProps<HTMLDialogElement>>;
|
|
29
|
-
textField?: Partial<TextfieldProps>;
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export function AfLookupEdit<T extends Record<string, unknown>>({
|
|
34
|
-
fullWidth = false,
|
|
35
|
-
label,
|
|
36
|
-
onChange,
|
|
37
|
-
slotProps,
|
|
38
|
-
nullable,
|
|
39
|
-
lookupField,
|
|
40
|
-
value,
|
|
41
|
-
...props
|
|
42
|
-
}: AfLookupEditProps<T>) {
|
|
43
|
-
let { inputId, dialog, anchorName, openDialog, onKeyDown } = useLookup<T>({
|
|
44
|
-
...props,
|
|
45
|
-
nullable,
|
|
46
|
-
slotProps: { dialog: slotProps?.dialog },
|
|
47
|
-
onChange: (item) => applyValue(item),
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
// The popup selects a single value from the dataset: the item's lookupField
|
|
51
|
-
// is written to the input through the native value setter so the same
|
|
52
|
-
// change event fires whether the user types or picks from the list/grid.
|
|
53
|
-
function applyValue(item: T | null) {
|
|
54
|
-
let input = document.getElementById(inputId) as HTMLInputElement;
|
|
55
|
-
let nativeInputValueSetter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, "value")?.set;
|
|
56
|
-
|
|
57
|
-
if (input && nativeInputValueSetter) {
|
|
58
|
-
nativeInputValueSetter.call(input, item ? String(item[lookupField]) : "");
|
|
59
|
-
input.dispatchEvent(new Event("input", { bubbles: true }));
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function handleKeyDown(event: React.KeyboardEvent<HTMLElement>) {
|
|
64
|
-
if (event.key === "Enter") {
|
|
65
|
-
event.preventDefault();
|
|
66
|
-
event.stopPropagation();
|
|
67
|
-
openDialog();
|
|
68
|
-
} else {
|
|
69
|
-
onKeyDown(event);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
let hasClear = !!(nullable && value && onChange);
|
|
74
|
-
|
|
75
|
-
return (
|
|
76
|
-
<div style={{ anchorName } as React.CSSProperties}>
|
|
77
|
-
<div
|
|
78
|
-
className="ObLookup-inputWrap"
|
|
79
|
-
style={
|
|
80
|
-
{
|
|
81
|
-
display: fullWidth ? "block" : "inline-block",
|
|
82
|
-
"--ObLookup-buttons-width": hasClear ? "5.5rem" : "3rem",
|
|
83
|
-
} as React.CSSProperties
|
|
84
|
-
}
|
|
85
|
-
>
|
|
86
|
-
<Textfield
|
|
87
|
-
id={inputId}
|
|
88
|
-
value={value ?? ""}
|
|
89
|
-
label={label}
|
|
90
|
-
onChange={onChange}
|
|
91
|
-
onKeyDown={handleKeyDown}
|
|
92
|
-
className={clsx(slotProps?.textField?.className, "ObLookup-input")}
|
|
93
|
-
{...(slotProps?.textField as any)}
|
|
94
|
-
style={{ width: fullWidth ? "100%" : undefined, ...slotProps?.textField?.style }}
|
|
95
|
-
/>
|
|
96
|
-
<div className="ObLookup-buttons">
|
|
97
|
-
{hasClear && (
|
|
98
|
-
<Button
|
|
99
|
-
icon
|
|
100
|
-
variant="tertiary"
|
|
101
|
-
data-size="sm"
|
|
102
|
-
aria-label={getLocalizedString("Clear")}
|
|
103
|
-
onKeyDown={(evt) => evt.stopPropagation()}
|
|
104
|
-
onClick={(evt) => {
|
|
105
|
-
evt.stopPropagation();
|
|
106
|
-
applyValue(null);
|
|
107
|
-
document.getElementById(inputId)?.focus();
|
|
108
|
-
}}
|
|
109
|
-
>
|
|
110
|
-
<XMarkIcon />
|
|
111
|
-
</Button>
|
|
112
|
-
)}
|
|
113
|
-
<Button
|
|
114
|
-
icon
|
|
115
|
-
variant="tertiary"
|
|
116
|
-
data-size="sm"
|
|
117
|
-
aria-label={getLocalizedString("Search")}
|
|
118
|
-
onClick={(evt) => {
|
|
119
|
-
evt.stopPropagation();
|
|
120
|
-
openDialog();
|
|
121
|
-
}}
|
|
122
|
-
>
|
|
123
|
-
<MagnifyingGlassIcon />
|
|
124
|
-
</Button>
|
|
125
|
-
</div>
|
|
126
|
-
</div>
|
|
127
|
-
{dialog}
|
|
128
|
-
</div>
|
|
129
|
-
);
|
|
130
|
-
}
|
|
1
|
+
import "./Lookup.css";
|
|
2
|
+
|
|
3
|
+
import { Button, Textfield, type TextfieldProps } from "@digdir/designsystemet-react";
|
|
4
|
+
import { MagnifyingGlassIcon, XMarkIcon } from "@navikt/aksel-icons";
|
|
5
|
+
import type { DistributiveOmit } from "@olenbetong/appframe-react";
|
|
6
|
+
|
|
7
|
+
import clsx from "clsx";
|
|
8
|
+
import type React from "react";
|
|
9
|
+
|
|
10
|
+
import type { LookupComboboxProps } from "./LookupCombobox.js";
|
|
11
|
+
import { useLookup } from "./Lookup.js";
|
|
12
|
+
import { getLocalizedString } from "../i18n.js";
|
|
13
|
+
|
|
14
|
+
export type AfLookupEditProps<T extends Record<string, unknown>> = DistributiveOmit<
|
|
15
|
+
LookupComboboxProps<T>,
|
|
16
|
+
"value" | "onChange"
|
|
17
|
+
> & {
|
|
18
|
+
/**
|
|
19
|
+
* Allows the user to enter a value manually that might not be in the list.
|
|
20
|
+
*/
|
|
21
|
+
editable?: boolean;
|
|
22
|
+
fullWidth?: boolean;
|
|
23
|
+
label?: string;
|
|
24
|
+
value?: string | null;
|
|
25
|
+
lookupField: keyof T;
|
|
26
|
+
onChange?: (evt: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => void;
|
|
27
|
+
slotProps?: {
|
|
28
|
+
dialog?: Partial<React.HTMLProps<HTMLDialogElement>>;
|
|
29
|
+
textField?: Partial<TextfieldProps>;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export function AfLookupEdit<T extends Record<string, unknown>>({
|
|
34
|
+
fullWidth = false,
|
|
35
|
+
label,
|
|
36
|
+
onChange,
|
|
37
|
+
slotProps,
|
|
38
|
+
nullable,
|
|
39
|
+
lookupField,
|
|
40
|
+
value,
|
|
41
|
+
...props
|
|
42
|
+
}: AfLookupEditProps<T>) {
|
|
43
|
+
let { inputId, dialog, anchorName, openDialog, onKeyDown } = useLookup<T>({
|
|
44
|
+
...props,
|
|
45
|
+
nullable,
|
|
46
|
+
slotProps: { dialog: slotProps?.dialog },
|
|
47
|
+
onChange: (item) => applyValue(item),
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
// The popup selects a single value from the dataset: the item's lookupField
|
|
51
|
+
// is written to the input through the native value setter so the same
|
|
52
|
+
// change event fires whether the user types or picks from the list/grid.
|
|
53
|
+
function applyValue(item: T | null) {
|
|
54
|
+
let input = document.getElementById(inputId) as HTMLInputElement;
|
|
55
|
+
let nativeInputValueSetter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, "value")?.set;
|
|
56
|
+
|
|
57
|
+
if (input && nativeInputValueSetter) {
|
|
58
|
+
nativeInputValueSetter.call(input, item ? String(item[lookupField]) : "");
|
|
59
|
+
input.dispatchEvent(new Event("input", { bubbles: true }));
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function handleKeyDown(event: React.KeyboardEvent<HTMLElement>) {
|
|
64
|
+
if (event.key === "Enter") {
|
|
65
|
+
event.preventDefault();
|
|
66
|
+
event.stopPropagation();
|
|
67
|
+
openDialog();
|
|
68
|
+
} else {
|
|
69
|
+
onKeyDown(event);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
let hasClear = !!(nullable && value && onChange);
|
|
74
|
+
|
|
75
|
+
return (
|
|
76
|
+
<div style={{ anchorName } as React.CSSProperties}>
|
|
77
|
+
<div
|
|
78
|
+
className="ObLookup-inputWrap"
|
|
79
|
+
style={
|
|
80
|
+
{
|
|
81
|
+
display: fullWidth ? "block" : "inline-block",
|
|
82
|
+
"--ObLookup-buttons-width": hasClear ? "5.5rem" : "3rem",
|
|
83
|
+
} as React.CSSProperties
|
|
84
|
+
}
|
|
85
|
+
>
|
|
86
|
+
<Textfield
|
|
87
|
+
id={inputId}
|
|
88
|
+
value={value ?? ""}
|
|
89
|
+
label={label}
|
|
90
|
+
onChange={onChange}
|
|
91
|
+
onKeyDown={handleKeyDown}
|
|
92
|
+
className={clsx(slotProps?.textField?.className, "ObLookup-input")}
|
|
93
|
+
{...(slotProps?.textField as any)}
|
|
94
|
+
style={{ width: fullWidth ? "100%" : undefined, ...slotProps?.textField?.style }}
|
|
95
|
+
/>
|
|
96
|
+
<div className="ObLookup-buttons">
|
|
97
|
+
{hasClear && (
|
|
98
|
+
<Button
|
|
99
|
+
icon
|
|
100
|
+
variant="tertiary"
|
|
101
|
+
data-size="sm"
|
|
102
|
+
aria-label={getLocalizedString("Clear")}
|
|
103
|
+
onKeyDown={(evt) => evt.stopPropagation()}
|
|
104
|
+
onClick={(evt) => {
|
|
105
|
+
evt.stopPropagation();
|
|
106
|
+
applyValue(null);
|
|
107
|
+
document.getElementById(inputId)?.focus();
|
|
108
|
+
}}
|
|
109
|
+
>
|
|
110
|
+
<XMarkIcon />
|
|
111
|
+
</Button>
|
|
112
|
+
)}
|
|
113
|
+
<Button
|
|
114
|
+
icon
|
|
115
|
+
variant="tertiary"
|
|
116
|
+
data-size="sm"
|
|
117
|
+
aria-label={getLocalizedString("Search")}
|
|
118
|
+
onClick={(evt) => {
|
|
119
|
+
evt.stopPropagation();
|
|
120
|
+
openDialog();
|
|
121
|
+
}}
|
|
122
|
+
>
|
|
123
|
+
<MagnifyingGlassIcon />
|
|
124
|
+
</Button>
|
|
125
|
+
</div>
|
|
126
|
+
</div>
|
|
127
|
+
{dialog}
|
|
128
|
+
</div>
|
|
129
|
+
);
|
|
130
|
+
}
|
|
@@ -1,52 +1,145 @@
|
|
|
1
|
-
.ObLookupGrid-root {
|
|
2
|
-
height: 100%;
|
|
3
|
-
overflow: hidden;
|
|
4
|
-
overscroll-behavior: contain;
|
|
5
|
-
border: 1px solid var(--ds-color-neutral-border-subtle);
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
overflow:
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
1
|
+
.ObLookupGrid-root {
|
|
2
|
+
height: 100%;
|
|
3
|
+
overflow: hidden;
|
|
4
|
+
overscroll-behavior: contain;
|
|
5
|
+
border: 1px solid var(--ds-color-neutral-border-subtle);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/* No text selection while a column is being dragged */
|
|
9
|
+
.ObLookupGrid-root[data-resizing] {
|
|
10
|
+
user-select: none;
|
|
11
|
+
cursor: col-resize;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/*
|
|
15
|
+
* The header does not scroll itself: the list is the only scroll container, and the header
|
|
16
|
+
* row inside is moved sideways with a transform to follow it.
|
|
17
|
+
*/
|
|
18
|
+
.ObLookupGrid-header {
|
|
19
|
+
height: 40px;
|
|
20
|
+
overflow: hidden;
|
|
21
|
+
border-bottom: 1px solid var(--ds-color-neutral-border-default);
|
|
22
|
+
background-color: var(--ds-color-neutral-background-tinted);
|
|
23
|
+
font-weight: 600;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.ObLookupGrid-headerRow {
|
|
27
|
+
display: grid;
|
|
28
|
+
align-items: center;
|
|
29
|
+
height: 100%;
|
|
30
|
+
box-sizing: border-box;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.ObLookupGrid-headerCell {
|
|
34
|
+
position: relative;
|
|
35
|
+
display: flex;
|
|
36
|
+
align-items: center;
|
|
37
|
+
height: 100%;
|
|
38
|
+
padding: 0 8px;
|
|
39
|
+
overflow: hidden;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.ObLookupGrid-headerText {
|
|
43
|
+
overflow: hidden;
|
|
44
|
+
text-overflow: ellipsis;
|
|
45
|
+
white-space: nowrap;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/* A sortable header: the whole cell text is the button, the arrow shows on hover and when sorted */
|
|
49
|
+
.ObLookupGrid-sortButton {
|
|
50
|
+
display: flex;
|
|
51
|
+
align-items: center;
|
|
52
|
+
gap: var(--ds-size-1, 0.25rem);
|
|
53
|
+
min-width: 0;
|
|
54
|
+
max-width: 100%;
|
|
55
|
+
padding: 0;
|
|
56
|
+
border: 0;
|
|
57
|
+
background: none;
|
|
58
|
+
color: inherit;
|
|
59
|
+
font: inherit;
|
|
60
|
+
cursor: pointer;
|
|
61
|
+
text-align: start;
|
|
62
|
+
|
|
63
|
+
.ObLookupGrid-sortIcon {
|
|
64
|
+
flex-shrink: 0;
|
|
65
|
+
font-size: 1.125em;
|
|
66
|
+
opacity: 0;
|
|
67
|
+
transition: opacity 0.15s ease-out;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
&:hover .ObLookupGrid-sortIcon {
|
|
71
|
+
opacity: 0.5;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
&.sorted .ObLookupGrid-sortIcon {
|
|
75
|
+
opacity: 1;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/* The drag handle: a wide hit area at the end of the cell with a thin line drawn in it */
|
|
80
|
+
.ObLookupGrid-resizer {
|
|
81
|
+
position: absolute;
|
|
82
|
+
inset-block: 0;
|
|
83
|
+
inset-inline-end: 0;
|
|
84
|
+
width: 9px;
|
|
85
|
+
cursor: col-resize;
|
|
86
|
+
touch-action: none;
|
|
87
|
+
|
|
88
|
+
&::after {
|
|
89
|
+
content: "";
|
|
90
|
+
position: absolute;
|
|
91
|
+
inset-block: 25%;
|
|
92
|
+
inset-inline-end: 4px;
|
|
93
|
+
width: 1px;
|
|
94
|
+
background-color: var(--ds-color-neutral-border-default);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
&:hover::after {
|
|
98
|
+
inset-block: 15%;
|
|
99
|
+
width: 2px;
|
|
100
|
+
background-color: var(--ds-color-neutral-border-strong);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/* Keeps the client width stable whether or not there are enough rows for a scrollbar */
|
|
105
|
+
.ObLookupGrid-list {
|
|
106
|
+
scrollbar-gutter: stable;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
.ObLookupGrid-row {
|
|
110
|
+
display: grid;
|
|
111
|
+
align-items: center;
|
|
112
|
+
box-sizing: border-box;
|
|
113
|
+
cursor: pointer;
|
|
114
|
+
border-bottom: 1px solid var(--ds-color-neutral-border-subtle);
|
|
115
|
+
|
|
116
|
+
&.active {
|
|
117
|
+
background-color: var(--ds-color-neutral-surface-active);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
&:hover {
|
|
121
|
+
background-color: var(--ds-color-neutral-surface-hover);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
.ObLookupGrid-cell {
|
|
126
|
+
padding: 0 8px;
|
|
127
|
+
height: 100%;
|
|
128
|
+
display: flex;
|
|
129
|
+
align-items: center;
|
|
130
|
+
overflow: hidden;
|
|
131
|
+
white-space: nowrap;
|
|
132
|
+
|
|
133
|
+
&.active {
|
|
134
|
+
outline: 2px solid var(--ds-color-neutral-border-strong);
|
|
135
|
+
outline-offset: -2px;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/* text-overflow does not apply to text directly inside a flex container, so it sits on this span */
|
|
140
|
+
.ObLookupGrid-cellText {
|
|
141
|
+
min-width: 0;
|
|
142
|
+
overflow: hidden;
|
|
143
|
+
text-overflow: ellipsis;
|
|
144
|
+
white-space: nowrap;
|
|
145
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import type { LookupColumn } from "@olenbetong/appframe-react";
|
|
2
|
+
import { fireEvent, render, screen } from "@testing-library/react";
|
|
3
|
+
import { beforeAll, describe, expect, it, vi } from "vitest";
|
|
4
|
+
|
|
5
|
+
import { LookupGrid } from "./LookupGrid.js";
|
|
6
|
+
|
|
7
|
+
type Row = { PrimKey: string; Name: string; Code: string };
|
|
8
|
+
|
|
9
|
+
const COLUMNS: LookupColumn<Row>[] = [
|
|
10
|
+
{ field: "Code", headerName: "Code", width: 100 },
|
|
11
|
+
{ field: "Name", headerName: "Name" },
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
const DATA: Row[] = [
|
|
15
|
+
{ PrimKey: "1", Code: "A", Name: "Alpha" },
|
|
16
|
+
{ PrimKey: "2", Code: "B", Name: "Beta" },
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
function renderGrid(props: Partial<React.ComponentProps<typeof LookupGrid<Row>>> = {}) {
|
|
20
|
+
return render(
|
|
21
|
+
<LookupGrid<Row>
|
|
22
|
+
columns={COLUMNS}
|
|
23
|
+
data={DATA}
|
|
24
|
+
height={300}
|
|
25
|
+
currentIndex={0}
|
|
26
|
+
currentColumn={0}
|
|
27
|
+
getItemId={(item) => item?.PrimKey}
|
|
28
|
+
onSelectItem={() => undefined}
|
|
29
|
+
{...props}
|
|
30
|
+
/>,
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function headerRow() {
|
|
35
|
+
return screen.getByRole("grid").querySelector(".ObLookupGrid-headerRow") as HTMLElement;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
beforeAll(() => {
|
|
39
|
+
// happy-dom has no pointer capture; the handle only checks that it holds it during a drag
|
|
40
|
+
let captured = new WeakMap<Element, number>();
|
|
41
|
+
Element.prototype.setPointerCapture = function (id: number) {
|
|
42
|
+
captured.set(this, id);
|
|
43
|
+
};
|
|
44
|
+
Element.prototype.hasPointerCapture = function (id: number) {
|
|
45
|
+
return captured.get(this) === id;
|
|
46
|
+
};
|
|
47
|
+
Element.prototype.releasePointerCapture = function () {
|
|
48
|
+
captured.delete(this);
|
|
49
|
+
};
|
|
50
|
+
if (typeof ResizeObserver === "undefined") {
|
|
51
|
+
globalThis.ResizeObserver = class {
|
|
52
|
+
observe() {}
|
|
53
|
+
unobserve() {}
|
|
54
|
+
disconnect() {}
|
|
55
|
+
} as never;
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
describe("LookupGrid", () => {
|
|
60
|
+
it("lays the header out with the configured column tracks", () => {
|
|
61
|
+
renderGrid();
|
|
62
|
+
|
|
63
|
+
expect(headerRow().style.gridTemplateColumns).toBe("100px minmax(80px, 1fr)");
|
|
64
|
+
expect(headerRow().style.minWidth).toBe("180px");
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("moves the header sideways with the list", () => {
|
|
68
|
+
renderGrid();
|
|
69
|
+
|
|
70
|
+
let list = screen.getByRole("rowgroup");
|
|
71
|
+
list.scrollLeft = 37;
|
|
72
|
+
fireEvent.scroll(list);
|
|
73
|
+
|
|
74
|
+
expect(headerRow().style.transform).toBe("translateX(-37px)");
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("resizes a column by dragging its handle, and resets it on double click", () => {
|
|
78
|
+
renderGrid();
|
|
79
|
+
|
|
80
|
+
let [handle] = screen.getAllByRole("separator", { name: "Resize column" });
|
|
81
|
+
let cell = handle.parentElement as HTMLElement;
|
|
82
|
+
vi.spyOn(cell, "getBoundingClientRect").mockReturnValue({ width: 100 } as DOMRect);
|
|
83
|
+
|
|
84
|
+
fireEvent.pointerDown(handle, { button: 0, pointerId: 1, clientX: 200 });
|
|
85
|
+
fireEvent.pointerMove(handle, { pointerId: 1, clientX: 250 });
|
|
86
|
+
expect(headerRow().style.gridTemplateColumns).toBe("150px minmax(80px, 1fr)");
|
|
87
|
+
expect(headerRow().style.minWidth).toBe("230px");
|
|
88
|
+
|
|
89
|
+
fireEvent.pointerMove(handle, { pointerId: 1, clientX: 0 });
|
|
90
|
+
expect(headerRow().style.gridTemplateColumns).toBe("80px minmax(80px, 1fr)");
|
|
91
|
+
|
|
92
|
+
fireEvent.pointerUp(handle, { pointerId: 1, clientX: 0 });
|
|
93
|
+
expect(screen.getByRole("grid")).not.toHaveAttribute("data-resizing");
|
|
94
|
+
|
|
95
|
+
fireEvent.doubleClick(handle);
|
|
96
|
+
expect(headerRow().style.gridTemplateColumns).toBe("100px minmax(80px, 1fr)");
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("renders plain headers when there is no sort handler", () => {
|
|
100
|
+
renderGrid();
|
|
101
|
+
|
|
102
|
+
expect(screen.queryByRole("button", { name: "Code" })).toBeNull();
|
|
103
|
+
expect(screen.getByRole("columnheader", { name: /^Code/ })).not.toHaveAttribute("aria-sort");
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("sorts on a header click, marks the sorted column and keeps the focus where it is", () => {
|
|
107
|
+
let onSort = vi.fn();
|
|
108
|
+
renderGrid({ onSort, sort: { field: "Name", direction: "desc" } });
|
|
109
|
+
|
|
110
|
+
expect(screen.getByRole("columnheader", { name: /^Name/ })).toHaveAttribute("aria-sort", "descending");
|
|
111
|
+
expect(screen.getByRole("columnheader", { name: /^Code/ })).not.toHaveAttribute("aria-sort");
|
|
112
|
+
|
|
113
|
+
let button = screen.getByRole("button", { name: "Code" });
|
|
114
|
+
let mouseDown = fireEvent.mouseDown(button);
|
|
115
|
+
expect(mouseDown).toBe(false);
|
|
116
|
+
|
|
117
|
+
fireEvent.click(button);
|
|
118
|
+
expect(onSort).toHaveBeenCalledWith("Code");
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it("leaves a column marked sortable: false as plain text", () => {
|
|
122
|
+
renderGrid({
|
|
123
|
+
onSort: vi.fn(),
|
|
124
|
+
columns: [
|
|
125
|
+
{ field: "Code", headerName: "Code", sortable: false },
|
|
126
|
+
{ field: "Name", headerName: "Name" },
|
|
127
|
+
],
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
expect(screen.queryByRole("button", { name: "Code" })).toBeNull();
|
|
131
|
+
expect(screen.getByRole("button", { name: "Name" })).toBeInTheDocument();
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it("ignores moves that are not part of a drag", () => {
|
|
135
|
+
renderGrid();
|
|
136
|
+
|
|
137
|
+
let [handle] = screen.getAllByRole("separator", { name: "Resize column" });
|
|
138
|
+
fireEvent.pointerMove(handle, { pointerId: 1, clientX: 250 });
|
|
139
|
+
|
|
140
|
+
expect(headerRow().style.gridTemplateColumns).toBe("100px minmax(80px, 1fr)");
|
|
141
|
+
});
|
|
142
|
+
});
|