react-data-matrix 0.2.0 → 0.3.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.
@@ -0,0 +1,109 @@
1
+ export interface MatrixDetail {
2
+ id: number;
3
+ position: number;
4
+ matrix_type: string;
5
+ likelihood: string;
6
+ consequence: number;
7
+ header_title: string;
8
+ header_sub_title: string;
9
+ row_header_title: string;
10
+ row_header_sub_title: string;
11
+ }
12
+
13
+ export interface MatrixValue {
14
+ id: number;
15
+ matrix_id: number;
16
+ description: string;
17
+ score_value: number;
18
+ colour: string;
19
+ position: number;
20
+ likelihood_descriptor: string;
21
+ consequence_descriptor: number;
22
+ response: string;
23
+ }
24
+
25
+ export interface MatrixData {
26
+ id: number;
27
+ matrix_size: number;
28
+ matrix_name: string;
29
+ primary_header_title: string;
30
+ primary_row_header_title: string;
31
+ matrix_description: string;
32
+ matrix_details: MatrixDetail[];
33
+ matrix_values: MatrixValue[];
34
+ }
35
+
36
+ export interface ReactMatrixProps {
37
+ data: MatrixData;
38
+ matrixName: string;
39
+ matrixDescription: string;
40
+ hasTableBorder?: boolean;
41
+ hasInlineStyles?: boolean | undefined;
42
+ hasContainerStyles?: boolean | undefined;
43
+ reverseMatrixValues?: boolean;
44
+ matrixSizeSelected?: number;
45
+ rowPrimaryUpper?: boolean;
46
+ headerPrimaryUpper?: boolean;
47
+ tableContainerStyles?: React.CSSProperties;
48
+ tableStyles?: React.CSSProperties;
49
+ thRowStyles?: React.CSSProperties;
50
+ thTitleStyles?: React.CSSProperties;
51
+ thSubTitleStyles?: React.CSSProperties;
52
+ thPrimaryTitleStyles?: React.CSSProperties;
53
+ trRowStyles?: React.CSSProperties;
54
+ trTitleStyles?: React.CSSProperties;
55
+ trSubTitleStyles?: React.CSSProperties;
56
+ trPrimaryTitleStyles?: React.CSSProperties;
57
+ tdStyles?: React.CSSProperties;
58
+ customHeaderRowIdValue?: string;
59
+ customDynamicHeaderTitleIdValue?: string;
60
+ customDynamicSubHeaderTitleIdValue?: string;
61
+ customRowDynamicIdValue?: string;
62
+ customRowHeaderDynamicIdValue?: string;
63
+ customTableDataDynamicIdValue?: string;
64
+ }
65
+
66
+ export interface MatrixHeaderProps {
67
+ data: MatrixData;
68
+ hasInlineStyles?: boolean | undefined;
69
+ headerPrimaryUpper?: boolean;
70
+ thRowStyles?: React.CSSProperties;
71
+ thTitleStyles?: React.CSSProperties;
72
+ thSubTitleStyles?: React.CSSProperties;
73
+ thPrimaryTitleStyles?: React.CSSProperties;
74
+ customHeaderRowIdValue?: string;
75
+ customDynamicHeaderTitleIdValue?: string;
76
+ customDynamicSubHeaderTitleIdValue?: string;
77
+ }
78
+
79
+ export interface MatrixRowsProps {
80
+ data: MatrixData;
81
+ rowPrimaryUpper?: boolean;
82
+ hasInlineStyles?: boolean | undefined;
83
+ reverseMatrixValues?: boolean;
84
+ trRowStyles?: React.CSSProperties;
85
+ trTitleStyles?: React.CSSProperties;
86
+ trSubTitleStyles?: React.CSSProperties;
87
+ trPrimaryTitleStyles?: React.CSSProperties;
88
+ tdStyles?: React.CSSProperties;
89
+ customRowDynamicIdValue?: string;
90
+ customRowHeaderDynamicIdValue?: string;
91
+ customTableDataDynamicIdValue?: string;
92
+ }
93
+
94
+ export interface TableDataProps {
95
+ data: {
96
+ id: number;
97
+ colour: string;
98
+ position: number;
99
+ matrix_id: number;
100
+ score_value: number;
101
+ description: string;
102
+ response: string;
103
+ likelihood_descriptor: string;
104
+ consequence_descriptor: number;
105
+ };
106
+ tdStyles?: React.CSSProperties;
107
+ hasInlineStyles?: boolean;
108
+ customTableDataDynamicIdValue?: string;
109
+ }
@@ -0,0 +1,346 @@
1
+ import { MatrixData } from "../types";
2
+
3
+ export const data: MatrixData = {
4
+ id: 1,
5
+ matrix_size: 5,
6
+ matrix_name: "React Matrix",
7
+ primary_header_title: "Consequence",
8
+ primary_row_header_title: "Likelihood",
9
+ matrix_description: "Risk Matrix Template",
10
+
11
+ matrix_details: [
12
+ {
13
+ id: 1,
14
+ likelihood: "E",
15
+ consequence: 1,
16
+ position: 5,
17
+ matrix_type: "Risk",
18
+ header_title: "Minor",
19
+ header_sub_title: "Header sub-title/description.",
20
+ row_header_title: "Rare",
21
+ row_header_sub_title: "Row Header sub-title/description.",
22
+ },
23
+ {
24
+ id: 2,
25
+ position: 5,
26
+ matrix_type: "Risk",
27
+ likelihood: "D",
28
+ consequence: 2,
29
+ header_title: "Moderate",
30
+ header_sub_title: "Header sub-title/description.",
31
+ row_header_title: "Unlikely",
32
+ row_header_sub_title: "Row Header sub-title/description.",
33
+ },
34
+ {
35
+ id: 3,
36
+ position: 5,
37
+ matrix_type: "Risk",
38
+ likelihood: "C",
39
+ consequence: 3,
40
+ header_title: "Significant",
41
+ header_sub_title: "Header sub-title/description.",
42
+ row_header_title: "Possible",
43
+ row_header_sub_title: "Row Header sub-title/description.",
44
+ },
45
+ {
46
+ id: 4,
47
+ position: 5,
48
+ matrix_type: "Risk",
49
+ likelihood: "B",
50
+ consequence: 4,
51
+ header_title: "Critical",
52
+ header_sub_title: "Header sub-title/description.",
53
+ row_header_title: "Likely",
54
+ row_header_sub_title: "Row Header sub-title/description.",
55
+ },
56
+ {
57
+ id: 5,
58
+ position: 5,
59
+ matrix_type: "Risk",
60
+ likelihood: "A",
61
+ consequence: 5,
62
+ header_title: "Catastrophic",
63
+ header_sub_title: "Header sub-title/description.",
64
+ row_header_title: "Almost Certain",
65
+ row_header_sub_title: "Row Header sub-title/description.",
66
+ },
67
+ ],
68
+
69
+ matrix_values: [
70
+ {
71
+ id: 26,
72
+ matrix_id: 1,
73
+ description: "low",
74
+ score_value: 1,
75
+ colour: "green",
76
+ position: 1,
77
+ likelihood_descriptor: "E",
78
+ consequence_descriptor: 1,
79
+ response: "Business as usual",
80
+ },
81
+ {
82
+ id: 27,
83
+ matrix_id: 1,
84
+ description: "low",
85
+ score_value: 2,
86
+ colour: "green",
87
+ position: 6,
88
+ likelihood_descriptor: "D",
89
+ consequence_descriptor: 1,
90
+ response: "Business as usual",
91
+ },
92
+ {
93
+ id: 28,
94
+ matrix_id: 1,
95
+ description: "low",
96
+ score_value: 3,
97
+ colour: "green",
98
+ position: 2,
99
+ likelihood_descriptor: "E",
100
+ consequence_descriptor: 2,
101
+ response: "Business as usual",
102
+ },
103
+ {
104
+ id: 29,
105
+ matrix_id: 1,
106
+ description: "low",
107
+ score_value: 4,
108
+ colour: "green",
109
+ position: 11,
110
+ likelihood_descriptor: "C",
111
+ consequence_descriptor: 1,
112
+ response: "Business as usual",
113
+ },
114
+ {
115
+ id: 30,
116
+ matrix_id: 1,
117
+ description: "low",
118
+ score_value: 5,
119
+ colour: "green",
120
+ position: 7,
121
+ likelihood_descriptor: "D",
122
+ consequence_descriptor: 2,
123
+ response: "Business as usual",
124
+ },
125
+ {
126
+ id: 31,
127
+ matrix_id: 1,
128
+ description: "low",
129
+ score_value: 6,
130
+ colour: "green",
131
+ position: 3,
132
+ likelihood_descriptor: "E",
133
+ consequence_descriptor: 3,
134
+ response: "Business as usual",
135
+ },
136
+ {
137
+ id: 32,
138
+ matrix_id: 1,
139
+ description: "medium",
140
+ score_value: 7,
141
+ colour: "yellow",
142
+ position: 16,
143
+ likelihood_descriptor: "B",
144
+ consequence_descriptor: 1,
145
+ response: "Requires routine to periodic monitoring",
146
+ },
147
+ {
148
+ id: 33,
149
+ matrix_id: 1,
150
+ description: "medium",
151
+ score_value: 8,
152
+ colour: "yellow",
153
+ position: 12,
154
+ likelihood_descriptor: "C",
155
+ consequence_descriptor: 2,
156
+ response: "Requires routine to periodic monitoring",
157
+ },
158
+ {
159
+ id: 34,
160
+ matrix_id: 1,
161
+ description: "medium",
162
+ score_value: 9,
163
+ colour: "yellow",
164
+ position: 8,
165
+ likelihood_descriptor: "D",
166
+ consequence_descriptor: 3,
167
+ response: "Requires routine to periodic monitoring",
168
+ },
169
+ {
170
+ id: 35,
171
+ matrix_id: 1,
172
+ description: "medium",
173
+ score_value: 10,
174
+ colour: "yellow",
175
+ position: 4,
176
+ likelihood_descriptor: "E",
177
+ consequence_descriptor: 4,
178
+ response: "Requires routine to periodic monitoring",
179
+ },
180
+ {
181
+ id: 36,
182
+ matrix_id: 1,
183
+ description: "medium",
184
+ score_value: 11,
185
+ colour: "yellow",
186
+ position: 21,
187
+ likelihood_descriptor: "A",
188
+ consequence_descriptor: 1,
189
+ response: "Requires routine to periodic monitoring",
190
+ },
191
+ {
192
+ id: 37,
193
+ matrix_id: 1,
194
+ description: "high",
195
+ score_value: 12,
196
+ colour: "orange",
197
+ position: 17,
198
+ likelihood_descriptor: "B",
199
+ consequence_descriptor: 2,
200
+ response: "Risk requires targeted management plan",
201
+ },
202
+ {
203
+ id: 38,
204
+ matrix_id: 1,
205
+ description: "high",
206
+ score_value: 13,
207
+ colour: "orange",
208
+ position: 13,
209
+ likelihood_descriptor: "C",
210
+ consequence_descriptor: 3,
211
+ response: "Risk requires targeted management plan",
212
+ },
213
+ {
214
+ id: 39,
215
+ matrix_id: 1,
216
+ description: "high",
217
+ score_value: 14,
218
+ colour: "orange",
219
+ position: 9,
220
+ likelihood_descriptor: "D",
221
+ consequence_descriptor: 4,
222
+ response: "Risk requires targeted management plan",
223
+ },
224
+ {
225
+ id: 40,
226
+ matrix_id: 1,
227
+ description: "high",
228
+ score_value: 15,
229
+ colour: "orange",
230
+ position: 5,
231
+ likelihood_descriptor: "E",
232
+ consequence_descriptor: 5,
233
+ response: "Risk requires targeted management plan",
234
+ },
235
+ {
236
+ id: 41,
237
+ matrix_id: 1,
238
+ description: "high",
239
+ score_value: 16,
240
+ colour: "orange",
241
+ position: 22,
242
+ likelihood_descriptor: "A",
243
+ consequence_descriptor: 2,
244
+ response: "Risk requires targeted management plan",
245
+ },
246
+ {
247
+ id: 42,
248
+ matrix_id: 1,
249
+ description: "high",
250
+ score_value: 17,
251
+ colour: "orange",
252
+ position: 18,
253
+ likelihood_descriptor: "B",
254
+ consequence_descriptor: 3,
255
+ response: "Risk requires targeted management plan",
256
+ },
257
+ {
258
+ id: 43,
259
+ matrix_id: 1,
260
+ description: "high",
261
+ score_value: 18,
262
+ colour: "orange",
263
+ position: 14,
264
+ likelihood_descriptor: "C",
265
+ consequence_descriptor: 4,
266
+ response: "Risk requires targeted management plan",
267
+ },
268
+ {
269
+ id: 44,
270
+ matrix_id: 1,
271
+ description: "high",
272
+ score_value: 19,
273
+ colour: "orange",
274
+ position: 10,
275
+ likelihood_descriptor: "D",
276
+ consequence_descriptor: 5,
277
+ response: "Risk requires targeted management plan",
278
+ },
279
+ {
280
+ id: 45,
281
+ matrix_id: 1,
282
+ description: "extreme",
283
+ score_value: 20,
284
+ colour: "red",
285
+ position: 23,
286
+ likelihood_descriptor: "A",
287
+ consequence_descriptor: 3,
288
+ response: "Activity should not commence",
289
+ },
290
+ {
291
+ id: 46,
292
+ matrix_id: 1,
293
+ description: "extreme",
294
+ score_value: 21,
295
+ colour: "red",
296
+ position: 19,
297
+ likelihood_descriptor: "B",
298
+ consequence_descriptor: 4,
299
+ response: "Activity should not commence",
300
+ },
301
+ {
302
+ id: 47,
303
+ matrix_id: 1,
304
+ description: "extreme",
305
+ score_value: 22,
306
+ colour: "red",
307
+ position: 15,
308
+ likelihood_descriptor: "C",
309
+ consequence_descriptor: 5,
310
+ response: "Activity should not commence",
311
+ },
312
+ {
313
+ id: 48,
314
+ matrix_id: 1,
315
+ description: "extreme",
316
+ score_value: 23,
317
+ colour: "red",
318
+ position: 24,
319
+ likelihood_descriptor: "A",
320
+ consequence_descriptor: 4,
321
+ response: "Activity should not commence",
322
+ },
323
+ {
324
+ id: 49,
325
+ matrix_id: 1,
326
+ description: "extreme",
327
+ score_value: 24,
328
+ colour: "red",
329
+ position: 20,
330
+ likelihood_descriptor: "B",
331
+ consequence_descriptor: 5,
332
+ response: "Activity should not commence",
333
+ },
334
+ {
335
+ id: 50,
336
+ matrix_id: 1,
337
+ description: "extreme",
338
+ score_value: 25,
339
+ colour: "red",
340
+ position: 25,
341
+ likelihood_descriptor: "A",
342
+ consequence_descriptor: 5,
343
+ response: "Activity should not commence",
344
+ },
345
+ ],
346
+ };
@@ -0,0 +1,33 @@
1
+ export const groupObjectsByProp = <T extends Record<string, any>>(
2
+ array: T[],
3
+ prop: keyof T
4
+ ) => {
5
+ const map = new Map<T[keyof T], T[]>(
6
+ Array.from(array, (obj) => [obj[prop], []])
7
+ );
8
+
9
+ array.forEach((obj) => {
10
+ const key = obj[prop];
11
+ if (key !== undefined) {
12
+ const group = map.get(key);
13
+ if (group) {
14
+ group.push(obj);
15
+ }
16
+ }
17
+ });
18
+
19
+ return Array.from(map.values());
20
+ };
21
+
22
+ // capitalises first character of each word
23
+ export const capitaliseFirstCharacter = (stringValue: string): string =>
24
+ stringValue.replace(/\b([a-z\s])/g, (string) => string.toUpperCase());
25
+
26
+ // capitalizes entire word
27
+ export const capitaliseString = (stringValue: string): string =>
28
+ stringValue.toUpperCase();
29
+
30
+ export const callAll =
31
+ <T extends (...args: any[]) => void>(...fns: T[]) =>
32
+ (...args: Parameters<T>) =>
33
+ fns.forEach((fn) => fn && fn(...args));
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "react-data-matrix",
3
- "version": "0.2.0",
3
+ "version": "0.3.2",
4
+ "types": "./lib/types/index.d.ts",
4
5
  "private": false,
5
6
  "license": "MIT",
6
7
  "homepage": "https://bronz3beard.github.io/react-matrix",
7
- "author": "bronz3beard <exempli.gratia.webdesign@gmail.com> (https://www.heyrory.com/)",
8
+ "author": "bronz3beard <heyrory.com@gmail.com> (https://www.heyrory.com/)",
8
9
  "keywords": [
9
10
  "data",
10
11
  "risk",
@@ -16,6 +17,10 @@
16
17
  "data grid",
17
18
  "data matrix"
18
19
  ],
20
+ "engines": {
21
+ "npm": ">=8.12.0",
22
+ "node": ">=18.4.0"
23
+ },
19
24
  "main": "dist/index.js",
20
25
  "module": "dist/index.js",
21
26
  "files": [
@@ -27,7 +32,6 @@
27
32
  "url": "git+https://github.com/bronz3beard/react-matrix.git"
28
33
  },
29
34
  "description": "View structured data in a matrix table (data grid), showing a value located at an X and Y coordinate.",
30
- "dependencies": {},
31
35
  "scripts": {
32
36
  "start": "react-scripts start",
33
37
  "build": "rm -rf dist && NODE_ENV=production babel src/lib --out-dir dist --copy-files",
@@ -58,6 +62,7 @@
58
62
  "devDependencies": {
59
63
  "@babel/cli": "^7.15.7",
60
64
  "@babel/core": "^7.15.8",
65
+ "@babel/plugin-proposal-private-property-in-object": "^7.21.11",
61
66
  "@babel/preset-env": "^7.15.8",
62
67
  "@fortawesome/fontawesome-svg-core": "latest",
63
68
  "@fortawesome/free-brands-svg-icons": "latest",
@@ -65,13 +70,16 @@
65
70
  "@testing-library/jest-dom": "latest",
66
71
  "@testing-library/react": "latest",
67
72
  "@testing-library/user-event": "latest",
73
+ "@types/react": "^18.2.15",
74
+ "@types/react-dom": "^18.2.7",
75
+ "gh-pages": "latest",
68
76
  "prop-types": "latest",
69
77
  "react": "latest",
70
78
  "react-data-matrix": "latest",
71
79
  "react-dom": "latest",
72
- "react-scripts": "latest",
80
+ "react-scripts": "^5.0.1",
73
81
  "sass": "latest",
74
- "web-vitals": "latest",
75
- "gh-pages": "latest"
82
+ "typescript": "latest",
83
+ "web-vitals": "latest"
76
84
  }
77
85
  }
@@ -1,78 +0,0 @@
1
- "use strict";
2
-
3
- require("core-js/modules/es.weak-map.js");
4
- require("core-js/modules/web.dom-collections.iterator.js");
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.default = void 0;
9
- var _react = _interopRequireWildcard(require("react"));
10
- var _getStyles = require("../helpers/getStyles");
11
- var _functions = require("../utils/functions");
12
- var _context = _interopRequireDefault(require("../context"));
13
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
15
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
16
- // import "./styles/riskMatrix.scss";
17
-
18
- const MatrixHeaders = () => {
19
- const {
20
- data,
21
- thRowStyles,
22
- thTitleStyles,
23
- hasInlineStyles,
24
- thSubTitleStyles,
25
- headerPrimaryUpper,
26
- thPrimaryTitleStyles,
27
- customHeaderRowIdValue,
28
- customDynamicHeaderTitleIdValue,
29
- customDynamicSubHeaderTitleIdValue
30
- } = (0, _react.useContext)(_context.default);
31
- const headerRowStyles = (0, _getStyles.getHeaderRowStyles)(hasInlineStyles, thRowStyles);
32
- const headerTitleStyles = (0, _getStyles.getHeaderTitleStyles)(hasInlineStyles, thTitleStyles);
33
- const headerSubTitleStyles = (0, _getStyles.getHeaderSubTitleStyles)(hasInlineStyles, thSubTitleStyles);
34
- const headerPrimaryTitleStyles = (0, _getStyles.getHeaderPrimaryTitleStyles)(hasInlineStyles, thPrimaryTitleStyles);
35
- const headerPrimaryTitle = headerPrimaryUpper ? (0, _functions.capitaliseString)(data.primary_header_title) : data.primary_header_title;
36
- return /*#__PURE__*/_react.default.createElement("thead", null, /*#__PURE__*/_react.default.createElement("tr", {
37
- id: "react-matrix-blank-headers-primary-title-row"
38
- }, /*#__PURE__*/_react.default.createElement("th", {
39
- headers: "blank",
40
- colSpan: "4"
41
- }), /*#__PURE__*/_react.default.createElement("th", {
42
- style: headerPrimaryTitleStyles,
43
- id: "react-matrix-header-primary-title"
44
- }, headerPrimaryTitle), /*#__PURE__*/_react.default.createElement("th", {
45
- headers: "blank",
46
- colSpan: "2"
47
- })), /*#__PURE__*/_react.default.createElement("tr", {
48
- style: headerRowStyles,
49
- id: "react-matrix-dynamic-headers-row-".concat(customHeaderRowIdValue)
50
- }, /*#__PURE__*/_react.default.createElement("th", {
51
- headers: "blank",
52
- colSpan: "2"
53
- }), data.matrix_details.slice(0, data.matrix_size).map((column, index) => {
54
- return /*#__PURE__*/_react.default.createElement("th", {
55
- scope: "col",
56
- style: headerTitleStyles,
57
- id: "react-matrix-dynamic-column-header-title".concat(!customDynamicHeaderTitleIdValue ? "" : "-".concat(customDynamicHeaderTitleIdValue)),
58
- key: "".concat(column.id, "-").concat(index)
59
- }, column.header_title, /*#__PURE__*/_react.default.createElement("div", {
60
- style: headerSubTitleStyles,
61
- id: "react-matrix-dynamic-column-header-sub-title".concat(!customDynamicSubHeaderTitleIdValue ? "" : "-".concat(customDynamicSubHeaderTitleIdValue))
62
- }, column.header_sub_title));
63
- })));
64
- };
65
- MatrixHeaders.defaultProps = {
66
- hasInlineStyles: true,
67
- headerPrimaryUpper: true,
68
- thRowStyles: {},
69
- thTitleStyles: {},
70
- thSubTitleStyles: {},
71
- thPrimaryTitleStyles: {},
72
- matrixSizeSelected: 5,
73
- customHeaderRowIdValue: "",
74
- customDynamicHeaderTitleIdValue: "",
75
- customDynamicSubHeaderTitleIdValue: ""
76
- };
77
- var _default = MatrixHeaders;
78
- exports.default = _default;