@linzjs/step-ag-grid 29.11.2 → 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/dist/src/contexts/GridContext.d.ts +1 -1
- package/dist/step-ag-grid.cjs +122 -79
- package/dist/step-ag-grid.cjs.map +1 -1
- package/dist/step-ag-grid.esm.js +123 -80
- package/dist/step-ag-grid.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Grid.tsx +104 -65
- package/src/contexts/GridContext.tsx +3 -3
- package/src/contexts/GridContextProvider.tsx +34 -20
- package/src/stories/grid/GridPopoutEditGeneric.stories.tsx +9 -3
- package/src/stories/grid/gridAutosize/GridAutoSize.stories.tsx +84 -0
- package/src/stories/grid/gridAutosize/GridFitSize.stories.tsx +84 -0
- package/src/stories/grid/gridAutosize/GridFitSizeFlex.stories.tsx +86 -0
- package/src/stories/grid/gridAutosize/ShowPanelResizingAgGrid/ShowPanelResizingStepAgGrid.tsx +49 -16
package/package.json
CHANGED
package/src/components/Grid.tsx
CHANGED
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
GetRowIdParams,
|
|
15
15
|
GridOptions,
|
|
16
16
|
GridReadyEvent,
|
|
17
|
+
GridSizeChangedEvent,
|
|
17
18
|
ModelUpdatedEvent,
|
|
18
19
|
ModuleRegistry,
|
|
19
20
|
RowClickedEvent,
|
|
@@ -204,69 +205,79 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
|
|
|
204
205
|
|
|
205
206
|
const autoSizeResultRef = useRef<AutoSizeColumnsResult | null>(null);
|
|
206
207
|
const prevRowsVisibleRef = useRef(false);
|
|
207
|
-
const
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
needsAutoSize.current = true;
|
|
211
|
-
return;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
const gridRendered = gridRenderState();
|
|
215
|
-
if (gridRendered === null) {
|
|
216
|
-
// Don't resize until grid has rendered, or it has 0 rows.
|
|
217
|
-
needsAutoSize.current = true;
|
|
208
|
+
const initialContentSizeInProgressRef = useRef(false);
|
|
209
|
+
const setInitialContentSize = useCallback(async (): Promise<void> => {
|
|
210
|
+
if (initialContentSizeInProgressRef.current) {
|
|
218
211
|
return;
|
|
219
212
|
}
|
|
213
|
+
initialContentSizeInProgressRef.current = true;
|
|
214
|
+
try {
|
|
215
|
+
needsAutoSize.current = false;
|
|
220
216
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
const skipHeader = sizeColumns === 'auto-skip-headers' && rowsVisible;
|
|
226
|
-
// If grid was empty and now has content we need to autosize
|
|
227
|
-
if (rowsVisible !== prevRowsVisibleRef.current && rowsVisible) {
|
|
228
|
-
prevRowsVisibleRef.current = rowsVisible;
|
|
229
|
-
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;
|
|
230
221
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
userSizedColIds: new Set(userSizedColIds.current.keys()),
|
|
236
|
-
});
|
|
237
|
-
// Auto-size failed retry later
|
|
238
|
-
if (!autoSizeResult) {
|
|
222
|
+
|
|
223
|
+
const gridRendered = gridRenderState();
|
|
224
|
+
if (gridRendered === null) {
|
|
225
|
+
// Don't resize until grid has rendered, or it has 0 rows.
|
|
239
226
|
needsAutoSize.current = true;
|
|
240
227
|
return;
|
|
241
228
|
}
|
|
242
229
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
//
|
|
249
|
-
if (
|
|
250
|
-
|
|
251
|
-
|
|
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;
|
|
252
239
|
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
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');
|
|
258
271
|
}
|
|
259
272
|
} else {
|
|
260
|
-
|
|
261
|
-
console.error('Unknown value returned from hasGridRendered');
|
|
273
|
+
sizeColumnsToFit();
|
|
262
274
|
}
|
|
263
|
-
} else {
|
|
264
|
-
console.log('sizeColumnsToFit 3');
|
|
265
|
-
sizeColumnsToFit();
|
|
266
|
-
}
|
|
267
275
|
|
|
268
|
-
|
|
269
|
-
|
|
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
|
-
|
|
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))
|
|
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
|
-
|
|
590
|
-
|
|
591
|
-
|
|
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.
|
|
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) => {
|
|
@@ -853,6 +878,15 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
|
|
|
853
878
|
selectable,
|
|
854
879
|
]);
|
|
855
880
|
|
|
881
|
+
const onGridSizeChanged = useCallback(
|
|
882
|
+
(event: GridSizeChangedEvent<TData>) => {
|
|
883
|
+
if (sizeColumns === 'fit' || (['auto', 'auto-skip-headers'].includes(sizeColumns) && hasSetContentSize.current)) {
|
|
884
|
+
event.api.sizeColumnsToFit();
|
|
885
|
+
}
|
|
886
|
+
},
|
|
887
|
+
[sizeColumns],
|
|
888
|
+
);
|
|
889
|
+
|
|
856
890
|
return (
|
|
857
891
|
<div
|
|
858
892
|
data-testid={dataTestId}
|
|
@@ -874,16 +908,22 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
|
|
|
874
908
|
enableSelectionWithoutKeys: params.enableSelectionWithoutKeys ?? false,
|
|
875
909
|
enableClickSelection: params.enableClickSelection ?? false,
|
|
876
910
|
mode: rowSelection === 'single' ? 'singleRow' : 'multiRow',
|
|
911
|
+
...(params.hideSelectColumn && {
|
|
912
|
+
checkboxes: false,
|
|
913
|
+
headerCheckbox: false,
|
|
914
|
+
}),
|
|
877
915
|
}
|
|
878
916
|
: undefined
|
|
879
917
|
}
|
|
918
|
+
selectionColumnDef={selectionColumnDef}
|
|
880
919
|
rowHeight={rowHeight}
|
|
881
920
|
animateRows={params.animateRows ?? false}
|
|
882
921
|
rowClassRules={params.rowClassRules}
|
|
883
922
|
getRowId={getRowId}
|
|
884
923
|
suppressColumnVirtualisation={suppressColumnVirtualization}
|
|
885
924
|
suppressClickEdit={true}
|
|
886
|
-
|
|
925
|
+
onGridSizeChanged={onGridSizeChanged}
|
|
926
|
+
onColumnVisible={() => void setInitialContentSize()}
|
|
887
927
|
onRowDataUpdated={onRowDataUpdated}
|
|
888
928
|
onCellFocused={onCellFocused}
|
|
889
929
|
onCellKeyDown={onCellKeyPress}
|
|
@@ -894,7 +934,6 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
|
|
|
894
934
|
onColumnResized={onColumnResized}
|
|
895
935
|
defaultColDef={defaultColDef}
|
|
896
936
|
columnDefs={columnDefsAdjusted}
|
|
897
|
-
selectionColumnDef={selectionColumnDef}
|
|
898
937
|
rowData={rowData}
|
|
899
938
|
postSortRows={params.onRowDragEnd || !defaultPostSort ? undefined : postSortRows}
|
|
900
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
|
-
//
|
|
454
|
-
|
|
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
|
-
|
|
457
|
-
gridApi.
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
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
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
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
|
-
{
|
|
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;
|