@chumsinc/sortable-tables 2.2.0 → 3.0.1
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/CHANGELOG.md +31 -1
- package/README.md +94 -4
- package/dist/DataTable.d.ts +1 -1
- package/dist/DataTableCell.d.ts +6 -2
- package/dist/DataTableCols.d.ts +1 -1
- package/dist/DataTableContext.d.ts +10 -0
- package/dist/DataTableProvider.d.ts +12 -0
- package/dist/DataTableTH.d.ts +1 -1
- package/dist/SortableTable.d.ts +1 -1
- package/dist/SortableTableHead.d.ts +1 -1
- package/dist/SortableTableHeadWrapper.d.ts +9 -0
- package/dist/SortableTableTH.d.ts +1 -1
- package/dist/StandaloneDataTable.d.ts +6 -0
- package/dist/StandaloneDataTableRow.d.ts +9 -0
- package/dist/StandaloneSortHelper.d.ts +5 -0
- package/dist/StandaloneSortableTable.d.ts +6 -0
- package/dist/Table.d.ts +5 -4
- package/dist/index.cjs.js +4 -8
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +12 -8
- package/dist/index.es.js +239 -198
- package/dist/index.es.js.map +1 -1
- package/dist/types.d.ts +4 -3
- package/dist/useField.d.ts +6 -0
- package/dist/useTableContext.d.ts +2 -0
- package/dist/useTableFields.d.ts +9 -0
- package/dist/useTableSort.d.ts +9 -0
- package/package.json +3 -3
- package/src/DataTable.tsx +34 -11
- package/src/DataTableCell.tsx +33 -28
- package/src/DataTableCols.tsx +11 -18
- package/src/DataTableContext.ts +13 -0
- package/src/DataTableHead.tsx +6 -7
- package/src/DataTableProvider.tsx +62 -0
- package/src/DataTableRow.tsx +8 -7
- package/src/DataTableTBody.tsx +1 -3
- package/src/DataTableTH.tsx +4 -3
- package/src/RowsPerPage.tsx +2 -4
- package/src/SortableTable.tsx +36 -12
- package/src/SortableTableHead.tsx +9 -9
- package/src/SortableTableHeadWrapper.tsx +20 -0
- package/src/SortableTableTH.tsx +4 -4
- package/src/StandaloneDataTable.tsx +16 -0
- package/src/StandaloneDataTableRow.tsx +42 -0
- package/src/StandaloneSortHelper.tsx +15 -0
- package/src/StandaloneSortableTable.tsx +21 -0
- package/src/Table.tsx +49 -44
- package/src/TablePagination.tsx +1 -3
- package/src/index.tsx +21 -15
- package/src/types.ts +127 -126
- package/src/useField.ts +19 -0
- package/src/useTableContext.ts +10 -0
- package/src/useTableFields.ts +20 -0
- package/src/useTableSort.ts +20 -0
- package/test/Main.tsx +37 -0
- package/test/TableColumnsHandler.tsx +9 -9
- package/test/TestTable.tsx +51 -46
- package/test/data.ts +232 -232
- package/test/index.tsx +11 -11
- package/test/tableFields.tsx +11 -3
- package/test/utils.ts +19 -0
- package/tsconfig.json +1 -0
- package/dist/DataTableWithContext.d.ts +0 -2
- package/dist/SortableTableWithContext.d.ts +0 -2
- package/dist/TableProvider.d.ts +0 -17
- package/src/DataTableWithContext.tsx +0 -41
- package/src/SortableTableWithContext.tsx +0 -44
- package/src/TableProvider.tsx +0 -77
package/CHANGELOG.md
CHANGED
|
@@ -7,7 +7,37 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
9
9
|
|
|
10
|
-
#### [
|
|
10
|
+
#### [v3.0.1](https://github.com/ChumsInc/sortable-tables/compare/v3.0.0...v3.0.1)
|
|
11
|
+
|
|
12
|
+
> 2026-01-19
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Commits
|
|
18
|
+
|
|
19
|
+
- [`34ca622`](https://github.com/ChumsInc/sortable-tables/commit/34ca622de8fc42834d663a4d680091cf69f283cf) chore: npm updates & build
|
|
20
|
+
- [`34d095c`](https://github.com/ChumsInc/sortable-tables/commit/34d095ce9ec7c406b51a771d95e881cbc2459a94) fix: add StandaloneDataTableRow
|
|
21
|
+
- [`830d3ef`](https://github.com/ChumsInc/sortable-tables/commit/830d3ef5375905427c6434f8fd64ccfd34cbe679) chore: update readme
|
|
22
|
+
|
|
23
|
+
#### [v3.0.0](https://github.com/ChumsInc/sortable-tables/compare/v2.2.0...v3.0.0) - 2025-12-30
|
|
24
|
+
|
|
25
|
+
> 2025-12-30
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
### Commits
|
|
31
|
+
|
|
32
|
+
- [`372fb75`](https://github.com/ChumsInc/sortable-tables/commit/372fb75f6401cdafe51a8c94bb725a9b5bb55054) Add DataTableProvider to allow for better modifying of columns.
|
|
33
|
+
- [`54f85e5`](https://github.com/ChumsInc/sortable-tables/commit/54f85e50d2390e7dfd2b9b3f4aad1a215abc51a5) Add DataTableProvider to allow for better modifying of columns.
|
|
34
|
+
- [`ca0dee4`](https://github.com/ChumsInc/sortable-tables/commit/ca0dee45c5f0e76c9239642e5946b171b0559fa0) chore: add type definitions for SortableTableHeadWrapper, declare component with displayName
|
|
35
|
+
- [`d5cb405`](https://github.com/ChumsInc/sortable-tables/commit/d5cb40577c6e9edbe84a0770af756b6e28d8ae5d) chore: replace "collapse" with "visible" for field visibility control, filter hidden fields in table rendering
|
|
36
|
+
- [`f8e67fb`](https://github.com/ChumsInc/sortable-tables/commit/f8e67fbc6f38cb8e457cb0f864abd3933b9f895b) chore: move field visibility filter to DataTableCell, simplify SortableTableHead rendering logic
|
|
37
|
+
- [`0d376b5`](https://github.com/ChumsInc/sortable-tables/commit/0d376b5567005ace9a64e14b6e593d5a7f617b20) chore: add StandaloneSortHelper to help handle sortChanges in StandaloneSortableTable component
|
|
38
|
+
- [`0780ecf`](https://github.com/ChumsInc/sortable-tables/commit/0780ecf033a3291e65d080915e14cb3c9812a1b6) chore: add testing for standalone tables
|
|
39
|
+
|
|
40
|
+
#### [v2.2.0](https://github.com/ChumsInc/sortable-tables/compare/v2.1.3...v2.2.0) - 2025-12-16
|
|
11
41
|
|
|
12
42
|
> 2025-12-16
|
|
13
43
|
|
package/README.md
CHANGED
|
@@ -8,10 +8,10 @@ This components uses [Bootstrap 5.3](https://getbootstrap.com/docs/5.3/content/t
|
|
|
8
8
|
additional table size 'xs' for less padding.
|
|
9
9
|
|
|
10
10
|
## Usage
|
|
11
|
-
|
|
11
|
+
### Configure Columns
|
|
12
12
|
```tsx
|
|
13
|
-
import {
|
|
14
|
-
import {ProductLine} from 'chums-
|
|
13
|
+
import {StandaloneSortableTable, SortableTableField, SortProps} from "@chumsinc/sortable-tables";
|
|
14
|
+
import {ProductLine} from 'chums-types'
|
|
15
15
|
|
|
16
16
|
const fields: SortableTableField<ProductLine>[] = [
|
|
17
17
|
{field: 'ProductLine', title: 'Prod Line', sortable: true, as: 'th'},
|
|
@@ -38,6 +38,94 @@ const fields: SortableTableField<ProductLine>[] = [
|
|
|
38
38
|
align: 'end'
|
|
39
39
|
},
|
|
40
40
|
];
|
|
41
|
+
```
|
|
42
|
+
### Usage in a DataTableProvider
|
|
43
|
+
```tsx
|
|
44
|
+
export default function Main() {
|
|
45
|
+
const dispatch = useAppDispatch();
|
|
46
|
+
const initialSort: SortProps<ProductLine> = {field: 'ProductLine', ascending: true};
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<DataTableProvider initialFields={tableFields} initialSort={initialSort}>
|
|
50
|
+
<TestTable />
|
|
51
|
+
</DataTableProvider>
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function TestTable() {
|
|
56
|
+
const dispatch = useAppDispatch();
|
|
57
|
+
const data = useAppSelector(selectSortedProductLines);
|
|
58
|
+
const sort = useAppSelector(selectProductLinesSort);
|
|
59
|
+
const [page, setPage] = useState(0);
|
|
60
|
+
const [rowsPerPage, setRowsPerPage] = useState(5);
|
|
61
|
+
const [, setCurrentSort] = useTableSort<ProductLine>();
|
|
62
|
+
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
setCurrentSort(sort);
|
|
65
|
+
setPage(0)
|
|
66
|
+
}, [sort, setCurrentSort])
|
|
67
|
+
|
|
68
|
+
const rowsPerPageChangeHandler = (rpp: number) => {
|
|
69
|
+
setPage(0);
|
|
70
|
+
setRowsPerPage(rpp);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const sortChangeHandler = (sort: SortProps<ProductLine>) => {
|
|
74
|
+
dispatch(setProductLinesSort(sort));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
<div>
|
|
80
|
+
<TableColumnsHandler/>
|
|
81
|
+
<SortableTable onChangeSort={sortChangeHandler} size="lg" responsive
|
|
82
|
+
data={data.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage)}
|
|
83
|
+
keyField="ProductLine" rowClassName={rowClassName}/>
|
|
84
|
+
<TablePagination page={page} onChangePage={setPage} size="sm"
|
|
85
|
+
rowsPerPage={rowsPerPage}
|
|
86
|
+
rowsPerPageProps={{
|
|
87
|
+
onChange: rowsPerPageChangeHandler,
|
|
88
|
+
label: <span className="bi-images" aria-label="Images Per Page"></span>,
|
|
89
|
+
pageValues: [5, 10, 15, 25, 50, 100]
|
|
90
|
+
}}
|
|
91
|
+
showFirst={data.length > rowsPerPage}
|
|
92
|
+
showLast={data.length > rowsPerPage}
|
|
93
|
+
count={data.length}/>
|
|
94
|
+
</div>
|
|
95
|
+
|
|
96
|
+
)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function TableColumnsHandler() {
|
|
100
|
+
const [getField, updateField] = useTableContext<ProductLine>();
|
|
101
|
+
const [collapse, setCollapse] = React.useState<boolean>(getField('ProductLineDesc')?.collapse ?? false);
|
|
102
|
+
const id = useId();
|
|
103
|
+
|
|
104
|
+
const toggleFieldCollapse = useCallback((key: string, next: boolean) => {
|
|
105
|
+
console.debug('toggleFieldVisibility', key, next);
|
|
106
|
+
updateField(key, (prev) => ({...prev, collapse: next}))
|
|
107
|
+
setCollapse(next);
|
|
108
|
+
}, [updateField]);
|
|
109
|
+
|
|
110
|
+
const handleVisibleChange = (ev: React.ChangeEvent<HTMLInputElement>) => {
|
|
111
|
+
toggleFieldCollapse('ProductLineDesc', ev.target.checked);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return (
|
|
115
|
+
<div style={{display: 'flex', alignItems: 'center', justifyContent: 'flex-start', gap: '1rem'}}>
|
|
116
|
+
<input type="checkbox" checked={collapse} id={id} onChange={handleVisibleChange}/>
|
|
117
|
+
<label htmlFor={id}>Hide Description</label>
|
|
118
|
+
</div>
|
|
119
|
+
)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
```
|
|
124
|
+
### Usage as a Standalone Table:
|
|
125
|
+
```tsx
|
|
126
|
+
import {StandaloneSortableTable, SortableTableField, SortProps} from "@chumsinc/sortable-tables";
|
|
127
|
+
import {ProductLine} from 'chums-type'
|
|
128
|
+
import {fields} from './fields'
|
|
41
129
|
|
|
42
130
|
export default function ProductLinesList() {
|
|
43
131
|
const [sort, setSort] = useState<SortProps<ProductLine>>({field: 'ProductLine', ascending: true});
|
|
@@ -58,7 +146,7 @@ export default function ProductLinesList() {
|
|
|
58
146
|
|
|
59
147
|
return (
|
|
60
148
|
<div>
|
|
61
|
-
<
|
|
149
|
+
<StandaloneSortableTable currentSort={sort} onChangeSort={setSort} fields={fields} size="lg" responsive
|
|
62
150
|
data={list.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage)}
|
|
63
151
|
keyField="ProductLine" rowClassName={rowClassName}/>
|
|
64
152
|
<TablePagination page={page} onChangePage={setPage} size="sm"
|
|
@@ -75,8 +163,10 @@ export default function ProductLinesList() {
|
|
|
75
163
|
}
|
|
76
164
|
```
|
|
77
165
|
|
|
166
|
+
##
|
|
78
167
|
## Breaking Changes
|
|
79
168
|
Breaking changes from `chums-components`
|
|
80
169
|
- TablePagination
|
|
81
170
|
- The rows per page options were moved to a new attribute `rowsPerPageProps`
|
|
82
171
|
- RowsPerPage now renders as a bootstrap InputGroup element
|
|
172
|
+
- For old standalone tables without the ContextProvider use version 2.1.3
|
package/dist/DataTable.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DataTableProps } from './types';
|
|
2
|
-
declare function DataTable<T = unknown>({
|
|
2
|
+
declare function DataTable<T = unknown>({ className, size, responsive, sticky, data, keyField, rowClassName, renderRow, onSelectRow, selected, tableHeadProps, children, tfoot, ...rest }: Omit<DataTableProps<T>, 'fields'>): import("react/jsx-runtime").JSX.Element;
|
|
3
3
|
declare namespace DataTable {
|
|
4
4
|
var displayName: string;
|
|
5
5
|
}
|
package/dist/DataTableCell.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
2
|
import { DataTableCellProps } from './types';
|
|
3
|
-
|
|
3
|
+
declare function DataTableCell<T = unknown>({ field, row, className, as, ...rest }: DataTableCellProps<T>): import('react').DetailedReactHTMLElement<{
|
|
4
4
|
children?: ReactNode | undefined;
|
|
5
5
|
align?: "left" | "center" | "right" | undefined;
|
|
6
6
|
bgcolor?: string | undefined;
|
|
@@ -292,4 +292,8 @@ export default function DataTableCell<T = unknown>({ field, row, className, as,
|
|
|
292
292
|
className: string;
|
|
293
293
|
scope: string | undefined;
|
|
294
294
|
colSpan: number | undefined;
|
|
295
|
-
}, HTMLElement
|
|
295
|
+
}, HTMLElement> | null;
|
|
296
|
+
declare namespace DataTableCell {
|
|
297
|
+
var displayName: string;
|
|
298
|
+
}
|
|
299
|
+
export default DataTableCell;
|
package/dist/DataTableCols.d.ts
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DataTableField, SortProps } from './types';
|
|
2
|
+
export interface TableContextData<T = unknown> {
|
|
3
|
+
fields: DataTableField<T>[];
|
|
4
|
+
setFields: (next: DataTableField<T>[] | ((prev: DataTableField<T>[]) => DataTableField<T>[])) => void;
|
|
5
|
+
sort: SortProps<T> | null;
|
|
6
|
+
setSort: (next: SortProps<T> | null | ((prev: SortProps<T> | null) => SortProps<T> | null)) => void;
|
|
7
|
+
getField: (key: string | number) => DataTableField<T> | undefined;
|
|
8
|
+
updateField: (key: string | number, arg: Partial<DataTableField<T>>) => void;
|
|
9
|
+
}
|
|
10
|
+
export declare const DataTableContext: import('react').Context<TableContextData<unknown> | null>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { DataTableField, SortProps } from './types';
|
|
3
|
+
export interface TableProviderProps<T = unknown> {
|
|
4
|
+
initialFields: DataTableField<T>[];
|
|
5
|
+
initialSort?: SortProps<T> | null;
|
|
6
|
+
children: ReactNode;
|
|
7
|
+
}
|
|
8
|
+
declare function DataTableProvider<T = unknown>({ children, initialFields, initialSort, }: TableProviderProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
declare namespace DataTableProvider {
|
|
10
|
+
var displayName: string;
|
|
11
|
+
}
|
|
12
|
+
export default DataTableProvider;
|
package/dist/DataTableTH.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DataTableTHProps } from './types';
|
|
2
|
-
declare function DataTableTH<T = unknown>({ field, className, children, ...rest }: DataTableTHProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
2
|
+
declare function DataTableTH<T = unknown>({ field, className, children, ...rest }: DataTableTHProps<T>): import("react/jsx-runtime").JSX.Element | null;
|
|
3
3
|
declare namespace DataTableTH {
|
|
4
4
|
var displayName: string;
|
|
5
5
|
}
|
package/dist/SortableTable.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SortableTableProps } from './types';
|
|
2
|
-
declare function SortableTable<T = unknown>({
|
|
2
|
+
declare function SortableTable<T = unknown>({ className, size, responsive, sticky, data, keyField, rowClassName, renderRow, onSelectRow, selected, tableHeadProps, children, tfoot, onChangeSort, ...rest }: Omit<SortableTableProps<T>, 'fields' | 'currentSort'>): import("react/jsx-runtime").JSX.Element;
|
|
3
3
|
declare namespace SortableTable {
|
|
4
4
|
var displayName: string;
|
|
5
5
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SortableTableHeadProps } from './types';
|
|
2
|
-
declare function SortableTableHead<T = unknown>({
|
|
2
|
+
declare function SortableTableHead<T = unknown>({ onChangeSort, }: SortableTableHeadProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
3
3
|
declare namespace SortableTableHead {
|
|
4
4
|
var displayName: string;
|
|
5
5
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { SortProps } from './types';
|
|
2
|
+
export interface SortableTableHeadWrapperProps<T = unknown> {
|
|
3
|
+
onChangeSort: (sort: SortProps<T>) => void;
|
|
4
|
+
}
|
|
5
|
+
declare function SortableTableHeadWrapper<T = unknown>({ onChangeSort, }: SortableTableHeadWrapperProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
6
|
+
declare namespace SortableTableHeadWrapper {
|
|
7
|
+
var displayName: string;
|
|
8
|
+
}
|
|
9
|
+
export default SortableTableHeadWrapper;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SortableTableTHProps } from './types';
|
|
2
|
-
declare function SortableTableTH<T = unknown>({ field, sorted, ascending, className, onClick }: SortableTableTHProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
2
|
+
declare function SortableTableTH<T = unknown>({ field, sorted, ascending, className, onClick }: SortableTableTHProps<T>): import("react/jsx-runtime").JSX.Element | null;
|
|
3
3
|
declare namespace SortableTableTH {
|
|
4
4
|
var displayName: string;
|
|
5
5
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { DataTableProps } from './types';
|
|
2
|
+
declare function StandaloneDataTable<T = unknown>({ fields, ...rest }: DataTableProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
3
|
+
declare namespace StandaloneDataTable {
|
|
4
|
+
var displayName: string;
|
|
5
|
+
}
|
|
6
|
+
export default StandaloneDataTable;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DataTableField, DataTableRowProps } from './types';
|
|
2
|
+
export interface StandaloneDataTableRowProps<T = unknown> extends DataTableRowProps<T> {
|
|
3
|
+
fields: DataTableField<T>[];
|
|
4
|
+
}
|
|
5
|
+
declare function StandaloneDataTableRow<T = unknown>({ fields, className, rowClassName, selected, row, trRef, onClick, ...rest }: StandaloneDataTableRowProps<T>): import("react/jsx-runtime").JSX.Element | null;
|
|
6
|
+
declare namespace StandaloneDataTableRow {
|
|
7
|
+
var displayName: string;
|
|
8
|
+
}
|
|
9
|
+
export default StandaloneDataTableRow;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { SortableTableProps } from './types';
|
|
2
|
+
declare function StandaloneSortableTable<T = unknown>({ fields, currentSort, ...rest }: SortableTableProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
3
|
+
declare namespace StandaloneSortableTable {
|
|
4
|
+
var displayName: string;
|
|
5
|
+
}
|
|
6
|
+
export default StandaloneSortableTable;
|
package/dist/Table.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RefObject, TableHTMLAttributes } from 'react';
|
|
2
2
|
import { DataTableProps } from './types';
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
export interface StyledTableProps extends TableHTMLAttributes<HTMLTableElement>, Pick<DataTableProps, 'sticky' | 'responsive'> {
|
|
4
|
+
ref?: RefObject<HTMLTableElement>;
|
|
5
|
+
}
|
|
6
|
+
export default function Table({ sticky, responsive, children, className, ref, ...rest }: StyledTableProps): import("react/jsx-runtime").JSX.Element;
|
package/dist/index.cjs.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),m=require("react"),R=require("@emotion/styled"),f=m.createContext(null);function y({children:e,initialFields:t=[],initialSort:a=null}){const[s,l]=m.useState(t),[r,i]=m.useState(a),c=m.useCallback(x=>{l(x)},[]),o=m.useCallback(x=>{i(x)},[]),u=m.useCallback((x,p)=>{const N=s.map(j=>j.id===x?{...j,...p}:j);l(N)},[s]),d=m.useCallback(x=>s.find(p=>p.id===x),[s]),b=m.useMemo(()=>({fields:s,setFields:c,sort:r,setSort:o,getField:d,updateField:u}),[s,c,r,o,u,d]);return n.jsx(f.Provider,{value:b,children:e})}y.displayName="DataTableProvider";function E(e){var t,a,s="";if(typeof e=="string"||typeof e=="number")s+=e;else if(typeof e=="object")if(Array.isArray(e)){var l=e.length;for(t=0;t<l;t++)e[t]&&(a=E(e[t]))&&(s&&(s+=" "),s+=a)}else for(a in e)e[a]&&(s&&(s+=" "),s+=a);return s}function h(){for(var e,t,a=0,s="",l=arguments.length;a<l;a++)(e=arguments[a])&&(t=E(e))&&(s&&(s+=" "),s+=t);return s}const F=R.table`
|
|
2
2
|
--table-sticky-top: ${e=>e.sticky?"0":void 0};
|
|
3
3
|
|
|
4
4
|
thead {
|
|
@@ -10,11 +10,11 @@
|
|
|
10
10
|
background: ${e=>e.sticky?"linear-gradient(var(--bs-table-bg) 75%, rgba(var(--bs-secondary-bg-rgb), 0.9))":"unset"};
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
-
|
|
13
|
+
`;function M({sticky:e,responsive:t,children:a,className:s,ref:l,...r}){if(t){const i=h(s,{"table-responsive":t===!0,[`table-responsive-${t}`]:t!==!0});return n.jsx("div",{className:i,children:n.jsx(F,{ref:l,...r,children:a})})}return n.jsx(F,{className:s,sticky:e,ref:l,...r,children:a})}function v({field:e,className:t,children:a,...s}){if(e.visible===!1)return null;const l=h({[`text-${e.align}`]:!!e.align},t);return n.jsx("th",{className:l,scope:"col",...s,children:a??e.title})}v.displayName="DataTableTH";function T(){const e=m.useContext(f);if(!e)throw new Error("useTableContext must be used within a DataTableProvider");return[e.fields,e.setFields]}function q({...e}){const[t]=T();return n.jsx("thead",{...e,children:n.jsx("tr",{children:t.map((a,s)=>n.jsx(v,{...a.thProps,field:a,className:h(typeof a.className=="function"?{[`text-${a.align}`]:!!a.align}:a.className)},String(a.id??s)))})})}q.displayName="DataTableHead";function D({className:e,size:t,responsive:a,sticky:s,data:l,keyField:r,rowClassName:i,renderRow:c,onSelectRow:o,selected:u,tableHeadProps:d,children:b,tfoot:x,...p}){const N=h("table",e,{[`table-${t}`]:!!t});return n.jsxs(M,{sticky:s,responsive:a,className:N,...p,children:[n.jsx(C,{}),n.jsx(q,{...d}),!!l.length&&n.jsx(S,{data:l,keyField:r,rowClassName:i,renderRow:c,onSelectRow:o,selected:u}),b,x]})}D.displayName="DataTable";function B({fields:e,...t}){return n.jsx(y,{initialFields:e,children:n.jsx(D,{...t})})}B.displayName="StandaloneDataTable";function W({field:e,row:t,className:a,as:s,...l}){if(e.visible===!1)return null;const r=h({[`text-${e.align}`]:!!e.align},a,typeof e.className=="function"?e.className(t):e.className);return m.createElement(s??e.as??"td",{className:r,scope:(s??e.as)==="th"?"row":void 0,colSpan:e.colSpan,...e.cellProps,...l},t[e.field]===void 0&&!e.render?null:typeof e.render=="function"?e.render(t):t[e.field])}W.displayName="DataTableCell";function k({className:e,rowClassName:t,selected:a,row:s,trRef:l,onClick:r,...i}){const[c]=T(),o=d=>{r?.(s,d)},u=typeof t=="function"?t(s):t;return s?n.jsx("tr",{ref:l,className:h({"table-active":a},e,u),onClick:o,...i,children:c.map((d,b)=>n.jsx(W,{field:d,row:s},String(d?.id??b)))}):null}k.displayName="DataTableRow";function S({data:e,keyField:t,rowClassName:a,renderRow:s,onSelectRow:l,selected:r="",children:i,...c}){return n.jsxs("tbody",{...c,children:[e.map(o=>{const u=String(typeof t=="function"?t(o):o[t]),d=typeof r=="function"?r(o):u===r;return s?s(o):n.jsx(k,{onClick:l,rowClassName:a,row:o,selected:d},u)}),i]})}S.displayName="DataTableTBody";function g(){const e=m.useContext(f);if(!e)throw new Error("useTableSort must be used within a DataTableProvider");return[e.sort,e.setSort]}const G=e=>e?e==="end"?"flex-end":"center":"flex-start",I=R.div`
|
|
14
14
|
display: flex;
|
|
15
15
|
width: 100%;
|
|
16
16
|
flex-direction: ${e=>e.align==="end"?"row-reverse":"row"};
|
|
17
|
-
justify-content: ${e=>
|
|
17
|
+
justify-content: ${e=>G(e.align)};
|
|
18
18
|
|
|
19
19
|
.sort-icon {
|
|
20
20
|
flex-grow: ${e=>e.align==="end"?"1":"0"};
|
|
@@ -26,9 +26,5 @@
|
|
|
26
26
|
opacity: 0.75;
|
|
27
27
|
transition: opacity 0.2s;
|
|
28
28
|
}
|
|
29
|
-
`;function
|
|
30
|
-
&.col-collapsed {
|
|
31
|
-
visibility: collapse;
|
|
32
|
-
}
|
|
33
|
-
`;function y(){const e=f();return s.jsx("colgroup",{children:e.map((t,a)=>s.jsx(K,{className:x(t.colClassName,{"col-collapsed":t.collapse}),span:t.colSpan??1},a))})}y.displayName="DataTableCols";exports.DataTable=W;exports.DataTableCols=y;exports.DataTableProvider=g;exports.DataTableRow=D;exports.DataTableTBody=T;exports.DataTableTH=N;exports.DataTableWithContext=M;exports.RowsPerPage=$;exports.SortableTable=B;exports.SortableTableHead=k;exports.SortableTableTH=S;exports.SortableTableWithContext=q;exports.TablePagination=E;exports.useField=V;exports.useHasTableFieldsContext=G;exports.useTableContext=F;exports.useTableFields=f;
|
|
29
|
+
`;function $({field:e,sorted:t,ascending:a,className:s,onClick:l}){if(e.visible===!1)return null;if(!e.sortable)return n.jsx(v,{field:e,className:s});const{className:r,...i}=e.thProps??{},c=h(s,r,{[`text-${e.align}`]:!!e.align}),o=()=>{l({field:e.field,ascending:t?!a:!0})},u={"bi-arrow-down":a,"bi-arrow-up":!a};return n.jsx("th",{...i,className:h("sortable",c),scope:"col",onClick:o,children:n.jsxs(I,{sorted:t,align:e.align,children:[n.jsx("div",{className:"field-title",children:e.title}),n.jsx("div",{className:h("me-1 sort-icon",u)})]})})}$.displayName="SortableTableTH";function H({onChangeSort:e}){const[t]=T(),[a]=g();return n.jsx("thead",{children:n.jsx("tr",{children:t.map((s,l)=>n.jsx($,{field:s,sorted:a?.field===s.field,ascending:a?.ascending,className:h(typeof s.className=="function"?{[`text-${s.align}`]:!!s.align}:s.className),onClick:e},l))})})}H.displayName="SortableTableHead";function _({onChangeSort:e}){const[t]=T(),[a]=g();return n.jsx(H,{fields:t,currentSort:a,onChangeSort:e})}_.displayName="SortableTableHeadWrapper";function w({className:e,size:t,responsive:a,sticky:s,data:l,keyField:r,rowClassName:i,renderRow:c,onSelectRow:o,selected:u,tableHeadProps:d,children:b,tfoot:x,onChangeSort:p,...N}){const j=h("table",e,{[`table-${t}`]:!!t});return n.jsxs(M,{className:j,responsive:a,sticky:s,...N,children:[n.jsx(C,{}),n.jsx(_,{onChangeSort:p,...d}),!!l.length&&n.jsx(S,{data:l,keyField:r,rowClassName:i,renderRow:c,onSelectRow:o,selected:u}),b,x]})}w.displayName="SortableTable";function J({nextSort:e}){const[,t]=g();return m.useEffect(()=>{console.log("setNextSort",e),t(e)},[e,t]),null}function A({fields:e,currentSort:t,...a}){return n.jsxs(y,{initialFields:e,initialSort:t,children:[n.jsx(J,{nextSort:t}),n.jsx(w,{...a})]})}A.displayName="StandaloneSortableTable";const L=[10,25,50,100,250,500,1e3];function P({value:e,pageValues:t=L,size:a,label:s,className:l,onChange:r,...i}){const c=m.useId(),o=b=>r(Number(b.target.value)),u=l??h("form-select",{[`form-select-${a}`]:!!a}),d=h("input-group",{[`input-group-${a}`]:!!a});return n.jsxs("div",{className:d,children:[n.jsx("label",{className:"input-group-text",htmlFor:c,children:s??"Rows"}),n.jsx("select",{className:u,id:c,value:e,onChange:o,...i,children:t.map(b=>n.jsx("option",{value:b,children:b},b))})]},e)}P.displayName="RowsPerPage";function V({page:e,rowsPerPage:t,onChangePage:a,count:s,size:l,showFirst:r,showLast:i,className:c,rowsPerPageProps:o,...u}){const d=s===0?0:e*t+1,b=Math.min(e*t+t,s),x=t===0?0:Math.floor((s-1)/t),p=h("btn btn-link",{[`btn-${l}`]:!!l});return n.jsxs("div",{className:h("row g-3 justify-content-end",c),...u,children:[!!o&&n.jsx("div",{className:"col-auto",children:n.jsx(P,{...o,value:t,size:l})}),n.jsx("div",{className:"col-auto",children:n.jsxs("div",{className:"row g-3 flex-nowrap align-items-baseline",children:[n.jsxs("div",{className:"col-auto",children:[d,"-",b," of ",s]}),r&&n.jsx("div",{className:"col-auto",children:n.jsx("button",{className:p,disabled:e===0,onClick:()=>a(0),"aria-label":"First page",children:n.jsx("span",{className:"bi-chevron-bar-left","aria-hidden":"true"})})}),n.jsx("div",{className:"col-auto",children:n.jsx("button",{className:p,disabled:e===0,onClick:()=>a(e-1),"aria-label":"Previous page",children:n.jsx("span",{className:"bi-chevron-left","aria-hidden":"true"})})}),n.jsx("div",{className:"col-auto",children:n.jsx("button",{className:p,disabled:e>=x,onClick:()=>a(e+1),"aria-label":"Next page",children:n.jsx("span",{className:"bi-chevron-right","aria-hidden":"true"})})}),i&&n.jsx("div",{className:"col-auto",children:n.jsx("button",{className:p,disabled:e>=x,onClick:()=>a(x),"aria-label":"Last page",children:n.jsx("span",{className:"bi-chevron-bar-right","aria-hidden":"true"})})})]})})]})}V.displayname="TablePagination";function C(){const[e]=T();return n.jsx("colgroup",{children:e.filter(t=>t.visible!==!1).map((t,a)=>n.jsx("col",{className:t.colClassName,span:t.colSpan??1},a))})}C.displayName="DataTableCols";function O(e){const t=m.useContext(f);if(!t)throw new Error("useField must be used within a DataTableProvider");return[t.fields.find(a=>a.id===e)??null,t.updateField]}function K(){const e=m.useContext(f);if(!e)throw new Error("useTableContext must be used within a DataTableProvider");return e}exports.DataTable=B;exports.DataTableCols=C;exports.DataTableContext=f;exports.DataTableProvider=y;exports.DataTableRow=k;exports.DataTableTBody=S;exports.DataTableTH=v;exports.DataTableWithContext=D;exports.RowsPerPage=P;exports.SortableTable=w;exports.SortableTableHead=H;exports.SortableTableTH=$;exports.StandaloneSortableTable=A;exports.TablePagination=V;exports.useField=O;exports.useTableContext=K;exports.useTableFields=T;exports.useTableSort=g;
|
|
34
30
|
//# sourceMappingURL=index.cjs.js.map
|