@bsol-oss/react-datatable5 1.0.2 → 1.0.4
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/dist/index.js +3 -3
- package/dist/types/components/DataTable.d.ts +17 -0
- package/dist/types/components/DataTableContext.d.ts +8 -0
- package/dist/types/components/EditFilterButton.d.ts +2 -0
- package/dist/types/components/EditSortingButton.d.ts +2 -0
- package/dist/types/components/EditViewButton.d.ts +2 -0
- package/dist/types/components/PageSizeControl.d.ts +5 -0
- package/dist/types/components/ResetFilteringButton.d.ts +2 -0
- package/dist/types/components/ResetSortingButton.d.ts +2 -0
- package/dist/types/components/Table.d.ts +6 -0
- package/dist/types/components/TableBody.d.ts +2 -0
- package/dist/types/components/TableCardContainer.d.ts +6 -0
- package/dist/types/components/TableCards.d.ts +2 -0
- package/dist/types/components/TableFilter.d.ts +2 -0
- package/dist/types/components/TableFooter.d.ts +2 -0
- package/dist/types/components/TableHeader.d.ts +5 -0
- package/dist/types/components/TablePagination.d.ts +4 -0
- package/dist/types/components/TableSorter.d.ts +2 -0
- package/dist/types/components/TextCell.d.ts +2 -0
- package/dist/types/components/useDataFromUrl.d.ts +13 -0
- package/dist/types/components/useDataTable.d.ts +4 -0
- package/dist/types/index.d.ts +15 -0
- package/dist/types/stories/CardViewShowcase.d.ts +2 -0
- package/dist/types/stories/DataTable.stories.d.ts +13 -0
- package/dist/types/stories/TableViewShowcase.d.ts +2 -0
- package/package.json +8 -1
- package/src/components/DataTable.tsx +23 -8
- package/src/components/DataTableContext.tsx +2 -3
- package/src/components/Table.tsx +1 -1
- package/src/components/TableHeader.tsx +1 -1
- package/src/components/TablePagination.tsx +3 -2
- package/src/stories/DataTable.stories.tsx +14 -41
- package/tsconfig.json +3 -2
- package/src/components/ChakraDataTable.tsx +0 -279
- package/src/stories/Button.stories.ts +0 -52
- package/src/stories/Button.tsx +0 -52
- package/src/stories/Configure.mdx +0 -369
- package/src/stories/DataTable-test.stories.tsx +0 -83
- package/src/stories/DefaultDataTable.tsx +0 -141
- package/src/stories/Header.stories.ts +0 -33
- package/src/stories/Header.tsx +0 -71
- package/src/stories/Page.stories.ts +0 -32
- package/src/stories/Page.tsx +0 -91
- package/src/stories/assets/accessibility.png +0 -0
- package/src/stories/assets/accessibility.svg +0 -5
- package/src/stories/assets/addon-library.png +0 -0
- package/src/stories/assets/assets.png +0 -0
- package/src/stories/assets/avif-test-image.avif +0 -0
- package/src/stories/assets/context.png +0 -0
- package/src/stories/assets/discord.svg +0 -15
- package/src/stories/assets/docs.png +0 -0
- package/src/stories/assets/figma-plugin.png +0 -0
- package/src/stories/assets/github.svg +0 -3
- package/src/stories/assets/share.png +0 -0
- package/src/stories/assets/styling.png +0 -0
- package/src/stories/assets/testing.png +0 -0
- package/src/stories/assets/theming.png +0 -0
- package/src/stories/assets/tutorials.svg +0 -12
- package/src/stories/assets/youtube.svg +0 -4
- package/src/stories/button.css +0 -30
- package/src/stories/header.css +0 -32
- package/src/stories/page.css +0 -69
package/dist/index.js
CHANGED
|
@@ -11,7 +11,7 @@ var md = require('react-icons/md');
|
|
|
11
11
|
var icons = require('@chakra-ui/icons');
|
|
12
12
|
|
|
13
13
|
const TableContext = react.createContext({
|
|
14
|
-
table:
|
|
14
|
+
table: {},
|
|
15
15
|
refreshData: () => { },
|
|
16
16
|
});
|
|
17
17
|
|
|
@@ -44,7 +44,7 @@ const useDataFromUrl = ({ url, params = {}, defaultData, }) => {
|
|
|
44
44
|
return { data, loading, hasError, refreshData };
|
|
45
45
|
};
|
|
46
46
|
|
|
47
|
-
const DataTable = ({ columns, url, children }) => {
|
|
47
|
+
const DataTable = ({ columns, url, children, }) => {
|
|
48
48
|
const [sorting, setSorting] = react.useState([]);
|
|
49
49
|
const [columnFilters, setColumnFilters] = react.useState([]); // can set initial column filter state here
|
|
50
50
|
const [pagination, setPagination] = react.useState({
|
|
@@ -190,7 +190,7 @@ const TableHeader = ({ canResize }) => {
|
|
|
190
190
|
}) }, crypto.randomUUID()))) }));
|
|
191
191
|
};
|
|
192
192
|
|
|
193
|
-
const TablePagination = (
|
|
193
|
+
const TablePagination = ({}) => {
|
|
194
194
|
const { firstPage, getCanPreviousPage, previousPage, getState, nextPage, getCanNextPage, lastPage, } = useDataTable().table;
|
|
195
195
|
return (jsxRuntime.jsxs(react$1.ButtonGroup, { isAttached: true, children: [jsxRuntime.jsx(react$1.IconButton, { icon: jsxRuntime.jsx(md.MdFirstPage, {}), onClick: () => firstPage(), disabled: !getCanPreviousPage(), "aria-label": "first-page" }), jsxRuntime.jsx(react$1.IconButton, { icon: jsxRuntime.jsx(md.MdArrowBack, {}), onClick: () => previousPage(), disabled: !getCanPreviousPage(), "aria-label": "previous-page" }), jsxRuntime.jsx(react$1.Button, { onClick: () => { }, disabled: !getCanPreviousPage(), children: getState().pagination.pageIndex + 1 }), jsxRuntime.jsx(react$1.IconButton, { onClick: () => nextPage(), disabled: !getCanNextPage(), "aria-label": "next-page", children: jsxRuntime.jsx(md.MdArrowForward, {}) }), jsxRuntime.jsx(react$1.IconButton, { onClick: () => lastPage(), disabled: !getCanNextPage(), "aria-label": "last-page", children: jsxRuntime.jsx(md.MdLastPage, {}) })] }));
|
|
196
196
|
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
import { Column } from "@tanstack/react-table";
|
|
3
|
+
export interface DataTableProps<T> {
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
url: string;
|
|
6
|
+
columns: Column<T>[];
|
|
7
|
+
}
|
|
8
|
+
export interface Result<T> {
|
|
9
|
+
results: T[];
|
|
10
|
+
}
|
|
11
|
+
export interface DataResponse<T> extends Result<T> {
|
|
12
|
+
success: boolean;
|
|
13
|
+
count: number;
|
|
14
|
+
filterCount: number;
|
|
15
|
+
}
|
|
16
|
+
declare const DataTable: <TData>({ columns, url, children, }: DataTableProps<TData>) => import("react/jsx-runtime").JSX.Element;
|
|
17
|
+
export default DataTable;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
interface useDataFromUrlReturn<T> {
|
|
2
|
+
data: T;
|
|
3
|
+
loading: boolean;
|
|
4
|
+
hasError: boolean;
|
|
5
|
+
refreshData: () => void;
|
|
6
|
+
}
|
|
7
|
+
interface useDataFromUrlProps<T> {
|
|
8
|
+
url: string;
|
|
9
|
+
params?: object;
|
|
10
|
+
defaultData: T;
|
|
11
|
+
}
|
|
12
|
+
declare const useDataFromUrl: <T>({ url, params, defaultData, }: useDataFromUrlProps<T>) => useDataFromUrlReturn<T>;
|
|
13
|
+
export default useDataFromUrl;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
DataTable: <TData>({ columns, url, children, }: import("./components/DataTable").DataTableProps<TData>) => import("react/jsx-runtime").JSX.Element;
|
|
3
|
+
EditViewButton: () => import("react/jsx-runtime").JSX.Element;
|
|
4
|
+
PageSizeControl: ({ pageSizes, }: import("./components/PageSizeControl").PageSizeControlProps) => import("react/jsx-runtime").JSX.Element;
|
|
5
|
+
ResetFilteringButton: () => import("react/jsx-runtime").JSX.Element;
|
|
6
|
+
ResetSortingButton: () => import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
Table: ({ children }: import("./components/Table").TableProps) => import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
TableBody: () => import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
TableFilter: () => import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
TableFooter: () => import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
TableHeader: ({ canResize }: import("./components/TableHeader").TableHeaderProps) => import("react/jsx-runtime").JSX.Element;
|
|
12
|
+
TablePagination: ({}: import("./components/TablePagination").PaginationProps) => import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
TextCell: ({ label, children }: any) => import("react/jsx-runtime").JSX.Element;
|
|
14
|
+
};
|
|
15
|
+
export default _default;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { StoryObj } from "@storybook/react";
|
|
2
|
+
declare const meta: {
|
|
3
|
+
title: string;
|
|
4
|
+
component: () => import("react/jsx-runtime").JSX.Element;
|
|
5
|
+
parameters: {};
|
|
6
|
+
argTypes: {};
|
|
7
|
+
};
|
|
8
|
+
export default meta;
|
|
9
|
+
type Story = StoryObj<typeof meta>;
|
|
10
|
+
export declare const TableView: Story;
|
|
11
|
+
export declare const CardView: {
|
|
12
|
+
render: () => import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bsol-oss/react-datatable5",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"repository": "https://github.com/bsol-oss/react-datatable5.git",
|
|
@@ -13,6 +13,13 @@
|
|
|
13
13
|
"@chakra-ui/react",
|
|
14
14
|
"react-icons"
|
|
15
15
|
],
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./dist/types/index.d.ts",
|
|
19
|
+
"default": "./dist/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./package.json": "./package.json"
|
|
22
|
+
},
|
|
16
23
|
"scripts": {
|
|
17
24
|
"build": "rollup -c",
|
|
18
25
|
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
|
|
@@ -16,22 +16,37 @@ import {
|
|
|
16
16
|
Column,
|
|
17
17
|
} from "@tanstack/react-table";
|
|
18
18
|
import useDataFromUrl from "./useDataFromUrl";
|
|
19
|
-
import { Container, Table } from "@chakra-ui/react";
|
|
20
19
|
|
|
21
|
-
interface DataTableProps {
|
|
20
|
+
export interface DataTableProps<T> {
|
|
22
21
|
children: ReactNode;
|
|
23
22
|
url: string;
|
|
24
|
-
columns: Column[];
|
|
23
|
+
columns: Column<T>[];
|
|
25
24
|
}
|
|
26
25
|
|
|
27
|
-
|
|
26
|
+
export interface Result<T> {
|
|
27
|
+
results: T[];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface DataResponse<T> extends Result<T> {
|
|
31
|
+
success: boolean;
|
|
32
|
+
count: number;
|
|
33
|
+
filterCount: number;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const DataTable = <TData,>({
|
|
37
|
+
columns,
|
|
38
|
+
url,
|
|
39
|
+
children,
|
|
40
|
+
}: DataTableProps<TData>) => {
|
|
28
41
|
const [sorting, setSorting] = useState<SortingState>([]);
|
|
29
42
|
const [columnFilters, setColumnFilters] = useState<ColumnFiltersState>([]); // can set initial column filter state here
|
|
30
43
|
const [pagination, setPagination] = useState({
|
|
31
44
|
pageIndex: 0, //initial page index
|
|
32
45
|
pageSize: 10, //default page size
|
|
33
46
|
});
|
|
34
|
-
const { data, loading, hasError, refreshData } = useDataFromUrl
|
|
47
|
+
const { data, loading, hasError, refreshData } = useDataFromUrl<
|
|
48
|
+
DataResponse<TData>
|
|
49
|
+
>({
|
|
35
50
|
url: url,
|
|
36
51
|
defaultData: {
|
|
37
52
|
success: false,
|
|
@@ -47,18 +62,18 @@ const DataTable = ({ columns, url, children }: DataTableProps) => {
|
|
|
47
62
|
sorting: JSON.stringify(
|
|
48
63
|
sorting.length > 0
|
|
49
64
|
? { field: sorting[0].id, sort: sorting[0].desc ? "desc" : "asc" }
|
|
50
|
-
: {}
|
|
65
|
+
: {}
|
|
51
66
|
),
|
|
52
67
|
where: JSON.stringify(
|
|
53
68
|
columnFilters.reduce((accumulator, filter) => {
|
|
54
69
|
const obj: any = {};
|
|
55
70
|
obj[filter.id] = filter.value;
|
|
56
71
|
return { ...accumulator, ...obj };
|
|
57
|
-
}, {})
|
|
72
|
+
}, {})
|
|
58
73
|
),
|
|
59
74
|
},
|
|
60
75
|
});
|
|
61
|
-
const table = useReactTable({
|
|
76
|
+
const table = useReactTable<TData>({
|
|
62
77
|
data: data.results,
|
|
63
78
|
columns: columns,
|
|
64
79
|
getCoreRowModel: getCoreRowModel(),
|
|
@@ -2,12 +2,11 @@ import { Table } from "@tanstack/react-table";
|
|
|
2
2
|
import { createContext } from "react";
|
|
3
3
|
|
|
4
4
|
interface DataTableContext<T> {
|
|
5
|
-
// tableWidth: number;
|
|
6
|
-
// setTableWidth: (num: number) => void;
|
|
7
5
|
table: Table<T>;
|
|
6
|
+
refreshData: () => void;
|
|
8
7
|
}
|
|
9
8
|
|
|
10
9
|
export const TableContext = createContext<DataTableContext<any>>({
|
|
11
|
-
table:
|
|
10
|
+
table: {} as Table<any>,
|
|
12
11
|
refreshData: () => {},
|
|
13
12
|
});
|
package/src/components/Table.tsx
CHANGED
|
@@ -7,8 +7,9 @@ import {
|
|
|
7
7
|
} from "react-icons/md";
|
|
8
8
|
import { useDataTable } from "./useDataTable";
|
|
9
9
|
|
|
10
|
-
interface PaginationProps {}
|
|
11
|
-
|
|
10
|
+
export interface PaginationProps {}
|
|
11
|
+
|
|
12
|
+
const TablePagination = ({}: PaginationProps) => {
|
|
12
13
|
const {
|
|
13
14
|
firstPage,
|
|
14
15
|
getCanPreviousPage,
|
|
@@ -1,57 +1,30 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from "@storybook/react";
|
|
2
|
-
import
|
|
2
|
+
import TableViewShowcase from "./TableViewShowcase";
|
|
3
|
+
import CardViewShowcase from "./CardViewShowcase";
|
|
3
4
|
|
|
4
5
|
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export
|
|
5
6
|
const meta = {
|
|
6
|
-
title: "
|
|
7
|
-
component:
|
|
7
|
+
title: "DataTable/TableView",
|
|
8
|
+
component: TableViewShowcase,
|
|
8
9
|
parameters: {
|
|
9
|
-
// Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout
|
|
10
|
-
// layout: 'centered',
|
|
11
10
|
},
|
|
12
|
-
|
|
13
|
-
tags: ["autodocs"],
|
|
14
|
-
// More on argTypes: https://storybook.js.org/docs/api/argtypes
|
|
11
|
+
|
|
15
12
|
argTypes: {
|
|
16
|
-
// backgroundColor: { control: 'color' },
|
|
17
13
|
},
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
} satisfies Meta<typeof DefaultDataTable>;
|
|
14
|
+
|
|
15
|
+
} satisfies Meta<typeof TableViewShowcase>;
|
|
21
16
|
|
|
22
17
|
export default meta;
|
|
23
18
|
type Story = StoryObj<typeof meta>;
|
|
24
19
|
|
|
25
|
-
export const
|
|
20
|
+
export const TableView: Story = {
|
|
26
21
|
render: () => {
|
|
27
|
-
return <
|
|
22
|
+
return <TableViewShowcase />;
|
|
28
23
|
},
|
|
29
24
|
};
|
|
30
25
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
// },
|
|
37
|
-
// };
|
|
38
|
-
|
|
39
|
-
// export const Secondary: Story = {
|
|
40
|
-
// args: {
|
|
41
|
-
// label: 'Button',
|
|
42
|
-
// },
|
|
43
|
-
// };
|
|
44
|
-
|
|
45
|
-
// export const Large: Story = {
|
|
46
|
-
// args: {
|
|
47
|
-
// size: 'large',
|
|
48
|
-
// label: 'Button',
|
|
49
|
-
// },
|
|
50
|
-
// };
|
|
51
|
-
|
|
52
|
-
// export const Small: Story = {
|
|
53
|
-
// args: {
|
|
54
|
-
// size: 'small',
|
|
55
|
-
// label: 'Button',
|
|
56
|
-
// },
|
|
57
|
-
// };
|
|
26
|
+
export const CardView = {
|
|
27
|
+
render: () => {
|
|
28
|
+
return <CardViewShowcase />;
|
|
29
|
+
},
|
|
30
|
+
};
|
package/tsconfig.json
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
+
"declaration": true,
|
|
4
|
+
"outDir": "./dist/types",
|
|
3
5
|
"target": "ES2020",
|
|
4
6
|
"useDefineForClassFields": true,
|
|
5
7
|
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
|
6
8
|
"module": "ESNext",
|
|
7
9
|
"skipLibCheck": true,
|
|
8
|
-
|
|
10
|
+
|
|
9
11
|
/* Bundler mode */
|
|
10
12
|
"moduleResolution": "bundler",
|
|
11
13
|
"allowImportingTsExtensions": true,
|
|
@@ -13,7 +15,6 @@
|
|
|
13
15
|
"isolatedModules": true,
|
|
14
16
|
"noEmit": true,
|
|
15
17
|
"jsx": "react-jsx",
|
|
16
|
-
|
|
17
18
|
/* Linting */
|
|
18
19
|
"strict": true,
|
|
19
20
|
"noUnusedLocals": true,
|