@neukoio/react-table 0.0.2 β†’ 0.0.3

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/README.md CHANGED
@@ -1,52 +1,100 @@
1
- # My React Table Package
2
1
 
3
- **`react-table-neuko-io`** is a lightweight, customizable, and reusable table component designed for React applications. Built with React and styled using Tailwind CSS, this package simplifies the creation of interactive and visually appealing tables.
2
+ # My React Table Package
3
+
4
+ **`react-table-neuko-io`** is a lightweight, customizable, and reusable table component designed for React applications. Built with React and styled using Tailwind CSS, this package simplifies the creation of interactive and visually appealing tables.
4
5
 
5
6
  ---
6
7
 
7
- ## Features
8
+ ## πŸš€ Features
8
9
 
9
- - πŸ“¦ **Reusable Components**: Comes with a `Table` and `Button` component out of the box.
10
- - 🎨 **Tailwind CSS Styling**: Fully styled and customizable using Tailwind CSS.
11
- - πŸ›  **Ease of Use**: Simple API for quick integration.
12
- - ⚑ **Responsive Design**: Adapts to all screen sizes seamlessly.
10
+ - πŸ“¦ **Reusable Components**: Includes `Table` and `Button` components out of the box.
11
+ - 🎨 **Tailwind CSS Styling**: Fully styled and customizable using Tailwind CSS.
12
+ - πŸ›  **Ease of Use**: Simple API for quick integration.
13
+ - ⚑ **Responsive Design**: Adapts seamlessly to all screen sizes.
13
14
 
14
15
  ---
15
16
 
16
- ## Installation
17
+ ## πŸ“₯ Installation
18
+
19
+ Install the package via npm:
17
20
 
18
- Install the package via npm:
21
+ ```bash
22
+ npm install react-table-neuko-io
23
+ ```
19
24
 
20
- ```bash
21
- npm install react-table-neuko-io
22
- ```
23
25
  ---
24
- ## File Structure
25
26
 
26
- Here’s the structure of the package:
27
+ ## πŸ›  Usage
28
+
29
+ Here's a basic example of how to use the `react-table-neuko-io` package:
30
+
31
+ ```jsx
32
+ import React from "react";
33
+ import { Table, Button } from "react-table-neuko-io";
27
34
 
28
- react-table-neuko-io/
29
- β”œβ”€β”€ src/
30
- β”‚ β”œβ”€β”€ index.js # Entry point for the components
31
- β”‚ β”œβ”€β”€ Table.js # Table component
32
- β”‚ β”œβ”€β”€ Button.js # Button component
33
- β”‚ β”œβ”€β”€ styles.css # Tailwind CSS styles
34
- β”‚ └── useWindowSize.js # Custom hook for handling responsive design
35
- β”œβ”€β”€ dist/ # Transpiled output
36
- β”œβ”€β”€ package.json # Package configuration
37
- β”œβ”€β”€ .babelrc # Babel configuration
38
- β”œβ”€β”€ tailwind.config.js # Tailwind configuration
39
- β”œβ”€β”€ postcss.config.js # PostCSS configuration
40
- └── README.md # Documentation
35
+ const App = () => {
36
+ const data = [
37
+ { name: "John Doe", email: "john@example.com", role: "Admin" },
38
+ { name: "Jane Smith", email: "jane@example.com", role: "User" },
39
+ ];
41
40
 
41
+ return (
42
+ <div className="container mx-auto">
43
+ <Table data={data} columns={["name", "email", "role"]} />
44
+ <Button onClick={() => alert("Button clicked!")}>Click Me</Button>
45
+ </div>
46
+ );
47
+ };
48
+
49
+ export default App;
50
+ ```
42
51
 
43
52
  ---
44
- ## Development
45
- If you'd like to contribute or make changes to the package, follow these steps:
46
53
 
47
- Clone the repository:
54
+ ## πŸ“‚ File Structure
55
+
56
+ Here’s the structure of the package:
57
+
58
+ ```plaintext
59
+ react-table-neuko-io/
60
+ β”œβ”€β”€ src/
61
+ β”‚ β”œβ”€β”€ index.js # Entry point for the components
62
+ β”‚ β”œβ”€β”€ Table.js # Table component
63
+ β”‚ β”œβ”€β”€ Button.js # Button component
64
+ β”‚ β”œβ”€β”€ styles.css # Tailwind CSS styles
65
+ β”‚ └── useWindowSize.js # Custom hook for handling responsive design
66
+ β”œβ”€β”€ dist/ # Transpiled output
67
+ β”œβ”€β”€ package.json # Package configuration
68
+ β”œβ”€β”€ .babelrc # Babel configuration
69
+ β”œβ”€β”€ tailwind.config.js # Tailwind configuration
70
+ β”œβ”€β”€ postcss.config.js # PostCSS configuration
71
+ └── README.md # Documentation
72
+ ```
48
73
 
49
74
  ---
50
- ## License
51
- This project is licensed under the MIT License. See the LICENSE file for more details.
52
75
 
76
+ ## πŸ§‘β€πŸ’» Development
77
+
78
+ If you'd like to contribute or make changes to the package, follow these steps:
79
+
80
+ 1. Clone the repository:
81
+ ```bash
82
+ git clone https://github.com/your-repo/react-table-neuko-io.git
83
+ ```
84
+
85
+ 2. Install dependencies:
86
+ ```bash
87
+ cd react-table-neuko-io
88
+ npm install
89
+ ```
90
+
91
+ 3. Run the development server:
92
+ ```bash
93
+ npm start
94
+ ```
95
+
96
+ ---
97
+
98
+ ## πŸ“œ License
99
+
100
+ This project is licensed under the **MIT License**. See the [LICENSE](./LICENSE) file for details.
package/dist/Table.js CHANGED
@@ -107,20 +107,26 @@ var Table = function Table(_ref) {
107
107
  }, /*#__PURE__*/_react["default"].createElement("tr", null, currentColumnDefs.map(function (col, index) {
108
108
  return /*#__PURE__*/_react["default"].createElement("th", {
109
109
  key: index,
110
- className: "".concat(col.style)
110
+ className: "".concat(col.style, " align-middle text-center whitespace-nowrap")
111
111
  }, col.name);
112
112
  }))), /*#__PURE__*/_react["default"].createElement("tbody", {
113
113
  className: "divide-y divide-gray-200 bg-white"
114
- }, currentData.map(function (row, rowIndex) {
114
+ }, currentData.length > 0 ? currentData.map(function (row, rowIndex) {
115
115
  return /*#__PURE__*/_react["default"].createElement("tr", {
116
116
  key: rowIndex
117
117
  }, currentColumnDefs.map(function (column, colIndex) {
118
118
  return /*#__PURE__*/_react["default"].createElement("td", {
119
119
  key: "cell-".concat(rowIndex, "-").concat(colIndex),
120
- className: "px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900"
120
+ className: "px-6 py-4 align-middle whitespace-nowrap text-sm font-medium text-gray-900"
121
121
  }, column.row ? column.row(row) : row[column.accessorKey]);
122
122
  }));
123
- }))))))), /*#__PURE__*/_react["default"].createElement("div", {
123
+ }) :
124
+ /*#__PURE__*/
125
+ // Render this row if there's no data
126
+ _react["default"].createElement("tr", null, /*#__PURE__*/_react["default"].createElement("td", {
127
+ colSpan: currentColumnDefs.length,
128
+ className: "px-6 py-4 text-center text-sm text-gray-500"
129
+ }, "No data available.")))))))), data.length > 0 && /*#__PURE__*/_react["default"].createElement("div", {
124
130
  className: "flex items-center justify-between border-t border-gray-200 bg-white px-4 py-3 sm:px-6"
125
131
  }, /*#__PURE__*/_react["default"].createElement("div", {
126
132
  className: "hidden sm:flex sm:flex-1 sm:items-center sm:justify-between"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neukoio/react-table",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "main": "dist/index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",
package/src/Table.js CHANGED
@@ -58,25 +58,37 @@ const Table = ({ data, columnDefs, isMoreData = false, onLoadMore = () => {} })
58
58
  <thead className="bg-gray-50">
59
59
  <tr>
60
60
  {currentColumnDefs.map((col, index) => (
61
- <th key={index} className={`${col.style}`}>
61
+ <th key={index} className={`${col.style} align-middle text-center whitespace-nowrap`}>
62
62
  {col.name}
63
63
  </th>
64
64
  ))}
65
65
  </tr>
66
66
  </thead>
67
67
  <tbody className="divide-y divide-gray-200 bg-white">
68
- {currentData.map((row, rowIndex) => (
69
- <tr key={rowIndex}>
70
- {currentColumnDefs.map((column, colIndex) => (
71
- <td
72
- key={`cell-${rowIndex}-${colIndex}`}
73
- className="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900"
74
- >
75
- {column.row ? column.row(row) : row[column.accessorKey]}
76
- </td>
77
- ))}
68
+ {currentData.length > 0 ? (
69
+ currentData.map((row, rowIndex) => (
70
+ <tr key={rowIndex}>
71
+ {currentColumnDefs.map((column, colIndex) => (
72
+ <td
73
+ key={`cell-${rowIndex}-${colIndex}`}
74
+ className="px-6 py-4 align-middle whitespace-nowrap text-sm font-medium text-gray-900"
75
+ >
76
+ {column.row ? column.row(row) : row[column.accessorKey]}
77
+ </td>
78
+ ))}
79
+ </tr>
80
+ ))
81
+ ) : (
82
+ // Render this row if there's no data
83
+ <tr>
84
+ <td
85
+ colSpan={currentColumnDefs.length}
86
+ className="px-6 py-4 text-center text-sm text-gray-500"
87
+ >
88
+ No data available.
89
+ </td>
78
90
  </tr>
79
- ))}
91
+ )}
80
92
  </tbody>
81
93
  </table>
82
94
  </div>
@@ -85,64 +97,69 @@ const Table = ({ data, columnDefs, isMoreData = false, onLoadMore = () => {} })
85
97
  </div>
86
98
 
87
99
  {/* Pagination Section */}
88
- <div className="flex items-center justify-between border-t border-gray-200 bg-white px-4 py-3 sm:px-6">
89
- <div className="hidden sm:flex sm:flex-1 sm:items-center sm:justify-between">
90
- <div className="flex items-center">
91
- <label htmlFor="results-per-page" className="mr-3 text-sm text-gray-700">
92
- Results per page:
93
- </label>
94
- <select
95
- id="results-per-page"
96
- name="results-per-page"
97
- value={itemsPerPage}
98
- onChange={(e) => handleResultsPerPageChange(Number(e.target.value))}
99
- className="block w-24 rounded-md border-gray-300 bg-white py-2 pl-3 pr-10 text-gray-900 focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm"
100
- >
101
- <option value="10">10</option>
102
- <option value="20">20</option>
103
- <option value="50">50</option>
104
- <option value="100">100</option>
105
- </select>
106
- </div>
107
-
108
- <nav aria-label="Pagination" className="isolate inline-flex -space-x-px rounded-md shadow-sm">
109
- <button
110
- onClick={handlePreviousPage}
111
- className={`relative inline-flex items-center rounded-l-md px-3 py-2 text-sm font-medium ${currentPage === 1
112
- ? 'text-gray-300 bg-gray-50 cursor-not-allowed'
113
- : 'text-gray-700 bg-white hover:bg-gray-100'
114
- }`}
115
- disabled={currentPage === 1}
116
- >
117
- <ChevronLeftIcon aria-hidden="true" className="w-5 h-5" />
118
- </button>
100
+ {data.length > 0 && (
101
+ <div className="flex items-center justify-between border-t border-gray-200 bg-white px-4 py-3 sm:px-6">
102
+ <div className="hidden sm:flex sm:flex-1 sm:items-center sm:justify-between">
103
+ <div className="flex items-center">
104
+ <label htmlFor="results-per-page" className="mr-3 text-sm text-gray-700">
105
+ Results per page:
106
+ </label>
107
+ <select
108
+ id="results-per-page"
109
+ name="results-per-page"
110
+ value={itemsPerPage}
111
+ onChange={(e) => handleResultsPerPageChange(Number(e.target.value))}
112
+ className="block w-24 rounded-md border-gray-300 bg-white py-2 pl-3 pr-10 text-gray-900 focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm"
113
+ >
114
+ <option value="10">10</option>
115
+ <option value="20">20</option>
116
+ <option value="50">50</option>
117
+ <option value="100">100</option>
118
+ </select>
119
+ </div>
119
120
 
120
- {[...Array(totalPages)].map((_, index) => (
121
+ <nav aria-label="Pagination" className="isolate inline-flex -space-x-px rounded-md shadow-sm">
121
122
  <button
122
- key={index}
123
- onClick={() => setCurrentPage(index + 1)}
124
- className={`relative inline-flex items-center px-4 py-2 text-sm font-medium ${currentPage === index + 1
125
- ? 'bg-indigo-600 text-white'
126
- : 'text-gray-700 bg-white hover:bg-gray-100'
127
- }`}
123
+ onClick={handlePreviousPage}
124
+ className={`relative inline-flex items-center rounded-l-md px-3 py-2 text-sm font-medium ${
125
+ currentPage === 1
126
+ ? 'text-gray-300 bg-gray-50 cursor-not-allowed'
127
+ : 'text-gray-700 bg-white hover:bg-gray-100'
128
+ }`}
129
+ disabled={currentPage === 1}
128
130
  >
129
- {index + 1}
131
+ <ChevronLeftIcon aria-hidden="true" className="w-5 h-5" />
130
132
  </button>
131
- ))}
132
133
 
133
- <button
134
- onClick={handleNextPage}
135
- className={`relative inline-flex items-center rounded-r-md px-3 py-2 text-sm font-medium ${currentPage === totalPages && !isMoreData
136
- ? 'text-gray-300 bg-gray-50 cursor-not-allowed'
137
- : 'text-gray-700 bg-white hover:bg-gray-100'
134
+ {[...Array(totalPages)].map((_, index) => (
135
+ <button
136
+ key={index}
137
+ onClick={() => setCurrentPage(index + 1)}
138
+ className={`relative inline-flex items-center px-4 py-2 text-sm font-medium ${
139
+ currentPage === index + 1
140
+ ? 'bg-indigo-600 text-white'
141
+ : 'text-gray-700 bg-white hover:bg-gray-100'
142
+ }`}
143
+ >
144
+ {index + 1}
145
+ </button>
146
+ ))}
147
+
148
+ <button
149
+ onClick={handleNextPage}
150
+ className={`relative inline-flex items-center rounded-r-md px-3 py-2 text-sm font-medium ${
151
+ currentPage === totalPages && !isMoreData
152
+ ? 'text-gray-300 bg-gray-50 cursor-not-allowed'
153
+ : 'text-gray-700 bg-white hover:bg-gray-100'
138
154
  }`}
139
- disabled={currentPage === totalPages && !isMoreData}
140
- >
141
- <ChevronRightIcon aria-hidden="true" className="w-5 h-5" />
142
- </button>
143
- </nav>
155
+ disabled={currentPage === totalPages && !isMoreData}
156
+ >
157
+ <ChevronRightIcon aria-hidden="true" className="w-5 h-5" />
158
+ </button>
159
+ </nav>
160
+ </div>
144
161
  </div>
145
- </div>
162
+ )}
146
163
  </div>
147
164
  );
148
165
  };