@linzjs/step-ag-grid 29.11.3 → 29.11.4

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": "29.11.3",
5
+ "version": "29.11.4",
6
6
  "keywords": [
7
7
  "aggrid",
8
8
  "ag-grid",
@@ -205,68 +205,79 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
205
205
 
206
206
  const autoSizeResultRef = useRef<AutoSizeColumnsResult | null>(null);
207
207
  const prevRowsVisibleRef = useRef(false);
208
- const setInitialContentSize = useCallback(() => {
209
- if (!gridDivRef.current?.clientWidth || rowData == null) {
210
- // Don't resize grids if they are offscreen as it doesn't work.
211
- needsAutoSize.current = true;
212
- return;
213
- }
214
-
215
- const gridRendered = gridRenderState();
216
- if (gridRendered === null) {
217
- // Don't resize until grid has rendered, or it has 0 rows.
218
- needsAutoSize.current = true;
208
+ const initialContentSizeInProgressRef = useRef(false);
209
+ const setInitialContentSize = useCallback(async (): Promise<void> => {
210
+ if (initialContentSizeInProgressRef.current) {
219
211
  return;
220
212
  }
213
+ initialContentSizeInProgressRef.current = true;
214
+ try {
215
+ needsAutoSize.current = false;
221
216
 
222
- // 1. First we autosize to get the size of the columns on an infinite grid.
223
- if (sizeColumns === 'auto' || sizeColumns === 'auto-skip-headers') {
224
- // You can't skip headers until the grid has content
225
- const rowsVisible = gridRendered === 'rows-visible';
226
- const skipHeader = sizeColumns === 'auto-skip-headers' && rowsVisible;
227
- // If grid was empty and now has content we need to autosize
228
- if (rowsVisible !== prevRowsVisibleRef.current && rowsVisible) {
229
- prevRowsVisibleRef.current = rowsVisible;
230
- autoSizeResultRef.current = null;
217
+ if (!gridDivRef.current?.clientWidth || rowData == null) {
218
+ // Don't resize grids if they are offscreen as it doesn't work.
219
+ needsAutoSize.current = true;
220
+ return;
231
221
  }
232
- const autoSizeResult =
233
- autoSizeResultRef.current ??
234
- autoSizeColumns({
235
- skipHeader,
236
- userSizedColIds: new Set(userSizedColIds.current.keys()),
237
- });
238
- // Auto-size failed retry later
239
- if (!autoSizeResult) {
222
+
223
+ const gridRendered = gridRenderState();
224
+ if (gridRendered === null) {
225
+ // Don't resize until grid has rendered, or it has 0 rows.
240
226
  needsAutoSize.current = true;
241
227
  return;
242
228
  }
243
229
 
244
- autoSizeResultRef.current = autoSizeResult;
245
- // Calculate the auto-sized width, limit it to maxInitialWidth
246
- autoSizeResult.width = maxInitialWidth ? Math.min(autoSizeResult.width, maxInitialWidth) : autoSizeResult.width;
247
- if (gridRendered === 'empty') {
248
- // If the grid is empty we still do an onContentSize callback, we will do another callback when grid has data
249
- // We don't do this callback if we have previously had row data, or have already called back for empty
250
- if (!hasSetContentSizeEmpty.current && !hasSetContentSize.current) {
251
- hasSetContentSizeEmpty.current = true;
252
- params.onContentSize?.(autoSizeResult);
230
+ // 1. First we autosize to get the size of the columns on an infinite grid.
231
+ if (sizeColumns === 'auto' || sizeColumns === 'auto-skip-headers') {
232
+ // You can't skip headers until the grid has content
233
+ const rowsVisible = gridRendered === 'rows-visible';
234
+ const skipHeader = sizeColumns === 'auto-skip-headers' && rowsVisible;
235
+ // If grid was empty and now has content we need to autosize
236
+ if (rowsVisible !== prevRowsVisibleRef.current && rowsVisible) {
237
+ prevRowsVisibleRef.current = rowsVisible;
238
+ autoSizeResultRef.current = null;
253
239
  }
254
- } else if (gridRendered === 'rows-visible') {
255
- // we have rows now so callback grid size
256
- if (!hasSetContentSize.current) {
257
- hasSetContentSize.current = true;
258
- params.onContentSize?.(autoSizeResult);
240
+ const autoSizeResult =
241
+ autoSizeResultRef.current ??
242
+ (await autoSizeColumns({
243
+ skipHeader,
244
+ userSizedColIds: new Set(userSizedColIds.current.keys()),
245
+ }));
246
+ // Auto-size failed retry later
247
+ if (!autoSizeResult) {
248
+ needsAutoSize.current = true;
249
+ return;
250
+ }
251
+
252
+ autoSizeResultRef.current = autoSizeResult;
253
+ // Calculate the auto-sized width, limit it to maxInitialWidth
254
+ autoSizeResult.width = maxInitialWidth ? Math.min(autoSizeResult.width, maxInitialWidth) : autoSizeResult.width;
255
+ if (gridRendered === 'empty') {
256
+ // If the grid is empty we still do an onContentSize callback, we will do another callback when grid has data
257
+ // We don't do this callback if we have previously had row data, or have already called back for empty
258
+ if (!hasSetContentSizeEmpty.current && !hasSetContentSize.current) {
259
+ hasSetContentSizeEmpty.current = true;
260
+ params.onContentSize?.(autoSizeResult);
261
+ }
262
+ } else if (gridRendered === 'rows-visible') {
263
+ // we have rows now so callback grid size
264
+ if (!hasSetContentSize.current) {
265
+ hasSetContentSize.current = true;
266
+ params.onContentSize?.(autoSizeResult);
267
+ }
268
+ } else {
269
+ // It should be impossible to get here
270
+ console.error('Unknown value returned from hasGridRendered');
259
271
  }
260
272
  } else {
261
- // It should be impossible to get here
262
- console.error('Unknown value returned from hasGridRendered');
273
+ sizeColumnsToFit();
263
274
  }
264
- } else {
265
- sizeColumnsToFit();
266
- }
267
275
 
268
- setAutoSized(true);
269
- needsAutoSize.current = false;
276
+ setAutoSized(true);
277
+ needsAutoSize.current = false;
278
+ } finally {
279
+ initialContentSizeInProgressRef.current = false;
280
+ }
270
281
  }, [autoSizeColumns, gridRenderState, maxInitialWidth, params, rowData, sizeColumns, sizeColumnsToFit]);
271
282
 
272
283
  const lastOwnerDocumentRef = useRef<Document>();
@@ -305,8 +316,7 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
305
316
  needsAutoSize.current ||
306
317
  (!hasSetContentSize.current && (sizeColumns === 'auto' || sizeColumns === 'auto-skip-headers'))
307
318
  ) {
308
- needsAutoSize.current = false;
309
- setInitialContentSize();
319
+ void setInitialContentSize();
310
320
  }
311
321
  }, 200);
312
322
 
@@ -460,11 +470,14 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
460
470
  if (previousRowDataLength.current !== length) {
461
471
  // We need to autosize all cells again
462
472
  autoSizeResultRef.current = null;
463
- setInitialContentSize();
464
473
  previousRowDataLength.current = length;
474
+ void setInitialContentSize();
475
+ return;
465
476
  }
466
477
 
467
- if (lastUpdatedDep.current === updatedDep || isEmpty(colIdsEdited.current)) return;
478
+ if (lastUpdatedDep.current === updatedDep || isEmpty(colIdsEdited.current)) {
479
+ return;
480
+ }
468
481
  lastUpdatedDep.current = updatedDep;
469
482
 
470
483
  // Don't update while there are spinners
@@ -474,7 +487,7 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
474
487
 
475
488
  const skipHeader = sizeColumns === 'auto-skip-headers';
476
489
  if ((sizeColumns === 'auto' || sizeColumns === 'auto-skip-headers') && hasSetContentSize.current) {
477
- autoSizeColumns({
490
+ void autoSizeColumns({
478
491
  skipHeader,
479
492
  userSizedColIds: new Set(userSizedColIds.current.keys()),
480
493
  colIds: colIdsEdited.current,
@@ -585,11 +598,21 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
585
598
  children: colDef.children.map((colDef) => adjustColDefOrGroup(colDef)),
586
599
  });
587
600
 
588
- const adjustColDef = (colDef: ColDef<TData>): ColDef<TData> => ({
589
- ...colDef,
590
- suppressSizeToFit: (sizeColumns === 'auto' || sizeColumns === 'auto-skip-headers') && !colDef.flex,
591
- sortable: colDef.sortable && params.defaultColDef?.sortable !== false,
592
- });
601
+ const adjustColDef = (colDef: ColDef<TData>): ColDef<TData> => {
602
+ const flex = colDef.flex ?? (sizeColumns === 'fit' ? 1 : undefined);
603
+ return {
604
+ ...colDef,
605
+ // You cannot pass a width to a flex
606
+ width: !!colDef.flex ? undefined : colDef.width,
607
+ flexAutoSizeWidth: colDef.width,
608
+ // If this is allowed flex columns don't size based on flex
609
+ suppressSizeToFit: true,
610
+ // Auto-sizing flex columns breaks everything
611
+ flex,
612
+ suppressAutoSize: !!flex,
613
+ sortable: colDef.sortable && params.defaultColDef?.sortable !== false,
614
+ } as ColDef<TData> & { flexAutoSizeWidth?: number };
615
+ };
593
616
 
594
617
  return columnDefs.map((colDef) => adjustColDefOrGroup(colDef));
595
618
  }, [columnDefs, params.defaultColDef?.sortable, sizeColumns]);
@@ -617,7 +640,7 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
617
640
  if (sizeColumns === 'auto' || skipHeader) {
618
641
  defer(() => {
619
642
  if (hasSetContentSize.current) {
620
- autoSizeColumns({
643
+ void autoSizeColumns({
621
644
  skipHeader,
622
645
  userSizedColIds: new Set(userSizedColIds.current.keys()),
623
646
  colIds: colIdsEdited.current,
@@ -812,9 +835,9 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
812
835
  [columnDefs, params.loading, params.noRowsMatchingOverlayText, params.noRowsOverlayText, rowData, rowHeight],
813
836
  );
814
837
 
815
- const selectionColumnDef = useMemo((): SelectionColumnDef => {
838
+ const selectionColumnDef = useMemo((): SelectionColumnDef | undefined => {
816
839
  // Note this has to be 1 for hidden otherwise ag-grid does crazy things whilst resizing
817
- const selectWidth = params.hideSelectColumn ? 0 : selectable && params.onRowDragEnd ? 76 : 48;
840
+ const selectWidth = params.onRowDragEnd ? 76 : 48;
818
841
  return {
819
842
  suppressNavigable: params.hideSelectColumn,
820
843
  rowDrag: !!params.onRowDragEnd,
@@ -824,6 +847,8 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
824
847
  headerComponentParams: {
825
848
  exportable: false,
826
849
  },
850
+ suppressAutoSize: true,
851
+ suppressSizeToFit: true,
827
852
  headerClass: clsx('ag-header-hide-default-select', params.onRowDragEnd && 'ag-header-select-draggable'),
828
853
  headerComponent: rowSelection == 'multiple' ? GridHeaderSelect : undefined,
829
854
  suppressHeaderKeyboardEvent: (e) => {
@@ -855,7 +880,7 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
855
880
 
856
881
  const onGridSizeChanged = useCallback(
857
882
  (event: GridSizeChangedEvent<TData>) => {
858
- if (sizeColumns === 'fit') {
883
+ if (sizeColumns === 'fit' || (['auto', 'auto-skip-headers'].includes(sizeColumns) && hasSetContentSize.current)) {
859
884
  event.api.sizeColumnsToFit();
860
885
  }
861
886
  },
@@ -883,9 +908,14 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
883
908
  enableSelectionWithoutKeys: params.enableSelectionWithoutKeys ?? false,
884
909
  enableClickSelection: params.enableClickSelection ?? false,
885
910
  mode: rowSelection === 'single' ? 'singleRow' : 'multiRow',
911
+ ...(params.hideSelectColumn && {
912
+ checkboxes: false,
913
+ headerCheckbox: false,
914
+ }),
886
915
  }
887
916
  : undefined
888
917
  }
918
+ selectionColumnDef={selectionColumnDef}
889
919
  rowHeight={rowHeight}
890
920
  animateRows={params.animateRows ?? false}
891
921
  rowClassRules={params.rowClassRules}
@@ -893,7 +923,7 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
893
923
  suppressColumnVirtualisation={suppressColumnVirtualization}
894
924
  suppressClickEdit={true}
895
925
  onGridSizeChanged={onGridSizeChanged}
896
- onColumnVisible={setInitialContentSize}
926
+ onColumnVisible={() => void setInitialContentSize()}
897
927
  onRowDataUpdated={onRowDataUpdated}
898
928
  onCellFocused={onCellFocused}
899
929
  onCellKeyDown={onCellKeyPress}
@@ -904,7 +934,6 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
904
934
  onColumnResized={onColumnResized}
905
935
  defaultColDef={defaultColDef}
906
936
  columnDefs={columnDefsAdjusted}
907
- selectionColumnDef={selectionColumnDef}
908
937
  rowData={rowData}
909
938
  postSortRows={params.onRowDragEnd || !defaultPostSort ? undefined : postSortRows}
910
939
  onModelUpdated={onModelUpdated}
@@ -45,7 +45,7 @@ export interface GridContextType<TData extends GridBaseRow> {
45
45
  ensureRowVisible: (id: number | string) => boolean;
46
46
  ensureSelectedRowIsVisible: () => void;
47
47
  getFirstRowId: () => number;
48
- autoSizeColumns: (props?: AutoSizeColumnsProps) => AutoSizeColumnsResult;
48
+ autoSizeColumns: (props?: AutoSizeColumnsProps) => Promise<AutoSizeColumnsResult>;
49
49
  sizeColumnsToFit: (paramsOrGridWidth?: ISizeColumnsToFitParams) => void;
50
50
  startCellEditing: ({ rowId, colId }: StartCellEditingProps) => Promise<void>;
51
51
  // Restores the previous focus after cell editing
@@ -153,9 +153,9 @@ export const GridContext = createContext<GridContextType<any>>({
153
153
  console.error('no context provider for getFirstRowId');
154
154
  return -1;
155
155
  },
156
- autoSizeColumns: () => {
156
+ autoSizeColumns: async () => {
157
157
  console.error('no context provider for autoSizeColumns');
158
- return null;
158
+ return Promise.resolve(null);
159
159
  },
160
160
  sizeColumnsToFit: () => {
161
161
  console.error('no context provider for autoSizeAllColumns');
@@ -434,10 +434,11 @@ export const GridContextProvider = <TData extends GridBaseRow>(props: PropsWithC
434
434
  * Then we size the flexed columns.
435
435
  */
436
436
  const autoSizeColumns = useCallback(
437
- ({ skipHeader, colIds, userSizedColIds }: AutoSizeColumnsProps = {}): AutoSizeColumnsResult => {
437
+ async ({ skipHeader, colIds, userSizedColIds }: AutoSizeColumnsProps = {}): Promise<AutoSizeColumnsResult> => {
438
438
  if (!gridApi || !gridApi.getColumnState()) {
439
439
  return null;
440
440
  }
441
+
441
442
  const colIdsSet = colIds instanceof Set ? colIds : new Set(colIds);
442
443
 
443
444
  const getVisibleColStates = () => {
@@ -450,31 +451,44 @@ export const GridContextProvider = <TData extends GridBaseRow>(props: PropsWithC
450
451
  const getFlexColStates = () => getVisibleColStates().filter(colStateFlexed);
451
452
  const getNonFlexColStates = () => getVisibleColStates().filter(colStateNotFlexed);
452
453
 
453
- // If we don't reset the flex columns auto size it causes issues with random resizing of flex columns
454
- let flexColumns = getFlexColStates();
454
+ // You cannot autosize flex columns it will break layout randomly
455
+ // So, a flex column is assumed to be 150 wide, unless width is provided
456
+ const flexColumns = getFlexColStates().map(colStateId);
455
457
  let width = 0;
456
- if (!isEmpty(flexColumns)) {
457
- gridApi.autoSizeColumns(flexColumns.map(colStateId), skipHeader);
458
- const flexColumnIds = flexColumns.map(colStateId);
459
- flexColumns = getVisibleColStates().filter((colState) => flexColumnIds.includes(colState.colId));
460
- width += sumBy(
461
- flexColumns.filter((col) => !col.hide),
462
- 'width',
463
- );
464
- gridApi.resetColumnState();
465
- }
458
+ flexColumns.forEach((colId) => {
459
+ const colDef = gridApi.getColumnDef(colId) as { flexAutoSizeWidth?: number } | undefined;
460
+ width += colDef?.flexAutoSizeWidth ?? 200;
461
+ });
462
+
463
+ const nonFlexColumns = getNonFlexColStates();
464
+ const nonFlexColumnIds = nonFlexColumns.map(colStateId);
465
+ gridApi.autoSizeColumns({ colIds: nonFlexColumnIds, skipHeader });
466
466
 
467
- let nonFlexColumns = getNonFlexColStates();
468
- if (!isEmpty(nonFlexColumns)) {
469
- gridApi.autoSizeColumns(nonFlexColumns.map(colStateId), skipHeader);
470
- const nonFlexColumnIds = nonFlexColumns.map(colStateId);
471
- nonFlexColumns = getVisibleColStates().filter((colState) => nonFlexColumnIds.includes(colState.colId));
472
- width += sumBy(
473
- nonFlexColumns.filter((col) => !col.hide),
467
+ const calcSubWidth = () => {
468
+ const updatedFlexColumns = getVisibleColStates().filter((colState) =>
469
+ nonFlexColumnIds.includes(colState.colId),
470
+ );
471
+ return sumBy(
472
+ updatedFlexColumns.filter((col) => !col.hide),
474
473
  'width',
475
474
  );
475
+ };
476
+
477
+ // ag-grid updates widths asynchronously, so we wait here for the default calculated width to change
478
+ let lastSubWidth = calcSubWidth();
479
+ const endTime = Date.now() + 1000;
480
+ while (Date.now() < endTime) {
481
+ await wait(40);
482
+ const newSubWidth = calcSubWidth();
483
+ if (lastSubWidth !== newSubWidth) {
484
+ lastSubWidth = newSubWidth;
485
+ break;
486
+ }
476
487
  }
477
488
 
489
+ width += lastSubWidth;
490
+
491
+ gridApi.sizeColumnsToFit();
478
492
  return {
479
493
  width,
480
494
  };
@@ -35,13 +35,11 @@ const GridPopoutEditGenericTemplate: StoryFn<typeof Grid<IFormTestRow>> = (props
35
35
  GridCell({
36
36
  field: 'id',
37
37
  headerName: 'Id',
38
- flex: 2,
39
38
  }),
40
39
  GridCell(
41
40
  {
42
41
  field: 'name',
43
42
  headerName: 'Popout Generic Edit',
44
- flex: 1,
45
43
  },
46
44
  {
47
45
  multiEdit: true,
@@ -55,7 +53,13 @@ const GridPopoutEditGenericTemplate: StoryFn<typeof Grid<IFormTestRow>> = (props
55
53
 
56
54
  const [rowData] = useState([
57
55
  { id: 1000, name: 'IS IS DP12345', nameType: 'IS', numba: 'IX', plan: 'DP 12345' },
58
- { id: 1001, name: 'PEG V SD523', nameType: 'PEG', numba: 'V', plan: 'SD 523' },
56
+ {
57
+ id: 1001,
58
+ name: 'PEG V SD523',
59
+ nameType: 'PEG',
60
+ numba: 'V',
61
+ plan: 'SD 523',
62
+ },
59
63
  ] as IFormTestRow[]);
60
64
 
61
65
  return (
@@ -64,6 +68,8 @@ const GridPopoutEditGenericTemplate: StoryFn<typeof Grid<IFormTestRow>> = (props
64
68
  externalSelectedItems={externalSelectedItems}
65
69
  setExternalSelectedItems={setExternalSelectedItems}
66
70
  columnDefs={columnDefs}
71
+ hideSelectColumn={true}
72
+ selectable={true}
67
73
  rowData={rowData}
68
74
  domLayout={'autoHeight'}
69
75
  />
@@ -0,0 +1,84 @@
1
+ import '../../../styles/GridTheme.scss';
2
+ import '../../../styles/index.scss';
3
+ import '@linzjs/lui/dist/scss/base.scss';
4
+ import '@linzjs/lui/dist/fonts';
5
+
6
+ import { Meta, StoryFn } from '@storybook/react-vite';
7
+ import { useMemo, useState } from 'react';
8
+
9
+ import { ColDefT, Grid, GridCell, GridContextProvider, GridProps, GridUpdatingContextProvider } from '../../..';
10
+ import { waitForGridReady } from '../../../utils/__tests__/storybookTestUtil';
11
+ import { FormTest, IFormTestRow } from '../FormTest';
12
+
13
+ export default {
14
+ title: 'Components / Grid Size',
15
+ component: Grid,
16
+ args: {
17
+ quickFilterValue: '',
18
+ selectable: true,
19
+ },
20
+ decorators: [
21
+ (Story) => (
22
+ <GridUpdatingContextProvider>
23
+ <GridContextProvider>
24
+ <Story />
25
+ </GridContextProvider>
26
+ </GridUpdatingContextProvider>
27
+ ),
28
+ ],
29
+ } as Meta<typeof Grid>;
30
+
31
+ const GridPopoutEditGenericTemplate: StoryFn<typeof Grid<IFormTestRow>> = (props: GridProps<IFormTestRow>) => {
32
+ const [externalSelectedItems, setExternalSelectedItems] = useState<any[]>([]);
33
+ const columnDefs: ColDefT<IFormTestRow>[] = useMemo(
34
+ () => [
35
+ GridCell({
36
+ field: 'id',
37
+ headerName: 'Id',
38
+ }),
39
+ GridCell(
40
+ {
41
+ field: 'name',
42
+ headerName: 'Popout Generic Edit',
43
+ flex: 1,
44
+ },
45
+ {
46
+ multiEdit: true,
47
+ editor: FormTest,
48
+ editorParams: {},
49
+ },
50
+ ),
51
+ ],
52
+ [],
53
+ );
54
+
55
+ const [rowData] = useState([
56
+ { id: 1000, name: 'IS IS DP12345', nameType: 'IS', numba: 'IX', plan: 'DP 12345' },
57
+ {
58
+ id: 1001,
59
+ name: 'PEG V SD523PEG V SD523PEG V SD523PEG V SD523PEG V SD523PEG V SD523PEG V SD523PEG V SD523PEG V SD523PEG V SD523PEG V SD523PEG V SD523',
60
+ nameType: 'PEG',
61
+ numba: 'V',
62
+ plan: 'SD 523',
63
+ },
64
+ ] as IFormTestRow[]);
65
+
66
+ return (
67
+ <>
68
+ Auto-size. Col 1 should autosize, Col 2 should flex to fill.
69
+ <Grid
70
+ {...props}
71
+ externalSelectedItems={externalSelectedItems}
72
+ setExternalSelectedItems={setExternalSelectedItems}
73
+ columnDefs={columnDefs}
74
+ hideSelectColumn={true}
75
+ selectable={true}
76
+ rowData={rowData}
77
+ domLayout={'autoHeight'}
78
+ />
79
+ </>
80
+ );
81
+ };
82
+
83
+ export const _AutoSize = GridPopoutEditGenericTemplate.bind({});
84
+ _AutoSize.play = waitForGridReady;
@@ -0,0 +1,84 @@
1
+ import '../../../styles/GridTheme.scss';
2
+ import '../../../styles/index.scss';
3
+ import '@linzjs/lui/dist/scss/base.scss';
4
+ import '@linzjs/lui/dist/fonts';
5
+
6
+ import { Meta, StoryFn } from '@storybook/react-vite';
7
+ import { useMemo, useState } from 'react';
8
+
9
+ import { ColDefT, Grid, GridCell, GridContextProvider, GridProps, GridUpdatingContextProvider } from '../../..';
10
+ import { waitForGridReady } from '../../../utils/__tests__/storybookTestUtil';
11
+ import { FormTest, IFormTestRow } from '../FormTest';
12
+
13
+ export default {
14
+ title: 'Components / Grid Size',
15
+ component: Grid,
16
+ args: {
17
+ quickFilterValue: '',
18
+ selectable: true,
19
+ },
20
+ decorators: [
21
+ (Story) => (
22
+ <GridUpdatingContextProvider>
23
+ <GridContextProvider>
24
+ <Story />
25
+ </GridContextProvider>
26
+ </GridUpdatingContextProvider>
27
+ ),
28
+ ],
29
+ } as Meta<typeof Grid>;
30
+
31
+ const GridPopoutEditGenericTemplate: StoryFn<typeof Grid<IFormTestRow>> = (props: GridProps<IFormTestRow>) => {
32
+ const [externalSelectedItems, setExternalSelectedItems] = useState<any[]>([]);
33
+ const columnDefs: ColDefT<IFormTestRow>[] = useMemo(
34
+ () => [
35
+ GridCell({
36
+ field: 'id',
37
+ headerName: 'Id',
38
+ }),
39
+ GridCell(
40
+ {
41
+ field: 'name',
42
+ headerName: 'Popout Generic Edit',
43
+ },
44
+ {
45
+ multiEdit: true,
46
+ editor: FormTest,
47
+ editorParams: {},
48
+ },
49
+ ),
50
+ ],
51
+ [],
52
+ );
53
+
54
+ const [rowData] = useState([
55
+ { id: 1000, name: 'IS IS DP12345', nameType: 'IS', numba: 'IX', plan: 'DP 12345' },
56
+ {
57
+ id: 1001,
58
+ name: 'PEG V SD523PEG V SD523PEG V SD523PEG V SD523PEG V SD523PEG V SD523PEG V SD523PEG V SD523PEG V SD523PEG V SD523PEG V SD523PEG V SD523',
59
+ nameType: 'PEG',
60
+ numba: 'V',
61
+ plan: 'SD 523',
62
+ },
63
+ ] as IFormTestRow[]);
64
+
65
+ return (
66
+ <>
67
+ Equisized flex columns spread across container
68
+ <Grid
69
+ {...props}
70
+ externalSelectedItems={externalSelectedItems}
71
+ setExternalSelectedItems={setExternalSelectedItems}
72
+ columnDefs={columnDefs}
73
+ sizeColumns={'fit'}
74
+ hideSelectColumn={true}
75
+ selectable={true}
76
+ rowData={rowData}
77
+ domLayout={'autoHeight'}
78
+ />
79
+ </>
80
+ );
81
+ };
82
+
83
+ export const _FitSize = GridPopoutEditGenericTemplate.bind({});
84
+ _FitSize.play = waitForGridReady;
@@ -0,0 +1,86 @@
1
+ import '../../../styles/GridTheme.scss';
2
+ import '../../../styles/index.scss';
3
+ import '@linzjs/lui/dist/scss/base.scss';
4
+ import '@linzjs/lui/dist/fonts';
5
+
6
+ import { Meta, StoryFn } from '@storybook/react-vite';
7
+ import { useMemo, useState } from 'react';
8
+
9
+ import { ColDefT, Grid, GridCell, GridContextProvider, GridProps, GridUpdatingContextProvider } from '../../..';
10
+ import { waitForGridReady } from '../../../utils/__tests__/storybookTestUtil';
11
+ import { FormTest, IFormTestRow } from '../FormTest';
12
+
13
+ export default {
14
+ title: 'Components / Grid Size',
15
+ component: Grid,
16
+ args: {
17
+ quickFilterValue: '',
18
+ selectable: true,
19
+ },
20
+ decorators: [
21
+ (Story) => (
22
+ <GridUpdatingContextProvider>
23
+ <GridContextProvider>
24
+ <Story />
25
+ </GridContextProvider>
26
+ </GridUpdatingContextProvider>
27
+ ),
28
+ ],
29
+ } as Meta<typeof Grid>;
30
+
31
+ const GridPopoutEditGenericTemplate: StoryFn<typeof Grid<IFormTestRow>> = (props: GridProps<IFormTestRow>) => {
32
+ const [externalSelectedItems, setExternalSelectedItems] = useState<any[]>([]);
33
+ const columnDefs: ColDefT<IFormTestRow>[] = useMemo(
34
+ () => [
35
+ GridCell({
36
+ field: 'id',
37
+ headerName: 'Id',
38
+ flex: 2,
39
+ }),
40
+ GridCell(
41
+ {
42
+ field: 'name',
43
+ headerName: 'Popout Generic Edit',
44
+ flex: 1,
45
+ },
46
+ {
47
+ multiEdit: true,
48
+ editor: FormTest,
49
+ editorParams: {},
50
+ },
51
+ ),
52
+ ],
53
+ [],
54
+ );
55
+
56
+ const [rowData] = useState([
57
+ { id: 1000, name: 'IS IS DP12345', nameType: 'IS', numba: 'IX', plan: 'DP 12345' },
58
+ {
59
+ id: 1001,
60
+ name: 'PEG V SD523PEG V SD523PEG V SD523PEG V SD523PEG V SD523PEG V SD523PEG V SD523PEG V SD523PEG V SD523PEG V SD523PEG V SD523PEG V SD523',
61
+ nameType: 'PEG',
62
+ numba: 'V',
63
+ plan: 'SD 523',
64
+ },
65
+ ] as IFormTestRow[]);
66
+
67
+ return (
68
+ <>
69
+ 1:3 flex columns spread across container. These columns should not be the same size.
70
+ <Grid
71
+ {...props}
72
+ externalSelectedItems={externalSelectedItems}
73
+ setExternalSelectedItems={setExternalSelectedItems}
74
+ columnDefs={columnDefs}
75
+ sizeColumns={'fit'}
76
+ hideSelectColumn={true}
77
+ selectable={true}
78
+ rowData={rowData}
79
+ domLayout={'autoHeight'}
80
+ />
81
+ </>
82
+ );
83
+ };
84
+
85
+ export const _FitSizeFlex = GridPopoutEditGenericTemplate.bind({});
86
+ _FitSizeFlex.play = waitForGridReady;