@scenid/react-formulator 0.5.3 → 0.5.4
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/package.json +4 -1
- package/.babelrc +0 -30
- package/.eslintignore +0 -22
- package/.eslintrc +0 -70
- package/.firebaserc +0 -5
- package/.storybook/main.js +0 -12
- package/.storybook/preview.js +0 -9
- package/firebase.json +0 -22
- package/functions/.eslintignore +0 -1
- package/functions/.eslintrc.js +0 -29
- package/functions/index.js +0 -32
- package/functions/package-lock.json +0 -6810
- package/functions/package.json +0 -29
- package/rollup.config.js +0 -40
- package/src/Components/HiddenData.jsx +0 -24
- package/src/Components/SelectOrCreate.jsx +0 -156
- package/src/Editable/FormAutocomplete/FormAutocomplete.jsx +0 -155
- package/src/Editable/FormAutocomplete/useFetchOptions.js +0 -83
- package/src/Editable/FormBoolean.jsx +0 -46
- package/src/Editable/FormCatalogType.jsx +0 -29
- package/src/Editable/FormField.jsx +0 -231
- package/src/Editable/FormNumber.jsx +0 -36
- package/src/Editable/FormRepeater.jsx +0 -218
- package/src/Editable/FormSelect.jsx +0 -52
- package/src/Editable/FormText.jsx +0 -20
- package/src/FormGroupHeader.jsx +0 -85
- package/src/FormHelpers.js +0 -191
- package/src/FormSectionBlock.jsx +0 -71
- package/src/FormSectionCard.jsx +0 -62
- package/src/FormulatorForm.jsx +0 -539
- package/src/FormulatorFormSection.jsx +0 -456
- package/src/ReadOnly/FormReadOnlyBoolean.jsx +0 -36
- package/src/ReadOnly/FormReadOnlyField.jsx +0 -126
- package/src/ReadOnly/FormReadOnlyMarkdown.jsx +0 -20
- package/src/ReadOnly/FormReadOnlyNumber.jsx +0 -17
- package/src/ReadOnly/FormReadOnlyRepeater.jsx +0 -52
- package/src/ReadOnly/FormReadOnlySelect.jsx +0 -18
- package/src/ReadOnly/FormReadOnlyText.jsx +0 -45
- package/src/helpers.js +0 -13
- package/src/index.js +0 -20
- package/stories/CustomRenderField.jsx +0 -46
- package/stories/Forms.stories.jsx +0 -283
- package/stories/Introduction.stories.mdx +0 -206
- package/stories/StoryBase.jsx +0 -35
- package/stories/assets/code-brackets.svg +0 -1
- package/stories/assets/colors.svg +0 -1
- package/stories/assets/comments.svg +0 -1
- package/stories/assets/direction.svg +0 -1
- package/stories/assets/flow.svg +0 -1
- package/stories/assets/plugin.svg +0 -1
- package/stories/assets/repo.svg +0 -1
- package/stories/assets/stackalt.svg +0 -1
- package/stories/forms/login.render.schema.json +0 -23
- package/stories/forms/login.validation.schema.json +0 -29
- package/stories/forms/markdown.render.schema.json +0 -30
- package/stories/forms/markdown.validation.schema.json +0 -18
- package/stories/forms/register.render.schema.json +0 -32
- package/stories/forms/register.validation.schema.json +0 -34
- package/stories/forms/rlp.render.schema.json +0 -153
- package/stories/forms/rlp.translations.json +0 -883
- package/stories/forms/rlp.validation.schema.json +0 -1631
- package/stories/forms/types.schemas.js +0 -319
|
@@ -1,456 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import PropTypes from 'prop-types'
|
|
3
|
-
|
|
4
|
-
import { Input } from '@material-ui/core'
|
|
5
|
-
|
|
6
|
-
import { render as mm } from 'micromustache'
|
|
7
|
-
|
|
8
|
-
import FormSectionCard from './FormSectionCard'
|
|
9
|
-
import FormSectionBlock from './FormSectionBlock'
|
|
10
|
-
|
|
11
|
-
import FormField from './Editable/FormField'
|
|
12
|
-
import FormText from './Editable/FormText'
|
|
13
|
-
import FormNumber from './Editable/FormNumber'
|
|
14
|
-
import FormCatalogType from './Editable/FormCatalogType'
|
|
15
|
-
import FormBoolean from './Editable/FormBoolean'
|
|
16
|
-
import FormRepeater from './Editable/FormRepeater'
|
|
17
|
-
|
|
18
|
-
import FormReadOnlyField from './ReadOnly/FormReadOnlyField'
|
|
19
|
-
import FormReadOnlyText from './ReadOnly/FormReadOnlyText'
|
|
20
|
-
import FormMarkdown from './ReadOnly/FormReadOnlyMarkdown'
|
|
21
|
-
import FormReadOnlyNumber from './ReadOnly/FormReadOnlyNumber'
|
|
22
|
-
import FormReadOnlySelect from './ReadOnly/FormReadOnlySelect'
|
|
23
|
-
import FormReadOnlyBoolean from './ReadOnly/FormReadOnlyBoolean'
|
|
24
|
-
import FormReadOnlyRepeater from './ReadOnly/FormReadOnlyRepeater'
|
|
25
|
-
|
|
26
|
-
import HiddenData from './Components/HiddenData'
|
|
27
|
-
|
|
28
|
-
const formReadOnlyComponentMap = {
|
|
29
|
-
default: FormReadOnlyText,
|
|
30
|
-
markdown: FormMarkdown,
|
|
31
|
-
string: FormReadOnlyText,
|
|
32
|
-
number: FormReadOnlyNumber,
|
|
33
|
-
select: FormReadOnlySelect,
|
|
34
|
-
boolean: FormReadOnlyBoolean,
|
|
35
|
-
array: FormReadOnlyRepeater
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const formComponentMap = {
|
|
39
|
-
default: FormText,
|
|
40
|
-
string: FormText,
|
|
41
|
-
number: FormNumber,
|
|
42
|
-
select: FormCatalogType,
|
|
43
|
-
boolean: FormBoolean,
|
|
44
|
-
array: FormRepeater
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const apComponentMap = {
|
|
48
|
-
default: Input,
|
|
49
|
-
string: Input,
|
|
50
|
-
number: FormNumber,
|
|
51
|
-
select: FormCatalogType,
|
|
52
|
-
boolean: FormBoolean
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
class FormulatorFormSection extends React.Component {
|
|
56
|
-
getFieldProps(fieldEntry, componentMap) {
|
|
57
|
-
const {
|
|
58
|
-
schema,
|
|
59
|
-
translations,
|
|
60
|
-
errorMessages,
|
|
61
|
-
results,
|
|
62
|
-
data,
|
|
63
|
-
fieldStates,
|
|
64
|
-
renderComponentMap
|
|
65
|
-
} = this.props
|
|
66
|
-
|
|
67
|
-
let field = fieldEntry, isRender = false, specialProps = {}
|
|
68
|
-
if (Array.isArray(fieldEntry)) {
|
|
69
|
-
if (fieldEntry[0] === '@@markdown') {
|
|
70
|
-
return ({
|
|
71
|
-
type: 'markdown',
|
|
72
|
-
name: fieldEntry[1],
|
|
73
|
-
component: formReadOnlyComponentMap.markdown,
|
|
74
|
-
componentProps: {
|
|
75
|
-
content: fieldEntry[2]
|
|
76
|
-
}
|
|
77
|
-
})
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (fieldEntry[0] === '@@render') {
|
|
81
|
-
if (!fieldEntry[1]) throw new Error(`render field "${field}" has no name`)
|
|
82
|
-
field = fieldEntry[1]
|
|
83
|
-
specialProps = fieldEntry[2] || {}
|
|
84
|
-
isRender = true
|
|
85
|
-
} else {
|
|
86
|
-
field = fieldEntry[0]
|
|
87
|
-
if (!fieldEntry[1]) throw new Error(`field "${field}" is defined in an array, but has no props definition`)
|
|
88
|
-
specialProps = fieldEntry[1]
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const { hidden, hideLabel, ...extraProps } = specialProps
|
|
93
|
-
|
|
94
|
-
if (hidden === true) return false
|
|
95
|
-
|
|
96
|
-
const fieldResult = results[field]
|
|
97
|
-
const { prohibited, required, optional, hasErrors, errors, data: fieldData } = fieldResult
|
|
98
|
-
if (prohibited === true || (!required && !optional && fieldData === undefined)) return false
|
|
99
|
-
|
|
100
|
-
const { type, default: defaultValue } = schema.properties[field]
|
|
101
|
-
|
|
102
|
-
let mapKey
|
|
103
|
-
if (isRender) mapKey = '@@render'
|
|
104
|
-
else if (componentMap[field] !== undefined) mapKey = field
|
|
105
|
-
else if (typeof type === 'string' && componentMap[type] !== undefined) mapKey = type
|
|
106
|
-
else if (Array.isArray(type)) mapKey = 'select'
|
|
107
|
-
else if (componentMap.default !== undefined) mapKey = 'default'
|
|
108
|
-
else throw new Error(`Could not find a Component to render for "${field}"`)
|
|
109
|
-
|
|
110
|
-
const mapEntry = isRender ? renderComponentMap[field] : componentMap[mapKey]
|
|
111
|
-
let component = mapEntry, props = {}
|
|
112
|
-
|
|
113
|
-
if (mapKey === 'array' && schema.properties[fieldEntry].options) {
|
|
114
|
-
props.options = (
|
|
115
|
-
schema.properties[fieldEntry].options
|
|
116
|
-
.reduce((l, r) => ({
|
|
117
|
-
...l,
|
|
118
|
-
[r]: translations?.[fieldEntry]?.[r] || r
|
|
119
|
-
}), {})
|
|
120
|
-
)
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
if (mapKey === 'select') {
|
|
124
|
-
props.options = (
|
|
125
|
-
type.map(value => ({
|
|
126
|
-
label: translations?.[field]?.[value] || value,
|
|
127
|
-
value
|
|
128
|
-
}))
|
|
129
|
-
)
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
if (Array.isArray(mapEntry)) {
|
|
133
|
-
/* eslint-disable prefer-destructuring */
|
|
134
|
-
component = mapEntry[0]
|
|
135
|
-
props = mapEntry[1]
|
|
136
|
-
/* eslint-enable prefer-destructuring */
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
if (!component) throw new Error(`could not find component for field "${field}"`)
|
|
140
|
-
|
|
141
|
-
return {
|
|
142
|
-
type: isRender ? '@@render' : mapKey,
|
|
143
|
-
name: field,
|
|
144
|
-
label: hideLabel !== true && ((translations.labels && translations.labels[field]) || field),
|
|
145
|
-
defaultValue,
|
|
146
|
-
component,
|
|
147
|
-
componentProps: extraProps,
|
|
148
|
-
value: data[field],
|
|
149
|
-
required,
|
|
150
|
-
hasErrors,
|
|
151
|
-
errors: errors.map(({ message, options, validator: eVal, ...restError }) => {
|
|
152
|
-
let finalMessage = message
|
|
153
|
-
|
|
154
|
-
if (options && options.human) finalMessage = options.human
|
|
155
|
-
else if (errorMessages[eVal]) finalMessage = mm(errorMessages[eVal], options)
|
|
156
|
-
|
|
157
|
-
return ({
|
|
158
|
-
message: finalMessage,
|
|
159
|
-
options,
|
|
160
|
-
validator: eVal,
|
|
161
|
-
...restError
|
|
162
|
-
})
|
|
163
|
-
}),
|
|
164
|
-
...props,
|
|
165
|
-
...fieldStates[field]
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
getSectionContent() {
|
|
170
|
-
const {
|
|
171
|
-
id,
|
|
172
|
-
variant,
|
|
173
|
-
inputVariant,
|
|
174
|
-
readOnly,
|
|
175
|
-
nested = 0,
|
|
176
|
-
schema,
|
|
177
|
-
fields,
|
|
178
|
-
obscuredFields,
|
|
179
|
-
results,
|
|
180
|
-
data,
|
|
181
|
-
fieldStates,
|
|
182
|
-
translations,
|
|
183
|
-
renderComponentMap,
|
|
184
|
-
errorMessages,
|
|
185
|
-
onChange,
|
|
186
|
-
disabled
|
|
187
|
-
} = this.props
|
|
188
|
-
|
|
189
|
-
const allFieldProps = (
|
|
190
|
-
fields
|
|
191
|
-
.filter(f => typeof f === 'string' || Array.isArray(f))
|
|
192
|
-
.map(fieldEntry => this.getFieldProps(fieldEntry, readOnly ? formReadOnlyComponentMap : formComponentMap))
|
|
193
|
-
)
|
|
194
|
-
|
|
195
|
-
return (
|
|
196
|
-
Array.isArray(fields)
|
|
197
|
-
&& (
|
|
198
|
-
fields.map((fieldEntry, fieldIndex) => {
|
|
199
|
-
if (fieldEntry === false) return false
|
|
200
|
-
|
|
201
|
-
if (typeof fieldEntry !== 'string' && !Array.isArray(fieldEntry)) {
|
|
202
|
-
return (
|
|
203
|
-
<FormulatorFormSection
|
|
204
|
-
key={`form-section-${fieldEntry.id}`}
|
|
205
|
-
variant={variant}
|
|
206
|
-
inputVariant={inputVariant}
|
|
207
|
-
readOnly={readOnly}
|
|
208
|
-
id={fieldEntry.id}
|
|
209
|
-
nested={nested + 1}
|
|
210
|
-
sectionId={fieldEntry.id}
|
|
211
|
-
schema={schema}
|
|
212
|
-
label={fieldEntry.label}
|
|
213
|
-
fields={fieldEntry.fields}
|
|
214
|
-
results={results}
|
|
215
|
-
data={data}
|
|
216
|
-
obscuredFields={obscuredFields}
|
|
217
|
-
fieldStates={fieldStates}
|
|
218
|
-
translations={translations}
|
|
219
|
-
errorMessages={errorMessages}
|
|
220
|
-
renderComponentMap={renderComponentMap}
|
|
221
|
-
onChange={onChange}
|
|
222
|
-
disabled={disabled}
|
|
223
|
-
/>
|
|
224
|
-
)
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
if (Array.isArray(fieldEntry) && (fieldEntry[1].appends || fieldEntry[1].prepends)) return false
|
|
228
|
-
|
|
229
|
-
const fieldProps = allFieldProps[fieldIndex]
|
|
230
|
-
if (!fieldProps) return false
|
|
231
|
-
|
|
232
|
-
const {
|
|
233
|
-
type,
|
|
234
|
-
name,
|
|
235
|
-
component,
|
|
236
|
-
componentProps,
|
|
237
|
-
label,
|
|
238
|
-
value,
|
|
239
|
-
defaultValue,
|
|
240
|
-
options,
|
|
241
|
-
required,
|
|
242
|
-
hasErrors,
|
|
243
|
-
errors,
|
|
244
|
-
validating,
|
|
245
|
-
dirty
|
|
246
|
-
} = fieldProps
|
|
247
|
-
|
|
248
|
-
if (readOnly) {
|
|
249
|
-
if (!value) return false
|
|
250
|
-
if (Array.isArray(obscuredFields) && obscuredFields.includes(name)) {
|
|
251
|
-
return <HiddenData key={`hidden-field-${name}`} subject="Das Feld" label={label} />
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
const apProps = {}
|
|
256
|
-
|
|
257
|
-
for (let i = 0; i < fields.length; i++) {
|
|
258
|
-
const apField = fields[i]
|
|
259
|
-
|
|
260
|
-
if (Array.isArray(apField) && apField[1].appends && apField[1].appends === name) {
|
|
261
|
-
if (!apProps.append) apProps.append = []
|
|
262
|
-
const aProps = this.getFieldProps(apField, apComponentMap)
|
|
263
|
-
|
|
264
|
-
apProps.append.push(
|
|
265
|
-
React.createElement(
|
|
266
|
-
aProps.component,
|
|
267
|
-
{
|
|
268
|
-
key: `form-field-${name}-append-${aProps.name}`,
|
|
269
|
-
variant: inputVariant,
|
|
270
|
-
disabled,
|
|
271
|
-
onChange,
|
|
272
|
-
...aProps
|
|
273
|
-
}
|
|
274
|
-
)
|
|
275
|
-
)
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
if (Array.isArray(apField) && apField[1].prepends && apField[1].prepends === name) {
|
|
279
|
-
if (!apProps.prepend) apProps.prepend = []
|
|
280
|
-
const aProps = this.getFieldProps(apField, apComponentMap)
|
|
281
|
-
|
|
282
|
-
apProps.prepend.push(
|
|
283
|
-
React.createElement(
|
|
284
|
-
aProps.component,
|
|
285
|
-
{
|
|
286
|
-
key: `form-field-${name}-append-${aProps.name}`,
|
|
287
|
-
variant: inputVariant,
|
|
288
|
-
disabled,
|
|
289
|
-
onChange,
|
|
290
|
-
...aProps
|
|
291
|
-
}
|
|
292
|
-
)
|
|
293
|
-
)
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
const FormFieldComponent = readOnly ? FormReadOnlyField : FormField
|
|
298
|
-
|
|
299
|
-
return (
|
|
300
|
-
React.createElement(
|
|
301
|
-
FormFieldComponent,
|
|
302
|
-
{
|
|
303
|
-
key: `form-${id}-${name}`,
|
|
304
|
-
variant: inputVariant,
|
|
305
|
-
type,
|
|
306
|
-
name,
|
|
307
|
-
label,
|
|
308
|
-
defaultValue,
|
|
309
|
-
value,
|
|
310
|
-
options,
|
|
311
|
-
required,
|
|
312
|
-
hasErrors,
|
|
313
|
-
errors,
|
|
314
|
-
validating,
|
|
315
|
-
dirty,
|
|
316
|
-
component,
|
|
317
|
-
componentProps,
|
|
318
|
-
prepend: apProps.prepend,
|
|
319
|
-
append: apProps.append,
|
|
320
|
-
disabled,
|
|
321
|
-
onChange
|
|
322
|
-
}
|
|
323
|
-
)
|
|
324
|
-
)
|
|
325
|
-
})
|
|
326
|
-
)
|
|
327
|
-
)
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
render() {
|
|
331
|
-
const {
|
|
332
|
-
variant,
|
|
333
|
-
readOnly,
|
|
334
|
-
nested = 0,
|
|
335
|
-
sectionId,
|
|
336
|
-
label,
|
|
337
|
-
labelVariant,
|
|
338
|
-
desc,
|
|
339
|
-
descVariant,
|
|
340
|
-
textAlign,
|
|
341
|
-
fields
|
|
342
|
-
} = this.props
|
|
343
|
-
|
|
344
|
-
const allFieldProps = (
|
|
345
|
-
fields
|
|
346
|
-
.filter(f => typeof f === 'string' || Array.isArray(f))
|
|
347
|
-
.map(fieldEntry => this.getFieldProps(fieldEntry, readOnly ? formReadOnlyComponentMap : formComponentMap))
|
|
348
|
-
)
|
|
349
|
-
|
|
350
|
-
const renderableFields = allFieldProps.filter(fp => {
|
|
351
|
-
if (
|
|
352
|
-
Array.isArray(fp)
|
|
353
|
-
&& (
|
|
354
|
-
fp[0] === '@@render'
|
|
355
|
-
|| fp[0] === '@@markdown'
|
|
356
|
-
)
|
|
357
|
-
) return false
|
|
358
|
-
|
|
359
|
-
return fp !== false
|
|
360
|
-
})
|
|
361
|
-
|
|
362
|
-
if (renderableFields.length === 0) return false
|
|
363
|
-
|
|
364
|
-
const sectionContent = this.getSectionContent()
|
|
365
|
-
|
|
366
|
-
if (readOnly && sectionContent.every(c => c === false)) return false
|
|
367
|
-
|
|
368
|
-
if (nested === 0) {
|
|
369
|
-
const FormSection = variant === 'card' ? FormSectionCard : FormSectionBlock
|
|
370
|
-
|
|
371
|
-
return (
|
|
372
|
-
React.createElement(
|
|
373
|
-
FormSection,
|
|
374
|
-
{
|
|
375
|
-
key: `form-section-${sectionId}`,
|
|
376
|
-
groupId: sectionId,
|
|
377
|
-
label,
|
|
378
|
-
labelVariant,
|
|
379
|
-
desc,
|
|
380
|
-
descVariant,
|
|
381
|
-
textAlign
|
|
382
|
-
},
|
|
383
|
-
sectionContent
|
|
384
|
-
)
|
|
385
|
-
)
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
return (
|
|
389
|
-
<FormSectionBlock
|
|
390
|
-
key={`form-section-${sectionId}`}
|
|
391
|
-
label={label}
|
|
392
|
-
labelVariant={labelVariant}
|
|
393
|
-
desc={desc}
|
|
394
|
-
descVariant={descVariant}
|
|
395
|
-
textAlign={textAlign}
|
|
396
|
-
>
|
|
397
|
-
{sectionContent}
|
|
398
|
-
</FormSectionBlock>
|
|
399
|
-
)
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
FormulatorFormSection.propTypes = {
|
|
404
|
-
id: PropTypes.string.isRequired,
|
|
405
|
-
variant: PropTypes.string.isRequired,
|
|
406
|
-
inputVariant: PropTypes.oneOf(['standard', 'filled', 'outlined']),
|
|
407
|
-
label: PropTypes.string,
|
|
408
|
-
desc: PropTypes.string,
|
|
409
|
-
labelVariant: PropTypes.oneOf([
|
|
410
|
-
'h1',
|
|
411
|
-
'h2',
|
|
412
|
-
'h3',
|
|
413
|
-
'h4',
|
|
414
|
-
'h5',
|
|
415
|
-
'h6',
|
|
416
|
-
'subtitle1',
|
|
417
|
-
'subtitle2',
|
|
418
|
-
'body1',
|
|
419
|
-
'body2',
|
|
420
|
-
'button',
|
|
421
|
-
'caption',
|
|
422
|
-
'overline'
|
|
423
|
-
]),
|
|
424
|
-
descVariant: PropTypes.oneOf([
|
|
425
|
-
'h1',
|
|
426
|
-
'h2',
|
|
427
|
-
'h3',
|
|
428
|
-
'h4',
|
|
429
|
-
'h5',
|
|
430
|
-
'h6',
|
|
431
|
-
'subtitle1',
|
|
432
|
-
'subtitle2',
|
|
433
|
-
'body1',
|
|
434
|
-
'body2',
|
|
435
|
-
'button',
|
|
436
|
-
'caption',
|
|
437
|
-
'overline'
|
|
438
|
-
]),
|
|
439
|
-
textAlign: PropTypes.oneOf(['left', 'center', 'right']),
|
|
440
|
-
disabled: PropTypes.bool,
|
|
441
|
-
readOnly: PropTypes.bool,
|
|
442
|
-
nested: PropTypes.number,
|
|
443
|
-
sectionId: PropTypes.string.isRequired,
|
|
444
|
-
fields: PropTypes.array.isRequired,
|
|
445
|
-
obscuredFields: PropTypes.array,
|
|
446
|
-
schema: PropTypes.object.isRequired,
|
|
447
|
-
results: PropTypes.object.isRequired,
|
|
448
|
-
data: PropTypes.object.isRequired,
|
|
449
|
-
fieldStates: PropTypes.object.isRequired,
|
|
450
|
-
translations: PropTypes.object.isRequired,
|
|
451
|
-
errorMessages: PropTypes.object.isRequired,
|
|
452
|
-
renderComponentMap: PropTypes.object,
|
|
453
|
-
onChange: PropTypes.func.isRequired
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
export default FormulatorFormSection
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import PropTypes from 'prop-types'
|
|
3
|
-
|
|
4
|
-
import { Checkbox, Switch } from '@material-ui/core'
|
|
5
|
-
|
|
6
|
-
const isBoolean = val => val === false || val === true
|
|
7
|
-
const isChecked = (value, defaultValue) => isBoolean(value) ? value : (defaultValue || false)
|
|
8
|
-
|
|
9
|
-
const FormReadOnlyBoolean = ({ variant, name, value, defaultValue }) => {
|
|
10
|
-
if (variant === 'checkbox') {
|
|
11
|
-
return (
|
|
12
|
-
<Checkbox
|
|
13
|
-
name={name}
|
|
14
|
-
checked={isChecked(value, defaultValue)}
|
|
15
|
-
disabled
|
|
16
|
-
/>
|
|
17
|
-
)
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return (
|
|
21
|
-
<Switch
|
|
22
|
-
name={name}
|
|
23
|
-
checked={isChecked(value, defaultValue)}
|
|
24
|
-
disabled
|
|
25
|
-
/>
|
|
26
|
-
)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
FormReadOnlyBoolean.propTypes = {
|
|
30
|
-
variant: PropTypes.string,
|
|
31
|
-
name: PropTypes.string.isRequired,
|
|
32
|
-
value: PropTypes.bool,
|
|
33
|
-
defaultValue: PropTypes.bool
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export default FormReadOnlyBoolean
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import PropTypes from 'prop-types'
|
|
3
|
-
|
|
4
|
-
import { Typography, Box } from '@material-ui/core'
|
|
5
|
-
|
|
6
|
-
const FormControlField = ({
|
|
7
|
-
type,
|
|
8
|
-
name,
|
|
9
|
-
label,
|
|
10
|
-
component,
|
|
11
|
-
componentProps,
|
|
12
|
-
value,
|
|
13
|
-
options,
|
|
14
|
-
required
|
|
15
|
-
}) => {
|
|
16
|
-
const finalProps = {
|
|
17
|
-
...componentProps,
|
|
18
|
-
name,
|
|
19
|
-
label,
|
|
20
|
-
value,
|
|
21
|
-
options,
|
|
22
|
-
required,
|
|
23
|
-
readOnly: true
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (componentProps?.readOnlyHidden === true) {
|
|
27
|
-
return false
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
let control
|
|
31
|
-
if (type === '@@render') control = React.cloneElement(component, finalProps)
|
|
32
|
-
else control = React.createElement(component, finalProps)
|
|
33
|
-
|
|
34
|
-
return (
|
|
35
|
-
<Box
|
|
36
|
-
width="100%"
|
|
37
|
-
display="flex"
|
|
38
|
-
flexDirection="column"
|
|
39
|
-
mb={1.5}
|
|
40
|
-
>
|
|
41
|
-
{
|
|
42
|
-
label
|
|
43
|
-
&& (
|
|
44
|
-
<Typography
|
|
45
|
-
variant="caption"
|
|
46
|
-
color="textSecondary"
|
|
47
|
-
>
|
|
48
|
-
{label}
|
|
49
|
-
</Typography>
|
|
50
|
-
)
|
|
51
|
-
}
|
|
52
|
-
{control}
|
|
53
|
-
</Box>
|
|
54
|
-
)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
FormControlField.propTypes = {
|
|
58
|
-
component: PropTypes.any.isRequired,
|
|
59
|
-
componentProps: PropTypes.object,
|
|
60
|
-
name: PropTypes.string.isRequired,
|
|
61
|
-
type: PropTypes.string.isRequired,
|
|
62
|
-
label: PropTypes.string.isRequired,
|
|
63
|
-
value: PropTypes.oneOfType([
|
|
64
|
-
PropTypes.string,
|
|
65
|
-
PropTypes.number,
|
|
66
|
-
PropTypes.bool,
|
|
67
|
-
PropTypes.array
|
|
68
|
-
]),
|
|
69
|
-
options: PropTypes.arrayOf(PropTypes.shape({
|
|
70
|
-
label: PropTypes.string.isRequired,
|
|
71
|
-
value: PropTypes.any
|
|
72
|
-
})),
|
|
73
|
-
required: PropTypes.bool
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
FormControlField.defaultProps = {
|
|
77
|
-
componentProps: {}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const FormReadOnlyField = ({
|
|
81
|
-
prepend,
|
|
82
|
-
append,
|
|
83
|
-
componentProps,
|
|
84
|
-
...fieldProps
|
|
85
|
-
}) => {
|
|
86
|
-
const finalProps = {
|
|
87
|
-
componentProps,
|
|
88
|
-
...fieldProps
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
if (componentProps?.type === 'hidden') {
|
|
92
|
-
return <input type="hidden" name={fieldProps.name} value={fieldProps.value} />
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return (
|
|
96
|
-
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
97
|
-
<FormControlField {...finalProps} />
|
|
98
|
-
)
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
FormReadOnlyField.propTypes = {
|
|
102
|
-
component: PropTypes.any.isRequired,
|
|
103
|
-
componentProps: PropTypes.object,
|
|
104
|
-
type: PropTypes.string.isRequired,
|
|
105
|
-
name: PropTypes.string.isRequired,
|
|
106
|
-
label: PropTypes.string.isRequired,
|
|
107
|
-
value: PropTypes.oneOfType([
|
|
108
|
-
PropTypes.string,
|
|
109
|
-
PropTypes.number,
|
|
110
|
-
PropTypes.bool,
|
|
111
|
-
PropTypes.array
|
|
112
|
-
]),
|
|
113
|
-
options: PropTypes.arrayOf(PropTypes.shape({
|
|
114
|
-
label: PropTypes.string.isRequired,
|
|
115
|
-
value: PropTypes.any
|
|
116
|
-
})),
|
|
117
|
-
prepend: PropTypes.array,
|
|
118
|
-
append: PropTypes.array,
|
|
119
|
-
hasErrors: PropTypes.bool,
|
|
120
|
-
errors: PropTypes.array,
|
|
121
|
-
validating: PropTypes.bool,
|
|
122
|
-
required: PropTypes.bool,
|
|
123
|
-
dirty: PropTypes.bool
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
export default React.memo(FormReadOnlyField)
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import PropTypes from 'prop-types'
|
|
3
|
-
|
|
4
|
-
import ReactMarkdown from 'react-markdown'
|
|
5
|
-
import remarkGfm from 'remark-gfm'
|
|
6
|
-
import rehypeHighlight from 'rehype-highlight'
|
|
7
|
-
|
|
8
|
-
const FormReadOnlyMarkdown = ({ content }) => (
|
|
9
|
-
<ReactMarkdown
|
|
10
|
-
children={content}
|
|
11
|
-
remarkPlugins={[remarkGfm]}
|
|
12
|
-
rehypePlugins={[rehypeHighlight]}
|
|
13
|
-
/>
|
|
14
|
-
)
|
|
15
|
-
|
|
16
|
-
FormReadOnlyMarkdown.propTypes = {
|
|
17
|
-
content: PropTypes.string
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export default FormReadOnlyMarkdown
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import PropTypes from 'prop-types'
|
|
3
|
-
|
|
4
|
-
import FormReadOnlyText from './FormReadOnlyText'
|
|
5
|
-
|
|
6
|
-
import { castToNumber } from '../helpers'
|
|
7
|
-
|
|
8
|
-
const FormReadOnlyNumber = ({ value }) => <FormReadOnlyText value={castToNumber(value)} />
|
|
9
|
-
|
|
10
|
-
FormReadOnlyNumber.propTypes = {
|
|
11
|
-
value: PropTypes.oneOfType([
|
|
12
|
-
PropTypes.number,
|
|
13
|
-
PropTypes.string
|
|
14
|
-
])
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export default FormReadOnlyNumber
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import PropTypes from 'prop-types'
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
List,
|
|
6
|
-
ListItem,
|
|
7
|
-
ListItemText
|
|
8
|
-
} from '@material-ui/core'
|
|
9
|
-
|
|
10
|
-
import { makeStyles } from '@material-ui/core/styles'
|
|
11
|
-
|
|
12
|
-
const useStyles = makeStyles(() => ({
|
|
13
|
-
formRepeater: {
|
|
14
|
-
padding: 0,
|
|
15
|
-
margin: 0
|
|
16
|
-
}
|
|
17
|
-
}))
|
|
18
|
-
|
|
19
|
-
const getValue = (value, catalog) => {
|
|
20
|
-
if (catalog && catalog[value] !== undefined) return catalog[value]
|
|
21
|
-
return value
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const FormReadOnlyRepeater = ({ value, options }) => {
|
|
25
|
-
const styles = useStyles()
|
|
26
|
-
|
|
27
|
-
return (
|
|
28
|
-
<List
|
|
29
|
-
className={styles.formRepeater}
|
|
30
|
-
dense
|
|
31
|
-
>
|
|
32
|
-
{
|
|
33
|
-
value && value.map((entry, index) => (
|
|
34
|
-
// eslint-disable-next-line react/no-array-index-key
|
|
35
|
-
<ListItem key={`entry-${index}`}>
|
|
36
|
-
<ListItemText
|
|
37
|
-
primary={getValue(entry, options)}
|
|
38
|
-
style={{ margin: 0 }}
|
|
39
|
-
/>
|
|
40
|
-
</ListItem>
|
|
41
|
-
))
|
|
42
|
-
}
|
|
43
|
-
</List>
|
|
44
|
-
)
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
FormReadOnlyRepeater.propTypes = {
|
|
48
|
-
value: PropTypes.array,
|
|
49
|
-
options: PropTypes.object
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export default FormReadOnlyRepeater
|