@linzjs/step-ag-grid 22.1.0 → 22.2.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/index.css +1 -0
- package/dist/src/components/gridPopoverEdit/GridButton.d.ts +12 -0
- package/dist/src/components/gridPopoverEdit/index.d.ts +1 -0
- package/dist/step-ag-grid.cjs.js +36 -0
- package/dist/step-ag-grid.cjs.js.map +1 -1
- package/dist/step-ag-grid.esm.js +36 -1
- package/dist/step-ag-grid.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/gridPopoverEdit/GridButton.tsx +63 -0
- package/src/components/gridPopoverEdit/index.ts +1 -0
- package/src/stories/grid/GridPopoutEditBoolean.stories.tsx +21 -1
- package/src/stories/grid/GridPopoverEditDropDown.stories.tsx +1 -1
- package/src/styles/Grid.scss +1 -0
package/package.json
CHANGED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { CellFocusedEvent, ICellEditorParams } from "ag-grid-community";
|
|
2
|
+
import { ColDefT, GridCell, SAICellRendererParams } from "../GridCell";
|
|
3
|
+
import { GenericCellColDef } from "../gridRender";
|
|
4
|
+
import { GridBaseRow } from "../Grid";
|
|
5
|
+
import { LuiButton, LuiIcon } from "@linzjs/lui";
|
|
6
|
+
import { useEffect, useRef } from "react";
|
|
7
|
+
|
|
8
|
+
const ButtonCellRenderer = (props: SAICellRendererParams) => {
|
|
9
|
+
const { data, node, column, colDef, api } = props;
|
|
10
|
+
const inputRef = useRef<HTMLButtonElement>(null);
|
|
11
|
+
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
const checkFocus = (event: CellFocusedEvent) => {
|
|
14
|
+
if (event.rowIndex === node.rowIndex && event.column === column) {
|
|
15
|
+
inputRef.current?.focus();
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
api.addEventListener("cellFocused", checkFocus);
|
|
19
|
+
return () => {
|
|
20
|
+
api.removeEventListener("cellFocused", checkFocus);
|
|
21
|
+
};
|
|
22
|
+
}, [api, column, node.rowIndex]);
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<LuiButton
|
|
26
|
+
ref={inputRef}
|
|
27
|
+
className="lui-button-icon-only"
|
|
28
|
+
size="sm"
|
|
29
|
+
level="text"
|
|
30
|
+
onClick={() => {
|
|
31
|
+
const selectedRows = [data];
|
|
32
|
+
const selectedRowIds = selectedRows.map((r) => r.id);
|
|
33
|
+
colDef?.cellEditorParams.onClick?.({ selectedRows, selectedRowIds });
|
|
34
|
+
}}
|
|
35
|
+
style={{ display: colDef?.cellEditorParams?.visible?.(props) !== false ? "" : "none" }}
|
|
36
|
+
>
|
|
37
|
+
<LuiIcon name="ic_redo" alt="revert" size="md" />
|
|
38
|
+
</LuiButton>
|
|
39
|
+
);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export interface GridButtonProps<TData> {
|
|
43
|
+
visible?: (cellEditorParams: ICellEditorParams) => boolean;
|
|
44
|
+
onClick?: (props: { selectedRows: TData[]; selectedRowIds: (string | number)[] }) => void;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export const GridButton = <TData extends GridBaseRow>(
|
|
48
|
+
colDef: GenericCellColDef<TData, boolean>,
|
|
49
|
+
editor: GridButtonProps<TData>,
|
|
50
|
+
): ColDefT<TData> => {
|
|
51
|
+
return GridCell({
|
|
52
|
+
minWidth: 72,
|
|
53
|
+
maxWidth: 72,
|
|
54
|
+
resizable: false,
|
|
55
|
+
headerClass: "GridHeaderAlignCenter",
|
|
56
|
+
cellClass: "GridCellAlignCenter",
|
|
57
|
+
cellRenderer: ButtonCellRenderer,
|
|
58
|
+
cellEditorParams: {
|
|
59
|
+
...editor,
|
|
60
|
+
},
|
|
61
|
+
...colDef,
|
|
62
|
+
});
|
|
63
|
+
};
|
|
@@ -7,7 +7,15 @@ import { useMemo, useState } from "react";
|
|
|
7
7
|
|
|
8
8
|
import "@linzjs/lui/dist/fonts";
|
|
9
9
|
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
ColDefT,
|
|
12
|
+
Grid,
|
|
13
|
+
GridButton,
|
|
14
|
+
GridCell,
|
|
15
|
+
GridContextProvider,
|
|
16
|
+
GridEditBoolean,
|
|
17
|
+
GridUpdatingContextProvider,
|
|
18
|
+
} from "../..";
|
|
11
19
|
import { waitForGridReady } from "../../utils/storybookTestUtil";
|
|
12
20
|
import { IFormTestRow } from "./FormTest";
|
|
13
21
|
|
|
@@ -39,6 +47,18 @@ const GridPopoutEditBooleanTemplate: StoryFn<typeof Grid> = () => {
|
|
|
39
47
|
field: "id",
|
|
40
48
|
headerName: "Id",
|
|
41
49
|
}),
|
|
50
|
+
GridButton(
|
|
51
|
+
{
|
|
52
|
+
colId: "button",
|
|
53
|
+
headerName: "Button",
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
visible: ({ data }) => !!(data.id & 1),
|
|
57
|
+
onClick: ({ selectedRowIds }) => {
|
|
58
|
+
alert("click " + selectedRowIds);
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
),
|
|
42
62
|
GridEditBoolean(
|
|
43
63
|
{
|
|
44
64
|
field: "bold",
|
|
@@ -171,7 +171,7 @@ const GridEditDropDownTemplate: StoryFn<typeof Grid> = (props: GridProps) => {
|
|
|
171
171
|
),
|
|
172
172
|
GridPopoverEditDropDown(
|
|
173
173
|
{
|
|
174
|
-
|
|
174
|
+
colId: "position4",
|
|
175
175
|
headerName: "Filtered (object)",
|
|
176
176
|
valueGetter: ({ data }) => data?.position4?.desc,
|
|
177
177
|
},
|