@timadey/generic-table 1.0.0

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 (2) hide show
  1. package/README.md +116 -0
  2. package/package.json +53 -0
package/README.md ADDED
@@ -0,0 +1,116 @@
1
+ # GenericTable
2
+
3
+ A highly flexible and reusable React table component built with [HeroUI](https://heroui.com/) (formerly NextUI) and [React Stately](https://react-spectrum.adobe.com/react-stately/).
4
+
5
+ ## Features
6
+
7
+ - **Client-side Searching:** Instant filtering across all columns.
8
+ - **Client-side Sorting:** Sort data by any column (supports numbers, dates, and strings).
9
+ - **Pagination:** Built-in pagination with configurable rows per page.
10
+ - **Async Data Loading:** Fetch data from a URL or provide it via props.
11
+ - **Customizable:** Override cell rendering and table styling.
12
+ - **Date Awareness:** Smart sorting and searching for date-based columns.
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ npm install @timadey/generic-table
18
+ # or
19
+ yarn add @timadey/generic-table
20
+ ```
21
+
22
+ Make sure you have the peer dependencies installed:
23
+
24
+ ```bash
25
+ npm install @heroui/react @react-stately/data lucide-react react react-dom use-debounce
26
+ ```
27
+
28
+ ## Usage
29
+
30
+ ### Basic Example
31
+
32
+ ```jsx
33
+ import { GenericTable } from "@timadey/generic-table";
34
+
35
+ const columns = [
36
+ { name: "Name", uid: "name", sortable: true },
37
+ { name: "Role", uid: "role", sortable: true },
38
+ { name: "Status", uid: "status", sortable: true },
39
+ ];
40
+
41
+ const data = [
42
+ { id: 1, name: "Tony Reichert", role: "CEO", status: "Active" },
43
+ { id: 2, name: "Zoey Lang", role: "Technical Lead", status: "Paused" },
44
+ // ...
45
+ ];
46
+
47
+ export default function App() {
48
+ return (
49
+ <GenericTable
50
+ title="Users"
51
+ columns={columns}
52
+ data={data}
53
+ />
54
+ );
55
+ }
56
+ ```
57
+
58
+ ### With Async Fetching and Custom Cells
59
+
60
+ ```jsx
61
+ import { GenericTable } from "@timadey/generic-table";
62
+ import { Chip } from "@heroui/react";
63
+
64
+ const columns = [
65
+ { name: "Amount", uid: "amount", sortable: true },
66
+ { name: "Status", uid: "status", sortable: true },
67
+ { name: "Date", uid: "created_at", sortable: true },
68
+ ];
69
+
70
+ function renderCell(item, columnKey) {
71
+ const value = item[columnKey];
72
+
73
+ switch (columnKey) {
74
+ case "amount":
75
+ return `₦${Number(value).toLocaleString()}`;
76
+ case "status":
77
+ return (
78
+ <Chip color={value === "success" ? "success" : "warning"} variant="flat">
79
+ {value.toUpperCase()}
80
+ </Chip>
81
+ );
82
+ default:
83
+ return value;
84
+ }
85
+ }
86
+
87
+ export default function TransactionsTable() {
88
+ return (
89
+ <GenericTable
90
+ title="Transactions"
91
+ columns={columns}
92
+ fetchUrl="/api/transactions"
93
+ renderCell={renderCell}
94
+ rowsPerPageOptions={[10, 25, 50]}
95
+ topContentPlacement="outside"
96
+ />
97
+ );
98
+ }
99
+ ```
100
+
101
+ ## Props
102
+
103
+ | Prop | Type | Default | Description |
104
+ |:----------------------|:----------------|:---------------|:-------------------------------------------------------------------------------------|
105
+ | `columns` | `Array` | `[]` | Array of column objects `{ name, uid, sortable, getValue }` |
106
+ | `fetchUrl` | `string` | `null` | URL to fetch JSON data from |
107
+ | `data` | `Array` | `[]` | Static data to display if `fetchUrl` is not provided |
108
+ | `title` | `string` | `"Data Table"` | Title displayed above the table |
109
+ | `rowsPerPageOptions` | `Array<number>` | `[5, 10, 15]` | Options for the rows per page dropdown |
110
+ | `renderCell` | `Function` | `null` | Custom cell renderer: `(item, columnKey, index) => ReactNode` |
111
+ | `topContentPlacement` | `string` | `outside` | Where to place the contents at the top of the table: `inside` or `outside` the table |
112
+ | `...props` | `any` | | Any other props are passed directly to the HeroUI `Table` component |
113
+
114
+ ## License
115
+
116
+ MIT
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@timadey/generic-table",
3
+ "version": "1.0.0",
4
+ "description": "A highly flexible and reusable React table component built with HeroUI (formerly NextUI) and React Stately.",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "scripts": {
11
+ "dev": "vite",
12
+ "build": "vite build",
13
+ "preview": "vite preview"
14
+ },
15
+ "peerDependencies": {
16
+ "@heroui/react": "^2.4.0",
17
+ "@react-stately/data": "^3.11.0",
18
+ "lucide-react": "^0.300.0",
19
+ "react": "^18.0.0 || ^19.0.0",
20
+ "react-dom": "^18.0.0 || ^19.0.0",
21
+ "use-debounce": "^10.0.0"
22
+ },
23
+ "devDependencies": {
24
+ "@heroui/react": "^2.4.33",
25
+ "@react-stately/data": "^3.12.0",
26
+ "@types/react": "^18.3.0",
27
+ "@types/react-dom": "^18.3.0",
28
+ "@vitejs/plugin-react": "^4.2.0",
29
+ "lucide-react": "^0.477.0",
30
+ "react": "^18.3.1",
31
+ "react-dom": "^18.3.1",
32
+ "use-debounce": "^10.0.4",
33
+ "vite": "^5.0.0"
34
+ },
35
+ "keywords": [
36
+ "react",
37
+ "table",
38
+ "generic",
39
+ "heroui",
40
+ "nextui",
41
+ "reusable"
42
+ ],
43
+ "repository": {
44
+ "type": "git",
45
+ "url": "git+https://github.com/Timadey/generic-table.git"
46
+ },
47
+ "bugs": {
48
+ "url": "https://github.com/Timadey/generic-table/issues"
49
+ },
50
+ "homepage": "https://github.com/Timadey/generic-table#readme",
51
+ "author": "Timothy Adeleke",
52
+ "license": "MIT"
53
+ }