@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
|
@@ -70,18 +70,16 @@ const EditorInput = _ref2 => {
|
|
|
70
70
|
showDebugger,
|
|
71
71
|
stopPropagationKeys,
|
|
72
72
|
setEditorState
|
|
73
|
-
// handleOnChange,
|
|
74
73
|
// ...otherProps
|
|
75
74
|
} = _ref2;
|
|
75
|
+
const [field,,] = (0, _formik.useField)(name);
|
|
76
76
|
const {
|
|
77
|
-
values,
|
|
78
77
|
setFieldValue
|
|
79
78
|
} = (0, _formik.useFormikContext)();
|
|
80
79
|
const setInitialValue = () => {
|
|
81
|
-
const value = values[name];
|
|
82
80
|
try {
|
|
83
|
-
JSON.parse(value);
|
|
84
|
-
return value;
|
|
81
|
+
JSON.parse(field.value);
|
|
82
|
+
return field.value;
|
|
85
83
|
} catch {
|
|
86
84
|
const defaultValue = {
|
|
87
85
|
root: {
|
|
@@ -108,7 +106,7 @@ const EditorInput = _ref2 => {
|
|
|
108
106
|
version: 1
|
|
109
107
|
}
|
|
110
108
|
};
|
|
111
|
-
defaultValue.root.children[0].children[0].text = value;
|
|
109
|
+
defaultValue.root.children[0].children[0].text = field.value;
|
|
112
110
|
return JSON.stringify(defaultValue);
|
|
113
111
|
}
|
|
114
112
|
};
|
|
@@ -29,9 +29,15 @@ const FormBuilder = _ref => {
|
|
|
29
29
|
style,
|
|
30
30
|
mode,
|
|
31
31
|
formData,
|
|
32
|
+
readOnly,
|
|
33
|
+
shouldSubmit,
|
|
32
34
|
formBuilderId,
|
|
33
35
|
onBuilderFormSave,
|
|
34
|
-
|
|
36
|
+
onBuilderError,
|
|
37
|
+
onRendererError,
|
|
38
|
+
onRendererFormSave,
|
|
39
|
+
onBuilderValidate,
|
|
40
|
+
initialBuilderValues
|
|
35
41
|
// ...otherProps
|
|
36
42
|
} = _ref;
|
|
37
43
|
return /*#__PURE__*/React.createElement("div", {
|
|
@@ -40,11 +46,17 @@ const FormBuilder = _ref => {
|
|
|
40
46
|
style: style
|
|
41
47
|
// {...otherProps}
|
|
42
48
|
}, mode === 'build' && /*#__PURE__*/React.createElement(_common.Builder, {
|
|
49
|
+
initialValues: initialBuilderValues,
|
|
43
50
|
formBuilderId: formBuilderId,
|
|
44
|
-
onSave: onBuilderFormSave
|
|
51
|
+
onSave: onBuilderFormSave,
|
|
52
|
+
onError: onBuilderError,
|
|
53
|
+
validate: onBuilderValidate
|
|
45
54
|
}), mode === 'render' && /*#__PURE__*/React.createElement(_common.Renderer, {
|
|
46
55
|
formData: formData,
|
|
47
|
-
onSave: onRendererFormSave
|
|
56
|
+
onSave: onRendererFormSave,
|
|
57
|
+
readOnly: readOnly,
|
|
58
|
+
shouldSubmit: shouldSubmit,
|
|
59
|
+
onError: onRendererError
|
|
48
60
|
}));
|
|
49
61
|
};
|
|
50
62
|
FormBuilder.propTypes = {
|
|
@@ -67,10 +79,31 @@ FormBuilder.propTypes = {
|
|
|
67
79
|
/**
|
|
68
80
|
* This is the ID of the form element in the <Builder /> component
|
|
69
81
|
*/
|
|
70
|
-
formBuilderId: _propTypes.default.string.isRequired
|
|
82
|
+
formBuilderId: _propTypes.default.string.isRequired,
|
|
83
|
+
/**
|
|
84
|
+
* The form data to be used to construct the form builder in renderer mode
|
|
85
|
+
*/
|
|
86
|
+
formData: _propTypes.default.shape({
|
|
87
|
+
sections: _propTypes.default.arrayOf(_propTypes.default.objectOf(_propTypes.default.any))
|
|
88
|
+
}),
|
|
89
|
+
/**
|
|
90
|
+
* The initial values to instatiate form builder in builder mode
|
|
91
|
+
*/
|
|
92
|
+
initialBuilderValues: _propTypes.default.shape({
|
|
93
|
+
sections: _propTypes.default.arrayOf(_propTypes.default.objectOf(_propTypes.default.any))
|
|
94
|
+
}),
|
|
95
|
+
/**
|
|
96
|
+
* Whether the whole Form in renderer mode should be readOnly
|
|
97
|
+
*/
|
|
98
|
+
readOnly: _propTypes.default.bool,
|
|
99
|
+
/**
|
|
100
|
+
* Whether the form builder in renderer mode should submit the form values itself
|
|
101
|
+
*/
|
|
102
|
+
shouldSubmit: _propTypes.default.bool
|
|
71
103
|
};
|
|
72
104
|
FormBuilder.defaultProps = {
|
|
73
|
-
mode: 'build'
|
|
105
|
+
mode: 'build',
|
|
106
|
+
readOnly: false
|
|
74
107
|
};
|
|
75
108
|
FormBuilder.Builder = _common.Builder;
|
|
76
109
|
FormBuilder.Renderer = _common.Renderer;
|
|
@@ -4,7 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
var
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
+
var React = _react;
|
|
8
9
|
var _formik = require("formik");
|
|
9
10
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
10
11
|
var _exports = _interopRequireDefault(require("@pareto-engineering/bem/exports"));
|
|
@@ -38,12 +39,42 @@ const Builder = _ref => {
|
|
|
38
39
|
className: userClassName,
|
|
39
40
|
style,
|
|
40
41
|
onSave,
|
|
41
|
-
|
|
42
|
+
onError,
|
|
43
|
+
validate,
|
|
44
|
+
formBuilderId,
|
|
45
|
+
initialValues = {}
|
|
42
46
|
// ...otherProps
|
|
43
47
|
} = _ref;
|
|
44
48
|
const handleSubmit = values => {
|
|
45
49
|
const reOrderedValues = reorderInputs(values);
|
|
46
|
-
onSave(reOrderedValues);
|
|
50
|
+
onSave?.(reOrderedValues);
|
|
51
|
+
};
|
|
52
|
+
const initialFormState = initialValues?.sections ? initialValues : {
|
|
53
|
+
sections: [{
|
|
54
|
+
title: '',
|
|
55
|
+
description: '',
|
|
56
|
+
key: 'section-0',
|
|
57
|
+
inputs: [],
|
|
58
|
+
orderedInputDragIds: [],
|
|
59
|
+
navigation: {
|
|
60
|
+
nextSection: 'next'
|
|
61
|
+
}
|
|
62
|
+
}]
|
|
63
|
+
};
|
|
64
|
+
const handleDeleteSection = _ref2 => {
|
|
65
|
+
let {
|
|
66
|
+
index,
|
|
67
|
+
remove,
|
|
68
|
+
values
|
|
69
|
+
} = _ref2;
|
|
70
|
+
remove(index);
|
|
71
|
+
values.sections.splice(index, 1);
|
|
72
|
+
values.sections.forEach((section, sectionIndex) => {
|
|
73
|
+
section.inputs.forEach((input, inputIndex) => {
|
|
74
|
+
// eslint-disable-next-line no-param-reassign
|
|
75
|
+
input.name = `section_${sectionIndex}_input_${inputIndex}`;
|
|
76
|
+
});
|
|
77
|
+
});
|
|
47
78
|
};
|
|
48
79
|
return /*#__PURE__*/React.createElement("div", {
|
|
49
80
|
id: id,
|
|
@@ -52,24 +83,23 @@ const Builder = _ref => {
|
|
|
52
83
|
}, /*#__PURE__*/React.createElement("p", {
|
|
53
84
|
className: "h3"
|
|
54
85
|
}, "Form Builder"), /*#__PURE__*/React.createElement(_formik.Formik, {
|
|
55
|
-
initialValues:
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
key: 'section-0',
|
|
60
|
-
inputs: [],
|
|
61
|
-
orderedInputDragIds: [],
|
|
62
|
-
navigation: {
|
|
63
|
-
nextSection: 'next'
|
|
64
|
-
}
|
|
65
|
-
}]
|
|
66
|
-
},
|
|
67
|
-
onSubmit: handleSubmit
|
|
68
|
-
}, _ref2 => {
|
|
86
|
+
initialValues: initialFormState,
|
|
87
|
+
onSubmit: handleSubmit,
|
|
88
|
+
validate: validate
|
|
89
|
+
}, _ref3 => {
|
|
69
90
|
let {
|
|
70
|
-
values
|
|
71
|
-
|
|
72
|
-
|
|
91
|
+
values,
|
|
92
|
+
errors,
|
|
93
|
+
setFieldValue
|
|
94
|
+
} = _ref3;
|
|
95
|
+
(0, _react.useEffect)(() => {
|
|
96
|
+
const reOrderedValues = reorderInputs(values);
|
|
97
|
+
onSave?.(reOrderedValues);
|
|
98
|
+
}, [values]);
|
|
99
|
+
(0, _react.useEffect)(() => {
|
|
100
|
+
onError?.(errors);
|
|
101
|
+
}, [errors, values]);
|
|
102
|
+
const availableSections = values?.sections?.map((section, idx) => ({
|
|
73
103
|
value: idx,
|
|
74
104
|
label: `Go to ${section.title || `Untitled Section ${idx + 1}`}`
|
|
75
105
|
}));
|
|
@@ -77,13 +107,20 @@ const Builder = _ref => {
|
|
|
77
107
|
id: formBuilderId
|
|
78
108
|
}, /*#__PURE__*/React.createElement(_formik.FieldArray, {
|
|
79
109
|
name: "sections"
|
|
80
|
-
},
|
|
110
|
+
}, _ref4 => {
|
|
81
111
|
let {
|
|
82
|
-
push
|
|
83
|
-
|
|
84
|
-
|
|
112
|
+
push,
|
|
113
|
+
remove
|
|
114
|
+
} = _ref4;
|
|
115
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, values?.sections?.map((section, index) => /*#__PURE__*/React.createElement(_common.Section, {
|
|
85
116
|
key: section.key,
|
|
86
|
-
index: index
|
|
117
|
+
index: index,
|
|
118
|
+
handleDeleteSection: () => handleDeleteSection({
|
|
119
|
+
index,
|
|
120
|
+
remove,
|
|
121
|
+
values,
|
|
122
|
+
setFieldValue
|
|
123
|
+
})
|
|
87
124
|
})), /*#__PURE__*/React.createElement("div", {
|
|
88
125
|
className: "section-footer"
|
|
89
126
|
}, /*#__PURE__*/React.createElement("button", {
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
+
var React = _react;
|
|
9
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
10
|
+
var _exports = _interopRequireDefault(require("@pareto-engineering/bem/exports"));
|
|
11
|
+
require("./styles.scss");
|
|
12
|
+
var _utils = require("../../../../../../utils");
|
|
13
|
+
var _a = require("../../../../../../a");
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
16
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
17
|
+
/* @pareto-engineering/generator-front 1.1.1-alpha.2 */
|
|
18
|
+
|
|
19
|
+
// Local Definitions
|
|
20
|
+
|
|
21
|
+
const baseClassName = _exports.default.base;
|
|
22
|
+
const componentClassName = 'actions-container';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* This is the component description.
|
|
26
|
+
*/
|
|
27
|
+
const ActionsContainer = _ref => {
|
|
28
|
+
let {
|
|
29
|
+
id,
|
|
30
|
+
className: userClassName,
|
|
31
|
+
style,
|
|
32
|
+
preferredPopoverOrder,
|
|
33
|
+
children
|
|
34
|
+
// ...otherProps
|
|
35
|
+
} = _ref;
|
|
36
|
+
const parentRef = (0, _react.useRef)(null);
|
|
37
|
+
const [isOpen, setIsOpen] = (0, _react.useState)(false);
|
|
38
|
+
(0, _utils.useOutsideClick)(parentRef, () => setIsOpen(false));
|
|
39
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
40
|
+
id: id,
|
|
41
|
+
className: [baseClassName, componentClassName, userClassName].filter(e => e).join(' '),
|
|
42
|
+
style: style,
|
|
43
|
+
ref: parentRef
|
|
44
|
+
}, /*#__PURE__*/React.createElement("button", {
|
|
45
|
+
type: "button",
|
|
46
|
+
onClick: () => setIsOpen(!isOpen)
|
|
47
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
48
|
+
className: "icon x-ui-icons c-x"
|
|
49
|
+
}, "!")), /*#__PURE__*/React.createElement(_a.Popover, {
|
|
50
|
+
isOpen: isOpen,
|
|
51
|
+
parentRef: parentRef,
|
|
52
|
+
preferredPrimaryOrder: preferredPopoverOrder
|
|
53
|
+
}, children));
|
|
54
|
+
};
|
|
55
|
+
ActionsContainer.propTypes = {
|
|
56
|
+
/**
|
|
57
|
+
* The HTML id for this element
|
|
58
|
+
*/
|
|
59
|
+
id: _propTypes.default.string,
|
|
60
|
+
/**
|
|
61
|
+
* The HTML class names for this element
|
|
62
|
+
*/
|
|
63
|
+
className: _propTypes.default.string,
|
|
64
|
+
/**
|
|
65
|
+
* The React-written, css properties for this element.
|
|
66
|
+
*/
|
|
67
|
+
style: _propTypes.default.objectOf(_propTypes.default.string),
|
|
68
|
+
/**
|
|
69
|
+
* The preferred order for the popover
|
|
70
|
+
*/
|
|
71
|
+
preferredPopoverOrder: _propTypes.default.arrayOf(_propTypes.default.string),
|
|
72
|
+
/**
|
|
73
|
+
* The children of the actions container
|
|
74
|
+
*/
|
|
75
|
+
children: _propTypes.default.node
|
|
76
|
+
};
|
|
77
|
+
ActionsContainer.defaultProps = {
|
|
78
|
+
preferredPopoverOrder: ['right', 'bottom', 'left', 'top']
|
|
79
|
+
};
|
|
80
|
+
var _default = exports.default = ActionsContainer;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "ActionsContainer", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _ActionsContainer.default;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
var _ActionsContainer = _interopRequireDefault(require("./ActionsContainer"));
|
|
13
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -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
|
+
|
|
@@ -11,8 +11,8 @@ var _formik = require("formik");
|
|
|
11
11
|
var _exports = _interopRequireDefault(require("@pareto-engineering/bem/exports"));
|
|
12
12
|
var _f = require("../../../../../../f");
|
|
13
13
|
var _a = require("../../../../../../a");
|
|
14
|
-
var _utils = require("../../../../../../utils");
|
|
15
14
|
require("./styles.scss");
|
|
15
|
+
var _ActionsContainer = require("../ActionsContainer");
|
|
16
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
17
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
18
18
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
@@ -33,32 +33,32 @@ const InputBuilder = _ref => {
|
|
|
33
33
|
style,
|
|
34
34
|
sectionIndex,
|
|
35
35
|
inputIndex,
|
|
36
|
-
onDelete
|
|
36
|
+
onDelete
|
|
37
37
|
// onCopy,
|
|
38
|
-
preferredPopoverOrder
|
|
39
38
|
// ...otherProps
|
|
40
39
|
} = _ref;
|
|
41
40
|
const {
|
|
42
41
|
values,
|
|
43
42
|
setFieldValue
|
|
44
43
|
} = (0, _formik.useFormikContext)();
|
|
45
|
-
const input = values.sections[sectionIndex]
|
|
44
|
+
const input = values.sections[sectionIndex]?.inputs[inputIndex];
|
|
46
45
|
const handleToggleRequired = () => {
|
|
47
|
-
setFieldValue(`sections.${sectionIndex}.inputs.${inputIndex}.required`, !input
|
|
46
|
+
setFieldValue(`sections.${sectionIndex}.inputs.${inputIndex}.required`, !input?.required);
|
|
48
47
|
};
|
|
49
48
|
const toggleSwitchStyles = {
|
|
50
49
|
...(!input?.required ? {
|
|
51
50
|
'--slider-background-color': 'var(--disabled)'
|
|
52
51
|
} : {})
|
|
53
52
|
};
|
|
54
|
-
const parentRef = (0, _react.useRef)(null);
|
|
55
|
-
const [isOpen, setIsOpen] = (0, _react.useState)(false);
|
|
56
|
-
(0, _utils.useOutsideClick)(parentRef, () => setIsOpen(false));
|
|
57
53
|
const [hasDescription, setHasDescription] = (0, _react.useState)(false);
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
54
|
+
|
|
55
|
+
// TODO: handle nav logic
|
|
56
|
+
// const handleToggleConditionalNavigation = () => {
|
|
57
|
+
// setFieldValue(`sections.${sectionIndex}.inputs.${inputIndex}.conditionalNavigation`,
|
|
58
|
+
// !input?.conditionalNavigation)
|
|
59
|
+
// }
|
|
60
|
+
|
|
61
|
+
const availableSections = values?.sections?.map((section, idx) => ({
|
|
62
62
|
value: idx,
|
|
63
63
|
label: `Go to ${section.title || `Untitled Section ${idx + 1}`}`
|
|
64
64
|
}));
|
|
@@ -96,9 +96,6 @@ const InputBuilder = _ref => {
|
|
|
96
96
|
}, {
|
|
97
97
|
value: 'select',
|
|
98
98
|
label: 'Dropdown select'
|
|
99
|
-
}, {
|
|
100
|
-
value: 'editor',
|
|
101
|
-
label: 'Editor input'
|
|
102
99
|
}, {
|
|
103
100
|
value: 'multiple',
|
|
104
101
|
label: 'Checkboxes'
|
|
@@ -122,33 +119,14 @@ const InputBuilder = _ref => {
|
|
|
122
119
|
checked: input?.required,
|
|
123
120
|
style: toggleSwitchStyles,
|
|
124
121
|
inputId: `sections_${sectionIndex}_inputs.${inputIndex}_toggle`
|
|
125
|
-
})), /*#__PURE__*/React.createElement("
|
|
126
|
-
className: "actions",
|
|
127
|
-
ref: parentRef
|
|
128
|
-
}, /*#__PURE__*/React.createElement("button", {
|
|
129
|
-
type: "button",
|
|
130
|
-
onClick: () => setIsOpen(!isOpen)
|
|
131
|
-
}, /*#__PURE__*/React.createElement("span", {
|
|
132
|
-
className: "icon x-ui-icons c-x"
|
|
133
|
-
}, "!")), /*#__PURE__*/React.createElement(_a.Popover, {
|
|
134
|
-
isOpen: isOpen,
|
|
135
|
-
parentRef: parentRef,
|
|
136
|
-
preferredPrimaryOrder: preferredPopoverOrder
|
|
137
|
-
}, /*#__PURE__*/React.createElement("p", null, "Show"), /*#__PURE__*/React.createElement("ul", null, /*#__PURE__*/React.createElement("li", {
|
|
122
|
+
})), /*#__PURE__*/React.createElement(_ActionsContainer.ActionsContainer, null, /*#__PURE__*/React.createElement("p", null, "Show"), /*#__PURE__*/React.createElement("ul", null, /*#__PURE__*/React.createElement("li", {
|
|
138
123
|
className: `option ${hasDescription ? 'with-check-mark' : ''}`
|
|
139
124
|
}, hasDescription && /*#__PURE__*/React.createElement("span", {
|
|
140
125
|
className: "x-ui-icons c-x icon"
|
|
141
126
|
}, "I"), /*#__PURE__*/React.createElement("button", {
|
|
142
127
|
onClick: () => setHasDescription(!hasDescription),
|
|
143
128
|
type: "button"
|
|
144
|
-
}, "Description")), /*#__PURE__*/React.createElement("
|
|
145
|
-
className: `option ${input?.conditionalNavigation ? 'with-check-mark' : ''}`
|
|
146
|
-
}, input?.conditionalNavigation && /*#__PURE__*/React.createElement("span", {
|
|
147
|
-
className: "x-ui-icons c-x icon"
|
|
148
|
-
}, "I"), /*#__PURE__*/React.createElement("button", {
|
|
149
|
-
onClick: handleToggleConditionalNavigation,
|
|
150
|
-
type: "button"
|
|
151
|
-
}, "Go to section based on answer"))))))), /*#__PURE__*/React.createElement("div", {
|
|
129
|
+
}, "Description")))))), /*#__PURE__*/React.createElement("div", {
|
|
152
130
|
className: "input-name-description"
|
|
153
131
|
}, /*#__PURE__*/React.createElement(_f.TextInput, {
|
|
154
132
|
label: "Input name",
|
|
@@ -170,8 +148,8 @@ const InputBuilder = _ref => {
|
|
|
170
148
|
}, /*#__PURE__*/React.createElement("p", null, "Options"), input?.options.map((option, optionIndex) => /*#__PURE__*/React.createElement("div", {
|
|
171
149
|
key: option.key,
|
|
172
150
|
className: "option-container"
|
|
173
|
-
}, input
|
|
174
|
-
className: `input-icon-sample ${input
|
|
151
|
+
}, input?.type !== 'select' && /*#__PURE__*/React.createElement("div", {
|
|
152
|
+
className: `input-icon-sample ${input?.type}`
|
|
175
153
|
}), /*#__PURE__*/React.createElement(_f.TextInput, {
|
|
176
154
|
name: `sections.${sectionIndex}.inputs.${inputIndex}.options.${optionIndex}.value`,
|
|
177
155
|
placeholder: `Option ${optionIndex + 1}`,
|
|
@@ -191,7 +169,7 @@ const InputBuilder = _ref => {
|
|
|
191
169
|
className: "add-option-cta",
|
|
192
170
|
type: "button",
|
|
193
171
|
onClick: () => push({
|
|
194
|
-
key: `sections-${sectionIndex}-inputs-${inputIndex}-options-${input
|
|
172
|
+
key: `sections-${sectionIndex}-inputs-${inputIndex}-options-${input?.options.length - 1}`,
|
|
195
173
|
value: '',
|
|
196
174
|
label: '',
|
|
197
175
|
nextSection: ''
|
|
@@ -217,13 +195,9 @@ InputBuilder.propTypes = {
|
|
|
217
195
|
/**
|
|
218
196
|
* The React-written, css properties for this element.
|
|
219
197
|
*/
|
|
220
|
-
style: _propTypes.default.objectOf(_propTypes.default.string)
|
|
221
|
-
/**
|
|
222
|
-
* The preferred primary order of the popover
|
|
223
|
-
*/
|
|
224
|
-
preferredPopoverOrder: _propTypes.default.arrayOf(_propTypes.default.string)
|
|
198
|
+
style: _propTypes.default.objectOf(_propTypes.default.string)
|
|
225
199
|
};
|
|
226
200
|
InputBuilder.defaultProps = {
|
|
227
|
-
|
|
201
|
+
// some properties
|
|
228
202
|
};
|
|
229
203
|
var _default = exports.default = InputBuilder;
|
|
@@ -54,55 +54,6 @@ $default-list-width: var(--action-button-width, 18rem);
|
|
|
54
54
|
font-size: calc(var(--s1) * 1rem);
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
|
-
|
|
58
|
-
> .actions {
|
|
59
|
-
position: relative;
|
|
60
|
-
|
|
61
|
-
> button {
|
|
62
|
-
background-color: transparent;
|
|
63
|
-
border: 0;
|
|
64
|
-
cursor: pointer;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
> .#{bem.$base}.popover {
|
|
68
|
-
background-color: var(--background-cards);
|
|
69
|
-
border: var(--theme-default-border-style) var(--main2);
|
|
70
|
-
border-radius: calc(var(--theme-default-border-radius) / 2);
|
|
71
|
-
cursor: default;
|
|
72
|
-
padding: $default-padding;
|
|
73
|
-
width: $default-list-width;
|
|
74
|
-
|
|
75
|
-
> p {
|
|
76
|
-
margin: 0;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
> ul {
|
|
80
|
-
list-style: none;
|
|
81
|
-
margin: 0;
|
|
82
|
-
padding: 0;
|
|
83
|
-
white-space: nowrap;
|
|
84
|
-
|
|
85
|
-
> .option {
|
|
86
|
-
cursor: pointer;
|
|
87
|
-
padding-block: calc($default-padding / 4);
|
|
88
|
-
|
|
89
|
-
&:not(.with-check-mark) {
|
|
90
|
-
padding-inline: $default-padding;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
> button {
|
|
94
|
-
background: transparent;
|
|
95
|
-
border: 0;
|
|
96
|
-
color: var(--paragraph);
|
|
97
|
-
cursor: pointer;
|
|
98
|
-
font-size: calc(var(--s0) * .875rem);
|
|
99
|
-
text-align: left;
|
|
100
|
-
width: 100%;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
57
|
}
|
|
107
58
|
}
|
|
108
59
|
|
|
@@ -12,6 +12,8 @@ var _exports = _interopRequireDefault(require("@pareto-engineering/bem/exports")
|
|
|
12
12
|
var _f = require("../../../../../../f");
|
|
13
13
|
var _ = require("../../../../..");
|
|
14
14
|
var _InputBuilder = require("../InputBuilder");
|
|
15
|
+
var _ActionsContainer = require("../ActionsContainer");
|
|
16
|
+
require("./styles.scss");
|
|
15
17
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
18
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
17
19
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
@@ -20,7 +22,7 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
|
|
|
20
22
|
// Local Definitions
|
|
21
23
|
|
|
22
24
|
const baseClassName = _exports.default.base;
|
|
23
|
-
const componentClassName = 'section';
|
|
25
|
+
const componentClassName = 'builder-section';
|
|
24
26
|
|
|
25
27
|
/**
|
|
26
28
|
* This is the component description.
|
|
@@ -30,7 +32,8 @@ const Section = _ref => {
|
|
|
30
32
|
id,
|
|
31
33
|
className: userClassName,
|
|
32
34
|
style,
|
|
33
|
-
index
|
|
35
|
+
index,
|
|
36
|
+
handleDeleteSection
|
|
34
37
|
// ...otherProps
|
|
35
38
|
} = _ref;
|
|
36
39
|
const {
|
|
@@ -72,9 +75,17 @@ const Section = _ref => {
|
|
|
72
75
|
id: id,
|
|
73
76
|
className: [baseClassName, componentClassName, userClassName].filter(e => e).join(' '),
|
|
74
77
|
style: style
|
|
78
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
79
|
+
className: "section-header"
|
|
75
80
|
}, /*#__PURE__*/React.createElement("p", {
|
|
76
81
|
className: "h4"
|
|
77
|
-
}, index === 0 ? 'Form title' : `Section ${index + 1}`), /*#__PURE__*/React.createElement(
|
|
82
|
+
}, index === 0 ? 'Form title' : `Section ${index + 1}`), index !== 0 && /*#__PURE__*/React.createElement(_ActionsContainer.ActionsContainer, null, /*#__PURE__*/React.createElement("ul", null, /*#__PURE__*/React.createElement("li", {
|
|
83
|
+
className: "option"
|
|
84
|
+
}, /*#__PURE__*/React.createElement("button", {
|
|
85
|
+
type: "button",
|
|
86
|
+
className: "remove-section-cta",
|
|
87
|
+
onClick: handleDeleteSection
|
|
88
|
+
}, "Delete Section"))))), /*#__PURE__*/React.createElement(_f.TextInput, {
|
|
78
89
|
name: `sections.${index}.title`,
|
|
79
90
|
placeholder: `Title of the ${index === 0 ? 'form' : 'section'}`
|
|
80
91
|
}), /*#__PURE__*/React.createElement(_f.EditorInput, {
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/* @pareto-engineering/generator-front 1.1.1-alpha.2 */
|
|
2
|
+
|
|
3
|
+
@use "@pareto-engineering/bem";
|
|
4
|
+
|
|
5
|
+
$default-margin: 1rem;
|
|
6
|
+
|
|
7
|
+
.#{bem.$base}.builder-section {
|
|
8
|
+
border-bottom: var(--theme-default-border-style) var(--on-background-inputs);
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
> .section-header {
|
|
12
|
+
align-items: center;
|
|
13
|
+
display: flex;
|
|
14
|
+
justify-content: space-between;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
> .#{bem.$base}.editor-input {
|
|
18
|
+
margin-top: $default-margin;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
> form {
|
|
22
|
+
/* stylelint-disable selector-max-compound-selectors -- required */
|
|
23
|
+
> .add-question-cta {
|
|
24
|
+
align-items: center;
|
|
25
|
+
background-color: transparent;
|
|
26
|
+
border: 0;
|
|
27
|
+
color: var(--hard-interactive);
|
|
28
|
+
cursor: pointer;
|
|
29
|
+
display: flex;
|
|
30
|
+
gap: var(--gap);
|
|
31
|
+
margin-block: calc($default-margin * 1.5);
|
|
32
|
+
margin-left: auto;
|
|
33
|
+
padding: 0;
|
|
34
|
+
transition: all .2s;
|
|
35
|
+
|
|
36
|
+
&:hover {
|
|
37
|
+
color: var(--interactive);
|
|
38
|
+
|
|
39
|
+
> .icon-container {
|
|
40
|
+
background-color: var(--interactive);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
> .icon-container {
|
|
45
|
+
align-items: center;
|
|
46
|
+
background-color: var(--hard-interactive);
|
|
47
|
+
border-radius: 50%;
|
|
48
|
+
display: flex;
|
|
49
|
+
height: 1.6rem;
|
|
50
|
+
justify-content: center;
|
|
51
|
+
width: 1.6rem;
|
|
52
|
+
|
|
53
|
+
> .icon {
|
|
54
|
+
color: var(--on-interactive);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
|