@absreim/react-bootstrap-data-grid 0.1.2
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 +5 -0
- package/component.d.ts +8 -0
- package/component.jsx +72 -0
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/package.json +28 -0
- package/types.d.ts +10 -0
- package/types.js +1 -0
package/README.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
**@absreim/react-bootstrap-data-grid** is a data grid UI component meant for web apps using both React and Bootstrap.
|
|
2
|
+
|
|
3
|
+
See the documentation site at https://react-bootstrap-data-grid.vercel.app/ for instructions on usage.
|
|
4
|
+
|
|
5
|
+
See the source repository at https://github.com/absreim/react-bootstrap-data-grid to view the source code.
|
package/component.d.ts
ADDED
package/component.jsx
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useMemo } from "react";
|
|
3
|
+
var Grid = function (_a) {
|
|
4
|
+
var rows = _a.rows, cols = _a.cols;
|
|
5
|
+
var displayRows = useMemo(function () {
|
|
6
|
+
var nameToIndex = new Map();
|
|
7
|
+
cols.forEach(function (_a, index) {
|
|
8
|
+
var name = _a.name;
|
|
9
|
+
nameToIndex.set(name, index);
|
|
10
|
+
});
|
|
11
|
+
return rows.map(function (row, index) {
|
|
12
|
+
cols
|
|
13
|
+
.map(function (_a) {
|
|
14
|
+
var name = _a.name;
|
|
15
|
+
return name;
|
|
16
|
+
})
|
|
17
|
+
.forEach(function (name) {
|
|
18
|
+
if (!(name in row)) {
|
|
19
|
+
throw new Error("Column definition specifies a property named \"".concat(name, "\",\n but it was no found in the row data object at index ").concat(index));
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
var displayRow = [];
|
|
23
|
+
Object.keys(row).forEach(function (name) {
|
|
24
|
+
if (!nameToIndex.has(name)) {
|
|
25
|
+
throw new Error("Row data contains a property named \"".concat(name, "\",\n but it was not found among the column definitions"));
|
|
26
|
+
}
|
|
27
|
+
var index = nameToIndex.get(name);
|
|
28
|
+
var formatter = cols[index].formatter;
|
|
29
|
+
var typeString = cols[index].type;
|
|
30
|
+
var value = row[name];
|
|
31
|
+
if (formatter) {
|
|
32
|
+
displayRow[index] = formatter(value);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (typeString === "date") {
|
|
36
|
+
displayRow[index] = value.toDateString();
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (typeString === "datetime") {
|
|
40
|
+
displayRow[index] = value.toLocaleString();
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (typeString === "number") {
|
|
44
|
+
displayRow[index] = value.toLocaleString();
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
displayRow[index] = value;
|
|
48
|
+
});
|
|
49
|
+
return displayRow;
|
|
50
|
+
});
|
|
51
|
+
}, [rows, cols]);
|
|
52
|
+
// Once this component implements selection state, and if such interactivity is enabled, (conditionally) change the
|
|
53
|
+
// aria role to "grid".
|
|
54
|
+
// Array index is okay for the key for rows until some type of feature involving changing the index of rows, such as
|
|
55
|
+
// sorting or pagination, is implemented.
|
|
56
|
+
return (<table className="table">
|
|
57
|
+
<thead>
|
|
58
|
+
<tr>
|
|
59
|
+
{cols.map(function (_a) {
|
|
60
|
+
var name = _a.name, label = _a.label;
|
|
61
|
+
return (<th key={name}>{label}</th>);
|
|
62
|
+
})}
|
|
63
|
+
</tr>
|
|
64
|
+
</thead>
|
|
65
|
+
<tbody>
|
|
66
|
+
{displayRows.map(function (row, index) { return (<tr key={index}>
|
|
67
|
+
{row.map(function (value, index) { return (<td key={index}>{value}</td>); })}
|
|
68
|
+
</tr>); })}
|
|
69
|
+
</tbody>
|
|
70
|
+
</table>);
|
|
71
|
+
};
|
|
72
|
+
export default Grid;
|
package/index.d.ts
ADDED
package/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@absreim/react-bootstrap-data-grid",
|
|
3
|
+
"description": "Data grid UI component for use with web apps using React and Bootstrap",
|
|
4
|
+
"version": "0.1.2",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Brook Li",
|
|
7
|
+
"homepage": "https://react-bootstrap-data-grid.vercel.app/",
|
|
8
|
+
"private": false,
|
|
9
|
+
"keywords": [
|
|
10
|
+
"react",
|
|
11
|
+
"bootstrap",
|
|
12
|
+
"data",
|
|
13
|
+
"table",
|
|
14
|
+
"grid"
|
|
15
|
+
],
|
|
16
|
+
"peerDependencies": {
|
|
17
|
+
"react": "^18",
|
|
18
|
+
"react-dom": "^18"
|
|
19
|
+
},
|
|
20
|
+
"main": "./index.js",
|
|
21
|
+
"module": "./index.js",
|
|
22
|
+
"types": "./index.d.ts",
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "https://github.com/absreim/react-bootstrap-data-grid.git",
|
|
26
|
+
"directory": "src/grid"
|
|
27
|
+
}
|
|
28
|
+
}
|
package/types.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type ColDataType = string | number | Date;
|
|
2
|
+
type ColDataTypeStrings = "string" | "number" | "date" | "datetime";
|
|
3
|
+
export interface ColDef {
|
|
4
|
+
type: ColDataTypeStrings;
|
|
5
|
+
name: string;
|
|
6
|
+
label: string;
|
|
7
|
+
formatter?: (value: any) => string;
|
|
8
|
+
}
|
|
9
|
+
export type RowDef = Record<string, ColDataType>;
|
|
10
|
+
export {};
|
package/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|