@linzjs/step-ag-grid 29.2.0 → 29.2.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/dist/src/components/Grid.d.ts +2 -1
- package/dist/step-ag-grid.cjs +34 -14
- package/dist/step-ag-grid.cjs.map +1 -1
- package/dist/step-ag-grid.esm.js +34 -14
- package/dist/step-ag-grid.esm.js.map +1 -1
- package/package.json +2 -1
- package/src/components/Grid.tsx +42 -13
- package/src/contexts/GridContextProvider.tsx +3 -1
- package/src/stories/grid/gridAutosize/ShowPanelResizingAgGrid/ShowPanelResizingAgGrid.stories.tsx +28 -0
- package/src/stories/grid/gridAutosize/ShowPanelResizingAgGrid/ShowPanelResizingStepAgGrid.tsx +169 -0
|
@@ -84,8 +84,9 @@ export interface GridProps<TData extends GridBaseRow = GridBaseRow> {
|
|
|
84
84
|
pinnedBottomRowData?: GridOptions['pinnedBottomRowData'];
|
|
85
85
|
onRowClicked?: (event: RowClickedEvent) => void;
|
|
86
86
|
onRowDoubleClicked?: (event: RowDoubleClickedEvent) => void;
|
|
87
|
+
allowResizeInStorybook?: boolean;
|
|
87
88
|
}
|
|
88
89
|
/**
|
|
89
90
|
* Wrapper for AgGrid to add commonly used functionality.
|
|
90
91
|
*/
|
|
91
|
-
export declare const Grid: <TData extends GridBaseRow = GridBaseRow>({ "data-testid": dataTestId, defaultPostSort, rowSelection, suppressColumnVirtualization, theme, sizeColumns, selectColumnPinned, contextMenuSelectRow, singleClickEdit, rowData, rowHeight, selectable, onCellFocused: paramsOnCellFocused, ...params }: GridProps<TData>) => ReactElement;
|
|
92
|
+
export declare const Grid: <TData extends GridBaseRow = GridBaseRow>({ "data-testid": dataTestId, defaultPostSort, rowSelection, suppressColumnVirtualization, theme, sizeColumns, selectColumnPinned, contextMenuSelectRow, singleClickEdit, rowData, rowHeight, selectable, allowResizeInStorybook, onCellFocused: paramsOnCellFocused, ...params }: GridProps<TData>) => ReactElement;
|
package/dist/step-ag-grid.cjs
CHANGED
|
@@ -2762,7 +2762,7 @@ agGridCommunity.ModuleRegistry.registerModules([agGridCommunity.AllCommunityModu
|
|
|
2762
2762
|
/**
|
|
2763
2763
|
* Wrapper for AgGrid to add commonly used functionality.
|
|
2764
2764
|
*/
|
|
2765
|
-
const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection = 'multiple', suppressColumnVirtualization = true, theme = 'ag-theme-step-default', sizeColumns = 'auto', selectColumnPinned = 'left', contextMenuSelectRow = false, singleClickEdit = false, rowData, rowHeight = theme === 'ag-theme-step-default' ? 40 : theme === 'ag-theme-step-compact' ? 36 : 40, selectable, onCellFocused: paramsOnCellFocused, ...params }) => {
|
|
2765
|
+
const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection = 'multiple', suppressColumnVirtualization = true, theme = 'ag-theme-step-default', sizeColumns = 'auto', selectColumnPinned = 'left', contextMenuSelectRow = false, singleClickEdit = false, rowData, rowHeight = theme === 'ag-theme-step-default' ? 40 : theme === 'ag-theme-step-compact' ? 36 : 40, selectable, allowResizeInStorybook, onCellFocused: paramsOnCellFocused, ...params }) => {
|
|
2766
2766
|
const { gridReady, gridRenderState, setApis, ensureRowVisible, getFirstRowId, selectRowsById, focusByRowById, ensureSelectedRowIsVisible, autoSizeColumns, sizeColumnsToFit, externallySelectedItemsAreInSync, setExternallySelectedItemsAreInSync, isExternalFilterPresent, doesExternalFilterPass, setOnBulkEditingComplete, getColDef, showNoRowsOverlay, prePopupOps, startCellEditing, } = useGridContext();
|
|
2767
2767
|
const { updatedDep, updatingCols } = React.useContext(GridUpdatingContext);
|
|
2768
2768
|
const gridDivRef = React.useRef(null);
|
|
@@ -2793,7 +2793,11 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
|
|
|
2793
2793
|
}
|
|
2794
2794
|
const skipHeader = sizeColumns === 'auto-skip-headers' && gridRendered === 'rows-visible';
|
|
2795
2795
|
if (sizeColumns === 'auto' || skipHeader) {
|
|
2796
|
-
const result = autoSizeColumns({
|
|
2796
|
+
const result = autoSizeColumns({
|
|
2797
|
+
skipHeader,
|
|
2798
|
+
userSizedColIds: new Set(userSizedColIds.current.keys()),
|
|
2799
|
+
includeFlex: true,
|
|
2800
|
+
});
|
|
2797
2801
|
if (!result) {
|
|
2798
2802
|
needsAutoSize.current = true;
|
|
2799
2803
|
return;
|
|
@@ -2989,7 +2993,11 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
|
|
|
2989
2993
|
return;
|
|
2990
2994
|
const skipHeader = sizeColumns === 'auto-skip-headers';
|
|
2991
2995
|
if (hasSetContentSize.current) {
|
|
2992
|
-
autoSizeColumns({
|
|
2996
|
+
autoSizeColumns({
|
|
2997
|
+
skipHeader,
|
|
2998
|
+
userSizedColIds: new Set(userSizedColIds.current.keys()),
|
|
2999
|
+
colIds: colIdsEdited.current,
|
|
3000
|
+
});
|
|
2993
3001
|
}
|
|
2994
3002
|
colIdsEdited.current.clear();
|
|
2995
3003
|
}, [autoSizeColumns, rowData?.length, setInitialContentSize, sizeColumns, updatedDep, updatingCols]);
|
|
@@ -3087,7 +3095,7 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
|
|
|
3087
3095
|
if (hasSetContentSize.current) {
|
|
3088
3096
|
autoSizeColumns({
|
|
3089
3097
|
skipHeader,
|
|
3090
|
-
userSizedColIds: userSizedColIds.current,
|
|
3098
|
+
userSizedColIds: new Set(userSizedColIds.current.keys()),
|
|
3091
3099
|
colIds: colIdsEdited.current,
|
|
3092
3100
|
});
|
|
3093
3101
|
}
|
|
@@ -3116,25 +3124,36 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
|
|
|
3116
3124
|
/**
|
|
3117
3125
|
* Resize columns to fit if required on window/container resize
|
|
3118
3126
|
*/
|
|
3119
|
-
const onGridSizeChanged = React.useCallback(() => {
|
|
3120
|
-
if (sizeColumns !== 'none') {
|
|
3121
|
-
|
|
3127
|
+
const onGridSizeChanged = React.useCallback((event) => {
|
|
3128
|
+
if (sizeColumns !== 'none' && (!window.__STORYBOOK_PREVIEW__ || allowResizeInStorybook)) {
|
|
3129
|
+
const columnLimits = [
|
|
3130
|
+
...userSizedColIds.current.entries().map(([c, w]) => ({
|
|
3131
|
+
key: c,
|
|
3132
|
+
minWidth: w,
|
|
3133
|
+
})),
|
|
3134
|
+
];
|
|
3135
|
+
event.api.sizeColumnsToFit({ columnLimits });
|
|
3122
3136
|
}
|
|
3123
|
-
}, [
|
|
3137
|
+
}, [allowResizeInStorybook, sizeColumns]);
|
|
3124
3138
|
/**
|
|
3125
3139
|
* Set of column I'd's that are prevented from auto-sizing as they are user set
|
|
3126
3140
|
*/
|
|
3127
|
-
const userSizedColIds = React.useRef(new
|
|
3141
|
+
const userSizedColIds = React.useRef(new Map());
|
|
3128
3142
|
/**
|
|
3129
3143
|
* Lock/unlock column width on user edit/reset.
|
|
3130
3144
|
*/
|
|
3131
3145
|
const onColumnResized = React.useCallback((e) => {
|
|
3132
3146
|
const colId = e.column?.getColId();
|
|
3133
|
-
if (colId == null)
|
|
3147
|
+
if (colId == null) {
|
|
3134
3148
|
return;
|
|
3149
|
+
}
|
|
3150
|
+
const width = e.column?.getActualWidth();
|
|
3151
|
+
if (width == null) {
|
|
3152
|
+
return;
|
|
3153
|
+
}
|
|
3135
3154
|
switch (e.source) {
|
|
3136
|
-
case '
|
|
3137
|
-
userSizedColIds.current.
|
|
3155
|
+
case 'uiColumnResized':
|
|
3156
|
+
userSizedColIds.current.set(colId, width);
|
|
3138
3157
|
break;
|
|
3139
3158
|
case 'autosizeColumns':
|
|
3140
3159
|
userSizedColIds.current.delete(colId);
|
|
@@ -3192,7 +3211,7 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
|
|
|
3192
3211
|
// Prevent repeated callbacks to cell focus when focus didn't change
|
|
3193
3212
|
const { sourceEvent } = event;
|
|
3194
3213
|
if (sourceEvent) {
|
|
3195
|
-
const cell = sourceEvent.target
|
|
3214
|
+
const cell = sourceEvent.target?.closest?.('.ag-cell') ?? null;
|
|
3196
3215
|
if (window.__stepaggrid_lastfocuseventtarget === cell) {
|
|
3197
3216
|
return;
|
|
3198
3217
|
}
|
|
@@ -5417,8 +5436,9 @@ const GridContextProvider = (props) => {
|
|
|
5417
5436
|
* Resize columns to fit container
|
|
5418
5437
|
*/
|
|
5419
5438
|
const autoSizeColumns = React.useCallback(({ skipHeader, colIds, userSizedColIds, includeFlex } = {}) => {
|
|
5420
|
-
if (!gridApi || !gridApi.getColumnState())
|
|
5439
|
+
if (!gridApi || !gridApi.getColumnState()) {
|
|
5421
5440
|
return null;
|
|
5441
|
+
}
|
|
5422
5442
|
const colIdsSet = colIds instanceof Set ? colIds : new Set(colIds);
|
|
5423
5443
|
const colsToResize = gridApi.getColumnState()?.filter?.((colState) => {
|
|
5424
5444
|
const colId = colState.colId;
|