@nolwenture/formik-jsonschema-form 0.4.2 → 0.6.0
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 +187 -0
- package/dist/Form.d.ts +2 -2
- package/dist/Form.js +15 -26
- package/dist/Form.stories.d.ts +12 -11
- package/dist/Form.stories.js +134 -101
- package/dist/Form.test.js +3 -3
- package/dist/FormEditor.d.ts +3 -3
- package/dist/FormEditor.js +14 -59
- package/dist/FormEditor.stories.d.ts +5 -4
- package/dist/FormEditor.stories.js +3 -16
- package/dist/fields/AnyField.d.ts +3 -3
- package/dist/fields/AnyField.js +12 -24
- package/dist/fields/ArrayField.d.ts +3 -3
- package/dist/fields/ArrayField.js +42 -64
- package/dist/fields/BooleanField.d.ts +3 -3
- package/dist/fields/BooleanField.js +7 -18
- package/dist/fields/DateField.d.ts +3 -3
- package/dist/fields/DateField.js +7 -18
- package/dist/fields/NullField.d.ts +3 -3
- package/dist/fields/NullField.js +5 -16
- package/dist/fields/NumberField.d.ts +3 -3
- package/dist/fields/NumberField.js +3 -14
- package/dist/fields/ObjectField.d.ts +3 -3
- package/dist/fields/ObjectField.js +43 -46
- package/dist/fields/RadioField.d.ts +3 -0
- package/dist/fields/RadioField.js +11 -0
- package/dist/fields/SchemaField.d.ts +3 -3
- package/dist/fields/SchemaField.js +13 -23
- package/dist/fields/SearchMultiTagSelectField.d.ts +3 -0
- package/dist/fields/SearchMultiTagSelectField.js +14 -0
- package/dist/fields/StringField.d.ts +3 -3
- package/dist/fields/StringField.js +13 -51
- package/dist/fields/ToggleField.d.ts +3 -0
- package/dist/fields/ToggleField.js +11 -0
- package/dist/fields/index.d.ts +3 -0
- package/dist/fields/index.js +3 -0
- package/dist/fields/types.js +1 -1
- package/dist/formEditorSchemas.d.ts +1 -1
- package/dist/formEditorSchemas.js +3 -3
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/index.js +2 -0
- package/dist/hooks/useExtractUiSchema.d.ts +8 -0
- package/dist/hooks/useExtractUiSchema.js +22 -0
- package/dist/hooks/useSetDefault.d.ts +2 -0
- package/dist/hooks/useSetDefault.js +16 -0
- package/dist/sampleData/completeSchema.d.ts +3 -0
- package/dist/{_sampleData.js → sampleData/completeSchema.js} +28 -97
- package/dist/sampleData/conditionsSchema.d.ts +3 -0
- package/dist/sampleData/conditionsSchema.js +80 -0
- package/dist/sampleData/generatedSchema.d.ts +2 -0
- package/dist/sampleData/generatedSchema.js +19 -0
- package/dist/sampleData/index.d.ts +5 -0
- package/dist/sampleData/index.js +5 -0
- package/dist/sampleData/requiredInputSchema.d.ts +3 -0
- package/dist/sampleData/requiredInputSchema.js +72 -0
- package/dist/sampleData/simpleData.d.ts +7 -0
- package/dist/sampleData/simpleData.js +16 -0
- package/dist/styledComponents.d.ts +193 -47
- package/dist/styledComponents.js +342 -138
- package/dist/templates/ArrayFieldTemplate.d.ts +3 -3
- package/dist/templates/ArrayFieldTemplate.js +11 -23
- package/dist/templates/FieldTemplate.d.ts +3 -3
- package/dist/templates/FieldTemplate.js +11 -23
- package/dist/templates/ObjectFieldTemplate.d.ts +3 -3
- package/dist/templates/ObjectFieldTemplate.js +13 -23
- package/dist/types.d.ts +34 -3
- package/dist/utils/__tests/getEnums.test.d.ts +1 -0
- package/dist/utils/__tests/getEnums.test.js +64 -0
- package/dist/utils/__tests/resolveSchema.test.d.ts +1 -0
- package/dist/utils/__tests/resolveSchema.test.js +106 -0
- package/dist/utils/deepEqual.d.ts +1 -0
- package/dist/utils/deepEqual.js +18 -0
- package/dist/utils/getEnums.d.ts +10 -0
- package/dist/utils/getEnums.js +30 -0
- package/dist/utils/getTitleAndDescription.d.ts +12 -0
- package/dist/utils/getTitleAndDescription.js +15 -0
- package/dist/utils/getTypes.d.ts +5 -0
- package/dist/utils/getTypes.js +53 -0
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/index.js +14 -0
- package/dist/utils/mergeSchemas.d.ts +1 -0
- package/dist/utils/mergeSchemas.js +26 -0
- package/dist/utils/resolveSchema.d.ts +2 -0
- package/dist/utils/resolveSchema.js +68 -0
- package/package.json +32 -37
- package/dist/_sampleData.d.ts +0 -11
- package/dist/utils.d.ts +0 -25
- package/dist/utils.js +0 -125
package/dist/styledComponents.js
CHANGED
|
@@ -1,18 +1,3 @@
|
|
|
1
|
-
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
|
|
2
|
-
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
|
3
|
-
return cooked;
|
|
4
|
-
};
|
|
5
|
-
var __assign = (this && this.__assign) || function () {
|
|
6
|
-
__assign = Object.assign || function(t) {
|
|
7
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
8
|
-
s = arguments[i];
|
|
9
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
10
|
-
t[p] = s[p];
|
|
11
|
-
}
|
|
12
|
-
return t;
|
|
13
|
-
};
|
|
14
|
-
return __assign.apply(this, arguments);
|
|
15
|
-
};
|
|
16
1
|
var __rest = (this && this.__rest) || function (s, e) {
|
|
17
2
|
var t = {};
|
|
18
3
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
@@ -25,140 +10,187 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
25
10
|
return t;
|
|
26
11
|
};
|
|
27
12
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
import { useContext, useState } from "react";
|
|
28
14
|
import styled from "styled-components";
|
|
29
15
|
import * as formik from "formik";
|
|
30
|
-
import { ArrayFieldButtonPurpose, ObjectFieldButtonPurpose, } from "./types";
|
|
31
|
-
import { useContext } from "react";
|
|
32
16
|
import { FormRegistry } from "./Form";
|
|
33
|
-
|
|
34
|
-
export
|
|
35
|
-
export
|
|
36
|
-
export
|
|
37
|
-
export
|
|
38
|
-
export
|
|
39
|
-
export
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
export
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
export
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
17
|
+
import { ArrayFieldButtonPurpose, ObjectFieldButtonPurpose } from "./types";
|
|
18
|
+
export const Form = styled(formik.Form) ``;
|
|
19
|
+
export const FormButtonWrapper = styled.div ``;
|
|
20
|
+
export const FormButton = styled.button ``;
|
|
21
|
+
export const ObjectFieldWrapper = styled.fieldset ``;
|
|
22
|
+
export const ObjectFieldTitle = styled.legend ``;
|
|
23
|
+
export const ObjectFieldList = styled.ul `
|
|
24
|
+
list-style-type: none;
|
|
25
|
+
padding: 0;
|
|
26
|
+
`;
|
|
27
|
+
export const ObjectFieldItem = styled.li `
|
|
28
|
+
display: flex;
|
|
29
|
+
`;
|
|
30
|
+
export const ObjectFieldItemButtons = styled.div `
|
|
31
|
+
display: flex;
|
|
32
|
+
margin: 0.5rem;
|
|
33
|
+
`;
|
|
34
|
+
export const ObjectFieldButton = styled.a `
|
|
35
|
+
cursor: pointer;
|
|
36
|
+
border: 1px solid black;
|
|
37
|
+
line-height: 1em;
|
|
38
|
+
height: 1em;
|
|
39
|
+
padding: 0 0.3em;
|
|
40
|
+
`;
|
|
41
|
+
export const ObjectFieldLineButton = styled(ObjectFieldButton) ``;
|
|
42
|
+
export const ObjectFieldUpButton = styled(ObjectFieldLineButton) ``;
|
|
43
|
+
export const ObjectFieldDownButton = styled(ObjectFieldLineButton) ``;
|
|
44
|
+
export const ObjectFieldRemoveButton = styled(ObjectFieldLineButton) ``;
|
|
45
|
+
export const ObjectFieldAddButton = styled(ObjectFieldButton) ``;
|
|
46
|
+
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;
|
|
50
48
|
switch (purpose) {
|
|
51
49
|
case ObjectFieldButtonPurpose.ADD:
|
|
52
|
-
return (_jsx(ObjectFieldAddButton,
|
|
50
|
+
return (_jsx(ObjectFieldAddButton, Object.assign({}, ((_b = (_a = uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema["ui:addButtonOptions"]) === null || _a === void 0 ? void 0 : _a.props) !== null && _b !== void 0 ? _b : {}), { onClick: onClick, children: (_d = (_c = uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema["ui:addButtonOptions"]) === null || _c === void 0 ? void 0 : _c.content) !== null && _d !== void 0 ? _d : "+" })));
|
|
53
51
|
case ObjectFieldButtonPurpose.REMOVE:
|
|
54
|
-
return (_jsx(ObjectFieldRemoveButton,
|
|
52
|
+
return (_jsx(ObjectFieldRemoveButton, Object.assign({}, ((_f = (_e = uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema["ui:removeButtonOptions"]) === null || _e === void 0 ? void 0 : _e.props) !== null && _f !== void 0 ? _f : {}), { onClick: onClick, children: (_h = (_g = uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema["ui:removeButtonOptions"]) === null || _g === void 0 ? void 0 : _g.content) !== null && _h !== void 0 ? _h : "-" })));
|
|
55
53
|
case ObjectFieldButtonPurpose.MOVE_UP:
|
|
56
|
-
return (_jsx(ObjectFieldUpButton,
|
|
54
|
+
return (_jsx(ObjectFieldUpButton, Object.assign({}, ((_k = (_j = uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema["ui:upButtonOptions"]) === null || _j === void 0 ? void 0 : _j.props) !== null && _k !== void 0 ? _k : {}), { onClick: onClick, children: (_m = (_l = uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema["ui:upButtonOptions"]) === null || _l === void 0 ? void 0 : _l.content) !== null && _m !== void 0 ? _m : "↑" })));
|
|
57
55
|
case ObjectFieldButtonPurpose.MOVE_DOWN:
|
|
58
|
-
return (_jsx(ObjectFieldDownButton,
|
|
56
|
+
return (_jsx(ObjectFieldDownButton, Object.assign({}, ((_p = (_o = uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema["ui:downButtonOptions"]) === null || _o === void 0 ? void 0 : _o.props) !== null && _p !== void 0 ? _p : {}), { onClick: onClick, children: (_r = (_q = uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema["ui:downButtonOptions"]) === null || _q === void 0 ? void 0 : _q.content) !== null && _r !== void 0 ? _r : "↓" })));
|
|
59
57
|
default:
|
|
60
|
-
return (_jsx(ObjectFieldButton,
|
|
58
|
+
return (_jsx(ObjectFieldButton, Object.assign({}, ((_t = (_s = uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema["ui:customButtonOptions"]) === null || _s === void 0 ? void 0 : _s.props) !== null && _t !== void 0 ? _t : {}), { onClick: onClick, children: (_v = (_u = uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema["ui:customButtonOptions"]) === null || _u === void 0 ? void 0 : _u.content) !== null && _v !== void 0 ? _v : "" })));
|
|
61
59
|
}
|
|
62
|
-
}
|
|
63
|
-
export
|
|
64
|
-
export
|
|
65
|
-
export
|
|
66
|
-
export
|
|
67
|
-
export
|
|
68
|
-
export
|
|
69
|
-
export
|
|
70
|
-
export
|
|
71
|
-
export
|
|
72
|
-
export
|
|
73
|
-
export
|
|
74
|
-
export
|
|
75
|
-
var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v
|
|
76
|
-
|
|
77
|
-
var _x = useContext(FormRegistry).components, ArrayFieldAddButton = _x.ArrayFieldAddButton, ArrayFieldRemoveButton = _x.ArrayFieldRemoveButton, ArrayFieldUpButton = _x.ArrayFieldUpButton, ArrayFieldDownButton = _x.ArrayFieldDownButton;
|
|
60
|
+
};
|
|
61
|
+
export const ArrayFieldWrapper = ObjectFieldWrapper;
|
|
62
|
+
export const ArrayFieldTitle = ObjectFieldTitle;
|
|
63
|
+
export const ArrayFieldList = ObjectFieldList;
|
|
64
|
+
export const ArrayFieldItem = ObjectFieldItem;
|
|
65
|
+
export const ArrayFieldItemButtons = ObjectFieldItemButtons;
|
|
66
|
+
export const ArrayFieldButton = styled(ObjectFieldButton) ``;
|
|
67
|
+
export const ArrayFieldLineButton = styled(ArrayFieldButton) ``;
|
|
68
|
+
export const ArrayFieldUpButton = styled(ArrayFieldLineButton) ``;
|
|
69
|
+
export const ArrayFieldDownButton = styled(ArrayFieldLineButton) ``;
|
|
70
|
+
export const ArrayFieldRemoveButton = styled(ArrayFieldLineButton) ``;
|
|
71
|
+
export const ArrayFieldAddButton = styled(ArrayFieldButton) ``;
|
|
72
|
+
export const GetArrayFieldButton = ({ purpose, onClick, uiSchema, }) => {
|
|
73
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
74
|
+
const { components: { ArrayFieldAddButton, ArrayFieldRemoveButton, ArrayFieldUpButton, ArrayFieldDownButton, }, } = useContext(FormRegistry);
|
|
78
75
|
switch (purpose) {
|
|
79
76
|
case ArrayFieldButtonPurpose.ADD:
|
|
80
|
-
return (_jsx(ArrayFieldAddButton,
|
|
77
|
+
return (_jsx(ArrayFieldAddButton, Object.assign({}, ((_b = (_a = uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema["ui:addButtonOptions"]) === null || _a === void 0 ? void 0 : _a.props) !== null && _b !== void 0 ? _b : {}), { onClick: onClick, children: (_d = (_c = uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema["ui:addButtonOptions"]) === null || _c === void 0 ? void 0 : _c.content) !== null && _d !== void 0 ? _d : "+" })));
|
|
81
78
|
case ArrayFieldButtonPurpose.REMOVE:
|
|
82
|
-
return (_jsx(ArrayFieldRemoveButton,
|
|
79
|
+
return (_jsx(ArrayFieldRemoveButton, Object.assign({}, ((_f = (_e = uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema["ui:removeButtonOptions"]) === null || _e === void 0 ? void 0 : _e.props) !== null && _f !== void 0 ? _f : {}), { onClick: onClick, children: (_h = (_g = uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema["ui:removeButtonOptions"]) === null || _g === void 0 ? void 0 : _g.content) !== null && _h !== void 0 ? _h : "-" })));
|
|
83
80
|
case ArrayFieldButtonPurpose.MOVE_UP:
|
|
84
|
-
return (_jsx(ArrayFieldUpButton,
|
|
81
|
+
return (_jsx(ArrayFieldUpButton, Object.assign({}, ((_k = (_j = uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema["ui:upButtonOptions"]) === null || _j === void 0 ? void 0 : _j.props) !== null && _k !== void 0 ? _k : {}), { onClick: onClick, children: (_m = (_l = uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema["ui:upButtonOptions"]) === null || _l === void 0 ? void 0 : _l.content) !== null && _m !== void 0 ? _m : "↑" })));
|
|
85
82
|
case ArrayFieldButtonPurpose.MOVE_DOWN:
|
|
86
|
-
return (_jsx(ArrayFieldDownButton,
|
|
83
|
+
return (_jsx(ArrayFieldDownButton, Object.assign({}, ((_p = (_o = uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema["ui:downButtonOptions"]) === null || _o === void 0 ? void 0 : _o.props) !== null && _p !== void 0 ? _p : {}), { onClick: onClick, children: (_r = (_q = uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema["ui:downButtonOptions"]) === null || _q === void 0 ? void 0 : _q.content) !== null && _r !== void 0 ? _r : "↓" })));
|
|
87
84
|
default:
|
|
88
|
-
return (_jsx(ArrayFieldButton,
|
|
85
|
+
return (_jsx(ArrayFieldButton, Object.assign({}, ((_t = (_s = uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema["ui:customButtonOptions"]) === null || _s === void 0 ? void 0 : _s.props) !== null && _t !== void 0 ? _t : {}), { onClick: onClick, children: (_v = (_u = uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema["ui:customButtonOptions"]) === null || _u === void 0 ? void 0 : _u.content) !== null && _v !== void 0 ? _v : "" })));
|
|
89
86
|
}
|
|
90
|
-
}
|
|
91
|
-
export
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
export
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
: position === "right" || position === "left"
|
|
131
|
-
? "40%"
|
|
132
|
-
: "unset";
|
|
133
|
-
}, function (_a) {
|
|
134
|
-
var position = _a.position;
|
|
135
|
-
return position === "top" || position === "bottom"
|
|
87
|
+
};
|
|
88
|
+
export const FieldWrapper = styled.div `
|
|
89
|
+
margin: 0.5rem 0;
|
|
90
|
+
`;
|
|
91
|
+
export const FieldTitle = styled.label `
|
|
92
|
+
font-weight: 700;
|
|
93
|
+
`;
|
|
94
|
+
export const FieldDescription = styled.p `
|
|
95
|
+
margin: 0;
|
|
96
|
+
font-size: 0.9em;
|
|
97
|
+
`;
|
|
98
|
+
export const FieldHelp = styled.p `
|
|
99
|
+
margin: 0;
|
|
100
|
+
font-size: 0.9em;
|
|
101
|
+
`;
|
|
102
|
+
export const InfoFieldBoxElement = styled.div `
|
|
103
|
+
transition: opacity 0.5s;
|
|
104
|
+
position: absolute;
|
|
105
|
+
z-index: 1080;
|
|
106
|
+
opacity: 0;
|
|
107
|
+
visibility: hidden;
|
|
108
|
+
margin: 0;
|
|
109
|
+
font-size: 0.875rem;
|
|
110
|
+
word-wrap: break-word;
|
|
111
|
+
min-width: max-content;
|
|
112
|
+
|
|
113
|
+
top: ${({ position }) => position === "bottom" ? "140%" : position === "top" ? "auto" : "50%"};
|
|
114
|
+
bottom: ${({ position }) => position === "top"
|
|
115
|
+
? "140%"
|
|
116
|
+
: position === "right" || position === "left"
|
|
117
|
+
? "50%"
|
|
118
|
+
: "auto"};
|
|
119
|
+
left: ${({ position }) => position === "right"
|
|
120
|
+
? "100%"
|
|
121
|
+
: position === "bottom" || position === "top"
|
|
122
|
+
? "50%"
|
|
123
|
+
: "auto"};
|
|
124
|
+
right: ${({ position }) => position === "left"
|
|
125
|
+
? "100%"
|
|
126
|
+
: position === "bottom" || position === "top"
|
|
136
127
|
? "50%"
|
|
137
|
-
:
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
128
|
+
: "auto"};
|
|
129
|
+
transform: translate(
|
|
130
|
+
${({ position }) => position === "bottom" || position === "top" ? "-50%" : "0"},
|
|
131
|
+
${({ position }) => position === "right" || position === "left" ? "-50%" : "0"}
|
|
132
|
+
);
|
|
133
|
+
`;
|
|
134
|
+
export const InfoFieldBoxArrowElement = styled.div `
|
|
135
|
+
top: ${({ position }) => position === "top"
|
|
136
|
+
? "100%"
|
|
137
|
+
: position === "right" || position === "left"
|
|
138
|
+
? "40%"
|
|
139
|
+
: "unset"};
|
|
140
|
+
left: ${({ position }) => position === "top" || position === "bottom"
|
|
141
|
+
? "50%"
|
|
142
|
+
: position === "right"
|
|
143
|
+
? "-2%"
|
|
144
|
+
: "102.5%"};
|
|
145
|
+
bottom: ${({ position }) => (position === "bottom" ? "100%" : "unset")};
|
|
146
|
+
border: solid transparent;
|
|
147
|
+
content: "";
|
|
148
|
+
height: 0;
|
|
149
|
+
width: 0;
|
|
150
|
+
position: absolute;
|
|
151
|
+
pointer-events: none;
|
|
152
|
+
border-top-color: ${({ position }) => position === "top" ? "grey" : "transparent"};
|
|
153
|
+
border-bottom-color: ${({ position }) => position === "bottom" ? "grey" : "transparent"};
|
|
154
|
+
border-right-color: ${({ position }) => position === "right" ? "grey" : "transparent"};
|
|
155
|
+
border-left-color: ${({ position }) => position === "left" ? "grey" : "transparent"};
|
|
156
|
+
border-width: 5px;
|
|
157
|
+
margin-left: -5px;
|
|
158
|
+
`;
|
|
159
|
+
export const InfoFieldBoxInnerElement = styled.div `
|
|
160
|
+
padding: 0.25rem 0.5rem;
|
|
161
|
+
color: white;
|
|
162
|
+
text-align: center;
|
|
163
|
+
background: grey;
|
|
164
|
+
border: solid 1px grey;
|
|
165
|
+
border-radius: 0.25rem;
|
|
166
|
+
cursor: default;
|
|
167
|
+
`;
|
|
168
|
+
export const InfoFieldContainerElement = styled.a `
|
|
169
|
+
position: relative;
|
|
170
|
+
color: black;
|
|
171
|
+
background: none;
|
|
172
|
+
outline: none;
|
|
173
|
+
cursor: pointer;
|
|
174
|
+
border: 1px solid black;
|
|
175
|
+
border-radius: 50%;
|
|
176
|
+
line-height: 1em;
|
|
177
|
+
font-size: 0.7em;
|
|
178
|
+
padding: 0 0.44em;
|
|
179
|
+
text-decoration: unset;
|
|
180
|
+
|
|
181
|
+
&:active,
|
|
182
|
+
&:focus {
|
|
183
|
+
color: white;
|
|
184
|
+
background: black;
|
|
185
|
+
${InfoFieldBoxElement} {
|
|
186
|
+
opacity: 1;
|
|
187
|
+
visibility: visible;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
`;
|
|
191
|
+
export const InfoFieldLabel = styled.span ``;
|
|
192
|
+
export const InfoFieldButton = ({ label, content, position, props, className, }) => {
|
|
193
|
+
return (_jsxs(InfoFieldContainerElement, { href: "#", onClick: (e) => e.preventDefault(), className: className, children: [_jsx(InfoFieldLabel, { children: label !== null && label !== void 0 ? label : "i" }), _jsxs(InfoFieldBoxElement, { position: position !== null && position !== void 0 ? position : "top", role: "tooltip", children: [_jsx(InfoFieldBoxArrowElement, { position: position !== null && position !== void 0 ? position : "top" }), _jsx(InfoFieldBoxInnerElement, { children: content })] })] }));
|
|
162
194
|
};
|
|
163
195
|
InfoFieldButton.styles = {
|
|
164
196
|
InfoFieldContainerElementStyle: InfoFieldContainerElement,
|
|
@@ -167,14 +199,186 @@ InfoFieldButton.styles = {
|
|
|
167
199
|
InfoFieldBoxArrowElementStyle: InfoFieldBoxArrowElement,
|
|
168
200
|
InfoFieldLabelStyle: InfoFieldLabel,
|
|
169
201
|
};
|
|
170
|
-
|
|
202
|
+
// <--- InfoFieldButton
|
|
203
|
+
export const ErrorMessage = styled(formik.ErrorMessage) ``;
|
|
171
204
|
/*
|
|
172
205
|
* Works like Formik field, but "as" props needs to be given with "formikAs", since styled components uses as.
|
|
173
206
|
*
|
|
174
207
|
*/
|
|
175
|
-
export
|
|
176
|
-
var formikAs = _a
|
|
177
|
-
return _jsx(formik.Field,
|
|
178
|
-
})
|
|
179
|
-
export
|
|
180
|
-
|
|
208
|
+
export const FieldInput = styled((_a) => {
|
|
209
|
+
var { formikAs } = _a, props = __rest(_a, ["formikAs"]);
|
|
210
|
+
return _jsx(formik.Field, Object.assign({}, props, { as: formikAs }));
|
|
211
|
+
}) ``;
|
|
212
|
+
export const RequiredIndicator = styled.span ``;
|
|
213
|
+
// ToggleSwitchField --->
|
|
214
|
+
export const Toggle = styled.span `
|
|
215
|
+
position: absolute;
|
|
216
|
+
cursor: pointer;
|
|
217
|
+
top: 0;
|
|
218
|
+
left: 0;
|
|
219
|
+
right: 0;
|
|
220
|
+
bottom: 0;
|
|
221
|
+
background: #ccc;
|
|
222
|
+
-webkit-transition: 0.4s;
|
|
223
|
+
transition: 0.4s;
|
|
224
|
+
border-radius: 34px;
|
|
225
|
+
|
|
226
|
+
&:before {
|
|
227
|
+
position: absolute;
|
|
228
|
+
content: "";
|
|
229
|
+
height: 0.9em;
|
|
230
|
+
width: 0.9em;
|
|
231
|
+
background: white;
|
|
232
|
+
-webkit-transition: 0.4s;
|
|
233
|
+
transition: 0.4s;
|
|
234
|
+
border-radius: 50%;
|
|
235
|
+
top: 0.13em;
|
|
236
|
+
left: 0.13em;
|
|
237
|
+
}
|
|
238
|
+
`;
|
|
239
|
+
export const ToggleLabel = styled.label `
|
|
240
|
+
position: relative;
|
|
241
|
+
display: inline-block;
|
|
242
|
+
width: 2em;
|
|
243
|
+
`;
|
|
244
|
+
export const ToggleFieldInput = styled(FieldInput) `
|
|
245
|
+
opacity: 0;
|
|
246
|
+
width: 0;
|
|
247
|
+
height: 0;
|
|
248
|
+
|
|
249
|
+
&:checked + ${Toggle} {
|
|
250
|
+
background: #2196f3;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
&:focus + ${Toggle} {
|
|
254
|
+
box-shadow: 0 0 1px #2196f3;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
&:checked + ${Toggle}:before {
|
|
258
|
+
transform: translateX(0.85em);
|
|
259
|
+
}
|
|
260
|
+
`;
|
|
261
|
+
export const ToggleSwitchField = ({ inputProps, name, className, }) => {
|
|
262
|
+
return (_jsxs(ToggleLabel, { className: className, children: [_jsx(ToggleFieldInput, Object.assign({}, inputProps, { name: name, type: "checkbox" })), _jsx(Toggle, {})] }));
|
|
263
|
+
};
|
|
264
|
+
ToggleSwitchField.styles = {
|
|
265
|
+
ToggleLabelStyle: ToggleLabel,
|
|
266
|
+
ToggleFieldInputStyle: ToggleFieldInput,
|
|
267
|
+
ToggleStyle: Toggle,
|
|
268
|
+
};
|
|
269
|
+
// <--- ToggleSwitchField
|
|
270
|
+
// RadioButtonField --->
|
|
271
|
+
export const RadioButtonFieldContainer = styled.div `
|
|
272
|
+
display: flex;
|
|
273
|
+
gap: 1em;
|
|
274
|
+
`;
|
|
275
|
+
export const RadioButtonFieldElement = styled.label `
|
|
276
|
+
display: inline-flex;
|
|
277
|
+
align-items: center;
|
|
278
|
+
`;
|
|
279
|
+
export const RadioButtonFieldInput = styled(FieldInput) `
|
|
280
|
+
margin: unset;
|
|
281
|
+
margin-top: 0.15em;
|
|
282
|
+
`;
|
|
283
|
+
export const ButtonLabel = styled.span `
|
|
284
|
+
margin-left: 0.2em;
|
|
285
|
+
`;
|
|
286
|
+
export const ButtonLabelTrue = styled(ButtonLabel) ``;
|
|
287
|
+
export const ButtonLabelFalse = styled(ButtonLabel) ``;
|
|
288
|
+
export const RadioButtonField = ({ label, inputProps, name, className, }) => {
|
|
289
|
+
var _a, _b;
|
|
290
|
+
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" })] })] }));
|
|
291
|
+
};
|
|
292
|
+
RadioButtonField.styles = {
|
|
293
|
+
RadioButtonFieldContainerStyle: RadioButtonFieldContainer,
|
|
294
|
+
RadioButtonFieldElementStyle: RadioButtonFieldElement,
|
|
295
|
+
RadioButtonFieldInputStyle: RadioButtonFieldInput,
|
|
296
|
+
ButtonLabelStyle: ButtonLabel,
|
|
297
|
+
ButtonLabelTrueStyle: ButtonLabelTrue,
|
|
298
|
+
ButtonLabelFalseStyle: ButtonLabelFalse,
|
|
299
|
+
};
|
|
300
|
+
// ---> SearchableMultiTagSelectField
|
|
301
|
+
export const MultiSelectContainer = styled.div `
|
|
302
|
+
display: flex;
|
|
303
|
+
flex-direction: column;
|
|
304
|
+
`;
|
|
305
|
+
export const MultiSelectInput = styled(FieldInput) ``;
|
|
306
|
+
export const MultiSelectBadgeContainer = styled.div `
|
|
307
|
+
margin: 0.3em 0;
|
|
308
|
+
display: inline-flex;
|
|
309
|
+
gap: 1em;
|
|
310
|
+
`;
|
|
311
|
+
export const MultiSelectBadge = styled.span `
|
|
312
|
+
background: lightgray;
|
|
313
|
+
padding: 0 0.2em 0 0.5em;
|
|
314
|
+
border-radius: 0.1em;
|
|
315
|
+
display: flex;
|
|
316
|
+
`;
|
|
317
|
+
export const MultiSelectBadgeCloseElement = styled.span `
|
|
318
|
+
cursor: pointer;
|
|
319
|
+
margin-left: 0.5em;
|
|
320
|
+
font-size: 0.7em;
|
|
321
|
+
align-self: baseline;
|
|
322
|
+
font-family: sans-serif;
|
|
323
|
+
`;
|
|
324
|
+
export const MultiSelectOptionList = styled.ul `
|
|
325
|
+
padding: unset;
|
|
326
|
+
margin: unset;
|
|
327
|
+
border: 1px solid gray;
|
|
328
|
+
border-radius: 0.2em;
|
|
329
|
+
position: absolute;
|
|
330
|
+
background: white;
|
|
331
|
+
margin: 1.3em 0;
|
|
332
|
+
`;
|
|
333
|
+
export const MultiSelectOptionListItem = styled.li `
|
|
334
|
+
cursor: pointer;
|
|
335
|
+
list-style-type: none;
|
|
336
|
+
padding: 0.06em 0.2em;
|
|
337
|
+
height: 1.2em;
|
|
338
|
+
&:hover {
|
|
339
|
+
background: lightgray;
|
|
340
|
+
}
|
|
341
|
+
`;
|
|
342
|
+
export const MultiSelectOptionListWithoutItem = styled.li `
|
|
343
|
+
cursor: default;
|
|
344
|
+
color: gray;
|
|
345
|
+
list-style-type: none;
|
|
346
|
+
padding: 0.06em 0.2em;
|
|
347
|
+
height: 1.2em;
|
|
348
|
+
`;
|
|
349
|
+
export const SearchableMultiTagSelectField = ({ name, placeholder, enums, emptySearchMessage, closeElement, className, }) => {
|
|
350
|
+
const [search, setSearch] = useState("");
|
|
351
|
+
const searchIncludedInEnum = () => {
|
|
352
|
+
const hasValue = enums === null || enums === void 0 ? void 0 : enums.values.map((value) => value.title.toLowerCase().includes(search.toLowerCase()));
|
|
353
|
+
return hasValue === null || hasValue === void 0 ? void 0 : hasValue.includes(true);
|
|
354
|
+
};
|
|
355
|
+
return (_jsx(formik.Field, { className: className, name: name, multiple: true, children: ({ field, form: { setValues }, meta, }) => {
|
|
356
|
+
var _a;
|
|
357
|
+
return (_jsxs(MultiSelectContainer, { className: className, children: [_jsx(FieldInput, Object.assign({ type: "hidden" }, field)), _jsx(MultiSelectInput, { className: className, type: "text", onChange: (e) => {
|
|
358
|
+
setSearch(e.currentTarget.value);
|
|
359
|
+
}, placeholder: placeholder, value: search }), _jsx(MultiSelectBadgeContainer, { children: ((_a = field.value) !== null && _a !== void 0 ? _a : []).map((value) => {
|
|
360
|
+
var _a;
|
|
361
|
+
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: () => setValues({
|
|
362
|
+
[name]: field.value.filter((v) => v !== value),
|
|
363
|
+
}), children: closeElement !== null && closeElement !== void 0 ? closeElement : "x" })] }, value));
|
|
364
|
+
}) }), search.length > 0 && (_jsx(MultiSelectOptionList, { children: searchIncludedInEnum() ? (enums === null || enums === void 0 ? void 0 : enums.values.filter((item) => { var _a; return !((_a = field.value) !== null && _a !== void 0 ? _a : []).includes(item.const); }).filter((value) => value.title.toLowerCase().includes(search.toLowerCase())).map((option, index) => (_jsx(MultiSelectOptionListItem, { value: option.const, onClick: () => {
|
|
365
|
+
var _a;
|
|
366
|
+
setValues({
|
|
367
|
+
[name]: [
|
|
368
|
+
...new Set([...((_a = field.value) !== null && _a !== void 0 ? _a : []), option.const]),
|
|
369
|
+
],
|
|
370
|
+
});
|
|
371
|
+
setSearch("");
|
|
372
|
+
}, children: option.title }, index)))) : (_jsx(MultiSelectOptionListWithoutItem, { children: emptySearchMessage !== null && emptySearchMessage !== void 0 ? emptySearchMessage : "No match found" })) })), meta.touched && meta.error && (_jsx("div", { className: "error", children: meta.error }))] }));
|
|
373
|
+
} }));
|
|
374
|
+
};
|
|
375
|
+
SearchableMultiTagSelectField.styles = {
|
|
376
|
+
MultiSelectContainerStyle: MultiSelectContainer,
|
|
377
|
+
MultiSelectInputStyle: MultiSelectInput,
|
|
378
|
+
MultiSelectBadgeContainerStyle: MultiSelectBadgeContainer,
|
|
379
|
+
MultiSelectBadgeStyle: MultiSelectBadge,
|
|
380
|
+
MultiSelectBadgeCloseElementStyle: MultiSelectBadgeCloseElement,
|
|
381
|
+
MultiSelectOptionListStyle: MultiSelectOptionList,
|
|
382
|
+
MultiSelectOptionListItemStyle: MultiSelectOptionListItem,
|
|
383
|
+
MultiSelectOptionListWithoutItemStyle: MultiSelectOptionListWithoutItem,
|
|
384
|
+
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
export declare
|
|
1
|
+
import type { ArrayFieldTemplateProps } from "../types";
|
|
2
|
+
import React from "react";
|
|
3
|
+
export declare const ArrayFieldTemplate: React.FC<ArrayFieldTemplateProps>;
|
|
@@ -1,28 +1,16 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
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";
|
|
15
|
-
import {
|
|
4
|
+
import { getDescription, getTitle } from "../utils";
|
|
5
|
+
import { useExtractUiSchema } from "../hooks";
|
|
16
6
|
import { RequiredIndicator } from "../styledComponents";
|
|
17
|
-
export
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
//TODO: This is not right
|
|
24
|
-
_c = _b.props,
|
|
7
|
+
export const ArrayFieldTemplate = (props) => {
|
|
8
|
+
const { components: { ArrayFieldWrapper, ArrayFieldTitle, FieldDescription, ErrorMessage, FieldHelp, InfoFieldButton, }, } = useContext(FormRegistry);
|
|
9
|
+
const { name, uiSchema, children } = props;
|
|
10
|
+
const title = getTitle(props);
|
|
11
|
+
const description = getDescription(props);
|
|
12
|
+
const { help, info,
|
|
25
13
|
//TODO: This is not right
|
|
26
|
-
|
|
27
|
-
return (_jsxs(ArrayFieldWrapper,
|
|
28
|
-
}
|
|
14
|
+
props: { wrapper: wrappertProps, title: titleProps, description: descriptionProps, help: helpProps, error: errorProps, } = {}, } = useExtractUiSchema(uiSchema);
|
|
15
|
+
return (_jsxs(ArrayFieldWrapper, Object.assign({}, wrappertProps, { children: [title && (_jsxs(ArrayFieldTitle, Object.assign({}, titleProps, { htmlFor: name, children: [title, (props === null || props === void 0 ? void 0 : props.required) && _jsx(RequiredIndicator, { children: "*" })] }))), info && _jsx(InfoFieldButton, Object.assign({}, info)), description && (_jsx(FieldDescription, Object.assign({}, descriptionProps, { children: description }))), children, help && _jsx(FieldHelp, Object.assign({}, helpProps, { children: help })), _jsx(ErrorMessage, Object.assign({}, errorProps, { name: name }))] })));
|
|
16
|
+
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
export declare
|
|
1
|
+
import type { FieldTemplateProps } from "../types";
|
|
2
|
+
import React from "react";
|
|
3
|
+
export declare const FieldTemplate: React.FC<FieldTemplateProps>;
|