@chumsinc/sortable-tables 3.0.2 → 3.1.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 +28 -1
- package/README.md +3 -3
- package/dist/ContainedDataTable.d.ts +6 -0
- package/dist/ContainedDataTableRow.d.ts +6 -0
- package/dist/ContainedSortableTable.d.ts +6 -0
- package/dist/DataTable.d.ts +2 -2
- package/dist/DataTableCell.d.ts +173 -173
- package/dist/DataTableContext.d.ts +2 -2
- package/dist/DataTableHead.d.ts +1 -1
- package/dist/DataTableProvider.d.ts +2 -2
- package/dist/DataTableRow.d.ts +2 -2
- package/dist/DataTableTBody.d.ts +1 -1
- package/dist/DataTableTH.d.ts +1 -1
- package/dist/RowsPerPage.d.ts +1 -1
- package/dist/SortHelper.d.ts +5 -0
- package/dist/SortableTable.d.ts +2 -2
- package/dist/SortableTableHead.d.ts +1 -1
- package/dist/SortableTableHeadWrapper.d.ts +1 -1
- package/dist/SortableTableTH.d.ts +1 -1
- package/dist/Table.d.ts +2 -2
- package/dist/TablePagination.d.ts +1 -1
- package/dist/index.cjs.js +3 -3
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +5 -6
- package/dist/index.es.js +127 -127
- package/dist/index.es.js.map +1 -1
- package/dist/types.d.ts +3 -2
- package/dist/useField.d.ts +1 -1
- package/dist/useTableContext.d.ts +1 -1
- package/dist/useTableFields.d.ts +1 -1
- package/dist/useTableSort.d.ts +1 -1
- package/{eslint.config.mjs → eslint.config.js} +2 -2
- package/package.json +9 -12
- package/src/ContainedDataTable.tsx +41 -0
- package/src/ContainedDataTableRow.tsx +39 -0
- package/src/ContainedSortableTable.tsx +42 -0
- package/src/DataTable.tsx +9 -34
- package/src/DataTableHead.tsx +1 -1
- package/src/DataTableRow.tsx +10 -12
- package/src/DataTableTBody.tsx +4 -5
- package/src/DataTableTH.tsx +0 -1
- package/src/RowsPerPage.tsx +1 -1
- package/src/{StandaloneSortHelper.tsx → SortHelper.tsx} +1 -1
- package/src/SortableTable.tsx +12 -35
- package/src/SortableTableHead.tsx +0 -1
- package/src/SortableTableTH.tsx +0 -1
- package/src/Table.tsx +1 -1
- package/src/TablePagination.tsx +0 -1
- package/src/index.tsx +5 -6
- package/src/types.ts +2 -1
- package/test/TableColumnsHandler.tsx +3 -3
- package/test/TestTable.tsx +5 -5
- package/test/tableFields.tsx +0 -1
- package/tsconfig-dts.json +8 -0
- package/tsconfig.json +1 -1
- package/vite.config.ts +3 -2
- package/dist/StandaloneDataTable.d.ts +0 -6
- package/dist/StandaloneDataTableRow.d.ts +0 -9
- package/dist/StandaloneSortHelper.d.ts +0 -5
- package/dist/StandaloneSortableTable.d.ts +0 -6
- package/src/StandaloneDataTable.tsx +0 -16
- package/src/StandaloneDataTableRow.tsx +0 -42
- package/src/StandaloneSortableTable.tsx +0 -21
|
@@ -5,7 +5,7 @@ import {useEffect} from "react";
|
|
|
5
5
|
export interface StandaloneSortHelperProps<T = unknown> {
|
|
6
6
|
nextSort: SortProps<T>
|
|
7
7
|
}
|
|
8
|
-
export function
|
|
8
|
+
export function SortHelper<T = unknown>({nextSort}:StandaloneSortHelperProps<T>) {
|
|
9
9
|
const [, setNextSort] = useTableSort<T>();
|
|
10
10
|
useEffect(() => {
|
|
11
11
|
console.log('setNextSort', nextSort);
|
package/src/SortableTable.tsx
CHANGED
|
@@ -1,43 +1,20 @@
|
|
|
1
1
|
import type {SortableTableProps} from "./types";
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
import SortableTableHeadWrapper from "./SortableTableHeadWrapper";
|
|
2
|
+
import DataTableProvider from "./DataTableProvider";
|
|
3
|
+
import ContainedSortableTable from "./ContainedSortableTable";
|
|
4
|
+
import {SortHelper} from "./SortHelper";
|
|
5
|
+
|
|
7
6
|
|
|
8
7
|
export default function SortableTable<T = unknown>({
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
responsive,
|
|
12
|
-
sticky,
|
|
13
|
-
data,
|
|
14
|
-
keyField,
|
|
15
|
-
rowClassName,
|
|
16
|
-
renderRow,
|
|
17
|
-
onSelectRow,
|
|
18
|
-
selected,
|
|
19
|
-
tableHeadProps,
|
|
20
|
-
children,
|
|
21
|
-
tfoot,
|
|
22
|
-
onChangeSort,
|
|
8
|
+
fields,
|
|
9
|
+
currentSort,
|
|
23
10
|
...rest
|
|
24
|
-
}:
|
|
25
|
-
const tableClassName = clsx('table', className, {
|
|
26
|
-
[`table-${size}`]: !!size,
|
|
27
|
-
})
|
|
28
|
-
|
|
11
|
+
}: SortableTableProps<T>) {
|
|
29
12
|
return (
|
|
30
|
-
<
|
|
31
|
-
<
|
|
32
|
-
<
|
|
33
|
-
|
|
34
|
-
<DataTableTBody data={data} keyField={keyField} rowClassName={rowClassName}
|
|
35
|
-
renderRow={renderRow}
|
|
36
|
-
onSelectRow={onSelectRow} selected={selected}/>
|
|
37
|
-
)}
|
|
38
|
-
{children}
|
|
39
|
-
{tfoot}
|
|
40
|
-
</Table>
|
|
13
|
+
<DataTableProvider initialFields={fields} initialSort={currentSort}>
|
|
14
|
+
<SortHelper nextSort={currentSort}/>
|
|
15
|
+
<ContainedSortableTable {...rest}/>
|
|
16
|
+
</DataTableProvider>
|
|
41
17
|
)
|
|
42
18
|
}
|
|
19
|
+
|
|
43
20
|
SortableTable.displayName = 'SortableTable';
|
package/src/SortableTableTH.tsx
CHANGED
package/src/Table.tsx
CHANGED
package/src/TablePagination.tsx
CHANGED
package/src/index.tsx
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
/* eslint-disable react-refresh/only-export-components */
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
export {default as DataTable} from './
|
|
4
|
+
export {default as DataTable} from './DataTable';
|
|
5
|
+
export {default as ContainedDataTableRow} from './ContainedDataTableRow';
|
|
5
6
|
export {default as DataTableRow} from './DataTableRow';
|
|
6
|
-
export {default as StandaloneDataTableRow} from './StandaloneDataTableRow';
|
|
7
7
|
export {default as DataTableTBody} from './DataTableTBody';
|
|
8
8
|
export {default as DataTableTH} from './DataTableTH';
|
|
9
|
-
export {default as
|
|
9
|
+
export {default as SortableTable} from './SortableTable';
|
|
10
10
|
export {default as SortableTableHead} from './SortableTableHead';
|
|
11
11
|
export {default as SortableTableTH} from './SortableTableTH';
|
|
12
12
|
export {default as RowsPerPage} from './RowsPerPage';
|
|
13
13
|
export {default as TablePagination} from './TablePagination';
|
|
14
14
|
export {default as DataTableCols} from './DataTableCols'
|
|
15
|
-
export {default as
|
|
16
|
-
export {default as
|
|
15
|
+
export {default as ContainedDataTable} from './ContainedDataTable'
|
|
16
|
+
export {default as ContainedSortableTable} from './ContainedSortableTable'
|
|
17
17
|
export {default as DataTableProvider} from './DataTableProvider'
|
|
18
18
|
export {useField} from './useField'
|
|
19
19
|
export {useTableFields} from './useTableFields'
|
|
@@ -21,7 +21,6 @@ export {useTableSort} from './useTableSort'
|
|
|
21
21
|
export {useTableContext} from './useTableContext'
|
|
22
22
|
export {DataTableContext, type TableContextData} from './DataTableContext'
|
|
23
23
|
export type {TableProviderProps} from './DataTableProvider'
|
|
24
|
-
export type {StandaloneDataTableRowProps} from './StandaloneDataTableRow'
|
|
25
24
|
export type {
|
|
26
25
|
SortProps,
|
|
27
26
|
DataTableField,
|
package/src/types.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {type HTMLAttributes, type MouseEvent, type ReactNode, type TableHTMLAttributes} from 'react'
|
|
2
2
|
import type {ClassValue} from "clsx";
|
|
3
3
|
|
|
4
4
|
|
|
@@ -75,6 +75,7 @@ export interface DataTableTBodyProps<T = unknown> extends TableHTMLAttributes<HT
|
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
export interface DataTableRowProps<T = unknown> extends Omit<TableHTMLAttributes<HTMLTableRowElement>, 'onClick'> {
|
|
78
|
+
fields: DataTableField<T>[];
|
|
78
79
|
rowClassName?: string | ClassValue | ((row: T) => string | ClassValue);
|
|
79
80
|
selected?: boolean;
|
|
80
81
|
row: T;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {useTableContext} from "../src";
|
|
2
|
-
import
|
|
2
|
+
import {type ChangeEvent, useCallback, useId, useState} from "react";
|
|
3
3
|
import type {ProductLine} from "./data";
|
|
4
4
|
|
|
5
5
|
export default function TableColumnsHandler() {
|
|
6
6
|
const {updateField, getField} = useTableContext<ProductLine>();
|
|
7
|
-
const [visible, setVisible] =
|
|
7
|
+
const [visible, setVisible] = useState<boolean>(getField('ProductLineDesc')?.visible ?? true);
|
|
8
8
|
// const {sort} = useTableSort();
|
|
9
9
|
const id = useId();
|
|
10
10
|
|
|
@@ -14,7 +14,7 @@ export default function TableColumnsHandler() {
|
|
|
14
14
|
setVisible(next);
|
|
15
15
|
}, [updateField]);
|
|
16
16
|
|
|
17
|
-
const handleVisibleChange = (ev:
|
|
17
|
+
const handleVisibleChange = (ev: ChangeEvent<HTMLInputElement>) => {
|
|
18
18
|
toggleFieldCollapse('ProductLineDesc', ev.target.checked);
|
|
19
19
|
}
|
|
20
20
|
|
package/test/TestTable.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {useState} from 'react';
|
|
2
2
|
import type {ProductLine} from './data'
|
|
3
|
-
import {
|
|
3
|
+
import {ContainedSortableTable, type SortProps, useTableSort} from "../src";
|
|
4
4
|
import TablePagination from "../src/TablePagination";
|
|
5
5
|
import TableColumnsHandler from "./TableColumnsHandler";
|
|
6
6
|
|
|
@@ -32,9 +32,9 @@ export default function TestTable({data, onChangeSort}: TestTableProps) {
|
|
|
32
32
|
return (
|
|
33
33
|
<div>
|
|
34
34
|
<TableColumnsHandler/>
|
|
35
|
-
<
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
<ContainedSortableTable onChangeSort={sortChangeHandler} size="lg" responsive
|
|
36
|
+
data={data.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage)}
|
|
37
|
+
keyField="ProductLine" rowClassName={rowClassName}/>
|
|
38
38
|
<TablePagination page={page} onChangePage={setPage} size="sm"
|
|
39
39
|
rowsPerPage={rowsPerPage}
|
|
40
40
|
rowsPerPageProps={{
|
package/test/tableFields.tsx
CHANGED
package/tsconfig.json
CHANGED
package/vite.config.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { defineConfig } from 'vite'
|
|
2
2
|
import react from '@vitejs/plugin-react';
|
|
3
|
-
import dts from 'vite-plugin-dts';
|
|
4
3
|
import {resolve} from 'node:path'
|
|
5
4
|
import {cwd} from 'node:process'
|
|
6
5
|
|
|
7
6
|
// https://vite.dev/config/
|
|
8
7
|
export default defineConfig({
|
|
9
|
-
plugins: [
|
|
8
|
+
plugins: [
|
|
9
|
+
react({}),
|
|
10
|
+
],
|
|
10
11
|
resolve: {},
|
|
11
12
|
build: {
|
|
12
13
|
lib: {
|
|
@@ -1,6 +0,0 @@
|
|
|
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;
|
|
@@ -1,9 +0,0 @@
|
|
|
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;
|
|
@@ -1,6 +0,0 @@
|
|
|
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;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type {DataTableProps} from "./types";
|
|
2
|
-
import DataTableProvider from "./DataTableProvider";
|
|
3
|
-
import DataTable from "./DataTable";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export default function StandaloneDataTable<T = unknown>({
|
|
7
|
-
fields,
|
|
8
|
-
...rest
|
|
9
|
-
}: DataTableProps<T>) {
|
|
10
|
-
return (
|
|
11
|
-
<DataTableProvider initialFields={fields}>
|
|
12
|
-
<DataTable {...rest}/>
|
|
13
|
-
</DataTableProvider>
|
|
14
|
-
)
|
|
15
|
-
}
|
|
16
|
-
StandaloneDataTable.displayName = 'StandaloneDataTable';
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import React, {type MouseEvent} from 'react';
|
|
2
|
-
import type {DataTableField, DataTableRowProps} from "./types";
|
|
3
|
-
import DataTableCell from "./DataTableCell";
|
|
4
|
-
import clsx from "clsx";
|
|
5
|
-
import {useTableFields} from "./useTableFields";
|
|
6
|
-
|
|
7
|
-
export interface StandaloneDataTableRowProps<T = unknown> extends DataTableRowProps<T> {
|
|
8
|
-
fields: DataTableField<T>[]
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export default function StandaloneDataTableRow<T = unknown>({
|
|
12
|
-
fields,
|
|
13
|
-
className,
|
|
14
|
-
rowClassName,
|
|
15
|
-
selected,
|
|
16
|
-
row,
|
|
17
|
-
trRef,
|
|
18
|
-
onClick,
|
|
19
|
-
...rest
|
|
20
|
-
}: StandaloneDataTableRowProps<T>) {
|
|
21
|
-
const clickHandler = (ev: MouseEvent<HTMLTableRowElement>) => {
|
|
22
|
-
onClick?.(row, ev)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const _className = typeof rowClassName === 'function' ? rowClassName(row) : rowClassName;
|
|
26
|
-
if (!row) {
|
|
27
|
-
return null;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return (
|
|
31
|
-
<tr ref={trRef}
|
|
32
|
-
className={clsx({'table-active': selected}, className, _className)}
|
|
33
|
-
onClick={clickHandler}
|
|
34
|
-
{...rest}>
|
|
35
|
-
{fields
|
|
36
|
-
.map((field, index) => (
|
|
37
|
-
<DataTableCell key={String(field?.id ?? index)} field={field} row={row}/>
|
|
38
|
-
))}
|
|
39
|
-
</tr>
|
|
40
|
-
)
|
|
41
|
-
}
|
|
42
|
-
StandaloneDataTableRow.displayName = 'StandaloneDataTableRow';
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import type {SortableTableProps} from "./types";
|
|
3
|
-
import DataTableProvider from "./DataTableProvider";
|
|
4
|
-
import SortableTable from "./SortableTable";
|
|
5
|
-
import {StandaloneSortHelper} from "./StandaloneSortHelper";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export default function StandaloneSortableTable<T = unknown>({
|
|
9
|
-
fields,
|
|
10
|
-
currentSort,
|
|
11
|
-
...rest
|
|
12
|
-
}: SortableTableProps<T>) {
|
|
13
|
-
return (
|
|
14
|
-
<DataTableProvider initialFields={fields} initialSort={currentSort}>
|
|
15
|
-
<StandaloneSortHelper nextSort={currentSort} />
|
|
16
|
-
<SortableTable {...rest}/>
|
|
17
|
-
</DataTableProvider>
|
|
18
|
-
)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
StandaloneSortableTable.displayName = 'StandaloneSortableTable';
|