@linzjs/step-ag-grid 15.0.2 → 15.1.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/README.md +27 -0
- package/dist/src/components/Grid.d.ts +10 -1
- package/dist/src/components/gridHook/index.d.ts +1 -0
- package/dist/src/components/gridHook/useGridContextMenu.d.ts +19 -0
- package/dist/src/components/index.d.ts +1 -0
- package/dist/src/contexts/GridContext.d.ts +1 -0
- package/dist/src/utils/testQuick.d.ts +1 -1
- package/dist/src/utils/testUtil.d.ts +5 -0
- package/dist/step-ag-grid.cjs.js +1373 -1330
- package/dist/step-ag-grid.cjs.js.map +1 -1
- package/dist/step-ag-grid.esm.js +1387 -1346
- package/dist/step-ag-grid.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Grid.tsx +18 -0
- package/src/components/gridHook/index.ts +1 -0
- package/src/components/gridHook/useGridContextMenu.tsx +92 -0
- package/src/components/index.ts +1 -0
- package/src/contexts/GridContext.tsx +4 -0
- package/src/contexts/GridContextProvider.tsx +11 -0
- package/src/stories/grid/GridPopoutContextMenu.stories.tsx +136 -0
- package/src/utils/testQuick.ts +2 -2
- package/src/utils/testUtil.ts +46 -58
package/README.md
CHANGED
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
- Bearing/Bearing Correction
|
|
17
17
|
- Popover message
|
|
18
18
|
- Custom form
|
|
19
|
+
- Context menu
|
|
19
20
|
|
|
20
21
|
_Please note this requires React >=17, ag-grid-community >=27, and sass._
|
|
21
22
|
|
|
@@ -55,6 +56,7 @@ import {
|
|
|
55
56
|
GridCell,
|
|
56
57
|
GridCellFiller,
|
|
57
58
|
GridContextProvider,
|
|
59
|
+
GridContextMenuComponentProps,
|
|
58
60
|
GridPopoverEditDropDown,
|
|
59
61
|
GridPopoverMessage,
|
|
60
62
|
GridUpdatingContextProvider,
|
|
@@ -124,6 +126,29 @@ const GridDemo = () => {
|
|
|
124
126
|
[],
|
|
125
127
|
);
|
|
126
128
|
|
|
129
|
+
const ContextMenu = ({ selectedRows, colDef, close }: GridContextMenuComponentProps<ITestRow>): ReactElement => {
|
|
130
|
+
const onClick = useCallback(() => {
|
|
131
|
+
selectedRows.forEach((row) => {
|
|
132
|
+
switch (colDef.field) {
|
|
133
|
+
case "name":
|
|
134
|
+
row.name = "";
|
|
135
|
+
break;
|
|
136
|
+
case "distance":
|
|
137
|
+
row.distance = null;
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
close();
|
|
142
|
+
}, [close, colDef.field, selectedRows]);
|
|
143
|
+
|
|
144
|
+
return (
|
|
145
|
+
<>
|
|
146
|
+
<button onClick={onClick}>Button - Clear cell</button>
|
|
147
|
+
<MenuItem onClick={onClick}>Menu Item - Clear cell</MenuItem>
|
|
148
|
+
</>
|
|
149
|
+
);
|
|
150
|
+
};
|
|
151
|
+
|
|
127
152
|
const rowData: ITestRow[] = useMemo(
|
|
128
153
|
() => [
|
|
129
154
|
{ id: 1000, name: "Tom", position: "Tester" },
|
|
@@ -159,6 +184,8 @@ const GridDemo = () => {
|
|
|
159
184
|
<Grid selectable={true}
|
|
160
185
|
columnDefs={columnDefs}
|
|
161
186
|
rowData={rowData}
|
|
187
|
+
contextMenu={contextMenu}
|
|
188
|
+
contextMenuSelectRow={false}
|
|
162
189
|
onContentSize={({ width }) => setPanelSize(width)} />
|
|
163
190
|
</GridWrapper>
|
|
164
191
|
</GridContextProvider>
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { ColDef } from "ag-grid-community";
|
|
3
3
|
import { GridOptions } from "ag-grid-community/dist/lib/entities/gridOptions";
|
|
4
|
+
import { GridContextMenuComponent } from "./gridHook";
|
|
4
5
|
export interface GridBaseRow {
|
|
5
6
|
id: string | number;
|
|
6
7
|
}
|
|
@@ -54,8 +55,16 @@ export interface GridProps {
|
|
|
54
55
|
* Once the last cell to edit closes this callback is called.
|
|
55
56
|
*/
|
|
56
57
|
onCellEditingComplete?: () => void;
|
|
58
|
+
/**
|
|
59
|
+
* Context menu definition if required.
|
|
60
|
+
*/
|
|
61
|
+
contextMenu?: GridContextMenuComponent<any>;
|
|
62
|
+
/**
|
|
63
|
+
* Whether to select row on context menu.
|
|
64
|
+
*/
|
|
65
|
+
contextMenuSelectRow?: boolean;
|
|
57
66
|
}
|
|
58
67
|
/**
|
|
59
68
|
* Wrapper for AgGrid to add commonly used functionality.
|
|
60
69
|
*/
|
|
61
|
-
export declare const Grid: ({ "data-testid": dataTestId, rowSelection, suppressColumnVirtualization, theme, sizeColumns, selectColumnPinned, ...params }: GridProps) => JSX.Element;
|
|
70
|
+
export declare const Grid: ({ "data-testid": dataTestId, rowSelection, suppressColumnVirtualization, theme, sizeColumns, selectColumnPinned, contextMenuSelectRow, ...params }: GridProps) => JSX.Element;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./useGridContextMenu";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ColDef } from "ag-grid-community";
|
|
2
|
+
import { CellContextMenuEvent } from "ag-grid-community/dist/lib/events";
|
|
3
|
+
import { ReactElement } from "react";
|
|
4
|
+
import { GridBaseRow } from "../Grid";
|
|
5
|
+
export interface GridContextMenuComponentProps<RowType extends GridBaseRow> {
|
|
6
|
+
selectedRows: RowType[];
|
|
7
|
+
clickedRow: RowType;
|
|
8
|
+
colDef: ColDef;
|
|
9
|
+
close: () => void;
|
|
10
|
+
}
|
|
11
|
+
export type GridContextMenuComponent<RowType extends GridBaseRow> = (props: GridContextMenuComponentProps<RowType>) => ReactElement | null;
|
|
12
|
+
export declare const useGridContextMenu: <RowType extends GridBaseRow>({ contextMenuSelectRow, contextMenu: ContextMenu, }: {
|
|
13
|
+
contextMenuSelectRow: boolean;
|
|
14
|
+
contextMenu?: GridContextMenuComponent<RowType> | undefined;
|
|
15
|
+
}) => {
|
|
16
|
+
openMenu: (e: PointerEvent | null | undefined) => void;
|
|
17
|
+
cellContextMenu: (event: CellContextMenuEvent) => void;
|
|
18
|
+
component: JSX.Element | null;
|
|
19
|
+
};
|
|
@@ -7,6 +7,7 @@ export * from "./GridCellMultiSelectClassRules";
|
|
|
7
7
|
export * from "./gridFilter";
|
|
8
8
|
export * from "./gridForm";
|
|
9
9
|
export * from "./gridHeader";
|
|
10
|
+
export * from "./gridHook";
|
|
10
11
|
export * from "./GridIcon";
|
|
11
12
|
export * from "./GridLoadableCell";
|
|
12
13
|
export * from "./GridNoRowsOverlay";
|
|
@@ -18,6 +18,7 @@ export interface GridContextType<RowType extends GridBaseRow> {
|
|
|
18
18
|
getColumnIds: (filter?: keyof ColDef | ((r: ColDef) => boolean | undefined | null | number | string)) => string[];
|
|
19
19
|
setApis: (gridApi: GridApi | undefined, columnApi: ColumnApi | undefined, dataTestId?: string) => void;
|
|
20
20
|
prePopupOps: () => void;
|
|
21
|
+
postPopupOps: () => void;
|
|
21
22
|
setQuickFilter: (quickFilter: string) => void;
|
|
22
23
|
editingCells: () => boolean;
|
|
23
24
|
getSelectedRows: <T extends GridBaseRow>() => T[];
|
|
@@ -53,7 +53,7 @@ export declare const getAllQuick: <T extends HTMLElement>(filter: IQueryQuick, c
|
|
|
53
53
|
*/
|
|
54
54
|
export declare const getQuick: (filter: IQueryQuick, container?: HTMLElement) => HTMLElement;
|
|
55
55
|
/**
|
|
56
|
-
* Find by filter. Waits up to
|
|
56
|
+
* Find by filter. Waits up to 5 seconds to find filter.
|
|
57
57
|
*
|
|
58
58
|
* @param filter Filter
|
|
59
59
|
* @param container Optional container to look in
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* allow external userEvent to be used
|
|
3
|
+
* @param customisedUserEvent
|
|
4
|
+
*/
|
|
5
|
+
export declare const setUpUserEvent: (customisedUserEvent: any) => void;
|
|
1
6
|
export declare const countRows: (within?: HTMLElement) => Promise<number>;
|
|
2
7
|
export declare const findRow: (rowId: number | string, within?: HTMLElement) => Promise<HTMLDivElement>;
|
|
3
8
|
export declare const queryRow: (rowId: number | string, within?: HTMLElement) => Promise<HTMLDivElement | null>;
|