@propellerads/table 7.0.1 → 8.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,144 @@
1
+ # Table
2
+
3
+ shadcn's data table on [TanStack Table 9](https://tanstack.com/table/latest), in the library's look: a
4
+ semantic `<table>`, one stylesheet, every colour, gap and duration from
5
+ [@propellerads/tokens](../Tokens/README.md).
6
+
7
+ ![](https://img.shields.io/npm/v/@propellerads/table.svg?style=flat-square)
8
+
9
+ [NPM](https://www.npmjs.com/package/@propellerads/table) |
10
+ [Github](https://github.com/propellerads/ui-components/tree/master/Components/Table)
11
+
12
+ ## Installation
13
+
14
+ ```sh
15
+ bun add @propellerads/table
16
+ ```
17
+
18
+ The built entry imports its own stylesheet. The tokens are the app's:
19
+
20
+ ```ts
21
+ import '@propellerads/tokens/common.css';
22
+ import '@propellerads/tokens/propellerads.css'; // or monetag / propush / zeydoo
23
+ ```
24
+
25
+ TanStack Table comes with the package and is re-exported from it: import `useTable`, the features and the
26
+ types from `@propellerads/table`, so the product and the table use one version.
27
+
28
+ ## Use
29
+
30
+ ### Columns and data
31
+
32
+ Every TanStack option goes in as it is, next to the table's own props. The table registers the features it
33
+ draws — sorting, row selection, expanding, pagination, column visibility, sizing and resizing — and a
34
+ product adds others with `features`. State a product passes, with its `on*Change`, wins over the table's.
35
+
36
+ ```tsx
37
+ import Table, {type TableColumn} from '@propellerads/table';
38
+ import Pagination from '@propellerads/pagination';
39
+
40
+ const columns: TableColumn<Row>[] = [
41
+ {accessorKey: 'geo', header: 'Country'},
42
+ {accessorKey: 'amount', header: 'Amount', meta: {align: 'right'}},
43
+ ];
44
+
45
+ <Table columns={columns} data={rows} hasDefaultPagination PaginationComponent={Pagination} />
46
+
47
+ // Pages and sort on the server: TanStack's own options
48
+ <Table
49
+ columns={columns}
50
+ data={page.items}
51
+ totalItems={page.total}
52
+ manualPagination
53
+ manualSorting
54
+ pageCount={page.count}
55
+ state={{pagination, sorting}}
56
+ onPaginationChange={setPagination}
57
+ onSortingChange={setSorting}
58
+ PaginationComponent={Pagination}
59
+ />
60
+ ```
61
+
62
+ ### An instance of your own
63
+
64
+ As shadcn's data table: build the instance with `useTable` and the table draws it. Put the table's features
65
+ in it for the header sort, the selection and the pagination; add any other.
66
+
67
+ ```tsx
68
+ import Table, {
69
+ columnFilteringFeature,
70
+ createFilteredRowModel,
71
+ filterFn_includesString,
72
+ tableBaseFeatures,
73
+ tableFeatures,
74
+ type TableColumn,
75
+ useTable,
76
+ } from '@propellerads/table';
77
+
78
+ const features = tableFeatures({
79
+ ...tableBaseFeatures,
80
+ columnFilteringFeature,
81
+ filteredRowModel: createFilteredRowModel(),
82
+ filterFns: {includesString: filterFn_includesString},
83
+ });
84
+ // A column's type carries its table's features
85
+ const columns: TableColumn<Row, typeof features>[] = [{accessorKey: 'geo', header: 'Country', filterFn: 'includesString'}];
86
+
87
+ const table = useTable({features, columns, data});
88
+
89
+ <Input value={table.getColumn('geo')?.getFilterValue() ?? ''} onChange={(e) => table.getColumn('geo')?.setFilterValue(e.target.value)} />
90
+ <Table table={table} noDataMessage="No results." />
91
+ ```
92
+
93
+ `createSelectionColumn()` is the checkbox column the table adds with `onSelectRowsChange`; put it first in
94
+ your columns for selection in an instance of your own. `tablePaginatedFeatures` is `tableBaseFeatures` with
95
+ the client-side page split.
96
+
97
+ ### Beside a header's title
98
+
99
+ `meta.headerAside` puts a control in the header beside the title — a filter, a hint — outside the sort button, so
100
+ a click on it does not sort and its controls are not inside a button:
101
+
102
+ ```tsx
103
+ {accessorKey: 'cpc', header: 'CPC', meta: {headerAside: ({column}) => <SmartFilter columnId={column.id} />}}
104
+ ```
105
+
106
+ ### The selection column
107
+
108
+ `onSelectRowsChange` adds the checkbox column. `selectColumnProps` changes it: its size, or its `header` and `cell`
109
+ for boxes of the product's own (ids its tests find, a mark instead of a box on some rows).
110
+
111
+ ### The parts
112
+
113
+ For markup of your own, compose shadcn's parts: `TableRoot` (the scrolling container and the `<table>`),
114
+ `TableHeader`, `TableBody`, `TableFooter`, `TableRow` (`data-state="selected"` tints it), `TableHead`,
115
+ `TableCell`, `TableCaption`. Each passes its props to the element and adds `className` to its own.
116
+
117
+ ## Deprecated — go in 9.0
118
+
119
+ They work in 8.x as they did in 7.x; each has TanStack's option in its place.
120
+
121
+ | 7.x prop | Use instead |
122
+ |---|---|
123
+ | `fetchData` | `manualPagination` and `onPaginationChange` |
124
+ | `controlledPagination` | `manualPagination`, `pageCount` and `state.pagination` |
125
+ | `onSortedChange` | `manualSorting` and `onSortingChange` |
126
+ | `isEnableRowSelect` | `enableRowSelection: (row) => …` |
127
+
128
+ ## From 7.x
129
+
130
+ - Both footers are a `<tfoot>`, as in 7.x; the one on top is shown as a header group, under the header.
131
+ - The markup is a `<table>`: `<thead>`, `<tbody>`, `<tr>`, `<th>`, `<td>` instead of divs. The classes
132
+ `table-root`, `table-head` (on `<thead>`), `table-body`, `table-footer-top`, `table-footer-bottom`,
133
+ `table-loading`, `table-wrapper`, `table-content` and the `data-role` attributes stay. Row and cell getters
134
+ (`getRowProps`, `getCellProps`…) give the props of `<tr>` and `<td>`.
135
+ - The look is shadcn's: a line under each row, a hover and a selected tint, the sort as a button in the
136
+ header with the arrow of its direction, the empty message in the body.
137
+ - Column types are TanStack 9's: `ColumnDef<TFeatures, TData>`. `StandardColumn`, `StandardRow`,
138
+ `StandardCell` and `VisibilityState` keep 7.x's names. `sortingFn` is `sortFn` in TanStack 9.
139
+ - `rowSubComponent` opens in a row of its own across the table, its height growing and folding back as
140
+ Collapser's panel does; the sub-rows of a tree fade in. With reduced motion both are instant.
141
+ - A table with a resizable column lays its columns out by their sizes (a `<colgroup>` in a fixed layout, as
142
+ TanStack's resizing examples): a dragged edge follows the pointer, the last column fills the rest, and the
143
+ table scrolls when the columns are wider than the box. 7.x shared the width out by size, and the other
144
+ columns moved too. A table without one is laid out by its content.
package/dist/index.css ADDED
@@ -0,0 +1 @@
1
+ .table-root{gap:var(--space-16);font:var(--font-text);font-family:var(--font-family);color:var(--color-dark-inversion);flex-direction:column;display:flex;position:relative}.table-head{-webkit-user-select:none;user-select:none}.table-wrapper{position:relative;overflow:hidden}.table-wrapper:before,.table-wrapper:after{content:"";z-index:1;width:var(--space-8);opacity:0;pointer-events:none;height:100%;transition:opacity var(--duration-200) var(--ease-flat);position:absolute;top:0}.table-wrapper:before{background:linear-gradient(to right, color-mix(in srgb, var(--color-dark) 12%, transparent), transparent);left:0}.table-wrapper:after{background:linear-gradient(to left, color-mix(in srgb, var(--color-dark) 12%, transparent), transparent);right:0}.table-wrapper.shadow_left:before,.table-wrapper.shadow_right:after{opacity:1}.table-content{width:100%;position:relative;overflow-x:auto}.table{border-collapse:collapse;caption-side:bottom;width:100%}.table-row{transition:background-color var(--duration-200) var(--ease-flat)}.table-header .table-row,.table-body .table-row{border-bottom:var(--space-1) solid var(--color-formal)}.table-body .table-row:last-child{border-bottom:0}.table-footer-top{display:table-header-group}.table-header-content{align-items:center;gap:var(--space-4);display:inline-flex}.table-footer{border-top:var(--space-1) solid var(--color-formal);background-color:var(--color-quiet-bg);font-weight:500}.table-footer .table-row:last-child{border-bottom:0}.table-body .table-row:hover{background-color:var(--color-quiet-bg)}.table-row[data-state=selected],.table-body .table-row[data-state=selected]:hover{background-color:var(--color-formal)}.table-header-cell{height:40px;padding:0 var(--space-8);vertical-align:middle;text-align:left;white-space:nowrap;color:var(--color-dark-inversion);font-weight:500;position:relative}.table-cell{padding:var(--space-8);vertical-align:middle;white-space:nowrap}:is(.table-header-cell:has([role=checkbox]),.table-cell:has([role=checkbox])){padding-right:0}.table-caption{margin-top:var(--space-16);color:var(--color-quiet-text)}.table-sort{align-items:center;gap:var(--space-4);margin:0 calc(-1 * var(--space-4));padding:var(--space-2) var(--space-4);border-radius:var(--radius-4);color:inherit;font:inherit;text-align:inherit;cursor:pointer;outline:var(--space-2) solid transparent;outline-offset:0;transition:background-color var(--duration-200) var(--ease-flat), outline-color var(--duration-200) var(--ease-flat);background:0 0;border:0;display:inline-flex}.table-sort:hover{background-color:var(--color-formal)}.table-sort:focus-visible{outline-color:var(--color-action)}.table-resizer{width:var(--space-4);cursor:col-resize;touch-action:none;-webkit-user-select:none;user-select:none;height:100%;position:absolute;top:0;right:0}.table-resizer:after{content:"";width:var(--space-1);background-color:var(--color-rich);height:50%;position:absolute;top:25%;right:0}.table-resizer[data-resizing=true]:after{background-color:var(--color-action)}.table-cell--full{white-space:normal}.table-cell--sub{white-space:normal;padding:0}.table-sub-panel{transition:grid-template-rows var(--duration-200) var(--ease-enter);grid-template-rows:1fr;display:grid}@starting-style{.table-sub-panel{grid-template-rows:0fr}}.table-sub-row--closing .table-sub-panel{transition-timing-function:var(--ease-exit);grid-template-rows:0fr}.table-sub-panel__content{min-height:0;overflow:hidden}.table-sub-panel__body{padding:var(--space-8)}.table-row--child{animation:table-row-enter var(--duration-200) var(--ease-enter)}@keyframes table-row-enter{0%{opacity:0}}.table-cell--empty{text-align:center;height:96px;color:var(--color-quiet-text);white-space:normal}.table-loading{z-index:2;background-color:color-mix(in srgb, var(--color-light-inversion) 80%, transparent);color:var(--color-quiet-text);opacity:0;pointer-events:none;transition:opacity var(--duration-200) var(--ease-flat);justify-content:center;align-items:center;display:flex;position:absolute;inset:0}.table-loading--active{opacity:1;pointer-events:all}.table-placeholder{width:100%;height:var(--space-16);border-radius:var(--radius-4);background:linear-gradient(to left, var(--color-formal), var(--color-light-inversion), var(--color-formal));background-size:200% 200%;animation:1.6s linear infinite table-placeholder}@keyframes table-placeholder{0%{background-position-x:0}50%{background-position-x:100%}to{background-position-x:0}}@media (prefers-reduced-motion:reduce){.table-placeholder,.table-row--child{animation:none}.table-sub-panel{transition:none}}.table--fixed{table-layout:fixed}.table--fixed .table-header-cell,.table--fixed .table-cell{text-overflow:ellipsis;overflow:hidden}
package/dist/index.d.ts CHANGED
@@ -1,20 +1,38 @@
1
- import * as styled_components_dist_types from 'styled-components/dist/types';
2
1
  import * as react from 'react';
3
- import { CSSProperties, ComponentPropsWithoutRef, ReactNode, ComponentType, ReactElement } from 'react';
4
- import { RowData, Cell, HeaderGroup, Header, ColumnDef, Row, TableState, VisibilityState, SortingState } from '@tanstack/react-table';
5
- export { SortingState, VisibilityState } from '@tanstack/react-table';
2
+ import { CSSProperties, ReactNode, ComponentPropsWithoutRef, ComponentType, ReactElement } from 'react';
3
+ import { TableFeatures, RowData, CellData, HeaderContext, Cell, Header, HeaderGroup, Row, ColumnDef, SortingState, ReactTable, TableOptions, ColumnVisibilityState } from '@tanstack/react-table';
4
+ export * from '@tanstack/react-table';
5
+ export { SortingState } from '@tanstack/react-table';
6
+
7
+ declare const tableBaseFeatures: any;
8
+ /**
9
+ * The base features and the client-side page split. Registered only when the
10
+ * table pages its rows itself: with the paginated row model in place every
11
+ * table would show ten rows a page, asked for or not.
12
+ */
13
+ declare const tablePaginatedFeatures: any;
14
+ type TableBaseFeatures = typeof tableBaseFeatures;
6
15
 
7
16
  declare module '@tanstack/react-table' {
8
- interface ColumnMeta<TData extends RowData, TValue> {
17
+ interface ColumnMeta<in out TFeatures extends TableFeatures, in out TData extends RowData, TValue extends CellData = CellData> {
18
+ /** The text-align of the column: its header, its cells and its footer. */
9
19
  align?: CSSProperties['textAlign'];
20
+ /**
21
+ * What stands in the header beside the title — a filter, a hint — outside the sort button, so a click on it
22
+ * does not sort and its controls are not inside a button.
23
+ */
24
+ headerAside?: (context: HeaderContext<TFeatures, TData, TValue>) => ReactNode;
10
25
  }
11
26
  }
12
27
  type DefaultObject = Record<string, unknown>;
13
- type LoadingState<TData extends DefaultObject = DefaultObject> = {
14
- loadingColumns?: ColumnDef<TData>[];
28
+ /** A column of the data table: TanStack's `ColumnDef` with the table's features. */
29
+ type TableColumn<TData extends RowData = DefaultObject, TFeatures extends TableFeatures = TableBaseFeatures> = ColumnDef<TFeatures, TData, any>;
30
+ type LoadingState<TData extends RowData = DefaultObject> = {
31
+ loadingColumns?: TableColumn<TData, any>[];
15
32
  loadingData: TData[];
16
33
  };
17
- type RowPreProps = ComponentPropsWithoutRef<'div'> & {
34
+ type RowPreProps = ComponentPropsWithoutRef<'tr'> & {
35
+ /** The row is a group title: its first cell spans the table, in bold. */
18
36
  isDelimiterTd?: boolean;
19
37
  };
20
38
  declare const FooterPlacement: {
@@ -38,79 +56,157 @@ type PaginationProps = {
38
56
  setPageSize: (size: number) => void;
39
57
  gotoPage: (page: number) => void;
40
58
  };
59
+ /** @deprecated Use TanStack's `manualPagination`, `pageCount` and `state.pagination`. Goes in 9.0. */
41
60
  type ControlledPagination = {
42
61
  paginationAmount?: ReactNode;
43
62
  pageSize: number;
44
63
  pageIndex: number;
45
64
  pageCount: number;
46
65
  };
47
- type HeaderGroupPropsGetter<TData extends DefaultObject = DefaultObject> = (headerGroup: HeaderGroup<TData>) => ComponentPropsWithoutRef<'div'>;
48
- type HeaderPropsGetter<TData extends DefaultObject = DefaultObject> = (header: Header<TData, unknown>) => ComponentPropsWithoutRef<'div'>;
49
- type RowPropsGetter<TData extends DefaultObject = DefaultObject> = (row: Row<TData>) => ComponentPropsWithoutRef<'div'>;
50
- type CellPropsGetter<TData extends DefaultObject = DefaultObject> = (cell: Cell<TData, unknown>) => ComponentPropsWithoutRef<'div'>;
51
- type SelectColumnProps<TData extends DefaultObject = DefaultObject> = Pick<ColumnDef<TData>, 'size' | 'minSize' | 'maxSize' | 'meta' | 'enableHiding'>;
52
- type TableProps<TData extends DefaultObject = DefaultObject> = {
53
- columns: ColumnDef<TData>[];
54
- data: TData[];
66
+ type HeaderGroupPropsGetter<TData extends RowData = DefaultObject, TFeatures extends TableFeatures = any> = (headerGroup: HeaderGroup<TFeatures, TData>) => ComponentPropsWithoutRef<'tr'>;
67
+ type HeaderPropsGetter<TData extends RowData = DefaultObject, TFeatures extends TableFeatures = any> = (header: Header<TFeatures, TData, any>) => ComponentPropsWithoutRef<'th'>;
68
+ type FooterPropsGetter<TData extends RowData = DefaultObject, TFeatures extends TableFeatures = any> = (header: Header<TFeatures, TData, any>) => ComponentPropsWithoutRef<'td'>;
69
+ type RowPropsGetter<TData extends RowData = DefaultObject, TFeatures extends TableFeatures = any> = (row: Row<TFeatures, TData>) => ComponentPropsWithoutRef<'tr'>;
70
+ type CellPropsGetter<TData extends RowData = DefaultObject, TFeatures extends TableFeatures = any> = (cell: Cell<TFeatures, TData, any>) => ComponentPropsWithoutRef<'td'>;
71
+ type SelectColumnProps<TData extends RowData = DefaultObject> = Pick<TableColumn<TData, any>, 'size' | 'minSize' | 'maxSize' | 'meta' | 'enableHiding' | 'header' | 'cell'>;
72
+ /** What the data table adds to TanStack's options: its markup, loading, footers and pagination. */
73
+ type TableOwnProps<TData extends RowData = DefaultObject, TFeatures extends TableFeatures = any> = {
74
+ /** The rows in all; the pagination counts from it. Defaults to `data.length`. */
55
75
  totalItems?: number;
76
+ /** Drawn under the table when it pages, with the page and the handlers. Usually `@propellerads/pagination`. */
56
77
  PaginationComponent?: ComponentType<PaginationProps>;
57
- initialState?: Partial<TableState> & {
58
- columnVisibility?: VisibilityState;
59
- };
60
- fetchData?: (params: {
61
- pageIndex: number;
62
- pageSize: number;
63
- }) => void;
64
- onSortedChange?: (sorting: SortingState) => void;
78
+ /** Fades the table under an overlay with `loadingMessage`, or shows placeholder rows with `showLoadingState`. */
65
79
  isLoading?: boolean;
80
+ /** @default 'loading...' */
81
+ loadingMessage?: string;
82
+ /** Placeholder rows instead of the overlay while `isLoading`. */
83
+ showLoadingState?: boolean;
84
+ /** The content of a placeholder cell. */
85
+ LoadingCellComponent?: ComponentType;
86
+ /** Where the footers of the columns stand. @default [] */
66
87
  footerPlacement?: FooterPlacement[];
88
+ /** The table splits its rows into pages itself and draws `PaginationComponent`. */
67
89
  hasDefaultPagination?: boolean;
90
+ /** Adds the checkbox column and reports the chosen rows, the originals. */
68
91
  onSelectRowsChange?: (rows: TData[]) => void;
69
- controlledPagination?: ControlledPagination;
70
- loadingMessage?: string;
92
+ /** @default 'Show rows' */
71
93
  labelPerPage?: string;
94
+ /** Prefix of the ids of the pagination controls. @default 'parent-element' */
72
95
  parentElementId?: string;
96
+ /** The id of the scrolling container. */
73
97
  tableContentId?: string;
74
- getRowPreProps?: (row: Row<TData>) => RowPreProps;
75
- getRowId?: (originalRow: TData, index: number, parent?: Row<TData>) => string;
76
- getSubRows?: (originalRow: TData, index: number) => TData[] | undefined;
77
- getTableProps?: () => ComponentPropsWithoutRef<'div'>;
78
- getHeaderGroupProps?: HeaderGroupPropsGetter<TData>;
79
- getHeaderProps?: HeaderPropsGetter<TData>;
80
- getRowProps?: RowPropsGetter<TData>;
81
- getCellProps?: CellPropsGetter<TData>;
82
- getFooterProps?: HeaderPropsGetter<TData>;
83
- getFooterGroupProps?: HeaderGroupPropsGetter<TData>;
84
- showLoadingState?: boolean;
85
- LoadingCellComponent?: ComponentType;
98
+ /** Shown in the body when there are no rows. */
86
99
  noDataMessage?: ReactNode;
87
- rowSubComponent?: (row: Row<TData>) => ReactElement;
88
- isEnableRowSelect?: (original: TData) => boolean;
100
+ /** A caption under the table. */
101
+ caption?: ReactNode;
102
+ /** Opened under an expanded row, across the whole table. */
103
+ rowSubComponent?: (row: Row<TFeatures, TData>) => ReactElement | null;
104
+ /** Props of the checkbox column that `onSelectRowsChange` adds. */
89
105
  selectColumnProps?: Partial<SelectColumnProps<TData>>;
106
+ getRowPreProps?: (row: Row<TFeatures, TData>) => RowPreProps;
107
+ getTableProps?: () => ComponentPropsWithoutRef<'table'>;
108
+ getHeaderGroupProps?: HeaderGroupPropsGetter<TData, TFeatures>;
109
+ getHeaderProps?: HeaderPropsGetter<TData, TFeatures>;
110
+ getRowProps?: RowPropsGetter<TData, TFeatures>;
111
+ getCellProps?: CellPropsGetter<TData, TFeatures>;
112
+ getFooterProps?: FooterPropsGetter<TData, TFeatures>;
113
+ getFooterGroupProps?: HeaderGroupPropsGetter<TData, TFeatures>;
114
+ /**
115
+ * @deprecated Use TanStack's `manualPagination`, `onPaginationChange` and
116
+ * `state.pagination`. Goes in 9.0.
117
+ */
118
+ fetchData?: (params: {
119
+ pageIndex: number;
120
+ pageSize: number;
121
+ }) => void;
122
+ /**
123
+ * @deprecated Use TanStack's `manualPagination`, `pageCount` and
124
+ * `state.pagination`. Goes in 9.0.
125
+ */
126
+ controlledPagination?: ControlledPagination;
127
+ /**
128
+ * @deprecated Use TanStack's `manualSorting` and `onSortingChange`. Goes in 9.0.
129
+ */
130
+ onSortedChange?: (sorting: SortingState) => void;
131
+ /**
132
+ * @deprecated Use TanStack's `enableRowSelection: (row) => …`. Goes in 9.0.
133
+ */
134
+ isEnableRowSelect?: (original: TData) => boolean;
90
135
  };
91
- type StandardColumn<TData extends DefaultObject = DefaultObject> = ColumnDef<TData>;
92
- type StandardRow<TData extends DefaultObject = DefaultObject> = Row<TData>;
93
- type StandardCell<TData extends DefaultObject = DefaultObject> = Cell<TData, unknown>;
94
-
95
- type TableRowData = DefaultObject & RowData;
96
- declare const defaultProps: {
97
- hasDefaultPagination: boolean;
98
- isLoading: boolean;
99
- footerPlacement: never[];
100
- loadingMessage: string;
101
- labelPerPage: string;
102
- parentElementId: string;
103
- tableContentId: string;
104
- showLoadingState: boolean;
105
- LoadingCellComponent: styled_components_dist_types.IStyledComponentBase<"web", Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "style"> & {
106
- style?: react.CSSProperties | styled_components_dist_types.CSSPropertiesWithVars | undefined;
107
- }> & string;
108
- getRowPreProps: () => RowPreProps;
109
- isEnableRowSelect: () => boolean;
110
- selectColumnProps: {};
111
- noDataMessage: string;
136
+ /**
137
+ * The table builds its TanStack instance: `columns` and `data`, every TanStack
138
+ * option as it is, and `features` with the ones the table does not register
139
+ * itself (filtering, pinning, grouping…). The state a product passes, with its
140
+ * `on*Change`, wins over the table's own.
141
+ */
142
+ type ManagedTableProps<TData extends RowData = DefaultObject, TExtra extends TableFeatures = {}> = Partial<Omit<TableOptions<TableBaseFeatures & TExtra, TData>, 'features' | 'columns' | 'data'>> & TableOwnProps<TData, TableBaseFeatures & TExtra> & {
143
+ columns: TableColumn<TData, TableBaseFeatures & TExtra>[];
144
+ data: TData[];
145
+ /** Features on top of the table's own; keep the object stable between renders. */
146
+ features?: TExtra;
147
+ table?: undefined;
112
148
  };
113
- declare const Table: <TData extends TableRowData = DefaultObject>({ columns, data, totalItems, fetchData, controlledPagination, initialState, isLoading, loadingMessage, labelPerPage, footerPlacement, onSortedChange, hasDefaultPagination, onSelectRowsChange, parentElementId, tableContentId, LoadingCellComponent, PaginationComponent, getRowPreProps, getRowId, getSubRows, getTableProps, getHeaderGroupProps, getHeaderProps, getRowProps, getCellProps, getFooterProps, getFooterGroupProps, showLoadingState, noDataMessage, rowSubComponent, isEnableRowSelect, selectColumnProps, }: TableProps<TData>) => react.JSX.Element;
149
+ /**
150
+ * The product builds the instance with `useTable` and the table draws it, as
151
+ * shadcn's data table does. Build it with `tableBaseFeatures` (or
152
+ * `tablePaginatedFeatures`) in its features for the header sort, the
153
+ * selection and the pagination to work.
154
+ */
155
+ type InstanceTableProps<TData extends RowData = DefaultObject, TFeatures extends TableFeatures = any> = TableOwnProps<TData, TFeatures> & {
156
+ table: ReactTable<TFeatures, TData, any>;
157
+ columns?: undefined;
158
+ data?: undefined;
159
+ };
160
+ type TableProps<TData extends RowData = DefaultObject, TExtra extends TableFeatures = {}> = ManagedTableProps<TData, TExtra> | InstanceTableProps<TData, any>;
161
+ type StandardColumn<TData extends RowData = DefaultObject> = TableColumn<TData>;
162
+ type StandardRow<TData extends RowData = DefaultObject> = Row<TableBaseFeatures, TData>;
163
+ type StandardCell<TData extends RowData = DefaultObject> = Cell<TableBaseFeatures, TData, unknown>;
164
+ /** 7.x's name of TanStack's `ColumnVisibilityState`. */
165
+ type VisibilityState = ColumnVisibilityState;
166
+
167
+ /** The scrolling container and the <table> in it. */
168
+ declare const TableRoot: react.ForwardRefExoticComponent<Omit<react.DetailedHTMLProps<react.TableHTMLAttributes<HTMLTableElement>, HTMLTableElement>, "ref"> & {
169
+ /** Props of the scrolling container round the table. */
170
+ containerProps?: ComponentPropsWithoutRef<"div">;
171
+ } & react.RefAttributes<HTMLTableElement>>;
172
+ declare const TableHeader: react.ForwardRefExoticComponent<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLTableSectionElement>, HTMLTableSectionElement>, "ref"> & react.RefAttributes<HTMLTableSectionElement>>;
173
+ declare const TableBody: react.ForwardRefExoticComponent<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLTableSectionElement>, HTMLTableSectionElement>, "ref"> & react.RefAttributes<HTMLTableSectionElement>>;
174
+ declare const TableFooter: react.ForwardRefExoticComponent<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLTableSectionElement>, HTMLTableSectionElement>, "ref"> & react.RefAttributes<HTMLTableSectionElement>>;
175
+ /** A row; `data-state="selected"` tints it. */
176
+ declare const TableRow: react.ForwardRefExoticComponent<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLTableRowElement>, HTMLTableRowElement>, "ref"> & react.RefAttributes<HTMLTableRowElement>>;
177
+ /** A header cell. */
178
+ declare const TableHead: react.ForwardRefExoticComponent<Omit<react.DetailedHTMLProps<react.ThHTMLAttributes<HTMLTableHeaderCellElement>, HTMLTableHeaderCellElement>, "ref"> & react.RefAttributes<HTMLTableCellElement>>;
179
+ declare const TableCell: react.ForwardRefExoticComponent<Omit<react.DetailedHTMLProps<react.TdHTMLAttributes<HTMLTableDataCellElement>, HTMLTableDataCellElement>, "ref"> & react.RefAttributes<HTMLTableCellElement>>;
180
+ declare const TableCaption: react.ForwardRefExoticComponent<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLElement>, HTMLElement>, "ref"> & react.RefAttributes<HTMLTableCaptionElement>>;
181
+
182
+ /** The placeholder of a cell while the table loads with `showLoadingState`. */
183
+ declare const TablePlaceholder: () => react.JSX.Element;
184
+ /**
185
+ * The checkbox column of shadcn's data table: a box in the header for the rows
186
+ * of the page, a box in each row. The data table adds it with
187
+ * `onSelectRowsChange`; a product that builds its own instance puts it first in
188
+ * its columns.
189
+ */
190
+ declare const createSelectionColumn: <TData extends RowData = DefaultObject>(props?: Partial<SelectColumnProps<TData>>) => TableColumn<TData, any>;
191
+ /**
192
+ * The header of a sortable column as shadcn draws it: a button with the title
193
+ * and, once sorted, the arrow of the direction. A click sorts by the column,
194
+ * descending first unless `sortDescFirst: false`, then flips the direction;
195
+ * one column at a time.
196
+ */
197
+ declare const TableColumnHeader: <TData extends RowData>({ header }: {
198
+ header: Header<any, TData, any>;
199
+ }) => react.JSX.Element;
200
+ /**
201
+ * shadcn's data table on TanStack Table 9, in the library's look.
202
+ *
203
+ * Give it `columns` and `data` with any TanStack option, and it builds the
204
+ * instance: the header sorts, `onSelectRowsChange` adds the checkbox column,
205
+ * `hasDefaultPagination` pages the rows. Or give it a `table` built with
206
+ * `useTable` and it draws that. For a table of other markup, compose the parts:
207
+ * `TableRoot`, `TableHeader`, `TableBody`, `TableRow`, `TableHead`, `TableCell`.
208
+ */
209
+ declare const Table: <TData extends RowData = DefaultObject, TExtra extends TableFeatures = {}>(props: TableProps<TData, TExtra>) => react.JSX.Element;
114
210
 
115
- export { Table as default, defaultProps };
116
- export type { CellPropsGetter, ControlledPagination, DefaultObject, HeaderGroupPropsGetter, HeaderPropsGetter, LoadingState, PaginationProps, RowPreProps, RowPropsGetter, SelectColumnProps, StandardCell, StandardColumn, StandardRow, TableProps };
211
+ export { FooterPlacement, TableBody, TableCaption, TableCell, TableColumnHeader, TableFooter, TableHead, TableHeader, TablePlaceholder, TableRoot, TableRow, createSelectionColumn, Table as default, tableBaseFeatures, tablePaginatedFeatures };
212
+ export type { CellPropsGetter, ControlledPagination, DefaultObject, FooterPropsGetter, HeaderGroupPropsGetter, HeaderPropsGetter, InstanceTableProps, LoadingState, ManagedTableProps, PaginationProps, RowPreProps, RowPropsGetter, SelectColumnProps, StandardCell, StandardColumn, StandardRow, TableBaseFeatures, TableColumn, TableOwnProps, TableProps, VisibilityState };