@linzjs/step-ag-grid 17.3.0 → 17.4.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/dist/GridTheme.scss +12 -2
- package/dist/index.css +16 -0
- package/dist/src/components/Grid.d.ts +2 -1
- package/dist/step-ag-grid.cjs.js +22 -6
- package/dist/step-ag-grid.cjs.js.map +1 -1
- package/dist/step-ag-grid.esm.js +22 -6
- package/dist/step-ag-grid.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Grid.tsx +30 -6
- package/src/react-menu3/components/ControlledMenu.tsx +5 -1
- package/src/stories/grid/GridDragRow.stories.tsx +121 -0
- package/src/styles/Grid.scss +19 -0
- package/src/styles/GridTheme.scss +12 -2
package/package.json
CHANGED
package/src/components/Grid.tsx
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
CellEvent,
|
|
7
7
|
CellKeyDownEvent,
|
|
8
8
|
GridReadyEvent,
|
|
9
|
+
RowDragEndEvent,
|
|
9
10
|
SelectionChangedEvent,
|
|
10
11
|
} from "ag-grid-community/dist/lib/events";
|
|
11
12
|
import { AgGridReact } from "ag-grid-react";
|
|
@@ -42,13 +43,14 @@ export interface GridProps {
|
|
|
42
43
|
*/
|
|
43
44
|
selectColumnPinned?: ColDef["pinned"];
|
|
44
45
|
noRowsOverlayText?: string;
|
|
45
|
-
postSortRows?: GridOptions["postSortRows"];
|
|
46
46
|
animateRows?: boolean;
|
|
47
47
|
rowHeight?: number;
|
|
48
48
|
rowClassRules?: GridOptions["rowClassRules"];
|
|
49
49
|
rowSelection?: "single" | "multiple";
|
|
50
50
|
autoSelectFirstRow?: boolean;
|
|
51
51
|
onColumnMoved?: GridOptions["onColumnMoved"];
|
|
52
|
+
rowDragText?: GridOptions["rowDragText"];
|
|
53
|
+
onRowDragEnd?: (movedRow: any, targetRow: any, targetIndex: number) => void;
|
|
52
54
|
alwaysShowVerticalScroll?: boolean;
|
|
53
55
|
suppressColumnVirtualization?: GridOptions["suppressColumnVirtualisation"];
|
|
54
56
|
/**
|
|
@@ -322,20 +324,24 @@ export const Grid = ({
|
|
|
322
324
|
},
|
|
323
325
|
};
|
|
324
326
|
});
|
|
325
|
-
|
|
327
|
+
|
|
328
|
+
return params.selectable || params.onRowDragEnd
|
|
326
329
|
? [
|
|
327
330
|
{
|
|
328
331
|
colId: "selection",
|
|
329
332
|
editable: false,
|
|
330
|
-
|
|
331
|
-
|
|
333
|
+
rowDrag: !!params.onRowDragEnd,
|
|
334
|
+
minWidth: params.selectable && params.onRowDragEnd ? 76 : 48,
|
|
335
|
+
maxWidth: params.selectable && params.onRowDragEnd ? 76 : 48,
|
|
332
336
|
pinned: selectColumnPinned,
|
|
333
337
|
headerComponentParams: {
|
|
334
338
|
exportable: false,
|
|
335
339
|
},
|
|
336
|
-
checkboxSelection:
|
|
340
|
+
checkboxSelection: params.selectable,
|
|
337
341
|
headerComponent: rowSelection === "multiple" ? GridHeaderSelect : null,
|
|
342
|
+
//headerCheckboxSelection:true,
|
|
338
343
|
suppressHeaderKeyboardEvent: (e) => {
|
|
344
|
+
if (!params.selectable) return false;
|
|
339
345
|
if ((e.event.key === "Enter" || e.event.key === " ") && !e.event.repeat) {
|
|
340
346
|
if (isEmpty(e.api.getSelectedRows())) {
|
|
341
347
|
e.api.selectAllFiltered();
|
|
@@ -354,6 +360,7 @@ export const Grid = ({
|
|
|
354
360
|
}, [
|
|
355
361
|
params.columnDefs,
|
|
356
362
|
params.selectable,
|
|
363
|
+
params.onRowDragEnd,
|
|
357
364
|
params.readOnly,
|
|
358
365
|
params.defaultColDef?.editable,
|
|
359
366
|
selectColumnPinned,
|
|
@@ -583,6 +590,19 @@ export const Grid = ({
|
|
|
583
590
|
|
|
584
591
|
const gridContextMenu = useGridContextMenu({ contextMenu: params.contextMenu, contextMenuSelectRow });
|
|
585
592
|
|
|
593
|
+
const onRowDragEnd = useCallback(
|
|
594
|
+
(event: RowDragEndEvent) => {
|
|
595
|
+
const moved = event.node.data;
|
|
596
|
+
const target = event.overNode?.data;
|
|
597
|
+
|
|
598
|
+
moved.id != target.id &&
|
|
599
|
+
event.node.rowIndex != null &&
|
|
600
|
+
params.onRowDragEnd &&
|
|
601
|
+
params.onRowDragEnd(moved, target, event.node.rowIndex);
|
|
602
|
+
},
|
|
603
|
+
[params],
|
|
604
|
+
);
|
|
605
|
+
|
|
586
606
|
// This is setting a ref in the GridContext so won't be triggering an update loop
|
|
587
607
|
setOnCellEditingComplete(params.onCellEditingComplete);
|
|
588
608
|
|
|
@@ -636,7 +656,7 @@ export const Grid = ({
|
|
|
636
656
|
onModelUpdated={onModelUpdated}
|
|
637
657
|
onGridReady={onGridReady}
|
|
638
658
|
onSortChanged={ensureSelectedRowIsVisible}
|
|
639
|
-
postSortRows={params.
|
|
659
|
+
postSortRows={params.onRowDragEnd ? undefined : postSortRows}
|
|
640
660
|
onSelectionChanged={synchroniseExternalStateToGridSelection}
|
|
641
661
|
onColumnMoved={params.onColumnMoved}
|
|
642
662
|
alwaysShowVerticalScroll={params.alwaysShowVerticalScroll}
|
|
@@ -645,6 +665,10 @@ export const Grid = ({
|
|
|
645
665
|
maintainColumnOrder={true}
|
|
646
666
|
preventDefaultOnContextMenu={true}
|
|
647
667
|
onCellContextMenu={gridContextMenu.cellContextMenu}
|
|
668
|
+
rowDragText={params.rowDragText}
|
|
669
|
+
rowDragManaged={!!params.onRowDragEnd}
|
|
670
|
+
suppressMoveWhenRowDragging={true}
|
|
671
|
+
onRowDragEnd={onRowDragEnd}
|
|
648
672
|
/>
|
|
649
673
|
</div>
|
|
650
674
|
</div>
|
|
@@ -67,7 +67,11 @@ export const ControlledMenuFr = (
|
|
|
67
67
|
);
|
|
68
68
|
|
|
69
69
|
const isWithinMenu = useCallback(
|
|
70
|
-
(target: EventTarget | null) =>
|
|
70
|
+
(target: EventTarget | null) =>
|
|
71
|
+
hasParentClass("szh-menu--state-open", target as Node) ||
|
|
72
|
+
// This is temporary, it will be removed when the overlay click is fixed
|
|
73
|
+
hasParentClass("LuiModalPrefab", target as Node) ||
|
|
74
|
+
hasParentClass("prefab-modal", target as Node),
|
|
71
75
|
[],
|
|
72
76
|
);
|
|
73
77
|
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import "../../styles/GridTheme.scss";
|
|
2
|
+
import "../../styles/index.scss";
|
|
3
|
+
import "@linzjs/lui/dist/scss/base.scss";
|
|
4
|
+
|
|
5
|
+
import { ComponentMeta, ComponentStory } from "@storybook/react/dist/ts3.9/client/preview/types-6-3";
|
|
6
|
+
import { useMemo, useState } from "react";
|
|
7
|
+
|
|
8
|
+
import "@linzjs/lui/dist/fonts";
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
ColDefT,
|
|
12
|
+
Grid,
|
|
13
|
+
GridCell,
|
|
14
|
+
GridContextProvider,
|
|
15
|
+
GridProps,
|
|
16
|
+
GridUpdatingContextProvider,
|
|
17
|
+
GridWrapper,
|
|
18
|
+
} from "../..";
|
|
19
|
+
import { waitForGridReady } from "../../utils/storybookTestUtil";
|
|
20
|
+
|
|
21
|
+
export default {
|
|
22
|
+
title: "Components / Grids",
|
|
23
|
+
component: Grid,
|
|
24
|
+
args: {
|
|
25
|
+
quickFilter: true,
|
|
26
|
+
quickFilterValue: "",
|
|
27
|
+
quickFilterPlaceholder: "Quick filter...",
|
|
28
|
+
selectable: false,
|
|
29
|
+
rowSelection: "single",
|
|
30
|
+
},
|
|
31
|
+
// Storybook hangs otherwise
|
|
32
|
+
parameters: {
|
|
33
|
+
docs: {
|
|
34
|
+
source: {
|
|
35
|
+
type: "code",
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
decorators: [
|
|
40
|
+
(Story) => (
|
|
41
|
+
<div style={{ maxWidth: 1024, height: 400, display: "flex", flexDirection: "column" }}>
|
|
42
|
+
<GridUpdatingContextProvider>
|
|
43
|
+
<GridContextProvider>
|
|
44
|
+
<Story />
|
|
45
|
+
</GridContextProvider>
|
|
46
|
+
</GridUpdatingContextProvider>
|
|
47
|
+
</div>
|
|
48
|
+
),
|
|
49
|
+
],
|
|
50
|
+
} as ComponentMeta<typeof Grid>;
|
|
51
|
+
|
|
52
|
+
interface ITestRow {
|
|
53
|
+
id: number;
|
|
54
|
+
position: string;
|
|
55
|
+
age: number;
|
|
56
|
+
height: number;
|
|
57
|
+
desc: string;
|
|
58
|
+
dd: string;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const GridDragRowTemplate: ComponentStory<typeof Grid> = (props: GridProps) => {
|
|
62
|
+
const columnDefs: ColDefT<ITestRow>[] = useMemo(
|
|
63
|
+
() => [
|
|
64
|
+
GridCell({
|
|
65
|
+
field: "id",
|
|
66
|
+
headerName: "Id",
|
|
67
|
+
lockVisible: true,
|
|
68
|
+
}),
|
|
69
|
+
GridCell({
|
|
70
|
+
field: "position",
|
|
71
|
+
headerName: "Position",
|
|
72
|
+
cellRendererParams: {
|
|
73
|
+
warning: (props) => props.value === "Tester" && "Testers are testing",
|
|
74
|
+
info: (props) => props.value === "Developer" && "Developers are awesome",
|
|
75
|
+
},
|
|
76
|
+
}),
|
|
77
|
+
GridCell({
|
|
78
|
+
field: "age",
|
|
79
|
+
headerName: "Age",
|
|
80
|
+
}),
|
|
81
|
+
GridCell({
|
|
82
|
+
field: "height",
|
|
83
|
+
headerName: "Height",
|
|
84
|
+
}),
|
|
85
|
+
GridCell({
|
|
86
|
+
field: "desc",
|
|
87
|
+
headerName: "Description",
|
|
88
|
+
flex: 1,
|
|
89
|
+
}),
|
|
90
|
+
],
|
|
91
|
+
[],
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
const [rowData] = useState([
|
|
95
|
+
{ id: 1000, position: "Tester", age: 30, height: `6'4"`, desc: "Tests application", dd: "1" },
|
|
96
|
+
{ id: 1001, position: "Developer", age: 12, height: `5'3"`, desc: "Develops application", dd: "2" },
|
|
97
|
+
{ id: 1002, position: "Manager", age: 65, height: `5'9"`, desc: "Manages", dd: "3" },
|
|
98
|
+
]);
|
|
99
|
+
|
|
100
|
+
return (
|
|
101
|
+
<GridWrapper maxHeight={300}>
|
|
102
|
+
<Grid
|
|
103
|
+
data-testid={"readonly"}
|
|
104
|
+
{...props}
|
|
105
|
+
selectable={true}
|
|
106
|
+
rowSelection="multiple"
|
|
107
|
+
animateRows={true}
|
|
108
|
+
columnDefs={columnDefs}
|
|
109
|
+
defaultColDef={{ sortable: false }}
|
|
110
|
+
rowData={rowData}
|
|
111
|
+
onRowDragEnd={(row, _, targetIndex) => {
|
|
112
|
+
alert(`Row ${row.id} has been moved to index ${targetIndex}.`);
|
|
113
|
+
}}
|
|
114
|
+
rowDragText={(params) => `${params.rowNode?.data.id} - ${params.rowNode?.data.position}`}
|
|
115
|
+
/>
|
|
116
|
+
</GridWrapper>
|
|
117
|
+
);
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
export const DragRowSingleSelection = GridDragRowTemplate.bind({});
|
|
121
|
+
DragRowSingleSelection.play = waitForGridReady;
|
package/src/styles/Grid.scss
CHANGED
|
@@ -85,6 +85,25 @@
|
|
|
85
85
|
visibility: visible;
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
+
.ag-drag-handle.ag-row-drag{
|
|
89
|
+
opacity: 0;
|
|
90
|
+
|
|
91
|
+
.ag-icon-grip{
|
|
92
|
+
background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 24 24' fill='%239999B3' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M11 18c0 1.1-.9 2-2 2s-2-.9-2-2 .9-2 2-2 2 .9 2 2Zm-2-8c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2Zm0-6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2Zm6 4c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2Zm0 2c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2Zm0 6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2Z' /%3E%3C/svg%3E");
|
|
93
|
+
background-repeat: no-repeat no-repeat;
|
|
94
|
+
background-position: center center;
|
|
95
|
+
background-size: cover;
|
|
96
|
+
color:transparent;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.ag-row:hover{
|
|
101
|
+
.ag-drag-handle.ag-row-drag{
|
|
102
|
+
opacity: 1;
|
|
103
|
+
transition: opacity 0.2s ease-in-out;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
88
107
|
.GridFormMessage-container {
|
|
89
108
|
padding: 4px 8px;
|
|
90
109
|
max-width: 400px;
|
|
@@ -47,9 +47,19 @@ $grid-base-font-size: calc(#{lui.$base-font-size} - 1px);
|
|
|
47
47
|
)
|
|
48
48
|
);
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
|
|
51
51
|
.ag-cell[col-id="selection"] {
|
|
52
|
-
display: flex
|
|
52
|
+
display: flex;// Fix that when you click below checkbox it doesn't process a click
|
|
53
|
+
justify-content: end; // fix alignment of cell content when grabber is present
|
|
54
|
+
|
|
55
|
+
.ag-selection-checkbox {
|
|
56
|
+
margin-right:0;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// fix alignment of cell content when grabber is present
|
|
61
|
+
.ag-header-cell-comp-wrapper {
|
|
62
|
+
justify-content: end;
|
|
53
63
|
}
|
|
54
64
|
|
|
55
65
|
// Fix that when you click below checkbox it doesn't process a click
|