@chumsinc/sortable-tables 2.0.6

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 (74) hide show
  1. package/CHANGELOG.md +98 -0
  2. package/LICENSE +21 -0
  3. package/README.md +82 -0
  4. package/babel.config.mjs +13 -0
  5. package/changelog-template.hbs +45 -0
  6. package/dist/DataTable.d.ts +6 -0
  7. package/dist/DataTable.js +15 -0
  8. package/dist/DataTable.js.map +1 -0
  9. package/dist/DataTableCell.d.ts +293 -0
  10. package/dist/DataTableCell.js +17 -0
  11. package/dist/DataTableCell.js.map +1 -0
  12. package/dist/DataTableHead.d.ts +6 -0
  13. package/dist/DataTableHead.js +11 -0
  14. package/dist/DataTableHead.js.map +1 -0
  15. package/dist/DataTableRow.d.ts +6 -0
  16. package/dist/DataTableRow.js +17 -0
  17. package/dist/DataTableRow.js.map +1 -0
  18. package/dist/DataTableTBody.d.ts +6 -0
  19. package/dist/DataTableTBody.js +16 -0
  20. package/dist/DataTableTBody.js.map +1 -0
  21. package/dist/DataTableTH.d.ts +6 -0
  22. package/dist/DataTableTH.js +9 -0
  23. package/dist/DataTableTH.js.map +1 -0
  24. package/dist/RowsPerPage.d.ts +7 -0
  25. package/dist/RowsPerPage.js +16 -0
  26. package/dist/RowsPerPage.js.map +1 -0
  27. package/dist/SortableTable.d.ts +6 -0
  28. package/dist/SortableTable.js +15 -0
  29. package/dist/SortableTable.js.map +1 -0
  30. package/dist/SortableTableHead.d.ts +6 -0
  31. package/dist/SortableTableHead.js +12 -0
  32. package/dist/SortableTableHead.js.map +1 -0
  33. package/dist/SortableTableTH.d.ts +6 -0
  34. package/dist/SortableTableTH.js +48 -0
  35. package/dist/SortableTableTH.js.map +1 -0
  36. package/dist/Table.d.ts +5 -0
  37. package/dist/Table.js +28 -0
  38. package/dist/Table.js.map +1 -0
  39. package/dist/TablePagination.d.ts +6 -0
  40. package/dist/TablePagination.js +13 -0
  41. package/dist/TablePagination.js.map +1 -0
  42. package/dist/index.d.ts +10 -0
  43. package/dist/index.js +10 -0
  44. package/dist/index.js.map +1 -0
  45. package/dist/types.d.ts +104 -0
  46. package/dist/types.js +2 -0
  47. package/dist/types.js.map +1 -0
  48. package/dist/utils.d.ts +1 -0
  49. package/dist/utils.js +2 -0
  50. package/dist/utils.js.map +1 -0
  51. package/eslint.config.mjs +14 -0
  52. package/package.json +91 -0
  53. package/public/index.html +28 -0
  54. package/src/DataTable.tsx +47 -0
  55. package/src/DataTableCell.tsx +28 -0
  56. package/src/DataTableHead.tsx +27 -0
  57. package/src/DataTableRow.tsx +38 -0
  58. package/src/DataTableTBody.tsx +40 -0
  59. package/src/DataTableTH.tsx +20 -0
  60. package/src/RowsPerPage.tsx +38 -0
  61. package/src/SortableTable.tsx +46 -0
  62. package/src/SortableTableHead.tsx +31 -0
  63. package/src/SortableTableTH.tsx +77 -0
  64. package/src/Table.tsx +43 -0
  65. package/src/TablePagination.tsx +72 -0
  66. package/src/index.tsx +14 -0
  67. package/src/types.ts +127 -0
  68. package/src/utils.ts +1 -0
  69. package/test/TestTable.tsx +67 -0
  70. package/test/data.ts +232 -0
  71. package/test/index.tsx +11 -0
  72. package/tsconfig.json +29 -0
  73. package/webpack.common.mjs +72 -0
  74. package/webpack.dev.mjs +35 -0
@@ -0,0 +1,67 @@
1
+ import React, {useEffect, useState} from 'react';
2
+ import {ProductLine, productLines, productLineSorter} from './data'
3
+ import {SortableTable, SortableTableField, SortProps} from "../src";
4
+ import TablePagination from "../src/TablePagination";
5
+
6
+ const fields: SortableTableField<ProductLine>[] = [
7
+ {field: 'ProductLine', title: 'Prod Line', sortable: true, as: 'th'},
8
+ {field: 'ProductLineDesc', title: 'Description', sortable: true},
9
+ {
10
+ field: 'ProductType',
11
+ title: 'Description',
12
+ sortable: true,
13
+ render: (row) => <span className="badge bg-info">{row.ProductType}</span>,
14
+ align: 'center'
15
+ },
16
+ {
17
+ field: 'Valuation',
18
+ title: 'Valuation',
19
+ sortable: true,
20
+ render: (row) => <span className="badge bg-secondary">{row.Valuation}</span>,
21
+ align: 'center'
22
+ },
23
+ {
24
+ field: 'ExplodeKitItems',
25
+ title: 'Explode Kit Items?',
26
+ sortable: true,
27
+ render: (row) => <span className="badge bg-primary">{row.ExplodeKitItems}</span>,
28
+ align: 'end'
29
+ },
30
+ ]
31
+ const rowClassName = (row: ProductLine) => row.active ? '' : 'table-warning';
32
+
33
+ export default function TestTable() {
34
+ const [sort, setSort] = useState<SortProps<ProductLine>>({field: 'ProductLine', ascending: true});
35
+ const [list, setList] = useState<ProductLine[]>(productLines);
36
+ const [page, setPage] = useState(0);
37
+ const [rowsPerPage, setRowsPerPage] = useState(5);
38
+
39
+
40
+ useEffect(() => {
41
+ setList([...productLines.sort(productLineSorter(sort))]);
42
+ setPage(0)
43
+ }, [sort]);
44
+
45
+ const rowsPerPageChangeHandler = (rpp: number) => {
46
+ setPage(0);
47
+ setRowsPerPage(rpp);
48
+ }
49
+
50
+ return (
51
+ <div>
52
+ <SortableTable currentSort={sort} onChangeSort={setSort} fields={fields} size="lg" responsive
53
+ data={list.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage)}
54
+ keyField="ProductLine" rowClassName={rowClassName}/>
55
+ <TablePagination page={page} onChangePage={setPage} size="sm"
56
+ rowsPerPage={rowsPerPage}
57
+ rowsPerPageProps={{
58
+ onChange: rowsPerPageChangeHandler,
59
+ pageValues: [5, 10, 15, 25, 50, 100]
60
+ }}
61
+ showFirst={list.length > rowsPerPage}
62
+ showLast={list.length > rowsPerPage}
63
+ count={list.length}/>
64
+ </div>
65
+
66
+ )
67
+ }
package/test/data.ts ADDED
@@ -0,0 +1,232 @@
1
+ import {SortProps} from "../src";
2
+
3
+ export interface ProductLine {
4
+ ProductLine: string,
5
+ ProductLineDesc: string,
6
+ ProductType: string;
7
+ Valuation: string;
8
+ ExplodeKitItems: string;
9
+ active: boolean;
10
+ }
11
+
12
+ export const productLines: ProductLine[] = [
13
+ {
14
+ "ProductLine": "A",
15
+ "ProductLineDesc": "Watchbands",
16
+ "ProductType": "F",
17
+ "Valuation": "2",
18
+ "ExplodeKitItems": "P",
19
+ "active": true
20
+ },
21
+ {
22
+ "ProductLine": "BC",
23
+ "ProductLineDesc": "Beyond Coastal",
24
+ "ProductType": "F",
25
+ "Valuation": "5",
26
+ "ExplodeKitItems": "P",
27
+ "active": true
28
+ },
29
+ {
30
+ "ProductLine": "CASE",
31
+ "ProductLineDesc": "Accessory Cases & Bags",
32
+ "ProductType": "F",
33
+ "Valuation": "2",
34
+ "ExplodeKitItems": "A",
35
+ "active": true
36
+ },
37
+ {
38
+ "ProductLine": "D",
39
+ "ProductLineDesc": "Display Racks",
40
+ "ProductType": "F",
41
+ "Valuation": "2",
42
+ "ExplodeKitItems": "P",
43
+ "active": true
44
+ },
45
+ {
46
+ "ProductLine": "E",
47
+ "ProductLineDesc": "Retainers",
48
+ "ProductType": "F",
49
+ "Valuation": "2",
50
+ "ExplodeKitItems": "P",
51
+ "active": true
52
+ },
53
+ {
54
+ "ProductLine": "E2",
55
+ "ProductLineDesc": "Optical Accessories",
56
+ "ProductType": "F",
57
+ "Valuation": "2",
58
+ "ExplodeKitItems": "P",
59
+ "active": true
60
+ },
61
+ {
62
+ "ProductLine": "F2",
63
+ "ProductLineDesc": "Active Gear/Fitness",
64
+ "ProductType": "F",
65
+ "Valuation": "2",
66
+ "ExplodeKitItems": "P",
67
+ "active": true
68
+ },
69
+ {
70
+ "ProductLine": "FGRM",
71
+ "ProductLineDesc": "Finished Goods w/USA Step",
72
+ "ProductType": "F",
73
+ "Valuation": "2",
74
+ "ExplodeKitItems": "P",
75
+ "active": true
76
+ },
77
+ {
78
+ "ProductLine": "FUSA",
79
+ "ProductLineDesc": "#Freestyle USA Sales",
80
+ "ProductType": "F",
81
+ "Valuation": "2",
82
+ "ExplodeKitItems": "A",
83
+ "active": false
84
+ },
85
+ {
86
+ "ProductLine": "G",
87
+ "ProductLineDesc": "Chums Custom OEM",
88
+ "ProductType": "F",
89
+ "Valuation": "2",
90
+ "ExplodeKitItems": "P",
91
+ "active": true
92
+ },
93
+ {
94
+ "ProductLine": "J",
95
+ "ProductLineDesc": "Winter Products",
96
+ "ProductType": "F",
97
+ "Valuation": "2",
98
+ "ExplodeKitItems": "P",
99
+ "active": true
100
+ },
101
+ {
102
+ "ProductLine": "JP",
103
+ "ProductLineDesc": "Japan Products",
104
+ "ProductType": "F",
105
+ "Valuation": "2",
106
+ "ExplodeKitItems": "A",
107
+ "active": true
108
+ },
109
+ {
110
+ "ProductLine": "K",
111
+ "ProductLineDesc": "Keychains",
112
+ "ProductType": "F",
113
+ "Valuation": "2",
114
+ "ExplodeKitItems": "P",
115
+ "active": true
116
+ },
117
+ {
118
+ "ProductLine": "L",
119
+ "ProductLineDesc": "Wallets",
120
+ "ProductType": "F",
121
+ "Valuation": "2",
122
+ "ExplodeKitItems": "P",
123
+ "active": true
124
+ },
125
+ {
126
+ "ProductLine": "M",
127
+ "ProductLineDesc": "Misc Products",
128
+ "ProductType": "F",
129
+ "Valuation": "2",
130
+ "ExplodeKitItems": "P",
131
+ "active": true
132
+ },
133
+ {
134
+ "ProductLine": "O",
135
+ "ProductLineDesc": "Lip Balm/Lotion",
136
+ "ProductType": "F",
137
+ "Valuation": "2",
138
+ "ExplodeKitItems": "P",
139
+ "active": true
140
+ },
141
+ {
142
+ "ProductLine": "P",
143
+ "ProductLineDesc": "Paracord",
144
+ "ProductType": "F",
145
+ "Valuation": "2",
146
+ "ExplodeKitItems": "A",
147
+ "active": true
148
+ },
149
+ {
150
+ "ProductLine": "POFG",
151
+ "ProductLineDesc": "Purchased Items with WT",
152
+ "ProductType": "F",
153
+ "Valuation": "2",
154
+ "ExplodeKitItems": "P",
155
+ "active": true
156
+ },
157
+ {
158
+ "ProductLine": "R",
159
+ "ProductLineDesc": "Rep Sample Product",
160
+ "ProductType": "F",
161
+ "Valuation": "2",
162
+ "ExplodeKitItems": "P",
163
+ "active": true
164
+ },
165
+ {
166
+ "ProductLine": "RBC",
167
+ "ProductLineDesc": "#Rep Sample BeyondCoastal",
168
+ "ProductType": "F",
169
+ "Valuation": "2",
170
+ "ExplodeKitItems": "A",
171
+ "active": false
172
+ },
173
+ {
174
+ "ProductLine": "RM",
175
+ "ProductLineDesc": "Raw Materials",
176
+ "ProductType": "R",
177
+ "Valuation": "2",
178
+ "ExplodeKitItems": "P",
179
+ "active": true
180
+ },
181
+ {
182
+ "ProductLine": "RMLY",
183
+ "ProductLineDesc": "Lanyard RHOOKS Sold",
184
+ "ProductType": "R",
185
+ "Valuation": "2",
186
+ "ExplodeKitItems": "P",
187
+ "active": true
188
+ },
189
+ {
190
+ "ProductLine": "S",
191
+ "ProductLineDesc": "Promotional Products",
192
+ "ProductType": "F",
193
+ "Valuation": "2",
194
+ "ExplodeKitItems": "P",
195
+ "active": true
196
+ },
197
+ {
198
+ "ProductLine": "T",
199
+ "ProductLineDesc": "Kits",
200
+ "ProductType": "F",
201
+ "Valuation": "2",
202
+ "ExplodeKitItems": "A",
203
+ "active": true
204
+ },
205
+ {
206
+ "ProductLine": "V",
207
+ "ProductLineDesc": "Lanyards",
208
+ "ProductType": "F",
209
+ "Valuation": "2",
210
+ "ExplodeKitItems": "P",
211
+ "active": true
212
+ }
213
+ ];
214
+
215
+ export const productLineSorter = (sort: SortProps<ProductLine>) => (a: ProductLine, b: ProductLine) => {
216
+ const {field, ascending} = sort;
217
+ const sortMod = ascending === false ? -1 : 1;
218
+ switch (field) {
219
+ case 'ProductLine':
220
+ case 'ProductLineDesc':
221
+ case 'ProductType':
222
+ case 'Valuation':
223
+ case 'ExplodeKitItems':
224
+ return (
225
+ a[field].localeCompare(b[field]) === 0
226
+ ? a.ProductLine.localeCompare(b.ProductLine)
227
+ : a[field].localeCompare(b[field])
228
+ ) * sortMod;
229
+ default:
230
+ return a.ProductLine.localeCompare(b.ProductLine)
231
+ }
232
+ }
package/test/index.tsx ADDED
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ import {createRoot} from "react-dom/client";
3
+ import TestTable from "./TestTable";
4
+
5
+ const container = document.getElementById('app');
6
+ const root = createRoot(container!);
7
+ root.render(
8
+ <React.StrictMode>
9
+ <TestTable />
10
+ </React.StrictMode>
11
+ );
package/tsconfig.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "compilerOptions": {
3
+ "allowJs": true,
4
+ "allowSyntheticDefaultImports": true,
5
+ "declaration": true,
6
+ "esModuleInterop": true,
7
+ "forceConsistentCasingInFileNames": true,
8
+ "isolatedModules": true,
9
+ "jsx": "react-jsx",
10
+ "lib": [
11
+ "dom",
12
+ "dom.iterable",
13
+ "esnext"
14
+ ],
15
+ "module": "esnext",
16
+ "moduleResolution": "node",
17
+ "noEmit": false,
18
+ "noFallthroughCasesInSwitch": true,
19
+ "noImplicitAny": true,
20
+ "outDir": "./dist/",
21
+ "resolveJsonModule": true,
22
+ "skipLibCheck": true,
23
+ "sourceMap": true,
24
+ "strict": true,
25
+ "target": "es2020"
26
+ },
27
+ "include": ["src/**/*"],
28
+ "exclude": ["node_modules"]
29
+ }
@@ -0,0 +1,72 @@
1
+ import path from 'node:path';
2
+ import process from "node:process";
3
+
4
+ export default {
5
+ entry: './src/index.tsx',
6
+ module: {
7
+ rules: [
8
+ {
9
+ test: /\.tsx?$/,
10
+ use: 'ts-loader',
11
+ exclude: /node_modules/,
12
+ },
13
+ {
14
+ test: /\.css$/,
15
+ use: [
16
+ {loader: 'style-loader'},
17
+ {loader: 'css-loader'},
18
+ ],
19
+ },
20
+ {
21
+ test: /\.s[ac]ss$/i,
22
+ use: [
23
+ 'style-loader',
24
+ 'css-loader',
25
+ 'sass-loader',
26
+ ],
27
+ }
28
+ ]
29
+ },
30
+ resolve: {
31
+ extensions: ['.tsx', '.ts', '.js'],
32
+ },
33
+ plugins: [
34
+ ],
35
+ optimization: {
36
+ splitChunks: {
37
+ chunks: 'async',
38
+ minSize: 20000,
39
+ minRemainingSize: 0,
40
+ minChunks: 1,
41
+ maxAsyncRequests: 30,
42
+ maxInitialRequests: 30,
43
+ enforceSizeThreshold: 50000,
44
+ cacheGroups: {
45
+ react: {
46
+ test: /[\\/]node_modules[\\/](react|react-dom)[\\/]/,
47
+ name: 'vendors-react',
48
+ chunks: 'all',
49
+ priority: 10,
50
+ },
51
+ defaultVendors: {
52
+ test: /[\\/]node_modules[\\/]/,
53
+ name: 'vendors',
54
+ chunks: 'all',
55
+ priority: 0,
56
+ },
57
+ default: {
58
+ minChunks: 2,
59
+ priority: -10,
60
+ reuseExistingChunk: true,
61
+ }
62
+ }
63
+ }
64
+ },
65
+ output: {
66
+ path: path.join(process.cwd(), 'public/js'),
67
+ filename: "[name].js",
68
+ sourceMapFilename: '[file].map',
69
+ publicPath: '/',
70
+ },
71
+ target: 'web',
72
+ }
@@ -0,0 +1,35 @@
1
+ import {merge} from 'webpack-merge';
2
+ import common from './webpack.common.mjs';
3
+ import path from 'node:path';
4
+ import process from 'node:process';
5
+
6
+ const localProxy = {
7
+ target: 'http://localhost:8081',
8
+ ignorePath: false,
9
+ changeOrigin: true,
10
+ secure: false,
11
+ };
12
+
13
+ export default merge(common, {
14
+ entry: './test/index.tsx',
15
+ mode: 'development',
16
+ devServer: {
17
+ allowedHosts: 'auto',
18
+ static: {
19
+ directory: path.join(process.cwd(), 'public'),
20
+ serveIndex: true,
21
+ watch: false,
22
+ },
23
+ hot: true,
24
+ port: 3000,
25
+ proxy: [
26
+ {context: ['/api'], ...localProxy},
27
+ ],
28
+ watchFiles: [
29
+ path.join(process.cwd(), 'src/**/*'),
30
+ path.join(process.cwd(), 'test/**/*')
31
+ ]
32
+ },
33
+ devtool: 'inline-source-map',
34
+ plugins: []
35
+ });