@eventuras/datatable 0.5.12
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/DataTable.d.ts +31 -0
- package/dist/DataTable.d.ts.map +1 -0
- package/dist/DataTable.js +98 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/package.json +43 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { RankingInfo } from '@tanstack/match-sorter-utils';
|
|
2
|
+
import { ColumnFilter, FilterFn, Row, TableState } from '@tanstack/react-table';
|
|
3
|
+
import { default as React } from 'react';
|
|
4
|
+
type DataTableProps = {
|
|
5
|
+
columns: any[];
|
|
6
|
+
data: any[];
|
|
7
|
+
pageSize?: number;
|
|
8
|
+
clientsidePagination?: boolean;
|
|
9
|
+
state?: Partial<TableState>;
|
|
10
|
+
enableGlobalSearch?: boolean;
|
|
11
|
+
columnFilters?: ColumnFilter[];
|
|
12
|
+
renderToolbar?: (searchInput: React.ReactNode) => React.ReactNode;
|
|
13
|
+
renderSubComponent?: (props: {
|
|
14
|
+
row: Row<any>;
|
|
15
|
+
}) => React.ReactElement;
|
|
16
|
+
getRowCanExpand?: (row: Row<any>) => boolean;
|
|
17
|
+
getRowId?: (originalRow: any, index: number) => string;
|
|
18
|
+
};
|
|
19
|
+
declare module '@tanstack/table-core' {
|
|
20
|
+
interface FilterFns {
|
|
21
|
+
fuzzy: FilterFn<unknown>;
|
|
22
|
+
}
|
|
23
|
+
interface FilterMeta {
|
|
24
|
+
itemRank: RankingInfo;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
declare const DataTable: (props: DataTableProps) => import("react/jsx-runtime").JSX.Element;
|
|
28
|
+
export default DataTable;
|
|
29
|
+
export type { ColumnFilter, ColumnSort, TableState } from '@tanstack/react-table';
|
|
30
|
+
export { createColumnHelper } from '@tanstack/react-table';
|
|
31
|
+
//# sourceMappingURL=DataTable.d.ts.map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,SAAS,CAAC;AACzB,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAClF,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { rankItem as e } from "@tanstack/match-sorter-utils";
|
|
3
|
+
import { Pagination as t } from "@eventuras/ratio-ui/core/Pagination";
|
|
4
|
+
import { createColumnHelper as n, flexRender as r, getCoreRowModel as i, getExpandedRowModel as a, getFilteredRowModel as o, getPaginationRowModel as s, useReactTable as c } from "@tanstack/react-table";
|
|
5
|
+
import l, { useEffect as u } from "react";
|
|
6
|
+
import { SearchField as d } from "@eventuras/ratio-ui/forms";
|
|
7
|
+
import { Fragment as f, jsx as p, jsxs as m } from "react/jsx-runtime";
|
|
8
|
+
//#region src/DataTable.tsx
|
|
9
|
+
var h = (t, n, r, i) => {
|
|
10
|
+
let a = e(t.getValue(n), r);
|
|
11
|
+
return i({ itemRank: a }), a.passed;
|
|
12
|
+
}, g = (e) => {
|
|
13
|
+
let { columns: n, data: g, clientsidePagination: _, pageSize: v = 25, state: y } = e, [b, x] = l.useState([]), [S, C] = l.useState(""), [w, T] = l.useState({}), E = (e) => {
|
|
14
|
+
O.setPageIndex(e);
|
|
15
|
+
};
|
|
16
|
+
u(() => {
|
|
17
|
+
e.columnFilters && x(e.columnFilters);
|
|
18
|
+
}, [e.columnFilters]), u(() => {
|
|
19
|
+
T(S ? !0 : {});
|
|
20
|
+
}, [S]);
|
|
21
|
+
let D = l.useCallback((e) => {
|
|
22
|
+
if (S) {
|
|
23
|
+
T(e);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
T((t) => {
|
|
27
|
+
let n = typeof e == "function" ? e(t) : e;
|
|
28
|
+
if (typeof n == "boolean") return n;
|
|
29
|
+
let r = Object.keys(t).filter((e) => t[e]), i = Object.keys(n).filter((e) => n[e]);
|
|
30
|
+
if (i.length > r.length) {
|
|
31
|
+
let e = i.find((e) => !r.includes(e));
|
|
32
|
+
if (e) return { [e]: !0 };
|
|
33
|
+
}
|
|
34
|
+
return n;
|
|
35
|
+
});
|
|
36
|
+
}, [S]), O = c({
|
|
37
|
+
columns: n,
|
|
38
|
+
data: g,
|
|
39
|
+
getRowId: e.getRowId,
|
|
40
|
+
getCoreRowModel: i(),
|
|
41
|
+
getPaginationRowModel: s(),
|
|
42
|
+
getExpandedRowModel: a(),
|
|
43
|
+
onGlobalFilterChange: C,
|
|
44
|
+
onColumnFiltersChange: x,
|
|
45
|
+
onExpandedChange: D,
|
|
46
|
+
getFilteredRowModel: o(),
|
|
47
|
+
getRowCanExpand: e.getRowCanExpand,
|
|
48
|
+
filterFns: { fuzzy: h },
|
|
49
|
+
globalFilterFn: h,
|
|
50
|
+
initialState: { pagination: { pageSize: v } },
|
|
51
|
+
state: {
|
|
52
|
+
...y,
|
|
53
|
+
globalFilter: S,
|
|
54
|
+
columnFilters: b,
|
|
55
|
+
expanded: w
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
u(() => {
|
|
59
|
+
_ && O.setPageSize(v);
|
|
60
|
+
}, []);
|
|
61
|
+
let k = e.enableGlobalSearch ? /* @__PURE__ */ p(d, {
|
|
62
|
+
value: S ?? "",
|
|
63
|
+
onChange: (e) => C(e),
|
|
64
|
+
placeholder: "Search all columns...",
|
|
65
|
+
"aria-label": "Search table"
|
|
66
|
+
}) : null;
|
|
67
|
+
return /* @__PURE__ */ m(f, { children: [
|
|
68
|
+
e.renderToolbar ? e.renderToolbar(k) : k,
|
|
69
|
+
/* @__PURE__ */ m("table", {
|
|
70
|
+
className: "table-auto w-full",
|
|
71
|
+
children: [/* @__PURE__ */ p("thead", { children: O.getHeaderGroups().map((e) => /* @__PURE__ */ p("tr", { children: e.headers.map((e) => /* @__PURE__ */ p("th", {
|
|
72
|
+
className: "text-left",
|
|
73
|
+
children: e.isPlaceholder ? null : r(e.column.columnDef.header, e.getContext())
|
|
74
|
+
}, e.id)) }, e.id)) }), /* @__PURE__ */ p("tbody", { children: O.getRowModel().rows.map((t) => /* @__PURE__ */ m(l.Fragment, { children: [/* @__PURE__ */ p("tr", {
|
|
75
|
+
className: "group even:bg-gray-50 odd:bg-white dark:even:bg-gray-950 dark:odd:bg-gray-900 text-black dark:text-white",
|
|
76
|
+
children: t.getVisibleCells().map((e) => /* @__PURE__ */ p("td", {
|
|
77
|
+
className: "p-2",
|
|
78
|
+
children: r(e.column.columnDef.cell, e.getContext())
|
|
79
|
+
}, e.id))
|
|
80
|
+
}), t.getIsExpanded() && e.renderSubComponent && /* @__PURE__ */ p("tr", {
|
|
81
|
+
className: "bg-gray-100 dark:bg-gray-800",
|
|
82
|
+
children: /* @__PURE__ */ p("td", {
|
|
83
|
+
colSpan: t.getVisibleCells().length,
|
|
84
|
+
className: "p-4",
|
|
85
|
+
children: e.renderSubComponent({ row: t })
|
|
86
|
+
})
|
|
87
|
+
})] }, t.id ?? t.index)) })]
|
|
88
|
+
}),
|
|
89
|
+
_ && O.getPageCount() > 1 ? /* @__PURE__ */ p(t, {
|
|
90
|
+
currentPage: O.getState().pagination.pageIndex + 1,
|
|
91
|
+
totalPages: O.getPageCount(),
|
|
92
|
+
onPreviousPageClick: () => E(O.getState().pagination.pageIndex - 1),
|
|
93
|
+
onNextPageClick: () => E(O.getState().pagination.pageIndex + 1)
|
|
94
|
+
}) : null
|
|
95
|
+
] });
|
|
96
|
+
};
|
|
97
|
+
//#endregion
|
|
98
|
+
export { n as createColumnHelper, g as default };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACvE,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@eventuras/datatable",
|
|
3
|
+
"version": "0.5.12",
|
|
4
|
+
"exports": {
|
|
5
|
+
".": {
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"import": "./dist/index.js"
|
|
8
|
+
}
|
|
9
|
+
},
|
|
10
|
+
"main": "./dist/index.js",
|
|
11
|
+
"module": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "vite build",
|
|
18
|
+
"dev": "vite build --watch"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@eventuras/ratio-ui": "workspace:*"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@eventuras/eslint-config": "workspace:*",
|
|
25
|
+
"@eventuras/typescript-config": "workspace:*",
|
|
26
|
+
"@eventuras/vite-config": "workspace:*",
|
|
27
|
+
"@tanstack/match-sorter-utils": "^8.19.4",
|
|
28
|
+
"@tanstack/react-table": "^8.21.3",
|
|
29
|
+
"@tanstack/table-core": "^8.21.3",
|
|
30
|
+
"@types/react": "^19.2.14",
|
|
31
|
+
"@types/react-dom": "^19.2.3",
|
|
32
|
+
"lucide-react": "^1.7.0",
|
|
33
|
+
"vite": "^8.0.3"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"@tanstack/match-sorter-utils": "^8.0.0",
|
|
37
|
+
"@tanstack/react-table": "^8.0.0",
|
|
38
|
+
"@tanstack/table-core": "^8.0.0",
|
|
39
|
+
"lucide-react": "^0.555.0 || ^0.577.0 || ^1.0.0",
|
|
40
|
+
"react": "^19.0.0",
|
|
41
|
+
"react-dom": "^19.0.0"
|
|
42
|
+
}
|
|
43
|
+
}
|