mirror of
https://github.com/gosticks/react-table.git
synced 2026-08-19 08:20:30 +00:00
Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f74e347a06 | ||
|
|
ef29b639bd | ||
|
|
12b5d05ba2 | ||
|
|
f9a6273184 | ||
|
|
83f889dad5 | ||
|
|
49674a094a |
+7
-7
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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`.
|
||||
|
||||
@@ -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
@@ -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>>
|
||||
>
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "react-table",
|
||||
"version": "7.0.0-beta.21",
|
||||
"version": "7.0.0-beta.23",
|
||||
"description": "A fast, lightweight, opinionated table and datagrid built on React",
|
||||
"license": "MIT",
|
||||
"homepage": "https://github.com/tannerlinsley/react-table#readme",
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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: {
|
||||
|
||||
@@ -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 },
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
})
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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] || {}
|
||||
),
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user