react-data-matrix 0.1.9 → 0.3.1
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 +229 -164
- package/dist/components/MatrixHeaders.tsx +92 -0
- package/dist/components/MatrixRows.tsx +135 -0
- package/dist/components/ReactMatrix.tsx +47 -0
- package/dist/components/TableData.tsx +48 -0
- package/dist/context/index.tsx +66 -0
- package/dist/helpers/getStyles.ts +77 -0
- package/dist/index.ts +1 -0
- package/dist/types/index.d.ts +106 -0
- package/dist/utils/data.ts +346 -0
- package/dist/utils/functions.ts +33 -0
- package/package.json +16 -8
- package/dist/components/matrixHeaders.js +0 -78
- package/dist/components/matrixRows.js +0 -84
- package/dist/components/reactMatrix.js +0 -106
- package/dist/components/tableData.js +0 -63
- package/dist/context/index.js +0 -37
- package/dist/helpers/getStyles.js +0 -54
- package/dist/index.js +0 -13
- package/dist/utils/data.js +0 -315
- package/dist/utils/functions.js +0 -35
package/README.md
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
# React Matrix [](https://badge.fury.io/js/react-data-matrix)
|
|
2
2
|
|
|
3
|
-
[React Matrix Demo](https://react-matrix
|
|
3
|
+
[React Matrix Demo](https://bronz3beard.github.io/react-matrix)
|
|
4
4
|
|
|
5
5
|
React Matrix table shows relationships between two or more variables in a data set in grid format.
|
|
6
6
|
|
|
7
|
-
The most common usage for a table like React Matrix, is to display the
|
|
7
|
+
The most common usage for a table like React Matrix, is to display the **likelihood** and **consequence** "scores" of **risks/hazards**, this can be for anything from Corporate, Work Health Safety and Environment risks, and more.
|
|
8
8
|
|
|
9
9
|
# PR's
|
|
10
|
+
|
|
10
11
|
- Have a look at the [PR template doc](https://github.com/bronz3beard/react-matrix/blob/main/docs) for best approach to getting your pr merged.
|
|
11
12
|
|
|
12
13
|
# Usage
|
|
13
14
|
|
|
14
|
-
```js
|
|
15
|
+
```js
|
|
15
16
|
import { ReactMatrix } from "react-data-matrix";
|
|
16
17
|
|
|
17
18
|
const App = () => {
|
|
@@ -24,7 +25,8 @@ const App = () => {
|
|
|
24
25
|
```
|
|
25
26
|
|
|
26
27
|
# Expected Data Structure
|
|
27
|
-
|
|
28
|
+
|
|
29
|
+
- See [`./src/lib/utils/data.js`](https://github.com/bronz3beard/react-matrix/blob/main/src/lib/utils/data.js) for an example of the data, this can be used for testing if needed,
|
|
28
30
|
or an example of how to construct/deconstruct your data objects from your api.
|
|
29
31
|
|
|
30
32
|
```js
|
|
@@ -83,192 +85,255 @@ const App = () => {
|
|
|
83
85
|
|
|
84
86
|
# PropTypes
|
|
85
87
|
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
88
|
+
```ts
|
|
89
|
+
export interface MatrixDetail {
|
|
90
|
+
id: number;
|
|
91
|
+
position: number;
|
|
92
|
+
matrix_type: string;
|
|
93
|
+
likelihood: string;
|
|
94
|
+
consequence: number;
|
|
95
|
+
header_title: string;
|
|
96
|
+
header_sub_title: string;
|
|
97
|
+
row_header_title: string;
|
|
98
|
+
row_header_sub_title: string;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export interface MatrixValue {
|
|
102
|
+
id: number;
|
|
103
|
+
matrix_id: number;
|
|
104
|
+
description: string;
|
|
105
|
+
score_value: number;
|
|
106
|
+
colour: string;
|
|
107
|
+
position: number;
|
|
108
|
+
likelihood_descriptor: string;
|
|
109
|
+
consequence_descriptor: number;
|
|
110
|
+
response: string;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export interface MatrixData {
|
|
114
|
+
id: number;
|
|
115
|
+
matrix_size: number;
|
|
116
|
+
matrix_name: string;
|
|
117
|
+
primary_header_title: string;
|
|
118
|
+
primary_row_header_title: string;
|
|
119
|
+
matrix_description: string;
|
|
120
|
+
matrix_details: MatrixDetail[];
|
|
121
|
+
matrix_values: MatrixValue[];
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export interface ReactMatrixProps {
|
|
125
|
+
data?: {
|
|
126
|
+
id: number;
|
|
127
|
+
matrix_name: string;
|
|
128
|
+
matrix_description: string;
|
|
129
|
+
matrix_size: number;
|
|
130
|
+
primary_header_title: string;
|
|
131
|
+
primary_row_header_title: string;
|
|
132
|
+
matrix_details: {
|
|
133
|
+
id: number;
|
|
134
|
+
likelihood: string;
|
|
135
|
+
consequence: number;
|
|
136
|
+
header_title: string;
|
|
137
|
+
header_sub_title: string;
|
|
138
|
+
row_header_title: string;
|
|
139
|
+
row_header_sub_title: string;
|
|
140
|
+
}[];
|
|
141
|
+
matrix_values: {
|
|
142
|
+
id: number;
|
|
143
|
+
colour: string;
|
|
144
|
+
position: number;
|
|
145
|
+
matrix_id: number;
|
|
146
|
+
score_value: number;
|
|
147
|
+
description: string;
|
|
148
|
+
response: string;
|
|
149
|
+
likelihood_descriptor: string;
|
|
150
|
+
consequence_descriptor: number;
|
|
151
|
+
}[];
|
|
149
152
|
};
|
|
153
|
+
hasTableBorder?: boolean;
|
|
154
|
+
hasInlineStyles?: boolean;
|
|
155
|
+
hasContainerStyles?: boolean;
|
|
156
|
+
reverseMatrixValues?: boolean;
|
|
157
|
+
matrixSizeSelected?: number;
|
|
158
|
+
rowPrimaryUpper?: boolean;
|
|
159
|
+
headerPrimaryUpper?: boolean;
|
|
160
|
+
tableContainerStyles?: React.CSSProperties;
|
|
161
|
+
tableStyles?: React.CSSProperties;
|
|
162
|
+
thRowStyles?: React.CSSProperties;
|
|
163
|
+
thTitleStyles?: React.CSSProperties;
|
|
164
|
+
thSubTitleStyles?: React.CSSProperties;
|
|
165
|
+
thPrimaryTitleStyles?: React.CSSProperties;
|
|
166
|
+
trRowStyles?: React.CSSProperties;
|
|
167
|
+
trTitleStyles?: React.CSSProperties;
|
|
168
|
+
trSubTitleStyles?: React.CSSProperties;
|
|
169
|
+
trPrimaryTitleStyles?: React.CSSProperties;
|
|
170
|
+
tdStyles?: React.CSSProperties;
|
|
171
|
+
customHeaderRowIdValue?: string;
|
|
172
|
+
customDynamicHeaderTitleIdValue?: string;
|
|
173
|
+
customDynamicSubHeaderTitleIdValue?: string;
|
|
174
|
+
customRowDynamicIdValue?: string;
|
|
175
|
+
customRowHeaderDynamicIdValue?: string;
|
|
176
|
+
customTableDataDynamicIdValue?: string;
|
|
177
|
+
}
|
|
150
178
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
thSubTitleStyles: {},
|
|
163
|
-
thPrimaryTitleStyles: {},
|
|
164
|
-
|
|
165
|
-
trRowStyles: {},
|
|
166
|
-
trTitleStyles: {},
|
|
167
|
-
trSubTitleStyles: {},
|
|
168
|
-
trPrimaryTitleStyles: {},
|
|
169
|
-
|
|
170
|
-
tdStyles: {},
|
|
171
|
-
|
|
172
|
-
matrixName: "",
|
|
173
|
-
matrixDescription: "",
|
|
174
|
-
customHeaderRowIdValue: "",
|
|
175
|
-
customRowDynamicIdValue: "",
|
|
176
|
-
customTableDataDynamicIdValue: "",
|
|
177
|
-
customRowHeaderDynamicIdValue: "",
|
|
178
|
-
customDynamicHeaderTitleIdValue: "",
|
|
179
|
-
customDynamicSubHeaderTitleIdValue: "",
|
|
179
|
+
export interface TableDataProps {
|
|
180
|
+
data: {
|
|
181
|
+
id: number;
|
|
182
|
+
colour: string;
|
|
183
|
+
position: number;
|
|
184
|
+
matrix_id: number;
|
|
185
|
+
score_value: number;
|
|
186
|
+
description: string;
|
|
187
|
+
response: string;
|
|
188
|
+
likelihood_descriptor: string;
|
|
189
|
+
consequence_descriptor: number;
|
|
180
190
|
};
|
|
191
|
+
tdStyles?: React.CSSProperties;
|
|
192
|
+
hasInlineStyles?: boolean;
|
|
193
|
+
customTableDataDynamicIdValue?: string;
|
|
194
|
+
}
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
```js
|
|
198
|
+
defaultProps = {
|
|
199
|
+
hasTableBorder: true,
|
|
200
|
+
rowPrimaryUpper: true,
|
|
201
|
+
hasInlineStyles: true,
|
|
202
|
+
matrixSizeSelected: 5,
|
|
203
|
+
headerPrimaryUpper: true,
|
|
204
|
+
hasContainerStyles: true,
|
|
205
|
+
reverseMatrixValues: true,
|
|
206
|
+
|
|
207
|
+
thRowStyles: {},
|
|
208
|
+
thTitleStyles: {},
|
|
209
|
+
thSubTitleStyles: {},
|
|
210
|
+
thPrimaryTitleStyles: {},
|
|
211
|
+
|
|
212
|
+
trRowStyles: {},
|
|
213
|
+
trTitleStyles: {},
|
|
214
|
+
trSubTitleStyles: {},
|
|
215
|
+
trPrimaryTitleStyles: {},
|
|
216
|
+
|
|
217
|
+
tdStyles: {},
|
|
218
|
+
|
|
219
|
+
matrixName: "",
|
|
220
|
+
matrixDescription: "",
|
|
221
|
+
customHeaderRowIdValue: "",
|
|
222
|
+
customRowDynamicIdValue: "",
|
|
223
|
+
customTableDataDynamicIdValue: "",
|
|
224
|
+
customRowHeaderDynamicIdValue: "",
|
|
225
|
+
customDynamicHeaderTitleIdValue: "",
|
|
226
|
+
customDynamicSubHeaderTitleIdValue: "",
|
|
227
|
+
};
|
|
181
228
|
```
|
|
182
229
|
|
|
183
230
|
# Available Properties
|
|
184
231
|
|
|
185
|
-
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
232
|
+
- **hasInlineStyles**
|
|
233
|
+
- Default is true.
|
|
234
|
+
- If false all inline styles are removed.
|
|
235
|
+
|
|
236
|
+
---
|
|
237
|
+
|
|
238
|
+
- **hasTableBorder**
|
|
239
|
+
- Default is true.
|
|
240
|
+
- If false the most outer border is removed.
|
|
241
|
+
|
|
242
|
+
---
|
|
243
|
+
|
|
244
|
+
- **hasContainerStyles**
|
|
245
|
+
- Default is true.
|
|
246
|
+
- This will center the matrix in the middle of the page.
|
|
247
|
+
|
|
248
|
+
---
|
|
249
|
+
|
|
250
|
+
- **reverseMatrixValues**
|
|
251
|
+
- Default is true.
|
|
252
|
+
- When true the lowest value will be in the bottom left and the highest value will be in the top right, with all sequential values in-between.
|
|
253
|
+
- When false the values will be reversed, lowest value top left highest value bottom right.
|
|
254
|
+
|
|
255
|
+
---
|
|
256
|
+
|
|
257
|
+
- **rowPrimaryUpper**
|
|
258
|
+
- Default is true.
|
|
259
|
+
- If false string formatting will be removed.
|
|
260
|
+
|
|
261
|
+
---
|
|
262
|
+
|
|
263
|
+
- **headerPrimaryUpper**
|
|
264
|
+
- Default is true.
|
|
265
|
+
- If false string formatting will be removed.
|
|
266
|
+
|
|
267
|
+
---
|
|
268
|
+
|
|
269
|
+
- **customHeaderRowIdValue**
|
|
270
|
+
- Default is empty string.
|
|
271
|
+
- can be used to target element through id prop.
|
|
272
|
+
|
|
273
|
+
---
|
|
274
|
+
|
|
275
|
+
- **customDynamicHeaderTitleIdValue**
|
|
276
|
+
- Default is empty string.
|
|
277
|
+
- can be used to target element through id prop.
|
|
278
|
+
|
|
279
|
+
---
|
|
280
|
+
|
|
281
|
+
- **customDynamicSubHeaderTitleIdValue**
|
|
282
|
+
- Default is empty string.
|
|
283
|
+
- can be used to target element through id prop.
|
|
284
|
+
|
|
285
|
+
---
|
|
286
|
+
|
|
287
|
+
- **customRowDynamicIdValue**
|
|
288
|
+
- Default is empty string.
|
|
289
|
+
- can be used to target element through id prop.
|
|
290
|
+
|
|
291
|
+
---
|
|
292
|
+
|
|
293
|
+
- **customRowHeaderDynamicIdValue**
|
|
294
|
+
- Default is empty string.
|
|
295
|
+
- can be used to target element through id prop.
|
|
296
|
+
|
|
297
|
+
---
|
|
298
|
+
|
|
299
|
+
- **customTableDataDynamicIdValue**
|
|
300
|
+
- Default is empty string.
|
|
301
|
+
- can be used to target element through id prop.
|
|
302
|
+
|
|
303
|
+
---
|
|
246
304
|
|
|
247
305
|
# Styling Properties
|
|
248
306
|
|
|
249
307
|
### Inline
|
|
250
|
-
__These styles can be added to the current styles or,
|
|
251
|
-
if you make ```hasInlineStyles = false```, then add these values with your own styles, you can have full control over styling inline.__
|
|
252
308
|
|
|
253
|
-
|
|
309
|
+
**These styles can be added to the current styles or,
|
|
310
|
+
if you make `hasInlineStyles = false`, then add these values with your own styles, you can have full control over styling inline.**
|
|
311
|
+
|
|
312
|
+
**ReactMatrix**
|
|
313
|
+
|
|
254
314
|
- tableContainerStyles={{}}
|
|
255
315
|
- tableStyles={{}}
|
|
256
316
|
|
|
257
|
-
|
|
317
|
+
**MatrixHeaders**
|
|
318
|
+
|
|
258
319
|
- thRowStyles={{}}
|
|
259
320
|
- thTitleStyles={{}}
|
|
260
321
|
- thSubTitleStyles={{}}
|
|
261
322
|
- thPrimaryTitleStyles={{}}
|
|
262
323
|
|
|
263
|
-
|
|
324
|
+
**MatrixRows**
|
|
325
|
+
|
|
264
326
|
- trRowStyles={{}},
|
|
265
327
|
- trTitleStyles={{}},
|
|
266
328
|
- trSubTitleStyles={{}},
|
|
267
329
|
- trPrimaryTitleStyles={{}},
|
|
268
330
|
|
|
269
|
-
|
|
331
|
+
**TableData**
|
|
332
|
+
|
|
270
333
|
- tdStyles={{}},
|
|
271
334
|
|
|
272
|
-
|
|
335
|
+
---
|
|
336
|
+
|
|
273
337
|
# Create React App
|
|
338
|
+
|
|
274
339
|
- This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import React, { FC, useContext } from "react";
|
|
2
|
+
import {
|
|
3
|
+
getHeaderRowStyles,
|
|
4
|
+
getHeaderTitleStyles,
|
|
5
|
+
getHeaderSubTitleStyles,
|
|
6
|
+
getHeaderPrimaryTitleStyles,
|
|
7
|
+
} from "../helpers/getStyles";
|
|
8
|
+
import { capitaliseString } from "../utils/functions";
|
|
9
|
+
import Context from "../context";
|
|
10
|
+
// import "./styles/riskMatrix.scss";
|
|
11
|
+
|
|
12
|
+
const MatrixHeaders: FC = () => {
|
|
13
|
+
const {
|
|
14
|
+
data,
|
|
15
|
+
hasInlineStyles = true,
|
|
16
|
+
headerPrimaryUpper = true,
|
|
17
|
+
thRowStyles = {},
|
|
18
|
+
thTitleStyles = {},
|
|
19
|
+
thSubTitleStyles = {},
|
|
20
|
+
thPrimaryTitleStyles = {},
|
|
21
|
+
customHeaderRowIdValue = "",
|
|
22
|
+
customDynamicHeaderTitleIdValue = "",
|
|
23
|
+
customDynamicSubHeaderTitleIdValue = "",
|
|
24
|
+
} = useContext(Context);
|
|
25
|
+
|
|
26
|
+
const headerRowStyles = getHeaderRowStyles(hasInlineStyles, thRowStyles);
|
|
27
|
+
const headerTitleStyles = getHeaderTitleStyles(
|
|
28
|
+
hasInlineStyles,
|
|
29
|
+
thTitleStyles
|
|
30
|
+
);
|
|
31
|
+
const headerSubTitleStyles = getHeaderSubTitleStyles(
|
|
32
|
+
hasInlineStyles,
|
|
33
|
+
thSubTitleStyles
|
|
34
|
+
);
|
|
35
|
+
const headerPrimaryTitleStyles = getHeaderPrimaryTitleStyles(
|
|
36
|
+
hasInlineStyles,
|
|
37
|
+
thPrimaryTitleStyles
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
const headerPrimaryTitle = !headerPrimaryUpper
|
|
41
|
+
? capitaliseString(data?.primary_header_title)
|
|
42
|
+
: data?.primary_header_title;
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<thead>
|
|
46
|
+
<tr id="react-matrix-blank-headers-primary-title-row">
|
|
47
|
+
<th headers="blank" colSpan={4}></th>
|
|
48
|
+
<th
|
|
49
|
+
style={headerPrimaryTitleStyles}
|
|
50
|
+
id="react-matrix-header-primary-title"
|
|
51
|
+
>
|
|
52
|
+
{headerPrimaryTitle}
|
|
53
|
+
</th>
|
|
54
|
+
<th headers="blank" colSpan={2}></th>
|
|
55
|
+
</tr>
|
|
56
|
+
<tr
|
|
57
|
+
style={headerRowStyles}
|
|
58
|
+
id={`react-matrix-dynamic-headers-row-${customHeaderRowIdValue}`}
|
|
59
|
+
>
|
|
60
|
+
<th headers="blank" colSpan={2}></th>
|
|
61
|
+
{data.matrix_details.slice(0, data.matrix_size).map((column, index) => {
|
|
62
|
+
return (
|
|
63
|
+
<th
|
|
64
|
+
scope="col"
|
|
65
|
+
style={headerTitleStyles}
|
|
66
|
+
id={`react-matrix-dynamic-column-header-title${
|
|
67
|
+
!customDynamicHeaderTitleIdValue
|
|
68
|
+
? ""
|
|
69
|
+
: `-${customDynamicHeaderTitleIdValue}`
|
|
70
|
+
}`}
|
|
71
|
+
key={`${column.id}-${index}`}
|
|
72
|
+
>
|
|
73
|
+
{column.header_title}
|
|
74
|
+
<div
|
|
75
|
+
style={headerSubTitleStyles}
|
|
76
|
+
id={`react-matrix-dynamic-column-header-sub-title${
|
|
77
|
+
!customDynamicSubHeaderTitleIdValue
|
|
78
|
+
? ""
|
|
79
|
+
: `-${customDynamicSubHeaderTitleIdValue}`
|
|
80
|
+
}`}
|
|
81
|
+
>
|
|
82
|
+
{column.header_sub_title}
|
|
83
|
+
</div>
|
|
84
|
+
</th>
|
|
85
|
+
);
|
|
86
|
+
})}
|
|
87
|
+
</tr>
|
|
88
|
+
</thead>
|
|
89
|
+
);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
export default MatrixHeaders;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import React, { FC, useContext } from "react";
|
|
2
|
+
import {
|
|
3
|
+
getHeaderRowStyles,
|
|
4
|
+
getHeaderTitleStyles,
|
|
5
|
+
getHeaderSubTitleStyles,
|
|
6
|
+
getHeaderPrimaryTitleStyles,
|
|
7
|
+
} from "../helpers/getStyles";
|
|
8
|
+
import { groupObjectsByProp, capitaliseString } from "../utils/functions";
|
|
9
|
+
import TableData from "./TableData";
|
|
10
|
+
import Context from "../context";
|
|
11
|
+
import { MatrixValue } from "../types";
|
|
12
|
+
|
|
13
|
+
const MatrixRows: FC = () => {
|
|
14
|
+
const {
|
|
15
|
+
data,
|
|
16
|
+
rowPrimaryUpper = true,
|
|
17
|
+
hasInlineStyles = true,
|
|
18
|
+
reverseMatrixValues = true,
|
|
19
|
+
trRowStyles = {},
|
|
20
|
+
trTitleStyles = {},
|
|
21
|
+
trSubTitleStyles = {},
|
|
22
|
+
trPrimaryTitleStyles = {},
|
|
23
|
+
tdStyles = {},
|
|
24
|
+
customRowDynamicIdValue = "",
|
|
25
|
+
customRowHeaderDynamicIdValue = "",
|
|
26
|
+
customTableDataDynamicIdValue = "",
|
|
27
|
+
} = useContext(Context);
|
|
28
|
+
|
|
29
|
+
const valuesArray = reverseMatrixValues
|
|
30
|
+
? groupObjectsByProp(data.matrix_values, "likelihood_descriptor")
|
|
31
|
+
.reverse()
|
|
32
|
+
.slice(0, data.matrix_size)
|
|
33
|
+
: groupObjectsByProp(data.matrix_values, "likelihood_descriptor").slice(
|
|
34
|
+
0,
|
|
35
|
+
data.matrix_size
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
const tableRowStyles = getHeaderRowStyles(hasInlineStyles, trRowStyles);
|
|
39
|
+
const tableRowHeaderTitleStyles = getHeaderTitleStyles(
|
|
40
|
+
hasInlineStyles,
|
|
41
|
+
trTitleStyles
|
|
42
|
+
);
|
|
43
|
+
const tableRowHeaderSubTitleStyles = getHeaderSubTitleStyles(
|
|
44
|
+
hasInlineStyles,
|
|
45
|
+
trSubTitleStyles
|
|
46
|
+
);
|
|
47
|
+
const rowHeaderPrimaryTitleStyles = getHeaderPrimaryTitleStyles(
|
|
48
|
+
hasInlineStyles,
|
|
49
|
+
trPrimaryTitleStyles
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
const rowPrimaryTitle = rowPrimaryUpper
|
|
53
|
+
? capitaliseString(data.primary_row_header_title)
|
|
54
|
+
: data.primary_row_header_title;
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<tbody>
|
|
58
|
+
<tr id="react-matrix-row-primary-title">
|
|
59
|
+
<th scope="row" rowSpan={6} style={rowHeaderPrimaryTitleStyles}>
|
|
60
|
+
{rowPrimaryTitle}
|
|
61
|
+
</th>
|
|
62
|
+
</tr>
|
|
63
|
+
{valuesArray.map((row, index) => {
|
|
64
|
+
const rowHeaderOrder = reverseMatrixValues
|
|
65
|
+
? data.matrix_size - (index + 1)
|
|
66
|
+
: index;
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<tr
|
|
70
|
+
style={tableRowStyles}
|
|
71
|
+
key={`row-${index}`}
|
|
72
|
+
id={`react-matrix-dynamic-rows-${
|
|
73
|
+
data.matrix_details[rowHeaderOrder]?.row_header_title
|
|
74
|
+
}-${data.matrix_details[rowHeaderOrder]?.row_header_sub_title}${
|
|
75
|
+
!customRowDynamicIdValue ? "" : `-${customRowDynamicIdValue}`
|
|
76
|
+
}`}
|
|
77
|
+
>
|
|
78
|
+
<th
|
|
79
|
+
scope="row"
|
|
80
|
+
style={tableRowHeaderTitleStyles}
|
|
81
|
+
id={`react-matrix-dynamic-rows-${
|
|
82
|
+
data.matrix_details[rowHeaderOrder]?.row_header_title
|
|
83
|
+
}-${data.matrix_details[rowHeaderOrder]?.row_header_sub_title}${
|
|
84
|
+
!customRowHeaderDynamicIdValue
|
|
85
|
+
? ""
|
|
86
|
+
: `-${customRowHeaderDynamicIdValue}`
|
|
87
|
+
}`}
|
|
88
|
+
>
|
|
89
|
+
{data.matrix_details[rowHeaderOrder]?.row_header_title}
|
|
90
|
+
<div style={tableRowHeaderSubTitleStyles}>
|
|
91
|
+
{data.matrix_details[rowHeaderOrder]?.row_header_sub_title}
|
|
92
|
+
</div>
|
|
93
|
+
</th>
|
|
94
|
+
{row
|
|
95
|
+
.slice(0, data.matrix_size)
|
|
96
|
+
.map((item: MatrixValue, index: number) => {
|
|
97
|
+
return (
|
|
98
|
+
<TableData
|
|
99
|
+
data={item}
|
|
100
|
+
tdStyles={tdStyles}
|
|
101
|
+
key={`${item.id}-${index}`}
|
|
102
|
+
hasInlineStyles={hasInlineStyles}
|
|
103
|
+
customTableDataDynamicIdValue={
|
|
104
|
+
customTableDataDynamicIdValue
|
|
105
|
+
}
|
|
106
|
+
/>
|
|
107
|
+
);
|
|
108
|
+
})}
|
|
109
|
+
</tr>
|
|
110
|
+
);
|
|
111
|
+
})}
|
|
112
|
+
</tbody>
|
|
113
|
+
);
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
MatrixRows.defaultProps = {
|
|
117
|
+
rowPrimaryUpper: true,
|
|
118
|
+
hasInlineStyles: true,
|
|
119
|
+
reverseMatrixValues: true,
|
|
120
|
+
|
|
121
|
+
trRowStyles: {},
|
|
122
|
+
trTitleStyles: {},
|
|
123
|
+
trSubTitleStyles: {},
|
|
124
|
+
trPrimaryTitleStyles: {},
|
|
125
|
+
|
|
126
|
+
tdStyles: {},
|
|
127
|
+
|
|
128
|
+
matrixSizeSelected: 5,
|
|
129
|
+
|
|
130
|
+
customRowDynamicIdValue: "",
|
|
131
|
+
customRowHeaderDynamicIdValue: "",
|
|
132
|
+
customTableDataDynamicIdValue: "",
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
export default MatrixRows;
|