react-data-matrix 0.3.1 → 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.
package/README.md CHANGED
@@ -12,14 +12,49 @@ The most common usage for a table like React Matrix, is to display the **likelih
12
12
 
13
13
  # Usage
14
14
 
15
- ```js
15
+ ```ts
16
16
  import { ReactMatrix } from "react-data-matrix";
17
17
 
18
- const App = () => {
18
+ const App: FC = () => {
19
19
  ...
20
20
 
21
21
  return (
22
- <ReactMatrix data={data} {...seeOtherPropsBelow} />
22
+ <ReactMatrix
23
+ {...{
24
+ matrixName: "",
25
+ matrixDescription: "",
26
+ hasTableBorder: true,
27
+ rowPrimaryUpper: true,
28
+ hasInlineStyles: true,
29
+ matrixSizeSelected: 5,
30
+ headerPrimaryUpper: true,
31
+ hasContainerStyles: true,
32
+ reverseMatrixValues: true,
33
+
34
+ tableContainerStyles: {},
35
+ tableStyles: {},
36
+
37
+ thRowStyles: {},
38
+ thTitleStyles: {},
39
+ thSubTitleStyles: {},
40
+ thPrimaryTitleStyles: {},
41
+
42
+ trRowStyles: {},
43
+ trTitleStyles: {},
44
+ trSubTitleStyles: {},
45
+ trPrimaryTitleStyles: {},
46
+
47
+ tdStyles: {},
48
+
49
+ customHeaderRowIdValue: "",
50
+ customRowDynamicIdValue: "",
51
+ customTableDataDynamicIdValue: "",
52
+ customRowHeaderDynamicIdValue: "",
53
+ customDynamicHeaderTitleIdValue: "",
54
+ customDynamicSubHeaderTitleIdValue: "",
55
+ data,
56
+ }}
57
+ />
23
58
  )
24
59
  }
25
60
  ```
@@ -29,7 +64,7 @@ const App = () => {
29
64
  - 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,
30
65
  or an example of how to construct/deconstruct your data objects from your api.
31
66
 
32
- ```js
67
+ ```ts
33
68
  const data = {
34
69
  id: 1,
35
70
  matrix_size: 5,
@@ -83,7 +118,7 @@ const App = () => {
83
118
  }
84
119
  ```
85
120
 
86
- # PropTypes
121
+ # Types
87
122
 
88
123
  ```ts
89
124
  export interface MatrixDetail {
@@ -122,34 +157,7 @@ export interface MatrixData {
122
157
  }
123
158
 
124
159
  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
- }[];
152
- };
160
+ data: MatrixData;
153
161
  hasTableBorder?: boolean;
154
162
  hasInlineStyles?: boolean;
155
163
  hasContainerStyles?: boolean;
@@ -194,8 +202,10 @@ export interface TableDataProps {
194
202
  }
195
203
  ```
196
204
 
197
- ```js
205
+ ```ts
198
206
  defaultProps = {
207
+ matrixName: "",
208
+ matrixDescription: "",
199
209
  hasTableBorder: true,
200
210
  rowPrimaryUpper: true,
201
211
  hasInlineStyles: true,
@@ -204,6 +214,9 @@ defaultProps = {
204
214
  hasContainerStyles: true,
205
215
  reverseMatrixValues: true,
206
216
 
217
+ tableContainerStyles: {},
218
+ tableStyles: {},
219
+
207
220
  thRowStyles: {},
208
221
  thTitleStyles: {},
209
222
  thSubTitleStyles: {},
@@ -216,8 +229,6 @@ defaultProps = {
216
229
 
217
230
  tdStyles: {},
218
231
 
219
- matrixName: "",
220
- matrixDescription: "",
221
232
  customHeaderRowIdValue: "",
222
233
  customRowDynamicIdValue: "",
223
234
  customTableDataDynamicIdValue: "",
@@ -1,4 +1,4 @@
1
- import React, { FC, useContext } from "react";
1
+ import React, { FC } from "react";
2
2
  import {
3
3
  getHeaderRowStyles,
4
4
  getHeaderTitleStyles,
@@ -6,23 +6,21 @@ import {
6
6
  getHeaderPrimaryTitleStyles,
7
7
  } from "../helpers/getStyles";
8
8
  import { capitaliseString } from "../utils/functions";
9
- import Context from "../context";
9
+ import { MatrixHeaderProps } from "../types";
10
10
  // import "./styles/riskMatrix.scss";
11
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
-
12
+ const MatrixHeaders: FC<MatrixHeaderProps> = ({
13
+ data,
14
+ hasInlineStyles = true,
15
+ headerPrimaryUpper = true,
16
+ thRowStyles = {},
17
+ thTitleStyles = {},
18
+ thSubTitleStyles = {},
19
+ thPrimaryTitleStyles = {},
20
+ customHeaderRowIdValue = "",
21
+ customDynamicHeaderTitleIdValue = "",
22
+ customDynamicSubHeaderTitleIdValue = "",
23
+ }: MatrixHeaderProps) => {
26
24
  const headerRowStyles = getHeaderRowStyles(hasInlineStyles, thRowStyles);
27
25
  const headerTitleStyles = getHeaderTitleStyles(
28
26
  hasInlineStyles,
@@ -1,4 +1,4 @@
1
- import React, { FC, useContext } from "react";
1
+ import React, { FC } from "react";
2
2
  import {
3
3
  getHeaderRowStyles,
4
4
  getHeaderTitleStyles,
@@ -7,25 +7,22 @@ import {
7
7
  } from "../helpers/getStyles";
8
8
  import { groupObjectsByProp, capitaliseString } from "../utils/functions";
9
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);
10
+ import { MatrixRowsProps, MatrixValue } from "../types";
28
11
 
12
+ const MatrixRows: FC<MatrixRowsProps> = ({
13
+ data,
14
+ rowPrimaryUpper = true,
15
+ hasInlineStyles = true,
16
+ reverseMatrixValues = true,
17
+ trRowStyles = {},
18
+ trTitleStyles = {},
19
+ trSubTitleStyles = {},
20
+ trPrimaryTitleStyles = {},
21
+ tdStyles = {},
22
+ customRowDynamicIdValue = "",
23
+ customRowHeaderDynamicIdValue = "",
24
+ customTableDataDynamicIdValue = "",
25
+ }: MatrixRowsProps) => {
29
26
  const valuesArray = reverseMatrixValues
30
27
  ? groupObjectsByProp(data.matrix_values, "likelihood_descriptor")
31
28
  .reverse()
@@ -113,23 +110,6 @@ const MatrixRows: FC = () => {
113
110
  );
114
111
  };
115
112
 
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
- };
113
+ MatrixRows.defaultProps = {};
134
114
 
135
115
  export default MatrixRows;
@@ -6,30 +6,30 @@ import {
6
6
  } from "../helpers/getStyles";
7
7
  import MatrixHeaders from "./MatrixHeaders";
8
8
  import MatrixRows from "./MatrixRows";
9
- import Context from "../context";
10
9
  import { ReactMatrixProps } from "../types";
11
10
 
12
- const ReactMatrix: FC<ReactMatrixProps> = ({ tableStyles = {} }) => {
13
- const {
14
- matrixName,
15
- tableStyles: contextTableStyles,
16
- hasTableBorder: contextHasTableBorder,
17
- hasInlineStyles: contextHasInlineStyles,
18
- matrixDescription,
19
- hasContainerStyles: contextHasContainerStyles,
20
- tableContainerStyles: contextTableContainerStyles,
21
- } = useContext(Context);
11
+ const ReactMatrix: FC<ReactMatrixProps> = ({
12
+ data,
13
+ matrixName,
14
+ tableStyles: contextTableStyles,
15
+ hasTableBorder: contextHasTableBorder,
16
+ hasInlineStyles: contextHasInlineStyles,
17
+ matrixDescription,
18
+ hasContainerStyles: contextHasContainerStyles,
19
+ tableContainerStyles: contextTableContainerStyles,
22
20
 
21
+ tableStyles = {},
22
+ }) => {
23
23
  const tableBorder = getTableBoarder(
24
- contextHasInlineStyles && contextHasTableBorder
24
+ !!(contextHasInlineStyles && contextHasTableBorder)
25
25
  );
26
26
  const tableElmStyles = getTableStyles(
27
27
  !!(contextHasInlineStyles && contextTableStyles),
28
28
  tableStyles
29
29
  );
30
30
  const containerStyles = getContainerStyles(
31
- contextHasInlineStyles && contextHasContainerStyles,
32
- contextTableContainerStyles
31
+ !!(contextHasInlineStyles && contextHasContainerStyles),
32
+ contextTableContainerStyles ?? {}
33
33
  );
34
34
 
35
35
  return (
@@ -37,8 +37,36 @@ const ReactMatrix: FC<ReactMatrixProps> = ({ tableStyles = {} }) => {
37
37
  <h1>{matrixName}</h1>
38
38
  <h4>{matrixDescription}</h4>
39
39
  <table id="matrix-table" style={{ ...tableElmStyles, ...tableBorder }}>
40
- <MatrixHeaders />
41
- <MatrixRows />
40
+ <MatrixHeaders
41
+ {...{
42
+ data,
43
+ hasInlineStyles: true,
44
+ headerPrimaryUpper: true,
45
+ thRowStyles: {},
46
+ thTitleStyles: {},
47
+ thSubTitleStyles: {},
48
+ thPrimaryTitleStyles: {},
49
+ customHeaderRowIdValue: "",
50
+ customDynamicHeaderTitleIdValue: "",
51
+ customDynamicSubHeaderTitleIdValue: "",
52
+ }}
53
+ />
54
+ <MatrixRows
55
+ {...{
56
+ data,
57
+ rowPrimaryUpper: true,
58
+ hasInlineStyles: true,
59
+ reverseMatrixValues: true,
60
+ trRowStyles: {},
61
+ trTitleStyles: {},
62
+ trSubTitleStyles: {},
63
+ trPrimaryTitleStyles: {},
64
+ tdStyles: {},
65
+ customRowDynamicIdValue: "",
66
+ customRowHeaderDynamicIdValue: "",
67
+ customTableDataDynamicIdValue: "",
68
+ }}
69
+ />
42
70
  </table>
43
71
  </div>
44
72
  );
@@ -34,37 +34,12 @@ export interface MatrixData {
34
34
  }
35
35
 
36
36
  export interface ReactMatrixProps {
37
- data?: {
38
- id: number;
39
- matrix_name: string;
40
- matrix_description: string;
41
- matrix_size: number;
42
- primary_header_title: string;
43
- primary_row_header_title: string;
44
- matrix_details: {
45
- id: number;
46
- likelihood: string;
47
- consequence: number;
48
- header_title: string;
49
- header_sub_title: string;
50
- row_header_title: string;
51
- row_header_sub_title: string;
52
- }[];
53
- matrix_values: {
54
- id: number;
55
- colour: string;
56
- position: number;
57
- matrix_id: number;
58
- score_value: number;
59
- description: string;
60
- response: string;
61
- likelihood_descriptor: string;
62
- consequence_descriptor: number;
63
- }[];
64
- };
37
+ data: MatrixData;
38
+ matrixName: string;
39
+ matrixDescription: string;
65
40
  hasTableBorder?: boolean;
66
- hasInlineStyles?: boolean;
67
- hasContainerStyles?: boolean;
41
+ hasInlineStyles?: boolean | undefined;
42
+ hasContainerStyles?: boolean | undefined;
68
43
  reverseMatrixValues?: boolean;
69
44
  matrixSizeSelected?: number;
70
45
  rowPrimaryUpper?: boolean;
@@ -88,6 +63,34 @@ export interface ReactMatrixProps {
88
63
  customTableDataDynamicIdValue?: string;
89
64
  }
90
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
+
91
94
  export interface TableDataProps {
92
95
  data: {
93
96
  id: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-data-matrix",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "types": "./lib/types/index.d.ts",
5
5
  "private": false,
6
6
  "license": "MIT",
@@ -1,66 +0,0 @@
1
- import { createContext } from "react";
2
- import { MatrixData } from "../types";
3
-
4
- interface ContextType {
5
- data: MatrixData;
6
- matrixName: string;
7
- matrixDescription: string;
8
- hasTableBorder: boolean;
9
- rowPrimaryUpper: boolean;
10
- hasInlineStyles: boolean;
11
- matrixSizeSelected: number;
12
- headerPrimaryUpper: boolean;
13
- hasContainerStyles: boolean;
14
- reverseMatrixValues: boolean;
15
- tableContainerStyles: Record<string, any>;
16
- tableStyles: Record<string, any>;
17
- thRowStyles: Record<string, any>;
18
- thTitleStyles: Record<string, any>;
19
- thSubTitleStyles: Record<string, any>;
20
- thPrimaryTitleStyles: Record<string, any>;
21
- trRowStyles: Record<string, any>;
22
- trTitleStyles: Record<string, any>;
23
- trSubTitleStyles: Record<string, any>;
24
- trPrimaryTitleStyles: Record<string, any>;
25
- tdStyles: Record<string, any>;
26
- customHeaderRowIdValue: string;
27
- customRowDynamicIdValue: string;
28
- customTableDataDynamicIdValue: string;
29
- customRowHeaderDynamicIdValue: string;
30
- customDynamicHeaderTitleIdValue: string;
31
- customDynamicSubHeaderTitleIdValue: string;
32
- }
33
-
34
- const Context = createContext<ContextType>({
35
- data: {} as MatrixData,
36
- matrixName: "",
37
- matrixDescription: "",
38
- hasTableBorder: true,
39
- rowPrimaryUpper: true,
40
- hasInlineStyles: true,
41
- matrixSizeSelected: 5,
42
- headerPrimaryUpper: true,
43
- hasContainerStyles: true,
44
- reverseMatrixValues: true,
45
- tableContainerStyles: {},
46
- tableStyles: {},
47
- thRowStyles: {},
48
- thTitleStyles: {},
49
- thSubTitleStyles: {},
50
- thPrimaryTitleStyles: {},
51
- trRowStyles: {},
52
- trTitleStyles: {},
53
- trSubTitleStyles: {},
54
- trPrimaryTitleStyles: {},
55
- tdStyles: {},
56
- customHeaderRowIdValue: "",
57
- customRowDynamicIdValue: "",
58
- customTableDataDynamicIdValue: "",
59
- customRowHeaderDynamicIdValue: "",
60
- customDynamicHeaderTitleIdValue: "",
61
- customDynamicSubHeaderTitleIdValue: "",
62
- });
63
-
64
- export const Provider = Context.Provider;
65
-
66
- export default Context;