@nolwenture/formik-jsonschema-form 0.2.0 → 0.4.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 +212 -1
- package/dist/Form.stories.d.ts +1 -0
- package/dist/Form.stories.js +14 -4
- package/dist/_sampleData.d.ts +1 -0
- package/dist/_sampleData.js +81 -0
- package/dist/fields/ArrayField.js +33 -10
- package/dist/fields/ObjectField.js +24 -12
- package/dist/fields/SchemaField.js +2 -2
- package/dist/fields/StringField.js +1 -1
- package/dist/styledComponents.d.ts +35 -5
- package/dist/styledComponents.js +115 -24
- package/dist/templates/ArrayFieldTemplate.js +3 -3
- package/dist/templates/FieldTemplate.js +3 -3
- package/dist/templates/ObjectFieldTemplate.js +3 -3
- package/dist/types.d.ts +22 -2
- package/dist/utils.d.ts +3 -0
- package/dist/utils.js +16 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -50,9 +50,70 @@ export function MyFormComponent() {
|
|
|
50
50
|
}
|
|
51
51
|
```
|
|
52
52
|
|
|
53
|
+
Pass your uiSchema to the `Form`component. which should be passed as a child to the `Formik`component,
|
|
54
|
+
just like schema. uiSchema will tell the form more about its own layout and styles.
|
|
55
|
+
|
|
56
|
+
Basic available elements to add to the form or a field of the form via uiSchema are:
|
|
57
|
+
|
|
58
|
+
- "ui:title"
|
|
59
|
+
- "ui:description"
|
|
60
|
+
- "ui:help"
|
|
61
|
+
- "ui:options"
|
|
62
|
+
- "ui:info"
|
|
63
|
+
|
|
64
|
+
Most of those elements take a string for value, but `ui:info` takes an object with the possible keys of
|
|
65
|
+
|
|
66
|
+
- `label` for the clickable anchor (if not provided, default value is "i")
|
|
67
|
+
- `content` for the content of the popup container, and
|
|
68
|
+
- `position` taking a string of either "top", "bottom", "left" or "right" (if not provided, default value is "top")
|
|
69
|
+
|
|
70
|
+
All elements of `ui:info` are customisable. The styledComponent is called `InfoFieldButton` and it consists of the following elements:
|
|
71
|
+
|
|
72
|
+
- InfoFieldContainerElement
|
|
73
|
+
- InfoFieldBoxElement
|
|
74
|
+
- InfoFieldBoxInnerElement
|
|
75
|
+
- InfoFieldBoxArrowElement
|
|
76
|
+
- InfoFieldLabel
|
|
77
|
+
|
|
78
|
+
```tsx
|
|
79
|
+
import { Form } from "@nolwenture/formik-jsonschema-form";
|
|
80
|
+
import { Formik } from "formik";
|
|
81
|
+
|
|
82
|
+
const schema = {
|
|
83
|
+
title: "My form",
|
|
84
|
+
type: "object",
|
|
85
|
+
properties: {
|
|
86
|
+
firstName: { type: "string", title: "First name" },
|
|
87
|
+
lastName: { type: "string", title: "Last name" },
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const uiSchema = {
|
|
92
|
+
"ui:description": "Form description",
|
|
93
|
+
firstName: { "ui:description": "Field description" },
|
|
94
|
+
lastName: {
|
|
95
|
+
"ui:info": {
|
|
96
|
+
label: "?",
|
|
97
|
+
content: "Add your family name",
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
export function MyFormComponent() {
|
|
103
|
+
return (
|
|
104
|
+
<Formik
|
|
105
|
+
initialValues={{ firstName: "", lastName: "" }}
|
|
106
|
+
onSubmit={handleSubmit}
|
|
107
|
+
>
|
|
108
|
+
<Form schema={schema} uiSchema={uiSchema}></Form>
|
|
109
|
+
</Formik>
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
53
114
|
### Using custom components
|
|
54
115
|
|
|
55
|
-
Form components (such as wrappers) can be
|
|
116
|
+
Form components (such as wrappers) can be overridden with custom ones
|
|
56
117
|
|
|
57
118
|
Here is an example of overriding `FieldWrapper` (wrapper used on all fields):
|
|
58
119
|
|
|
@@ -87,6 +148,37 @@ return (
|
|
|
87
148
|
);
|
|
88
149
|
```
|
|
89
150
|
|
|
151
|
+
And another example how to override `InfoFieldButton`:
|
|
152
|
+
|
|
153
|
+
```tsx
|
|
154
|
+
const CustomInfoFieldButton = styled(InfoFieldButton)`
|
|
155
|
+
outline: 2px red solid;
|
|
156
|
+
margin: 0.5em;
|
|
157
|
+
${InfoFieldButton.styles.InfoFieldBoxInnerElementStyle} {
|
|
158
|
+
min-width: 200px;
|
|
159
|
+
background: orange;
|
|
160
|
+
color: blue;
|
|
161
|
+
}
|
|
162
|
+
${InfoFieldButton.styles.InfoFieldLabelStyle} {
|
|
163
|
+
color: green;
|
|
164
|
+
}
|
|
165
|
+
`;
|
|
166
|
+
|
|
167
|
+
...
|
|
168
|
+
|
|
169
|
+
return (
|
|
170
|
+
<Formik initialValues={initialValues} onSubmit={handleOnSubmit}>
|
|
171
|
+
<Form
|
|
172
|
+
schema={schema}
|
|
173
|
+
uiSchema={uiSchema}
|
|
174
|
+
components={{
|
|
175
|
+
InfoFieldButton: CustomInfoFieldButton,
|
|
176
|
+
}}
|
|
177
|
+
></Form>
|
|
178
|
+
</Formik>
|
|
179
|
+
);
|
|
180
|
+
```
|
|
181
|
+
|
|
90
182
|
Custom fields can be used in addition to all the default fields:
|
|
91
183
|
|
|
92
184
|
```tsx
|
|
@@ -129,6 +221,125 @@ return (
|
|
|
129
221
|
);
|
|
130
222
|
```
|
|
131
223
|
|
|
224
|
+
The style for buttons to add and remove (and move) array or object items can be overridden within the uiSchema by giving inline style.
|
|
225
|
+
|
|
226
|
+
The buttons that can be customized that way are:
|
|
227
|
+
|
|
228
|
+
- "ui:addButtonOptions"
|
|
229
|
+
- "ui:removeButtonOptions"
|
|
230
|
+
- "ui:upButtonOptions"
|
|
231
|
+
- "ui:downButtonOptions"
|
|
232
|
+
- "ui:customButtonOptions"
|
|
233
|
+
|
|
234
|
+
`content` takes a ReactNode as input.
|
|
235
|
+
|
|
236
|
+
```tsx
|
|
237
|
+
|
|
238
|
+
const schema = {
|
|
239
|
+
title: "Form with customized buttons",
|
|
240
|
+
type: "object",
|
|
241
|
+
properties: {
|
|
242
|
+
someArray: {
|
|
243
|
+
type: "array",
|
|
244
|
+
title: "Some array",
|
|
245
|
+
description: "Array with customized buttons",
|
|
246
|
+
additionalItems: {
|
|
247
|
+
type: "string",
|
|
248
|
+
},
|
|
249
|
+
},
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
const uiSchema = {
|
|
254
|
+
"ui:description": "Form description",
|
|
255
|
+
// make a green ADD button for someArray that reads "Hello!"
|
|
256
|
+
someArray: {
|
|
257
|
+
"ui:addButtonOptions": {
|
|
258
|
+
content: <b>Hello!</b>,
|
|
259
|
+
props: { style: { background: "green" } },
|
|
260
|
+
},
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
...
|
|
264
|
+
|
|
265
|
+
return (
|
|
266
|
+
<Formik initialValues={initialValues} onSubmit={handleOnSubmit}>
|
|
267
|
+
<Form
|
|
268
|
+
schema={schema}
|
|
269
|
+
uiSchema={uiSchema}
|
|
270
|
+
></Form>
|
|
271
|
+
</Formik>
|
|
272
|
+
);
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
### Required input
|
|
276
|
+
|
|
277
|
+
Required input can be displayed with an asterisk next to the title.
|
|
278
|
+
The respective fieldname needs to be given inside the required-array of the object holding the field in question in the schema.
|
|
279
|
+
In the example, required fields are 'lastName', 'favouriteFood' inside the arrayOfObject, and 'tasks' in nestedObject.
|
|
280
|
+
|
|
281
|
+
The styling of the asterisk can be customised by applying style to styledComponents.RequiredIndicator.
|
|
282
|
+
|
|
283
|
+
```tsx
|
|
284
|
+
import { Form } from "@nolwenture/formik-jsonschema-form";
|
|
285
|
+
import { Formik } from "formik";
|
|
286
|
+
|
|
287
|
+
const CustomizedRequiredIndicator = styled(styledComponents.RequiredIndicator)`
|
|
288
|
+
color: aqua;
|
|
289
|
+
`;
|
|
290
|
+
|
|
291
|
+
const schema = {
|
|
292
|
+
title: "My Form",
|
|
293
|
+
required: ["lastName"],
|
|
294
|
+
properties: {
|
|
295
|
+
firstName: { type: "string", title: "First name" },
|
|
296
|
+
lastName: { type: "string", title: "Last name" },
|
|
297
|
+
arrayOfObject: {
|
|
298
|
+
type: "array",
|
|
299
|
+
title: "Array of objects",
|
|
300
|
+
items: {
|
|
301
|
+
type: "object",
|
|
302
|
+
title: "Favourites",
|
|
303
|
+
required: ["favouriteFood"],
|
|
304
|
+
properties: {
|
|
305
|
+
favouriteFood: { type: "string", title: "Favourite food" },
|
|
306
|
+
favouriteSong: { type: "string", title: "Favourite song" },
|
|
307
|
+
},
|
|
308
|
+
},
|
|
309
|
+
},
|
|
310
|
+
nestedObject: {
|
|
311
|
+
type: "object",
|
|
312
|
+
title: "Nested Object",
|
|
313
|
+
required: ["tasks"],
|
|
314
|
+
properties: {
|
|
315
|
+
hobbies: { type: "string", title: "Hobbies" },
|
|
316
|
+
tasks: { type: "string", title: "Tasks" },
|
|
317
|
+
},
|
|
318
|
+
},
|
|
319
|
+
},
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
const uiSchema = {
|
|
323
|
+
"ui:description": "Form description",
|
|
324
|
+
firstName: { "ui:description": "Field description" },
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
export function MyFormComponent() {
|
|
328
|
+
return (
|
|
329
|
+
<Formik
|
|
330
|
+
initialValues={{ firstName: "", lastName: "" }}
|
|
331
|
+
onSubmit={handleSubmit}
|
|
332
|
+
>
|
|
333
|
+
<Form
|
|
334
|
+
schema={schema}
|
|
335
|
+
uiSchema={uiSchema}
|
|
336
|
+
components={{ RequiredIndicator: CustomizedRequiredIndicator }}
|
|
337
|
+
></Form>
|
|
338
|
+
</Formik>
|
|
339
|
+
);
|
|
340
|
+
}
|
|
341
|
+
```
|
|
342
|
+
|
|
132
343
|
## Props
|
|
133
344
|
|
|
134
345
|
`Form` component props:
|
package/dist/Form.stories.d.ts
CHANGED
|
@@ -9,3 +9,4 @@ export declare const CompleteSchema: ComponentStory<typeof Form>;
|
|
|
9
9
|
export declare const StrictlyTyped: () => JSX.Element;
|
|
10
10
|
export declare const StylesCustomized: () => JSX.Element;
|
|
11
11
|
export declare const WithGeneratedSchema: ComponentStory<typeof Form>;
|
|
12
|
+
export declare const WithRequiredInput: ComponentStory<typeof Form>;
|
package/dist/Form.stories.js
CHANGED
|
@@ -53,7 +53,8 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
53
53
|
import { action } from "@storybook/addon-actions";
|
|
54
54
|
import styled from "styled-components";
|
|
55
55
|
import { Formik, useFormikContext } from "formik";
|
|
56
|
-
import {
|
|
56
|
+
import { InfoFieldButton } from "./styledComponents";
|
|
57
|
+
import { completeSchema, completeUiSchema, simpleSchema, simpleUiSchema, generatedSchema, requiredInputSchema, } from "./_sampleData";
|
|
57
58
|
import { Form, styledComponents } from "./";
|
|
58
59
|
export default {
|
|
59
60
|
title: "Form",
|
|
@@ -76,10 +77,12 @@ export var Simple = Template.bind({});
|
|
|
76
77
|
Simple.args = {
|
|
77
78
|
schema: simpleSchema,
|
|
78
79
|
};
|
|
80
|
+
var InfoFieldButtonNew = styled(InfoFieldButton)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n outline: 2px red solid;\n margin: 0.5em;\n ", " {\n min-width: 200px;\n background: orange;\n color: blue;\n }\n ", " {\n color: green;\n }\n"], ["\n outline: 2px red solid;\n margin: 0.5em;\n ", " {\n min-width: 200px;\n background: orange;\n color: blue;\n }\n ", " {\n color: green;\n }\n"])), InfoFieldButton.styles.InfoFieldBoxInnerElementStyle, InfoFieldButton.styles.InfoFieldLabelStyle);
|
|
79
81
|
export var WithUiSchema = Template.bind({});
|
|
80
82
|
WithUiSchema.args = {
|
|
81
83
|
schema: simpleSchema,
|
|
82
84
|
uiSchema: simpleUiSchema,
|
|
85
|
+
components: { InfoFieldButton: InfoFieldButtonNew },
|
|
83
86
|
};
|
|
84
87
|
export var CompleteSchema = Template.bind({});
|
|
85
88
|
CompleteSchema.args = {
|
|
@@ -97,14 +100,15 @@ export var StrictlyTyped = function () {
|
|
|
97
100
|
}); } }, { children: _jsx(Form, { schema: simpleSchema }) })));
|
|
98
101
|
};
|
|
99
102
|
/*** CUSTOMIZATION ***/
|
|
100
|
-
var CustomizedForm = styled(Form)(
|
|
101
|
-
var CustomizedFieldWrapper = styled.div(
|
|
103
|
+
var CustomizedForm = styled(Form)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n ", " {\n color: red;\n }\n"], ["\n ", " {\n color: red;\n }\n"])), styledComponents.FieldTitle);
|
|
104
|
+
var CustomizedFieldWrapper = styled.div(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n outline: 2px solid\n ", ";\n"], ["\n outline: 2px solid\n ", ";\n"])), function (props) { return (props.title === "ABC" ? "blue" : "transparent"); });
|
|
102
105
|
var CustomizedErrorMessage = function (props) {
|
|
103
106
|
var name = props.name;
|
|
104
107
|
var errors = useFormikContext().errors;
|
|
105
108
|
var error = errors[name];
|
|
106
109
|
return error ? _jsx("p", { children: error }) : _jsx("p", { children: "Hurray! No errors" });
|
|
107
110
|
};
|
|
111
|
+
var CustomizedRequiredIndicator = styled(styledComponents.RequiredIndicator)(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n color: aqua;\n"], ["\n color: aqua;\n"])));
|
|
108
112
|
export var StylesCustomized = function () {
|
|
109
113
|
return (_jsx(Formik, __assign({ initialValues: {}, onSubmit: function (values, formikHelpers) { return __awaiter(void 0, void 0, void 0, function () {
|
|
110
114
|
return __generator(this, function (_a) {
|
|
@@ -124,6 +128,7 @@ export var StylesCustomized = function () {
|
|
|
124
128
|
}, components: {
|
|
125
129
|
FieldWrapper: CustomizedFieldWrapper,
|
|
126
130
|
ErrorMessage: CustomizedErrorMessage,
|
|
131
|
+
RequiredIndicator: CustomizedRequiredIndicator,
|
|
127
132
|
} }) })));
|
|
128
133
|
};
|
|
129
134
|
export var WithGeneratedSchema = Template.bind({});
|
|
@@ -132,4 +137,9 @@ WithGeneratedSchema.args = {
|
|
|
132
137
|
uiSchema: {},
|
|
133
138
|
useItemsAsAdditionalItems: true,
|
|
134
139
|
};
|
|
135
|
-
var
|
|
140
|
+
export var WithRequiredInput = Template.bind({});
|
|
141
|
+
WithRequiredInput.args = {
|
|
142
|
+
schema: requiredInputSchema,
|
|
143
|
+
uiSchema: {},
|
|
144
|
+
};
|
|
145
|
+
var templateObject_1, templateObject_2, templateObject_3, templateObject_4;
|
package/dist/_sampleData.d.ts
CHANGED
package/dist/_sampleData.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
2
|
export var simpleSchema = {
|
|
2
3
|
title: "TITLE",
|
|
3
4
|
properties: {
|
|
@@ -7,6 +8,11 @@ export var simpleSchema = {
|
|
|
7
8
|
};
|
|
8
9
|
export var simpleUiSchema = {
|
|
9
10
|
"ui:description": "Description text",
|
|
11
|
+
firstName: {
|
|
12
|
+
"ui:info": {
|
|
13
|
+
content: "A small info",
|
|
14
|
+
},
|
|
15
|
+
},
|
|
10
16
|
};
|
|
11
17
|
export var completeSchema = {
|
|
12
18
|
title: "Inventory",
|
|
@@ -178,6 +184,7 @@ export var completeSchema = {
|
|
|
178
184
|
},
|
|
179
185
|
},
|
|
180
186
|
},
|
|
187
|
+
default: [{ string: "Hello" }],
|
|
181
188
|
},
|
|
182
189
|
},
|
|
183
190
|
};
|
|
@@ -207,6 +214,7 @@ export var completeUiSchema = {
|
|
|
207
214
|
enum: {
|
|
208
215
|
"ui:help": "Enum help",
|
|
209
216
|
},
|
|
217
|
+
enumOneOf: { placeholder: "Select one" },
|
|
210
218
|
null: {
|
|
211
219
|
"ui:help": "Null help",
|
|
212
220
|
},
|
|
@@ -239,6 +247,34 @@ export var completeUiSchema = {
|
|
|
239
247
|
null: {
|
|
240
248
|
"ui:help": "Null help",
|
|
241
249
|
},
|
|
250
|
+
"ui:addButtonOptions": {
|
|
251
|
+
content: _jsx("b", { children: "Hello in an Object!" }),
|
|
252
|
+
props: { style: { background: "pink" } },
|
|
253
|
+
},
|
|
254
|
+
},
|
|
255
|
+
partiallyFixedArray: {
|
|
256
|
+
"ui:addButtonOptions": {
|
|
257
|
+
content: _jsx("b", { children: "Hello!" }),
|
|
258
|
+
props: { style: { background: "green" } },
|
|
259
|
+
},
|
|
260
|
+
"ui:removeButtonOptions": {
|
|
261
|
+
content: _jsx("span", { children: "-" }),
|
|
262
|
+
props: {
|
|
263
|
+
style: {
|
|
264
|
+
height: "25px",
|
|
265
|
+
width: "25px",
|
|
266
|
+
background: "red",
|
|
267
|
+
borderRadius: "50%",
|
|
268
|
+
display: "inline-block",
|
|
269
|
+
border: "unset",
|
|
270
|
+
padding: "unset",
|
|
271
|
+
color: "white",
|
|
272
|
+
fontWeight: "bolder",
|
|
273
|
+
textAlign: "center",
|
|
274
|
+
lineHeight: "1.4em",
|
|
275
|
+
},
|
|
276
|
+
},
|
|
277
|
+
},
|
|
242
278
|
},
|
|
243
279
|
};
|
|
244
280
|
export var generatedSchema = {
|
|
@@ -260,3 +296,48 @@ export var generatedSchema = {
|
|
|
260
296
|
required: ["object", "value", "property"],
|
|
261
297
|
additionalProperties: false,
|
|
262
298
|
};
|
|
299
|
+
export var requiredInputSchema = {
|
|
300
|
+
title: "TITLE",
|
|
301
|
+
required: ["lastName"],
|
|
302
|
+
properties: {
|
|
303
|
+
firstName: { type: "string", title: "First name" },
|
|
304
|
+
lastName: { type: "string", title: "Last name" },
|
|
305
|
+
arrayOfObject: {
|
|
306
|
+
type: "array",
|
|
307
|
+
title: "Array of objects",
|
|
308
|
+
items: {
|
|
309
|
+
type: "object",
|
|
310
|
+
title: "Favourites",
|
|
311
|
+
required: ["favouriteFood"],
|
|
312
|
+
properties: {
|
|
313
|
+
favouriteFood: { type: "string", title: "Favourite food" },
|
|
314
|
+
favouriteSong: { type: "string", title: "Favourite song" },
|
|
315
|
+
},
|
|
316
|
+
},
|
|
317
|
+
additionalItems: {
|
|
318
|
+
type: "object",
|
|
319
|
+
title: "Second favourites",
|
|
320
|
+
required: ["secondFavouriteSong"],
|
|
321
|
+
properties: {
|
|
322
|
+
secondFavouriteFood: {
|
|
323
|
+
type: "string",
|
|
324
|
+
title: "Second favourite food",
|
|
325
|
+
},
|
|
326
|
+
secondFavouriteSong: {
|
|
327
|
+
type: "string",
|
|
328
|
+
title: "Second favourite song",
|
|
329
|
+
},
|
|
330
|
+
},
|
|
331
|
+
},
|
|
332
|
+
},
|
|
333
|
+
nestedObject: {
|
|
334
|
+
type: "object",
|
|
335
|
+
title: "Nested Object",
|
|
336
|
+
required: ["tasks"],
|
|
337
|
+
properties: {
|
|
338
|
+
hobbies: { type: "string", title: "Hobbies" },
|
|
339
|
+
tasks: { type: "string", title: "Tasks" },
|
|
340
|
+
},
|
|
341
|
+
},
|
|
342
|
+
},
|
|
343
|
+
};
|
|
@@ -23,7 +23,8 @@ import { useContext, useMemo } from "react";
|
|
|
23
23
|
import { FormRegistry } from "../Form";
|
|
24
24
|
import { useField } from "formik";
|
|
25
25
|
import { ArrayFieldButtonPurpose } from "../types";
|
|
26
|
-
import { useExtractUiSchema } from "../utils";
|
|
26
|
+
import { useExtractUiSchema, useSetDefault } from "../utils";
|
|
27
|
+
import { GetArrayFieldButton } from "../styledComponents";
|
|
27
28
|
function appendArray(values) {
|
|
28
29
|
return values ? __spreadArray(__spreadArray([], values, true), [""], false) : [""];
|
|
29
30
|
}
|
|
@@ -45,7 +46,8 @@ function moveInArray(values, index, direction) {
|
|
|
45
46
|
}
|
|
46
47
|
}
|
|
47
48
|
export function ArrayField(props) {
|
|
48
|
-
var _a = useContext(FormRegistry), SchemaField = _a.fields.SchemaField, ArrayFieldTemplate = _a.templates.ArrayFieldTemplate, _b = _a.components, ArrayFieldItem = _b.ArrayFieldItem, ArrayFieldList = _b.ArrayFieldList, ArrayFieldItemButtons = _b.ArrayFieldItemButtons,
|
|
49
|
+
var _a = useContext(FormRegistry), SchemaField = _a.fields.SchemaField, ArrayFieldTemplate = _a.templates.ArrayFieldTemplate, _b = _a.components, ArrayFieldItem = _b.ArrayFieldItem, ArrayFieldList = _b.ArrayFieldList, ArrayFieldItemButtons = _b.ArrayFieldItemButtons, useItemsAsAdditionalItems = _a.useItemsAsAdditionalItems;
|
|
50
|
+
useSetDefault(props);
|
|
49
51
|
var name = props.name, schema = props.schema, uiSchema = props.uiSchema;
|
|
50
52
|
var _c = useField(name), value = _c[0].value, _ = _c[1], setValue = _c[2].setValue;
|
|
51
53
|
var _d = useMemo(function () {
|
|
@@ -106,14 +108,35 @@ export function ArrayField(props) {
|
|
|
106
108
|
// [schema]
|
|
107
109
|
// );
|
|
108
110
|
// Bacwards compatibility ends
|
|
109
|
-
var
|
|
110
|
-
return (_jsxs(ArrayFieldTemplate, __assign({}, props, { children: [_jsxs(ArrayFieldList, { children: [(items || []).map(function (itemSchema, index) { return (_jsx(ArrayFieldItem, { children: _jsx(SchemaField, { name: "".concat(name, "[").concat(index, "]"), schema: typeof itemSchema !== "boolean" ? itemSchema : {}, uiSchema: (uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema[index]) || (uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema.items) }, index)
|
|
111
|
+
var disabled = useExtractUiSchema(uiSchema).disabled;
|
|
112
|
+
return (_jsxs(ArrayFieldTemplate, __assign({}, props, { children: [_jsxs(ArrayFieldList, { children: [(items || []).map(function (itemSchema, index) { return (_jsx(ArrayFieldItem, { children: _jsx(SchemaField, { name: "".concat(name, "[").concat(index, "]"), schema: typeof itemSchema !== "boolean" ? itemSchema : {}, uiSchema: (uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema[index]) || (uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema.items), forceDefaultValue: true }) }, index)); }), ((value === null || value === void 0 ? void 0 : value.slice(items.length)) || []).map(function (_, index) { return (_jsxs(ArrayFieldItem, { children: [_jsx(SchemaField, { name: "".concat(name, "[").concat(index + items.length, "]"), schema: additionalItems && typeof additionalItems !== "boolean"
|
|
111
113
|
? additionalItems
|
|
112
|
-
: {}, uiSchema: __assign({ disabled: disabled }, ((uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema[index + items.length]) || (uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema.items))) }),
|
|
114
|
+
: {}, uiSchema: __assign({ disabled: disabled }, ((uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema[index + items.length]) || (uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema.items))) }), _jsxs(ArrayFieldItemButtons, { children: [GetArrayFieldButton({
|
|
115
|
+
purpose: ArrayFieldButtonPurpose.REMOVE,
|
|
116
|
+
onClick: function () {
|
|
113
117
|
return setValue(removeFromArray(value, index + items.length));
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
118
|
+
},
|
|
119
|
+
uiSchema: uiSchema,
|
|
120
|
+
}), value.length > 1 &&
|
|
121
|
+
index > 0 &&
|
|
122
|
+
GetArrayFieldButton({
|
|
123
|
+
purpose: ArrayFieldButtonPurpose.MOVE_UP,
|
|
124
|
+
onClick: function () {
|
|
125
|
+
return setValue(moveInArray(value, index + items.length, -1));
|
|
126
|
+
},
|
|
127
|
+
uiSchema: uiSchema,
|
|
128
|
+
}), value.length > 1 &&
|
|
129
|
+
index < value.length - 1 &&
|
|
130
|
+
GetArrayFieldButton({
|
|
131
|
+
purpose: ArrayFieldButtonPurpose.MOVE_DOWN,
|
|
132
|
+
onClick: function () {
|
|
133
|
+
return setValue(moveInArray(value, index + items.length, 1));
|
|
134
|
+
},
|
|
135
|
+
uiSchema: uiSchema,
|
|
136
|
+
})] })] }, index)); })] }), additionalItems &&
|
|
137
|
+
GetArrayFieldButton({
|
|
138
|
+
purpose: ArrayFieldButtonPurpose.ADD,
|
|
139
|
+
onClick: function () { return setValue(appendArray(value)); },
|
|
140
|
+
uiSchema: uiSchema,
|
|
141
|
+
})] })));
|
|
119
142
|
}
|
|
@@ -25,11 +25,14 @@ import { useField } from "formik";
|
|
|
25
25
|
import { useContext, useMemo } from "react";
|
|
26
26
|
import { FormRegistry } from "../Form";
|
|
27
27
|
import { ObjectFieldButtonPurpose } from "../types";
|
|
28
|
+
import { useSetDefault } from "../utils";
|
|
29
|
+
import { getObjectFieldButton } from "../styledComponents";
|
|
28
30
|
export function ObjectField(props) {
|
|
29
|
-
var _a = useContext(FormRegistry), SchemaField = _a.fields.SchemaField, ObjectFieldTemplate = _a.templates.ObjectFieldTemplate, _b = _a.components, ObjectFieldItem = _b.ObjectFieldItem,
|
|
31
|
+
var _a = useContext(FormRegistry), SchemaField = _a.fields.SchemaField, ObjectFieldTemplate = _a.templates.ObjectFieldTemplate, _b = _a.components, ObjectFieldItem = _b.ObjectFieldItem, ObjectFieldItemButtons = _b.ObjectFieldItemButtons, hideUnmarkedAdditionalProperties = _a.hideUnmarkedAdditionalProperties;
|
|
32
|
+
useSetDefault(props);
|
|
30
33
|
var name = props.name, schema = props.schema, uiSchema = props.uiSchema;
|
|
31
34
|
var _c = useField(name), value = _c[0].value, _ = _c[1], setValue = _c[2].setValue;
|
|
32
|
-
var properties = schema.properties, additionalProperties = schema.additionalProperties;
|
|
35
|
+
var properties = schema.properties, additionalProperties = schema.additionalProperties, required = schema.required;
|
|
33
36
|
var propertyKeys = useMemo(function () { return Object.keys(properties || {}); }, [properties]);
|
|
34
37
|
var additionalValues = useMemo(function () {
|
|
35
38
|
return Object.fromEntries(Object.entries(value || {}).filter(function (_a) {
|
|
@@ -39,19 +42,28 @@ export function ObjectField(props) {
|
|
|
39
42
|
}, [value, propertyKeys]);
|
|
40
43
|
return (_jsxs(ObjectFieldTemplate, __assign({}, props, { children: [Object.entries(properties || {}).map(function (_a) {
|
|
41
44
|
var childName = _a[0], childSchema = _a[1];
|
|
42
|
-
return (_jsx(SchemaField, { name: name ? [name, childName].join(".") : childName, schema: typeof childSchema !== "boolean" ? childSchema : {}, uiSchema: uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema[childName] }, childName));
|
|
45
|
+
return (_jsx(SchemaField, { required: required === null || required === void 0 ? void 0 : required.includes(childName), name: name ? [name, childName].join(".") : childName, schema: typeof childSchema !== "boolean" ? childSchema : {}, uiSchema: uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema[childName] }, childName));
|
|
43
46
|
}), (!hideUnmarkedAdditionalProperties || additionalProperties) &&
|
|
44
47
|
Object.entries(additionalValues || {}).map(function (_a) {
|
|
45
48
|
var childName = _a[0], childSchema = _a[1];
|
|
46
|
-
return (_jsxs(ObjectFieldItem, { children: [_jsx(SchemaField, { name: name ? [name, childName].join(".") : childName, schema: typeof childSchema !== "boolean" ? childSchema : {}, uiSchema: uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema[childName] }), _jsx(ObjectFieldItemButtons, { children:
|
|
49
|
+
return (_jsxs(ObjectFieldItem, { children: [_jsx(SchemaField, { required: required === null || required === void 0 ? void 0 : required.includes(childName), name: name ? [name, childName].join(".") : childName, schema: typeof childSchema !== "boolean" ? childSchema : {}, uiSchema: uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema[childName] }, childName), _jsx(ObjectFieldItemButtons, { children: getObjectFieldButton({
|
|
50
|
+
purpose: ObjectFieldButtonPurpose.REMOVE,
|
|
51
|
+
onClick: function () {
|
|
47
52
|
var _a = value, _b = childName, _removedProperty = _a[_b], newValue = __rest(_a, [typeof _b === "symbol" ? _b : _b + ""]);
|
|
48
53
|
setValue(newValue);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
},
|
|
55
|
+
uiSchema: uiSchema,
|
|
56
|
+
}) })] }, childName));
|
|
57
|
+
}), additionalProperties &&
|
|
58
|
+
getObjectFieldButton({
|
|
59
|
+
purpose: ObjectFieldButtonPurpose.ADD,
|
|
60
|
+
onClick: function () {
|
|
61
|
+
var _a;
|
|
62
|
+
var key = prompt("Give key");
|
|
63
|
+
if (key) {
|
|
64
|
+
setValue(__assign(__assign({}, value), (_a = {}, _a[key] = undefined, _a)));
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
uiSchema: uiSchema,
|
|
68
|
+
})] })));
|
|
57
69
|
}
|
|
@@ -14,7 +14,7 @@ import { useContext } from "react";
|
|
|
14
14
|
import { useExtractUiSchema, getSchemaType } from "../utils";
|
|
15
15
|
import { FormRegistry } from "../Form";
|
|
16
16
|
import { COMPONENT_TYPES } from "./types";
|
|
17
|
-
function
|
|
17
|
+
function useFieldComponent(schema, uiSchema, fields) {
|
|
18
18
|
var field = useExtractUiSchema(uiSchema).field;
|
|
19
19
|
if (typeof field === "function") {
|
|
20
20
|
return field;
|
|
@@ -34,6 +34,6 @@ function getFieldComponent(schema, uiSchema, fields) {
|
|
|
34
34
|
export function SchemaField(props) {
|
|
35
35
|
var schema = props.schema, uiSchema = props.uiSchema;
|
|
36
36
|
var fields = useContext(FormRegistry).fields;
|
|
37
|
-
var FieldComponent =
|
|
37
|
+
var FieldComponent = useFieldComponent(schema, uiSchema, fields);
|
|
38
38
|
return _jsx(FieldComponent, __assign({}, props));
|
|
39
39
|
}
|
|
@@ -53,7 +53,7 @@ export function StringField(props) {
|
|
|
53
53
|
switch (enums === null || enums === void 0 ? void 0 : enums.type) {
|
|
54
54
|
case "select":
|
|
55
55
|
case "multiSelect":
|
|
56
|
-
return (_jsx(FieldTemplate, __assign({}, props, { children: _jsxs(FieldInput, __assign({}, __assign({ type: type, placeholder: placeholder }, inputProps), { name: name, formikAs: "select", multiple: enums.type === "multiSelect" }, { children: [enums.type !== "multiSelect" && _jsx("option", { value: "" }), enums === null || enums === void 0 ? void 0 : enums.values.map(function (option, index) { return (_jsx("option", __assign({ value: option.const }, { children: option.title }), index)); })] })) })));
|
|
56
|
+
return (_jsx(FieldTemplate, __assign({}, props, { children: _jsxs(FieldInput, __assign({}, __assign({ type: type, placeholder: placeholder }, inputProps), { name: name, formikAs: "select", multiple: enums.type === "multiSelect" }, { children: [enums.type !== "multiSelect" && (_jsx("option", __assign({ value: "", disabled: true, selected: true, hidden: true }, { children: placeholder }))), enums === null || enums === void 0 ? void 0 : enums.values.map(function (option, index) { return (_jsx("option", __assign({ value: option.const }, { children: option.title }), index)); })] })) })));
|
|
57
57
|
default:
|
|
58
58
|
return (_jsx(FieldTemplate, __assign({}, props, { children: _jsx(FieldInput, __assign({}, __assign({ type: type, placeholder: placeholder }, inputProps), { name: name })) })));
|
|
59
59
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import * as formik from "formik";
|
|
3
|
-
import { ArrayFieldButtonProps, ObjectFieldButtonProps } from "./types";
|
|
3
|
+
import { ArrayFieldButtonProps, InfoFieldButtonProps, ObjectFieldButtonProps } from "./types";
|
|
4
4
|
export declare const Form: import("styled-components").StyledComponent<import("react").ForwardRefExoticComponent<Pick<import("react").DetailedHTMLProps<import("react").FormHTMLAttributes<HTMLFormElement>, HTMLFormElement>, "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "className" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "placeholder" | "slot" | "spellCheck" | "style" | "tabIndex" | "title" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "children" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "name" | "acceptCharset" | "action" | "autoComplete" | "encType" | "method" | "noValidate" | "target" | "key"> & import("react").RefAttributes<HTMLFormElement>>, any, {}, never>;
|
|
5
5
|
export declare const FormButtonWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
6
6
|
export declare const FormButton: import("styled-components").StyledComponent<"button", any, {}, never>;
|
|
@@ -9,18 +9,48 @@ export declare const ObjectFieldTitle: import("styled-components").StyledCompone
|
|
|
9
9
|
export declare const ObjectFieldList: import("styled-components").StyledComponent<"ul", any, {}, never>;
|
|
10
10
|
export declare const ObjectFieldItem: import("styled-components").StyledComponent<"li", any, {}, never>;
|
|
11
11
|
export declare const ObjectFieldItemButtons: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
12
|
-
export declare const
|
|
13
|
-
export declare
|
|
12
|
+
export declare const ObjectFieldButton: import("styled-components").StyledComponent<"a", any, {}, never>;
|
|
13
|
+
export declare const ObjectFieldLineButton: import("styled-components").StyledComponent<"a", any, {}, never>;
|
|
14
|
+
export declare const ObjectFieldUpButton: import("styled-components").StyledComponent<"a", any, {}, never>;
|
|
15
|
+
export declare const ObjectFieldDownButton: import("styled-components").StyledComponent<"a", any, {}, never>;
|
|
16
|
+
export declare const ObjectFieldRemoveButton: import("styled-components").StyledComponent<"a", any, {}, never>;
|
|
17
|
+
export declare const ObjectFieldAddButton: import("styled-components").StyledComponent<"a", any, {}, never>;
|
|
18
|
+
export declare function getObjectFieldButton({ purpose, onClick, uiSchema, }: ObjectFieldButtonProps): JSX.Element;
|
|
14
19
|
export declare const ArrayFieldWrapper: import("styled-components").StyledComponent<"fieldset", any, {}, never>;
|
|
15
20
|
export declare const ArrayFieldTitle: import("styled-components").StyledComponent<"legend", any, {}, never>;
|
|
16
21
|
export declare const ArrayFieldList: import("styled-components").StyledComponent<"ul", any, {}, never>;
|
|
17
22
|
export declare const ArrayFieldItem: import("styled-components").StyledComponent<"li", any, {}, never>;
|
|
18
23
|
export declare const ArrayFieldItemButtons: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
19
|
-
export declare const
|
|
20
|
-
export declare
|
|
24
|
+
export declare const ArrayFieldButton: import("styled-components").StyledComponent<"a", any, {}, never>;
|
|
25
|
+
export declare const ArrayFieldLineButton: import("styled-components").StyledComponent<"a", any, {}, never>;
|
|
26
|
+
export declare const ArrayFieldUpButton: import("styled-components").StyledComponent<"a", any, {}, never>;
|
|
27
|
+
export declare const ArrayFieldDownButton: import("styled-components").StyledComponent<"a", any, {}, never>;
|
|
28
|
+
export declare const ArrayFieldRemoveButton: import("styled-components").StyledComponent<"a", any, {}, never>;
|
|
29
|
+
export declare const ArrayFieldAddButton: import("styled-components").StyledComponent<"a", any, {}, never>;
|
|
30
|
+
export declare function GetArrayFieldButton({ purpose, onClick, uiSchema, }: ArrayFieldButtonProps): JSX.Element;
|
|
21
31
|
export declare const FieldWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
22
32
|
export declare const FieldTitle: import("styled-components").StyledComponent<"label", any, {}, never>;
|
|
23
33
|
export declare const FieldDescription: import("styled-components").StyledComponent<"p", any, {}, never>;
|
|
24
34
|
export declare const FieldHelp: import("styled-components").StyledComponent<"p", any, {}, never>;
|
|
35
|
+
interface InfoFieldBoxElementProps {
|
|
36
|
+
position: "top" | "right" | "bottom" | "left";
|
|
37
|
+
}
|
|
38
|
+
export declare const InfoFieldBoxElement: import("styled-components").StyledComponent<"div", any, InfoFieldBoxElementProps, never>;
|
|
39
|
+
export declare const InfoFieldBoxArrowElement: import("styled-components").StyledComponent<"div", any, InfoFieldBoxElementProps, never>;
|
|
40
|
+
export declare const InfoFieldBoxInnerElement: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
41
|
+
export declare const InfoFieldContainerElement: import("styled-components").StyledComponent<"a", any, {}, never>;
|
|
42
|
+
export declare const InfoFieldLabel: import("styled-components").StyledComponent<"span", any, {}, never>;
|
|
43
|
+
export declare const InfoFieldButton: {
|
|
44
|
+
({ label, content, position, props, className, }: InfoFieldButtonProps): JSX.Element;
|
|
45
|
+
styles: {
|
|
46
|
+
InfoFieldContainerElementStyle: import("styled-components").StyledComponent<"a", any, {}, never>;
|
|
47
|
+
InfoFieldBoxElementStyle: import("styled-components").StyledComponent<"div", any, InfoFieldBoxElementProps, never>;
|
|
48
|
+
InfoFieldBoxInnerElementStyle: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
49
|
+
InfoFieldBoxArrowElementStyle: import("styled-components").StyledComponent<"div", any, InfoFieldBoxElementProps, never>;
|
|
50
|
+
InfoFieldLabelStyle: import("styled-components").StyledComponent<"span", any, {}, never>;
|
|
51
|
+
};
|
|
52
|
+
};
|
|
25
53
|
export declare const ErrorMessage: import("styled-components").StyledComponent<import("react").ComponentType<formik.ErrorMessageProps>, any, {}, never>;
|
|
26
54
|
export declare const FieldInput: import("styled-components").StyledComponent<({ formikAs, ...props }: any) => JSX.Element, any, {}, never>;
|
|
55
|
+
export declare const RequiredIndicator: import("styled-components").StyledComponent<"span", any, {}, never>;
|
|
56
|
+
export {};
|
package/dist/styledComponents.js
CHANGED
|
@@ -24,10 +24,12 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
24
24
|
}
|
|
25
25
|
return t;
|
|
26
26
|
};
|
|
27
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
27
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
28
28
|
import styled from "styled-components";
|
|
29
29
|
import * as formik from "formik";
|
|
30
30
|
import { ArrayFieldButtonPurpose, ObjectFieldButtonPurpose, } from "./types";
|
|
31
|
+
import { useContext } from "react";
|
|
32
|
+
import { FormRegistry } from "./Form";
|
|
31
33
|
export var Form = styled(formik.Form)(templateObject_1 || (templateObject_1 = __makeTemplateObject([""], [""])));
|
|
32
34
|
export var FormButtonWrapper = styled.div(templateObject_2 || (templateObject_2 = __makeTemplateObject([""], [""])));
|
|
33
35
|
export var FormButton = styled.button(templateObject_3 || (templateObject_3 = __makeTemplateObject([""], [""])));
|
|
@@ -36,20 +38,26 @@ export var ObjectFieldTitle = styled.legend(templateObject_5 || (templateObject_
|
|
|
36
38
|
export var ObjectFieldList = styled.ul(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n list-style-type: none;\n padding: 0;\n"], ["\n list-style-type: none;\n padding: 0;\n"])));
|
|
37
39
|
export var ObjectFieldItem = styled.li(templateObject_7 || (templateObject_7 = __makeTemplateObject(["\n display: flex;\n"], ["\n display: flex;\n"])));
|
|
38
40
|
export var ObjectFieldItemButtons = styled.div(templateObject_8 || (templateObject_8 = __makeTemplateObject(["\n display: flex;\n margin: 0.5rem;\n"], ["\n display: flex;\n margin: 0.5rem;\n"])));
|
|
39
|
-
export var
|
|
40
|
-
export
|
|
41
|
-
|
|
41
|
+
export var ObjectFieldButton = styled.a(templateObject_9 || (templateObject_9 = __makeTemplateObject(["\n cursor: pointer;\n border: 1px solid black;\n line-height: 1em;\n height: 1em;\n padding: 0 0.3em;\n"], ["\n cursor: pointer;\n border: 1px solid black;\n line-height: 1em;\n height: 1em;\n padding: 0 0.3em;\n"])));
|
|
42
|
+
export var ObjectFieldLineButton = styled(ObjectFieldButton)(templateObject_10 || (templateObject_10 = __makeTemplateObject([""], [""])));
|
|
43
|
+
export var ObjectFieldUpButton = styled(ObjectFieldLineButton)(templateObject_11 || (templateObject_11 = __makeTemplateObject([""], [""])));
|
|
44
|
+
export var ObjectFieldDownButton = styled(ObjectFieldLineButton)(templateObject_12 || (templateObject_12 = __makeTemplateObject([""], [""])));
|
|
45
|
+
export var ObjectFieldRemoveButton = styled(ObjectFieldLineButton)(templateObject_13 || (templateObject_13 = __makeTemplateObject([""], [""])));
|
|
46
|
+
export var ObjectFieldAddButton = styled(ObjectFieldButton)(templateObject_14 || (templateObject_14 = __makeTemplateObject([""], [""])));
|
|
47
|
+
export function getObjectFieldButton(_a) {
|
|
48
|
+
var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
|
|
49
|
+
var purpose = _a.purpose, onClick = _a.onClick, uiSchema = _a.uiSchema;
|
|
42
50
|
switch (purpose) {
|
|
43
51
|
case ObjectFieldButtonPurpose.ADD:
|
|
44
|
-
return _jsx(
|
|
52
|
+
return (_jsx(ObjectFieldAddButton, __assign({}, ((_c = (_b = uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema["ui:addButtonOptions"]) === null || _b === void 0 ? void 0 : _b.props) !== null && _c !== void 0 ? _c : {}), { onClick: onClick }, { children: (_e = (_d = uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema["ui:addButtonOptions"]) === null || _d === void 0 ? void 0 : _d.content) !== null && _e !== void 0 ? _e : "+" })));
|
|
45
53
|
case ObjectFieldButtonPurpose.REMOVE:
|
|
46
|
-
return _jsx(
|
|
54
|
+
return (_jsx(ObjectFieldRemoveButton, __assign({}, ((_g = (_f = uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema["ui:removeButtonOptions"]) === null || _f === void 0 ? void 0 : _f.props) !== null && _g !== void 0 ? _g : {}), { onClick: onClick }, { children: (_j = (_h = uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema["ui:removeButtonOptions"]) === null || _h === void 0 ? void 0 : _h.content) !== null && _j !== void 0 ? _j : "-" })));
|
|
47
55
|
case ObjectFieldButtonPurpose.MOVE_UP:
|
|
48
|
-
return _jsx(
|
|
56
|
+
return (_jsx(ObjectFieldUpButton, __assign({}, ((_l = (_k = uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema["ui:upButtonOptions"]) === null || _k === void 0 ? void 0 : _k.props) !== null && _l !== void 0 ? _l : {}), { onClick: onClick }, { children: (_o = (_m = uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema["ui:upButtonOptions"]) === null || _m === void 0 ? void 0 : _m.content) !== null && _o !== void 0 ? _o : "↑" })));
|
|
49
57
|
case ObjectFieldButtonPurpose.MOVE_DOWN:
|
|
50
|
-
return _jsx(
|
|
58
|
+
return (_jsx(ObjectFieldDownButton, __assign({}, ((_q = (_p = uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema["ui:downButtonOptions"]) === null || _p === void 0 ? void 0 : _p.props) !== null && _q !== void 0 ? _q : {}), { onClick: onClick }, { children: (_s = (_r = uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema["ui:downButtonOptions"]) === null || _r === void 0 ? void 0 : _r.content) !== null && _s !== void 0 ? _s : "↓" })));
|
|
51
59
|
default:
|
|
52
|
-
return (_jsx(
|
|
60
|
+
return (_jsx(ObjectFieldButton, __assign({}, ((_u = (_t = uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema["ui:customButtonOptions"]) === null || _t === void 0 ? void 0 : _t.props) !== null && _u !== void 0 ? _u : {}), { onClick: onClick }, { children: (_w = (_v = uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema["ui:customButtonOptions"]) === null || _v === void 0 ? void 0 : _v.content) !== null && _w !== void 0 ? _w : "" })));
|
|
53
61
|
}
|
|
54
62
|
}
|
|
55
63
|
export var ArrayFieldWrapper = ObjectFieldWrapper;
|
|
@@ -57,27 +65,109 @@ export var ArrayFieldTitle = ObjectFieldTitle;
|
|
|
57
65
|
export var ArrayFieldList = ObjectFieldList;
|
|
58
66
|
export var ArrayFieldItem = ObjectFieldItem;
|
|
59
67
|
export var ArrayFieldItemButtons = ObjectFieldItemButtons;
|
|
60
|
-
export var
|
|
61
|
-
export
|
|
62
|
-
|
|
68
|
+
export var ArrayFieldButton = styled(ObjectFieldButton)(templateObject_15 || (templateObject_15 = __makeTemplateObject([""], [""])));
|
|
69
|
+
export var ArrayFieldLineButton = styled(ArrayFieldButton)(templateObject_16 || (templateObject_16 = __makeTemplateObject([""], [""])));
|
|
70
|
+
export var ArrayFieldUpButton = styled(ArrayFieldLineButton)(templateObject_17 || (templateObject_17 = __makeTemplateObject([""], [""])));
|
|
71
|
+
export var ArrayFieldDownButton = styled(ArrayFieldLineButton)(templateObject_18 || (templateObject_18 = __makeTemplateObject([""], [""])));
|
|
72
|
+
export var ArrayFieldRemoveButton = styled(ArrayFieldLineButton)(templateObject_19 || (templateObject_19 = __makeTemplateObject([""], [""])));
|
|
73
|
+
export var ArrayFieldAddButton = styled(ArrayFieldButton)(templateObject_20 || (templateObject_20 = __makeTemplateObject([""], [""])));
|
|
74
|
+
export function GetArrayFieldButton(_a) {
|
|
75
|
+
var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
|
|
76
|
+
var purpose = _a.purpose, onClick = _a.onClick, uiSchema = _a.uiSchema;
|
|
77
|
+
var _x = useContext(FormRegistry).components, ArrayFieldAddButton = _x.ArrayFieldAddButton, ArrayFieldRemoveButton = _x.ArrayFieldRemoveButton, ArrayFieldUpButton = _x.ArrayFieldUpButton, ArrayFieldDownButton = _x.ArrayFieldDownButton;
|
|
63
78
|
switch (purpose) {
|
|
64
79
|
case ArrayFieldButtonPurpose.ADD:
|
|
65
|
-
return _jsx(
|
|
80
|
+
return (_jsx(ArrayFieldAddButton, __assign({}, ((_c = (_b = uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema["ui:addButtonOptions"]) === null || _b === void 0 ? void 0 : _b.props) !== null && _c !== void 0 ? _c : {}), { onClick: onClick }, { children: (_e = (_d = uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema["ui:addButtonOptions"]) === null || _d === void 0 ? void 0 : _d.content) !== null && _e !== void 0 ? _e : "+" })));
|
|
66
81
|
case ArrayFieldButtonPurpose.REMOVE:
|
|
67
|
-
return _jsx(
|
|
82
|
+
return (_jsx(ArrayFieldRemoveButton, __assign({}, ((_g = (_f = uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema["ui:removeButtonOptions"]) === null || _f === void 0 ? void 0 : _f.props) !== null && _g !== void 0 ? _g : {}), { onClick: onClick }, { children: (_j = (_h = uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema["ui:removeButtonOptions"]) === null || _h === void 0 ? void 0 : _h.content) !== null && _j !== void 0 ? _j : "-" })));
|
|
68
83
|
case ArrayFieldButtonPurpose.MOVE_UP:
|
|
69
|
-
return _jsx(
|
|
84
|
+
return (_jsx(ArrayFieldUpButton, __assign({}, ((_l = (_k = uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema["ui:upButtonOptions"]) === null || _k === void 0 ? void 0 : _k.props) !== null && _l !== void 0 ? _l : {}), { onClick: onClick }, { children: (_o = (_m = uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema["ui:upButtonOptions"]) === null || _m === void 0 ? void 0 : _m.content) !== null && _o !== void 0 ? _o : "↑" })));
|
|
70
85
|
case ArrayFieldButtonPurpose.MOVE_DOWN:
|
|
71
|
-
return _jsx(
|
|
86
|
+
return (_jsx(ArrayFieldDownButton, __assign({}, ((_q = (_p = uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema["ui:downButtonOptions"]) === null || _p === void 0 ? void 0 : _p.props) !== null && _q !== void 0 ? _q : {}), { onClick: onClick }, { children: (_s = (_r = uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema["ui:downButtonOptions"]) === null || _r === void 0 ? void 0 : _r.content) !== null && _s !== void 0 ? _s : "↓" })));
|
|
72
87
|
default:
|
|
73
|
-
return (_jsx(
|
|
88
|
+
return (_jsx(ArrayFieldButton, __assign({}, ((_u = (_t = uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema["ui:customButtonOptions"]) === null || _t === void 0 ? void 0 : _t.props) !== null && _u !== void 0 ? _u : {}), { onClick: onClick }, { children: (_w = (_v = uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema["ui:customButtonOptions"]) === null || _v === void 0 ? void 0 : _v.content) !== null && _w !== void 0 ? _w : "" })));
|
|
74
89
|
}
|
|
75
90
|
}
|
|
76
|
-
export var FieldWrapper = styled.div(
|
|
77
|
-
export var FieldTitle = styled.label(
|
|
78
|
-
export var FieldDescription = styled.p(
|
|
79
|
-
export var FieldHelp = styled.p(
|
|
80
|
-
export var
|
|
91
|
+
export var FieldWrapper = styled.div(templateObject_21 || (templateObject_21 = __makeTemplateObject(["\n margin: 0.5rem 0;\n"], ["\n margin: 0.5rem 0;\n"])));
|
|
92
|
+
export var FieldTitle = styled.label(templateObject_22 || (templateObject_22 = __makeTemplateObject(["\n font-weight: 700;\n"], ["\n font-weight: 700;\n"])));
|
|
93
|
+
export var FieldDescription = styled.p(templateObject_23 || (templateObject_23 = __makeTemplateObject(["\n margin: 0;\n font-size: 0.9em;\n"], ["\n margin: 0;\n font-size: 0.9em;\n"])));
|
|
94
|
+
export var FieldHelp = styled.p(templateObject_24 || (templateObject_24 = __makeTemplateObject(["\n margin: 0;\n font-size: 0.9em;\n"], ["\n margin: 0;\n font-size: 0.9em;\n"])));
|
|
95
|
+
export var InfoFieldBoxElement = styled.div(templateObject_25 || (templateObject_25 = __makeTemplateObject(["\n transition: opacity 0.5s;\n position: absolute;\n z-index: 1080;\n opacity: 0;\n visibility: hidden;\n margin: 0;\n font-size: 0.875rem;\n word-wrap: break-word;\n min-width: max-content;\n\n top: ", ";\n bottom: ", ";\n left: ", ";\n right: ", ";\n transform: translate(\n ", ",\n ", "\n );\n"], ["\n transition: opacity 0.5s;\n position: absolute;\n z-index: 1080;\n opacity: 0;\n visibility: hidden;\n margin: 0;\n font-size: 0.875rem;\n word-wrap: break-word;\n min-width: max-content;\n\n top: ", ";\n bottom: ", ";\n left: ", ";\n right: ", ";\n transform: translate(\n ", ",\n ", "\n );\n"])), function (_a) {
|
|
96
|
+
var position = _a.position;
|
|
97
|
+
return position === "bottom" ? "140%" : position === "top" ? "auto" : "50%";
|
|
98
|
+
}, function (_a) {
|
|
99
|
+
var position = _a.position;
|
|
100
|
+
return position === "top"
|
|
101
|
+
? "140%"
|
|
102
|
+
: position === "right" || position === "left"
|
|
103
|
+
? "50%"
|
|
104
|
+
: "auto";
|
|
105
|
+
}, function (_a) {
|
|
106
|
+
var position = _a.position;
|
|
107
|
+
return position === "right"
|
|
108
|
+
? "100%"
|
|
109
|
+
: position === "bottom" || position === "top"
|
|
110
|
+
? "50%"
|
|
111
|
+
: "auto";
|
|
112
|
+
}, function (_a) {
|
|
113
|
+
var position = _a.position;
|
|
114
|
+
return position === "left"
|
|
115
|
+
? "100%"
|
|
116
|
+
: position === "bottom" || position === "top"
|
|
117
|
+
? "50%"
|
|
118
|
+
: "auto";
|
|
119
|
+
}, function (_a) {
|
|
120
|
+
var position = _a.position;
|
|
121
|
+
return position === "bottom" || position === "top" ? "-50%" : "0";
|
|
122
|
+
}, function (_a) {
|
|
123
|
+
var position = _a.position;
|
|
124
|
+
return position === "right" || position === "left" ? "-50%" : "0";
|
|
125
|
+
});
|
|
126
|
+
export var InfoFieldBoxArrowElement = styled.div(templateObject_26 || (templateObject_26 = __makeTemplateObject(["\n top: ", ";\n left: ", ";\n bottom: ", ";\n border: solid transparent;\n content: \"\";\n height: 0;\n width: 0;\n position: absolute;\n pointer-events: none;\n border-top-color: ", ";\n border-bottom-color: ", ";\n border-right-color: ", ";\n border-left-color: ", ";\n border-width: 5px;\n margin-left: -5px;\n"], ["\n top: ", ";\n left: ", ";\n bottom: ", ";\n border: solid transparent;\n content: \"\";\n height: 0;\n width: 0;\n position: absolute;\n pointer-events: none;\n border-top-color: ", ";\n border-bottom-color: ", ";\n border-right-color: ", ";\n border-left-color: ", ";\n border-width: 5px;\n margin-left: -5px;\n"])), function (_a) {
|
|
127
|
+
var position = _a.position;
|
|
128
|
+
return position === "top"
|
|
129
|
+
? "100%"
|
|
130
|
+
: position === "right" || position === "left"
|
|
131
|
+
? "40%"
|
|
132
|
+
: "unset";
|
|
133
|
+
}, function (_a) {
|
|
134
|
+
var position = _a.position;
|
|
135
|
+
return position === "top" || position === "bottom"
|
|
136
|
+
? "50%"
|
|
137
|
+
: position === "right"
|
|
138
|
+
? "-2%"
|
|
139
|
+
: "102.5%";
|
|
140
|
+
}, function (_a) {
|
|
141
|
+
var position = _a.position;
|
|
142
|
+
return (position === "bottom" ? "100%" : "unset");
|
|
143
|
+
}, function (_a) {
|
|
144
|
+
var position = _a.position;
|
|
145
|
+
return position === "top" ? "grey" : "transparent";
|
|
146
|
+
}, function (_a) {
|
|
147
|
+
var position = _a.position;
|
|
148
|
+
return position === "bottom" ? "grey" : "transparent";
|
|
149
|
+
}, function (_a) {
|
|
150
|
+
var position = _a.position;
|
|
151
|
+
return position === "right" ? "grey" : "transparent";
|
|
152
|
+
}, function (_a) {
|
|
153
|
+
var position = _a.position;
|
|
154
|
+
return position === "left" ? "grey" : "transparent";
|
|
155
|
+
});
|
|
156
|
+
export var InfoFieldBoxInnerElement = styled.div(templateObject_27 || (templateObject_27 = __makeTemplateObject(["\n padding: 0.25rem 0.5rem;\n color: white;\n text-align: center;\n background: grey;\n border: solid 1px grey;\n border-radius: 0.25rem;\n cursor: default;\n"], ["\n padding: 0.25rem 0.5rem;\n color: white;\n text-align: center;\n background: grey;\n border: solid 1px grey;\n border-radius: 0.25rem;\n cursor: default;\n"])));
|
|
157
|
+
export var InfoFieldContainerElement = styled.a(templateObject_28 || (templateObject_28 = __makeTemplateObject(["\n position: relative;\n color: black;\n background: none;\n outline: none;\n cursor: pointer;\n border: 1px solid black;\n border-radius: 50%;\n line-height: 1em;\n font-size: 0.7em;\n padding: 0 0.44em;\n text-decoration: unset;\n\n &:active,\n &:focus {\n color: white;\n background: black;\n ", " {\n opacity: 1;\n visibility: visible;\n }\n }\n"], ["\n position: relative;\n color: black;\n background: none;\n outline: none;\n cursor: pointer;\n border: 1px solid black;\n border-radius: 50%;\n line-height: 1em;\n font-size: 0.7em;\n padding: 0 0.44em;\n text-decoration: unset;\n\n &:active,\n &:focus {\n color: white;\n background: black;\n ", " {\n opacity: 1;\n visibility: visible;\n }\n }\n"])), InfoFieldBoxElement);
|
|
158
|
+
export var InfoFieldLabel = styled.span(templateObject_29 || (templateObject_29 = __makeTemplateObject([""], [""])));
|
|
159
|
+
export var InfoFieldButton = function (_a) {
|
|
160
|
+
var label = _a.label, content = _a.content, position = _a.position, props = _a.props, className = _a.className;
|
|
161
|
+
return (_jsxs(InfoFieldContainerElement, __assign({ href: "#", onClick: function (e) { return e.preventDefault(); }, className: className }, { children: [_jsx(InfoFieldLabel, { children: label !== null && label !== void 0 ? label : "i" }), _jsxs(InfoFieldBoxElement, __assign({ 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
|
+
};
|
|
163
|
+
InfoFieldButton.styles = {
|
|
164
|
+
InfoFieldContainerElementStyle: InfoFieldContainerElement,
|
|
165
|
+
InfoFieldBoxElementStyle: InfoFieldBoxElement,
|
|
166
|
+
InfoFieldBoxInnerElementStyle: InfoFieldBoxInnerElement,
|
|
167
|
+
InfoFieldBoxArrowElementStyle: InfoFieldBoxArrowElement,
|
|
168
|
+
InfoFieldLabelStyle: InfoFieldLabel,
|
|
169
|
+
};
|
|
170
|
+
export var ErrorMessage = styled(formik.ErrorMessage)(templateObject_30 || (templateObject_30 = __makeTemplateObject([""], [""])));
|
|
81
171
|
/*
|
|
82
172
|
* Works like Formik field, but "as" props needs to be given with "formikAs", since styled components uses as.
|
|
83
173
|
*
|
|
@@ -85,5 +175,6 @@ export var ErrorMessage = styled(formik.ErrorMessage)(templateObject_14 || (temp
|
|
|
85
175
|
export var FieldInput = styled(function (_a) {
|
|
86
176
|
var formikAs = _a.formikAs, props = __rest(_a, ["formikAs"]);
|
|
87
177
|
return _jsx(formik.Field, __assign({}, props, { as: formikAs }));
|
|
88
|
-
})(
|
|
89
|
-
var
|
|
178
|
+
})(templateObject_31 || (templateObject_31 = __makeTemplateObject([""], [""])));
|
|
179
|
+
export var RequiredIndicator = styled.span(templateObject_32 || (templateObject_32 = __makeTemplateObject([""], [""])));
|
|
180
|
+
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7, templateObject_8, templateObject_9, templateObject_10, templateObject_11, templateObject_12, templateObject_13, templateObject_14, templateObject_15, templateObject_16, templateObject_17, templateObject_18, templateObject_19, templateObject_20, templateObject_21, templateObject_22, templateObject_23, templateObject_24, templateObject_25, templateObject_26, templateObject_27, templateObject_28, templateObject_29, templateObject_30, templateObject_31, templateObject_32;
|
|
@@ -14,14 +14,14 @@ import { useContext } from "react";
|
|
|
14
14
|
import { FormRegistry } from "../Form";
|
|
15
15
|
import { useExtractUiSchema, getDescription, getTitle } from "../utils";
|
|
16
16
|
export function ArrayFieldTemplate(props) {
|
|
17
|
-
var _a = useContext(FormRegistry).components, ArrayFieldWrapper = _a.ArrayFieldWrapper, ArrayFieldTitle = _a.ArrayFieldTitle, FieldDescription = _a.FieldDescription, ErrorMessage = _a.ErrorMessage, FieldHelp = _a.FieldHelp;
|
|
17
|
+
var _a = useContext(FormRegistry).components, ArrayFieldWrapper = _a.ArrayFieldWrapper, ArrayFieldTitle = _a.ArrayFieldTitle, FieldDescription = _a.FieldDescription, ErrorMessage = _a.ErrorMessage, FieldHelp = _a.FieldHelp, InfoFieldButton = _a.InfoFieldButton;
|
|
18
18
|
var name = props.name, uiSchema = props.uiSchema, children = props.children;
|
|
19
19
|
var title = getTitle(props);
|
|
20
20
|
var description = getDescription(props);
|
|
21
|
-
var _b = useExtractUiSchema(uiSchema), help = _b.help,
|
|
21
|
+
var _b = useExtractUiSchema(uiSchema), help = _b.help, info = _b.info,
|
|
22
22
|
//TODO: This is not right
|
|
23
23
|
_c = _b.props,
|
|
24
24
|
//TODO: This is not right
|
|
25
25
|
_d = _c === void 0 ? {} : _c, wrappertProps = _d.wrapper, titleProps = _d.title, descriptionProps = _d.description, helpProps = _d.help, errorProps = _d.error;
|
|
26
|
-
return (_jsxs(ArrayFieldWrapper, __assign({}, wrappertProps, { children: [title && (_jsx(ArrayFieldTitle, __assign({}, titleProps, { htmlFor: name }, { children: title }))), description && (_jsx(FieldDescription, __assign({}, descriptionProps, { children: description }))), children, help && _jsx(FieldHelp, __assign({}, helpProps, { children: help })), _jsx(ErrorMessage, __assign({}, errorProps, { name: name }))] })));
|
|
26
|
+
return (_jsxs(ArrayFieldWrapper, __assign({}, wrappertProps, { children: [title && (_jsx(ArrayFieldTitle, __assign({}, titleProps, { htmlFor: name }, { children: title }))), info && _jsx(InfoFieldButton, __assign({}, info)), description && (_jsx(FieldDescription, __assign({}, descriptionProps, { children: description }))), children, help && _jsx(FieldHelp, __assign({}, helpProps, { children: help })), _jsx(ErrorMessage, __assign({}, errorProps, { name: name }))] })));
|
|
27
27
|
}
|
|
@@ -14,14 +14,14 @@ import { useContext } from "react";
|
|
|
14
14
|
import { FormRegistry } from "../Form";
|
|
15
15
|
import { useExtractUiSchema, getDescription, getTitle } from "../utils";
|
|
16
16
|
export function FieldTemplate(props) {
|
|
17
|
-
var _a = useContext(FormRegistry).components, FieldWrapper = _a.FieldWrapper, FieldTitle = _a.FieldTitle, FieldDescription = _a.FieldDescription, ErrorMessage = _a.ErrorMessage, FieldHelp = _a.FieldHelp;
|
|
17
|
+
var _a = useContext(FormRegistry).components, FieldWrapper = _a.FieldWrapper, FieldTitle = _a.FieldTitle, FieldDescription = _a.FieldDescription, ErrorMessage = _a.ErrorMessage, FieldHelp = _a.FieldHelp, RequiredIndicator = _a.RequiredIndicator, InfoFieldButton = _a.InfoFieldButton;
|
|
18
18
|
var name = props.name, uiSchema = props.uiSchema, children = props.children;
|
|
19
19
|
var title = getTitle(props);
|
|
20
20
|
var description = getDescription(props);
|
|
21
|
-
var _b = useExtractUiSchema(uiSchema), help = _b.help,
|
|
21
|
+
var _b = useExtractUiSchema(uiSchema), help = _b.help, info = _b.info,
|
|
22
22
|
//TODO: This is not right
|
|
23
23
|
_c = _b.props,
|
|
24
24
|
//TODO: This is not right
|
|
25
25
|
_d = _c === void 0 ? {} : _c, wrappertProps = _d.wrapper, titleProps = _d.title, descriptionProps = _d.description, helpProps = _d.help, errorProps = _d.error;
|
|
26
|
-
return (_jsxs(FieldWrapper, __assign({}, wrappertProps, { children: [title && (
|
|
26
|
+
return (_jsxs(FieldWrapper, __assign({}, wrappertProps, { children: [title && (_jsxs(FieldTitle, __assign({}, titleProps, { htmlFor: name }, { children: [title, props.required && _jsx(RequiredIndicator, { children: "*" })] }))), info && _jsx(InfoFieldButton, __assign({}, info)), description && (_jsx(FieldDescription, __assign({}, descriptionProps, { children: description }))), children, help && _jsx(FieldHelp, __assign({}, helpProps, { children: help })), _jsx(ErrorMessage, __assign({}, errorProps, { name: name }))] })));
|
|
27
27
|
}
|
|
@@ -14,14 +14,14 @@ import { useContext } from "react";
|
|
|
14
14
|
import { FormRegistry } from "../Form";
|
|
15
15
|
import { getDescription, getTitle, useExtractUiSchema } from "../utils";
|
|
16
16
|
export function ObjectFieldTemplate(props) {
|
|
17
|
-
var _a = useContext(FormRegistry).components, FieldDescription = _a.FieldDescription, ObjectFieldTitle = _a.ObjectFieldTitle, ObjectFieldWrapper = _a.ObjectFieldWrapper, FieldHelp = _a.FieldHelp;
|
|
17
|
+
var _a = useContext(FormRegistry).components, FieldDescription = _a.FieldDescription, ObjectFieldTitle = _a.ObjectFieldTitle, ObjectFieldWrapper = _a.ObjectFieldWrapper, FieldHelp = _a.FieldHelp, InfoFieldButton = _a.InfoFieldButton;
|
|
18
18
|
var children = props.children, uiSchema = props.uiSchema;
|
|
19
19
|
var title = getTitle(props);
|
|
20
20
|
var description = getDescription(props);
|
|
21
|
-
var _b = useExtractUiSchema(uiSchema), help = _b.help,
|
|
21
|
+
var _b = useExtractUiSchema(uiSchema), help = _b.help, info = _b.info,
|
|
22
22
|
//TODO: This is not right
|
|
23
23
|
_c = _b.props,
|
|
24
24
|
//TODO: This is not right
|
|
25
25
|
_d = _c === void 0 ? {} : _c, wrapperProps = _d.wrapper, titleProps = _d.title, descriptionProps = _d.description, helpProps = _d.help;
|
|
26
|
-
return (_jsxs(ObjectFieldWrapper, __assign({}, wrapperProps, { children: [title && _jsx(ObjectFieldTitle, __assign({}, titleProps, { children: title })), description && _jsx(FieldDescription, __assign({}, descriptionProps, { children: description })), children, help && _jsx(FieldHelp, __assign({}, helpProps, { children: help }))] })));
|
|
26
|
+
return (_jsxs(ObjectFieldWrapper, __assign({}, wrapperProps, { children: [title && _jsx(ObjectFieldTitle, __assign({}, titleProps, { children: title })), info && _jsx(InfoFieldButton, __assign({}, info)), description && (_jsx(FieldDescription, __assign({}, descriptionProps, { children: description }))), children, help && _jsx(FieldHelp, __assign({}, helpProps, { children: help }))] })));
|
|
27
27
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -36,6 +36,7 @@ export type UiSchema = {
|
|
|
36
36
|
[key: string]: any;
|
|
37
37
|
};
|
|
38
38
|
"ui:help"?: React.ReactNode | React.ReactNode[];
|
|
39
|
+
"ui:info"?: InfoFieldButtonProps;
|
|
39
40
|
[name: string]: any;
|
|
40
41
|
};
|
|
41
42
|
export type FormRegistryContextValue = {
|
|
@@ -97,19 +98,29 @@ export type ComponentsType = {
|
|
|
97
98
|
ObjectFieldItem: React.FunctionComponent<any>;
|
|
98
99
|
ObjectFieldItemButtons: React.FunctionComponent<any>;
|
|
99
100
|
ObjectFieldList: React.FunctionComponent<any>;
|
|
100
|
-
ObjectFieldButton: React.FunctionComponent<
|
|
101
|
+
ObjectFieldButton: React.FunctionComponent<any>;
|
|
102
|
+
ObjectFieldAddButton: React.FunctionComponent<any>;
|
|
103
|
+
ObjectFieldRemoveButton: React.FunctionComponent<any>;
|
|
104
|
+
ObjectFieldUpButton: React.FunctionComponent<any>;
|
|
105
|
+
ObjectFieldDownButton: React.FunctionComponent<any>;
|
|
101
106
|
ArrayFieldWrapper: React.FunctionComponent<any>;
|
|
102
107
|
ArrayFieldTitle: React.FunctionComponent<any>;
|
|
103
108
|
ArrayFieldItem: React.FunctionComponent<any>;
|
|
104
109
|
ArrayFieldItemButtons: React.FunctionComponent<any>;
|
|
105
110
|
ArrayFieldList: React.FunctionComponent<any>;
|
|
106
|
-
ArrayFieldButton: React.FunctionComponent<
|
|
111
|
+
ArrayFieldButton: React.FunctionComponent<any>;
|
|
112
|
+
ArrayFieldAddButton: React.FunctionComponent<any>;
|
|
113
|
+
ArrayFieldRemoveButton: React.FunctionComponent<any>;
|
|
114
|
+
ArrayFieldUpButton: React.FunctionComponent<any>;
|
|
115
|
+
ArrayFieldDownButton: React.FunctionComponent<any>;
|
|
107
116
|
FieldWrapper: React.FunctionComponent<any>;
|
|
108
117
|
FieldTitle: React.FunctionComponent<any>;
|
|
109
118
|
FieldDescription: React.FunctionComponent<any>;
|
|
110
119
|
FieldHelp: React.FunctionComponent<any>;
|
|
120
|
+
InfoFieldButton: React.FunctionComponent<any>;
|
|
111
121
|
ErrorMessage: React.FunctionComponent<any>;
|
|
112
122
|
FieldInput: React.FunctionComponent<any>;
|
|
123
|
+
RequiredIndicator: React.FunctionComponent<any>;
|
|
113
124
|
};
|
|
114
125
|
export declare enum ObjectFieldButtonPurpose {
|
|
115
126
|
ADD = 0,
|
|
@@ -120,6 +131,7 @@ export declare enum ObjectFieldButtonPurpose {
|
|
|
120
131
|
export type ObjectFieldButtonProps = {
|
|
121
132
|
purpose: ObjectFieldButtonPurpose;
|
|
122
133
|
onClick: () => void;
|
|
134
|
+
uiSchema: UiSchema;
|
|
123
135
|
};
|
|
124
136
|
export declare enum ArrayFieldButtonPurpose {
|
|
125
137
|
ADD = 0,
|
|
@@ -130,6 +142,14 @@ export declare enum ArrayFieldButtonPurpose {
|
|
|
130
142
|
export type ArrayFieldButtonProps = {
|
|
131
143
|
purpose: ArrayFieldButtonPurpose;
|
|
132
144
|
onClick: () => void;
|
|
145
|
+
uiSchema: UiSchema;
|
|
146
|
+
};
|
|
147
|
+
export type InfoFieldButtonProps = {
|
|
148
|
+
label?: React.ReactNode;
|
|
149
|
+
content: React.ReactNode;
|
|
150
|
+
position?: 'top' | 'right' | 'bottom' | 'left';
|
|
151
|
+
className?: string;
|
|
152
|
+
props: any;
|
|
133
153
|
};
|
|
134
154
|
/*** ***/
|
|
135
155
|
export type AjvError = {
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { FieldProps, Schema, UiSchema } from "./types";
|
|
2
|
+
import { JSONSchema7 } from "json-schema";
|
|
2
3
|
export declare function getTitle({ title, uiSchema, schema, name, }: {
|
|
3
4
|
title?: string;
|
|
4
5
|
uiSchema?: UiSchema;
|
|
@@ -10,12 +11,14 @@ export declare function getDescription({ description, uiSchema, schema, }: {
|
|
|
10
11
|
uiSchema?: UiSchema;
|
|
11
12
|
schema?: Schema;
|
|
12
13
|
}): any;
|
|
14
|
+
export declare function getDefaultValueForType(type: JSONSchema7["type"]): {} | null;
|
|
13
15
|
export declare function useSetDefault(props: FieldProps): void;
|
|
14
16
|
export declare function useExtractUiSchema(props?: UiSchema | undefined): {
|
|
15
17
|
[name: string]: any;
|
|
16
18
|
field?: UiSchema["ui:field"];
|
|
17
19
|
props?: UiSchema["ui:props"];
|
|
18
20
|
help?: UiSchema["ui:help"];
|
|
21
|
+
info?: UiSchema["ui:info"];
|
|
19
22
|
};
|
|
20
23
|
export declare const guessType: (value: any) => "string" | "number" | "boolean" | "object" | "array" | "null";
|
|
21
24
|
export declare function getSchemaType(schema: Schema): import("json-schema").JSONSchema7TypeName | import("json-schema").JSONSchema7TypeName[] | undefined;
|
package/dist/utils.js
CHANGED
|
@@ -39,11 +39,25 @@ export function getDescription(_a) {
|
|
|
39
39
|
(uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema["ui:description"]) ||
|
|
40
40
|
(schema === null || schema === void 0 ? void 0 : schema.description));
|
|
41
41
|
}
|
|
42
|
+
export function getDefaultValueForType(type) {
|
|
43
|
+
if (type && !Array.isArray(type)) {
|
|
44
|
+
if (type === "array")
|
|
45
|
+
return [];
|
|
46
|
+
if (type === "object")
|
|
47
|
+
return {};
|
|
48
|
+
}
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
42
51
|
export function useSetDefault(props) {
|
|
43
52
|
var _a = useField(props.name), value = _a[0].value, _ = _a[1], setValue = _a[2].setValue;
|
|
44
53
|
useEffect(function () {
|
|
45
|
-
if (!value
|
|
46
|
-
|
|
54
|
+
if (!value) {
|
|
55
|
+
if (props.schema.default) {
|
|
56
|
+
setValue(props.schema.default);
|
|
57
|
+
}
|
|
58
|
+
else if (props.forceDefaultValue) {
|
|
59
|
+
setValue(getDefaultValueForType(props.schema.type));
|
|
60
|
+
}
|
|
47
61
|
}
|
|
48
62
|
}, []);
|
|
49
63
|
}
|