@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.
Files changed (63) hide show
  1. package/CHANGELOG.md +28 -1
  2. package/README.md +3 -3
  3. package/dist/ContainedDataTable.d.ts +6 -0
  4. package/dist/ContainedDataTableRow.d.ts +6 -0
  5. package/dist/ContainedSortableTable.d.ts +6 -0
  6. package/dist/DataTable.d.ts +2 -2
  7. package/dist/DataTableCell.d.ts +173 -173
  8. package/dist/DataTableContext.d.ts +2 -2
  9. package/dist/DataTableHead.d.ts +1 -1
  10. package/dist/DataTableProvider.d.ts +2 -2
  11. package/dist/DataTableRow.d.ts +2 -2
  12. package/dist/DataTableTBody.d.ts +1 -1
  13. package/dist/DataTableTH.d.ts +1 -1
  14. package/dist/RowsPerPage.d.ts +1 -1
  15. package/dist/SortHelper.d.ts +5 -0
  16. package/dist/SortableTable.d.ts +2 -2
  17. package/dist/SortableTableHead.d.ts +1 -1
  18. package/dist/SortableTableHeadWrapper.d.ts +1 -1
  19. package/dist/SortableTableTH.d.ts +1 -1
  20. package/dist/Table.d.ts +2 -2
  21. package/dist/TablePagination.d.ts +1 -1
  22. package/dist/index.cjs.js +3 -3
  23. package/dist/index.cjs.js.map +1 -1
  24. package/dist/index.d.ts +5 -6
  25. package/dist/index.es.js +127 -127
  26. package/dist/index.es.js.map +1 -1
  27. package/dist/types.d.ts +3 -2
  28. package/dist/useField.d.ts +1 -1
  29. package/dist/useTableContext.d.ts +1 -1
  30. package/dist/useTableFields.d.ts +1 -1
  31. package/dist/useTableSort.d.ts +1 -1
  32. package/{eslint.config.mjs → eslint.config.js} +2 -2
  33. package/package.json +9 -12
  34. package/src/ContainedDataTable.tsx +41 -0
  35. package/src/ContainedDataTableRow.tsx +39 -0
  36. package/src/ContainedSortableTable.tsx +42 -0
  37. package/src/DataTable.tsx +9 -34
  38. package/src/DataTableHead.tsx +1 -1
  39. package/src/DataTableRow.tsx +10 -12
  40. package/src/DataTableTBody.tsx +4 -5
  41. package/src/DataTableTH.tsx +0 -1
  42. package/src/RowsPerPage.tsx +1 -1
  43. package/src/{StandaloneSortHelper.tsx → SortHelper.tsx} +1 -1
  44. package/src/SortableTable.tsx +12 -35
  45. package/src/SortableTableHead.tsx +0 -1
  46. package/src/SortableTableTH.tsx +0 -1
  47. package/src/Table.tsx +1 -1
  48. package/src/TablePagination.tsx +0 -1
  49. package/src/index.tsx +5 -6
  50. package/src/types.ts +2 -1
  51. package/test/TableColumnsHandler.tsx +3 -3
  52. package/test/TestTable.tsx +5 -5
  53. package/test/tableFields.tsx +0 -1
  54. package/tsconfig-dts.json +8 -0
  55. package/tsconfig.json +1 -1
  56. package/vite.config.ts +3 -2
  57. package/dist/StandaloneDataTable.d.ts +0 -6
  58. package/dist/StandaloneDataTableRow.d.ts +0 -9
  59. package/dist/StandaloneSortHelper.d.ts +0 -5
  60. package/dist/StandaloneSortableTable.d.ts +0 -6
  61. package/src/StandaloneDataTable.tsx +0 -16
  62. package/src/StandaloneDataTableRow.tsx +0 -42
  63. 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 StandaloneSortHelper<T = unknown>({nextSort}:StandaloneSortHelperProps<T>) {
8
+ export function SortHelper<T = unknown>({nextSort}:StandaloneSortHelperProps<T>) {
9
9
  const [, setNextSort] = useTableSort<T>();
10
10
  useEffect(() => {
11
11
  console.log('setNextSort', nextSort);
@@ -1,43 +1,20 @@
1
1
  import type {SortableTableProps} from "./types";
2
- import clsx from "clsx";
3
- import Table from "./Table";
4
- import {DataTableCols, DataTableTBody} from "./index";
5
- import React from "react";
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
- className,
10
- size,
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
- }: Omit<SortableTableProps<T>, 'fields' | 'currentSort'>) {
25
- const tableClassName = clsx('table', className, {
26
- [`table-${size}`]: !!size,
27
- })
28
-
11
+ }: SortableTableProps<T>) {
29
12
  return (
30
- <Table className={tableClassName} responsive={responsive} sticky={sticky} {...rest}>
31
- <DataTableCols/>
32
- <SortableTableHeadWrapper onChangeSort={onChangeSort} {...tableHeadProps}/>
33
- {!!data.length && (
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';
@@ -1,4 +1,3 @@
1
- import React from "react";
2
1
  import SortableTableTH from "./SortableTableTH";
3
2
  import type {SortableTableHeadProps} from "./types";
4
3
  import clsx from "clsx";
@@ -1,4 +1,3 @@
1
- import React from "react";
2
1
  import DataTableTH from "./DataTableTH";
3
2
  import type {SortableTableTHProps, UIFlexAlign} from "./types";
4
3
  import styled from '@emotion/styled';
package/src/Table.tsx CHANGED
@@ -1,4 +1,4 @@
1
- import React, {type RefObject, type TableHTMLAttributes} from 'react';
1
+ import {type RefObject, type TableHTMLAttributes} from 'react';
2
2
  import styled from "@emotion/styled";
3
3
  import type {DataTableProps} from "./types";
4
4
  import clsx from "clsx";
@@ -1,4 +1,3 @@
1
- import React from 'react';
2
1
  import RowsPerPage from "./RowsPerPage";
3
2
  import type {TablePaginationProps} from "./types";
4
3
  import clsx from "clsx";
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 './StandaloneDataTable';
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 StandaloneSortableTable} from './StandaloneSortableTable';
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 DataTableWithContext} from './DataTable'
16
- export {default as SortableTable} from './SortableTable'
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 React, {type HTMLAttributes, type MouseEvent, type ReactNode, type TableHTMLAttributes} from 'react'
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 React, {useCallback, useId} from "react";
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] = React.useState<boolean>(getField('ProductLineDesc')?.visible ?? true);
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: React.ChangeEvent<HTMLInputElement>) => {
17
+ const handleVisibleChange = (ev: ChangeEvent<HTMLInputElement>) => {
18
18
  toggleFieldCollapse('ProductLineDesc', ev.target.checked);
19
19
  }
20
20
 
@@ -1,6 +1,6 @@
1
- import React, {useState} from 'react';
1
+ import {useState} from 'react';
2
2
  import type {ProductLine} from './data'
3
- import {SortableTable, type SortProps, useTableSort} from "../src";
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
- <SortableTable onChangeSort={sortChangeHandler} size="lg" responsive
36
- data={data.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage)}
37
- keyField="ProductLine" rowClassName={rowClassName}/>
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={{
@@ -1,6 +1,5 @@
1
1
  import type {SortableTableField} from "../src";
2
2
  import type {ProductLine} from "./data";
3
- import React from "react";
4
3
 
5
4
  export const tableFields: SortableTableField<ProductLine>[] = [
6
5
  {
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "declaration": true,
5
+ "emitDeclarationOnly": true,
6
+ "noEmit": false,
7
+ }
8
+ }
package/tsconfig.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "allowJs": false,
4
4
  "allowSyntheticDefaultImports": true,
5
5
  "declaration": true,
6
- "declarationDir": "./dist/types",
6
+ "declarationDir": "./dist",
7
7
  "esModuleInterop": true,
8
8
  "forceConsistentCasingInFileNames": true,
9
9
  "isolatedModules": true,
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: [react({}), dts({include: ['src']})],
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,5 +0,0 @@
1
- import { SortProps } from './types';
2
- export interface StandaloneSortHelperProps<T = unknown> {
3
- nextSort: SortProps<T>;
4
- }
5
- export declare function StandaloneSortHelper<T = unknown>({ nextSort }: StandaloneSortHelperProps<T>): null;
@@ -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';