@pareto-engineering/design-system 4.0.0 → 4.0.1-alpha.1

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.
Files changed (79) hide show
  1. package/dist/cjs/a/ToggleSwitch/ToggleSwitch.js +10 -5
  2. package/dist/cjs/f/FormInput/FormInput.js +7 -0
  3. package/dist/cjs/f/fields/EditorInput/EditorInput.js +9 -7
  4. package/dist/cjs/f/fields/SelectInput/SelectInput.js +4 -5
  5. package/dist/cjs/f/fields/SelectInput/common/Single/Single.js +3 -3
  6. package/dist/cjs/g/FormBuilder/FormBuilder.js +77 -0
  7. package/dist/cjs/g/FormBuilder/common/Builder/Builder.js +156 -0
  8. package/dist/cjs/g/FormBuilder/common/Builder/common/InputBuilder/InputBuilder.js +229 -0
  9. package/dist/cjs/g/FormBuilder/common/Builder/common/InputBuilder/index.js +13 -0
  10. package/dist/cjs/g/FormBuilder/common/Builder/common/InputBuilder/styles.scss +192 -0
  11. package/dist/cjs/g/FormBuilder/common/Builder/common/Section/Section.js +133 -0
  12. package/dist/cjs/g/FormBuilder/common/Builder/common/Section/index.js +13 -0
  13. package/dist/cjs/g/FormBuilder/common/Builder/common/index.js +19 -0
  14. package/dist/cjs/g/FormBuilder/common/Builder/index.js +13 -0
  15. package/dist/cjs/g/FormBuilder/common/Builder/styles.scss +106 -0
  16. package/dist/cjs/g/FormBuilder/common/Renderer/Renderer.js +119 -0
  17. package/dist/cjs/g/FormBuilder/common/Renderer/common/Section/Section.js +60 -0
  18. package/dist/cjs/g/FormBuilder/common/Renderer/common/Section/index.js +13 -0
  19. package/dist/cjs/g/FormBuilder/common/Renderer/common/index.js +12 -0
  20. package/dist/cjs/g/FormBuilder/common/Renderer/index.js +13 -0
  21. package/dist/cjs/g/FormBuilder/common/Renderer/styles.scss +15 -0
  22. package/dist/cjs/g/FormBuilder/common/index.js +19 -0
  23. package/dist/cjs/g/FormBuilder/index.js +13 -0
  24. package/dist/cjs/g/FormBuilder/styles.scss +7 -0
  25. package/dist/cjs/g/index.js +8 -1
  26. package/dist/es/a/ToggleSwitch/ToggleSwitch.js +10 -5
  27. package/dist/es/f/FormInput/FormInput.js +7 -0
  28. package/dist/es/f/fields/EditorInput/EditorInput.js +9 -7
  29. package/dist/es/f/fields/SelectInput/SelectInput.js +4 -3
  30. package/dist/es/f/fields/SelectInput/common/Single/Single.js +3 -3
  31. package/dist/es/g/FormBuilder/FormBuilder.js +65 -0
  32. package/dist/es/g/FormBuilder/common/Builder/Builder.js +142 -0
  33. package/dist/es/g/FormBuilder/common/Builder/common/InputBuilder/InputBuilder.js +216 -0
  34. package/dist/es/g/FormBuilder/common/Builder/common/InputBuilder/index.js +2 -0
  35. package/dist/es/g/FormBuilder/common/Builder/common/InputBuilder/styles.scss +192 -0
  36. package/dist/es/g/FormBuilder/common/Builder/common/Section/Section.js +120 -0
  37. package/dist/es/g/FormBuilder/common/Builder/common/Section/index.js +2 -0
  38. package/dist/es/g/FormBuilder/common/Builder/common/index.js +2 -0
  39. package/dist/es/g/FormBuilder/common/Builder/index.js +2 -0
  40. package/dist/es/g/FormBuilder/common/Builder/styles.scss +106 -0
  41. package/dist/es/g/FormBuilder/common/Renderer/Renderer.js +113 -0
  42. package/dist/es/g/FormBuilder/common/Renderer/common/Section/Section.js +52 -0
  43. package/dist/es/g/FormBuilder/common/Renderer/common/Section/index.js +2 -0
  44. package/dist/es/g/FormBuilder/common/Renderer/common/index.js +1 -0
  45. package/dist/es/g/FormBuilder/common/Renderer/index.js +2 -0
  46. package/dist/es/g/FormBuilder/common/Renderer/styles.scss +15 -0
  47. package/dist/es/g/FormBuilder/common/index.js +2 -0
  48. package/dist/es/g/FormBuilder/index.js +2 -0
  49. package/dist/es/g/FormBuilder/styles.scss +7 -0
  50. package/dist/es/g/index.js +2 -1
  51. package/package.json +3 -3
  52. package/src/stories/a/ToggleSwitch.stories.jsx +8 -2
  53. package/src/stories/g/FormBuilder.stories.jsx +97 -0
  54. package/src/ui/a/ToggleSwitch/ToggleSwitch.jsx +9 -3
  55. package/src/ui/f/FormInput/FormInput.jsx +10 -0
  56. package/src/ui/f/fields/EditorInput/EditorInput.jsx +5 -6
  57. package/src/ui/f/fields/SelectInput/SelectInput.jsx +5 -2
  58. package/src/ui/f/fields/SelectInput/common/Single/Single.jsx +2 -1
  59. package/src/ui/g/FormBuilder/FormBuilder.jsx +85 -0
  60. package/src/ui/g/FormBuilder/common/Builder/Builder.jsx +175 -0
  61. package/src/ui/g/FormBuilder/common/Builder/common/InputBuilder/InputBuilder.jsx +279 -0
  62. package/src/ui/g/FormBuilder/common/Builder/common/InputBuilder/index.js +2 -0
  63. package/src/ui/g/FormBuilder/common/Builder/common/InputBuilder/styles.scss +192 -0
  64. package/src/ui/g/FormBuilder/common/Builder/common/Section/Section.jsx +156 -0
  65. package/src/ui/g/FormBuilder/common/Builder/common/Section/index.js +2 -0
  66. package/src/ui/g/FormBuilder/common/Builder/common/index.js +2 -0
  67. package/src/ui/g/FormBuilder/common/Builder/index.js +2 -0
  68. package/src/ui/g/FormBuilder/common/Builder/styles.scss +106 -0
  69. package/src/ui/g/FormBuilder/common/Renderer/Renderer.jsx +145 -0
  70. package/src/ui/g/FormBuilder/common/Renderer/common/Section/Section.jsx +75 -0
  71. package/src/ui/g/FormBuilder/common/Renderer/common/Section/index.js +2 -0
  72. package/src/ui/g/FormBuilder/common/Renderer/common/index.js +1 -0
  73. package/src/ui/g/FormBuilder/common/Renderer/index.js +2 -0
  74. package/src/ui/g/FormBuilder/common/Renderer/styles.scss +15 -0
  75. package/src/ui/g/FormBuilder/common/index.js +2 -0
  76. package/src/ui/g/FormBuilder/index.js +2 -0
  77. package/src/ui/g/FormBuilder/styles.scss +7 -0
  78. package/src/ui/g/index.js +1 -0
  79. package/tests/__snapshots__/Storyshots.test.js.snap +793 -1
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "Renderer", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _Renderer.default;
10
+ }
11
+ });
12
+ var _Renderer = _interopRequireDefault(require("./Renderer"));
13
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -0,0 +1,15 @@
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}.renderer {
8
+ > form {
9
+ > .navigator-container {
10
+ display: flex;
11
+ gap: var(--gap);
12
+ margin-top: $default-margin;
13
+ }
14
+ }
15
+ }
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "Builder", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _Builder.Builder;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "Renderer", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _Renderer.Renderer;
16
+ }
17
+ });
18
+ var _Builder = require("./Builder");
19
+ var _Renderer = require("./Renderer");
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "FormBuilder", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _FormBuilder.default;
10
+ }
11
+ });
12
+ var _FormBuilder = _interopRequireDefault(require("./FormBuilder"));
13
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -0,0 +1,7 @@
1
+ // /* @pareto-engineering/generator-front 1.1.1-alpha.2 */
2
+
3
+ // @use "@pareto-engineering/bem";
4
+
5
+ // .#{bem.$base}.form-builder{
6
+
7
+ // }
@@ -15,5 +15,12 @@ Object.defineProperty(exports, "ExpandableLexicalPreview", {
15
15
  return _ExpandableLexicalPreview.ExpandableLexicalPreview;
16
16
  }
17
17
  });
18
+ Object.defineProperty(exports, "FormBuilder", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _FormBuilder.FormBuilder;
22
+ }
23
+ });
18
24
  var _ExpandableLexicalPreview = require("./ExpandableLexicalPreview");
19
- var _DragAndDrop = require("./DragAndDrop");
25
+ var _DragAndDrop = require("./DragAndDrop");
26
+ var _FormBuilder = require("./FormBuilder");
@@ -18,7 +18,8 @@ const ToggleSwitch = ({
18
18
  style,
19
19
  handleOnChange,
20
20
  checked,
21
- size
21
+ size,
22
+ inputId
22
23
  // ...otherProps
23
24
  }) => /*#__PURE__*/React.createElement("button", {
24
25
  id: id,
@@ -31,11 +32,11 @@ const ToggleSwitch = ({
31
32
  // {...otherProps}
32
33
  }, /*#__PURE__*/React.createElement("input", {
33
34
  type: "checkbox",
34
- id: "switch",
35
+ id: inputId,
35
36
  checked: checked,
36
37
  onChange: handleOnChange
37
38
  }), /*#__PURE__*/React.createElement("label", {
38
- htmlFor: "switch"
39
+ htmlFor: inputId
39
40
  }));
40
41
  ToggleSwitch.propTypes = {
41
42
  /**
@@ -61,9 +62,13 @@ ToggleSwitch.propTypes = {
61
62
  /**
62
63
  * The size of this element
63
64
  */
64
- size: PropTypes.string
65
+ size: PropTypes.string,
66
+ /**
67
+ * The ID of the elelment to be toggled
68
+ */
69
+ inputId: PropTypes.string
65
70
  };
66
71
  ToggleSwitch.defaultProps = {
67
- // someProp:false,
72
+ inputId: 'switch'
68
73
  };
69
74
  export default ToggleSwitch;
@@ -29,6 +29,13 @@ const FormInput = ({
29
29
  disabled: disabled
30
30
  }, otherProps));
31
31
  }
32
+ if (type === 'multiple') {
33
+ return /*#__PURE__*/React.createElement(ChoicesInput, _extends({
34
+ className: newClassName,
35
+ disabled: disabled,
36
+ multiple: true
37
+ }, otherProps));
38
+ }
32
39
  if (type === 'choices') {
33
40
  return /*#__PURE__*/React.createElement(ChoicesInput, _extends({
34
41
  className: newClassName,
@@ -59,11 +59,15 @@ const EditorInput = ({
59
59
  showDebugger,
60
60
  stopPropagationKeys,
61
61
  setEditorState
62
+ // handleOnChange,
62
63
  // ...otherProps
63
64
  }) => {
64
- const formik = useFormikContext();
65
+ const {
66
+ values,
67
+ setFieldValue
68
+ } = useFormikContext();
65
69
  const setInitialValue = () => {
66
- const value = formik.values[name];
70
+ const value = values[name];
67
71
  try {
68
72
  JSON.parse(value);
69
73
  return value;
@@ -98,10 +102,7 @@ const EditorInput = ({
98
102
  }
99
103
  };
100
104
  const onChange = state => {
101
- formik.setValues({
102
- ...formik.values,
103
- [name]: JSON.stringify(state)
104
- });
105
+ setFieldValue(name, JSON.stringify(state));
105
106
  };
106
107
  const initialConfig = {
107
108
  nameSpace: name,
@@ -138,7 +139,8 @@ const EditorInput = ({
138
139
  }, label), !disabled && /*#__PURE__*/React.createElement(ToolbarPlugin, null), /*#__PURE__*/React.createElement(RichTextPlugin, {
139
140
  contentEditable: /*#__PURE__*/React.createElement(ContentEditable, {
140
141
  className: "content-editable",
141
- id: name
142
+ id: name,
143
+ name: name
142
144
  }),
143
145
  ErrorBoundary: LexicalErrorBoundary
144
146
  }), /*#__PURE__*/React.createElement(ListPlugin, null), /*#__PURE__*/React.createElement(CheckListPlugin, null), /*#__PURE__*/React.createElement(OnChangePlugin, {
@@ -1,3 +1,4 @@
1
+ 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); }
1
2
  /* @pareto-engineering/generator-front 1.0.12 */
2
3
  import * as React from 'react';
3
4
  import { memo } from 'react';
@@ -32,8 +33,8 @@ const SelectInput = ({
32
33
  autoComplete,
33
34
  placeholder,
34
35
  getTagColor,
35
- multiple
36
- // ...otherProps
36
+ multiple,
37
+ ...otherProps
37
38
  }) => {
38
39
  const inputProps = {
39
40
  name,
@@ -56,7 +57,7 @@ const SelectInput = ({
56
57
  id: id,
57
58
  className: [baseClassName, componentClassName, userClassName].filter(e => e).join(' '),
58
59
  style: style
59
- }, /*#__PURE__*/React.createElement(Input, inputProps));
60
+ }, /*#__PURE__*/React.createElement(Input, _extends({}, inputProps, otherProps)));
60
61
  };
61
62
  SelectInput.propTypes = {
62
63
  /**
@@ -31,8 +31,8 @@ const Single = ({
31
31
  description,
32
32
  disabled,
33
33
  isLoading,
34
- autoComplete
35
- // ...otherProps
34
+ autoComplete,
35
+ ...otherProps
36
36
  }) => {
37
37
  const [field,, helpers] = useField({
38
38
  name,
@@ -64,7 +64,7 @@ const Single = ({
64
64
  id: name,
65
65
  disabled: disabled,
66
66
  autoComplete: autoComplete
67
- }), options.map(option => {
67
+ }, otherProps), options.map(option => {
68
68
  // i.e if option is a string like "blah", return { value: "blah", label: "blah" }
69
69
  const newOption = typeof option === 'string' ? {
70
70
  value: option,
@@ -0,0 +1,65 @@
1
+ /* @pareto-engineering/generator-front 1.1.1-alpha.2 */
2
+ import * as React from 'react';
3
+ import PropTypes from 'prop-types';
4
+ import styleNames from '@pareto-engineering/bem/exports';
5
+ import "./styles.scss";
6
+
7
+ // Local Definitions
8
+
9
+ import { Renderer, Builder } from "./common";
10
+ const baseClassName = styleNames.base;
11
+ const componentClassName = 'form-builder';
12
+
13
+ /**
14
+ * This is the component description.
15
+ */
16
+ const FormBuilder = ({
17
+ id,
18
+ className: userClassName,
19
+ style,
20
+ mode,
21
+ formData,
22
+ formBuilderId,
23
+ onBuilderFormSave,
24
+ onRendererFormSave
25
+ // ...otherProps
26
+ }) => /*#__PURE__*/React.createElement("div", {
27
+ id: id,
28
+ className: [baseClassName, componentClassName, userClassName].filter(e => e).join(' '),
29
+ style: style
30
+ // {...otherProps}
31
+ }, mode === 'build' && /*#__PURE__*/React.createElement(Builder, {
32
+ formBuilderId: formBuilderId,
33
+ onSave: onBuilderFormSave
34
+ }), mode === 'render' && /*#__PURE__*/React.createElement(Renderer, {
35
+ formData: formData,
36
+ onSave: onRendererFormSave
37
+ }));
38
+ FormBuilder.propTypes = {
39
+ /**
40
+ * The HTML id for this element
41
+ */
42
+ id: PropTypes.string,
43
+ /**
44
+ * The HTML class names for this element
45
+ */
46
+ className: PropTypes.string,
47
+ /**
48
+ * The React-written, css properties for this element.
49
+ */
50
+ style: PropTypes.objectOf(PropTypes.string),
51
+ /**
52
+ * The mode of the form builder to determine whether to render a form or build a form
53
+ */
54
+ mode: PropTypes.oneOf(['build', 'render']),
55
+ /**
56
+ * This is the ID of the form element in the <Builder /> component
57
+ */
58
+ formBuilderId: PropTypes.string.isRequired
59
+ };
60
+ FormBuilder.defaultProps = {
61
+ mode: 'build'
62
+ };
63
+ FormBuilder.Builder = Builder;
64
+ FormBuilder.Renderer = Renderer;
65
+ export default FormBuilder;
@@ -0,0 +1,142 @@
1
+ /* @pareto-engineering/generator-front 1.1.1-alpha.2 */
2
+ import * as React from 'react';
3
+ import { Formik, Form, FieldArray } from 'formik';
4
+ import PropTypes from 'prop-types';
5
+ import styleNames from '@pareto-engineering/bem/exports';
6
+ import { SelectInput } from "../../../../f";
7
+ import { Section } from "./common";
8
+ import "./styles.scss";
9
+
10
+ // Local Definitions
11
+
12
+ const baseClassName = styleNames.base;
13
+ const componentClassName = 'builder';
14
+ const reorderInputs = values => {
15
+ const valuesCopy = JSON.parse(JSON.stringify(values));
16
+ valuesCopy.sections.forEach(section => {
17
+ const orderMap = new Map();
18
+ section.orderedInputDragIds.forEach((id, index) => orderMap.set(id, index));
19
+ section.inputs.sort((a, b) => orderMap.get(a.name) - orderMap.get(b.name));
20
+ });
21
+ return valuesCopy;
22
+ };
23
+
24
+ /**
25
+ */
26
+ const Builder = ({
27
+ id,
28
+ className: userClassName,
29
+ style,
30
+ onSave,
31
+ formBuilderId
32
+ // ...otherProps
33
+ }) => {
34
+ const handleSubmit = values => {
35
+ const reOrderedValues = reorderInputs(values);
36
+ onSave(reOrderedValues);
37
+ };
38
+ return /*#__PURE__*/React.createElement("div", {
39
+ id: id,
40
+ className: [baseClassName, componentClassName, userClassName].filter(e => e).join(' '),
41
+ style: style
42
+ }, /*#__PURE__*/React.createElement("p", {
43
+ className: "h3"
44
+ }, "Form Builder"), /*#__PURE__*/React.createElement(Formik, {
45
+ initialValues: {
46
+ sections: [{
47
+ title: '',
48
+ description: '',
49
+ key: 'section-0',
50
+ inputs: [],
51
+ orderedInputDragIds: [],
52
+ navigation: {
53
+ nextSection: 'next'
54
+ }
55
+ }]
56
+ },
57
+ onSubmit: handleSubmit
58
+ }, ({
59
+ values
60
+ }) => {
61
+ const availableSections = values.sections.map((section, idx) => ({
62
+ value: idx,
63
+ label: `Go to ${section.title || `Untitled Section ${idx + 1}`}`
64
+ }));
65
+ return /*#__PURE__*/React.createElement(Form, {
66
+ id: formBuilderId
67
+ }, /*#__PURE__*/React.createElement(FieldArray, {
68
+ name: "sections"
69
+ }, ({
70
+ push
71
+ }) => /*#__PURE__*/React.createElement(React.Fragment, null, values.sections.map((section, index) => /*#__PURE__*/React.createElement(Section, {
72
+ key: section.key,
73
+ index: index
74
+ })), /*#__PURE__*/React.createElement("div", {
75
+ className: "section-footer"
76
+ }, /*#__PURE__*/React.createElement("button", {
77
+ className: "add-section-cta",
78
+ type: "button",
79
+ onClick: () => {
80
+ const currentIndex = values.sections.length;
81
+ return push({
82
+ title: '',
83
+ description: '',
84
+ key: `section-${currentIndex}`,
85
+ inputs: [{
86
+ type: 'text',
87
+ options: [],
88
+ required: true,
89
+ description: '',
90
+ name: `section_${values.sections.length}_input_0`,
91
+ label: ''
92
+ }],
93
+ orderedInputDragIds: [],
94
+ navigation: {
95
+ nextSection: 'next'
96
+ }
97
+ });
98
+ }
99
+ }, /*#__PURE__*/React.createElement("div", {
100
+ className: "icon-container"
101
+ }, /*#__PURE__*/React.createElement("span", {
102
+ className: "icon"
103
+ }, "+")), /*#__PURE__*/React.createElement("span", {
104
+ className: "text x-paragraph c-x"
105
+ }, "Add Section")), /*#__PURE__*/React.createElement("div", {
106
+ className: "section-navigation"
107
+ }, /*#__PURE__*/React.createElement("span", {
108
+ className: "x-paragraph c-x"
109
+ }, "After Section", ' ', values.sections.length), /*#__PURE__*/React.createElement(SelectInput, {
110
+ name: `sections.${values.sections.length - 1}.navigation.nextSection`,
111
+ options: [{
112
+ label: 'Select section',
113
+ value: '',
114
+ disabled: true
115
+ }, {
116
+ label: 'Continue to next section',
117
+ value: 'next'
118
+ }, ...availableSections, {
119
+ label: 'Submit form',
120
+ value: 'submit'
121
+ }]
122
+ }))))));
123
+ }));
124
+ };
125
+ Builder.propTypes = {
126
+ /**
127
+ * The HTML id for this element
128
+ */
129
+ id: PropTypes.string,
130
+ /**
131
+ * The HTML class names for this element
132
+ */
133
+ className: PropTypes.string,
134
+ /**
135
+ * The React-written, css properties for this element.
136
+ */
137
+ style: PropTypes.objectOf(PropTypes.string)
138
+ };
139
+ Builder.defaultProps = {
140
+ // someProp:false
141
+ };
142
+ export default Builder;
@@ -0,0 +1,216 @@
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 { FieldArray, useFormikContext } from 'formik';
6
+ import styleNames from '@pareto-engineering/bem/exports';
7
+ import { SelectInput, TextInput } from "../../../../../../f";
8
+ import { ToggleSwitch, Popover } from "../../../../../../a";
9
+ import { useOutsideClick } from "../../../../../../utils";
10
+ import "./styles.scss";
11
+
12
+ // Local Definitions
13
+
14
+ const baseClassName = styleNames.base;
15
+ const componentClassName = 'input-builder';
16
+
17
+ /**
18
+ * This is the component description.
19
+ */
20
+ const InputBuilder = ({
21
+ id,
22
+ className: userClassName,
23
+ style,
24
+ sectionIndex,
25
+ inputIndex,
26
+ onDelete,
27
+ // onCopy,
28
+ preferredPopoverOrder
29
+ // ...otherProps
30
+ }) => {
31
+ const {
32
+ values,
33
+ setFieldValue
34
+ } = useFormikContext();
35
+ const input = values.sections[sectionIndex].inputs[inputIndex];
36
+ const handleToggleRequired = () => {
37
+ setFieldValue(`sections.${sectionIndex}.inputs.${inputIndex}.required`, !input.required);
38
+ };
39
+ const toggleSwitchStyles = {
40
+ ...(!input?.required ? {
41
+ '--slider-background-color': 'var(--disabled)'
42
+ } : {})
43
+ };
44
+ const parentRef = useRef(null);
45
+ const [isOpen, setIsOpen] = useState(false);
46
+ useOutsideClick(parentRef, () => setIsOpen(false));
47
+ const [hasDescription, setHasDescription] = useState(false);
48
+ const handleToggleConditionalNavigation = () => {
49
+ setFieldValue(`sections.${sectionIndex}.inputs.${inputIndex}.conditionalNavigation`, !input.conditionalNavigation);
50
+ };
51
+ const availableSections = values.sections.map((section, idx) => ({
52
+ value: idx,
53
+ label: `Go to ${section.title || `Untitled Section ${idx + 1}`}`
54
+ }));
55
+ const shouldRenderOptions = input?.type === 'select' || input?.type === 'multiple' || input?.type === 'choices';
56
+ const handleSelectOptionBlur = (e, optionIndex) => {
57
+ const {
58
+ value
59
+ } = e.target;
60
+ setFieldValue(`sections.${sectionIndex}.inputs.${inputIndex}.options.${optionIndex}.label`, value);
61
+ };
62
+ return /*#__PURE__*/React.createElement("div", {
63
+ id: id,
64
+ className: [baseClassName, componentClassName, userClassName].filter(e => e).join(' '),
65
+ style: style
66
+ }, /*#__PURE__*/React.createElement("div", {
67
+ className: "drag-icon"
68
+ }, /*#__PURE__*/React.createElement("span", {
69
+ className: "ai-icon"
70
+ }, "H")), /*#__PURE__*/React.createElement("div", {
71
+ className: "input-options-container"
72
+ }, /*#__PURE__*/React.createElement("div", {
73
+ className: "controls-container"
74
+ }, /*#__PURE__*/React.createElement(SelectInput, {
75
+ name: `sections.${sectionIndex}.inputs.${inputIndex}.type`,
76
+ options: [{
77
+ value: '',
78
+ label: 'Select an option',
79
+ disabled: true
80
+ }, {
81
+ value: 'text',
82
+ label: 'Basic input'
83
+ }, {
84
+ value: 'textarea',
85
+ label: 'Long paragraph'
86
+ }, {
87
+ value: 'select',
88
+ label: 'Dropdown select'
89
+ }, {
90
+ value: 'editor',
91
+ label: 'Editor input'
92
+ }, {
93
+ value: 'multiple',
94
+ label: 'Checkboxes'
95
+ }, {
96
+ value: 'choices',
97
+ label: 'Radio buttons'
98
+ }]
99
+ }), /*#__PURE__*/React.createElement("div", {
100
+ className: "controls"
101
+ }, /*#__PURE__*/React.createElement("button", {
102
+ type: "button",
103
+ onClick: () => onDelete(inputIndex)
104
+ }, /*#__PURE__*/React.createElement("span", {
105
+ className: "icon x-ui-icons c-x"
106
+ }, "D")), /*#__PURE__*/React.createElement("div", {
107
+ className: "is-required"
108
+ }, /*#__PURE__*/React.createElement("span", {
109
+ className: "s0"
110
+ }, "Required"), /*#__PURE__*/React.createElement(ToggleSwitch, {
111
+ handleOnChange: handleToggleRequired,
112
+ checked: input?.required,
113
+ style: toggleSwitchStyles,
114
+ inputId: `sections_${sectionIndex}_inputs.${inputIndex}_toggle`
115
+ })), /*#__PURE__*/React.createElement("div", {
116
+ className: "actions",
117
+ ref: parentRef
118
+ }, /*#__PURE__*/React.createElement("button", {
119
+ type: "button",
120
+ onClick: () => setIsOpen(!isOpen)
121
+ }, /*#__PURE__*/React.createElement("span", {
122
+ className: "icon x-ui-icons c-x"
123
+ }, "!")), /*#__PURE__*/React.createElement(Popover, {
124
+ isOpen: isOpen,
125
+ parentRef: parentRef,
126
+ preferredPrimaryOrder: preferredPopoverOrder
127
+ }, /*#__PURE__*/React.createElement("p", null, "Show"), /*#__PURE__*/React.createElement("ul", null, /*#__PURE__*/React.createElement("li", {
128
+ className: `option ${hasDescription ? 'with-check-mark' : ''}`
129
+ }, hasDescription && /*#__PURE__*/React.createElement("span", {
130
+ className: "x-ui-icons c-x icon"
131
+ }, "I"), /*#__PURE__*/React.createElement("button", {
132
+ onClick: () => setHasDescription(!hasDescription),
133
+ type: "button"
134
+ }, "Description")), /*#__PURE__*/React.createElement("li", {
135
+ className: `option ${input?.conditionalNavigation ? 'with-check-mark' : ''}`
136
+ }, input?.conditionalNavigation && /*#__PURE__*/React.createElement("span", {
137
+ className: "x-ui-icons c-x icon"
138
+ }, "I"), /*#__PURE__*/React.createElement("button", {
139
+ onClick: handleToggleConditionalNavigation,
140
+ type: "button"
141
+ }, "Go to section based on answer"))))))), /*#__PURE__*/React.createElement("div", {
142
+ className: "input-name-description"
143
+ }, /*#__PURE__*/React.createElement(TextInput, {
144
+ label: "Input name",
145
+ name: `sections.${sectionIndex}.inputs.${inputIndex}.label`,
146
+ placeholder: "Question"
147
+ }), hasDescription && /*#__PURE__*/React.createElement(TextInput, {
148
+ label: "Description(optional)",
149
+ name: `sections.${sectionIndex}.inputs.${inputIndex}.description`,
150
+ placeholder: "Describe details for the question"
151
+ })), shouldRenderOptions && /*#__PURE__*/React.createElement(FieldArray, {
152
+ name: `sections.${sectionIndex}.inputs.${inputIndex}.options`
153
+ }, ({
154
+ push,
155
+ remove
156
+ }) => /*#__PURE__*/React.createElement("div", {
157
+ className: "input-options"
158
+ }, /*#__PURE__*/React.createElement("p", null, "Options"), input?.options.map((option, optionIndex) => /*#__PURE__*/React.createElement("div", {
159
+ key: option.key,
160
+ className: "option-container"
161
+ }, input.type !== 'select' && /*#__PURE__*/React.createElement("div", {
162
+ className: `input-icon-sample ${input.type}`
163
+ }), /*#__PURE__*/React.createElement(TextInput, {
164
+ name: `sections.${sectionIndex}.inputs.${inputIndex}.options.${optionIndex}.value`,
165
+ placeholder: `Option ${optionIndex + 1}`,
166
+ onBlur: e => handleSelectOptionBlur(e, optionIndex)
167
+ }), input?.conditionalNavigation && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(SelectInput, {
168
+ options: [{
169
+ label: 'Select section',
170
+ value: '',
171
+ disabled: true
172
+ }, ...availableSections],
173
+ name: `sections.${sectionIndex}.inputs.${inputIndex}.options.${optionIndex}.nextSection`
174
+ })), /*#__PURE__*/React.createElement("button", {
175
+ className: "icon",
176
+ type: "button",
177
+ onClick: () => remove(optionIndex)
178
+ }, "Y"))), /*#__PURE__*/React.createElement("button", {
179
+ className: "add-option-cta",
180
+ type: "button",
181
+ onClick: () => push({
182
+ key: `sections-${sectionIndex}-inputs-${inputIndex}-options-${input.options.length - 1}`,
183
+ value: '',
184
+ label: '',
185
+ nextSection: ''
186
+ })
187
+ }, /*#__PURE__*/React.createElement("div", {
188
+ className: "icon-container"
189
+ }, /*#__PURE__*/React.createElement("span", {
190
+ className: "icon"
191
+ }, "+")), /*#__PURE__*/React.createElement("span", {
192
+ className: "text x-paragraph c-x"
193
+ }, "Add Option"))))));
194
+ };
195
+ InputBuilder.propTypes = {
196
+ /**
197
+ * The HTML id for this element
198
+ */
199
+ id: PropTypes.string,
200
+ /**
201
+ * The HTML class names for this element
202
+ */
203
+ className: PropTypes.string,
204
+ /**
205
+ * The React-written, css properties for this element.
206
+ */
207
+ style: PropTypes.objectOf(PropTypes.string),
208
+ /**
209
+ * The preferred primary order of the popover
210
+ */
211
+ preferredPopoverOrder: PropTypes.arrayOf(PropTypes.string)
212
+ };
213
+ InputBuilder.defaultProps = {
214
+ preferredPopoverOrder: ['right', 'bottom', 'left', 'top']
215
+ };
216
+ export default InputBuilder;
@@ -0,0 +1,2 @@
1
+ /* @pareto-engineering/generator-front 1.1.1-alpha.2 */
2
+ export { default as InputBuilder } from "./InputBuilder";