@pareto-engineering/design-system 4.2.0 → 4.2.1-alpha.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/dist/cjs/f/fields/EditorInput/EditorInput.js +4 -6
- package/dist/cjs/g/FormBuilder/FormBuilder.js +38 -5
- package/dist/cjs/g/FormBuilder/common/Builder/Builder.js +62 -25
- package/dist/cjs/g/FormBuilder/common/Builder/common/ActionsContainer/ActionsContainer.js +80 -0
- package/dist/cjs/g/FormBuilder/common/Builder/common/ActionsContainer/index.js +13 -0
- package/dist/cjs/g/FormBuilder/common/Builder/common/ActionsContainer/styles.scss +59 -0
- package/dist/cjs/g/FormBuilder/common/Builder/common/InputBuilder/InputBuilder.js +19 -45
- package/dist/cjs/g/FormBuilder/common/Builder/common/InputBuilder/styles.scss +0 -49
- package/dist/cjs/g/FormBuilder/common/Builder/common/Section/Section.js +14 -3
- package/dist/cjs/g/FormBuilder/common/Builder/common/Section/styles.scss +61 -0
- package/dist/cjs/g/FormBuilder/common/Builder/common/index.js +8 -1
- package/dist/cjs/g/FormBuilder/common/Builder/styles.scss +5 -48
- package/dist/cjs/g/FormBuilder/common/Renderer/Renderer.js +76 -33
- package/dist/cjs/g/FormBuilder/common/Renderer/common/Section/Section.js +8 -3
- package/dist/cjs/g/FormBuilder/common/Renderer/styles.scss +12 -1
- package/dist/es/f/fields/EditorInput/EditorInput.js +5 -7
- package/dist/es/g/FormBuilder/FormBuilder.js +38 -5
- package/dist/es/g/FormBuilder/common/Builder/Builder.js +56 -20
- package/dist/es/g/FormBuilder/common/Builder/common/ActionsContainer/ActionsContainer.js +70 -0
- package/dist/es/g/FormBuilder/common/Builder/common/ActionsContainer/index.js +2 -0
- package/dist/es/g/FormBuilder/common/Builder/common/ActionsContainer/styles.scss +59 -0
- package/dist/es/g/FormBuilder/common/Builder/common/InputBuilder/InputBuilder.js +21 -47
- package/dist/es/g/FormBuilder/common/Builder/common/InputBuilder/styles.scss +0 -49
- package/dist/es/g/FormBuilder/common/Builder/common/Section/Section.js +14 -3
- package/dist/es/g/FormBuilder/common/Builder/common/Section/styles.scss +61 -0
- package/dist/es/g/FormBuilder/common/Builder/common/index.js +2 -1
- package/dist/es/g/FormBuilder/common/Builder/styles.scss +5 -48
- package/dist/es/g/FormBuilder/common/Renderer/Renderer.js +76 -34
- package/dist/es/g/FormBuilder/common/Renderer/common/Section/Section.js +8 -3
- package/dist/es/g/FormBuilder/common/Renderer/styles.scss +12 -1
- package/package.json +3 -3
- package/src/stories/g/FormBuilder.stories.jsx +116 -21
- package/src/ui/f/fields/EditorInput/EditorInput.jsx +6 -8
- package/src/ui/g/FormBuilder/FormBuilder.jsx +50 -3
- package/src/ui/g/FormBuilder/common/Builder/Builder.jsx +56 -18
- package/src/ui/g/FormBuilder/common/Builder/common/ActionsContainer/ActionsContainer.jsx +97 -0
- package/src/ui/g/FormBuilder/common/Builder/common/ActionsContainer/index.js +2 -0
- package/src/ui/g/FormBuilder/common/Builder/common/ActionsContainer/styles.scss +59 -0
- package/src/ui/g/FormBuilder/common/Builder/common/InputBuilder/InputBuilder.jsx +40 -60
- package/src/ui/g/FormBuilder/common/Builder/common/InputBuilder/styles.scss +0 -49
- package/src/ui/g/FormBuilder/common/Builder/common/Section/Section.jsx +26 -4
- package/src/ui/g/FormBuilder/common/Builder/common/Section/styles.scss +61 -0
- package/src/ui/g/FormBuilder/common/Builder/common/index.js +1 -0
- package/src/ui/g/FormBuilder/common/Builder/styles.scss +5 -48
- package/src/ui/g/FormBuilder/common/Renderer/Renderer.jsx +84 -33
- package/src/ui/g/FormBuilder/common/Renderer/common/Section/Section.jsx +3 -2
- package/src/ui/g/FormBuilder/common/Renderer/styles.scss +12 -1
- package/tests/__snapshots__/Storyshots.test.js.snap +395 -133
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
Object.defineProperty(exports, "ActionsContainer", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _ActionsContainer.ActionsContainer;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
6
12
|
Object.defineProperty(exports, "InputBuilder", {
|
|
7
13
|
enumerable: true,
|
|
8
14
|
get: function () {
|
|
@@ -16,4 +22,5 @@ Object.defineProperty(exports, "Section", {
|
|
|
16
22
|
}
|
|
17
23
|
});
|
|
18
24
|
var _Section = require("./Section");
|
|
19
|
-
var _InputBuilder = require("./InputBuilder");
|
|
25
|
+
var _InputBuilder = require("./InputBuilder");
|
|
26
|
+
var _ActionsContainer = require("./ActionsContainer");
|
|
@@ -49,56 +49,13 @@ $default-margin: 1rem;
|
|
|
49
49
|
flex: .4;
|
|
50
50
|
gap: var(--gap);
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
/* stylelint-disable-next-line selector-max-compound-selectors -- required */
|
|
53
|
+
> span {
|
|
54
|
+
white-space: nowrap;
|
|
54
55
|
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
> .#{bem.$base}.section {
|
|
58
|
-
border-bottom: var(--theme-default-border-style) var(--on-background-inputs);
|
|
59
|
-
|
|
60
|
-
> .#{bem.$base}.editor-input {
|
|
61
|
-
margin-top: $default-margin;
|
|
62
|
-
}
|
|
63
56
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
> .add-question-cta {
|
|
67
|
-
align-items: center;
|
|
68
|
-
background-color: transparent;
|
|
69
|
-
border: 0;
|
|
70
|
-
color: var(--hard-interactive);
|
|
71
|
-
cursor: pointer;
|
|
72
|
-
display: flex;
|
|
73
|
-
gap: var(--gap);
|
|
74
|
-
margin-block: calc($default-margin * 1.5);
|
|
75
|
-
margin-left: auto;
|
|
76
|
-
padding: 0;
|
|
77
|
-
transition: all .2s;
|
|
78
|
-
|
|
79
|
-
/* stylelint-disable-next-line max-nesting-depth -- required */
|
|
80
|
-
&:hover {
|
|
81
|
-
color: var(--interactive);
|
|
82
|
-
|
|
83
|
-
/* stylelint-disable max-nesting-depth -- required */
|
|
84
|
-
> .icon-container {
|
|
85
|
-
background-color: var(--interactive);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
> .icon-container {
|
|
90
|
-
align-items: center;
|
|
91
|
-
background-color: var(--hard-interactive);
|
|
92
|
-
border-radius: 50%;
|
|
93
|
-
display: flex;
|
|
94
|
-
height: 1.6rem;
|
|
95
|
-
justify-content: center;
|
|
96
|
-
width: 1.6rem;
|
|
97
|
-
|
|
98
|
-
> .icon {
|
|
99
|
-
color: var(--on-interactive);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
57
|
+
> .#{bem.$base}.select-input {
|
|
58
|
+
flex: auto;
|
|
102
59
|
}
|
|
103
60
|
}
|
|
104
61
|
}
|
|
@@ -18,6 +18,27 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
|
|
|
18
18
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } /* @pareto-engineering/generator-front 1.1.1-alpha.2 */ // Local Definitions
|
|
19
19
|
const baseClassName = _exports.default.base;
|
|
20
20
|
const componentClassName = 'renderer';
|
|
21
|
+
const reconstructFormDataWithValues = (formData, values) => {
|
|
22
|
+
const newData = {
|
|
23
|
+
...formData
|
|
24
|
+
};
|
|
25
|
+
Object.keys(values).forEach(key => {
|
|
26
|
+
const [sectionIdx, inputIdx] = key.match(/\d+/g).map(Number);
|
|
27
|
+
newData.sections[sectionIdx].inputs[inputIdx].value = values[key];
|
|
28
|
+
});
|
|
29
|
+
return newData;
|
|
30
|
+
};
|
|
31
|
+
const validate = values => {
|
|
32
|
+
const errors = {};
|
|
33
|
+
const hasAtLeastOneValue = Object.keys(values).some(valueKey => {
|
|
34
|
+
const inputValue = values[valueKey];
|
|
35
|
+
return inputValue && inputValue !== '';
|
|
36
|
+
});
|
|
37
|
+
if (!hasAtLeastOneValue) {
|
|
38
|
+
errors.message = 'At least one input must have a value';
|
|
39
|
+
}
|
|
40
|
+
return errors;
|
|
41
|
+
};
|
|
21
42
|
|
|
22
43
|
/**
|
|
23
44
|
* This is the component description.
|
|
@@ -28,28 +49,36 @@ const Renderer = _ref => {
|
|
|
28
49
|
className: userClassName,
|
|
29
50
|
style,
|
|
30
51
|
formData,
|
|
31
|
-
|
|
52
|
+
readOnly,
|
|
53
|
+
onSave,
|
|
54
|
+
onError,
|
|
55
|
+
shouldSubmit
|
|
32
56
|
// ...otherProps
|
|
33
57
|
} = _ref;
|
|
34
58
|
const [currentSectionIndex, setCurrentSectionIndex] = (0, _react.useState)(0);
|
|
35
59
|
const [sectionHistory, setSectionHistory] = (0, _react.useState)([]);
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
60
|
+
const [updatedFormData, setUpdatedFormData] = (0, _react.useState)(formData);
|
|
61
|
+
(0, _react.useEffect)(() => {
|
|
62
|
+
setUpdatedFormData(formData);
|
|
63
|
+
}, [formData]);
|
|
64
|
+
const initialValues = formData.sections.reduce((acc, section, sectionIndex) => {
|
|
65
|
+
section.inputs.forEach((input, inputIndex) => {
|
|
66
|
+
const inputName = `section_${sectionIndex}_input_${inputIndex}`;
|
|
67
|
+
acc[inputName] = input.value || '';
|
|
39
68
|
});
|
|
40
69
|
return acc;
|
|
41
70
|
}, {});
|
|
42
71
|
const handleSubmit = values => {
|
|
43
|
-
const currentSection =
|
|
72
|
+
const currentSection = updatedFormData.sections[currentSectionIndex];
|
|
44
73
|
// by default, 'next' section is the immediate section after the current one
|
|
45
74
|
let nextSectionIndex = currentSectionIndex + 1;
|
|
46
75
|
|
|
47
76
|
// Any other value is either submit or an index to a section
|
|
48
77
|
if (currentSection.navigation.nextSection !== 'next') {
|
|
49
|
-
nextSectionIndex = currentSection.navigation.nextSection === 'submit' ?
|
|
78
|
+
nextSectionIndex = currentSection.navigation.nextSection === 'submit' ? updatedFormData.sections.length // submit
|
|
50
79
|
: parseInt(currentSection.navigation.nextSection, 10); // go to specific section
|
|
51
80
|
}
|
|
52
|
-
if (nextSectionIndex >=
|
|
81
|
+
if (nextSectionIndex >= updatedFormData.sections.length) {
|
|
53
82
|
// submit
|
|
54
83
|
onSave(values);
|
|
55
84
|
} else {
|
|
@@ -68,28 +97,50 @@ const Renderer = _ref => {
|
|
|
68
97
|
setSectionHistory([...sectionHistory]);
|
|
69
98
|
}
|
|
70
99
|
};
|
|
100
|
+
const isSubmit = currentSectionIndex === updatedFormData.sections.length - 1 || updatedFormData.sections[currentSectionIndex].navigation.nextSection === 'submit';
|
|
71
101
|
return /*#__PURE__*/React.createElement("div", {
|
|
72
102
|
id: id,
|
|
73
103
|
className: [baseClassName, componentClassName, userClassName].filter(e => e).join(' '),
|
|
74
104
|
style: style
|
|
75
105
|
}, /*#__PURE__*/React.createElement(_formik.Formik, {
|
|
76
106
|
initialValues: initialValues,
|
|
77
|
-
onSubmit: handleSubmit
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
107
|
+
onSubmit: handleSubmit,
|
|
108
|
+
validate: validate
|
|
109
|
+
}, _ref2 => {
|
|
110
|
+
let {
|
|
111
|
+
values,
|
|
112
|
+
errors
|
|
113
|
+
} = _ref2;
|
|
114
|
+
(0, _react.useEffect)(() => {
|
|
115
|
+
const formDataWithValues = reconstructFormDataWithValues(updatedFormData, values);
|
|
116
|
+
setUpdatedFormData(formDataWithValues);
|
|
117
|
+
onSave?.(formDataWithValues);
|
|
118
|
+
}, [values]);
|
|
119
|
+
(0, _react.useEffect)(() => {
|
|
120
|
+
onError?.({
|
|
121
|
+
errors,
|
|
122
|
+
values
|
|
123
|
+
});
|
|
124
|
+
}, [errors, values]);
|
|
125
|
+
return /*#__PURE__*/React.createElement(_formik.Form, null, updatedFormData.sections.map((section, sectionIndex) => sectionIndex === currentSectionIndex && /*#__PURE__*/React.createElement(_common.Section, _extends({
|
|
126
|
+
key: `${section.title}`
|
|
127
|
+
}, section, {
|
|
128
|
+
readOnly: readOnly
|
|
129
|
+
}))), /*#__PURE__*/React.createElement("div", {
|
|
130
|
+
className: "navigator-container"
|
|
131
|
+
}, /*#__PURE__*/React.createElement(_b.Button, {
|
|
132
|
+
color: "interactive",
|
|
133
|
+
isGradient: true,
|
|
134
|
+
isCompact: true,
|
|
135
|
+
isGhost: true,
|
|
136
|
+
onClick: handlePrevious,
|
|
137
|
+
disabled: sectionHistory.length === 0
|
|
138
|
+
}, "Previous"), (!isSubmit || shouldSubmit) && /*#__PURE__*/React.createElement(_b.Button, {
|
|
139
|
+
color: "interactive",
|
|
140
|
+
isGradient: true,
|
|
141
|
+
type: "submit"
|
|
142
|
+
}, isSubmit ? 'Submit' : 'Next')));
|
|
143
|
+
}));
|
|
93
144
|
};
|
|
94
145
|
Renderer.propTypes = {
|
|
95
146
|
/**
|
|
@@ -103,17 +154,9 @@ Renderer.propTypes = {
|
|
|
103
154
|
/**
|
|
104
155
|
* The React-written, css properties for this element.
|
|
105
156
|
*/
|
|
106
|
-
style: _propTypes.default.objectOf(_propTypes.default.string)
|
|
107
|
-
/**
|
|
108
|
-
* The children JSX
|
|
109
|
-
*/
|
|
110
|
-
formData: _propTypes.default.shape({
|
|
111
|
-
formTitle: _propTypes.default.string.isRequired,
|
|
112
|
-
formDescription: _propTypes.default.string.isRequired,
|
|
113
|
-
sections: _propTypes.default.arrayOf(_propTypes.default.objectOf(_propTypes.default.any))
|
|
114
|
-
})
|
|
157
|
+
style: _propTypes.default.objectOf(_propTypes.default.string)
|
|
115
158
|
};
|
|
116
159
|
Renderer.defaultProps = {
|
|
117
|
-
// someProp:false
|
|
160
|
+
// someProp: false,
|
|
118
161
|
};
|
|
119
162
|
var _default = exports.default = Renderer;
|
|
@@ -26,19 +26,24 @@ const Section = _ref => {
|
|
|
26
26
|
style,
|
|
27
27
|
title,
|
|
28
28
|
description,
|
|
29
|
-
inputs
|
|
29
|
+
inputs,
|
|
30
|
+
readOnly
|
|
30
31
|
// ...otherProps
|
|
31
32
|
} = _ref;
|
|
32
33
|
return /*#__PURE__*/React.createElement("div", {
|
|
33
34
|
id: id,
|
|
34
35
|
className: [baseClassName, componentClassName, userClassName].filter(e => e).join(' '),
|
|
35
36
|
style: style
|
|
36
|
-
}, /*#__PURE__*/React.createElement("
|
|
37
|
+
}, /*#__PURE__*/React.createElement("p", {
|
|
38
|
+
className: "h3"
|
|
39
|
+
}, title), /*#__PURE__*/React.createElement(_.ExpandableLexicalPreview, {
|
|
37
40
|
nodes: description,
|
|
38
41
|
name: "instructions"
|
|
39
42
|
}), inputs.map(input => /*#__PURE__*/React.createElement(_f.FormInput, _extends({
|
|
40
43
|
key: input.name
|
|
41
|
-
}, input
|
|
44
|
+
}, input, {
|
|
45
|
+
disabled: readOnly
|
|
46
|
+
}))));
|
|
42
47
|
};
|
|
43
48
|
Section.propTypes = {
|
|
44
49
|
/**
|
|
@@ -6,10 +6,21 @@ $default-margin: 1rem;
|
|
|
6
6
|
|
|
7
7
|
.#{bem.$base}.renderer {
|
|
8
8
|
> form {
|
|
9
|
+
> .#{bem.$base}.section {
|
|
10
|
+
margin-bottom: calc($default-margin * 2);
|
|
11
|
+
|
|
12
|
+
> p {
|
|
13
|
+
margin: 0;
|
|
14
|
+
}
|
|
15
|
+
> .#{bem.$base}.expandable-lexical-preview {
|
|
16
|
+
margin-bottom: $default-margin;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
9
20
|
> .navigator-container {
|
|
10
21
|
display: flex;
|
|
11
22
|
gap: var(--gap);
|
|
12
|
-
|
|
23
|
+
justify-content: space-between;
|
|
13
24
|
}
|
|
14
25
|
}
|
|
15
26
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/* eslint-disable import/no-extraneous-dependencies -- required here */
|
|
3
3
|
import * as React from 'react';
|
|
4
4
|
import { memo, useEffect } from 'react';
|
|
5
|
-
import { useFormikContext } from 'formik';
|
|
5
|
+
import { useField, useFormikContext } from 'formik';
|
|
6
6
|
import { LexicalComposer } from '@lexical/react/LexicalComposer';
|
|
7
7
|
import { RichTextPlugin } from '@lexical/react/LexicalRichTextPlugin';
|
|
8
8
|
import { ContentEditable } from '@lexical/react/LexicalContentEditable';
|
|
@@ -59,18 +59,16 @@ const EditorInput = ({
|
|
|
59
59
|
showDebugger,
|
|
60
60
|
stopPropagationKeys,
|
|
61
61
|
setEditorState
|
|
62
|
-
// handleOnChange,
|
|
63
62
|
// ...otherProps
|
|
64
63
|
}) => {
|
|
64
|
+
const [field,,] = useField(name);
|
|
65
65
|
const {
|
|
66
|
-
values,
|
|
67
66
|
setFieldValue
|
|
68
67
|
} = useFormikContext();
|
|
69
68
|
const setInitialValue = () => {
|
|
70
|
-
const value = values[name];
|
|
71
69
|
try {
|
|
72
|
-
JSON.parse(value);
|
|
73
|
-
return value;
|
|
70
|
+
JSON.parse(field.value);
|
|
71
|
+
return field.value;
|
|
74
72
|
} catch {
|
|
75
73
|
const defaultValue = {
|
|
76
74
|
root: {
|
|
@@ -97,7 +95,7 @@ const EditorInput = ({
|
|
|
97
95
|
version: 1
|
|
98
96
|
}
|
|
99
97
|
};
|
|
100
|
-
defaultValue.root.children[0].children[0].text = value;
|
|
98
|
+
defaultValue.root.children[0].children[0].text = field.value;
|
|
101
99
|
return JSON.stringify(defaultValue);
|
|
102
100
|
}
|
|
103
101
|
};
|
|
@@ -19,9 +19,15 @@ const FormBuilder = ({
|
|
|
19
19
|
style,
|
|
20
20
|
mode,
|
|
21
21
|
formData,
|
|
22
|
+
readOnly,
|
|
23
|
+
shouldSubmit,
|
|
22
24
|
formBuilderId,
|
|
23
25
|
onBuilderFormSave,
|
|
24
|
-
|
|
26
|
+
onBuilderError,
|
|
27
|
+
onRendererError,
|
|
28
|
+
onRendererFormSave,
|
|
29
|
+
onBuilderValidate,
|
|
30
|
+
initialBuilderValues
|
|
25
31
|
// ...otherProps
|
|
26
32
|
}) => /*#__PURE__*/React.createElement("div", {
|
|
27
33
|
id: id,
|
|
@@ -29,11 +35,17 @@ const FormBuilder = ({
|
|
|
29
35
|
style: style
|
|
30
36
|
// {...otherProps}
|
|
31
37
|
}, mode === 'build' && /*#__PURE__*/React.createElement(Builder, {
|
|
38
|
+
initialValues: initialBuilderValues,
|
|
32
39
|
formBuilderId: formBuilderId,
|
|
33
|
-
onSave: onBuilderFormSave
|
|
40
|
+
onSave: onBuilderFormSave,
|
|
41
|
+
onError: onBuilderError,
|
|
42
|
+
validate: onBuilderValidate
|
|
34
43
|
}), mode === 'render' && /*#__PURE__*/React.createElement(Renderer, {
|
|
35
44
|
formData: formData,
|
|
36
|
-
onSave: onRendererFormSave
|
|
45
|
+
onSave: onRendererFormSave,
|
|
46
|
+
readOnly: readOnly,
|
|
47
|
+
shouldSubmit: shouldSubmit,
|
|
48
|
+
onError: onRendererError
|
|
37
49
|
}));
|
|
38
50
|
FormBuilder.propTypes = {
|
|
39
51
|
/**
|
|
@@ -55,10 +67,31 @@ FormBuilder.propTypes = {
|
|
|
55
67
|
/**
|
|
56
68
|
* This is the ID of the form element in the <Builder /> component
|
|
57
69
|
*/
|
|
58
|
-
formBuilderId: PropTypes.string.isRequired
|
|
70
|
+
formBuilderId: PropTypes.string.isRequired,
|
|
71
|
+
/**
|
|
72
|
+
* The form data to be used to construct the form builder in renderer mode
|
|
73
|
+
*/
|
|
74
|
+
formData: PropTypes.shape({
|
|
75
|
+
sections: PropTypes.arrayOf(PropTypes.objectOf(PropTypes.any))
|
|
76
|
+
}),
|
|
77
|
+
/**
|
|
78
|
+
* The initial values to instatiate form builder in builder mode
|
|
79
|
+
*/
|
|
80
|
+
initialBuilderValues: PropTypes.shape({
|
|
81
|
+
sections: PropTypes.arrayOf(PropTypes.objectOf(PropTypes.any))
|
|
82
|
+
}),
|
|
83
|
+
/**
|
|
84
|
+
* Whether the whole Form in renderer mode should be readOnly
|
|
85
|
+
*/
|
|
86
|
+
readOnly: PropTypes.bool,
|
|
87
|
+
/**
|
|
88
|
+
* Whether the form builder in renderer mode should submit the form values itself
|
|
89
|
+
*/
|
|
90
|
+
shouldSubmit: PropTypes.bool
|
|
59
91
|
};
|
|
60
92
|
FormBuilder.defaultProps = {
|
|
61
|
-
mode: 'build'
|
|
93
|
+
mode: 'build',
|
|
94
|
+
readOnly: false
|
|
62
95
|
};
|
|
63
96
|
FormBuilder.Builder = Builder;
|
|
64
97
|
FormBuilder.Renderer = Renderer;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/* @pareto-engineering/generator-front 1.1.1-alpha.2 */
|
|
2
2
|
import * as React from 'react';
|
|
3
|
+
import { useEffect } from 'react';
|
|
3
4
|
import { Formik, Form, FieldArray } from 'formik';
|
|
4
5
|
import PropTypes from 'prop-types';
|
|
5
6
|
import styleNames from '@pareto-engineering/bem/exports';
|
|
@@ -28,12 +29,41 @@ const Builder = ({
|
|
|
28
29
|
className: userClassName,
|
|
29
30
|
style,
|
|
30
31
|
onSave,
|
|
31
|
-
|
|
32
|
+
onError,
|
|
33
|
+
validate,
|
|
34
|
+
formBuilderId,
|
|
35
|
+
initialValues = {}
|
|
32
36
|
// ...otherProps
|
|
33
37
|
}) => {
|
|
34
38
|
const handleSubmit = values => {
|
|
35
39
|
const reOrderedValues = reorderInputs(values);
|
|
36
|
-
onSave(reOrderedValues);
|
|
40
|
+
onSave?.(reOrderedValues);
|
|
41
|
+
};
|
|
42
|
+
const initialFormState = initialValues?.sections ? initialValues : {
|
|
43
|
+
sections: [{
|
|
44
|
+
title: '',
|
|
45
|
+
description: '',
|
|
46
|
+
key: 'section-0',
|
|
47
|
+
inputs: [],
|
|
48
|
+
orderedInputDragIds: [],
|
|
49
|
+
navigation: {
|
|
50
|
+
nextSection: 'next'
|
|
51
|
+
}
|
|
52
|
+
}]
|
|
53
|
+
};
|
|
54
|
+
const handleDeleteSection = ({
|
|
55
|
+
index,
|
|
56
|
+
remove,
|
|
57
|
+
values
|
|
58
|
+
}) => {
|
|
59
|
+
remove(index);
|
|
60
|
+
values.sections.splice(index, 1);
|
|
61
|
+
values.sections.forEach((section, sectionIndex) => {
|
|
62
|
+
section.inputs.forEach((input, inputIndex) => {
|
|
63
|
+
// eslint-disable-next-line no-param-reassign
|
|
64
|
+
input.name = `section_${sectionIndex}_input_${inputIndex}`;
|
|
65
|
+
});
|
|
66
|
+
});
|
|
37
67
|
};
|
|
38
68
|
return /*#__PURE__*/React.createElement("div", {
|
|
39
69
|
id: id,
|
|
@@ -42,23 +72,22 @@ const Builder = ({
|
|
|
42
72
|
}, /*#__PURE__*/React.createElement("p", {
|
|
43
73
|
className: "h3"
|
|
44
74
|
}, "Form Builder"), /*#__PURE__*/React.createElement(Formik, {
|
|
45
|
-
initialValues:
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
description: '',
|
|
49
|
-
key: 'section-0',
|
|
50
|
-
inputs: [],
|
|
51
|
-
orderedInputDragIds: [],
|
|
52
|
-
navigation: {
|
|
53
|
-
nextSection: 'next'
|
|
54
|
-
}
|
|
55
|
-
}]
|
|
56
|
-
},
|
|
57
|
-
onSubmit: handleSubmit
|
|
75
|
+
initialValues: initialFormState,
|
|
76
|
+
onSubmit: handleSubmit,
|
|
77
|
+
validate: validate
|
|
58
78
|
}, ({
|
|
59
|
-
values
|
|
79
|
+
values,
|
|
80
|
+
errors,
|
|
81
|
+
setFieldValue
|
|
60
82
|
}) => {
|
|
61
|
-
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
const reOrderedValues = reorderInputs(values);
|
|
85
|
+
onSave?.(reOrderedValues);
|
|
86
|
+
}, [values]);
|
|
87
|
+
useEffect(() => {
|
|
88
|
+
onError?.(errors);
|
|
89
|
+
}, [errors, values]);
|
|
90
|
+
const availableSections = values?.sections?.map((section, idx) => ({
|
|
62
91
|
value: idx,
|
|
63
92
|
label: `Go to ${section.title || `Untitled Section ${idx + 1}`}`
|
|
64
93
|
}));
|
|
@@ -67,10 +96,17 @@ const Builder = ({
|
|
|
67
96
|
}, /*#__PURE__*/React.createElement(FieldArray, {
|
|
68
97
|
name: "sections"
|
|
69
98
|
}, ({
|
|
70
|
-
push
|
|
71
|
-
|
|
99
|
+
push,
|
|
100
|
+
remove
|
|
101
|
+
}) => /*#__PURE__*/React.createElement(React.Fragment, null, values?.sections?.map((section, index) => /*#__PURE__*/React.createElement(Section, {
|
|
72
102
|
key: section.key,
|
|
73
|
-
index: index
|
|
103
|
+
index: index,
|
|
104
|
+
handleDeleteSection: () => handleDeleteSection({
|
|
105
|
+
index,
|
|
106
|
+
remove,
|
|
107
|
+
values,
|
|
108
|
+
setFieldValue
|
|
109
|
+
})
|
|
74
110
|
})), /*#__PURE__*/React.createElement("div", {
|
|
75
111
|
className: "section-footer"
|
|
76
112
|
}, /*#__PURE__*/React.createElement("button", {
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/* @pareto-engineering/generator-front 1.1.1-alpha.2 */
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { useState, useRef } from 'react';
|
|
4
|
+
import PropTypes from 'prop-types';
|
|
5
|
+
import styleNames from '@pareto-engineering/bem/exports';
|
|
6
|
+
import "./styles.scss";
|
|
7
|
+
|
|
8
|
+
// Local Definitions
|
|
9
|
+
|
|
10
|
+
import { useOutsideClick } from "../../../../../../utils";
|
|
11
|
+
import { Popover } from "../../../../../../a";
|
|
12
|
+
const baseClassName = styleNames.base;
|
|
13
|
+
const componentClassName = 'actions-container';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* This is the component description.
|
|
17
|
+
*/
|
|
18
|
+
const ActionsContainer = ({
|
|
19
|
+
id,
|
|
20
|
+
className: userClassName,
|
|
21
|
+
style,
|
|
22
|
+
preferredPopoverOrder,
|
|
23
|
+
children
|
|
24
|
+
// ...otherProps
|
|
25
|
+
}) => {
|
|
26
|
+
const parentRef = useRef(null);
|
|
27
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
28
|
+
useOutsideClick(parentRef, () => setIsOpen(false));
|
|
29
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
30
|
+
id: id,
|
|
31
|
+
className: [baseClassName, componentClassName, userClassName].filter(e => e).join(' '),
|
|
32
|
+
style: style,
|
|
33
|
+
ref: parentRef
|
|
34
|
+
}, /*#__PURE__*/React.createElement("button", {
|
|
35
|
+
type: "button",
|
|
36
|
+
onClick: () => setIsOpen(!isOpen)
|
|
37
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
38
|
+
className: "icon x-ui-icons c-x"
|
|
39
|
+
}, "!")), /*#__PURE__*/React.createElement(Popover, {
|
|
40
|
+
isOpen: isOpen,
|
|
41
|
+
parentRef: parentRef,
|
|
42
|
+
preferredPrimaryOrder: preferredPopoverOrder
|
|
43
|
+
}, children));
|
|
44
|
+
};
|
|
45
|
+
ActionsContainer.propTypes = {
|
|
46
|
+
/**
|
|
47
|
+
* The HTML id for this element
|
|
48
|
+
*/
|
|
49
|
+
id: PropTypes.string,
|
|
50
|
+
/**
|
|
51
|
+
* The HTML class names for this element
|
|
52
|
+
*/
|
|
53
|
+
className: PropTypes.string,
|
|
54
|
+
/**
|
|
55
|
+
* The React-written, css properties for this element.
|
|
56
|
+
*/
|
|
57
|
+
style: PropTypes.objectOf(PropTypes.string),
|
|
58
|
+
/**
|
|
59
|
+
* The preferred order for the popover
|
|
60
|
+
*/
|
|
61
|
+
preferredPopoverOrder: PropTypes.arrayOf(PropTypes.string),
|
|
62
|
+
/**
|
|
63
|
+
* The children of the actions container
|
|
64
|
+
*/
|
|
65
|
+
children: PropTypes.node
|
|
66
|
+
};
|
|
67
|
+
ActionsContainer.defaultProps = {
|
|
68
|
+
preferredPopoverOrder: ['right', 'bottom', 'left', 'top']
|
|
69
|
+
};
|
|
70
|
+
export default ActionsContainer;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/* @pareto-engineering/generator-front 1.1.1-alpha.2 */
|
|
2
|
+
|
|
3
|
+
@use "@pareto-engineering/bem";
|
|
4
|
+
|
|
5
|
+
$default-padding: 1rem;
|
|
6
|
+
$default-margin: 1rem;
|
|
7
|
+
$default-list-width: var(--action-button-width, 18rem);
|
|
8
|
+
|
|
9
|
+
.#{bem.$base}.actions-container {
|
|
10
|
+
position: relative;
|
|
11
|
+
|
|
12
|
+
> button {
|
|
13
|
+
background-color: transparent;
|
|
14
|
+
border: 0;
|
|
15
|
+
cursor: pointer;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
> .#{bem.$base}.popover {
|
|
19
|
+
background-color: var(--background-cards);
|
|
20
|
+
border: var(--theme-default-border-style) var(--main2);
|
|
21
|
+
border-radius: calc(var(--theme-default-border-radius) / 2);
|
|
22
|
+
cursor: default;
|
|
23
|
+
padding: $default-padding;
|
|
24
|
+
width: $default-list-width;
|
|
25
|
+
|
|
26
|
+
> p {
|
|
27
|
+
margin: 0;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
> ul {
|
|
31
|
+
list-style: none;
|
|
32
|
+
margin: 0;
|
|
33
|
+
padding: 0;
|
|
34
|
+
white-space: nowrap;
|
|
35
|
+
|
|
36
|
+
> .option {
|
|
37
|
+
cursor: pointer;
|
|
38
|
+
padding-block: calc($default-padding / 4);
|
|
39
|
+
|
|
40
|
+
&:not(.with-check-mark) {
|
|
41
|
+
padding-inline: $default-padding;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/* stylelint-disable-next-line selector-max-compound-selectors -- required */
|
|
45
|
+
> button {
|
|
46
|
+
background: transparent;
|
|
47
|
+
border: 0;
|
|
48
|
+
color: var(--paragraph);
|
|
49
|
+
cursor: pointer;
|
|
50
|
+
font-size: calc(var(--s0) * .875rem);
|
|
51
|
+
text-align: left;
|
|
52
|
+
width: 100%;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
|