@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.
Files changed (48) hide show
  1. package/dist/cjs/f/fields/EditorInput/EditorInput.js +4 -6
  2. package/dist/cjs/g/FormBuilder/FormBuilder.js +38 -5
  3. package/dist/cjs/g/FormBuilder/common/Builder/Builder.js +62 -25
  4. package/dist/cjs/g/FormBuilder/common/Builder/common/ActionsContainer/ActionsContainer.js +80 -0
  5. package/dist/cjs/g/FormBuilder/common/Builder/common/ActionsContainer/index.js +13 -0
  6. package/dist/cjs/g/FormBuilder/common/Builder/common/ActionsContainer/styles.scss +59 -0
  7. package/dist/cjs/g/FormBuilder/common/Builder/common/InputBuilder/InputBuilder.js +19 -45
  8. package/dist/cjs/g/FormBuilder/common/Builder/common/InputBuilder/styles.scss +0 -49
  9. package/dist/cjs/g/FormBuilder/common/Builder/common/Section/Section.js +14 -3
  10. package/dist/cjs/g/FormBuilder/common/Builder/common/Section/styles.scss +61 -0
  11. package/dist/cjs/g/FormBuilder/common/Builder/common/index.js +8 -1
  12. package/dist/cjs/g/FormBuilder/common/Builder/styles.scss +5 -48
  13. package/dist/cjs/g/FormBuilder/common/Renderer/Renderer.js +76 -33
  14. package/dist/cjs/g/FormBuilder/common/Renderer/common/Section/Section.js +8 -3
  15. package/dist/cjs/g/FormBuilder/common/Renderer/styles.scss +12 -1
  16. package/dist/es/f/fields/EditorInput/EditorInput.js +5 -7
  17. package/dist/es/g/FormBuilder/FormBuilder.js +38 -5
  18. package/dist/es/g/FormBuilder/common/Builder/Builder.js +56 -20
  19. package/dist/es/g/FormBuilder/common/Builder/common/ActionsContainer/ActionsContainer.js +70 -0
  20. package/dist/es/g/FormBuilder/common/Builder/common/ActionsContainer/index.js +2 -0
  21. package/dist/es/g/FormBuilder/common/Builder/common/ActionsContainer/styles.scss +59 -0
  22. package/dist/es/g/FormBuilder/common/Builder/common/InputBuilder/InputBuilder.js +21 -47
  23. package/dist/es/g/FormBuilder/common/Builder/common/InputBuilder/styles.scss +0 -49
  24. package/dist/es/g/FormBuilder/common/Builder/common/Section/Section.js +14 -3
  25. package/dist/es/g/FormBuilder/common/Builder/common/Section/styles.scss +61 -0
  26. package/dist/es/g/FormBuilder/common/Builder/common/index.js +2 -1
  27. package/dist/es/g/FormBuilder/common/Builder/styles.scss +5 -48
  28. package/dist/es/g/FormBuilder/common/Renderer/Renderer.js +76 -34
  29. package/dist/es/g/FormBuilder/common/Renderer/common/Section/Section.js +8 -3
  30. package/dist/es/g/FormBuilder/common/Renderer/styles.scss +12 -1
  31. package/package.json +3 -3
  32. package/src/stories/g/FormBuilder.stories.jsx +116 -21
  33. package/src/ui/f/fields/EditorInput/EditorInput.jsx +6 -8
  34. package/src/ui/g/FormBuilder/FormBuilder.jsx +50 -3
  35. package/src/ui/g/FormBuilder/common/Builder/Builder.jsx +56 -18
  36. package/src/ui/g/FormBuilder/common/Builder/common/ActionsContainer/ActionsContainer.jsx +97 -0
  37. package/src/ui/g/FormBuilder/common/Builder/common/ActionsContainer/index.js +2 -0
  38. package/src/ui/g/FormBuilder/common/Builder/common/ActionsContainer/styles.scss +59 -0
  39. package/src/ui/g/FormBuilder/common/Builder/common/InputBuilder/InputBuilder.jsx +40 -60
  40. package/src/ui/g/FormBuilder/common/Builder/common/InputBuilder/styles.scss +0 -49
  41. package/src/ui/g/FormBuilder/common/Builder/common/Section/Section.jsx +26 -4
  42. package/src/ui/g/FormBuilder/common/Builder/common/Section/styles.scss +61 -0
  43. package/src/ui/g/FormBuilder/common/Builder/common/index.js +1 -0
  44. package/src/ui/g/FormBuilder/common/Builder/styles.scss +5 -48
  45. package/src/ui/g/FormBuilder/common/Renderer/Renderer.jsx +84 -33
  46. package/src/ui/g/FormBuilder/common/Renderer/common/Section/Section.jsx +3 -2
  47. package/src/ui/g/FormBuilder/common/Renderer/styles.scss +12 -1
  48. package/tests/__snapshots__/Storyshots.test.js.snap +395 -133
@@ -1,16 +1,16 @@
1
1
  /* @pareto-engineering/generator-front 1.1.1-alpha.2 */
2
2
  import * as React from 'react';
3
- import { useState, useRef } from 'react';
3
+ import { useState } from 'react';
4
4
  import PropTypes from 'prop-types';
5
5
  import { FieldArray, useFormikContext } from 'formik';
6
6
  import styleNames from '@pareto-engineering/bem/exports';
7
7
  import { SelectInput, TextInput } from "../../../../../../f";
8
- import { ToggleSwitch, Popover } from "../../../../../../a";
9
- import { useOutsideClick } from "../../../../../../utils";
8
+ import { ToggleSwitch } from "../../../../../../a";
10
9
  import "./styles.scss";
11
10
 
12
11
  // Local Definitions
13
12
 
13
+ import { ActionsContainer } from "../ActionsContainer";
14
14
  const baseClassName = styleNames.base;
15
15
  const componentClassName = 'input-builder';
16
16
 
@@ -23,32 +23,32 @@ const InputBuilder = ({
23
23
  style,
24
24
  sectionIndex,
25
25
  inputIndex,
26
- onDelete,
26
+ onDelete
27
27
  // onCopy,
28
- preferredPopoverOrder
29
28
  // ...otherProps
30
29
  }) => {
31
30
  const {
32
31
  values,
33
32
  setFieldValue
34
33
  } = useFormikContext();
35
- const input = values.sections[sectionIndex].inputs[inputIndex];
34
+ const input = values.sections[sectionIndex]?.inputs[inputIndex];
36
35
  const handleToggleRequired = () => {
37
- setFieldValue(`sections.${sectionIndex}.inputs.${inputIndex}.required`, !input.required);
36
+ setFieldValue(`sections.${sectionIndex}.inputs.${inputIndex}.required`, !input?.required);
38
37
  };
39
38
  const toggleSwitchStyles = {
40
39
  ...(!input?.required ? {
41
40
  '--slider-background-color': 'var(--disabled)'
42
41
  } : {})
43
42
  };
44
- const parentRef = useRef(null);
45
- const [isOpen, setIsOpen] = useState(false);
46
- useOutsideClick(parentRef, () => setIsOpen(false));
47
43
  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) => ({
44
+
45
+ // TODO: handle nav logic
46
+ // const handleToggleConditionalNavigation = () => {
47
+ // setFieldValue(`sections.${sectionIndex}.inputs.${inputIndex}.conditionalNavigation`,
48
+ // !input?.conditionalNavigation)
49
+ // }
50
+
51
+ const availableSections = values?.sections?.map((section, idx) => ({
52
52
  value: idx,
53
53
  label: `Go to ${section.title || `Untitled Section ${idx + 1}`}`
54
54
  }));
@@ -86,9 +86,6 @@ const InputBuilder = ({
86
86
  }, {
87
87
  value: 'select',
88
88
  label: 'Dropdown select'
89
- }, {
90
- value: 'editor',
91
- label: 'Editor input'
92
89
  }, {
93
90
  value: 'multiple',
94
91
  label: 'Checkboxes'
@@ -112,33 +109,14 @@ const InputBuilder = ({
112
109
  checked: input?.required,
113
110
  style: toggleSwitchStyles,
114
111
  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", {
112
+ })), /*#__PURE__*/React.createElement(ActionsContainer, null, /*#__PURE__*/React.createElement("p", null, "Show"), /*#__PURE__*/React.createElement("ul", null, /*#__PURE__*/React.createElement("li", {
128
113
  className: `option ${hasDescription ? 'with-check-mark' : ''}`
129
114
  }, hasDescription && /*#__PURE__*/React.createElement("span", {
130
115
  className: "x-ui-icons c-x icon"
131
116
  }, "I"), /*#__PURE__*/React.createElement("button", {
132
117
  onClick: () => setHasDescription(!hasDescription),
133
118
  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", {
119
+ }, "Description")))))), /*#__PURE__*/React.createElement("div", {
142
120
  className: "input-name-description"
143
121
  }, /*#__PURE__*/React.createElement(TextInput, {
144
122
  label: "Input name",
@@ -158,8 +136,8 @@ const InputBuilder = ({
158
136
  }, /*#__PURE__*/React.createElement("p", null, "Options"), input?.options.map((option, optionIndex) => /*#__PURE__*/React.createElement("div", {
159
137
  key: option.key,
160
138
  className: "option-container"
161
- }, input.type !== 'select' && /*#__PURE__*/React.createElement("div", {
162
- className: `input-icon-sample ${input.type}`
139
+ }, input?.type !== 'select' && /*#__PURE__*/React.createElement("div", {
140
+ className: `input-icon-sample ${input?.type}`
163
141
  }), /*#__PURE__*/React.createElement(TextInput, {
164
142
  name: `sections.${sectionIndex}.inputs.${inputIndex}.options.${optionIndex}.value`,
165
143
  placeholder: `Option ${optionIndex + 1}`,
@@ -179,7 +157,7 @@ const InputBuilder = ({
179
157
  className: "add-option-cta",
180
158
  type: "button",
181
159
  onClick: () => push({
182
- key: `sections-${sectionIndex}-inputs-${inputIndex}-options-${input.options.length - 1}`,
160
+ key: `sections-${sectionIndex}-inputs-${inputIndex}-options-${input?.options.length - 1}`,
183
161
  value: '',
184
162
  label: '',
185
163
  nextSection: ''
@@ -204,13 +182,9 @@ InputBuilder.propTypes = {
204
182
  /**
205
183
  * The React-written, css properties for this element.
206
184
  */
207
- style: PropTypes.objectOf(PropTypes.string),
208
- /**
209
- * The preferred primary order of the popover
210
- */
211
- preferredPopoverOrder: PropTypes.arrayOf(PropTypes.string)
185
+ style: PropTypes.objectOf(PropTypes.string)
212
186
  };
213
187
  InputBuilder.defaultProps = {
214
- preferredPopoverOrder: ['right', 'bottom', 'left', 'top']
188
+ // some properties
215
189
  };
216
190
  export 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
 
@@ -10,8 +10,10 @@ import styleNames from '@pareto-engineering/bem/exports';
10
10
  import { TextInput, EditorInput } from "../../../../../../f";
11
11
  import { DragAndDrop } from "../../../../..";
12
12
  import { InputBuilder } from "../InputBuilder";
13
+ import { ActionsContainer } from "../ActionsContainer";
14
+ import "./styles.scss";
13
15
  const baseClassName = styleNames.base;
14
- const componentClassName = 'section';
16
+ const componentClassName = 'builder-section';
15
17
 
16
18
  /**
17
19
  * This is the component description.
@@ -20,7 +22,8 @@ const Section = ({
20
22
  id,
21
23
  className: userClassName,
22
24
  style,
23
- index
25
+ index,
26
+ handleDeleteSection
24
27
  // ...otherProps
25
28
  }) => {
26
29
  const {
@@ -62,9 +65,17 @@ const Section = ({
62
65
  id: id,
63
66
  className: [baseClassName, componentClassName, userClassName].filter(e => e).join(' '),
64
67
  style: style
68
+ }, /*#__PURE__*/React.createElement("div", {
69
+ className: "section-header"
65
70
  }, /*#__PURE__*/React.createElement("p", {
66
71
  className: "h4"
67
- }, index === 0 ? 'Form title' : `Section ${index + 1}`), /*#__PURE__*/React.createElement(TextInput, {
72
+ }, index === 0 ? 'Form title' : `Section ${index + 1}`), index !== 0 && /*#__PURE__*/React.createElement(ActionsContainer, null, /*#__PURE__*/React.createElement("ul", null, /*#__PURE__*/React.createElement("li", {
73
+ className: "option"
74
+ }, /*#__PURE__*/React.createElement("button", {
75
+ type: "button",
76
+ className: "remove-section-cta",
77
+ onClick: handleDeleteSection
78
+ }, "Delete Section"))))), /*#__PURE__*/React.createElement(TextInput, {
68
79
  name: `sections.${index}.title`,
69
80
  placeholder: `Title of the ${index === 0 ? 'form' : 'section'}`
70
81
  }), /*#__PURE__*/React.createElement(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
+
@@ -1,2 +1,3 @@
1
1
  export { Section } from "./Section";
2
- export { InputBuilder } from "./InputBuilder";
2
+ export { InputBuilder } from "./InputBuilder";
3
+ export { ActionsContainer } from "./ActionsContainer";
@@ -49,56 +49,13 @@ $default-margin: 1rem;
49
49
  flex: .4;
50
50
  gap: var(--gap);
51
51
 
52
- > .#{bem.$base}.select-input {
53
- flex: auto;
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
- > form {
65
- /* stylelint-disable selector-max-compound-selectors -- required */
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
  }
@@ -1,8 +1,8 @@
1
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); }
2
2
  /* @pareto-engineering/generator-front 1.1.1-alpha.2 */
3
3
  import * as React from 'react';
4
+ import { useState, useEffect } from 'react';
4
5
  import { Formik, Form } from 'formik';
5
- import { useState } from 'react';
6
6
  import PropTypes from 'prop-types';
7
7
  import styleNames from '@pareto-engineering/bem/exports';
8
8
  import { Button } from "../../../../b";
@@ -13,6 +13,27 @@ import "./styles.scss";
13
13
  import { Section } from "./common";
14
14
  const baseClassName = styleNames.base;
15
15
  const componentClassName = 'renderer';
16
+ const reconstructFormDataWithValues = (formData, values) => {
17
+ const newData = {
18
+ ...formData
19
+ };
20
+ Object.keys(values).forEach(key => {
21
+ const [sectionIdx, inputIdx] = key.match(/\d+/g).map(Number);
22
+ newData.sections[sectionIdx].inputs[inputIdx].value = values[key];
23
+ });
24
+ return newData;
25
+ };
26
+ const validate = values => {
27
+ const errors = {};
28
+ const hasAtLeastOneValue = Object.keys(values).some(valueKey => {
29
+ const inputValue = values[valueKey];
30
+ return inputValue && inputValue !== '';
31
+ });
32
+ if (!hasAtLeastOneValue) {
33
+ errors.message = 'At least one input must have a value';
34
+ }
35
+ return errors;
36
+ };
16
37
 
17
38
  /**
18
39
  * This is the component description.
@@ -22,28 +43,36 @@ const Renderer = ({
22
43
  className: userClassName,
23
44
  style,
24
45
  formData,
25
- onSave
46
+ readOnly,
47
+ onSave,
48
+ onError,
49
+ shouldSubmit
26
50
  // ...otherProps
27
51
  }) => {
28
52
  const [currentSectionIndex, setCurrentSectionIndex] = useState(0);
29
53
  const [sectionHistory, setSectionHistory] = useState([]);
30
- const initialValues = formData.sections.reduce((acc, section) => {
31
- section.inputs.forEach(input => {
32
- acc[input.name] = '';
54
+ const [updatedFormData, setUpdatedFormData] = useState(formData);
55
+ useEffect(() => {
56
+ setUpdatedFormData(formData);
57
+ }, [formData]);
58
+ const initialValues = formData.sections.reduce((acc, section, sectionIndex) => {
59
+ section.inputs.forEach((input, inputIndex) => {
60
+ const inputName = `section_${sectionIndex}_input_${inputIndex}`;
61
+ acc[inputName] = input.value || '';
33
62
  });
34
63
  return acc;
35
64
  }, {});
36
65
  const handleSubmit = values => {
37
- const currentSection = formData.sections[currentSectionIndex];
66
+ const currentSection = updatedFormData.sections[currentSectionIndex];
38
67
  // by default, 'next' section is the immediate section after the current one
39
68
  let nextSectionIndex = currentSectionIndex + 1;
40
69
 
41
70
  // Any other value is either submit or an index to a section
42
71
  if (currentSection.navigation.nextSection !== 'next') {
43
- nextSectionIndex = currentSection.navigation.nextSection === 'submit' ? formData.sections.length // submit
72
+ nextSectionIndex = currentSection.navigation.nextSection === 'submit' ? updatedFormData.sections.length // submit
44
73
  : parseInt(currentSection.navigation.nextSection, 10); // go to specific section
45
74
  }
46
- if (nextSectionIndex >= formData.sections.length) {
75
+ if (nextSectionIndex >= updatedFormData.sections.length) {
47
76
  // submit
48
77
  onSave(values);
49
78
  } else {
@@ -62,28 +91,49 @@ const Renderer = ({
62
91
  setSectionHistory([...sectionHistory]);
63
92
  }
64
93
  };
94
+ const isSubmit = currentSectionIndex === updatedFormData.sections.length - 1 || updatedFormData.sections[currentSectionIndex].navigation.nextSection === 'submit';
65
95
  return /*#__PURE__*/React.createElement("div", {
66
96
  id: id,
67
97
  className: [baseClassName, componentClassName, userClassName].filter(e => e).join(' '),
68
98
  style: style
69
99
  }, /*#__PURE__*/React.createElement(Formik, {
70
100
  initialValues: initialValues,
71
- onSubmit: handleSubmit
72
- }, /*#__PURE__*/React.createElement(Form, null, formData.sections.map((section, sectionIndex) => sectionIndex === currentSectionIndex && /*#__PURE__*/React.createElement(Section, _extends({
73
- key: `${section.title}`
74
- }, section))), /*#__PURE__*/React.createElement("div", {
75
- className: "navigator-container"
76
- }, /*#__PURE__*/React.createElement(Button, {
77
- color: "interactive",
78
- isGradient: true,
79
- isGhost: true,
80
- onClick: handlePrevious,
81
- disabled: sectionHistory.length === 0
82
- }, "Previous"), /*#__PURE__*/React.createElement(Button, {
83
- color: "interactive",
84
- isGradient: true,
85
- type: "submit"
86
- }, formData.sections[currentSectionIndex].navigation.nextSection === 'submit' ? 'Submit' : 'Next')))));
101
+ onSubmit: handleSubmit,
102
+ validate: validate
103
+ }, ({
104
+ values,
105
+ errors
106
+ }) => {
107
+ useEffect(() => {
108
+ const formDataWithValues = reconstructFormDataWithValues(updatedFormData, values);
109
+ setUpdatedFormData(formDataWithValues);
110
+ onSave?.(formDataWithValues);
111
+ }, [values]);
112
+ useEffect(() => {
113
+ onError?.({
114
+ errors,
115
+ values
116
+ });
117
+ }, [errors, values]);
118
+ return /*#__PURE__*/React.createElement(Form, null, updatedFormData.sections.map((section, sectionIndex) => sectionIndex === currentSectionIndex && /*#__PURE__*/React.createElement(Section, _extends({
119
+ key: `${section.title}`
120
+ }, section, {
121
+ readOnly: readOnly
122
+ }))), /*#__PURE__*/React.createElement("div", {
123
+ className: "navigator-container"
124
+ }, /*#__PURE__*/React.createElement(Button, {
125
+ color: "interactive",
126
+ isGradient: true,
127
+ isCompact: true,
128
+ isGhost: true,
129
+ onClick: handlePrevious,
130
+ disabled: sectionHistory.length === 0
131
+ }, "Previous"), (!isSubmit || shouldSubmit) && /*#__PURE__*/React.createElement(Button, {
132
+ color: "interactive",
133
+ isGradient: true,
134
+ type: "submit"
135
+ }, isSubmit ? 'Submit' : 'Next')));
136
+ }));
87
137
  };
88
138
  Renderer.propTypes = {
89
139
  /**
@@ -97,17 +147,9 @@ Renderer.propTypes = {
97
147
  /**
98
148
  * The React-written, css properties for this element.
99
149
  */
100
- style: PropTypes.objectOf(PropTypes.string),
101
- /**
102
- * The children JSX
103
- */
104
- formData: PropTypes.shape({
105
- formTitle: PropTypes.string.isRequired,
106
- formDescription: PropTypes.string.isRequired,
107
- sections: PropTypes.arrayOf(PropTypes.objectOf(PropTypes.any))
108
- })
150
+ style: PropTypes.objectOf(PropTypes.string)
109
151
  };
110
152
  Renderer.defaultProps = {
111
- // someProp:false
153
+ // someProp: false,
112
154
  };
113
155
  export default Renderer;
@@ -20,18 +20,23 @@ const Section = ({
20
20
  style,
21
21
  title,
22
22
  description,
23
- inputs
23
+ inputs,
24
+ readOnly
24
25
  // ...otherProps
25
26
  }) => /*#__PURE__*/React.createElement("div", {
26
27
  id: id,
27
28
  className: [baseClassName, componentClassName, userClassName].filter(e => e).join(' '),
28
29
  style: style
29
- }, /*#__PURE__*/React.createElement("h3", null, title), /*#__PURE__*/React.createElement(ExpandableLexicalPreview, {
30
+ }, /*#__PURE__*/React.createElement("p", {
31
+ className: "h3"
32
+ }, title), /*#__PURE__*/React.createElement(ExpandableLexicalPreview, {
30
33
  nodes: description,
31
34
  name: "instructions"
32
35
  }), inputs.map(input => /*#__PURE__*/React.createElement(FormInput, _extends({
33
36
  key: input.name
34
- }, input))));
37
+ }, input, {
38
+ disabled: readOnly
39
+ }))));
35
40
  Section.propTypes = {
36
41
  /**
37
42
  * The HTML id for this element
@@ -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
- margin-top: $default-margin;
23
+ justify-content: space-between;
13
24
  }
14
25
  }
15
26
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pareto-engineering/design-system",
3
- "version": "4.2.0",
3
+ "version": "4.2.1-alpha.0",
4
4
  "description": "",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/es/index.js",
@@ -59,7 +59,7 @@
59
59
  "@lexical/selection": "0.12.2",
60
60
  "@lexical/table": "0.12.2",
61
61
  "@lexical/utils": "0.12.2",
62
- "@pareto-engineering/assets": "^4.1.0",
62
+ "@pareto-engineering/assets": "^4.2.1-alpha.0",
63
63
  "@pareto-engineering/bem": "^4.0.0",
64
64
  "@pareto-engineering/styles": "^4.2.0",
65
65
  "@pareto-engineering/utils": "^4.0.0",
@@ -82,5 +82,5 @@
82
82
  "relay-test-utils": "^15.0.0"
83
83
  },
84
84
  "browserslist": "> 2%",
85
- "gitHead": "7b24b23f9f4b091e2046d21bc0984cf7b7e6c0da"
85
+ "gitHead": "959e968b733eab6cfef5dca5f8239084afbe2652"
86
86
  }