mirror of
https://github.com/gosticks/react-table.git
synced 2025-10-16 11:55:36 +00:00
v7.0.0-beta.24
This commit is contained in:
parent
f74e347a06
commit
92603b6a70
@ -1,20 +1,20 @@
|
||||
{
|
||||
"dist/index.js": {
|
||||
"bundled": 96769,
|
||||
"minified": 46778,
|
||||
"gzipped": 12295
|
||||
"bundled": 96773,
|
||||
"minified": 46756,
|
||||
"gzipped": 12302
|
||||
},
|
||||
"dist/index.es.js": {
|
||||
"bundled": 96204,
|
||||
"minified": 46286,
|
||||
"gzipped": 12179,
|
||||
"bundled": 96208,
|
||||
"minified": 46264,
|
||||
"gzipped": 12186,
|
||||
"treeshaked": {
|
||||
"rollup": {
|
||||
"code": 78,
|
||||
"import_statements": 21
|
||||
},
|
||||
"webpack": {
|
||||
"code": 11136
|
||||
"code": 11143
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,3 +1,8 @@
|
||||
## 7.0.0-beta.24
|
||||
|
||||
- Removed types and related files from the repo. The community will now maintain types externally on Definitely Typed
|
||||
- Changed `selectedRowPaths` to use a `Set()` instead of an array for performance.
|
||||
|
||||
## 7.0.0-beta.23
|
||||
|
||||
- The internal `useMain` hook has been renamed to `useInstance`
|
||||
|
||||
@ -1,39 +1,5 @@
|
||||
# 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`.
|
||||
Types for React Table are maintained externally by the Typescript community and are located at https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/react-table.
|
||||
|
||||
To 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 extend 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.
|
||||
Because React Table is not written in Typescript and the types are not maintained by the core team, there are no guarantees around the types always being up to date or working perfectly. If this is an issue for you, please contribute to the community types and discuss solutions there.
|
||||
|
||||
@ -847,9 +847,9 @@ The following values are provided to the table `instance`:
|
||||
|
||||
The following options are supported via the main options object passed to `useTable(options)`
|
||||
|
||||
- `state.selectedRowPaths: Array<RowPathKey>`
|
||||
- `state.selectedRowPaths: Set<RowPathKey>`
|
||||
- Optional
|
||||
- Defaults to `[]`
|
||||
- Defaults to `new Set()`
|
||||
- If a row's path key (eg. a row path of `[1, 3, 2]` would have a path key of `1.3.2`) is found in this array, it will have a selected state.
|
||||
- `initialState.selectedRowPaths`
|
||||
- Identical to the `state.selectedRowPaths` option above
|
||||
|
||||
@ -66,7 +66,7 @@ function Table({ columns, data }) {
|
||||
))}
|
||||
</thead>
|
||||
<tbody {...getTableBodyProps()}>
|
||||
{rows.map((row, i) => {
|
||||
{rows.slice(0, 10).map((row, i) => {
|
||||
prepareRow(row)
|
||||
return (
|
||||
<tr {...row.getRowProps()}>
|
||||
@ -79,11 +79,11 @@ function Table({ columns, data }) {
|
||||
</tbody>
|
||||
</table>
|
||||
<p>Selected Rows: {selectedRowPaths.length}</p>
|
||||
<pre>
|
||||
{/* <pre>
|
||||
<code>
|
||||
{JSON.stringify(
|
||||
{
|
||||
selectedRowPaths,
|
||||
selectedRowPaths: [...selectedRowPaths.values()],
|
||||
'selectedFlatRows[].original': selectedFlatRows.map(
|
||||
d => d.original
|
||||
),
|
||||
@ -92,7 +92,7 @@ function Table({ columns, data }) {
|
||||
2
|
||||
)}
|
||||
</code>
|
||||
</pre>
|
||||
</pre> */}
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
638
index.d.ts
vendored
638
index.d.ts
vendored
@ -1,638 +0,0 @@
|
||||
// TypeScript Version: 3.5
|
||||
|
||||
import { ReactNode, ComponentType, MouseEvent } from 'react'
|
||||
|
||||
/**
|
||||
* 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 interface TableInstance<D extends object = {}>
|
||||
extends Omit<TableOptions<D>, 'columns' | 'state'>,
|
||||
UseTableInstanceProps<D> {}
|
||||
|
||||
export interface TableState<
|
||||
D extends object = {}
|
||||
> {} /* tslint:disable-line no-empty-interface */ // eslint-disable-line @typescript-eslint/no-empty-interface
|
||||
|
||||
export interface Hooks<D extends object = {}> extends UseTableHooks<D> {}
|
||||
|
||||
export interface Cell<D extends object = {}> extends UseTableCellProps<D> {}
|
||||
|
||||
export interface Column<D extends object = {}>
|
||||
extends UseTableColumnOptions<D> {}
|
||||
|
||||
export interface ColumnInstance<D extends object = {}>
|
||||
extends Omit<Column<D>, 'id'>,
|
||||
UseTableColumnProps<D> {}
|
||||
|
||||
export interface HeaderGroup<D extends object = {}>
|
||||
extends ColumnInstance<D>,
|
||||
UseTableHeaderGroupProps<D> {}
|
||||
|
||||
export interface Row<D extends object = {}> extends UseTableRowProps<D> {}
|
||||
|
||||
/* #region useTable */
|
||||
export function useTable<D extends object = {}>(
|
||||
options: TableOptions<D>,
|
||||
...plugins: Array<PluginHook<D>>
|
||||
): TableInstance<D>
|
||||
|
||||
/**
|
||||
* NOTE: To use custom options, use "Interface Merging" to add the custom options
|
||||
*/
|
||||
export type UseTableOptions<D extends object> = {
|
||||
columns: Array<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: (originalRow: D, relativeIndex: number) => Array<D>
|
||||
getRowID: (originalRow: D, relativeIndex: number) => IdType<D>
|
||||
debug: boolean
|
||||
}>
|
||||
|
||||
export interface UseTableHooks<D extends object> {
|
||||
columnsBeforeHeaderGroups: Array<
|
||||
(
|
||||
flatColumns: Array<Column<D>>,
|
||||
instance: TableInstance<D>
|
||||
) => Array<Column<D>>
|
||||
>
|
||||
columnsBeforeHeaderGroupsDeps: Array<
|
||||
(deps: any[], instance: TableInstance<D>) => any[]
|
||||
>
|
||||
useInstance: Array<(instance: TableInstance<D>) => TableInstance<D>>
|
||||
useRows: Array<
|
||||
(rows: Array<Row<D>>, instance: TableInstance<D>) => Array<Row<D>>
|
||||
>
|
||||
prepareRow: Array<(row: Row<D>, instance: TableInstance<D>) => Row<D>>
|
||||
|
||||
// Prop Hooks
|
||||
getTableProps: Array<(instance: TableInstance<D>) => object>
|
||||
getTableBodyProps: Array<(instance: TableInstance<D>) => object>
|
||||
getRowProps: Array<(row: Row<D>, instance: TableInstance<D>) => object>
|
||||
getHeaderGroupProps: Array<
|
||||
(headerGroup: HeaderGroup<D>, instance: TableInstance<D>) => object
|
||||
>
|
||||
getHeaderProps: Array<
|
||||
(column: Column<D>, instance: TableInstance<D>) => object
|
||||
>
|
||||
getCellProps: Array<(cell: Cell<D>, instance: TableInstance<D>) => object>
|
||||
}
|
||||
|
||||
export interface UseTableColumnOptions<D extends object>
|
||||
extends Accessor<D>,
|
||||
Partial<{
|
||||
columns: Array<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: Array<ColumnInstance<D>>
|
||||
flatColumns: Array<ColumnInstance<D>>
|
||||
headerGroups: Array<HeaderGroup<D>>
|
||||
headers: Array<ColumnInstance<D>>
|
||||
flatHeaders: Array<ColumnInstance<D>>
|
||||
rows: Array<Row<D>>
|
||||
getTableProps: (props?: object) => object
|
||||
getTableBodyProps: (props?: object) => object
|
||||
prepareRow: (row: Row<D>) => void
|
||||
rowPaths: string[]
|
||||
flatRows: Array<Row<D>>
|
||||
state: TableState<D>
|
||||
setState: SetState<D>
|
||||
totalColumnsWidth: number
|
||||
}
|
||||
|
||||
export interface UseTableHeaderGroupProps<D extends object> {
|
||||
headers: Array<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: Array<Cell<D>>
|
||||
values: Record<IdType<D>, CellValue>
|
||||
getRowProps: (props?: object) => object
|
||||
index: number
|
||||
original: D
|
||||
path: Array<IdType<D>>
|
||||
subRows: Array<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>
|
||||
}
|
||||
|
||||
export type CellProps<D extends object> = TableInstance<D> & {
|
||||
column: ColumnInstance<D>
|
||||
row: Row<D>
|
||||
cell: Cell<D>
|
||||
}
|
||||
|
||||
// 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: Array<IdType<D>>
|
||||
}
|
||||
|
||||
export interface UseColumnOrderInstanceProps<D extends object> {
|
||||
setColumnOrder: (
|
||||
updater: (columnOrder: Array<IdType<D>>) => Array<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<{
|
||||
manualExpandedKey: IdType<D>
|
||||
paginateExpandedRows: boolean
|
||||
getResetExpandedDeps: (i: TableInstance) => Array<any>
|
||||
}>
|
||||
|
||||
export interface UseExpandedHooks<D extends object> {
|
||||
getExpandedToggleProps: Array<
|
||||
(row: Row<D>, instance: TableInstance<D>) => object
|
||||
>
|
||||
}
|
||||
|
||||
export interface UseExpandedState<D extends object> {
|
||||
expanded: Array<IdType<D>>
|
||||
}
|
||||
|
||||
export interface UseExpandedInstanceProps<D extends object> {
|
||||
rows: Array<Row<D>>
|
||||
toggleExpandedByPath: (path: Array<IdType<D>>, isExpanded: boolean) => void
|
||||
expandedDepth: number
|
||||
}
|
||||
|
||||
export interface UseExpandedRowProps<D extends object> {
|
||||
isExpanded: boolean
|
||||
canExpand: boolean
|
||||
subRows: Array<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>
|
||||
getResetFiltersDeps: (i: TableInstance) => Array<any>
|
||||
}>
|
||||
|
||||
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: Array<Row<D>>
|
||||
preFilteredRows: Array<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: Array<Row<D>>
|
||||
filteredRows: Array<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: Array<Row<D>>,
|
||||
columnId: IdType<D>,
|
||||
filterValue: FilterValue,
|
||||
column: ColumnInstance<D>
|
||||
): Array<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
|
||||
disableGroupBy: boolean
|
||||
aggregations: Record<string, AggregatorFn<D>>
|
||||
groupByFn: (
|
||||
rows: Array<Row<D>>,
|
||||
columnId: IdType<D>
|
||||
) => Record<string, Row<D>>
|
||||
getResetGroupByDeps: (i: TableInstance) => Array<any>
|
||||
}>
|
||||
|
||||
export interface UseGroupByHooks<D extends object> {
|
||||
getGroupByToggleProps: Array<
|
||||
(header: HeaderGroup<D>, instance: TableInstance<D>) => object
|
||||
>
|
||||
}
|
||||
|
||||
export interface UseGroupByState<D extends object> {
|
||||
groupBy: Array<IdType<D>>
|
||||
}
|
||||
|
||||
export type UseGroupByColumnOptions<D extends object> = Partial<{
|
||||
aggregate: Aggregator<D> | Array<Aggregator<D>>
|
||||
Aggregated: Renderer<CellProps<D>>
|
||||
disableGroupBy: boolean
|
||||
groupByBoundary: boolean
|
||||
}>
|
||||
|
||||
export interface UseGroupByInstanceProps<D extends object> {
|
||||
rows: Array<Row<D>>
|
||||
preGroupedRows: Array<Row<D>>
|
||||
toggleGroupBy: (columnId: IdType<D>, toggle: boolean) => void
|
||||
}
|
||||
|
||||
export interface UseGroupByColumnProps<D extends object> {
|
||||
canGroupBy: boolean
|
||||
isGrouped: boolean
|
||||
groupedIndex: number
|
||||
toggleGroupBy: () => void
|
||||
getGroupByToggleProps: (props?: object) => object
|
||||
}
|
||||
|
||||
export interface UseGroupByRowProps<D extends object> {
|
||||
isAggregated: boolean
|
||||
groupByID: IdType<D>
|
||||
groupByVal: string
|
||||
values: Record<IdType<D>, AggregatedValue>
|
||||
subRows: Array<Row<D>>
|
||||
depth: number
|
||||
path: Array<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: Array<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
|
||||
getResetPageDeps: (i: TableInstance) => Array<any>
|
||||
paginateExpandedRows: boolean
|
||||
}>
|
||||
|
||||
export interface UsePaginationState<D extends object> {
|
||||
pageSize: number
|
||||
pageIndex: number
|
||||
}
|
||||
|
||||
export interface UsePaginationInstanceProps<D extends object> {
|
||||
page: Array<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>
|
||||
getResetSelectedRowPathsDeps: (i: TableInstance) => Array<any>
|
||||
}>
|
||||
|
||||
export interface UseRowSelectHooks<D extends object> {
|
||||
getToggleRowSelectedProps: Array<
|
||||
(row: Row<D>, instance: TableInstance<D>) => object
|
||||
>
|
||||
getToggleAllRowsSelectedProps: Array<(instance: TableInstance<D>) => object>
|
||||
}
|
||||
|
||||
export interface UseRowSelectState<D extends object> {
|
||||
selectedRowPaths: Array<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
|
||||
selectedFlatRows: Array<Row<D>>
|
||||
}
|
||||
|
||||
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
|
||||
disableSortBy: boolean
|
||||
disableMultiSort: boolean
|
||||
isMultiSortEvent: (e: MouseEvent) => boolean
|
||||
maxMultiSortColCount: number
|
||||
disableSortRemove: boolean
|
||||
disabledMultiRemove: boolean
|
||||
orderByFn: (
|
||||
rows: Array<Row<D>>,
|
||||
sortFns: Array<SortByFn<D>>,
|
||||
directions: boolean[]
|
||||
) => Array<Row<D>>
|
||||
sortTypes: Record<string, SortByFn<D>>
|
||||
getResetSortByDeps: (i: TableInstance) => Array<any>
|
||||
}>
|
||||
|
||||
export interface UseSortByHooks<D extends object> {
|
||||
getSortByToggleProps: Array<
|
||||
(column: Column<D>, instance: TableInstance<D>) => object
|
||||
>
|
||||
}
|
||||
|
||||
export interface UseSortByState<D extends object> {
|
||||
sortBy: Array<SortingRule<D>>
|
||||
}
|
||||
|
||||
export type UseSortByColumnOptions<D extends object> = Partial<{
|
||||
disableSortBy: boolean
|
||||
sortDescFirst: boolean
|
||||
sortInverted: boolean
|
||||
sortType: SortByFn<D> | DefaultSortTypes | string
|
||||
}>
|
||||
|
||||
export interface UseSortByInstanceProps<D extends object> {
|
||||
rows: Array<Row<D>>
|
||||
preSortedRows: Array<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
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "react-table",
|
||||
"version": "7.0.0-beta.23",
|
||||
"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": {
|
||||
|
||||
99
react-table-config.d.ts
vendored
99
react-table-config.d.ts
vendored
@ -1,99 +0,0 @@
|
||||
import {
|
||||
UseColumnOrderInstanceProps,
|
||||
UseColumnOrderState,
|
||||
UseExpandedInstanceProps,
|
||||
UseExpandedOptions,
|
||||
UseExpandedRowProps,
|
||||
UseExpandedState,
|
||||
UseFiltersColumnOptions,
|
||||
UseFiltersColumnProps,
|
||||
UseFiltersInstanceProps,
|
||||
UseFiltersOptions,
|
||||
UseFiltersState,
|
||||
UseGroupByCellProps,
|
||||
UseGroupByColumnOptions,
|
||||
UseGroupByColumnProps,
|
||||
UseGroupByInstanceProps,
|
||||
UseGroupByOptions,
|
||||
UseGroupByRowProps,
|
||||
UseGroupByState,
|
||||
UsePaginationInstanceProps,
|
||||
UsePaginationOptions,
|
||||
UsePaginationState,
|
||||
UseResizeColumnsColumnOptions,
|
||||
UseResizeColumnsHeaderProps,
|
||||
UseResizeColumnsOptions,
|
||||
UseRowSelectInstanceProps,
|
||||
UseRowSelectOptions,
|
||||
UseRowSelectRowProps,
|
||||
UseRowSelectState,
|
||||
UseRowStateCellProps,
|
||||
UseRowStateInstanceProps,
|
||||
UseRowStateRowProps,
|
||||
UseSortByColumnOptions,
|
||||
UseSortByColumnProps,
|
||||
UseSortByInstanceProps,
|
||||
UseSortByOptions,
|
||||
UseSortByState,
|
||||
UseTableCellProps,
|
||||
} from 'react-table'
|
||||
|
||||
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> {}
|
||||
}
|
||||
@ -113,9 +113,15 @@ function Table({ columns, data }) {
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
<p>Selected Rows: {selectedRowPaths.length}</p>
|
||||
<p>Selected Rows: {selectedRowPaths.size}</p>
|
||||
<pre>
|
||||
<code>{JSON.stringify({ selectedRowPaths }, null, 2)}</code>
|
||||
<code>
|
||||
{JSON.stringify(
|
||||
{ selectedRowPaths: [...selectedRowPaths.values()] },
|
||||
null,
|
||||
2
|
||||
)}
|
||||
</code>
|
||||
</pre>
|
||||
</>
|
||||
)
|
||||
|
||||
@ -19,7 +19,7 @@ actions.toggleRowSelected = 'toggleRowSelected'
|
||||
reducerHandlers[pluginName] = (state, action) => {
|
||||
if (action.type === actions.init) {
|
||||
return {
|
||||
selectedRowPaths: [],
|
||||
selectedRowPaths: new Set(),
|
||||
...state,
|
||||
}
|
||||
}
|
||||
@ -27,7 +27,7 @@ reducerHandlers[pluginName] = (state, action) => {
|
||||
if (action.type === actions.resetSelectedRows) {
|
||||
return {
|
||||
...state,
|
||||
selectedRowPaths: [],
|
||||
selectedRowPaths: new Set(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -44,7 +44,7 @@ reducerHandlers[pluginName] = (state, action) => {
|
||||
|
||||
return {
|
||||
...state,
|
||||
selectedRowPaths: selectAll ? flatRowPaths : [],
|
||||
selectedRowPaths: selectAll ? new Set(flatRowPaths) : new Set(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -63,20 +63,21 @@ reducerHandlers[pluginName] = (state, action) => {
|
||||
// Join the paths of deep rows
|
||||
// to make a key, then manage all of the keys
|
||||
// in a flat object
|
||||
const exists = state.selectedRowPaths.includes(key)
|
||||
const exists = state.selectedRowPaths.has(key)
|
||||
const shouldExist = typeof set !== 'undefined' ? selected : !exists
|
||||
let newSelectedRows = new Set(state.selectedRowPaths)
|
||||
|
||||
let newSelectedRowPaths = new Set(state.selectedRowPaths)
|
||||
|
||||
if (!exists && shouldExist) {
|
||||
flatRowPaths.forEach(rowPath => {
|
||||
if (rowPath === key || rowPath.startsWith(childRowPrefixKey)) {
|
||||
newSelectedRows.add(rowPath)
|
||||
newSelectedRowPaths.add(rowPath)
|
||||
}
|
||||
})
|
||||
} else if (exists && !shouldExist) {
|
||||
flatRowPaths.forEach(rowPath => {
|
||||
if (rowPath === key || rowPath.startsWith(childRowPrefixKey)) {
|
||||
newSelectedRows.delete(rowPath)
|
||||
newSelectedRowPaths.delete(rowPath)
|
||||
}
|
||||
})
|
||||
} else {
|
||||
@ -105,11 +106,11 @@ reducerHandlers[pluginName] = (state, action) => {
|
||||
|
||||
// If the row is a subRow update
|
||||
// its parent row to reflect changes
|
||||
if (path.length > 1) updateParentRow(newSelectedRows, path)
|
||||
if (path.length > 1) updateParentRow(newSelectedRowPaths, path)
|
||||
|
||||
return {
|
||||
...state,
|
||||
selectedRowPaths: [...newSelectedRows.values()],
|
||||
selectedRowPaths: newSelectedRowPaths,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -167,10 +168,10 @@ function useInstance(instance) {
|
||||
|
||||
const flatRowPaths = flatRows.map(d => d.path.join('.'))
|
||||
|
||||
let isAllRowsSelected = !!flatRowPaths.length && !!selectedRowPaths.length
|
||||
let isAllRowsSelected = !!flatRowPaths.length && !!selectedRowPaths.size
|
||||
|
||||
if (isAllRowsSelected) {
|
||||
if (flatRowPaths.some(d => !selectedRowPaths.includes(d))) {
|
||||
if (flatRowPaths.some(d => !selectedRowPaths.has(d))) {
|
||||
isAllRowsSelected = false
|
||||
}
|
||||
}
|
||||
@ -270,5 +271,5 @@ function getRowIsSelected(row, selectedRowPaths) {
|
||||
)
|
||||
}
|
||||
|
||||
return selectedRowPaths.includes(row.path.join('.'))
|
||||
return selectedRowPaths.has(row.path.join('.'))
|
||||
}
|
||||
|
||||
@ -1,10 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": ["es6"],
|
||||
"strict": true,
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": ["index.d.ts"]
|
||||
}
|
||||
@ -1,9 +0,0 @@
|
||||
{
|
||||
"extends": "dtslint/dtslint.json",
|
||||
"rules": {
|
||||
"no-empty-interface": false,
|
||||
"no-unnecessary-generics": false,
|
||||
"semicolon": false,
|
||||
"whitespace": false
|
||||
}
|
||||
}
|
||||
@ -8840,6 +8840,11 @@ typedarray@^0.0.6:
|
||||
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
|
||||
integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=
|
||||
|
||||
typescript@^3.7.2:
|
||||
version "3.7.2"
|
||||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.7.2.tgz#27e489b95fa5909445e9fef5ee48d81697ad18fb"
|
||||
integrity sha512-ml7V7JfiN2Xwvcer+XAf2csGO1bPBdRbFCkYBczNZggrBZ9c7G3riSUeJmqEU5uOtXNPMhE3n+R4FA/3YOAWOQ==
|
||||
|
||||
typescript@next:
|
||||
version "3.7.0-dev.20191009"
|
||||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.7.0-dev.20191009.tgz#852e49dca797bb35acf930583ef65e7b3b23fc01"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user