Compare commits

...
Author SHA1 Message Date
Tanner Linsley 1d34906f29 v7.0.0-beta.24 2019-12-03 09:40:18 -07:00
Tanner Linsley f74e347a06 v7.0.0-beta.23 2019-12-02 16:53:57 -07:00
Tanner Linsley ef29b639bd Update CHANGELOG.md 2019-12-02 16:52:37 -07:00
Tanner Linsley 12b5d05ba2 Fix column resizing 2019-12-02 16:52:10 -07:00
Tanner Linsley f9a6273184 Rename useMain and useBeforeDimensions hooks 2019-12-02 16:12:23 -07:00
Tanner Linsley 83f889dad5 v7.0.0-beta.22 2019-12-02 12:29:46 -07:00
Tanner Linsley 49674a094a Update README.md 2019-12-02 11:18:06 -07:00
18 changed files with 103 additions and 94 deletions
+7 -7
View File
@@ -1,20 +1,20 @@
{
"dist/index.js": {
"bundled": 96409,
"minified": 46532,
"gzipped": 12274
"bundled": 96769,
"minified": 46778,
"gzipped": 12295
},
"dist/index.es.js": {
"bundled": 95844,
"minified": 46040,
"gzipped": 12164,
"bundled": 96204,
"minified": 46286,
"gzipped": 12179,
"treeshaked": {
"rollup": {
"code": 78,
"import_statements": 21
},
"webpack": {
"code": 11105
"code": 11136
}
}
}
+10
View File
@@ -1,3 +1,13 @@
## 7.0.0-beta.23
- The internal `useMain` hook has been renamed to `useInstance`
- The internal `useBeforeDimensions` hook has been renamed to `useInstanceBeforeDimensions`
- Fixed an issue where `useResizeColumns` wasn't working properly
## 7.0.0-beta.22
- Fixed an issue where `useRowState` would crash due to invalid initial state attempting to spread into the new state
## 7.0.0-beta.21
- Removed deprecated `defaultState` export
+17 -24
View File
@@ -37,36 +37,13 @@ Enjoy this library? Try them all! [React Query](https://github.com/tannerlinsley
- Extensible via hook-based plugin system
- <a href="https://medium.com/@tannerlinsley/why-i-wrote-react-table-and-the-problems-it-has-solved-for-nozzle-others-445c4e93d4a8#.axza4ixba" target="\_parent">"Why I wrote React Table and the problems it has solved for Nozzle.io"</a> by Tanner Linsley
## News / Q&A
#### What is the current state of React Table?
React Table v7 is still under active development, and its API is still changing, albeit only slightly. For this reason, it is currently in an **beta** release state. It's estimated that it will be fully released as a stable version sometime during October 2019.
#### Should I use v7@beta in production?
You can use it in production as long as you lock in the beta version in your package.json and also accept that there may be unlikely, but possible bug fixes and/or API changes before it's official release.
#### I'm still using v6, what should I do?
v6 is a great library and is still the default install for `react-table`, however, I do not intend on offering any long-term support for it. If you intend to keep using v6, I recommend maintaining your own fork of the library and keeping it up to date for your version of React.
#### Where are the docs for the older v6 version?
Please [visit the v6 branch](https://github.com/tannerlinsley/react-table/tree/v6)
#### I want to migrate from v6 to v7. How do I do that?
The differences between the 2 versions are incredibly massive. Unfortunately, I cannot write a one-to-one upgrade guide for any of v6's API, simply because much of it is irrelevant with v7's headless approach. The best approach for migrating to v7 is to learn its API by reading the documentation and then following some of the examples to begin building your own table component.
In case you would need to have both v6 and v7 in one app during the migration process (large codebase, complex use cases), you can install an official [`react-table-6` package](https://www.npmjs.com/package/react-table-6) alongside the `react-table`.
## Documentation
- [Installation](./docs/installation.md) - Walk through how to install React Table
- [Concepts](./docs/concepts.md) - Read how React Table works and how you can use it better
- [Examples](./docs/examples.md) - Experience and learn from some examples and guides of how to use React Table and implement common patterns
- [API](./docs/api.md) - Get to know React Table's API, how to use it and how to extend its functionality
- [Using V6 Still?](#v6-info)
- [Contributing](./CONTRIBUTING.md) - Become familiar with how to contribute back to React Table
- [Code of Conduct](./CODE_OF_CONDUCT.md) - Be a good React Table citizen by following these repository rules
@@ -216,3 +193,19 @@ This library is being built and maintained by me, @tannerlinsley and I am always
</table>
### [Become a Sponsor](https://github.com/sponsors/tannerlinsley/)
## v6 Info
#### I'm still using v6, what should I do?
v6 is a great library and while it is still available for use, I do not intend on offering any long-term support for it. If you intend to keep using v6, I recommend maintaining your own fork of the library and keeping it up to date for your version of React.
#### Where are the docs for the older v6 version?
Please [visit the v6 branch](https://github.com/tannerlinsley/react-table/tree/v6)
#### I want to migrate from v6 to v7. How do I do that?
The differences between the 2 versions are incredibly massive. Unfortunately, I cannot write a one-to-one upgrade guide for any of v6's API, simply because much of it is irrelevant with v7's headless approach. The best approach for migrating to v7 is to learn its API by reading the documentation and then following some of the examples to begin building your own table component.
In case you would need to have both v6 and v7 in one app during the migration process (large codebase, complex use cases), you can install an official [`react-table-6` package](https://www.npmjs.com/package/react-table-6) alongside the `react-table`.
+16 -17
View File
@@ -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 }) {
</div>
<div {...getTableBodyProps()}>
{rows.map(
(row, i) => {
prepareRow(row);
return (
<div {...row.getRowProps()} className="tr">
{row.cells.map(cell => {
return (
<div {...cell.getCellProps()} className="td">
{cell.render('Cell')}
</div>
)
})}
</div>
)}
)}
{rows.map((row, i) => {
prepareRow(row)
return (
<div {...row.getRowProps()} className="tr">
{row.cells.map(cell => {
return (
<div {...cell.getCellProps()} className="td">
{cell.render('Cell')}
</div>
)
})}
</div>
)
})}
</div>
</div>
)
Vendored
+1 -1
View File
@@ -75,7 +75,7 @@ export interface UseTableHooks<D extends object> {
columnsBeforeHeaderGroupsDeps: Array<
(deps: any[], instance: TableInstance<D>) => any[]
>
useMain: Array<(instance: TableInstance<D>) => TableInstance<D>>
useInstance: Array<(instance: TableInstance<D>) => TableInstance<D>>
useRows: Array<
(rows: Array<Row<D>>, instance: TableInstance<D>) => Array<Row<D>>
>
+3 -2
View File
@@ -1,6 +1,6 @@
{
"name": "react-table",
"version": "7.0.0-beta.21",
"version": "7.0.0-beta.24",
"description": "A fast, lightweight, opinionated table and datagrid built on React",
"license": "MIT",
"homepage": "https://github.com/tannerlinsley/react-table#readme",
@@ -94,7 +94,8 @@
"rollup-plugin-peer-deps-external": "^2.2.0",
"rollup-plugin-size-snapshot": "^0.10.0",
"rollup-plugin-terser": "^5.1.2",
"snapshot-diff": "^0.6.1"
"snapshot-diff": "^0.6.1",
"typescript": "^3.7.2"
},
"config": {
"commitizen": {
+8 -8
View File
@@ -84,8 +84,8 @@ export const useTable = (props, ...plugins) => {
hooks: {
columnsBeforeHeaderGroups: [],
columnsBeforeHeaderGroupsDeps: [],
useBeforeDimensions: [],
useMain: [],
useInstanceBeforeDimensions: [],
useInstance: [],
useRows: [],
prepareRow: [],
getTableProps: [],
@@ -230,24 +230,24 @@ export const useTable = (props, ...plugins) => {
)
if (process.env.NODE_ENV !== 'production' && debug)
console.time('hooks.useBeforeDimensions')
console.time('hooks.useInstanceBeforeDimensions')
instanceRef.current = applyHooks(
instanceRef.current.hooks.useBeforeDimensions,
instanceRef.current.hooks.useInstanceBeforeDimensions,
instanceRef.current
)
if (process.env.NODE_ENV !== 'production' && debug)
console.timeEnd('hooks.useBeforeDimensions')
console.timeEnd('hooks.useInstanceBeforeDimensions')
calculateDimensions(instanceRef.current)
if (process.env.NODE_ENV !== 'production' && debug)
console.time('hooks.useMain')
console.time('hooks.useInstance')
instanceRef.current = applyHooks(
instanceRef.current.hooks.useMain,
instanceRef.current.hooks.useInstance,
instanceRef.current
)
if (process.env.NODE_ENV !== 'production' && debug)
console.timeEnd('hooks.useMain')
console.timeEnd('hooks.useInstance')
// Each materialized header needs to be assigned a render function and other
// prop getter properties here.
+2 -2
View File
@@ -1,10 +1,10 @@
export const useAbsoluteLayout = hooks => {
hooks.useMain.push(useMain)
hooks.useInstance.push(useInstance)
}
useAbsoluteLayout.pluginName = 'useAbsoluteLayout'
const useMain = instance => {
const useInstance = instance => {
const {
totalColumnsWidth,
hooks: {
+2 -2
View File
@@ -1,10 +1,10 @@
export const useBlockLayout = hooks => {
hooks.useMain.push(useMain)
hooks.useInstance.push(useInstance)
}
useBlockLayout.pluginName = 'useBlockLayout'
const useMain = instance => {
const useInstance = instance => {
const {
totalColumnsWidth,
hooks: { getRowProps, getHeaderGroupProps, getHeaderProps, getCellProps },
+2 -2
View File
@@ -38,7 +38,7 @@ export const useColumnOrder = hooks => {
return [...deps, instance.state.columnOrder]
})
hooks.columnsBeforeHeaderGroups.push(columnsBeforeHeaderGroups)
hooks.useMain.push(useMain)
hooks.useInstance.push(useInstance)
}
useColumnOrder.pluginName = pluginName
@@ -74,7 +74,7 @@ function columnsBeforeHeaderGroups(columns, instance) {
return [...columnsInOrder, ...columnsCopy]
}
function useMain(instance) {
function useInstance(instance) {
const { dispatch } = instance
const setColumnOrder = React.useCallback(
+2 -2
View File
@@ -54,14 +54,14 @@ reducerHandlers[pluginName] = (state, action) => {
export const useExpanded = hooks => {
hooks.getExpandedToggleProps = []
hooks.useMain.push(useMain)
hooks.useInstance.push(useInstance)
}
useExpanded.pluginName = pluginName
const defaultGetResetExpandedDeps = ({ data }) => [data]
function useMain(instance) {
function useInstance(instance) {
const {
debug,
rows,
+2 -2
View File
@@ -109,12 +109,12 @@ reducerHandlers[pluginName] = (state, action) => {
}
export const useFilters = hooks => {
hooks.useMain.push(useMain)
hooks.useInstance.push(useInstance)
}
useFilters.pluginName = pluginName
function useMain(instance) {
function useInstance(instance) {
const {
debug,
rows,
+2 -2
View File
@@ -58,7 +58,7 @@ export const useGroupBy = hooks => {
deps.push(instance.state.groupBy)
return deps
})
hooks.useMain.push(useMain)
hooks.useInstance.push(useInstance)
}
useGroupBy.pluginName = pluginName
@@ -83,7 +83,7 @@ function columnsBeforeHeaderGroups(flatColumns, { state: { groupBy } }) {
const defaultUserAggregations = {}
function useMain(instance) {
function useInstance(instance) {
const {
debug,
rows,
+2 -2
View File
@@ -61,7 +61,7 @@ reducerHandlers[pluginName] = (state, action) => {
}
export const usePagination = hooks => {
hooks.useMain.push(useMain)
hooks.useInstance.push(useInstance)
}
usePagination.pluginName = pluginName
@@ -72,7 +72,7 @@ const defaultGetResetPageDeps = ({
state: { filters, groupBy, sortBy },
}) => [manualPagination ? null : data, filters, groupBy, sortBy]
function useMain(instance) {
function useInstance(instance) {
const {
rows,
manualPagination,
+15 -9
View File
@@ -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,
},
},
}
@@ -80,12 +85,12 @@ reducerHandlers[pluginName] = (state, action) => {
}
export const useResizeColumns = hooks => {
hooks.useBeforeDimensions.push(useBeforeDimensions)
hooks.useInstanceBeforeDimensions.push(useInstanceBeforeDimensions)
}
useResizeColumns.pluginName = pluginName
const useBeforeDimensions = instance => {
const useInstanceBeforeDimensions = instance => {
instance.hooks.getResizerProps = []
const {
@@ -129,6 +134,7 @@ const useBeforeDimensions = instance => {
dispatch({
type: actions.columnStartResizing,
columnId: header.id,
columnWidth: header.totalWidth,
headerIdWidths,
clientX,
})
+2 -2
View File
@@ -118,7 +118,7 @@ export const useRowSelect = hooks => {
hooks.getToggleRowSelectedProps = []
hooks.getToggleAllRowsSelectedProps = []
hooks.useRows.push(useRows)
hooks.useMain.push(useMain)
hooks.useInstance.push(useInstance)
}
useRowSelect.pluginName = pluginName
@@ -147,7 +147,7 @@ function useRows(rows, instance) {
const defaultGetResetSelectedRowPathsDeps = ({ data }) => [data]
function useMain(instance) {
function useInstance(instance) {
const {
hooks,
manualRowSelectedKey = 'isSelected',
+8 -8
View File
@@ -36,21 +36,21 @@ reducerHandlers[pluginName] = (state, action) => {
...state,
rowState: {
...state.rowState,
[pathKey]: functionalUpdate(value, state.rowState[pathKey]),
[pathKey]: functionalUpdate(value, state.rowState[pathKey] || {}),
},
}
}
}
export const useRowState = hooks => {
hooks.useMain.push(useMain)
hooks.useInstance.push(useInstance)
}
useRowState.pluginName = pluginName
const defaultGetResetRowStateDeps = ({ data }) => [data]
function useMain(instance) {
function useInstance(instance) {
const {
hooks,
initialRowStateAccessor,
@@ -71,7 +71,7 @@ function useMain(instance) {
)
const setCellState = React.useCallback(
(rowPath, columnId, updater) => {
(rowPath, columnId, value) => {
return setRowState(
rowPath,
old => {
@@ -79,10 +79,10 @@ function useMain(instance) {
...old,
cellState: {
...old.cellState,
[columnId]:
typeof updater === 'function'
? updater(old.cellState[columnId])
: updater,
[columnId]: functionalUpdate(
value,
old.cellState[columnId] || {}
),
},
}
},
+2 -2
View File
@@ -149,12 +149,12 @@ defaultColumn.sortType = 'alphanumeric'
defaultColumn.sortDescFirst = false
export const useSortBy = hooks => {
hooks.useMain.push(useMain)
hooks.useInstance.push(useInstance)
}
useSortBy.pluginName = pluginName
function useMain(instance) {
function useInstance(instance) {
const {
debug,
rows,