diff --git a/.size-snapshot.json b/.size-snapshot.json index c5256ab..4e4c5d5 100644 --- a/.size-snapshot.json +++ b/.size-snapshot.json @@ -1,20 +1,20 @@ { "dist/index.js": { - "bundled": 96601, - "minified": 46726, - "gzipped": 12271 + "bundled": 96769, + "minified": 46778, + "gzipped": 12295 }, "dist/index.es.js": { - "bundled": 96036, - "minified": 46234, - "gzipped": 12155, + "bundled": 96204, + "minified": 46286, + "gzipped": 12179, "treeshaked": { "rollup": { "code": 78, "import_statements": 21 }, "webpack": { - "code": 11109 + "code": 11136 } } } diff --git a/examples/column-resizing/src/App.js b/examples/column-resizing/src/App.js index 41f88f0..4355c4e 100644 --- a/examples/column-resizing/src/App.js +++ b/examples/column-resizing/src/App.js @@ -59,9 +59,9 @@ const Styles = styled.div` function Table({ columns, data }) { const defaultColumn = React.useMemo( () => ({ - minWidth: 20, + minWidth: 30, width: 150, - maxWidth: 500, + maxWidth: 400, }), [] ) @@ -102,21 +102,20 @@ function Table({ columns, data }) {
- {rows.map( - (row, i) => { - prepareRow(row); - return ( -
- {row.cells.map(cell => { - return ( -
- {cell.render('Cell')} -
- ) - })} -
- )} - )} + {rows.map((row, i) => { + prepareRow(row) + return ( +
+ {row.cells.map(cell => { + return ( +
+ {cell.render('Cell')} +
+ ) + })} +
+ ) + })}
) diff --git a/src/plugin-hooks/useResizeColumns.js b/src/plugin-hooks/useResizeColumns.js index 0cc953c..7d069e0 100644 --- a/src/plugin-hooks/useResizeColumns.js +++ b/src/plugin-hooks/useResizeColumns.js @@ -30,14 +30,15 @@ reducerHandlers[pluginName] = (state, action) => { } if (action.type === actions.columnStartResizing) { - const { startX, columnId, headerIdWidths } = action + const { clientX, columnId, columnWidth, headerIdWidths } = action return { ...state, columnResizing: { ...state.columnResizing, - startX, + startX: clientX, headerIdWidths, + columnWidth, isResizingColumn: columnId, }, } @@ -45,14 +46,18 @@ reducerHandlers[pluginName] = (state, action) => { if (action.type === actions.columnResizing) { const { clientX } = action - const { startX, headerIdWidths } = state.columnResizing + const { startX, columnWidth, headerIdWidths } = state.columnResizing const deltaX = clientX - startX - const percentageDeltaX = deltaX / headerIdWidths.length + const percentageDeltaX = deltaX / columnWidth const newColumnWidths = {} - headerIdWidths.forEach(([headerId, headerWidth], index) => { - newColumnWidths[headerId] = Math.max(headerWidth + percentageDeltaX, 0) + + headerIdWidths.forEach(([headerId, headerWidth]) => { + newColumnWidths[headerId] = Math.max( + headerWidth + headerWidth * percentageDeltaX, + 0 + ) }) return { @@ -61,7 +66,7 @@ reducerHandlers[pluginName] = (state, action) => { ...state.columnResizing, columnWidths: { ...state.columnResizing.columnWidths, - ...action.columnWidths, + ...newColumnWidths, }, }, } @@ -129,6 +134,7 @@ const useInstanceBeforeDimensions = instance => { dispatch({ type: actions.columnStartResizing, columnId: header.id, + columnWidth: header.totalWidth, headerIdWidths, clientX, })