@proteinjs/ui 2.0.2 → 2.0.3

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 (80) hide show
  1. package/.eslintrc.js +20 -0
  2. package/.prettierignore +3 -0
  3. package/.prettierrc +8 -0
  4. package/CHANGELOG.md +10 -19
  5. package/LICENSE +21 -0
  6. package/dist/generated/index.js +1 -1
  7. package/dist/generated/index.js.map +1 -1
  8. package/dist/src/container/AccountIconButton.d.ts +1 -1
  9. package/dist/src/container/AccountIconButton.d.ts.map +1 -1
  10. package/dist/src/container/AccountIconButton.js +13 -6
  11. package/dist/src/container/AccountIconButton.js.map +1 -1
  12. package/dist/src/container/NavMenu.d.ts.map +1 -1
  13. package/dist/src/container/NavMenu.js +9 -9
  14. package/dist/src/container/NavMenu.js.map +1 -1
  15. package/dist/src/container/PageContainer.d.ts +1 -1
  16. package/dist/src/container/PageContainer.d.ts.map +1 -1
  17. package/dist/src/container/PageContainer.js +12 -7
  18. package/dist/src/container/PageContainer.js.map +1 -1
  19. package/dist/src/form/Field.d.ts.map +1 -1
  20. package/dist/src/form/Field.js +4 -2
  21. package/dist/src/form/Field.js.map +1 -1
  22. package/dist/src/form/Form.d.ts.map +1 -1
  23. package/dist/src/form/Form.js +75 -40
  24. package/dist/src/form/Form.js.map +1 -1
  25. package/dist/src/form/FormButton.d.ts.map +1 -1
  26. package/dist/src/form/FormButton.js +1 -1
  27. package/dist/src/form/FormButton.js.map +1 -1
  28. package/dist/src/form/container/FormPage.d.ts.map +1 -1
  29. package/dist/src/form/container/FormPage.js.map +1 -1
  30. package/dist/src/form/container/FormPaper.js +1 -1
  31. package/dist/src/form/container/FormPaper.js.map +1 -1
  32. package/dist/src/form/fields/TextField.d.ts.map +1 -1
  33. package/dist/src/form/fields/TextField.js +8 -6
  34. package/dist/src/form/fields/TextField.js.map +1 -1
  35. package/dist/src/list/NestedList.d.ts.map +1 -1
  36. package/dist/src/list/NestedList.js +10 -10
  37. package/dist/src/list/NestedList.js.map +1 -1
  38. package/dist/src/router/Page.d.ts.map +1 -1
  39. package/dist/src/router/Router.d.ts.map +1 -1
  40. package/dist/src/router/Router.js +11 -7
  41. package/dist/src/router/Router.js.map +1 -1
  42. package/dist/src/router/createUrlParams.d.ts.map +1 -1
  43. package/dist/src/router/createUrlParams.js +2 -1
  44. package/dist/src/router/createUrlParams.js.map +1 -1
  45. package/dist/src/router/withRouter.d.ts.map +1 -1
  46. package/dist/src/router/withRouter.js +1 -1
  47. package/dist/src/router/withRouter.js.map +1 -1
  48. package/dist/src/table/Table.d.ts +1 -1
  49. package/dist/src/table/Table.d.ts.map +1 -1
  50. package/dist/src/table/Table.js +31 -23
  51. package/dist/src/table/Table.js.map +1 -1
  52. package/dist/src/table/TableButton.d.ts.map +1 -1
  53. package/dist/src/table/TableLoader.d.ts.map +1 -1
  54. package/dist/src/table/TableToolbar.d.ts.map +1 -1
  55. package/dist/src/table/TableToolbar.js +10 -7
  56. package/dist/src/table/TableToolbar.js.map +1 -1
  57. package/generated/index.ts +1 -1
  58. package/index.ts +1 -1
  59. package/jest.config.js +8 -17
  60. package/package.json +56 -50
  61. package/src/container/AccountIconButton.tsx +103 -102
  62. package/src/container/NavMenu.tsx +20 -21
  63. package/src/container/PageContainer.tsx +110 -80
  64. package/src/form/Field.tsx +42 -35
  65. package/src/form/Form.tsx +370 -351
  66. package/src/form/FormButton.tsx +24 -22
  67. package/src/form/FunctionalForm.tsx +15 -15
  68. package/src/form/container/FormPage.tsx +16 -18
  69. package/src/form/container/FormPaper.tsx +12 -12
  70. package/src/form/fields/TextField.tsx +63 -61
  71. package/src/list/NestedList.tsx +18 -21
  72. package/src/router/Page.ts +18 -18
  73. package/src/router/Router.tsx +66 -52
  74. package/src/router/createUrlParams.ts +8 -7
  75. package/src/router/withRouter.tsx +6 -11
  76. package/src/table/Table.tsx +96 -80
  77. package/src/table/TableButton.ts +9 -9
  78. package/src/table/TableLoader.ts +6 -6
  79. package/src/table/TableToolbar.tsx +52 -59
  80. package/tsconfig.json +17 -17
package/src/form/Form.tsx CHANGED
@@ -6,400 +6,419 @@ import { FormButton, FormButtons } from './FormButton';
6
6
  import { withRouter, WithRouterProps } from '../router/withRouter';
7
7
 
8
8
  export type FormProps<F extends Fields, B extends FormButtons<F>> = {
9
- name?: string,
10
- documentation?: React.ComponentType,
11
- createFields: () => F,
12
- fieldLayout?: (keyof F)[]|(keyof F)[][],
13
- buttons: B,
14
- onLoad?: (fields: F, buttons: B) => Promise<void>,
15
- onLoadProgressMessage?: string
16
- } & Partial<WithRouterProps>
9
+ name?: string;
10
+ documentation?: React.ComponentType;
11
+ createFields: () => F;
12
+ fieldLayout?: (keyof F)[] | (keyof F)[][];
13
+ buttons: B;
14
+ onLoad?: (fields: F, buttons: B) => Promise<void>;
15
+ onLoadProgressMessage?: string;
16
+ } & Partial<WithRouterProps>;
17
17
 
18
18
  export type FormState<F extends Fields> = {
19
- status?: { message?: string, isError?: boolean },
20
- fields: F,
21
- progress?: { visible?: boolean, message?: string },
22
- onLoadExecuted?: boolean
23
- }
24
-
25
- export class FormComponent<F extends Fields, B extends FormButtons<F>> extends React.Component<FormProps<F, B>, FormState<F>> {
26
- constructor(props: FormProps<F, B>) {
27
- super(props);
28
- this.state = { fields: props.createFields() };
29
- }
30
-
31
- componentDidMount() {
32
- if (this.state.onLoadExecuted)
33
- return;
34
-
35
- this.onLoad();
19
+ status?: { message?: string; isError?: boolean };
20
+ fields: F;
21
+ progress?: { visible?: boolean; message?: string };
22
+ onLoadExecuted?: boolean;
23
+ };
24
+
25
+ export class FormComponent<F extends Fields, B extends FormButtons<F>> extends React.Component<
26
+ FormProps<F, B>,
27
+ FormState<F>
28
+ > {
29
+ constructor(props: FormProps<F, B>) {
30
+ super(props);
31
+ this.state = { fields: props.createFields() };
32
+ }
33
+
34
+ componentDidMount() {
35
+ if (this.state.onLoadExecuted) {
36
+ return;
36
37
  }
37
38
 
38
- private async onLoad() {
39
- this.setState({ progress: { visible: true, message: this.props.onLoadProgressMessage }});
40
- const newFields = this.props.createFields();
41
- try {
42
- for (const fieldPropertyName in newFields) {
43
- const field = newFields[fieldPropertyName].field;
44
- if (!field)
45
- continue;
46
-
47
- if (field.onLoad)
48
- await field.onLoad(newFields);
39
+ this.onLoad();
40
+ }
41
+
42
+ private async onLoad() {
43
+ this.setState({ progress: { visible: true, message: this.props.onLoadProgressMessage } });
44
+ const newFields = this.props.createFields();
45
+ try {
46
+ for (const fieldPropertyName in newFields) {
47
+ const field = newFields[fieldPropertyName].field;
48
+ if (!field) {
49
+ continue;
50
+ }
49
51
 
50
- if (!field.accessibility)
51
- field.accessibility = {};
52
- }
52
+ if (field.onLoad) {
53
+ await field.onLoad(newFields);
54
+ }
53
55
 
54
- if (this.props.onLoad)
55
- await this.props.onLoad(newFields, this.props.buttons);
56
- } catch (error) {
57
- console.error(`Failed while running onLoad functions`, error);
56
+ if (!field.accessibility) {
57
+ field.accessibility = {};
58
58
  }
59
+ }
59
60
 
60
- this.setState({
61
- status: {},
62
- fields: newFields,
63
- progress: { visible: false },
64
- onLoadExecuted: true
65
- });
61
+ if (this.props.onLoad) {
62
+ await this.props.onLoad(newFields, this.props.buttons);
63
+ }
64
+ } catch (error) {
65
+ console.error(`Failed while running onLoad functions`, error);
66
66
  }
67
67
 
68
- private async onChange(field: Field<any, any>, value: any, setFieldStatus: (message: string, isError: boolean) => void) {
69
- field.value = value;
70
- if (field.onChange) {
71
- try {
72
- await field.onChange(field.value, this.state.fields, setFieldStatus);
73
- } catch (error) {
74
- console.error(`Failed while running onChange for field: ${field.name}`, error);
75
- }
76
- }
77
-
78
- this.setState(this.state);
68
+ this.setState({
69
+ status: {},
70
+ fields: newFields,
71
+ progress: { visible: false },
72
+ onLoadExecuted: true,
73
+ });
74
+ }
75
+
76
+ private async onChange(
77
+ field: Field<any, any>,
78
+ value: any,
79
+ setFieldStatus: (message: string, isError: boolean) => void
80
+ ) {
81
+ field.value = value;
82
+ if (field.onChange) {
83
+ try {
84
+ await field.onChange(field.value, this.state.fields, setFieldStatus);
85
+ } catch (error) {
86
+ console.error(`Failed while running onChange for field: ${field.name}`, error);
87
+ }
79
88
  }
80
89
 
81
- private async onClick(button: FormButton<any>) {
82
- if (button.onClick) {
83
- this.setState({ progress: { visible: true, message: button.progressMessage ? button.progressMessage(this.state.fields) : undefined }});
84
- try {
85
- const successMessage = await button.onClick(this.state.fields, this.props.buttons);
86
- if (successMessage)
87
- this.setState({ status: { message: successMessage, isError: false}});
88
- } catch (error: any) {
89
- this.setState({ status: { message: error.message, isError: true}});
90
- console.error(`Error when clicking button: ${button.name}`, error);
91
- }
92
- this.setState({ progress: { visible: false }});
90
+ this.setState(this.state);
91
+ }
92
+
93
+ private async onClick(button: FormButton<any>) {
94
+ if (button.onClick) {
95
+ this.setState({
96
+ progress: {
97
+ visible: true,
98
+ message: button.progressMessage ? button.progressMessage(this.state.fields) : undefined,
99
+ },
100
+ });
101
+ try {
102
+ const successMessage = await button.onClick(this.state.fields, this.props.buttons);
103
+ if (successMessage) {
104
+ this.setState({ status: { message: successMessage, isError: false } });
93
105
  }
106
+ } catch (error: any) {
107
+ this.setState({ status: { message: error.message, isError: true } });
108
+ console.error(`Error when clicking button: ${button.name}`, error);
109
+ }
110
+ this.setState({ progress: { visible: false } });
111
+ }
94
112
 
95
- if (button.redirect) {
96
- const redirect = await button.redirect(this.state.fields, this.props.buttons);
97
- let path = redirect.path;
98
- if (redirect.props)
99
- path += `?${queryString.stringify(redirect.props)}`;
100
-
101
- if (this.props.navigate)
102
- this.props.navigate(path);
113
+ if (button.redirect) {
114
+ const redirect = await button.redirect(this.state.fields, this.props.buttons);
115
+ let path = redirect.path;
116
+ if (redirect.props) {
117
+ path += `?${queryString.stringify(redirect.props)}`;
118
+ }
103
119
 
104
- return;
105
- }
120
+ if (this.props.navigate) {
121
+ this.props.navigate(path);
122
+ }
106
123
 
107
- if (button.clearFormOnClick)
108
- await this.onLoad();
124
+ return;
109
125
  }
110
126
 
111
- render() {
112
- return (
113
- <Container sx={{ padding: 0 }} maxWidth={this.getContainerMaxWidth()}>
114
- <form autoComplete='off'>
115
- <Grid container>
116
- {this.Title()}
117
- {this.Documentation()}
118
- {this.Status()}
119
- {this.Fields()}
120
- {this.Progress()}
121
- {this.Buttons()}
122
- </Grid>
123
- </form>
124
- </Container>
125
- );
127
+ if (button.clearFormOnClick) {
128
+ await this.onLoad();
126
129
  }
130
+ }
131
+
132
+ render() {
133
+ return (
134
+ <Container sx={{ padding: 0 }} maxWidth={this.getContainerMaxWidth()}>
135
+ <form autoComplete='off'>
136
+ <Grid container>
137
+ {this.Title()}
138
+ {this.Documentation()}
139
+ {this.Status()}
140
+ {this.Fields()}
141
+ {this.Progress()}
142
+ {this.Buttons()}
143
+ </Grid>
144
+ </form>
145
+ </Container>
146
+ );
147
+ }
148
+
149
+ private getContainerMaxWidth(): 'xs' | 'sm' {
150
+ if (this.props.fieldLayout) {
151
+ // TODO validate that fields are not hidden
152
+ if (this.props.fieldLayout.length < 2) {
153
+ return 'xs';
154
+ }
127
155
 
128
- private getContainerMaxWidth(): 'xs'|'sm' {
129
- if (this.props.fieldLayout) { // TODO validate that fields are not hidden
130
- if (this.props.fieldLayout.length < 2)
131
- return 'xs';
132
-
133
- for (const row of this.props.fieldLayout) {
134
- if ((row as string[]).length > 1)
135
- return 'sm';
136
- }
137
- } else {
138
- const rows: boolean[] = [];
139
- for (const fieldPropertyName in this.state.fields) {
140
- const field = this.state.fields[fieldPropertyName].field;
141
- if (field.accessibility?.hidden)
142
- continue;
143
-
144
- if (!field.layout)
145
- continue;
156
+ for (const row of this.props.fieldLayout) {
157
+ if ((row as string[]).length > 1) {
158
+ return 'sm';
159
+ }
160
+ }
161
+ } else {
162
+ const rows: boolean[] = [];
163
+ for (const fieldPropertyName in this.state.fields) {
164
+ const field = this.state.fields[fieldPropertyName].field;
165
+ if (field.accessibility?.hidden) {
166
+ continue;
167
+ }
146
168
 
147
- if (rows[field.layout.row])
148
- return 'sm';
169
+ if (!field.layout) {
170
+ continue;
171
+ }
149
172
 
150
- rows[field.layout.row] = true;
151
- }
173
+ if (rows[field.layout.row]) {
174
+ return 'sm';
152
175
  }
153
176
 
154
- return 'xs';
177
+ rows[field.layout.row] = true;
178
+ }
155
179
  }
156
180
 
157
- private Title() {
158
- if (!this.props.name)
159
- return null;
181
+ return 'xs';
182
+ }
160
183
 
161
- return (
162
- <Grid
163
- container
164
- xs={12}
165
- justifyContent='flex-start'
166
- alignItems='flex-start'
167
- sx={(theme) => ({
168
- marginTop: theme.spacing(1),
169
- marginBottom: theme.spacing(3),
170
- })}
171
- >
172
- <Typography
173
- variant='h5'
174
- >
175
- {this.props.name}
176
- </Typography>
177
- </Grid>
178
- );
184
+ private Title() {
185
+ if (!this.props.name) {
186
+ return null;
179
187
  }
180
188
 
181
- private Documentation() {
182
- if (!this.props.documentation)
183
- return null;
184
-
185
- return (
186
- <Grid
187
- container
188
- xs={12}
189
- justifyContent='flex-start'
190
- alignItems='flex-start'
191
- >
192
- <Container>
193
- <this.props.documentation />
194
- </Container>
195
- </Grid>
196
- );
189
+ return (
190
+ <Grid
191
+ container
192
+ xs={12}
193
+ justifyContent='flex-start'
194
+ alignItems='flex-start'
195
+ sx={(theme) => ({
196
+ marginTop: theme.spacing(1),
197
+ marginBottom: theme.spacing(3),
198
+ })}
199
+ >
200
+ <Typography variant='h5'>{this.props.name}</Typography>
201
+ </Grid>
202
+ );
203
+ }
204
+
205
+ private Documentation() {
206
+ if (!this.props.documentation) {
207
+ return null;
197
208
  }
198
-
199
- private Status() {
200
- if (!this.state.status || !this.state.status.message)
201
- return null;
202
209
 
203
- return (
204
- <Grid
205
- container
206
- xs={12}
207
- >
208
- <Container
209
- sx={(theme) => ({
210
- marginBottom: theme.spacing(1),
211
- })}
212
- >
213
- <Typography
214
- variant='subtitle1'
215
- color={this.state.status.isError ? 'error' : 'primary'}
216
- >
217
- {this.state.status.message}
218
- </Typography>
219
- </Container>
220
- </Grid>
221
- );
210
+ return (
211
+ <Grid container xs={12} justifyContent='flex-start' alignItems='flex-start'>
212
+ <Container>
213
+ <this.props.documentation />
214
+ </Container>
215
+ </Grid>
216
+ );
217
+ }
218
+
219
+ private Status() {
220
+ if (!this.state.status || !this.state.status.message) {
221
+ return null;
222
222
  }
223
-
224
- private Fields() {
225
- return (
226
- <Grid
227
- container
228
- direction='column'
229
- xs={12}
223
+
224
+ return (
225
+ <Grid container xs={12}>
226
+ <Container
227
+ sx={(theme) => ({
228
+ marginBottom: theme.spacing(1),
229
+ })}
230
+ >
231
+ <Typography variant='subtitle1' color={this.state.status.isError ? 'error' : 'primary'}>
232
+ {this.state.status.message}
233
+ </Typography>
234
+ </Container>
235
+ </Grid>
236
+ );
237
+ }
238
+
239
+ private Fields() {
240
+ return (
241
+ <Grid container direction='column' xs={12}>
242
+ {this.getFieldRows().map((fieldComponents, index) => {
243
+ if (!this.isFieldRowVisible(fieldComponents)) {
244
+ return null;
245
+ }
246
+
247
+ return (
248
+ <Grid
249
+ container
250
+ spacing={3}
251
+ alignItems='center'
252
+ sx={(theme) => ({
253
+ flexGrow: 1,
254
+ marginBottom: theme.spacing(3),
255
+ })}
256
+ key={index}
230
257
  >
231
- {
232
- this.getFieldRows().map((fieldComponents, index) => {
233
- if (!this.isFieldRowVisible(fieldComponents))
234
- return null;
235
-
236
- return (
237
- <Grid
238
- container
239
- spacing={3}
240
- alignItems='center'
241
- sx={(theme) => ({
242
- flexGrow: 1,
243
- marginBottom: theme.spacing(3),
244
- })}
245
- key={index}
246
- >
247
- {
248
- fieldComponents.filter((fieldComponent) => {
249
- if (fieldComponent.field.accessibility?.hidden)
250
- return false;
251
-
252
- return true;
253
- }).map((fieldComponent) => (
254
- <Grid item xs key={fieldComponent.field.name}>
255
- <fieldComponent.component
256
- field={fieldComponent.field}
257
- onChange={this.onChange.bind(this)}
258
- />
259
- </Grid>
260
- ))
261
- }
262
- </Grid>
263
- );
264
- })
265
- }
258
+ {fieldComponents
259
+ .filter((fieldComponent) => {
260
+ if (fieldComponent.field.accessibility?.hidden) {
261
+ return false;
262
+ }
263
+
264
+ return true;
265
+ })
266
+ .map((fieldComponent) => (
267
+ <Grid item xs key={fieldComponent.field.name}>
268
+ <fieldComponent.component field={fieldComponent.field} onChange={this.onChange.bind(this)} />
269
+ </Grid>
270
+ ))}
266
271
  </Grid>
267
- );
272
+ );
273
+ })}
274
+ </Grid>
275
+ );
276
+ }
277
+
278
+ private getFieldRows(): FieldComponent<any, any>[][] {
279
+ const rows: FieldComponent<any, any>[][] = [];
280
+ if (!this.state.fields) {
281
+ return rows;
268
282
  }
269
-
270
- private getFieldRows(): FieldComponent<any, any>[][] {
271
- const rows: FieldComponent<any, any>[][] = [];
272
- if (!this.state.fields)
273
- return rows;
274
-
275
- if (this.props.fieldLayout) {
276
- if (typeof this.props.fieldLayout[0] === 'string') {
277
- for (let i = 0; i < this.props.fieldLayout.length; i++) {
278
- const fieldPropertyName = this.props.fieldLayout[i] as string;
279
- const fieldComponent = this.state.fields[fieldPropertyName];
280
- fieldComponent.field.layout = { row: i, width: 12 };
281
- rows.push([fieldComponent]);
282
- }
283
- } else {
284
- for (let i = 0; i < this.props.fieldLayout.length; i++) {
285
- const row = this.props.fieldLayout[i] as string[];
286
- const columns = row.length;
287
- if (columns > 6)
288
- throw new Error(`When using FormProps.fieldLayout, the maximum number of fields per row is 6, provided: ${columns}. For more granular layout control use Field.layout`);
289
-
290
- const currentRow: FieldComponent<any, any>[] = [];
291
- for (const fieldPropertyName of row ) {
292
- const fieldComponent = this.state.fields[fieldPropertyName];
293
- fieldComponent.field.layout = { row: i, width: columns == 5 ? 2 : 12/columns as 1 };
294
- currentRow.push(fieldComponent);
295
- }
296
- rows.push(currentRow);
297
- }
298
- }
283
+
284
+ if (this.props.fieldLayout) {
285
+ if (typeof this.props.fieldLayout[0] === 'string') {
286
+ for (let i = 0; i < this.props.fieldLayout.length; i++) {
287
+ const fieldPropertyName = this.props.fieldLayout[i] as string;
288
+ const fieldComponent = this.state.fields[fieldPropertyName];
289
+ fieldComponent.field.layout = { row: i, width: 12 };
290
+ rows.push([fieldComponent]);
291
+ }
292
+ } else {
293
+ for (let i = 0; i < this.props.fieldLayout.length; i++) {
294
+ const row = this.props.fieldLayout[i] as string[];
295
+ const columns = row.length;
296
+ if (columns > 6) {
297
+ throw new Error(
298
+ `When using FormProps.fieldLayout, the maximum number of fields per row is 6, provided: ${columns}. For more granular layout control use Field.layout`
299
+ );
300
+ }
301
+
302
+ const currentRow: FieldComponent<any, any>[] = [];
303
+ for (const fieldPropertyName of row) {
304
+ const fieldComponent = this.state.fields[fieldPropertyName];
305
+ fieldComponent.field.layout = { row: i, width: columns == 5 ? 2 : ((12 / columns) as 1) };
306
+ currentRow.push(fieldComponent);
307
+ }
308
+ rows.push(currentRow);
309
+ }
310
+ }
311
+ } else {
312
+ for (const fieldPropertyName in this.state.fields) {
313
+ const fieldComponent: FieldComponent<any, any> = this.state.fields[fieldPropertyName];
314
+ const field = fieldComponent.field;
315
+ if (!field.layout) {
316
+ throw new Error(
317
+ `Unless using FormProps.fieldLayout, Field.layout must be provided; layout not provided for field: ${field.name}`
318
+ );
319
+ }
320
+
321
+ if (typeof rows[field.layout.row] === 'undefined') {
322
+ rows[field.layout.row] = [];
323
+ }
324
+
325
+ if (field.layout.column && rows[field.layout.row].length >= field.layout.column) {
326
+ rows[field.layout.row].splice(field.layout.column - 1, 0, fieldComponent);
299
327
  } else {
300
- for (const fieldPropertyName in this.state.fields) {
301
- const fieldComponent: FieldComponent<any, any> = this.state.fields[fieldPropertyName];
302
- const field = fieldComponent.field;
303
- if (!field.layout)
304
- throw new Error(`Unless using FormProps.fieldLayout, Field.layout must be provided; layout not provided for field: ${field.name}`);
305
-
306
- if (typeof rows[field.layout.row] === 'undefined')
307
- rows[field.layout.row] = [];
308
-
309
- if (field.layout.column && rows[field.layout.row].length >= field.layout.column) {
310
- rows[field.layout.row].splice(field.layout.column - 1, 0, fieldComponent);
311
- } else
312
- rows[field.layout.row].push(fieldComponent);
313
-
314
- const rowWidth = rows[field.layout.row].map((fieldComponent) => fieldComponent.field.layout?.width ? fieldComponent.field.layout.width as number : 0).reduce((accumulator, currentWidth) => accumulator + currentWidth);
315
- if (rowWidth > 12)
316
- throw new Error(`Width of row exceeds maximum width (12), row width: ${rowWidth}, row index: ${field.layout.row}`);
317
- }
328
+ rows[field.layout.row].push(fieldComponent);
318
329
  }
319
-
320
- return rows;
321
- }
322
-
323
- private isFieldRowVisible(fieldComponents: FieldComponent<any, any>[]): boolean {
324
- for (const fieldComponent of fieldComponents) {
325
- if (!fieldComponent.field.accessibility || !fieldComponent.field.accessibility?.hidden)
326
- return true;
330
+
331
+ const rowWidth = rows[field.layout.row]
332
+ .map((fieldComponent) =>
333
+ fieldComponent.field.layout?.width ? (fieldComponent.field.layout.width as number) : 0
334
+ )
335
+ .reduce((accumulator, currentWidth) => accumulator + currentWidth);
336
+ if (rowWidth > 12) {
337
+ throw new Error(
338
+ `Width of row exceeds maximum width (12), row width: ${rowWidth}, row index: ${field.layout.row}`
339
+ );
327
340
  }
328
-
329
- return false;
341
+ }
330
342
  }
331
-
332
- private Progress() {
333
- if (!this.state.progress || !this.state.progress.visible)
334
- return null;
335
343
 
336
- return (
337
- <Grid
338
- container
339
- xs={12}
340
- justifyContent='center'
341
- alignItems='center'
342
- spacing={2}
343
- >
344
- <Container>
345
- <LinearProgress variant='indeterminate' color='primary' />
346
- </Container>
347
- </Grid>
348
- );
344
+ return rows;
345
+ }
346
+
347
+ private isFieldRowVisible(fieldComponents: FieldComponent<any, any>[]): boolean {
348
+ for (const fieldComponent of fieldComponents) {
349
+ if (!fieldComponent.field.accessibility || !fieldComponent.field.accessibility?.hidden) {
350
+ return true;
351
+ }
349
352
  }
350
-
351
- private Buttons() {
352
- return (
353
- <Grid
354
- container
355
- direction="row"
356
- justifyContent="flex-end"
357
- alignItems="center"
358
- xs={12}
353
+
354
+ return false;
355
+ }
356
+
357
+ private Progress() {
358
+ if (!this.state.progress || !this.state.progress.visible) {
359
+ return null;
360
+ }
361
+
362
+ return (
363
+ <Grid container xs={12} justifyContent='center' alignItems='center' spacing={2}>
364
+ <Container>
365
+ <LinearProgress variant='indeterminate' color='primary' />
366
+ </Container>
367
+ </Grid>
368
+ );
369
+ }
370
+
371
+ private Buttons() {
372
+ return (
373
+ <Grid
374
+ container
375
+ direction='row'
376
+ justifyContent='flex-end'
377
+ alignItems='center'
378
+ xs={12}
379
+ sx={(theme) => ({
380
+ marginTop: theme.spacing(2),
381
+ marginBottom: theme.spacing(1),
382
+ })}
383
+ >
384
+ {Object.keys(this.props.buttons)
385
+ .map((buttonPropertyName) => this.props.buttons[buttonPropertyName])
386
+ .filter((button) => {
387
+ if (button.accessibility?.hidden) {
388
+ return false;
389
+ }
390
+
391
+ return true;
392
+ })
393
+ .map((button, key) => {
394
+ return (
395
+ <Grid
396
+ key={key}
359
397
  sx={(theme) => ({
360
- marginTop: theme.spacing(2),
361
- marginBottom: theme.spacing(1),
398
+ marginLeft: theme.spacing(1),
362
399
  })}
363
- >
364
- {
365
- Object.keys(this.props.buttons).map((buttonPropertyName) => this.props.buttons[buttonPropertyName]).filter((button) => {
366
- if (button.accessibility?.hidden)
367
- return false;
368
-
369
- return true;
370
- }).map((button, key) => {
371
- return (
372
- <Grid
373
- key={key}
374
- sx={(theme) => ({
375
- marginLeft: theme.spacing(1),
376
- })}
377
- >
378
- { button.style.icon ?
379
- <IconButton
380
- disabled={button.accessibility?.disabled}
381
- onClick={(event: any) => this.onClick(button)}
382
- >
383
- <button.style.icon />
384
- </IconButton>
385
- :
386
- <Button
387
- color={button.style.color}
388
- variant={button.style.variant ? button.style.variant : 'contained'}
389
- disabled={button.accessibility?.disabled}
390
- onClick={event => this.onClick(button)}
391
- >
392
- {button.name}
393
- </Button>
394
- }
395
- </Grid>
396
- )
397
- })
398
- }
399
- </Grid>
400
- );
401
- }
400
+ >
401
+ {button.style.icon ? (
402
+ <IconButton disabled={button.accessibility?.disabled} onClick={(event: any) => this.onClick(button)}>
403
+ <button.style.icon />
404
+ </IconButton>
405
+ ) : (
406
+ <Button
407
+ color={button.style.color}
408
+ variant={button.style.variant ? button.style.variant : 'contained'}
409
+ disabled={button.accessibility?.disabled}
410
+ onClick={(event) => this.onClick(button)}
411
+ >
412
+ {button.name}
413
+ </Button>
414
+ )}
415
+ </Grid>
416
+ );
417
+ })}
418
+ </Grid>
419
+ );
420
+ }
402
421
  }
403
422
 
404
423
  type FormType = <F extends Fields, B extends FormButtons<F>>(props: Omit<FormProps<F, B>, 'classes'>) => JSX.Element;
405
- export const Form = withRouter(FormComponent) as FormType;
424
+ export const Form = withRouter(FormComponent) as FormType;