@pareto-engineering/design-system 4.2.0 → 4.2.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 (63) hide show
  1. package/dist/cjs/a/XMLEditor/XMLEditor.js +3 -15
  2. package/dist/cjs/f/fields/EditorInput/EditorInput.js +6 -21
  3. package/dist/cjs/f/fields/EditorInput/common/StopPropagationPlugin.js +2 -7
  4. package/dist/cjs/f/fields/SelectInput/common/Menu/Menu.js +1 -1
  5. package/dist/cjs/f/fields/SelectInput/common/Multiple/Multiple.js +1 -1
  6. package/dist/cjs/f/fields/SelectInput/styles.scss +1 -1
  7. package/dist/cjs/g/FormBuilder/FormBuilder.js +38 -5
  8. package/dist/cjs/g/FormBuilder/common/Builder/Builder.js +62 -25
  9. package/dist/cjs/g/FormBuilder/common/Builder/common/ActionsContainer/ActionsContainer.js +80 -0
  10. package/dist/cjs/g/FormBuilder/common/Builder/common/ActionsContainer/index.js +13 -0
  11. package/dist/cjs/g/FormBuilder/common/Builder/common/ActionsContainer/styles.scss +59 -0
  12. package/dist/cjs/g/FormBuilder/common/Builder/common/InputBuilder/InputBuilder.js +19 -45
  13. package/dist/cjs/g/FormBuilder/common/Builder/common/InputBuilder/styles.scss +0 -49
  14. package/dist/cjs/g/FormBuilder/common/Builder/common/Section/Section.js +14 -3
  15. package/dist/cjs/g/FormBuilder/common/Builder/common/Section/styles.scss +61 -0
  16. package/dist/cjs/g/FormBuilder/common/Builder/common/index.js +8 -1
  17. package/dist/cjs/g/FormBuilder/common/Builder/styles.scss +5 -48
  18. package/dist/cjs/g/FormBuilder/common/Renderer/Renderer.js +76 -33
  19. package/dist/cjs/g/FormBuilder/common/Renderer/common/Section/Section.js +8 -3
  20. package/dist/cjs/g/FormBuilder/common/Renderer/styles.scss +12 -1
  21. package/dist/es/a/XMLEditor/XMLEditor.js +3 -15
  22. package/dist/es/f/fields/EditorInput/EditorInput.js +7 -22
  23. package/dist/es/f/fields/EditorInput/common/StopPropagationPlugin.js +2 -6
  24. package/dist/es/f/fields/SelectInput/common/Menu/Menu.js +1 -1
  25. package/dist/es/f/fields/SelectInput/common/Multiple/Multiple.js +1 -1
  26. package/dist/es/f/fields/SelectInput/styles.scss +1 -1
  27. package/dist/es/g/FormBuilder/FormBuilder.js +38 -5
  28. package/dist/es/g/FormBuilder/common/Builder/Builder.js +56 -20
  29. package/dist/es/g/FormBuilder/common/Builder/common/ActionsContainer/ActionsContainer.js +70 -0
  30. package/dist/es/g/FormBuilder/common/Builder/common/ActionsContainer/index.js +2 -0
  31. package/dist/es/g/FormBuilder/common/Builder/common/ActionsContainer/styles.scss +59 -0
  32. package/dist/es/g/FormBuilder/common/Builder/common/InputBuilder/InputBuilder.js +21 -47
  33. package/dist/es/g/FormBuilder/common/Builder/common/InputBuilder/styles.scss +0 -49
  34. package/dist/es/g/FormBuilder/common/Builder/common/Section/Section.js +14 -3
  35. package/dist/es/g/FormBuilder/common/Builder/common/Section/styles.scss +61 -0
  36. package/dist/es/g/FormBuilder/common/Builder/common/index.js +2 -1
  37. package/dist/es/g/FormBuilder/common/Builder/styles.scss +5 -48
  38. package/dist/es/g/FormBuilder/common/Renderer/Renderer.js +76 -34
  39. package/dist/es/g/FormBuilder/common/Renderer/common/Section/Section.js +8 -3
  40. package/dist/es/g/FormBuilder/common/Renderer/styles.scss +12 -1
  41. package/package.json +4 -4
  42. package/src/stories/g/FormBuilder.stories.jsx +116 -21
  43. package/src/ui/a/XMLEditor/XMLEditor.jsx +1 -15
  44. package/src/ui/f/fields/EditorInput/EditorInput.jsx +7 -23
  45. package/src/ui/f/fields/EditorInput/common/StopPropagationPlugin.jsx +2 -6
  46. package/src/ui/f/fields/SelectInput/common/Menu/Menu.jsx +1 -0
  47. package/src/ui/f/fields/SelectInput/common/Multiple/Multiple.jsx +1 -1
  48. package/src/ui/f/fields/SelectInput/styles.scss +1 -1
  49. package/src/ui/g/FormBuilder/FormBuilder.jsx +50 -3
  50. package/src/ui/g/FormBuilder/common/Builder/Builder.jsx +56 -18
  51. package/src/ui/g/FormBuilder/common/Builder/common/ActionsContainer/ActionsContainer.jsx +97 -0
  52. package/src/ui/g/FormBuilder/common/Builder/common/ActionsContainer/index.js +2 -0
  53. package/src/ui/g/FormBuilder/common/Builder/common/ActionsContainer/styles.scss +59 -0
  54. package/src/ui/g/FormBuilder/common/Builder/common/InputBuilder/InputBuilder.jsx +40 -60
  55. package/src/ui/g/FormBuilder/common/Builder/common/InputBuilder/styles.scss +0 -49
  56. package/src/ui/g/FormBuilder/common/Builder/common/Section/Section.jsx +26 -4
  57. package/src/ui/g/FormBuilder/common/Builder/common/Section/styles.scss +61 -0
  58. package/src/ui/g/FormBuilder/common/Builder/common/index.js +1 -0
  59. package/src/ui/g/FormBuilder/common/Builder/styles.scss +5 -48
  60. package/src/ui/g/FormBuilder/common/Renderer/Renderer.jsx +84 -33
  61. package/src/ui/g/FormBuilder/common/Renderer/common/Section/Section.jsx +3 -2
  62. package/src/ui/g/FormBuilder/common/Renderer/styles.scss +12 -1
  63. package/tests/__snapshots__/Storyshots.test.js.snap +395 -133
@@ -24,9 +24,15 @@ const FormBuilder = ({
24
24
  style,
25
25
  mode,
26
26
  formData,
27
+ readOnly,
28
+ shouldSubmit,
27
29
  formBuilderId,
28
30
  onBuilderFormSave,
31
+ onBuilderError,
32
+ onRendererError,
29
33
  onRendererFormSave,
34
+ onBuilderValidate,
35
+ initialBuilderValues,
30
36
  // ...otherProps
31
37
  }) => (
32
38
  <div
@@ -43,8 +49,24 @@ const FormBuilder = ({
43
49
  style={style}
44
50
  // {...otherProps}
45
51
  >
46
- {mode === 'build' && <Builder formBuilderId={formBuilderId} onSave={onBuilderFormSave} />}
47
- {mode === 'render' && <Renderer formData={formData} onSave={onRendererFormSave} />}
52
+ {mode === 'build' && (
53
+ <Builder
54
+ initialValues={initialBuilderValues}
55
+ formBuilderId={formBuilderId}
56
+ onSave={onBuilderFormSave}
57
+ onError={onBuilderError}
58
+ validate={onBuilderValidate}
59
+ />
60
+ )}
61
+ {mode === 'render' && (
62
+ <Renderer
63
+ formData={formData}
64
+ onSave={onRendererFormSave}
65
+ readOnly={readOnly}
66
+ shouldSubmit={shouldSubmit}
67
+ onError={onRendererError}
68
+ />
69
+ )}
48
70
  </div>
49
71
  )
50
72
 
@@ -73,10 +95,35 @@ FormBuilder.propTypes = {
73
95
  * This is the ID of the form element in the <Builder /> component
74
96
  */
75
97
  formBuilderId:PropTypes.string.isRequired,
98
+
99
+ /**
100
+ * The form data to be used to construct the form builder in renderer mode
101
+ */
102
+ formData:PropTypes.shape({
103
+ sections:PropTypes.arrayOf(PropTypes.objectOf(PropTypes.any)),
104
+ }),
105
+
106
+ /**
107
+ * The initial values to instatiate form builder in builder mode
108
+ */
109
+ initialBuilderValues:PropTypes.shape({
110
+ sections:PropTypes.arrayOf(PropTypes.objectOf(PropTypes.any)),
111
+ }),
112
+
113
+ /**
114
+ * Whether the whole Form in renderer mode should be readOnly
115
+ */
116
+ readOnly:PropTypes.bool,
117
+
118
+ /**
119
+ * Whether the form builder in renderer mode should submit the form values itself
120
+ */
121
+ shouldSubmit:PropTypes.bool,
76
122
  }
77
123
 
78
124
  FormBuilder.defaultProps = {
79
- mode:'build',
125
+ mode :'build',
126
+ readOnly:false,
80
127
  }
81
128
 
82
129
  FormBuilder.Builder = Builder
@@ -1,6 +1,8 @@
1
1
  /* @pareto-engineering/generator-front 1.1.1-alpha.2 */
2
2
  import * as React from 'react'
3
3
 
4
+ import { useEffect } from 'react'
5
+
4
6
  import { Formik, Form, FieldArray } from 'formik'
5
7
 
6
8
  import PropTypes from 'prop-types'
@@ -38,12 +40,43 @@ const Builder = ({
38
40
  className:userClassName,
39
41
  style,
40
42
  onSave,
43
+ onError,
44
+ validate,
41
45
  formBuilderId,
46
+ initialValues = {},
42
47
  // ...otherProps
43
48
  }) => {
44
49
  const handleSubmit = (values) => {
45
50
  const reOrderedValues = reorderInputs(values)
46
- onSave(reOrderedValues)
51
+ onSave?.(reOrderedValues)
52
+ }
53
+
54
+ const initialFormState = initialValues?.sections
55
+ ? initialValues
56
+ : {
57
+ sections:[
58
+ {
59
+ title :'',
60
+ description :'',
61
+ key :'section-0',
62
+ inputs :[],
63
+ orderedInputDragIds:[],
64
+ navigation :{ nextSection: 'next' },
65
+ },
66
+ ],
67
+ }
68
+
69
+ const handleDeleteSection = ({ index, remove, values }) => {
70
+ remove(index)
71
+
72
+ values.sections.splice(index, 1)
73
+
74
+ values.sections.forEach((section, sectionIndex) => {
75
+ section.inputs.forEach((input, inputIndex) => {
76
+ // eslint-disable-next-line no-param-reassign
77
+ input.name = `section_${sectionIndex}_input_${inputIndex}`
78
+ })
79
+ })
47
80
  }
48
81
 
49
82
  return (
@@ -61,22 +94,21 @@ const Builder = ({
61
94
 
62
95
  <p className="h3">Form Builder</p>
63
96
  <Formik
64
- initialValues={{
65
- sections:[
66
- {
67
- title :'',
68
- description :'',
69
- key :'section-0',
70
- inputs :[],
71
- orderedInputDragIds:[],
72
- navigation :{ nextSection: 'next' },
73
- },
74
- ],
75
- }}
97
+ initialValues={initialFormState}
76
98
  onSubmit={handleSubmit}
99
+ validate={validate}
77
100
  >
78
- {({ values }) => {
79
- const availableSections = values.sections.map((section, idx) => ({
101
+ {({ values, errors, setFieldValue }) => {
102
+ useEffect(() => {
103
+ const reOrderedValues = reorderInputs(values)
104
+ onSave?.(reOrderedValues)
105
+ }, [values])
106
+
107
+ useEffect(() => {
108
+ onError?.(errors)
109
+ }, [errors, values])
110
+
111
+ const availableSections = values?.sections?.map((section, idx) => ({
80
112
  value:idx,
81
113
  label:`Go to ${section.title || `Untitled Section ${idx + 1}`}`,
82
114
  }))
@@ -84,10 +116,16 @@ const Builder = ({
84
116
  return (
85
117
  <Form id={formBuilderId}>
86
118
  <FieldArray name="sections">
87
- {({ push }) => (
119
+ {({ push, remove }) => (
88
120
  <>
89
- {values.sections.map((section, index) => (
90
- <Section key={section.key} index={index} />
121
+ {values?.sections?.map((section, index) => (
122
+ <Section
123
+ key={section.key}
124
+ index={index}
125
+ handleDeleteSection={() => handleDeleteSection({
126
+ index, remove, values, setFieldValue,
127
+ })}
128
+ />
91
129
  ))}
92
130
  <div className="section-footer">
93
131
  <button
@@ -0,0 +1,97 @@
1
+ /* @pareto-engineering/generator-front 1.1.1-alpha.2 */
2
+ import * as React from 'react'
3
+
4
+ import { useState, useRef } from 'react'
5
+
6
+ import PropTypes from 'prop-types'
7
+
8
+ import styleNames from '@pareto-engineering/bem/exports'
9
+
10
+ import './styles.scss'
11
+
12
+ // Local Definitions
13
+
14
+ import { useOutsideClick } from 'ui/utils'
15
+
16
+ import { Popover } from 'ui/a'
17
+
18
+ const baseClassName = styleNames.base
19
+
20
+ const componentClassName = 'actions-container'
21
+
22
+ /**
23
+ * This is the component description.
24
+ */
25
+ const ActionsContainer = ({
26
+ id,
27
+ className:userClassName,
28
+ style,
29
+ preferredPopoverOrder,
30
+ children,
31
+ // ...otherProps
32
+ }) => {
33
+ const parentRef = useRef(null)
34
+ const [isOpen, setIsOpen] = useState(false)
35
+ useOutsideClick(parentRef, () => setIsOpen(false))
36
+
37
+ return (
38
+ <div
39
+ id={id}
40
+ className={[
41
+
42
+ baseClassName,
43
+
44
+ componentClassName,
45
+ userClassName,
46
+ ]
47
+ .filter((e) => e)
48
+ .join(' ')}
49
+ style={style}
50
+ ref={parentRef}
51
+ >
52
+ <button type="button" onClick={() => setIsOpen(!isOpen)}>
53
+ <span className="icon x-ui-icons c-x">!</span>
54
+ </button>
55
+ <Popover
56
+ isOpen={isOpen}
57
+ parentRef={parentRef}
58
+ preferredPrimaryOrder={preferredPopoverOrder}
59
+ >
60
+ {children}
61
+ </Popover>
62
+ </div>
63
+ )
64
+ }
65
+
66
+ ActionsContainer.propTypes = {
67
+ /**
68
+ * The HTML id for this element
69
+ */
70
+ id:PropTypes.string,
71
+
72
+ /**
73
+ * The HTML class names for this element
74
+ */
75
+ className:PropTypes.string,
76
+
77
+ /**
78
+ * The React-written, css properties for this element.
79
+ */
80
+ style:PropTypes.objectOf(PropTypes.string),
81
+
82
+ /**
83
+ * The preferred order for the popover
84
+ */
85
+ preferredPopoverOrder:PropTypes.arrayOf(PropTypes.string),
86
+
87
+ /**
88
+ * The children of the actions container
89
+ */
90
+ children:PropTypes.node,
91
+ }
92
+
93
+ ActionsContainer.defaultProps = {
94
+ preferredPopoverOrder:['right', 'bottom', 'left', 'top'],
95
+ }
96
+
97
+ export default ActionsContainer
@@ -0,0 +1,2 @@
1
+ /* @pareto-engineering/generator-front 1.1.1-alpha.2 */
2
+ export { default as ActionsContainer } from './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
+
@@ -1,7 +1,7 @@
1
1
  /* @pareto-engineering/generator-front 1.1.1-alpha.2 */
2
2
  import * as React from 'react'
3
3
 
4
- import { useState, useRef } from 'react'
4
+ import { useState } from 'react'
5
5
 
6
6
  import PropTypes from 'prop-types'
7
7
 
@@ -11,14 +11,14 @@ import styleNames from '@pareto-engineering/bem/exports'
11
11
 
12
12
  import { SelectInput, TextInput } from 'ui/f'
13
13
 
14
- import { ToggleSwitch, Popover } from 'ui/a'
15
-
16
- import { useOutsideClick } from 'ui/utils'
14
+ import { ToggleSwitch } from 'ui/a'
17
15
 
18
16
  import './styles.scss'
19
17
 
20
18
  // Local Definitions
21
19
 
20
+ import { ActionsContainer } from '../ActionsContainer'
21
+
22
22
  const baseClassName = styleNames.base
23
23
 
24
24
  const componentClassName = 'input-builder'
@@ -34,14 +34,13 @@ const InputBuilder = ({
34
34
  inputIndex,
35
35
  onDelete,
36
36
  // onCopy,
37
- preferredPopoverOrder,
38
37
  // ...otherProps
39
38
  }) => {
40
39
  const { values, setFieldValue } = useFormikContext()
41
- const input = values.sections[sectionIndex].inputs[inputIndex]
40
+ const input = values.sections[sectionIndex]?.inputs[inputIndex]
42
41
 
43
42
  const handleToggleRequired = () => {
44
- setFieldValue(`sections.${sectionIndex}.inputs.${inputIndex}.required`, !input.required)
43
+ setFieldValue(`sections.${sectionIndex}.inputs.${inputIndex}.required`, !input?.required)
45
44
  }
46
45
 
47
46
  const toggleSwitchStyles = {
@@ -53,17 +52,15 @@ const InputBuilder = ({
53
52
  ),
54
53
  }
55
54
 
56
- const parentRef = useRef(null)
57
- const [isOpen, setIsOpen] = useState(false)
58
- useOutsideClick(parentRef, () => setIsOpen(false))
59
-
60
55
  const [hasDescription, setHasDescription] = useState(false)
61
56
 
62
- const handleToggleConditionalNavigation = () => {
63
- setFieldValue(`sections.${sectionIndex}.inputs.${inputIndex}.conditionalNavigation`, !input.conditionalNavigation)
64
- }
57
+ // TODO: handle nav logic
58
+ // const handleToggleConditionalNavigation = () => {
59
+ // setFieldValue(`sections.${sectionIndex}.inputs.${inputIndex}.conditionalNavigation`,
60
+ // !input?.conditionalNavigation)
61
+ // }
65
62
 
66
- const availableSections = values.sections.map((section, idx) => ({
63
+ const availableSections = values?.sections?.map((section, idx) => ({
67
64
  value:idx,
68
65
  label:`Go to ${section.title || `Untitled Section ${idx + 1}`}`,
69
66
  }))
@@ -116,10 +113,6 @@ const InputBuilder = ({
116
113
  value:'select',
117
114
  label:'Dropdown select',
118
115
  },
119
- {
120
- value:'editor',
121
- label:'Editor input',
122
- },
123
116
  {
124
117
  value:'multiple',
125
118
  label:'Checkboxes',
@@ -149,39 +142,32 @@ const InputBuilder = ({
149
142
  inputId={`sections_${sectionIndex}_inputs.${inputIndex}_toggle`}
150
143
  />
151
144
  </div>
152
- <div className="actions" ref={parentRef}>
153
- <button type="button" onClick={() => setIsOpen(!isOpen)}>
154
- <span className="icon x-ui-icons c-x">!</span>
155
- </button>
156
- <Popover
157
- isOpen={isOpen}
158
- parentRef={parentRef}
159
- preferredPrimaryOrder={preferredPopoverOrder}
160
- >
161
- <p>Show</p>
162
- <ul>
163
- <li className={`option ${hasDescription ? 'with-check-mark' : ''}`}>
164
- {hasDescription
145
+ <ActionsContainer>
146
+ <p>Show</p>
147
+ <ul>
148
+ <li className={`option ${hasDescription ? 'with-check-mark' : ''}`}>
149
+ {hasDescription
165
150
  && <span className="x-ui-icons c-x icon">I</span>}
166
- <button
167
- onClick={() => setHasDescription(!hasDescription)}
168
- type="button"
169
- >
170
- Description
171
- </button>
172
- </li>
173
- <li className={`option ${input?.conditionalNavigation ? 'with-check-mark' : ''}`}>
174
- {input?.conditionalNavigation && <span className="x-ui-icons c-x icon">I</span>}
175
- <button
176
- onClick={handleToggleConditionalNavigation}
177
- type="button"
178
- >
179
- Go to section based on answer
180
- </button>
181
- </li>
182
- </ul>
183
- </Popover>
184
- </div>
151
+ <button
152
+ onClick={() => setHasDescription(!hasDescription)}
153
+ type="button"
154
+ >
155
+ Description
156
+ </button>
157
+ </li>
158
+ {/* TODO: implement logic */}
159
+ {/*
160
+ <li className={`option ${input?.conditionalNavigation ? 'with-check-mark' : ''}`}>
161
+ {input?.conditionalNavigation && <span className="x-ui-icons c-x icon">I</span>}
162
+ <button
163
+ onClick={handleToggleConditionalNavigation}
164
+ type="button"
165
+ >
166
+ Go to section based on answer
167
+ </button>
168
+ </li> */}
169
+ </ul>
170
+ </ActionsContainer>
185
171
  </div>
186
172
  </div>
187
173
  <div className="input-name-description">
@@ -205,7 +191,7 @@ const InputBuilder = ({
205
191
  <p>Options</p>
206
192
  {input?.options.map((option, optionIndex) => (
207
193
  <div key={option.key} className="option-container">
208
- {input.type !== 'select' && <div className={`input-icon-sample ${input.type}`} />}
194
+ {input?.type !== 'select' && <div className={`input-icon-sample ${input?.type}`} />}
209
195
 
210
196
  <TextInput
211
197
  name={`sections.${sectionIndex}.inputs.${inputIndex}.options.${optionIndex}.value`}
@@ -228,7 +214,7 @@ const InputBuilder = ({
228
214
  className="add-option-cta"
229
215
  type="button"
230
216
  onClick={() => push({
231
- key :`sections-${sectionIndex}-inputs-${inputIndex}-options-${input.options.length - 1}`,
217
+ key :`sections-${sectionIndex}-inputs-${inputIndex}-options-${input?.options.length - 1}`,
232
218
  value :'',
233
219
  label :'',
234
220
  nextSection:'',
@@ -264,16 +250,10 @@ InputBuilder.propTypes = {
264
250
  * The React-written, css properties for this element.
265
251
  */
266
252
  style:PropTypes.objectOf(PropTypes.string),
267
-
268
- /**
269
- * The preferred primary order of the popover
270
- */
271
- preferredPopoverOrder:PropTypes.arrayOf(PropTypes.string),
272
-
273
253
  }
274
254
 
275
255
  InputBuilder.defaultProps = {
276
- preferredPopoverOrder:['right', 'bottom', 'left', 'top'],
256
+ // some properties
277
257
  }
278
258
 
279
259
  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
 
@@ -19,9 +19,13 @@ import { DragAndDrop } from 'ui/g'
19
19
 
20
20
  import { InputBuilder } from '../InputBuilder'
21
21
 
22
+ import { ActionsContainer } from '../ActionsContainer'
23
+
24
+ import './styles.scss'
25
+
22
26
  const baseClassName = styleNames.base
23
27
 
24
- const componentClassName = 'section'
28
+ const componentClassName = 'builder-section'
25
29
 
26
30
  /**
27
31
  * This is the component description.
@@ -31,6 +35,7 @@ const Section = ({
31
35
  className:userClassName,
32
36
  style,
33
37
  index,
38
+ handleDeleteSection,
34
39
  // ...otherProps
35
40
  }) => {
36
41
  const { values, setFieldValue } = useFormikContext()
@@ -84,9 +89,26 @@ const Section = ({
84
89
  .join(' ')}
85
90
  style={style}
86
91
  >
87
- <p className="h4">
88
- {index === 0 ? 'Form title' : `Section ${index + 1}`}
89
- </p>
92
+ <div className="section-header">
93
+ <p className="h4">
94
+ {index === 0 ? 'Form title' : `Section ${index + 1}`}
95
+ </p>
96
+ {index !== 0 && (
97
+ <ActionsContainer>
98
+ <ul>
99
+ <li className="option">
100
+ <button
101
+ type="button"
102
+ className="remove-section-cta"
103
+ onClick={handleDeleteSection}
104
+ >
105
+ Delete Section
106
+ </button>
107
+ </li>
108
+ </ul>
109
+ </ActionsContainer>
110
+ )}
111
+ </div>
90
112
  <TextInput
91
113
  name={`sections.${index}.title`}
92
114
  placeholder={`Title of the ${index === 0 ? 'form' : 'section'}`}
@@ -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
+