mirror of
https://github.com/gosticks/react-table.git
synced 2026-08-19 16:30:21 +00:00
Compare commits
13
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fb94eaf103 | ||
|
|
409c050cbf | ||
|
|
cee24c74d8 | ||
|
|
499f21c349 | ||
|
|
2a39d5a21c | ||
|
|
36ba233e27 | ||
|
|
c7dfc45e2e | ||
|
|
9dd36263fb | ||
|
|
227f7905b0 | ||
|
|
f1ad032587 | ||
|
|
93703d027c | ||
|
|
75fb61a17f | ||
|
|
7c73a7a631 |
@@ -10,3 +10,4 @@ react-table.css
|
||||
.idea
|
||||
.DS_Store
|
||||
.history
|
||||
package-lock.json
|
||||
|
||||
+13
-2
@@ -1,7 +1,18 @@
|
||||
language: node_js
|
||||
|
||||
node_js:
|
||||
- "10"
|
||||
- 10
|
||||
- 12
|
||||
|
||||
os:
|
||||
- linux
|
||||
- osx
|
||||
- windows
|
||||
|
||||
env:
|
||||
global:
|
||||
- YARN_GPG=no
|
||||
|
||||
cache: yarn
|
||||
|
||||
script: npm test
|
||||
script: yarn test
|
||||
|
||||
@@ -85,7 +85,7 @@ The differences between the 2 versions are incredibly massive. Unfortunately, I
|
||||
**React Table v7** is being built and maintained by me, @tannerlinsley and I am always in need of more Patreon support to keep this project afloat. If you would like to contribute to my Patreon goal for v7 and beyond, [visit my Patreon and help me out!](https://patreon.com/tannerlinsley)
|
||||
|
||||
<table>
|
||||
<tbody {...getTableBodyProps()}>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td align="center" valign="middle">
|
||||
<a href="https://patreon.com/tannerlinsley" target="_blank">
|
||||
@@ -107,7 +107,7 @@ The differences between the 2 versions are incredibly massive. Unfortunately, I
|
||||
</table>
|
||||
|
||||
<table>
|
||||
<tbody {...getTableBodyProps()}>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td align="center" valign="middle">
|
||||
<a href="https://patreon.com/tannerlinsley" target="_blank">
|
||||
@@ -129,7 +129,7 @@ The differences between the 2 versions are incredibly massive. Unfortunately, I
|
||||
</table>
|
||||
|
||||
<table>
|
||||
<tbody {...getTableBodyProps()}>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td align="center" valign="middle">
|
||||
<a href="https://patreon.com/tannerlinsley" target="_blank">
|
||||
@@ -146,7 +146,7 @@ The differences between the 2 versions are incredibly massive. Unfortunately, I
|
||||
</table>
|
||||
|
||||
<table>
|
||||
<tbody {...getTableBodyProps()}>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td valign="top">
|
||||
<a href="https://patreon.com/tannerlinsley">
|
||||
@@ -156,13 +156,14 @@ The differences between the 2 versions are incredibly massive. Unfortunately, I
|
||||
<td>
|
||||
<div><a href="https://www.metso.com/">Pekka</a></div>
|
||||
<div>Jon Eickmeier</div>
|
||||
<div><a href="https://github.com/Shah-Sahab">Syed Hussain<a></div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<table>
|
||||
<tbody {...getTableBodyProps()}>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td valign="top">
|
||||
<a href="https://patreon.com/tannerlinsley">
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
# Using TypeScript with React-Table
|
||||
|
||||
React-table is a very flexible library, because of this, the shape of data at almost every contact point is defined by the specific set of plugins that you choose to pass to `useTable`.
|
||||
|
||||
Tto get started, copy the file `react-table-config.d.ts` into your source tree (e.g. into a types folder). This expands the default types with all of the plugin extensions currently in the type definitions.
|
||||
|
||||
You can stop here if you like, but while this is simple, it's a bit misleading. Out of the box, these types will suggest that you have access to values that come from plugins that you aren't using, i.e. the error checking is weakened.
|
||||
|
||||
To bring the resulting types into better alignment with your plugins, you should edit your local copy of `react-table-config.d.ts` and comment out all of the interfaces that don't apply to your chosen set of plugins.
|
||||
|
||||
e.g.
|
||||
|
||||
if you are only using `useSortBy` and `usePagination` then you would take this:
|
||||
|
||||
```tsx
|
||||
extends UseExpandedOptions<D>,
|
||||
UseFiltersOptions<D>,
|
||||
UseGroupByOptions<D>,
|
||||
UsePaginationOptions<D>,
|
||||
UseRowSelectOptions<D>,
|
||||
UseSortByOptions<D>,
|
||||
UseFiltersOptions<D>,
|
||||
UseResizeColumnsOptions<D>,
|
||||
Record<string, any> {}
|
||||
```
|
||||
|
||||
and convert it to this:
|
||||
|
||||
```tsx
|
||||
export interface TableOptions<D extends object>
|
||||
extends UsePaginationOptions<D>,
|
||||
UseSortByOptions<D> {}
|
||||
```
|
||||
|
||||
Then follow the same pattern for all of the other interfaces in the file. You'll notice that many plugins don't extends all of the top level interfaces.
|
||||
|
||||
## Caveat
|
||||
|
||||
The interfaces are all global. If you have several different configurations for the table, you should create interfaces using the union of all of the plugins that you are using.
|
||||
@@ -465,13 +465,6 @@ The following options are supported via the main options object passed to `useTa
|
||||
- An object of columnID's and their corresponding filter values. This information is stored in state since the table is allowed to manipulate the filter through user interaction.
|
||||
- `initialState.filters`
|
||||
- Identical to the `state.filters` option above
|
||||
- `defaultFilter: String | Function`
|
||||
- If a **function** is passed, it must be **memoized**
|
||||
- Defaults to `text`
|
||||
- The function (or resolved function from the string) will be used as the default/fallback filter method for every column that has filtering enabled.
|
||||
- If a `string` is passed, the function with that name located on the `filterTypes` option object will be used.
|
||||
- If a `function` is passed, it will be used.
|
||||
- For more information on filter types, see Filtering
|
||||
- `manualFilters: Bool`
|
||||
- Enables filter detection functionality, but does not automatically perform row filtering.
|
||||
- Turn this on if you wish to implement your own row filter outside of the table (eg. server-side or manual row grouping/nesting)
|
||||
|
||||
+3
-3
@@ -2,7 +2,7 @@
|
||||
|
||||
## React Table is a "headless" UI library
|
||||
|
||||
React Table is a headless utility, which means out of the box, it doesn't render or supply any actual UI elements. You are in charge of utilizing the state and callbacks of the hooks provided by this library to render your own table markup. [Read this article to understand why React Table is built this way.](https://medium.com/merrickchristensen/headless-user-interface-components-565b0c0f2e18). If you don't want to, then here's a quick rundown anyway:
|
||||
React Table is a headless utility, which means out of the box, it doesn't render or supply any actual UI elements. You are in charge of utilizing the state and callbacks of the hooks provided by this library to render your own table markup. [Read this article to understand why React Table is built this way](https://medium.com/merrickchristensen/headless-user-interface-components-565b0c0f2e18). If you don't want to, then here's a quick rundown anyway:
|
||||
|
||||
- Separation of Concerns - Not that superficial kind you read about all the time. The real kind. React Table as a library honestly has no business being in charge of your UI. The look, feel, and overall experience of your table is what makes your app or product great. The less React Table gets in the way of that, the better!
|
||||
- Maintenance - By removing the massive (and seemingly endless) API surface area required to support every UI use-case, React Table can remain small, easy-to-use and simple to update/maintain.
|
||||
@@ -10,7 +10,7 @@ React Table is a headless utility, which means out of the box, it doesn't render
|
||||
|
||||
## The React Table instance
|
||||
|
||||
At the heart of every React Table is the `useTable` hook and the table `instance` object that it returns. This `instance` object contains everything you'll ever need to build a table and interact with it's state. This includes, but is not limited to:
|
||||
At the heart of every React Table is the `useTable` hook and the table `instance` object that it returns. This `instance` object contains everything you'll ever need to build a table and interact with its state. This includes, but is not limited to:
|
||||
|
||||
- Columns
|
||||
- Materialized Data
|
||||
@@ -23,7 +23,7 @@ At the heart of every React Table is the `useTable` hook and the table `instance
|
||||
|
||||
## Rendering your own UI
|
||||
|
||||
As of React Table v7, **you the developer** are responsible for rendering your own UI, but don't let that intimidate you! Table UI's are fun and React Table makes it so easy to wire up your own table UI. The easiest way to learn how to build your own table UI is to [see some existing React Table examples](./examples.md)!
|
||||
As of React Table v7, **you the developer** are responsible for rendering your own UI, but don't let that intimidate you! Table UIs are fun and React Table makes it so easy to wire up your own table UI. The easiest way to learn how to build your own table UI is to [see some existing React Table examples](./examples.md)!
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import React from 'react'
|
||||
import styled from 'styled-components'
|
||||
import { useTable, usePagination } from 'react-table'
|
||||
import React from "react";
|
||||
import styled from "styled-components";
|
||||
import { useTable, usePagination } from "react-table";
|
||||
|
||||
import makeData from './makeData'
|
||||
import makeData from "./makeData";
|
||||
|
||||
const Styles = styled.div`
|
||||
padding: 1rem;
|
||||
@@ -35,7 +35,7 @@ const Styles = styled.div`
|
||||
.pagination {
|
||||
padding: 0.5rem;
|
||||
}
|
||||
`
|
||||
`;
|
||||
|
||||
// Let's add a fetchData method to our Table component that will be used to fetch
|
||||
// new data when pagination state changes
|
||||
@@ -45,7 +45,7 @@ function Table({
|
||||
data,
|
||||
fetchData,
|
||||
loading,
|
||||
pageCount: controlledPageCount,
|
||||
pageCount: controlledPageCount
|
||||
}) {
|
||||
const {
|
||||
getTableProps,
|
||||
@@ -61,28 +61,30 @@ function Table({
|
||||
nextPage,
|
||||
previousPage,
|
||||
setPageSize,
|
||||
rows,
|
||||
// Get the state from the instance
|
||||
state: { pageIndex, pageSize },
|
||||
state: { pageIndex, pageSize }
|
||||
} = useTable(
|
||||
{
|
||||
columns,
|
||||
data,
|
||||
state: { pageIndex: 0 }, // Pass our hoisted table state
|
||||
initialState: { pageIndex: 0 }, // Pass our hoisted table state
|
||||
manualPagination: true, // Tell the usePagination
|
||||
// hook that we'll handle our own data fetching
|
||||
// This means we'll also have to provide our own
|
||||
// pageCount.
|
||||
pageCount: controlledPageCount,
|
||||
pageCount: controlledPageCount
|
||||
},
|
||||
usePagination
|
||||
)
|
||||
);
|
||||
|
||||
// Now we can get our table state from the hoisted table state tuple
|
||||
|
||||
// Listen for changes in pagination and use the state to fetch our new data
|
||||
React.useEffect(() => {
|
||||
fetchData({ pageIndex, pageSize })
|
||||
}, [fetchData, pageIndex, pageSize])
|
||||
console.log(pageIndex);
|
||||
fetchData({ pageIndex, pageSize });
|
||||
}, [fetchData, pageIndex, pageSize]);
|
||||
|
||||
// Render the UI for your table
|
||||
return (
|
||||
@@ -95,7 +97,7 @@ function Table({
|
||||
pageSize,
|
||||
pageCount,
|
||||
canNextPage,
|
||||
canPreviousPage,
|
||||
canPreviousPage
|
||||
},
|
||||
null,
|
||||
2
|
||||
@@ -107,7 +109,7 @@ function Table({
|
||||
{headerGroups.map(headerGroup => (
|
||||
<tr {...headerGroup.getHeaderGroupProps()}>
|
||||
{headerGroup.headers.map(column => (
|
||||
<th {...column.getHeaderProps()}>{column.render('Header')}</th>
|
||||
<th {...column.getHeaderProps()}>{column.render("Header")}</th>
|
||||
))}
|
||||
</tr>
|
||||
))}
|
||||
@@ -119,18 +121,23 @@ function Table({
|
||||
<tr {...row.getRowProps()}>
|
||||
{row.cells.map(cell => {
|
||||
return (
|
||||
<td {...cell.getCellProps()}>{cell.render('Cell')}</td>
|
||||
)
|
||||
<td {...cell.getCellProps()}>{cell.render("Cell")}</td>
|
||||
);
|
||||
})}
|
||||
</tr>
|
||||
)
|
||||
)}
|
||||
{loading ? (
|
||||
// Use our custom loading state to show a loading indicator
|
||||
<tr>
|
||||
<tr>
|
||||
{loading ? (
|
||||
// Use our custom loading state to show a loading indicator
|
||||
<td>Loading...</td>
|
||||
</tr>
|
||||
) : null}
|
||||
) : (
|
||||
<td>
|
||||
Showing {page.length} of ~{controlledPageCount * pageSize}{" "}
|
||||
results
|
||||
</td>
|
||||
)}
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
{/*
|
||||
@@ -139,39 +146,39 @@ function Table({
|
||||
*/}
|
||||
<div className="pagination">
|
||||
<button onClick={() => gotoPage(0)} disabled={!canPreviousPage}>
|
||||
{'<<'}
|
||||
</button>{' '}
|
||||
{"<<"}
|
||||
</button>{" "}
|
||||
<button onClick={() => previousPage()} disabled={!canPreviousPage}>
|
||||
{'<'}
|
||||
</button>{' '}
|
||||
{"<"}
|
||||
</button>{" "}
|
||||
<button onClick={() => nextPage()} disabled={!canNextPage}>
|
||||
{'>'}
|
||||
</button>{' '}
|
||||
{">"}
|
||||
</button>{" "}
|
||||
<button onClick={() => gotoPage(pageCount - 1)} disabled={!canNextPage}>
|
||||
{'>>'}
|
||||
</button>{' '}
|
||||
{">>"}
|
||||
</button>{" "}
|
||||
<span>
|
||||
Page{' '}
|
||||
Page{" "}
|
||||
<strong>
|
||||
{pageIndex + 1} of {pageOptions.length}
|
||||
</strong>{' '}
|
||||
</strong>{" "}
|
||||
</span>
|
||||
<span>
|
||||
| Go to page:{' '}
|
||||
| Go to page:{" "}
|
||||
<input
|
||||
type="number"
|
||||
defaultValue={pageIndex + 1}
|
||||
onChange={e => {
|
||||
const page = e.target.value ? Number(e.target.value) - 1 : 0
|
||||
gotoPage(page)
|
||||
const page = e.target.value ? Number(e.target.value) - 1 : 0;
|
||||
gotoPage(page);
|
||||
}}
|
||||
style={{ width: '100px' }}
|
||||
style={{ width: "100px" }}
|
||||
/>
|
||||
</span>{' '}
|
||||
</span>{" "}
|
||||
<select
|
||||
value={pageSize}
|
||||
onChange={e => {
|
||||
setPageSize(Number(e.target.value))
|
||||
setPageSize(Number(e.target.value));
|
||||
}}
|
||||
>
|
||||
{[10, 20, 30, 40, 50].map(pageSize => (
|
||||
@@ -182,79 +189,86 @@ function Table({
|
||||
</select>
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Let's simulate a large dataset on the server (outside of our component)
|
||||
const serverData = makeData(10000)
|
||||
const serverData = makeData(10000);
|
||||
|
||||
function App() {
|
||||
const columns = React.useMemo(
|
||||
() => [
|
||||
{
|
||||
Header: 'Name',
|
||||
Header: "Name",
|
||||
columns: [
|
||||
{
|
||||
Header: 'First Name',
|
||||
accessor: 'firstName',
|
||||
Header: "First Name",
|
||||
accessor: "firstName"
|
||||
},
|
||||
{
|
||||
Header: 'Last Name',
|
||||
accessor: 'lastName',
|
||||
},
|
||||
],
|
||||
Header: "Last Name",
|
||||
accessor: "lastName"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
Header: 'Info',
|
||||
Header: "Info",
|
||||
columns: [
|
||||
{
|
||||
Header: 'Age',
|
||||
accessor: 'age',
|
||||
Header: "Age",
|
||||
accessor: "age"
|
||||
},
|
||||
{
|
||||
Header: 'Visits',
|
||||
accessor: 'visits',
|
||||
Header: "Visits",
|
||||
accessor: "visits"
|
||||
},
|
||||
{
|
||||
Header: 'Status',
|
||||
accessor: 'status',
|
||||
Header: "Status",
|
||||
accessor: "status"
|
||||
},
|
||||
{
|
||||
Header: 'Profile Progress',
|
||||
accessor: 'progress',
|
||||
},
|
||||
],
|
||||
},
|
||||
Header: "Profile Progress",
|
||||
accessor: "progress"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
[]
|
||||
)
|
||||
);
|
||||
|
||||
// We'll start our table without any data
|
||||
const [data, setData] = React.useState([])
|
||||
const [loading, setLoading] = React.useState(false)
|
||||
const [pageCount, setPageCount] = React.useState(0)
|
||||
const [data, setData] = React.useState([]);
|
||||
const [loading, setLoading] = React.useState(false);
|
||||
const [pageCount, setPageCount] = React.useState(0);
|
||||
const fetchIdRef = React.useRef(0);
|
||||
|
||||
const fetchData = React.useCallback(({ pageSize, pageIndex }) => {
|
||||
// This will get called when the table needs new data
|
||||
// You could fetch your data from literally anywhere,
|
||||
// even a server. But for this example, we'll just fake it.
|
||||
|
||||
// Give this fetch an ID
|
||||
const fetchID = ++fetchIdRef.current;
|
||||
|
||||
// Set the loading state
|
||||
setLoading(true)
|
||||
setLoading(true);
|
||||
|
||||
// We'll even set a delay to simulate a server here
|
||||
setTimeout(() => {
|
||||
const startRow = pageSize * pageIndex
|
||||
const endRow = startRow + pageSize
|
||||
setData(serverData.slice(startRow, endRow))
|
||||
// Only update the data if this is the latest fetch
|
||||
if (fetchID === fetchIdRef.current) {
|
||||
const startRow = pageSize * pageIndex;
|
||||
const endRow = startRow + pageSize;
|
||||
setData(serverData.slice(startRow, endRow));
|
||||
|
||||
// Your server could send back total page count.
|
||||
// For now we'll just fake it, too
|
||||
setPageCount(Math.ceil(serverData.length / pageSize))
|
||||
// Your server could send back total page count.
|
||||
// For now we'll just fake it, too
|
||||
setPageCount(Math.ceil(serverData.length / pageSize));
|
||||
|
||||
setLoading(false)
|
||||
}, 1000)
|
||||
}, [])
|
||||
setLoading(false);
|
||||
}
|
||||
}, 1000);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<Styles>
|
||||
@@ -266,7 +280,7 @@ function App() {
|
||||
pageCount={pageCount}
|
||||
/>
|
||||
</Styles>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
export default App
|
||||
export default App;
|
||||
|
||||
Vendored
+615
-266
@@ -1,281 +1,630 @@
|
||||
declare module 'react-table' {
|
||||
import { ReactNode, useState } from 'react'
|
||||
// TypeScript Version: 3.5
|
||||
|
||||
type StringKey<D> = Extract<keyof D, string>
|
||||
type IdType<D> = StringKey<D> | string
|
||||
import { ReactNode, ComponentType, MouseEvent } from 'react'
|
||||
|
||||
type SortingRule<D> = {
|
||||
id: IdType<D>
|
||||
desc: boolean
|
||||
}
|
||||
/**
|
||||
* The empty definitions of below provides a base definition for the parts used by useTable, that can then be extended in the users code.
|
||||
*
|
||||
* @example
|
||||
* export interface TableOptions<D extends object = {}}>
|
||||
* extends
|
||||
* UseExpandedOptions<D>,
|
||||
* UseFiltersOptions<D> {}
|
||||
*/
|
||||
export interface TableOptions<D extends object> extends UseTableOptions<D> {}
|
||||
|
||||
export type SortingRules<D> = SortingRule<D>[]
|
||||
export interface TableInstance<D extends object = {}>
|
||||
extends Omit<TableOptions<D>, 'columns' | 'state'>,
|
||||
UseTableInstanceProps<D> {}
|
||||
|
||||
export type SortByFn = (a: any, b: any, desc: boolean) => 0 | 1 | -1
|
||||
export interface TableState<
|
||||
D extends object = {}
|
||||
> {} /* tslint:disable-line no-empty-interface */ // eslint-disable-line @typescript-eslint/no-empty-interface
|
||||
|
||||
export type Filters<D> = Record<IdType<D>, string>
|
||||
export interface Hooks<D extends object = {}> extends UseTableHooks<D> {}
|
||||
|
||||
export interface Cell<D = {}> extends TableInstance<D> {
|
||||
cell: { value: any }
|
||||
column: Column<D>
|
||||
row: Row<D>
|
||||
render: (type: 'Cell' | 'Aggregated', userProps?: any) => any
|
||||
isGrouped?: boolean
|
||||
isAggregated?: boolean
|
||||
isRepeatedValue?: boolean
|
||||
getCellProps: () => any
|
||||
}
|
||||
export interface Cell<D extends object = {}> extends UseTableCellProps<D> {}
|
||||
|
||||
export interface Row<D = {}> {
|
||||
index: number
|
||||
cells: Cell<D>[]
|
||||
getRowProps: (userProps?: any) => any
|
||||
original: D
|
||||
path: any[]
|
||||
values: any[]
|
||||
depth: number
|
||||
}
|
||||
export interface Column<D extends object = {}>
|
||||
extends UseTableColumnOptions<D> {}
|
||||
|
||||
export interface UseExpandedRow<D = {}> {
|
||||
subRows?: D[]
|
||||
groupByID?: string | number
|
||||
toggleExpanded?: () => any
|
||||
isExpanded?: boolean
|
||||
isAggregated?: boolean
|
||||
}
|
||||
export interface ColumnInstance<D extends object = {}>
|
||||
extends Omit<Column<D>, 'id'>,
|
||||
UseTableColumnProps<D> {}
|
||||
|
||||
export type AccessorFn<D> = (
|
||||
originalRow: D,
|
||||
index: number,
|
||||
sub: {
|
||||
subRows: [D]
|
||||
depth: number
|
||||
data: [D]
|
||||
}
|
||||
) => unknown
|
||||
export interface HeaderGroup<D extends object = {}>
|
||||
extends ColumnInstance<D>,
|
||||
UseTableHeaderGroupProps<D> {}
|
||||
|
||||
export interface HeaderColumn<D> {
|
||||
/**
|
||||
* This string/function is used to build the data model for your column.
|
||||
*/
|
||||
accessor: IdType<D> | AccessorFn<D>
|
||||
Header?: ReactNode | ((props: TableInstance<D>) => ReactNode)
|
||||
Filter?: ReactNode | ((props: TableInstance<D>) => ReactNode)
|
||||
Cell?: ReactNode | ((cell: Cell<D>) => ReactNode)
|
||||
/**
|
||||
* This is the unique ID for the column. It is used by reference in things like sorting, grouping, filtering etc.
|
||||
*/
|
||||
id?: IdType<D>
|
||||
minWidth?: string | number
|
||||
maxWidth?: string | number
|
||||
width?: string | number
|
||||
disableSorting?: boolean
|
||||
canSortBy?: boolean
|
||||
sortByFn?: SortByFn
|
||||
defaultSortDesc?: boolean
|
||||
isAggregated?: any
|
||||
}
|
||||
export interface Row<D extends object = {}> extends UseTableRowProps<D> {}
|
||||
|
||||
export interface Column<D> extends HeaderColumn<D> {
|
||||
show?: boolean | ((instance: TableInstance<D>) => boolean)
|
||||
columns?: Column<D>[]
|
||||
}
|
||||
/* #region useTable */
|
||||
export function useTable<D extends object = {}>(
|
||||
options: TableOptions<D>,
|
||||
...plugins: PluginHook<D>[]
|
||||
): TableInstance<D>
|
||||
|
||||
export type Page<D = {}> = Row<D>[]
|
||||
/**
|
||||
* NOTE: To use custom options, use "Interface Merging" to add the custom options
|
||||
*/
|
||||
export type UseTableOptions<D extends object> = {
|
||||
columns: Column<D>[]
|
||||
data: D[]
|
||||
} & Partial<{
|
||||
initialState: Partial<TableState<D>>
|
||||
state: Partial<TableState<D>>
|
||||
reducer: (
|
||||
oldState: TableState<D>,
|
||||
newState: TableState<D>,
|
||||
type: string
|
||||
) => TableState<D>
|
||||
defaultColumn: Partial<Column<D>>
|
||||
initialRowStateKey: IdType<D>
|
||||
getSubRows: (row: Row<D>, relativeIndex: number) => Row<D>[]
|
||||
getRowID: (row: Row<D>, relativeIndex: number) => string
|
||||
debug: boolean
|
||||
}>
|
||||
|
||||
export interface EnhancedColumn<D>
|
||||
extends Omit<Column<D>, 'columns'>,
|
||||
TableInstance<D> {
|
||||
id: IdType<D>
|
||||
column: Column<D>
|
||||
render: (type: 'Header' | 'Filter', userProps?: any) => any
|
||||
getHeaderProps: (userProps?: any) => any
|
||||
getSortByToggleProps: (userProps?: any) => any
|
||||
isSorted: boolean
|
||||
isSortedDesc: boolean
|
||||
sortedIndex: number
|
||||
isVisible: boolean
|
||||
canSort?: boolean
|
||||
}
|
||||
export interface UseTableHooks<D extends object> {
|
||||
columnsBeforeHeaderGroups: ((
|
||||
flatColumns: Column<D>[],
|
||||
instance: TableInstance<D>
|
||||
) => Column<D>[])[]
|
||||
columnsBeforeHeaderGroupsDeps: ((
|
||||
deps: any[],
|
||||
instance: TableInstance<D>
|
||||
) => any[])[]
|
||||
useMain: ((instance: TableInstance<D>) => TableInstance<D>)[]
|
||||
useRows: ((rows: Row<D>[], instance: TableInstance<D>) => Row<D>[])[]
|
||||
prepareRow: ((row: Row<D>, instance: TableInstance<D>) => Row<D>)[]
|
||||
|
||||
export interface HeaderGroup<D = {}> {
|
||||
headers: EnhancedColumn<D>[]
|
||||
getHeaderGroupProps: (userProps?: any) => any
|
||||
}
|
||||
|
||||
export interface Hooks {
|
||||
columnsBeforeHeaderGroups: any[]
|
||||
columnsBeforeHeaderGroupsDeps: any[]
|
||||
useMain: any[]
|
||||
useColumns: any[]
|
||||
useHeaders: any[]
|
||||
useHeaderGroups: any[]
|
||||
useRows: any[]
|
||||
prepareRow: any[]
|
||||
getTableProps: any[]
|
||||
getRowProps: any[]
|
||||
getHeaderGroupProps: any[]
|
||||
getHeaderProps: any[]
|
||||
getCellProps: any[]
|
||||
}
|
||||
|
||||
export interface RowsProps {
|
||||
subRowsKey: string
|
||||
}
|
||||
|
||||
export interface FiltersProps {
|
||||
filterFn: () => void
|
||||
manualFilters: boolean
|
||||
disableFilters: boolean
|
||||
setFilter: () => any
|
||||
setAllFilters: () => any
|
||||
}
|
||||
|
||||
export interface UsePaginationState {
|
||||
pageIndex: number
|
||||
pageSize: number
|
||||
pageCount: number
|
||||
rowCount: number
|
||||
}
|
||||
|
||||
export interface UsePaginationValues<D = {}> {
|
||||
page: Page<D>
|
||||
pageIndex: number // yes, this is on instance and state
|
||||
pageSize: number // yes, this is on instance and state
|
||||
canPreviousPage: boolean
|
||||
canNextPage: boolean
|
||||
nextPage: () => any
|
||||
previousPage: () => any
|
||||
setPageSize: (size: number) => any
|
||||
pageOptions: any[]
|
||||
manualPagination: boolean
|
||||
paginateExpandedRows: boolean
|
||||
disablePageResetOnDataChange: boolean
|
||||
pageCount: number
|
||||
gotoPage: (page: number) => any
|
||||
}
|
||||
|
||||
export interface UseFiltersState<D> {
|
||||
filters?: Filters<D>
|
||||
}
|
||||
|
||||
export interface UseFiltersValues<D> {
|
||||
setFilter: (columnID: keyof D, value: string) => void
|
||||
setAllFilters: (values: Filters<D>) => void
|
||||
disableFilters: boolean
|
||||
}
|
||||
|
||||
export interface UseGroupByValues {
|
||||
groupByFn: any
|
||||
manualGroupBy: boolean
|
||||
disableGrouping: boolean
|
||||
aggregations: any
|
||||
}
|
||||
|
||||
export interface UseGroupByState {
|
||||
groupBy: string[]
|
||||
isAggregated?: boolean
|
||||
}
|
||||
|
||||
export interface UseExpandedValues {
|
||||
toggleExpanded?: () => any
|
||||
}
|
||||
|
||||
export interface UseSortbyOptions {
|
||||
sortByFn?: SortByFn
|
||||
manualSorting?: boolean
|
||||
disableSorting?: boolean
|
||||
defaultSortDesc?: boolean
|
||||
disableMultiSort?: boolean
|
||||
}
|
||||
|
||||
export interface UseSortbyState<D> {
|
||||
sortBy?: SortingRules<D>
|
||||
}
|
||||
|
||||
export interface TableInstance<D = {}> extends TableOptions<D> {
|
||||
hooks: Hooks
|
||||
rows: Row<D>[]
|
||||
columns: EnhancedColumn<D>[]
|
||||
headerGroups: HeaderGroup<D>[]
|
||||
headers: HeaderGroup<D>[]
|
||||
getTableProps: (userProps?: any) => any
|
||||
getRowProps: (userProps?: any) => any
|
||||
prepareRow: (row: Row<D>) => any
|
||||
state: TableState<D>
|
||||
setState: SetState<D>
|
||||
}
|
||||
|
||||
export interface TableOptions<D = {}> {
|
||||
data: D[]
|
||||
columns: HeaderColumn<D>[]
|
||||
debug?: boolean
|
||||
loading: boolean
|
||||
defaultColumn?: Partial<Column<D>>
|
||||
initialState?: Partial<TableState<D>>
|
||||
state?: Partial<TableState<D>>
|
||||
reducer?: (
|
||||
oldState: TableState<D>,
|
||||
newState: TableState<D>,
|
||||
type: string
|
||||
) => any
|
||||
}
|
||||
|
||||
// The empty definition of TableState is not an error. It provides a definition
|
||||
// for the state, that can then be extended in the users code.
|
||||
//
|
||||
// e.g.
|
||||
//
|
||||
// export interface TableState<D = {}}>
|
||||
// extends UsePaginationState,
|
||||
// UseGroupByState,
|
||||
// UseSortbyState<D>,
|
||||
// UseFiltersState<D> {}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
||||
export interface TableState<D = {}> {}
|
||||
|
||||
export type SetState<D> = (
|
||||
updater: (old: TableState<D>) => TableState<D>,
|
||||
actions: any
|
||||
) => void
|
||||
|
||||
export function useTable<D = {}>(
|
||||
props: TableOptions<D>,
|
||||
...plugins: any[]
|
||||
): TableInstance<D>
|
||||
|
||||
export function useFilters<D = {}>(
|
||||
props: TableOptions<D>
|
||||
): TableOptions<D> & {
|
||||
rows: Row<D>[]
|
||||
}
|
||||
|
||||
export function useSortBy<D = {}>(
|
||||
props: TableOptions<D>
|
||||
): TableOptions<D> & {
|
||||
rows: Row<D>[]
|
||||
}
|
||||
|
||||
export function useGroupBy<D = {}>(
|
||||
props: TableOptions<D>
|
||||
): TableOptions<D> & { rows: Row<D>[] }
|
||||
|
||||
export function usePagination<D = {}>(
|
||||
props: TableOptions<D>
|
||||
): UsePaginationValues<D>
|
||||
|
||||
export function useExpanded<D = {}>(
|
||||
props: TableOptions<D>
|
||||
): TableOptions<D> & {
|
||||
toggleExpandedByPath: () => any
|
||||
expandedDepth: []
|
||||
rows: Row<D>[]
|
||||
}
|
||||
|
||||
export const actions: Record<string, string>
|
||||
|
||||
export function addActions(...actions: string[]): void
|
||||
|
||||
export const defaultState: Record<string, any>
|
||||
// Prop Hooks
|
||||
getTableProps: ((instance: TableInstance<D>) => object)[]
|
||||
getTableBodyProps: ((instance: TableInstance<D>) => object)[]
|
||||
getRowProps: ((row: Row<D>, instance: TableInstance<D>) => object)[]
|
||||
getHeaderGroupProps: ((
|
||||
headerGroup: HeaderGroup<D>,
|
||||
instance: TableInstance<D>
|
||||
) => object)[]
|
||||
getHeaderProps: ((column: Column<D>, instance: TableInstance<D>) => object)[]
|
||||
getCellProps: ((cell: Cell<D>, instance: TableInstance<D>) => object)[]
|
||||
}
|
||||
|
||||
export interface UseTableColumnOptions<D extends object>
|
||||
extends Accessor<D>,
|
||||
Partial<{
|
||||
columns: Column<D>[]
|
||||
show: boolean | ((instance: TableInstance<D>) => boolean)
|
||||
Header: Renderer<HeaderProps<D>>
|
||||
Cell: Renderer<CellProps<D>>
|
||||
width?: number
|
||||
minWidth?: number
|
||||
maxWidth?: number
|
||||
}> {}
|
||||
|
||||
export interface UseTableInstanceProps<D extends object> {
|
||||
columns: ColumnInstance<D>[]
|
||||
flatColumns: ColumnInstance<D>[]
|
||||
headerGroups: HeaderGroup<D>[]
|
||||
headers: ColumnInstance<D>[]
|
||||
flatHeaders: ColumnInstance<D>[]
|
||||
rows: Row<D>[]
|
||||
getTableProps: (props?: object) => object
|
||||
getTableBodyProps: (props?: object) => object
|
||||
prepareRow: (row: Row<D>) => void
|
||||
rowPaths: string[]
|
||||
flatRows: Row<D>[]
|
||||
state: TableState<D>
|
||||
setState: SetState<D>
|
||||
totalColumnsWidth: number
|
||||
}
|
||||
|
||||
export interface UseTableHeaderGroupProps<D extends object> {
|
||||
headers: ColumnInstance<D>[]
|
||||
getHeaderGroupProps: (props?: object) => object
|
||||
totalHeaderCount: number
|
||||
}
|
||||
|
||||
export interface UseTableColumnProps<D extends object> {
|
||||
id: IdType<D>
|
||||
isVisible: boolean
|
||||
render: (type: 'Header' | string, props?: object) => ReactNode
|
||||
getHeaderProps: (props?: object) => object
|
||||
parent: ColumnInstance<D>
|
||||
depth: number
|
||||
index: number
|
||||
}
|
||||
|
||||
export interface UseTableRowProps<D extends object> {
|
||||
cells: Cell<D>[]
|
||||
values: Record<IdType<D>, CellValue>
|
||||
getRowProps: (props?: object) => object
|
||||
index: number
|
||||
original: D
|
||||
path: IdType<D>[]
|
||||
subRows: Row<D>[]
|
||||
}
|
||||
|
||||
export interface UseTableCellProps<D extends object> {
|
||||
column: ColumnInstance<D>
|
||||
row: Row<D>
|
||||
value: CellValue
|
||||
getCellProps: (props?: object) => object
|
||||
render: (type: 'Cell' | string, userProps?: object) => ReactNode
|
||||
}
|
||||
|
||||
export type HeaderProps<D extends object> = TableInstance<D> & {
|
||||
column: ColumnInstance<D>
|
||||
} & Record<string, any>
|
||||
export type CellProps<D extends object> = TableInstance<D> & {
|
||||
column: ColumnInstance<D>
|
||||
row: Row<D>
|
||||
cell: Cell<D>
|
||||
} & Record<string, any>
|
||||
|
||||
// NOTE: At least one of (id | accessor | Header as string) required
|
||||
export interface Accessor<D extends object> {
|
||||
accessor?:
|
||||
| IdType<D>
|
||||
| ((
|
||||
originalRow: D,
|
||||
index: number,
|
||||
sub: {
|
||||
subRows: D[]
|
||||
depth: number
|
||||
data: D[]
|
||||
}
|
||||
) => CellValue)
|
||||
id?: IdType<D>
|
||||
}
|
||||
/* #endregion */
|
||||
|
||||
// Plugins
|
||||
|
||||
/* #region useColumnOrder */
|
||||
export function useColumnOrder<D extends object = {}>(hooks: Hooks<D>): void
|
||||
export namespace useColumnOrder {
|
||||
const pluginName = 'useColumnOrder'
|
||||
}
|
||||
|
||||
export interface UseColumnOrderState<D extends object> {
|
||||
columnOrder: IdType<D>[]
|
||||
}
|
||||
|
||||
export interface UseColumnOrderInstanceProps<D extends object> {
|
||||
setColumnOrder: (updater: (columnOrder: IdType<D>[]) => IdType<D>[]) => void
|
||||
}
|
||||
/* #endregion */
|
||||
|
||||
/* #region useExpanded */
|
||||
export function useExpanded<D extends object = {}>(hooks: Hooks<D>): void
|
||||
export namespace useExpanded {
|
||||
const pluginName = 'useExpanded'
|
||||
}
|
||||
|
||||
export type UseExpandedOptions<D extends object> = Partial<{
|
||||
getSubRows: (row: Row<D>, relativeIndex: number) => Row<D>[]
|
||||
manualExpandedKey: IdType<D>
|
||||
paginateExpandedRows: boolean
|
||||
}>
|
||||
|
||||
export interface UseExpandedHooks<D extends object> {
|
||||
getExpandedToggleProps: ((
|
||||
row: Row<D>,
|
||||
instance: TableInstance<D>
|
||||
) => object)[]
|
||||
}
|
||||
|
||||
export interface UseExpandedState<D extends object> {
|
||||
expanded: IdType<D>[]
|
||||
}
|
||||
|
||||
export interface UseExpandedInstanceProps<D extends object> {
|
||||
rows: Row<D>[]
|
||||
toggleExpandedByPath: (path: IdType<D>[], isExpanded: boolean) => void
|
||||
expandedDepth: number
|
||||
}
|
||||
|
||||
export interface UseExpandedRowProps<D extends object> {
|
||||
isExpanded: boolean
|
||||
canExpand: boolean
|
||||
subRows: Row<D>[]
|
||||
toggleExpanded: (isExpanded?: boolean) => void
|
||||
getExpandedToggleProps: (props?: object) => object
|
||||
}
|
||||
/* #endregion */
|
||||
|
||||
/* #region useFilters */
|
||||
export function useFilters<D extends object = {}>(hooks: Hooks<D>): void
|
||||
export namespace useFilters {
|
||||
const pluginName = 'useFilters'
|
||||
}
|
||||
|
||||
export type UseFiltersOptions<D extends object> = Partial<{
|
||||
manualFilters: boolean
|
||||
disableFilters: boolean
|
||||
filterTypes: Filters<D>
|
||||
}>
|
||||
|
||||
export interface UseFiltersState<D extends object> {
|
||||
filters: Filters<D>
|
||||
}
|
||||
|
||||
export type UseFiltersColumnOptions<D extends object> = Partial<{
|
||||
disableFilters: boolean
|
||||
Filter: Renderer<FilterProps<D>>
|
||||
filter: FilterType<D> | DefaultFilterTypes | keyof Filters<D>
|
||||
}>
|
||||
|
||||
export interface UseFiltersInstanceProps<D extends object> {
|
||||
rows: Row<D>[]
|
||||
preFilteredRows: Row<D>[]
|
||||
setFilter: (
|
||||
columnId: IdType<D>,
|
||||
updater: ((filterValue: FilterValue) => FilterValue) | FilterValue
|
||||
) => void
|
||||
setAllFilters: (
|
||||
updater: Filters<D> | ((filters: Filters<D>) => Filters<D>)
|
||||
) => void
|
||||
}
|
||||
|
||||
export interface UseFiltersColumnProps<D extends object> {
|
||||
canFilter: boolean
|
||||
setFilter: (
|
||||
updater: ((filterValue: FilterValue) => FilterValue) | FilterValue
|
||||
) => void
|
||||
filterValue: FilterValue
|
||||
preFilteredRows: Row<D>[]
|
||||
filteredRows: Row<D>[]
|
||||
}
|
||||
|
||||
export type FilterProps<D extends object> = HeaderProps<D>
|
||||
export type FilterValue = any
|
||||
export type Filters<D extends object> = Record<IdType<D>, FilterValue>
|
||||
|
||||
export type DefaultFilterTypes =
|
||||
| 'text'
|
||||
| 'exactText'
|
||||
| 'exactTextCase'
|
||||
| 'includes'
|
||||
| 'includesAll'
|
||||
| 'exact'
|
||||
| 'equals'
|
||||
| 'between'
|
||||
|
||||
export interface FilterType<D extends object> {
|
||||
(
|
||||
rows: Row<D>[],
|
||||
columnId: IdType<D>,
|
||||
filterValue: FilterValue,
|
||||
column: ColumnInstance<D>
|
||||
): Row<D>[]
|
||||
autoRemove?: (filterValue: FilterValue) => boolean
|
||||
}
|
||||
/* #endregion */
|
||||
|
||||
/* #region useGroupBy */
|
||||
export function useGroupBy<D extends object = {}>(hooks: Hooks<D>): void
|
||||
export namespace useGroupBy {
|
||||
const pluginName = 'useGroupBy'
|
||||
}
|
||||
|
||||
export type UseGroupByOptions<D extends object> = Partial<{
|
||||
manualGroupBy: boolean
|
||||
disableGrouping: boolean
|
||||
aggregations: Record<string, AggregatorFn<D>>
|
||||
groupByFn: (rows: Row<D>[], columnId: IdType<D>) => Record<string, Row<D>>
|
||||
}>
|
||||
|
||||
export interface UseGroupByHooks<D extends object> {
|
||||
getGroupByToggleProps: ((
|
||||
header: HeaderGroup<D>,
|
||||
instance: TableInstance<D>
|
||||
) => object)[]
|
||||
}
|
||||
|
||||
export interface UseGroupByState<D extends object> {
|
||||
groupBy: IdType<D>[]
|
||||
}
|
||||
|
||||
export type UseGroupByColumnOptions<D extends object> = Partial<{
|
||||
aggregate: Aggregator<D> | Aggregator<D>[]
|
||||
Aggregated: Renderer<CellProps<D>>
|
||||
disableGrouping: boolean
|
||||
groupByBoundary: boolean
|
||||
}>
|
||||
|
||||
export interface UseGroupByInstanceProps<D extends object> {
|
||||
rows: Row<D>[]
|
||||
preGroupedRows: Row<D>[]
|
||||
toggleGroupBy: (columnId: IdType<D>, toggle: boolean) => void
|
||||
}
|
||||
|
||||
export interface UseGroupByColumnProps<D extends object> {
|
||||
canGroupBy: boolean
|
||||
isGrouped: boolean
|
||||
groupedIndex: number
|
||||
toggleGroupBy: () => void
|
||||
}
|
||||
|
||||
export interface UseGroupByHeaderProps<D extends object> {
|
||||
getGroupByToggleProps: (props?: object) => object
|
||||
}
|
||||
|
||||
export interface UseGroupByRowProps<D extends object> {
|
||||
isAggregated: boolean
|
||||
groupByID: IdType<D>
|
||||
groupByVal: string
|
||||
values: Record<IdType<D>, AggregatedValue>
|
||||
subRows: Row<D>[]
|
||||
depth: number
|
||||
path: IdType<D>[]
|
||||
index: number
|
||||
}
|
||||
|
||||
export interface UseGroupByCellProps<D extends object> {
|
||||
isGrouped: boolean
|
||||
isRepeatedValue: boolean
|
||||
isAggregated: boolean
|
||||
}
|
||||
|
||||
export type DefaultAggregators =
|
||||
| 'sum'
|
||||
| 'average'
|
||||
| 'median'
|
||||
| 'uniqueCount'
|
||||
| 'count'
|
||||
|
||||
export type AggregatorFn<D extends object> = (
|
||||
columnValues: CellValue[],
|
||||
rows: Row<D>[]
|
||||
) => AggregatedValue
|
||||
export type Aggregator<D extends object> =
|
||||
| AggregatorFn<D>
|
||||
| DefaultAggregators
|
||||
| string
|
||||
export type AggregatedValue = any
|
||||
/* #endregion */
|
||||
|
||||
/* #region usePagination */
|
||||
export function usePagination<D extends object = {}>(hooks: Hooks<D>): void
|
||||
export namespace usePagination {
|
||||
const pluginName = 'usePagination'
|
||||
}
|
||||
|
||||
export type UsePaginationOptions<D extends object> = Partial<{
|
||||
pageCount: number
|
||||
manualPagination: boolean
|
||||
disablePageResetOnDataChange: boolean
|
||||
paginateExpandedRows: boolean
|
||||
}>
|
||||
|
||||
export interface UsePaginationState<D extends object> {
|
||||
pageSize: number
|
||||
pageIndex: number
|
||||
}
|
||||
|
||||
export interface UsePaginationInstanceProps<D extends object> {
|
||||
page: Row<D>[]
|
||||
pageCount: number
|
||||
pageOptions: number[]
|
||||
canPreviousPage: boolean
|
||||
canNextPage: boolean
|
||||
gotoPage: (updater: ((pageIndex: number) => number) | number) => void
|
||||
previousPage: () => void
|
||||
nextPage: () => void
|
||||
setPageSize: (pageSize: number) => void
|
||||
pageIndex: number
|
||||
pageSize: number
|
||||
}
|
||||
/* #endregion */
|
||||
|
||||
/* #region useRowSelect */
|
||||
export function useRowSelect<D extends object = {}>(hooks: Hooks<D>): void
|
||||
export namespace useRowSelect {
|
||||
const pluginName = 'useRowSelect'
|
||||
}
|
||||
|
||||
export type UseRowSelectOptions<D extends object> = Partial<{
|
||||
manualRowSelectedKey: IdType<D>
|
||||
}>
|
||||
|
||||
export interface UseRowSelectHooks<D extends object> {
|
||||
getToggleRowSelectedProps: ((
|
||||
row: Row<D>,
|
||||
instance: TableInstance<D>
|
||||
) => object)[]
|
||||
getToggleAllRowsSelectedProps: ((instance: TableInstance<D>) => object)[]
|
||||
}
|
||||
|
||||
export interface UseRowSelectState<D extends object> {
|
||||
selectedRows: IdType<D>[]
|
||||
}
|
||||
|
||||
export interface UseRowSelectInstanceProps<D extends object> {
|
||||
toggleRowSelected: (rowPath: IdType<D>, set?: boolean) => void
|
||||
toggleRowSelectedAll: (set?: boolean) => void
|
||||
getToggleAllRowsSelectedProps: (props?: object) => object
|
||||
isAllRowsSelected: boolean
|
||||
}
|
||||
|
||||
export interface UseRowSelectRowProps<D extends object> {
|
||||
isSelected: boolean
|
||||
toggleRowSelected: (set?: boolean) => void
|
||||
getToggleRowSelectedProps: (props?: object) => object
|
||||
}
|
||||
/* #endregion */
|
||||
|
||||
/* #region useRowState */
|
||||
export function useRowState<D extends object = {}>(hooks: Hooks<D>): void
|
||||
export namespace useRowState {
|
||||
const pluginName = 'useRowState'
|
||||
}
|
||||
|
||||
export type UseRowStateOptions<D extends object> = Partial<{
|
||||
initialRowStateAccessor: (row: Row<D>) => UseRowStateLocalState<D>
|
||||
}>
|
||||
|
||||
export interface UseRowStateState<D extends object> {
|
||||
rowState: Partial<{
|
||||
cellState: UseRowStateLocalState<D>
|
||||
rowState: UseRowStateLocalState<D>
|
||||
}>
|
||||
}
|
||||
|
||||
export interface UseRowStateInstanceProps<D extends object> {
|
||||
setRowState: (rowPath: string[], updater: UseRowUpdater) => void // Purposely not exposing action
|
||||
setCellState: (
|
||||
rowPath: string[],
|
||||
columnID: IdType<D>,
|
||||
updater: UseRowUpdater
|
||||
) => void
|
||||
}
|
||||
|
||||
export interface UseRowStateRowProps<D extends object> {
|
||||
state: UseRowStateLocalState<D>
|
||||
setState: (updater: UseRowUpdater) => void
|
||||
}
|
||||
export interface UseRowStateCellProps<D extends object> {
|
||||
state: UseRowStateLocalState<D>
|
||||
setState: (updater: UseRowUpdater) => void
|
||||
}
|
||||
|
||||
export type UseRowUpdater<T = unknown> = T | ((prev: T) => T)
|
||||
export type UseRowStateLocalState<D extends object, T = unknown> = Record<
|
||||
IdType<D>,
|
||||
T
|
||||
>
|
||||
/* #endregion */
|
||||
|
||||
/* #region useSortBy */
|
||||
export function useSortBy<D extends object = {}>(hooks: Hooks<D>): void
|
||||
export namespace useSortBy {
|
||||
const pluginName = 'useSortBy'
|
||||
}
|
||||
|
||||
export type UseSortByOptions<D extends object> = Partial<{
|
||||
manualSorting: boolean
|
||||
disableSorting: boolean
|
||||
disableMultiSort: boolean
|
||||
isMultiSortEvent: (e: MouseEvent) => boolean
|
||||
maxMultiSortColCount: number
|
||||
disableSortRemove: boolean
|
||||
disabledMultiRemove: boolean
|
||||
orderByFn: (
|
||||
rows: Row<D>[],
|
||||
sortFns: SortByFn<D>[],
|
||||
directions: boolean[]
|
||||
) => Row<D>[] // CHECK
|
||||
sortTypes: Record<string, SortByFn<D>>
|
||||
}>
|
||||
|
||||
export interface UseSortByHooks<D extends object> {
|
||||
getSortByToggleProps: ((
|
||||
column: Column<D>,
|
||||
instance: TableInstance<D>
|
||||
) => object)[]
|
||||
}
|
||||
|
||||
export interface UseSortByState<D extends object> {
|
||||
sortBy: SortingRule<D>[]
|
||||
}
|
||||
|
||||
export type UseSortByColumnOptions<D extends object> = Partial<{
|
||||
disableSorting: boolean
|
||||
sortDescFirst: boolean
|
||||
sortInverted: boolean
|
||||
sortType: SortByFn<D> | DefaultSortTypes | string
|
||||
}>
|
||||
|
||||
export interface UseSortByInstanceProps<D extends object> {
|
||||
rows: Row<D>[]
|
||||
preSortedRows: Row<D>[]
|
||||
toggleSortBy: (
|
||||
columnId: IdType<D>,
|
||||
descending: boolean,
|
||||
isMulti: boolean
|
||||
) => void
|
||||
}
|
||||
|
||||
export interface UseSortByColumnProps<D extends object> {
|
||||
canSort: boolean
|
||||
toggleSortBy: (descending: boolean, multi: boolean) => void
|
||||
getSortByToggleProps: (props?: object) => object
|
||||
clearSorting: () => void
|
||||
isSorted: boolean
|
||||
sortedIndex: number
|
||||
isSortedDesc: boolean | undefined
|
||||
}
|
||||
|
||||
export type SortByFn<D extends object> = (
|
||||
rowA: Row<D>,
|
||||
rowB: Row<D>,
|
||||
columnId: IdType<D>
|
||||
) => 0 | 1 | -1
|
||||
|
||||
export type DefaultSortTypes = 'alphanumeric' | 'datetime' | 'basic'
|
||||
|
||||
export interface SortingRule<D> {
|
||||
id: IdType<D>
|
||||
desc?: boolean
|
||||
}
|
||||
/* #endregion */
|
||||
|
||||
/* #region useAbsoluteLayout */
|
||||
export function useAbsoluteLayout<D extends object = {}>(hooks: Hooks<D>): void
|
||||
export namespace useAbsoluteLayout {
|
||||
const pluginName = 'useAbsoluteLayout'
|
||||
}
|
||||
/* #endregion */
|
||||
|
||||
/* #region useBlockLayout */
|
||||
export function useBlockLayout<D extends object = {}>(hooks: Hooks<D>): void
|
||||
export namespace useBlockLayout {
|
||||
const pluginName = 'useBlockLayout'
|
||||
}
|
||||
/* #endregion */
|
||||
|
||||
/* #region useResizeColumns */
|
||||
export function useResizeColumns<D extends object = {}>(hooks: Hooks<D>): void
|
||||
export namespace useResizeColumns {
|
||||
const pluginName = 'useResizeColumns'
|
||||
}
|
||||
|
||||
export interface UseResizeColumnsOptions<D extends object> {
|
||||
disableResizing?: boolean
|
||||
}
|
||||
|
||||
export interface UseResizeColumnsColumnOptions<D extends object> {
|
||||
disableResizing?: boolean
|
||||
}
|
||||
|
||||
export interface UseResizeColumnsHeaderProps<D extends object> {
|
||||
getResizerProps: (props?: object) => object
|
||||
canResize: boolean
|
||||
isResizing: boolean
|
||||
}
|
||||
/* #endregion */
|
||||
|
||||
// Additional API
|
||||
export const actions: Record<string, string>
|
||||
export function addActions(...actions: string[]): void
|
||||
|
||||
export const defaultState: Record<string, any>
|
||||
|
||||
// Helpers
|
||||
export type StringKey<D> = Extract<keyof D, string>
|
||||
export type IdType<D> = StringKey<D> | string
|
||||
export type CellValue = any
|
||||
|
||||
export type Renderer<Props> = ComponentType<Props> | ReactNode
|
||||
|
||||
export interface PluginHook<D extends object> {
|
||||
(hooks: Hooks<D>): void
|
||||
pluginName: string
|
||||
}
|
||||
|
||||
export type SetState<D extends object> = (
|
||||
updater: (old: TableState<D>) => TableState<D>,
|
||||
type: keyof typeof actions
|
||||
) => void
|
||||
|
||||
Generated
-11527
File diff suppressed because it is too large
Load Diff
+3
-3
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "react-table",
|
||||
"version": "7.0.0-beta.10",
|
||||
"version": "7.0.0-beta.12",
|
||||
"description": "A fast, lightweight, opinionated table and datagrid built on React",
|
||||
"license": "MIT",
|
||||
"homepage": "https://github.com/tannerlinsley/react-table#readme",
|
||||
@@ -20,7 +20,7 @@
|
||||
"sideEffects": false,
|
||||
"scripts": {
|
||||
"commit": "git add . && git-cz",
|
||||
"test": "is-ci 'test:ci' 'test:dev'",
|
||||
"test": "is-ci \"test:ci\" \"test:dev\"",
|
||||
"test:dev": "jest --watch",
|
||||
"test:ci": "jest",
|
||||
"build": "rollup -c",
|
||||
@@ -75,7 +75,7 @@
|
||||
"eslint-plugin-react-hooks": "1.7.0",
|
||||
"eslint-plugin-standard": "^4.0.0",
|
||||
"husky": "^3.0.3",
|
||||
"is-ci-cli": "^1.1.1",
|
||||
"is-ci-cli": "^2.0.0",
|
||||
"jest": "^24.8.0",
|
||||
"jest-cli": "^24.8.0",
|
||||
"jest-runner-eslint": "^0.7.4",
|
||||
|
||||
Vendored
+59
@@ -0,0 +1,59 @@
|
||||
declare module 'react-table' {
|
||||
// take this file as-is, or comment out the sections that don't apply to your plugin configuration
|
||||
|
||||
export interface TableOptions<D extends object>
|
||||
extends UseExpandedOptions<D>,
|
||||
UseFiltersOptions<D>,
|
||||
UseGroupByOptions<D>,
|
||||
UsePaginationOptions<D>,
|
||||
UseRowSelectOptions<D>,
|
||||
UseSortByOptions<D>,
|
||||
UseFiltersOptions<D>,
|
||||
UseResizeColumnsOptions<D>,
|
||||
// note that having Record here allows you to add anything to the options, this matches the spirit of the
|
||||
// underlying js library, but might be cleaner if it's replaced by a more specific type that matches your
|
||||
// feature set, this is a safe default.
|
||||
Record<string, any> {}
|
||||
|
||||
export interface TableInstance<D extends object = {}>
|
||||
extends UseColumnOrderInstanceProps<D>,
|
||||
UseExpandedInstanceProps<D>,
|
||||
UseFiltersInstanceProps<D>,
|
||||
UseGroupByInstanceProps<D>,
|
||||
UsePaginationInstanceProps<D>,
|
||||
UseRowSelectInstanceProps<D>,
|
||||
UseRowStateInstanceProps<D>,
|
||||
UseSortByInstanceProps<D> {}
|
||||
|
||||
export interface TableState<D extends object = {}>
|
||||
extends UseColumnOrderState<D>,
|
||||
UseExpandedState<D>,
|
||||
UseFiltersState<D>,
|
||||
UseGroupByState<D>,
|
||||
UsePaginationState<D>,
|
||||
UseRowSelectState<D>,
|
||||
UseSortByState<D> {}
|
||||
|
||||
export interface Column<D extends object = {}>
|
||||
extends UseFiltersColumnOptions<D>,
|
||||
UseGroupByColumnOptions<D>,
|
||||
UseSortByColumnOptions<D>,
|
||||
UseResizeColumnsColumnOptions<D> {}
|
||||
|
||||
export interface ColumnInstance<D extends object = {}>
|
||||
extends UseFiltersColumnProps<D>,
|
||||
UseGroupByColumnProps<D>,
|
||||
UseSortByColumnProps<D>,
|
||||
UseResizeColumnsHeaderProps<D> {}
|
||||
|
||||
export interface Cell<D extends object = {}>
|
||||
extends UseTableCellProps<D>,
|
||||
UseGroupByCellProps<D>,
|
||||
UseRowStateCellProps<D> {}
|
||||
|
||||
export interface Row<D extends object = {}>
|
||||
extends UseExpandedRowProps<D>,
|
||||
UseGroupByRowProps<D>,
|
||||
UseRowSelectRowProps<D>,
|
||||
UseRowStateRowProps<D> {}
|
||||
}
|
||||
+4
-1
@@ -288,7 +288,10 @@ export function flexRender(Comp, props) {
|
||||
function isClassComponent(component) {
|
||||
return (
|
||||
typeof component === 'function' &&
|
||||
!!Object.getPrototypeOf(component).isReactComponent
|
||||
!!(() => {
|
||||
let proto = Object.getPrototypeOf(component)
|
||||
return proto.prototype && proto.prototype.isReactComponent
|
||||
})()
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -2374,6 +2374,15 @@ cross-spawn@^6.0.0, cross-spawn@^6.0.5:
|
||||
shebang-command "^1.2.0"
|
||||
which "^1.2.9"
|
||||
|
||||
cross-spawn@^7.0.0:
|
||||
version "7.0.1"
|
||||
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.1.tgz#0ab56286e0f7c24e153d04cc2aa027e43a9a5d14"
|
||||
integrity sha512-u7v4o84SwFpD32Z8IIcPZ6z1/ie24O6RU3RbtL5Y316l3KuHVPx9ItBgWQ6VlfAFnRnTtMUrsQ9MUUTuEZjogg==
|
||||
dependencies:
|
||||
path-key "^3.1.0"
|
||||
shebang-command "^2.0.0"
|
||||
which "^2.0.1"
|
||||
|
||||
css-select-base-adapter@^0.1.1:
|
||||
version "0.1.1"
|
||||
resolved "https://registry.yarnpkg.com/css-select-base-adapter/-/css-select-base-adapter-0.1.1.tgz#3b2ff4972cc362ab88561507a95408a1432135d7"
|
||||
@@ -4016,12 +4025,13 @@ is-callable@^1.1.4:
|
||||
resolved "https://registry.yarnpkg.com/is-callable/-/is-callable-1.1.4.tgz#1e1adf219e1eeb684d691f9d6a05ff0d30a24d75"
|
||||
integrity sha512-r5p9sxJjYnArLjObpjA4xu5EKI3CuKHkJXMhT7kwbpUyIFD1n5PMAsoPvWnvtZiNz7LjkYDRZhd7FlI0eMijEA==
|
||||
|
||||
is-ci-cli@^1.1.1:
|
||||
version "1.1.1"
|
||||
resolved "https://registry.yarnpkg.com/is-ci-cli/-/is-ci-cli-1.1.1.tgz#2dc924d192fe8d76074dcb96a2122a7d00d0ee83"
|
||||
integrity sha512-c8xV1IkPvcdB9fAKo3QZ4SmdzsgPHOZ8Xz88T9CCSMrksKMn41R4jUxUP1UbFNPYiYoz8XvHt3RZ3ODKIPyLYQ==
|
||||
is-ci-cli@^2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/is-ci-cli/-/is-ci-cli-2.0.0.tgz#606dd5051c636ac80e1deb4c1c30aa5294220159"
|
||||
integrity sha512-pgdXwbBaRfyG3XJ/+AYbgCb5WE10TZwj4pvoSYI1YrmGDslcS0lhvqvAKmZrSq2248/jGoZ2g9yC63APlBy1uQ==
|
||||
dependencies:
|
||||
is-ci "^1.0.10"
|
||||
cross-spawn "^7.0.0"
|
||||
is-ci "^2.0.0"
|
||||
|
||||
is-ci@^1.0.10:
|
||||
version "1.2.1"
|
||||
@@ -6171,7 +6181,7 @@ path-key@^2.0.0, path-key@^2.0.1:
|
||||
resolved "https://registry.yarnpkg.com/path-key/-/path-key-2.0.1.tgz#411cadb574c5a140d3a4b1910d40d80cc9f40b40"
|
||||
integrity sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A=
|
||||
|
||||
path-key@^3.0.0:
|
||||
path-key@^3.0.0, path-key@^3.1.0:
|
||||
version "3.1.0"
|
||||
resolved "https://registry.yarnpkg.com/path-key/-/path-key-3.1.0.tgz#99a10d870a803bdd5ee6f0470e58dfcd2f9a54d3"
|
||||
integrity sha512-8cChqz0RP6SHJkMt48FW0A7+qUOn+OsnOsVtzI59tZ8m+5bCSk7hzwET0pulwOM2YMn9J1efb07KB9l9f30SGg==
|
||||
@@ -7052,11 +7062,23 @@ shebang-command@^1.2.0:
|
||||
dependencies:
|
||||
shebang-regex "^1.0.0"
|
||||
|
||||
shebang-command@^2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/shebang-command/-/shebang-command-2.0.0.tgz#ccd0af4f8835fbdc265b82461aaf0c36663f34ea"
|
||||
integrity sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==
|
||||
dependencies:
|
||||
shebang-regex "^3.0.0"
|
||||
|
||||
shebang-regex@^1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-1.0.0.tgz#da42f49740c0b42db2ca9728571cb190c98efea3"
|
||||
integrity sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=
|
||||
|
||||
shebang-regex@^3.0.0:
|
||||
version "3.0.0"
|
||||
resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-3.0.0.tgz#ae16f1644d873ecad843b0307b143362d4c42172"
|
||||
integrity sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==
|
||||
|
||||
shelljs@0.7.6:
|
||||
version "0.7.6"
|
||||
resolved "https://registry.yarnpkg.com/shelljs/-/shelljs-0.7.6.tgz#379cccfb56b91c8601e4793356eb5382924de9ad"
|
||||
@@ -7873,6 +7895,13 @@ which@^1.2.14, which@^1.2.9, which@^1.3.0:
|
||||
dependencies:
|
||||
isexe "^2.0.0"
|
||||
|
||||
which@^2.0.1:
|
||||
version "2.0.1"
|
||||
resolved "https://registry.yarnpkg.com/which/-/which-2.0.1.tgz#f1cf94d07a8e571b6ff006aeb91d0300c47ef0a4"
|
||||
integrity sha512-N7GBZOTswtB9lkQBZA4+zAXrjEIWAUOB93AvzUiudRzRxhUdLURQ7D/gAIMY1gatT/LTbmbcv8SiYazy3eYB7w==
|
||||
dependencies:
|
||||
isexe "^2.0.0"
|
||||
|
||||
wide-align@^1.1.0:
|
||||
version "1.1.3"
|
||||
resolved "https://registry.yarnpkg.com/wide-align/-/wide-align-1.1.3.tgz#ae074e6bdc0c14a431e804e624549c633b000457"
|
||||
|
||||
Reference in New Issue
Block a user