react-hrnet-table-gandrica 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.
package/README.md ADDED
@@ -0,0 +1,112 @@
1
+ # React HRNet DataTable
2
+
3
+ A modern, lightweight, and dependency-free (except React & Redux) data table component.
4
+ Built as a purely functional React replacement for the legacy jQuery DataTables plugin.
5
+ This plugin features its own isolated Redux state management to avoid conflicts with the host application.
6
+
7
+ ## 🌟 Features
8
+
9
+ - **Modular Architecture**: Built with isolated functional components (`TableSearch`, `TablePagination`, `TableCore`).
10
+ - **Internal State Management**: Uses Redux Toolkit internally, wrapped in its own Provider.
11
+ - **Smart Sorting & Filtering**: Instantly search across all data or sort by specific column headers.
12
+ - **Pagination**: Automatically paginates data (10 rows per page).
13
+
14
+ ## 📋 Prerequisites
15
+
16
+ To use this plugin, your project must have the following installed:
17
+
18
+ - **Node.js**: v16.0.0 or higher
19
+ - **React & ReactDOM**: v18.0.0 or higher
20
+ - **Redux Toolkit & React-Redux**: Required as peer dependencies.
21
+
22
+ ## 🛠️ Installation
23
+
24
+ Run the following command in your terminal to install the package via NPM:
25
+
26
+ ```bash
27
+ npm install react-hrnet-table-gandrica
28
+ ```
29
+
30
+ 💻 Usage & ImplementationHere is how to import and use the DataTable in your React application (like HRNet).
31
+
32
+ 1. Import the Component and its CSS:JavaScript
33
+ 2. import { Table } from 'react-hrnet-table-gandrica';
34
+ 3. import 'react-hrnet-table-gandrica/style.css'; // Don't forget the styles!
35
+ 4. Pass the list and tableHeaders props:JavaScript
36
+ 5. import React from 'react';
37
+ import { Table } from 'react-hrnet-table-[votre-pseudo]';
38
+ import 'react-hrnet-table-[votre-pseudo]/style.css';
39
+
40
+ export default function EmployeeList() {
41
+ // 1. The data array
42
+ const employeeList = [
43
+ {
44
+ firstName: "John",
45
+ lastName: "Doe",
46
+ startDate: "2022-01-01",
47
+ department: "Sales",
48
+ birthDate: "1990-01-01",
49
+ street: "123 Main St",
50
+ city: "New York",
51
+ state: "NY",
52
+ zipCode: "10001",
53
+ },
54
+ {
55
+ firstName: "Jane",
56
+ lastName: "Smith",
57
+ startDate: "2022-01-01",
58
+ department: "Marketing",
59
+ birthDate: "1995-01-01",
60
+ street: "456 Oak Ave",
61
+ city: "Los Angeles",
62
+ state: "CA",
63
+ zipCode: "90210",
64
+ },
65
+ {
66
+ firstName: "Michael",
67
+ lastName: "Johnson",
68
+ startDate: "2022-01-01",
69
+ department: "Engineering",
70
+ birthDate: "1985-01-01",
71
+ street: "789 Elm St",
72
+ city: "Chicago",
73
+ state: "IL",
74
+ zipCode: "60601",
75
+ },
76
+ ];
77
+
78
+ // 2. The columns configuration (label = Header, accessor = data key)
79
+ const columns = [
80
+ { firstName: "First Name" },
81
+ { lastName: "Last Name" },
82
+ { startDate: "Start Date" },
83
+ { department: "Department" },
84
+ { birthDate: "Date of Birth" },
85
+ { street: "Street" },
86
+ { city: "City" },
87
+ { state: "State" },
88
+ { zipCode: "Zip Code" },
89
+ ];
90
+
91
+ return (
92
+
93
+ <div className="table-wrapper">
94
+ <h2>Current Employees</h2>
95
+ <Table tableHeaders="{columns}" list="{employeeList}"/>
96
+ </div>
97
+ );
98
+ }
99
+
100
+ 🎛️ Props Reference
101
+ Prop Name : tableHeaders
102
+ Type : Array
103
+ Required : Yes
104
+ Description : Array of objects representing the data
105
+
106
+ Prop Name : list
107
+ Type : Array
108
+ Required : Yes
109
+ Description : Array of objects to display in the tableHeaders
110
+
111
+ 👨‍💻 Author
112
+ Created by Gabriel ANDRICA for the OpenClassrooms Front-End Developer Path.
@@ -0,0 +1,2 @@
1
+ ._entriesControl_h5mt7_2{color:#000;font-family:Times New Roman,Times,serif;font-size:16px}._entriesControl_h5mt7_2 select{font-family:inherit;font-size:inherit;cursor:pointer;background-color:#fff;border:2px solid #000;border-radius:4px;margin:0 4px;padding:1px 4px}._cellHeader_mvi5q_1{cursor:pointer;-webkit-user-select:none;user-select:none}._cellHeader_mvi5q_1 ._sortIcon_mvi5q_5{vertical-align:middle;flex-direction:column;align-items:center;gap:1px;margin-left:8px;font-size:.75em;line-height:.7;display:inline-flex}._cellHeader_mvi5q_1 ._sortIcon_mvi5q_5 ._sortArrows_mvi5q_15{vertical-align:middle;color:#d1d5db;flex-direction:column;flex:0;align-items:center;margin-left:5px;font-size:.9em;line-height:.7;transition:opacity .2s ease-in-out;display:inline-flex}._table_gudt1_1{border-collapse:collapse;width:100%;font-size:16px}._table_gudt1_1 th,._table_gudt1_1 td{text-align:left;border-bottom:1px solid #e0e0e0;height:35px;padding:4px 8px}._table_gudt1_1 th{white-space:nowrap;cursor:pointer;border-bottom:1px solid #030303;font-weight:700}._table_gudt1_1 tbody tr:nth-child(odd){background-color:#f9f9f9}._table_gudt1_1 tbody tr:nth-child(odd) td:first-of-type{background-color:#f0f0f0bf}._table_gudt1_1 tbody tr:nth-child(2n){background-color:#fff}._table_gudt1_1 tbody tr:nth-child(2n) td:first-of-type{background-color:#f9f9f9bf}._table_gudt1_1 tbody tr:hover td:first-of-type{background-color:#e1e1e1bf}._table_gudt1_1 tbody tr:hover td{background-color:#f9f9f9}._pagination_1kyfl_1{display:flex}._pagination_1kyfl_1 button{color:#666;background-color:#fff;border:none;padding:8px 16px}._pagination_1kyfl_1 span{background:linear-gradient(#fff 0%,#dcdcdc 100%);background-position-x:initial;background-position-y:initial;background-size:initial;background-repeat:initial;background-attachment:initial;background-origin:initial;background-clip:initial;background-color:initial;border:1px solid #9a9a9a;border-radius:2px;justify-content:center;align-items:center;padding:8px 16px;display:flex}._tableHeader_jg9ws_1,._tableFooter_jg9ws_2{justify-content:space-between;display:flex}._tableHeader_jg9ws_1{padding:.75rem 0}._tableFooter_jg9ws_2{border-top:1px solid #030303;height:40px;padding:.25rem 0}
2
+ /*$vite$:1*/
@@ -0,0 +1,421 @@
1
+ import { Provider as e, useDispatch as t, useSelector as n } from "react-redux";
2
+ import { configureStore as r, createSlice as i } from "@reduxjs/toolkit";
3
+ import { useState as a } from "react";
4
+ //#region \0rolldown/runtime.js
5
+ var o = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t.exports), s = /* @__PURE__ */ ((e) => typeof require < "u" ? require : typeof Proxy < "u" ? new Proxy(e, { get: (e, t) => (typeof require < "u" ? require : e)[t] }) : e)(function(e) {
6
+ if (typeof require < "u") return require.apply(this, arguments);
7
+ throw Error("Calling `require` for \"" + e + "\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.");
8
+ }), c = (e, t) => t ? e.filter((e) => Object.values(e).map((e) => e.toString().toLowerCase()).some((e) => e.includes(t.toLowerCase()))) : e, l = (e, t) => t?.key ? [...e].sort((e, n) => {
9
+ let r = e[t.key], i = n[t.key];
10
+ return r < i ? t.direction === "asc" ? -1 : 1 : r > i ? t.direction === "asc" ? 1 : -1 : 0;
11
+ }) : e, u = (e, t, n) => {
12
+ if (!Array.isArray(e)) return [];
13
+ let r = Math.max(0, (t - 1) * n), i = Math.min(r + n, e.length), a = e.slice(r, i);
14
+ return console.log(r, i), {
15
+ slice: a,
16
+ startIndex: r,
17
+ endIndex: i
18
+ };
19
+ }, d = i({
20
+ name: "table",
21
+ initialState: {
22
+ searchResult: "",
23
+ currentPage: 1,
24
+ entriesPerPage: 10,
25
+ sortConfig: {
26
+ key: null,
27
+ direction: "asc"
28
+ }
29
+ },
30
+ reducers: {
31
+ setList: (e, t) => {
32
+ e.initialList = t.payload.list, e.tableHeaders = t.payload.tableHeaders, e.currentList = e.initialList, e.listSliced = u(e.currentList, e.currentPage, e.entriesPerPage), e.listToDisplay = e.listSliced.slice;
33
+ },
34
+ setSearchResult: (e, t) => {
35
+ e.searchResult = t.payload, e.currentPage = 1, e.currentList = c(e.initialList, t.payload), e.listSliced = u(e.currentList, e.currentPage, e.entriesPerPage), e.listToDisplay = e.listSliced.slice;
36
+ },
37
+ setCurrentPage: (e, t) => {
38
+ e.currentPage = t.payload, e.listSliced = u(e.currentList, e.currentPage, e.entriesPerPage), e.listToDisplay = e.listSliced.slice;
39
+ },
40
+ setEntriesPerPage: (e, t) => {
41
+ e.searchResult = "", e.currentPage = 1, e.entriesPerPage = t.payload, e.listSliced = u(e.currentList, e.currentPage, e.entriesPerPage), e.listToDisplay = e.listSliced.slice;
42
+ },
43
+ setSortConfig: (e, t) => {
44
+ e.sortConfig = t.payload, e.listToDisplay = l(e.listToDisplay, t.payload);
45
+ }
46
+ }
47
+ }), { setList: f, setSearchResult: p, setCurrentPage: m, setEntriesPerPage: h, setSortConfig: g } = d.actions, _ = d.reducer, v = r({ reducer: { table: _ } });
48
+ v.subscribe(() => {
49
+ console.log("State updated:", v.getState());
50
+ });
51
+ var y = { entriesControl: "_entriesControl_h5mt7_2" }, b = /* @__PURE__ */ o(((e) => {
52
+ var t = Symbol.for("react.transitional.element"), n = Symbol.for("react.fragment");
53
+ function r(e, n, r) {
54
+ var i = null;
55
+ if (r !== void 0 && (i = "" + r), n.key !== void 0 && (i = "" + n.key), "key" in n) for (var a in r = {}, n) a !== "key" && (r[a] = n[a]);
56
+ else r = n;
57
+ return n = r.ref, {
58
+ $$typeof: t,
59
+ type: e,
60
+ key: i,
61
+ ref: n === void 0 ? null : n,
62
+ props: r
63
+ };
64
+ }
65
+ e.Fragment = n, e.jsx = r, e.jsxs = r;
66
+ })), x = /* @__PURE__ */ o(((e) => {
67
+ process.env.NODE_ENV !== "production" && (function() {
68
+ function t(e) {
69
+ if (e == null) return null;
70
+ if (typeof e == "function") return e.$$typeof === k ? null : e.displayName || e.name || null;
71
+ if (typeof e == "string") return e;
72
+ switch (e) {
73
+ case v: return "Fragment";
74
+ case b: return "Profiler";
75
+ case y: return "StrictMode";
76
+ case w: return "Suspense";
77
+ case T: return "SuspenseList";
78
+ case O: return "Activity";
79
+ }
80
+ if (typeof e == "object") switch (typeof e.tag == "number" && console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), e.$$typeof) {
81
+ case _: return "Portal";
82
+ case S: return e.displayName || "Context";
83
+ case x: return (e._context.displayName || "Context") + ".Consumer";
84
+ case C:
85
+ var n = e.render;
86
+ return e = e.displayName, e ||= (e = n.displayName || n.name || "", e === "" ? "ForwardRef" : "ForwardRef(" + e + ")"), e;
87
+ case E: return n = e.displayName || null, n === null ? t(e.type) || "Memo" : n;
88
+ case D:
89
+ n = e._payload, e = e._init;
90
+ try {
91
+ return t(e(n));
92
+ } catch {}
93
+ }
94
+ return null;
95
+ }
96
+ function n(e) {
97
+ return "" + e;
98
+ }
99
+ function r(e) {
100
+ try {
101
+ n(e);
102
+ var t = !1;
103
+ } catch {
104
+ t = !0;
105
+ }
106
+ if (t) {
107
+ t = console;
108
+ var r = t.error, i = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
109
+ return r.call(t, "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.", i), n(e);
110
+ }
111
+ }
112
+ function i(e) {
113
+ if (e === v) return "<>";
114
+ if (typeof e == "object" && e && e.$$typeof === D) return "<...>";
115
+ try {
116
+ var n = t(e);
117
+ return n ? "<" + n + ">" : "<...>";
118
+ } catch {
119
+ return "<...>";
120
+ }
121
+ }
122
+ function a() {
123
+ var e = A.A;
124
+ return e === null ? null : e.getOwner();
125
+ }
126
+ function o() {
127
+ return Error("react-stack-top-frame");
128
+ }
129
+ function c(e) {
130
+ if (j.call(e, "key")) {
131
+ var t = Object.getOwnPropertyDescriptor(e, "key").get;
132
+ if (t && t.isReactWarning) return !1;
133
+ }
134
+ return e.key !== void 0;
135
+ }
136
+ function l(e, t) {
137
+ function n() {
138
+ P || (P = !0, console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)", t));
139
+ }
140
+ n.isReactWarning = !0, Object.defineProperty(e, "key", {
141
+ get: n,
142
+ configurable: !0
143
+ });
144
+ }
145
+ function u() {
146
+ var e = t(this.type);
147
+ return F[e] || (F[e] = !0, console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")), e = this.props.ref, e === void 0 ? null : e;
148
+ }
149
+ function d(e, t, n, r, i, a) {
150
+ var o = n.ref;
151
+ return e = {
152
+ $$typeof: g,
153
+ type: e,
154
+ key: t,
155
+ props: n,
156
+ _owner: r
157
+ }, (o === void 0 ? null : o) === null ? Object.defineProperty(e, "ref", {
158
+ enumerable: !1,
159
+ value: null
160
+ }) : Object.defineProperty(e, "ref", {
161
+ enumerable: !1,
162
+ get: u
163
+ }), e._store = {}, Object.defineProperty(e._store, "validated", {
164
+ configurable: !1,
165
+ enumerable: !1,
166
+ writable: !0,
167
+ value: 0
168
+ }), Object.defineProperty(e, "_debugInfo", {
169
+ configurable: !1,
170
+ enumerable: !1,
171
+ writable: !0,
172
+ value: null
173
+ }), Object.defineProperty(e, "_debugStack", {
174
+ configurable: !1,
175
+ enumerable: !1,
176
+ writable: !0,
177
+ value: i
178
+ }), Object.defineProperty(e, "_debugTask", {
179
+ configurable: !1,
180
+ enumerable: !1,
181
+ writable: !0,
182
+ value: a
183
+ }), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
184
+ }
185
+ function f(e, n, i, o, s, u) {
186
+ var f = n.children;
187
+ if (f !== void 0) {
188
+ if (o) {
189
+ if (M(f)) {
190
+ for (o = 0; o < f.length; o++) p(f[o]);
191
+ Object.freeze && Object.freeze(f);
192
+ } else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");
193
+ } else p(f);
194
+ }
195
+ if (j.call(n, "key")) {
196
+ f = t(e);
197
+ var m = Object.keys(n).filter(function(e) {
198
+ return e !== "key";
199
+ });
200
+ o = 0 < m.length ? "{key: someKey, " + m.join(": ..., ") + ": ...}" : "{key: someKey}", R[f + o] || (m = 0 < m.length ? "{" + m.join(": ..., ") + ": ...}" : "{}", console.error("A props object containing a \"key\" prop is being spread into JSX:\n let props = %s;\n <%s {...props} />\nReact keys must be passed directly to JSX without using spread:\n let props = %s;\n <%s key={someKey} {...props} />", o, f, m, f), R[f + o] = !0);
201
+ }
202
+ if (f = null, i !== void 0 && (r(i), f = "" + i), c(n) && (r(n.key), f = "" + n.key), "key" in n) for (var h in i = {}, n) h !== "key" && (i[h] = n[h]);
203
+ else i = n;
204
+ return f && l(i, typeof e == "function" ? e.displayName || e.name || "Unknown" : e), d(e, f, i, a(), s, u);
205
+ }
206
+ function p(e) {
207
+ m(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e && e.$$typeof === D && (e._payload.status === "fulfilled" ? m(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
208
+ }
209
+ function m(e) {
210
+ return typeof e == "object" && !!e && e.$$typeof === g;
211
+ }
212
+ var h = s("react"), g = Symbol.for("react.transitional.element"), _ = Symbol.for("react.portal"), v = Symbol.for("react.fragment"), y = Symbol.for("react.strict_mode"), b = Symbol.for("react.profiler"), x = Symbol.for("react.consumer"), S = Symbol.for("react.context"), C = Symbol.for("react.forward_ref"), w = Symbol.for("react.suspense"), T = Symbol.for("react.suspense_list"), E = Symbol.for("react.memo"), D = Symbol.for("react.lazy"), O = Symbol.for("react.activity"), k = Symbol.for("react.client.reference"), A = h.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, j = Object.prototype.hasOwnProperty, M = Array.isArray, N = console.createTask ? console.createTask : function() {
213
+ return null;
214
+ };
215
+ h = { react_stack_bottom_frame: function(e) {
216
+ return e();
217
+ } };
218
+ var P, F = {}, I = h.react_stack_bottom_frame.bind(h, o)(), L = N(i(o)), R = {};
219
+ e.Fragment = v, e.jsx = function(e, t, n) {
220
+ var r = 1e4 > A.recentlyCreatedOwnerStacks++;
221
+ return f(e, t, n, !1, r ? Error("react-stack-top-frame") : I, r ? N(i(e)) : L);
222
+ }, e.jsxs = function(e, t, n) {
223
+ var r = 1e4 > A.recentlyCreatedOwnerStacks++;
224
+ return f(e, t, n, !0, r ? Error("react-stack-top-frame") : I, r ? N(i(e)) : L);
225
+ };
226
+ })();
227
+ })), S = (/* @__PURE__ */ o(((e, t) => {
228
+ t.exports = process.env.NODE_ENV === "production" ? b() : x();
229
+ })))();
230
+ function C() {
231
+ let e = t(), r = n((e) => e.table.entriesPerPage) || 10;
232
+ return /* @__PURE__ */ (0, S.jsx)("div", {
233
+ className: y.entriesControl,
234
+ children: /* @__PURE__ */ (0, S.jsxs)("label", { children: [
235
+ "Show",
236
+ /* @__PURE__ */ (0, S.jsxs)("select", {
237
+ name: "table-entries",
238
+ id: "table-entries",
239
+ value: r,
240
+ onChange: (t) => {
241
+ e(h(Number(t.target.value)));
242
+ },
243
+ children: [
244
+ /* @__PURE__ */ (0, S.jsx)("option", {
245
+ value: "10",
246
+ children: "10"
247
+ }),
248
+ /* @__PURE__ */ (0, S.jsx)("option", {
249
+ value: "25",
250
+ children: "25"
251
+ }),
252
+ /* @__PURE__ */ (0, S.jsx)("option", {
253
+ value: "50",
254
+ children: "50"
255
+ }),
256
+ /* @__PURE__ */ (0, S.jsx)("option", {
257
+ value: "100",
258
+ children: "100"
259
+ })
260
+ ]
261
+ }),
262
+ "entries"
263
+ ] })
264
+ });
265
+ }
266
+ //#endregion
267
+ //#region src/components/searchBar/SearchBar.jsx
268
+ function w() {
269
+ let [e, n] = a(""), r = t();
270
+ return /* @__PURE__ */ (0, S.jsxs)("label", { children: [
271
+ "Search:",
272
+ " ",
273
+ /* @__PURE__ */ (0, S.jsx)("input", {
274
+ type: "search",
275
+ value: e,
276
+ onChange: (e) => {
277
+ n(e.target.value), r(p(e.target.value));
278
+ },
279
+ "aria-controls": "employee-table"
280
+ })
281
+ ] });
282
+ }
283
+ var T = {
284
+ cellHeader: "_cellHeader_mvi5q_1",
285
+ sortIcon: "_sortIcon_mvi5q_5",
286
+ sortArrows: "_sortArrows_mvi5q_15"
287
+ };
288
+ //#endregion
289
+ //#region src/components/tableCellHeader/TableCellHeader.jsx
290
+ function E({ header: e }) {
291
+ let r = t(), i = n((e) => e.table.sortConfig), a = Object.keys(e)[0], o = e[a], s = () => {
292
+ let e = "asc";
293
+ i?.key === a && (e = i.direction === "asc" ? "desc" : "asc"), r(g({
294
+ key: a,
295
+ direction: e
296
+ }));
297
+ }, c = i?.key === a, l = c && i.direction === "asc", u = c && i.direction === "desc";
298
+ return /* @__PURE__ */ (0, S.jsxs)("th", {
299
+ className: T.cellHeader,
300
+ onClick: s,
301
+ children: [/* @__PURE__ */ (0, S.jsx)("span", { children: o }), /* @__PURE__ */ (0, S.jsxs)("span", {
302
+ className: T.sortIcon,
303
+ children: [/* @__PURE__ */ (0, S.jsx)("span", {
304
+ className: T.sortArrows,
305
+ style: {
306
+ opacity: l ? 1 : .3,
307
+ color: "#6366f1"
308
+ },
309
+ children: "▲"
310
+ }), /* @__PURE__ */ (0, S.jsx)("span", {
311
+ className: T.sortArrows,
312
+ style: {
313
+ opacity: u ? 1 : .3,
314
+ color: "#6366f1"
315
+ },
316
+ children: "▼"
317
+ })]
318
+ })]
319
+ });
320
+ }
321
+ //#endregion
322
+ //#region src/components/tableListHeader/TableListHeader.jsx
323
+ function D() {
324
+ let e = n((e) => e.table.tableHeaders);
325
+ return /* @__PURE__ */ (0, S.jsx)("thead", { children: /* @__PURE__ */ (0, S.jsx)("tr", { children: e.map((e, t) => /* @__PURE__ */ (0, S.jsx)(E, { header: e }, t)) }) });
326
+ }
327
+ //#endregion
328
+ //#region src/components/tableListBody/TableListBody.jsx
329
+ function O() {
330
+ let e = n((e) => e.table.listToDisplay);
331
+ return /* @__PURE__ */ (0, S.jsx)("tbody", { children: e.map((e, t) => /* @__PURE__ */ (0, S.jsxs)("tr", { children: [
332
+ /* @__PURE__ */ (0, S.jsx)("td", { children: e.firstName }),
333
+ /* @__PURE__ */ (0, S.jsx)("td", { children: e.lastName }),
334
+ /* @__PURE__ */ (0, S.jsx)("td", { children: e.startDate }),
335
+ /* @__PURE__ */ (0, S.jsx)("td", { children: e.department }),
336
+ /* @__PURE__ */ (0, S.jsx)("td", { children: e.birthDate }),
337
+ /* @__PURE__ */ (0, S.jsx)("td", { children: e.street }),
338
+ /* @__PURE__ */ (0, S.jsx)("td", { children: e.city }),
339
+ /* @__PURE__ */ (0, S.jsx)("td", { children: e.state }),
340
+ /* @__PURE__ */ (0, S.jsx)("td", { children: e.zipCode })
341
+ ] }, t)) });
342
+ }
343
+ var k = { table: "_table_gudt1_1" };
344
+ //#endregion
345
+ //#region src/components/tableList/TableList.jsx
346
+ function A() {
347
+ return /* @__PURE__ */ (0, S.jsxs)("table", {
348
+ className: k.table,
349
+ children: [/* @__PURE__ */ (0, S.jsx)(D, {}), /* @__PURE__ */ (0, S.jsx)(O, {})]
350
+ });
351
+ }
352
+ //#endregion
353
+ //#region src/components/entriesDisplay/EntriesDisplay.jsx
354
+ function j() {
355
+ let e = n((e) => e.table), t = e.listSliced.startIndex + 1, r = e.listSliced.endIndex, i = e.currentList.length;
356
+ return /* @__PURE__ */ (0, S.jsxs)("p", { children: [
357
+ "Showing ",
358
+ t,
359
+ " to ",
360
+ r,
361
+ " of ",
362
+ i,
363
+ " entries."
364
+ ] });
365
+ }
366
+ var M = { pagination: "_pagination_1kyfl_1" };
367
+ //#endregion
368
+ //#region src/components/pagination/Pagination.jsx
369
+ function N() {
370
+ let e = t(), r = n((e) => e.table), i = r.currentPage, a = r.listSliced.endIndex, o = r.currentList.length;
371
+ return /* @__PURE__ */ (0, S.jsxs)("div", {
372
+ className: M.pagination,
373
+ children: [
374
+ /* @__PURE__ */ (0, S.jsx)("button", {
375
+ onClick: () => {
376
+ i !== 1 && e(m(i - 1));
377
+ },
378
+ children: "Previous"
379
+ }),
380
+ /* @__PURE__ */ (0, S.jsx)("span", { children: i }),
381
+ /* @__PURE__ */ (0, S.jsx)("button", {
382
+ onClick: () => {
383
+ console.log(i), a !== o && e(m(i + 1));
384
+ },
385
+ children: "Next"
386
+ })
387
+ ]
388
+ });
389
+ }
390
+ var P = {
391
+ tableHeader: "_tableHeader_jg9ws_1",
392
+ tableFooter: "_tableFooter_jg9ws_2"
393
+ };
394
+ //#endregion
395
+ //#region src/components/tableCore/TableCore.jsx
396
+ function F({ list: e, tableHeaders: n }) {
397
+ return t()(f({
398
+ list: e,
399
+ tableHeaders: n
400
+ })), /* @__PURE__ */ (0, S.jsxs)(S.Fragment, { children: [
401
+ /* @__PURE__ */ (0, S.jsxs)("div", {
402
+ className: P.tableHeader,
403
+ children: [/* @__PURE__ */ (0, S.jsx)(C, {}), /* @__PURE__ */ (0, S.jsx)(w, {})]
404
+ }),
405
+ /* @__PURE__ */ (0, S.jsx)(A, {}),
406
+ /* @__PURE__ */ (0, S.jsxs)("div", {
407
+ className: P.tableFooter,
408
+ children: [/* @__PURE__ */ (0, S.jsx)(j, {}), /* @__PURE__ */ (0, S.jsx)(N, {})]
409
+ })
410
+ ] });
411
+ }
412
+ //#endregion
413
+ //#region src/Table.jsx
414
+ function I(t) {
415
+ return /* @__PURE__ */ (0, S.jsx)(e, {
416
+ store: v,
417
+ children: /* @__PURE__ */ (0, S.jsx)(F, { ...t })
418
+ });
419
+ }
420
+ //#endregion
421
+ export { I as Table };
@@ -0,0 +1,6 @@
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("react-redux"),require("@reduxjs/toolkit"),require("react")):typeof define==`function`&&define.amd?define([`exports`,`react-redux`,`@reduxjs/toolkit`,`react`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.ReactHrnetTable={},e.ReactRedux,e.ReduxToolkit,e.React))})(this,function(e,t,n,r){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var i=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),a=(e,t)=>t?e.filter(e=>Object.values(e).map(e=>e.toString().toLowerCase()).some(e=>e.includes(t.toLowerCase()))):e,o=(e,t)=>t?.key?[...e].sort((e,n)=>{let r=e[t.key],i=n[t.key];return r<i?t.direction===`asc`?-1:1:r>i?t.direction===`asc`?1:-1:0}):e,s=(e,t,n)=>{if(!Array.isArray(e))return[];let r=Math.max(0,(t-1)*n),i=Math.min(r+n,e.length),a=e.slice(r,i);return console.log(r,i),{slice:a,startIndex:r,endIndex:i}},c=(0,n.createSlice)({name:`table`,initialState:{searchResult:``,currentPage:1,entriesPerPage:10,sortConfig:{key:null,direction:`asc`}},reducers:{setList:(e,t)=>{e.initialList=t.payload.list,e.tableHeaders=t.payload.tableHeaders,e.currentList=e.initialList,e.listSliced=s(e.currentList,e.currentPage,e.entriesPerPage),e.listToDisplay=e.listSliced.slice},setSearchResult:(e,t)=>{e.searchResult=t.payload,e.currentPage=1,e.currentList=a(e.initialList,t.payload),e.listSliced=s(e.currentList,e.currentPage,e.entriesPerPage),e.listToDisplay=e.listSliced.slice},setCurrentPage:(e,t)=>{e.currentPage=t.payload,e.listSliced=s(e.currentList,e.currentPage,e.entriesPerPage),e.listToDisplay=e.listSliced.slice},setEntriesPerPage:(e,t)=>{e.searchResult=``,e.currentPage=1,e.entriesPerPage=t.payload,e.listSliced=s(e.currentList,e.currentPage,e.entriesPerPage),e.listToDisplay=e.listSliced.slice},setSortConfig:(e,t)=>{e.sortConfig=t.payload,e.listToDisplay=o(e.listToDisplay,t.payload)}}}),{setList:l,setSearchResult:u,setCurrentPage:d,setEntriesPerPage:f,setSortConfig:p}=c.actions,m=c.reducer,h=(0,n.configureStore)({reducer:{table:m}});h.subscribe(()=>{console.log(`State updated:`,h.getState())});var g={entriesControl:`_entriesControl_h5mt7_2`},_=i((e=>{var t=Symbol.for(`react.transitional.element`),n=Symbol.for(`react.fragment`);function r(e,n,r){var i=null;if(r!==void 0&&(i=``+r),n.key!==void 0&&(i=``+n.key),`key`in n)for(var a in r={},n)a!==`key`&&(r[a]=n[a]);else r=n;return n=r.ref,{$$typeof:t,type:e,key:i,ref:n===void 0?null:n,props:r}}e.Fragment=n,e.jsx=r,e.jsxs=r})),v=i((e=>{process.env.NODE_ENV!==`production`&&(function(){function t(e){if(e==null)return null;if(typeof e==`function`)return e.$$typeof===O?null:e.displayName||e.name||null;if(typeof e==`string`)return e;switch(e){case _:return`Fragment`;case y:return`Profiler`;case v:return`StrictMode`;case C:return`Suspense`;case w:return`SuspenseList`;case D:return`Activity`}if(typeof e==`object`)switch(typeof e.tag==`number`&&console.error(`Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue.`),e.$$typeof){case g:return`Portal`;case x:return e.displayName||`Context`;case b:return(e._context.displayName||`Context`)+`.Consumer`;case S:var n=e.render;return e=e.displayName,e||=(e=n.displayName||n.name||``,e===``?`ForwardRef`:`ForwardRef(`+e+`)`),e;case T:return n=e.displayName||null,n===null?t(e.type)||`Memo`:n;case E:n=e._payload,e=e._init;try{return t(e(n))}catch{}}return null}function n(e){return``+e}function r(e){try{n(e);var t=!1}catch{t=!0}if(t){t=console;var r=t.error,i=typeof Symbol==`function`&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||`Object`;return r.call(t,`The provided key is an unsupported type %s. This value must be coerced to a string before using it here.`,i),n(e)}}function i(e){if(e===_)return`<>`;if(typeof e==`object`&&e&&e.$$typeof===E)return`<...>`;try{var n=t(e);return n?`<`+n+`>`:`<...>`}catch{return`<...>`}}function a(){var e=k.A;return e===null?null:e.getOwner()}function o(){return Error(`react-stack-top-frame`)}function s(e){if(A.call(e,`key`)){var t=Object.getOwnPropertyDescriptor(e,`key`).get;if(t&&t.isReactWarning)return!1}return e.key!==void 0}function c(e,t){function n(){N||(N=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",t))}n.isReactWarning=!0,Object.defineProperty(e,"key",{get:n,configurable:!0})}function l(){var e=t(this.type);return P[e]||(P[e]=!0,console.error(`Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.`)),e=this.props.ref,e===void 0?null:e}function u(e,t,n,r,i,a){var o=n.ref;return e={$$typeof:h,type:e,key:t,props:n,_owner:r},(o===void 0?null:o)===null?Object.defineProperty(e,"ref",{enumerable:!1,value:null}):Object.defineProperty(e,"ref",{enumerable:!1,get:l}),e._store={},Object.defineProperty(e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:i}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:a}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function d(e,n,i,o,l,d){var p=n.children;if(p!==void 0){if(o){if(j(p)){for(o=0;o<p.length;o++)f(p[o]);Object.freeze&&Object.freeze(p)}else console.error(`React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.`)}else f(p)}if(A.call(n,`key`)){p=t(e);var m=Object.keys(n).filter(function(e){return e!==`key`});o=0<m.length?`{key: someKey, `+m.join(`: ..., `)+`: ...}`:`{key: someKey}`,L[p+o]||(m=0<m.length?`{`+m.join(`: ..., `)+`: ...}`:`{}`,console.error(`A props object containing a "key" prop is being spread into JSX:
2
+ let props = %s;
3
+ <%s {...props} />
4
+ React keys must be passed directly to JSX without using spread:
5
+ let props = %s;
6
+ <%s key={someKey} {...props} />`,o,p,m,p),L[p+o]=!0)}if(p=null,i!==void 0&&(r(i),p=``+i),s(n)&&(r(n.key),p=``+n.key),`key`in n)for(var h in i={},n)h!==`key`&&(i[h]=n[h]);else i=n;return p&&c(i,typeof e==`function`?e.displayName||e.name||`Unknown`:e),u(e,p,i,a(),l,d)}function f(e){p(e)?e._store&&(e._store.validated=1):typeof e==`object`&&e&&e.$$typeof===E&&(e._payload.status===`fulfilled`?p(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function p(e){return typeof e==`object`&&!!e&&e.$$typeof===h}var m=require("react"),h=Symbol.for(`react.transitional.element`),g=Symbol.for(`react.portal`),_=Symbol.for(`react.fragment`),v=Symbol.for(`react.strict_mode`),y=Symbol.for(`react.profiler`),b=Symbol.for(`react.consumer`),x=Symbol.for(`react.context`),S=Symbol.for(`react.forward_ref`),C=Symbol.for(`react.suspense`),w=Symbol.for(`react.suspense_list`),T=Symbol.for(`react.memo`),E=Symbol.for(`react.lazy`),D=Symbol.for(`react.activity`),O=Symbol.for(`react.client.reference`),k=m.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,A=Object.prototype.hasOwnProperty,j=Array.isArray,M=console.createTask?console.createTask:function(){return null};m={react_stack_bottom_frame:function(e){return e()}};var N,P={},F=m.react_stack_bottom_frame.bind(m,o)(),I=M(i(o)),L={};e.Fragment=_,e.jsx=function(e,t,n){var r=1e4>k.recentlyCreatedOwnerStacks++;return d(e,t,n,!1,r?Error(`react-stack-top-frame`):F,r?M(i(e)):I)},e.jsxs=function(e,t,n){var r=1e4>k.recentlyCreatedOwnerStacks++;return d(e,t,n,!0,r?Error(`react-stack-top-frame`):F,r?M(i(e)):I)}})()})),y=i(((e,t)=>{t.exports=process.env.NODE_ENV===`production`?_():v()}))();function b(){let e=(0,t.useDispatch)(),n=(0,t.useSelector)(e=>e.table.entriesPerPage)||10;return(0,y.jsx)(`div`,{className:g.entriesControl,children:(0,y.jsxs)(`label`,{children:[`Show`,(0,y.jsxs)(`select`,{name:`table-entries`,id:`table-entries`,value:n,onChange:t=>{e(f(Number(t.target.value)))},children:[(0,y.jsx)(`option`,{value:`10`,children:`10`}),(0,y.jsx)(`option`,{value:`25`,children:`25`}),(0,y.jsx)(`option`,{value:`50`,children:`50`}),(0,y.jsx)(`option`,{value:`100`,children:`100`})]}),`entries`]})})}function x(){let[e,n]=(0,r.useState)(``),i=(0,t.useDispatch)();return(0,y.jsxs)(`label`,{children:[`Search:`,` `,(0,y.jsx)(`input`,{type:`search`,value:e,onChange:e=>{n(e.target.value),i(u(e.target.value))},"aria-controls":`employee-table`})]})}var S={cellHeader:`_cellHeader_mvi5q_1`,sortIcon:`_sortIcon_mvi5q_5`,sortArrows:`_sortArrows_mvi5q_15`};function C({header:e}){let n=(0,t.useDispatch)(),r=(0,t.useSelector)(e=>e.table.sortConfig),i=Object.keys(e)[0],a=e[i],o=()=>{let e=`asc`;r?.key===i&&(e=r.direction===`asc`?`desc`:`asc`),n(p({key:i,direction:e}))},s=r?.key===i,c=s&&r.direction===`asc`,l=s&&r.direction===`desc`;return(0,y.jsxs)(`th`,{className:S.cellHeader,onClick:o,children:[(0,y.jsx)(`span`,{children:a}),(0,y.jsxs)(`span`,{className:S.sortIcon,children:[(0,y.jsx)(`span`,{className:S.sortArrows,style:{opacity:c?1:.3,color:`#6366f1`},children:`▲`}),(0,y.jsx)(`span`,{className:S.sortArrows,style:{opacity:l?1:.3,color:`#6366f1`},children:`▼`})]})]})}function w(){let e=(0,t.useSelector)(e=>e.table.tableHeaders);return(0,y.jsx)(`thead`,{children:(0,y.jsx)(`tr`,{children:e.map((e,t)=>(0,y.jsx)(C,{header:e},t))})})}function T(){let e=(0,t.useSelector)(e=>e.table.listToDisplay);return(0,y.jsx)(`tbody`,{children:e.map((e,t)=>(0,y.jsxs)(`tr`,{children:[(0,y.jsx)(`td`,{children:e.firstName}),(0,y.jsx)(`td`,{children:e.lastName}),(0,y.jsx)(`td`,{children:e.startDate}),(0,y.jsx)(`td`,{children:e.department}),(0,y.jsx)(`td`,{children:e.birthDate}),(0,y.jsx)(`td`,{children:e.street}),(0,y.jsx)(`td`,{children:e.city}),(0,y.jsx)(`td`,{children:e.state}),(0,y.jsx)(`td`,{children:e.zipCode})]},t))})}var E={table:`_table_gudt1_1`};function D(){return(0,y.jsxs)(`table`,{className:E.table,children:[(0,y.jsx)(w,{}),(0,y.jsx)(T,{})]})}function O(){let e=(0,t.useSelector)(e=>e.table),n=e.listSliced.startIndex+1,r=e.listSliced.endIndex,i=e.currentList.length;return(0,y.jsxs)(`p`,{children:[`Showing `,n,` to `,r,` of `,i,` entries.`]})}var k={pagination:`_pagination_1kyfl_1`};function A(){let e=(0,t.useDispatch)(),n=(0,t.useSelector)(e=>e.table),r=n.currentPage,i=n.listSliced.endIndex,a=n.currentList.length;return(0,y.jsxs)(`div`,{className:k.pagination,children:[(0,y.jsx)(`button`,{onClick:()=>{r!==1&&e(d(r-1))},children:`Previous`}),(0,y.jsx)(`span`,{children:r}),(0,y.jsx)(`button`,{onClick:()=>{console.log(r),i!==a&&e(d(r+1))},children:`Next`})]})}var j={tableHeader:`_tableHeader_jg9ws_1`,tableFooter:`_tableFooter_jg9ws_2`};function M({list:e,tableHeaders:n}){return(0,t.useDispatch)()(l({list:e,tableHeaders:n})),(0,y.jsxs)(y.Fragment,{children:[(0,y.jsxs)(`div`,{className:j.tableHeader,children:[(0,y.jsx)(b,{}),(0,y.jsx)(x,{})]}),(0,y.jsx)(D,{}),(0,y.jsxs)(`div`,{className:j.tableFooter,children:[(0,y.jsx)(O,{}),(0,y.jsx)(A,{})]})]})}function N(e){return(0,y.jsx)(t.Provider,{store:h,children:(0,y.jsx)(M,{...e})})}e.Table=N});
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "react-hrnet-table-gandrica",
3
+ "version": "1.0.0",
4
+ "private": false,
5
+ "type": "module",
6
+ "main": "dist/react-hrnet-table.umd.js",
7
+ "module": "dist/react-hrnet-table.es.js",
8
+ "style": "dist/style.css",
9
+ "exports": {
10
+ ".": {
11
+ "import": "./dist/react-hrnet-table.es.js",
12
+ "require": "./dist/react-hrnet-table.umd.js"
13
+ },
14
+ "./style.css": "./dist/style.css"
15
+ },
16
+ "files": [
17
+ "dist"
18
+ ],
19
+ "scripts": {
20
+ "dev": "vite",
21
+ "build": "vite build",
22
+ "lint": "eslint .",
23
+ "preview": "vite preview",
24
+ "test": "vitest"
25
+ },
26
+ "peerDependencies": {
27
+ "react": "^18.2.0 || ^19.0.0",
28
+ "react-dom": "^18.2.0 || ^19.0.0",
29
+ "@reduxjs/toolkit": "^1.9.0 || ^2.0.0",
30
+ "react-redux": "^8.0.0 || ^9.0.0"
31
+ },
32
+ "devDependencies": {
33
+ "@reduxjs/toolkit": "^2.12.0",
34
+ "react": "^19.2.8",
35
+ "react-dom": "^19.2.8",
36
+ "react-redux": "^9.3.0",
37
+ "sass": "^1.102.0",
38
+ "@eslint/js": "^10.0.1",
39
+ "@testing-library/jest-dom": "^7.0.1",
40
+ "@testing-library/react": "^16.3.2",
41
+ "@types/react": "^19.2.17",
42
+ "@types/react-dom": "^19.2.3",
43
+ "@vitejs/plugin-react": "^6.0.4",
44
+ "eslint": "^10.8.0",
45
+ "eslint-plugin-react-hooks": "^7.1.1",
46
+ "eslint-plugin-react-refresh": "^0.5.3",
47
+ "globals": "^17.7.0",
48
+ "jsdom": "^29.1.1",
49
+ "vite": "^8.2.0",
50
+ "vitest": "^4.1.10"
51
+ }
52
+ }