@nolwenture/formik-jsonschema-form 0.26.1 → 0.26.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.
- package/dist/Form.js +3 -3
- package/dist/Form.stories.js +9 -32
- package/dist/FormEditor.js +3 -12
- package/dist/FormPdf.js +3 -3
- package/dist/FormPdf.stories.js +7 -30
- package/dist/fields/AnyField.js +3 -3
- package/dist/fields/ArrayField.js +9 -9
- package/dist/fields/BooleanField.js +6 -3
- package/dist/fields/DateField.js +1 -1
- package/dist/fields/FileUploadField.js +9 -18
- package/dist/fields/MultipleChoiceField.js +2 -2
- package/dist/fields/NullField.js +1 -1
- package/dist/fields/NumberField.js +4 -2
- package/dist/fields/ObjectField.js +11 -23
- package/dist/fields/RadioField.js +1 -1
- package/dist/fields/SchemaField.js +6 -2
- package/dist/fields/SearchMultiTagSelectField.js +1 -1
- package/dist/fields/SearchableSelectField.js +19 -25
- package/dist/fields/StringField.js +11 -9
- package/dist/fields/TextAreaField.js +1 -1
- package/dist/fields/ToggleField.js +1 -1
- package/dist/fields/stories/AnyField.stories.js +22 -31
- package/dist/fields/stories/ArrayField.stories.js +64 -73
- package/dist/fields/stories/BooleanField.stories.js +6 -15
- package/dist/fields/stories/DateField.stories.js +4 -13
- package/dist/fields/stories/FileUploadField.stories.js +9 -18
- package/dist/fields/stories/MultipleChoiceField.stories.js +24 -33
- package/dist/fields/stories/NullField.stories.js +3 -12
- package/dist/fields/stories/NumberField.stories.js +4 -13
- package/dist/fields/stories/ObjectField.stories.js +11 -20
- package/dist/fields/stories/RadioField.stories.js +8 -17
- package/dist/fields/stories/SchemaField.stories.js +24 -17
- package/dist/fields/stories/SearchMultiTagSelectField.stories.js +8 -17
- package/dist/fields/stories/StringField.stories.js +17 -26
- package/dist/fields/stories/TextAreaField.stories.js +4 -13
- package/dist/fields/stories/ToggleField.stories.js +6 -15
- package/dist/hooks/useExtractUiSchema.js +13 -16
- package/dist/pdfFields/AnyField.js +3 -3
- package/dist/pdfFields/ArrayField.js +3 -4
- package/dist/pdfFields/BooleanField.js +1 -1
- package/dist/pdfFields/DateField.js +4 -2
- package/dist/pdfFields/EJSField.js +1 -2
- package/dist/pdfFields/MultipleChoiceField.js +2 -3
- package/dist/pdfFields/NullField.js +1 -1
- package/dist/pdfFields/NumberField.js +4 -2
- package/dist/pdfFields/ObjectField.js +7 -19
- package/dist/pdfFields/RadioField.js +7 -2
- package/dist/pdfFields/SchemaField.js +6 -2
- package/dist/pdfFields/SearchMultiTagSelectField.js +1 -1
- package/dist/pdfFields/SearchableSelectField.js +1 -1
- package/dist/pdfFields/StringField.js +2 -3
- package/dist/pdfFields/TextAreaField.js +1 -1
- package/dist/pdfFields/ToggleField.js +7 -2
- package/dist/pdfTemplates/ArrayFieldTemplate.js +1 -1
- package/dist/pdfTemplates/CollapsibleObjectFieldTemplate.js +1 -1
- package/dist/pdfTemplates/FieldTemplate.js +1 -1
- package/dist/pdfTemplates/ObjectFieldTemplate.js +1 -1
- package/dist/styledComponents.js +39 -59
- package/dist/templates/ArrayFieldTemplate.js +6 -14
- package/dist/templates/CollapsibleObjectFieldTemplate.js +6 -14
- package/dist/templates/FieldTemplate.js +6 -14
- package/dist/templates/ObjectFieldTemplate.js +6 -14
- package/dist/utils/__tests/createInitialValues.test.js +2 -11
- package/dist/utils/__tests/createValidationSchema.test.js +30 -35
- package/dist/utils/__tests/solveReferences.test.js +4 -8
- package/dist/utils/createInitialValues.js +9 -7
- package/dist/utils/createValidationSchema.js +19 -32
- package/dist/utils/getEnums.js +2 -2
- package/dist/utils/getTitleAndDescription.js +7 -9
- package/dist/utils/hasReferences.js +2 -2
- package/dist/utils/resolveSchema.js +16 -30
- package/dist/utils/solveReferences.js +3 -4
- package/package.json +9 -9
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { BooleanField } from "./BooleanField";
|
|
3
3
|
export const ToggleField = (props) => {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
return (_jsx(BooleanField, { ...props, uiSchema: {
|
|
5
|
+
...props.uiSchema,
|
|
6
|
+
"ui:props": {
|
|
7
|
+
...(props.uiSchema?.["ui:props"] || {}),
|
|
8
|
+
type: "boolean",
|
|
9
|
+
},
|
|
10
|
+
} }));
|
|
6
11
|
};
|
|
@@ -12,5 +12,5 @@ export const ArrayFieldTemplate = (props) => {
|
|
|
12
12
|
const { help, info,
|
|
13
13
|
//TODO: This is not right
|
|
14
14
|
props: { wrapper: wrapperProps, title: titleProps, description: descriptionProps, help: helpProps, error: errorProps, } = {}, } = useExtractUiSchema(uiSchema);
|
|
15
|
-
return (_jsxs(ArrayFieldWrapper,
|
|
15
|
+
return (_jsxs(ArrayFieldWrapper, { ...wrapperProps, children: [title && (_jsxs(ArrayFieldTitle, { ...titleProps, htmlFor: name, children: [title, props?.required && _jsx(RequiredIndicator, { children: "*" })] })), info && _jsx(InfoFieldButton, { ...info }), description && (_jsx(FieldDescription, { ...descriptionProps, children: description })), children, help && _jsx(FieldHelp, { ...helpProps, children: help }), _jsx(ErrorMessage, { ...errorProps, name: name })] }));
|
|
16
16
|
};
|
|
@@ -16,5 +16,5 @@ export const CollapsibleObjectFieldTemplate = (props) => {
|
|
|
16
16
|
} = {}, } = useExtractUiSchema(uiSchema);
|
|
17
17
|
const [collapsed, setCollapsed] = useState(isCollapsedOnLoad);
|
|
18
18
|
const hide = collapsed;
|
|
19
|
-
return (_jsxs(CollapsibleObjectFieldWrapper,
|
|
19
|
+
return (_jsxs(CollapsibleObjectFieldWrapper, { ...wrapperProps, children: [title && (_jsx(CollapsibleToggle, { onClick: () => setCollapsed(!collapsed), ariaExpanded: !hide, ariaLabel: ariaLabel ?? name, children: _jsxs(CollapsibleObjectFieldTitle, { style: { display: "flex", alignItems: "center" }, ...titleProps, children: [title, props?.required && _jsx(RequiredIndicator, { children: "*" }), _jsx(Icon, { children: hide ? collapsedIcon ?? "▸" : openIcon ?? "▾" })] }) })), info && _jsx(InfoFieldButton, { ...info }), description && (_jsx(FieldDescription, { ...descriptionProps, children: description })), !hide && _jsx(CollapsibleChildWrapper, { children: children }), help && _jsx(FieldHelp, { ...helpProps, children: help })] }));
|
|
20
20
|
};
|
|
@@ -11,5 +11,5 @@ export const FieldTemplate = (props) => {
|
|
|
11
11
|
const { help,
|
|
12
12
|
//TODO: This is not right
|
|
13
13
|
props: { wrapper: wrapperProps, title: titleProps, description: descriptionProps, help: helpProps, } = {}, } = useExtractUiSchema(uiSchema);
|
|
14
|
-
return (_jsxs(FieldWrapper,
|
|
14
|
+
return (_jsxs(FieldWrapper, { ...wrapperProps, children: [title && (_jsxs(FieldTitle, { ...titleProps, htmlFor: name, children: [title, props.required && _jsx(RequiredIndicator, { children: "*" })] })), description && (_jsx(FieldDescription, { ...descriptionProps, children: description })), children, help && _jsx(FieldHelp, { ...helpProps, children: help })] }));
|
|
15
15
|
};
|
|
@@ -14,5 +14,5 @@ export const ObjectFieldTemplate = (props) => {
|
|
|
14
14
|
props: { wrapper: wrapperProps, title: titleProps, description: descriptionProps, help: helpProps,
|
|
15
15
|
// error: errorProps,
|
|
16
16
|
} = {}, } = useExtractUiSchema(uiSchema);
|
|
17
|
-
return (_jsxs(ObjectFieldWrapper,
|
|
17
|
+
return (_jsxs(ObjectFieldWrapper, { ...wrapperProps, children: [title && (_jsxs(ObjectFieldTitle, { ...titleProps, children: [title, props?.required && _jsx(RequiredIndicator, { children: "*" })] })), info && _jsx(InfoFieldButton, { ...info }), description && (_jsx(FieldDescription, { ...descriptionProps, children: description })), children, help && _jsx(FieldHelp, { ...helpProps, children: help })] }));
|
|
18
18
|
};
|
package/dist/styledComponents.js
CHANGED
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
-
var t = {};
|
|
3
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
-
t[p] = s[p];
|
|
5
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
-
t[p[i]] = s[p[i]];
|
|
9
|
-
}
|
|
10
|
-
return t;
|
|
11
|
-
};
|
|
12
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
13
2
|
import * as formik from "formik";
|
|
14
3
|
import { useState } from "react";
|
|
@@ -44,18 +33,17 @@ export const ObjectFieldDownButton = styled(ObjectFieldLineButton) ``;
|
|
|
44
33
|
export const ObjectFieldRemoveButton = styled(ObjectFieldLineButton) ``;
|
|
45
34
|
export const ObjectFieldAddButton = styled(ObjectFieldButton) ``;
|
|
46
35
|
export const getObjectFieldButton = ({ purpose, onClick, uiSchema, }) => {
|
|
47
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
48
36
|
switch (purpose) {
|
|
49
37
|
case ObjectFieldButtonPurpose.ADD:
|
|
50
|
-
return (_jsx(ObjectFieldAddButton,
|
|
38
|
+
return (_jsx(ObjectFieldAddButton, { ...(uiSchema?.["ui:addButtonOptions"]?.props ?? {}), onClick: onClick, children: uiSchema?.["ui:addButtonOptions"]?.content ?? "+" }));
|
|
51
39
|
case ObjectFieldButtonPurpose.REMOVE:
|
|
52
|
-
return (_jsx(ObjectFieldRemoveButton,
|
|
40
|
+
return (_jsx(ObjectFieldRemoveButton, { ...(uiSchema?.["ui:removeButtonOptions"]?.props ?? {}), onClick: onClick, children: uiSchema?.["ui:removeButtonOptions"]?.content ?? "-" }));
|
|
53
41
|
case ObjectFieldButtonPurpose.MOVE_UP:
|
|
54
|
-
return (_jsx(ObjectFieldUpButton,
|
|
42
|
+
return (_jsx(ObjectFieldUpButton, { ...(uiSchema?.["ui:upButtonOptions"]?.props ?? {}), onClick: onClick, children: uiSchema?.["ui:upButtonOptions"]?.content ?? "↑" }));
|
|
55
43
|
case ObjectFieldButtonPurpose.MOVE_DOWN:
|
|
56
|
-
return (_jsx(ObjectFieldDownButton,
|
|
44
|
+
return (_jsx(ObjectFieldDownButton, { ...(uiSchema?.["ui:downButtonOptions"]?.props ?? {}), onClick: onClick, children: uiSchema?.["ui:downButtonOptions"]?.content ?? "↓" }));
|
|
57
45
|
default:
|
|
58
|
-
return (_jsx(ObjectFieldButton,
|
|
46
|
+
return (_jsx(ObjectFieldButton, { ...(uiSchema?.["ui:customButtonOptions"]?.props ?? {}), onClick: onClick, children: uiSchema?.["ui:customButtonOptions"]?.content ?? "" }));
|
|
59
47
|
}
|
|
60
48
|
};
|
|
61
49
|
export const ArrayFieldWrapper = ObjectFieldWrapper;
|
|
@@ -174,7 +162,7 @@ export const InfoFieldContainerElement = styled.a `
|
|
|
174
162
|
`;
|
|
175
163
|
export const InfoFieldLabel = styled.span ``;
|
|
176
164
|
export const InfoFieldButton = ({ label, content, position, props, className, }) => {
|
|
177
|
-
return (_jsxs(InfoFieldContainerElement, { href: "#", onClick: (e) => e.preventDefault(), className: className, children: [_jsx(InfoFieldLabel, { children: label
|
|
165
|
+
return (_jsxs(InfoFieldContainerElement, { href: "#", onClick: (e) => e.preventDefault(), className: className, children: [_jsx(InfoFieldLabel, { children: label ?? "i" }), _jsxs(InfoFieldBoxElement, { position: position ?? "top", role: "tooltip", children: [_jsx(InfoFieldBoxArrowElement, { position: position ?? "top" }), _jsx(InfoFieldBoxInnerElement, { children: content })] })] }));
|
|
178
166
|
};
|
|
179
167
|
InfoFieldButton.styles = {
|
|
180
168
|
InfoFieldContainerElementStyle: InfoFieldContainerElement,
|
|
@@ -189,9 +177,8 @@ export const ErrorMessage = styled(formik.ErrorMessage) ``;
|
|
|
189
177
|
* Works like Formik field, but "as" props needs to be given with "formikAs", since styled components uses as.
|
|
190
178
|
*
|
|
191
179
|
*/
|
|
192
|
-
export const FieldInput = styled((
|
|
193
|
-
|
|
194
|
-
return _jsx(formik.Field, Object.assign({}, props, { as: formikAs }));
|
|
180
|
+
export const FieldInput = styled(({ formikAs, ...props }) => {
|
|
181
|
+
return _jsx(formik.Field, { ...props, as: formikAs });
|
|
195
182
|
}) ``;
|
|
196
183
|
export const RequiredIndicator = styled.span ``;
|
|
197
184
|
// ToggleSwitchField --->
|
|
@@ -243,7 +230,7 @@ export const ToggleFieldInput = styled(FieldInput) `
|
|
|
243
230
|
}
|
|
244
231
|
`;
|
|
245
232
|
export const ToggleSwitchField = ({ inputProps, name, className, }) => {
|
|
246
|
-
return (_jsxs(ToggleLabel, { className: className, children: [_jsx(ToggleFieldInput,
|
|
233
|
+
return (_jsxs(ToggleLabel, { className: className, children: [_jsx(ToggleFieldInput, { ...inputProps, name: name, type: "checkbox" }), _jsx(Toggle, {})] }));
|
|
247
234
|
};
|
|
248
235
|
ToggleSwitchField.styles = {
|
|
249
236
|
ToggleLabelStyle: ToggleLabel,
|
|
@@ -270,8 +257,7 @@ export const ButtonLabel = styled.span `
|
|
|
270
257
|
export const ButtonLabelTrue = styled(ButtonLabel) ``;
|
|
271
258
|
export const ButtonLabelFalse = styled(ButtonLabel) ``;
|
|
272
259
|
export const RadioButtonField = ({ label, inputProps, name, className, }) => {
|
|
273
|
-
|
|
274
|
-
return (_jsxs(RadioButtonFieldContainer, { className: className, children: [_jsxs(RadioButtonFieldElement, { children: [_jsx(RadioButtonFieldInput, Object.assign({}, inputProps, { name: name, type: "radio", value: "true" })), _jsx(ButtonLabelTrue, { children: (_a = label === null || label === void 0 ? void 0 : label.true) !== null && _a !== void 0 ? _a : "true" })] }), _jsxs(RadioButtonFieldElement, { children: [_jsx(RadioButtonFieldInput, Object.assign({}, inputProps, { name: name, type: "radio", value: "false" })), _jsx(ButtonLabelFalse, { children: (_b = label === null || label === void 0 ? void 0 : label.false) !== null && _b !== void 0 ? _b : "false" })] })] }));
|
|
260
|
+
return (_jsxs(RadioButtonFieldContainer, { className: className, children: [_jsxs(RadioButtonFieldElement, { children: [_jsx(RadioButtonFieldInput, { ...inputProps, name: name, type: "radio", value: "true" }), _jsx(ButtonLabelTrue, { children: label?.true ?? "true" })] }), _jsxs(RadioButtonFieldElement, { children: [_jsx(RadioButtonFieldInput, { ...inputProps, name: name, type: "radio", value: "false" }), _jsx(ButtonLabelFalse, { children: label?.false ?? "false" })] })] }));
|
|
275
261
|
};
|
|
276
262
|
RadioButtonField.styles = {
|
|
277
263
|
RadioButtonFieldContainerStyle: RadioButtonFieldContainer,
|
|
@@ -303,15 +289,15 @@ export const MultipleChoiceField = ({ inputProps, name, className, enums, style,
|
|
|
303
289
|
const newValue = isChecked(optionValue)
|
|
304
290
|
? currentValue.filter((v) => v !== optionValue)
|
|
305
291
|
: [...currentValue, optionValue];
|
|
306
|
-
form
|
|
292
|
+
form?.setFieldValue(name, newValue);
|
|
307
293
|
}
|
|
308
294
|
else {
|
|
309
|
-
form
|
|
295
|
+
form?.setFieldValue(name, optionValue);
|
|
310
296
|
}
|
|
311
297
|
};
|
|
312
|
-
return (_jsx(MultipleChoiceFieldContainer, { className: className, style: getStyle(style
|
|
298
|
+
return (_jsx(MultipleChoiceFieldContainer, { className: className, style: getStyle(style ?? ""), children: enums.values.map((v) => {
|
|
313
299
|
const optionValue = v.const;
|
|
314
|
-
return (_jsxs(MultipleChoiceFieldElement, { "data-fjsf-enum-value": optionValue, children: [_jsx(MultipleChoiceFieldInput,
|
|
300
|
+
return (_jsxs(MultipleChoiceFieldElement, { "data-fjsf-enum-value": optionValue, children: [_jsx(MultipleChoiceFieldInput, { ...inputProps, name: name, type: isMultiSelect ? "checkbox" : "radio", value: optionValue !== undefined ? optionValue.toString() : "", checked: isChecked(optionValue), onChange: () => handleChange(optionValue) }), _jsx(MultipleChoiceFieldLabel, { children: v.title })] }, optionValue !== undefined ? optionValue.toString() : "undefined"));
|
|
315
301
|
}) }));
|
|
316
302
|
};
|
|
317
303
|
MultipleChoiceField.styles = {
|
|
@@ -380,24 +366,21 @@ export const MultiSelectOptionListWithoutItem = styled.li `
|
|
|
380
366
|
export const SearchableMultiTagSelectField = ({ name, placeholder, enums, emptySearchMessage, closeElement, className, }) => {
|
|
381
367
|
const [search, setSearch] = useState("");
|
|
382
368
|
const searchIncludedInEnum = () => {
|
|
383
|
-
const hasValue = enums
|
|
384
|
-
return hasValue
|
|
369
|
+
const hasValue = enums?.values.map((value) => value.title.toLowerCase().includes(search.toLowerCase()));
|
|
370
|
+
return hasValue?.includes(true);
|
|
385
371
|
};
|
|
386
|
-
return (_jsx(formik.Field, { className: className, name: name, multiple: true, children: ({ field, form: { setFieldValue }, meta, }) => {
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
return (_jsxs(MultiSelectBadge, { children: [(_a = enums === null || enums === void 0 ? void 0 : enums.values.find((option) => option.const === value)) === null || _a === void 0 ? void 0 : _a.title, _jsx(MultiSelectBadgeCloseElement, { onClick: () => setFieldValue(name, field.value.filter((v) => v !== value)), children: closeElement !== null && closeElement !== void 0 ? closeElement : "x" })] }, value));
|
|
399
|
-
}) }), meta.touched && meta.error && (_jsx("div", { className: "error", children: meta.error }))] }));
|
|
400
|
-
} }));
|
|
372
|
+
return (_jsx(formik.Field, { className: className, name: name, multiple: true, children: ({ field, form: { setFieldValue }, meta, }) => (_jsxs(MultiSelectContainer, { className: className, children: [_jsx(FieldInput, { id: className, type: "hidden", ...field }), _jsxs(MultiSelectSearchContainer, { children: [_jsx(MultiSelectInput, { id: className + "_id", className: className, type: "text", onChange: (e) => {
|
|
373
|
+
setSearch(e.currentTarget.value);
|
|
374
|
+
}, placeholder: placeholder, value: search }), search.length > 0 && (_jsx(MultiSelectOptionList, { children: searchIncludedInEnum() ? (enums?.values
|
|
375
|
+
.filter((item) => !(field.value ?? []).includes(item.const))
|
|
376
|
+
.filter((value) => value.title.toLowerCase().includes(search.toLowerCase()))
|
|
377
|
+
.map((option, index) => (_jsx(MultiSelectOptionListItem, { value: option.const, onClick: () => {
|
|
378
|
+
setFieldValue(name, [
|
|
379
|
+
...new Set([...(field.value ?? []), option.const]),
|
|
380
|
+
]);
|
|
381
|
+
setSearch("");
|
|
382
|
+
}, children: option.title }, index)))) : (_jsx(MultiSelectOptionListWithoutItem, { children: emptySearchMessage ?? "No match found" })) }))] }), _jsx(MultiSelectBadgeContainer, { children: (field.value ?? []).map((value) => (_jsxs(MultiSelectBadge, { children: [enums?.values.find((option) => option.const === value)
|
|
383
|
+
?.title, _jsx(MultiSelectBadgeCloseElement, { onClick: () => setFieldValue(name, field.value.filter((v) => v !== value)), children: closeElement ?? "x" })] }, value))) }), meta.touched && meta.error && (_jsx("div", { className: "error", children: meta.error }))] })) }));
|
|
401
384
|
};
|
|
402
385
|
SearchableMultiTagSelectField.styles = {
|
|
403
386
|
MultiSelectContainerStyle: MultiSelectContainer,
|
|
@@ -415,7 +398,7 @@ export const TextAreaFieldInput = styled(FieldInput) `
|
|
|
415
398
|
min-height: 5rem;
|
|
416
399
|
`;
|
|
417
400
|
export const TextAreaInputField = ({ inputProps, name, className, }) => {
|
|
418
|
-
return _jsx(TextAreaFieldInput,
|
|
401
|
+
return _jsx(TextAreaFieldInput, { ...inputProps, name: name, formikAs: "textarea" });
|
|
419
402
|
};
|
|
420
403
|
export const BooleanFieldWrapper = styled.div `
|
|
421
404
|
display: flex;
|
|
@@ -531,17 +514,11 @@ const NotSelectedCircle = styled.span `
|
|
|
531
514
|
width: 1rem;
|
|
532
515
|
`;
|
|
533
516
|
export const MultipleChoiceFieldPdf = ({ inputProps, name, className, style, selected, notSelected, }) => {
|
|
534
|
-
return (_jsxs(MultipleChoiceFieldContainer, { className: className, style: getStyle(style
|
|
517
|
+
return (_jsxs(MultipleChoiceFieldContainer, { className: className, style: getStyle(style ?? ""), children: [!selected && !notSelected && _jsx(_Fragment, { children: "Nothing was selected" }), selected &&
|
|
535
518
|
selected.length > 0 &&
|
|
536
|
-
selected.map((s) => {
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
}), notSelected &&
|
|
540
|
-
(notSelected === null || notSelected === void 0 ? void 0 : notSelected.length) > 0 &&
|
|
541
|
-
notSelected.map((n) => {
|
|
542
|
-
var _a;
|
|
543
|
-
return (_jsx(MultipleChoiceFieldElement, { children: _jsxs(NotSelected, { children: [_jsx(NotSelectedCircle, { children: "\u2715" }), _jsx(MultipleChoiceFieldLabel, { children: n.title })] }) }, (_a = n.title) !== null && _a !== void 0 ? _a : n));
|
|
544
|
-
})] }));
|
|
519
|
+
selected.map((s) => (_jsx(MultipleChoiceFieldElement, { children: _jsxs(Selected, { children: [_jsx(SelectedBox, { children: "\u2713" }), _jsx(MultipleChoiceFieldLabel, { children: s.title ?? "Hello" })] }) }, s.title ?? s))), notSelected &&
|
|
520
|
+
notSelected?.length > 0 &&
|
|
521
|
+
notSelected.map((n) => (_jsx(MultipleChoiceFieldElement, { children: _jsxs(NotSelected, { children: [_jsx(NotSelectedCircle, { children: "\u2715" }), _jsx(MultipleChoiceFieldLabel, { children: n.title })] }) }, n.title ?? n)))] }));
|
|
545
522
|
};
|
|
546
523
|
// --> FileUploadField
|
|
547
524
|
export const FileUploadButton = styled.button `
|
|
@@ -597,14 +574,17 @@ export const FileInfoText = styled.span `
|
|
|
597
574
|
`;
|
|
598
575
|
export const FileUploadFieldContainer = styled.div ``;
|
|
599
576
|
export const FileUploadField = ({ name, uploadedFile, handleFileUpload, value, setFieldValue, className, uploadProgress, handleRemoveFile, removeButton, uploadButtonText, infoText, hideRemoveButton, }) => {
|
|
600
|
-
|
|
601
|
-
return (_jsxs(FileUploadFieldContainer, { className: className, children: [_jsxs("div", { children: [_jsx(FileUploadButton, { type: "button", onClick: () => { var _a; return (_a = document.getElementById(name)) === null || _a === void 0 ? void 0 : _a.click(); }, children: uploadButtonText !== null && uploadButtonText !== void 0 ? uploadButtonText : "Choose File" }), _jsx(HiddenFileInput, { id: name, name: name, type: "file", onChange: (event) => {
|
|
577
|
+
return (_jsxs(FileUploadFieldContainer, { className: className, children: [_jsxs("div", { children: [_jsx(FileUploadButton, { type: "button", onClick: () => document.getElementById(name)?.click(), children: uploadButtonText ?? "Choose File" }), _jsx(HiddenFileInput, { id: name, name: name, type: "file", onChange: (event) => {
|
|
602
578
|
const file = event.currentTarget.files[0];
|
|
603
579
|
if (file) {
|
|
604
580
|
handleFileUpload(file, setFieldValue);
|
|
605
581
|
event.target.value = null;
|
|
606
582
|
}
|
|
607
|
-
} }), !value ? (_jsx(FileInfoText, { children: infoText
|
|
583
|
+
} }), !value ? (_jsx(FileInfoText, { children: infoText ?? "No file chosen" })) : null] }), uploadedFile && value && (_jsx(FileItemContainer, { children: uploadProgress === 100 ? (_jsxs(_Fragment, { children: [_jsx("span", { children: uploadedFile.name }), !hideRemoveButton && (_jsx(RemoveButton, { type: "button", onClick: () => handleRemoveFile(setFieldValue), ...removeButton?.props, style: {
|
|
584
|
+
color: "red",
|
|
585
|
+
fontWeight: "bold",
|
|
586
|
+
...(removeButton?.props?.style ?? {}),
|
|
587
|
+
}, children: removeButton?.content ?? "X" }))] })) : (_jsxs(_Fragment, { children: [_jsx("span", { children: uploadedFile.name }), _jsxs(ProgressBarContainer, { children: [_jsx(ProgressBar, { "$progress": uploadProgress }), _jsxs(ProgressText, { children: [uploadProgress, "%"] })] })] })) }))] }));
|
|
608
588
|
};
|
|
609
589
|
FileUploadField.styles = {
|
|
610
590
|
FileUploadFieldFileUploadFieldContainerStyle: FileUploadFieldContainer,
|
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
-
var t = {};
|
|
3
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
-
t[p] = s[p];
|
|
5
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
-
t[p[i]] = s[p[i]];
|
|
9
|
-
}
|
|
10
|
-
return t;
|
|
11
|
-
};
|
|
12
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
2
|
import { useContext } from "react";
|
|
14
3
|
import { FormRegistry } from "../Form";
|
|
@@ -18,7 +7,7 @@ import { RequiredIndicator } from "../styledComponents";
|
|
|
18
7
|
import { getIn, useFormikContext } from "formik";
|
|
19
8
|
export const ArrayFieldTemplate = (props) => {
|
|
20
9
|
const { components: { ArrayFieldWrapper, ArrayFieldTitle, FieldDescription, ErrorMessage, FieldHelp, InfoFieldButton, }, } = useContext(FormRegistry);
|
|
21
|
-
const { name, uiSchema, children
|
|
10
|
+
const { name, uiSchema, children, ...otherProps } = props;
|
|
22
11
|
const title = getTitle(props);
|
|
23
12
|
const description = getDescription(props);
|
|
24
13
|
const { help, info,
|
|
@@ -30,7 +19,10 @@ export const ArrayFieldTemplate = (props) => {
|
|
|
30
19
|
acc[key] = otherProps[key];
|
|
31
20
|
return acc;
|
|
32
21
|
}, {});
|
|
33
|
-
const mergedWrapperProps =
|
|
22
|
+
const mergedWrapperProps = {
|
|
23
|
+
...wrapperProps,
|
|
24
|
+
...dataAttributes,
|
|
25
|
+
};
|
|
34
26
|
// These lines make sure the error message is a string, which means the error
|
|
35
27
|
// is actually for the whole Array component, not for one of the children.
|
|
36
28
|
const { errors } = useFormikContext();
|
|
@@ -38,5 +30,5 @@ export const ArrayFieldTemplate = (props) => {
|
|
|
38
30
|
// In case of array of objects, it will give error message as an object value,
|
|
39
31
|
// which is incorrect value for React, causing UI to crash.
|
|
40
32
|
const errorIsString = typeof error === "string";
|
|
41
|
-
return (_jsxs(ArrayFieldWrapper,
|
|
33
|
+
return (_jsxs(ArrayFieldWrapper, { ...mergedWrapperProps, children: [title && (_jsxs(ArrayFieldTitle, { ...titleProps, htmlFor: name, children: [title, props?.required && _jsx(RequiredIndicator, { children: "*" })] })), info && _jsx(InfoFieldButton, { ...info }), description && (_jsx(FieldDescription, { ...descriptionProps, children: description })), children, help && _jsx(FieldHelp, { ...helpProps, children: help }), errorIsString && _jsx(ErrorMessage, { ...errorProps, name: name })] }));
|
|
42
34
|
};
|
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
-
var t = {};
|
|
3
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
-
t[p] = s[p];
|
|
5
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
-
t[p[i]] = s[p[i]];
|
|
9
|
-
}
|
|
10
|
-
return t;
|
|
11
|
-
};
|
|
12
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
2
|
import { useContext, useState } from "react";
|
|
14
3
|
import { FormRegistry } from "../Form";
|
|
@@ -17,7 +6,7 @@ import { useExtractUiSchema } from "../hooks";
|
|
|
17
6
|
import { CollapsibleChildWrapper, CollapsibleToggle, Icon, RequiredIndicator, } from "../styledComponents";
|
|
18
7
|
export const CollapsibleObjectFieldTemplate = (props) => {
|
|
19
8
|
const { components: { FieldDescription, CollapsibleObjectFieldTitle, CollapsibleObjectFieldWrapper, FieldHelp, InfoFieldButton, }, } = useContext(FormRegistry);
|
|
20
|
-
const { children, name, uiSchema
|
|
9
|
+
const { children, name, uiSchema, ...otherProps } = props;
|
|
21
10
|
const title = getTitle(props);
|
|
22
11
|
const description = getDescription(props);
|
|
23
12
|
const { help, info,
|
|
@@ -31,8 +20,11 @@ export const CollapsibleObjectFieldTemplate = (props) => {
|
|
|
31
20
|
acc[key] = otherProps[key];
|
|
32
21
|
return acc;
|
|
33
22
|
}, {});
|
|
34
|
-
const mergedWrapperProps =
|
|
23
|
+
const mergedWrapperProps = {
|
|
24
|
+
...wrapperProps,
|
|
25
|
+
...dataAttributes,
|
|
26
|
+
};
|
|
35
27
|
const [collapsed, setCollapsed] = useState(isCollapsedOnLoad);
|
|
36
28
|
const hide = collapsed;
|
|
37
|
-
return (_jsxs(CollapsibleObjectFieldWrapper,
|
|
29
|
+
return (_jsxs(CollapsibleObjectFieldWrapper, { ...mergedWrapperProps, children: [title && (_jsx(CollapsibleToggle, { onClick: () => setCollapsed(!collapsed), ariaExpanded: !hide, ariaLabel: ariaLabel ?? name, children: _jsxs(CollapsibleObjectFieldTitle, { style: { display: "flex", alignItems: "center" }, ...titleProps, children: [title, props?.required && _jsx(RequiredIndicator, { children: "*" }), _jsx(Icon, { children: hide ? collapsedIcon ?? "▸" : openIcon ?? "▾" })] }) })), info && _jsx(InfoFieldButton, { ...info }), description && (_jsx(FieldDescription, { ...descriptionProps, children: description })), !hide && _jsx(CollapsibleChildWrapper, { children: children }), help && _jsx(FieldHelp, { ...helpProps, children: help })] }));
|
|
38
30
|
};
|
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
-
var t = {};
|
|
3
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
-
t[p] = s[p];
|
|
5
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
-
t[p[i]] = s[p[i]];
|
|
9
|
-
}
|
|
10
|
-
return t;
|
|
11
|
-
};
|
|
12
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
2
|
import { useContext } from "react";
|
|
14
3
|
import { FormRegistry } from "../Form";
|
|
@@ -16,7 +5,7 @@ import { getDescription, getTitle } from "../utils";
|
|
|
16
5
|
import { useExtractUiSchema } from "../hooks";
|
|
17
6
|
export const FieldTemplate = (props) => {
|
|
18
7
|
const { components: { FieldWrapper, FieldTitle, FieldDescription, ErrorMessage, FieldHelp, RequiredIndicator, InfoFieldButton, }, } = useContext(FormRegistry);
|
|
19
|
-
const { name, uiSchema, children
|
|
8
|
+
const { name, uiSchema, children, ...otherProps } = props;
|
|
20
9
|
const title = getTitle(props);
|
|
21
10
|
const description = getDescription(props);
|
|
22
11
|
const { help, info, props: { wrapper: wrapperProps = {}, title: titleProps, description: descriptionProps, help: helpProps, error: errorProps, } = {}, } = useExtractUiSchema(uiSchema);
|
|
@@ -27,6 +16,9 @@ export const FieldTemplate = (props) => {
|
|
|
27
16
|
return acc;
|
|
28
17
|
}, {});
|
|
29
18
|
// Merge the wrapperProps with the filtered dataAttributes
|
|
30
|
-
const mergedWrapperProps =
|
|
31
|
-
|
|
19
|
+
const mergedWrapperProps = {
|
|
20
|
+
...wrapperProps,
|
|
21
|
+
...dataAttributes, // This will only include data-* attributes
|
|
22
|
+
};
|
|
23
|
+
return (_jsxs(FieldWrapper, { ...mergedWrapperProps, children: [title && (_jsxs(FieldTitle, { ...titleProps, htmlFor: name, children: [title, props.required && _jsx(RequiredIndicator, { children: "*" })] })), info && _jsx(InfoFieldButton, { ...info }), description && (_jsx(FieldDescription, { ...descriptionProps, children: description })), children, help && _jsx(FieldHelp, { ...helpProps, children: help }), _jsx(ErrorMessage, { ...errorProps, name: name })] }));
|
|
32
24
|
};
|
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
-
var t = {};
|
|
3
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
-
t[p] = s[p];
|
|
5
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
-
t[p[i]] = s[p[i]];
|
|
9
|
-
}
|
|
10
|
-
return t;
|
|
11
|
-
};
|
|
12
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
2
|
import { useContext } from "react";
|
|
14
3
|
import { FormRegistry } from "../Form";
|
|
@@ -17,7 +6,7 @@ import { useExtractUiSchema } from "../hooks";
|
|
|
17
6
|
import { RequiredIndicator } from "../styledComponents";
|
|
18
7
|
export const ObjectFieldTemplate = (props) => {
|
|
19
8
|
const { components: { FieldDescription, ObjectFieldTitle, ObjectFieldWrapper, FieldHelp, InfoFieldButton, }, } = useContext(FormRegistry);
|
|
20
|
-
const { children, uiSchema
|
|
9
|
+
const { children, uiSchema, ...otherProps } = props;
|
|
21
10
|
const title = getTitle(props);
|
|
22
11
|
const description = getDescription(props);
|
|
23
12
|
const { help, info,
|
|
@@ -31,6 +20,9 @@ export const ObjectFieldTemplate = (props) => {
|
|
|
31
20
|
acc[key] = otherProps[key];
|
|
32
21
|
return acc;
|
|
33
22
|
}, {});
|
|
34
|
-
const mergedWrapperProps =
|
|
35
|
-
|
|
23
|
+
const mergedWrapperProps = {
|
|
24
|
+
...wrapperProps,
|
|
25
|
+
...dataAttributes,
|
|
26
|
+
};
|
|
27
|
+
return (_jsxs(ObjectFieldWrapper, { ...mergedWrapperProps, children: [title && (_jsxs(ObjectFieldTitle, { ...titleProps, children: [title, props?.required && _jsx(RequiredIndicator, { children: "*" })] })), info && _jsx(InfoFieldButton, { ...info }), description && (_jsx(FieldDescription, { ...descriptionProps, children: description })), children, help && _jsx(FieldHelp, { ...helpProps, children: help })] }));
|
|
36
28
|
};
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import { ageFieldDefinition } from "../../sampleData/ageFieldDefinition";
|
|
11
2
|
import { createInitialValues } from "../createInitialValues";
|
|
12
3
|
const exampleSchema = {
|
|
@@ -60,7 +51,7 @@ const exampleSchema = {
|
|
|
60
51
|
},
|
|
61
52
|
};
|
|
62
53
|
describe("Create Initial Values", () => {
|
|
63
|
-
it("creates for an object type", () =>
|
|
54
|
+
it("creates for an object type", async () => {
|
|
64
55
|
const result = createInitialValues(exampleSchema);
|
|
65
56
|
const expected = {
|
|
66
57
|
name: "",
|
|
@@ -109,5 +100,5 @@ describe("Create Initial Values", () => {
|
|
|
109
100
|
},
|
|
110
101
|
},
|
|
111
102
|
};
|
|
112
|
-
})
|
|
103
|
+
});
|
|
113
104
|
});
|