@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/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@linzjs/step-ag-grid",
3
3
  "repository": "github:linz/step-ag-grid.git",
4
4
  "license": "MIT",
5
- "version": "22.1.0",
5
+ "version": "22.2.0",
6
6
  "keywords": [
7
7
  "aggrid",
8
8
  "ag-grid",
@@ -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
+ };
@@ -1,3 +1,4 @@
1
+ export * from "./GridButton";
1
2
  export * from "./GridEditBoolean";
2
3
  export * from "./GridPopoutEditMultiSelect";
3
4
  export * from "./GridPopoutEditMultiSelectGrid";
@@ -7,7 +7,15 @@ import { useMemo, useState } from "react";
7
7
 
8
8
  import "@linzjs/lui/dist/fonts";
9
9
 
10
- import { ColDefT, Grid, GridCell, GridContextProvider, GridEditBoolean, GridUpdatingContextProvider } from "../..";
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
- field: "position4",
174
+ colId: "position4",
175
175
  headerName: "Filtered (object)",
176
176
  valueGetter: ({ data }) => data?.position4?.desc,
177
177
  },
@@ -125,6 +125,7 @@
125
125
 
126
126
  .GridCellAlignCenter .GridCell-container {
127
127
  display: flex;
128
+ justify-content: center;
128
129
  }
129
130
 
130
131
  .GridCellAlignCenter .ag-wrapper {