@pareto-engineering/design-system 4.0.0 → 4.1.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/a/ToggleSwitch/ToggleSwitch.js +10 -5
- package/dist/cjs/f/FormInput/FormInput.js +7 -0
- package/dist/cjs/f/fields/EditorInput/EditorInput.js +9 -7
- package/dist/cjs/f/fields/SelectInput/SelectInput.js +4 -5
- package/dist/cjs/f/fields/SelectInput/common/Single/Single.js +3 -3
- package/dist/cjs/g/FormBuilder/FormBuilder.js +77 -0
- package/dist/cjs/g/FormBuilder/common/Builder/Builder.js +156 -0
- package/dist/cjs/g/FormBuilder/common/Builder/common/InputBuilder/InputBuilder.js +229 -0
- package/dist/cjs/g/FormBuilder/common/Builder/common/InputBuilder/index.js +13 -0
- package/dist/cjs/g/FormBuilder/common/Builder/common/InputBuilder/styles.scss +192 -0
- package/dist/cjs/g/FormBuilder/common/Builder/common/Section/Section.js +133 -0
- package/dist/cjs/g/FormBuilder/common/Builder/common/Section/index.js +13 -0
- package/dist/cjs/g/FormBuilder/common/Builder/common/index.js +19 -0
- package/dist/cjs/g/FormBuilder/common/Builder/index.js +13 -0
- package/dist/cjs/g/FormBuilder/common/Builder/styles.scss +106 -0
- package/dist/cjs/g/FormBuilder/common/Renderer/Renderer.js +119 -0
- package/dist/cjs/g/FormBuilder/common/Renderer/common/Section/Section.js +60 -0
- package/dist/cjs/g/FormBuilder/common/Renderer/common/Section/index.js +13 -0
- package/dist/cjs/g/FormBuilder/common/Renderer/common/index.js +12 -0
- package/dist/cjs/g/FormBuilder/common/Renderer/index.js +13 -0
- package/dist/cjs/g/FormBuilder/common/Renderer/styles.scss +15 -0
- package/dist/cjs/g/FormBuilder/common/index.js +19 -0
- package/dist/cjs/g/FormBuilder/index.js +13 -0
- package/dist/cjs/g/FormBuilder/styles.scss +7 -0
- package/dist/cjs/g/index.js +8 -1
- package/dist/es/a/ToggleSwitch/ToggleSwitch.js +10 -5
- package/dist/es/f/FormInput/FormInput.js +7 -0
- package/dist/es/f/fields/EditorInput/EditorInput.js +9 -7
- package/dist/es/f/fields/SelectInput/SelectInput.js +4 -3
- package/dist/es/f/fields/SelectInput/common/Single/Single.js +3 -3
- package/dist/es/g/FormBuilder/FormBuilder.js +65 -0
- package/dist/es/g/FormBuilder/common/Builder/Builder.js +142 -0
- package/dist/es/g/FormBuilder/common/Builder/common/InputBuilder/InputBuilder.js +216 -0
- package/dist/es/g/FormBuilder/common/Builder/common/InputBuilder/index.js +2 -0
- package/dist/es/g/FormBuilder/common/Builder/common/InputBuilder/styles.scss +192 -0
- package/dist/es/g/FormBuilder/common/Builder/common/Section/Section.js +120 -0
- package/dist/es/g/FormBuilder/common/Builder/common/Section/index.js +2 -0
- package/dist/es/g/FormBuilder/common/Builder/common/index.js +2 -0
- package/dist/es/g/FormBuilder/common/Builder/index.js +2 -0
- package/dist/es/g/FormBuilder/common/Builder/styles.scss +106 -0
- package/dist/es/g/FormBuilder/common/Renderer/Renderer.js +113 -0
- package/dist/es/g/FormBuilder/common/Renderer/common/Section/Section.js +52 -0
- package/dist/es/g/FormBuilder/common/Renderer/common/Section/index.js +2 -0
- package/dist/es/g/FormBuilder/common/Renderer/common/index.js +1 -0
- package/dist/es/g/FormBuilder/common/Renderer/index.js +2 -0
- package/dist/es/g/FormBuilder/common/Renderer/styles.scss +15 -0
- package/dist/es/g/FormBuilder/common/index.js +2 -0
- package/dist/es/g/FormBuilder/index.js +2 -0
- package/dist/es/g/FormBuilder/styles.scss +7 -0
- package/dist/es/g/index.js +2 -1
- package/package.json +3 -3
- package/src/stories/a/ToggleSwitch.stories.jsx +8 -2
- package/src/stories/g/FormBuilder.stories.jsx +97 -0
- package/src/ui/a/ToggleSwitch/ToggleSwitch.jsx +9 -3
- package/src/ui/f/FormInput/FormInput.jsx +10 -0
- package/src/ui/f/fields/EditorInput/EditorInput.jsx +5 -6
- package/src/ui/f/fields/SelectInput/SelectInput.jsx +5 -2
- package/src/ui/f/fields/SelectInput/common/Single/Single.jsx +2 -1
- package/src/ui/g/FormBuilder/FormBuilder.jsx +85 -0
- package/src/ui/g/FormBuilder/common/Builder/Builder.jsx +175 -0
- package/src/ui/g/FormBuilder/common/Builder/common/InputBuilder/InputBuilder.jsx +279 -0
- package/src/ui/g/FormBuilder/common/Builder/common/InputBuilder/index.js +2 -0
- package/src/ui/g/FormBuilder/common/Builder/common/InputBuilder/styles.scss +192 -0
- package/src/ui/g/FormBuilder/common/Builder/common/Section/Section.jsx +156 -0
- package/src/ui/g/FormBuilder/common/Builder/common/Section/index.js +2 -0
- package/src/ui/g/FormBuilder/common/Builder/common/index.js +2 -0
- package/src/ui/g/FormBuilder/common/Builder/index.js +2 -0
- package/src/ui/g/FormBuilder/common/Builder/styles.scss +106 -0
- package/src/ui/g/FormBuilder/common/Renderer/Renderer.jsx +145 -0
- package/src/ui/g/FormBuilder/common/Renderer/common/Section/Section.jsx +75 -0
- package/src/ui/g/FormBuilder/common/Renderer/common/Section/index.js +2 -0
- package/src/ui/g/FormBuilder/common/Renderer/common/index.js +1 -0
- package/src/ui/g/FormBuilder/common/Renderer/index.js +2 -0
- package/src/ui/g/FormBuilder/common/Renderer/styles.scss +15 -0
- package/src/ui/g/FormBuilder/common/index.js +2 -0
- package/src/ui/g/FormBuilder/index.js +2 -0
- package/src/ui/g/FormBuilder/styles.scss +7 -0
- package/src/ui/g/index.js +1 -0
- package/tests/__snapshots__/Storyshots.test.js.snap +793 -1
|
@@ -0,0 +1,279 @@
|
|
|
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 { FieldArray, useFormikContext } from 'formik'
|
|
9
|
+
|
|
10
|
+
import styleNames from '@pareto-engineering/bem/exports'
|
|
11
|
+
|
|
12
|
+
import { SelectInput, TextInput } from 'ui/f'
|
|
13
|
+
|
|
14
|
+
import { ToggleSwitch, Popover } from 'ui/a'
|
|
15
|
+
|
|
16
|
+
import { useOutsideClick } from 'ui/utils'
|
|
17
|
+
|
|
18
|
+
import './styles.scss'
|
|
19
|
+
|
|
20
|
+
// Local Definitions
|
|
21
|
+
|
|
22
|
+
const baseClassName = styleNames.base
|
|
23
|
+
|
|
24
|
+
const componentClassName = 'input-builder'
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* This is the component description.
|
|
28
|
+
*/
|
|
29
|
+
const InputBuilder = ({
|
|
30
|
+
id,
|
|
31
|
+
className:userClassName,
|
|
32
|
+
style,
|
|
33
|
+
sectionIndex,
|
|
34
|
+
inputIndex,
|
|
35
|
+
onDelete,
|
|
36
|
+
// onCopy,
|
|
37
|
+
preferredPopoverOrder,
|
|
38
|
+
// ...otherProps
|
|
39
|
+
}) => {
|
|
40
|
+
const { values, setFieldValue } = useFormikContext()
|
|
41
|
+
const input = values.sections[sectionIndex].inputs[inputIndex]
|
|
42
|
+
|
|
43
|
+
const handleToggleRequired = () => {
|
|
44
|
+
setFieldValue(`sections.${sectionIndex}.inputs.${inputIndex}.required`, !input.required)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const toggleSwitchStyles = {
|
|
48
|
+
...(!input?.required
|
|
49
|
+
? {
|
|
50
|
+
'--slider-background-color':'var(--disabled)',
|
|
51
|
+
}
|
|
52
|
+
: {}
|
|
53
|
+
),
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const parentRef = useRef(null)
|
|
57
|
+
const [isOpen, setIsOpen] = useState(false)
|
|
58
|
+
useOutsideClick(parentRef, () => setIsOpen(false))
|
|
59
|
+
|
|
60
|
+
const [hasDescription, setHasDescription] = useState(false)
|
|
61
|
+
|
|
62
|
+
const handleToggleConditionalNavigation = () => {
|
|
63
|
+
setFieldValue(`sections.${sectionIndex}.inputs.${inputIndex}.conditionalNavigation`, !input.conditionalNavigation)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const availableSections = values.sections.map((section, idx) => ({
|
|
67
|
+
value:idx,
|
|
68
|
+
label:`Go to ${section.title || `Untitled Section ${idx + 1}`}`,
|
|
69
|
+
}))
|
|
70
|
+
|
|
71
|
+
const shouldRenderOptions = input?.type === 'select' || input?.type === 'multiple' || input?.type === 'choices'
|
|
72
|
+
|
|
73
|
+
const handleSelectOptionBlur = (e, optionIndex) => {
|
|
74
|
+
const { value } = e.target
|
|
75
|
+
setFieldValue(`sections.${sectionIndex}.inputs.${inputIndex}.options.${optionIndex}.label`, value)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
<div
|
|
80
|
+
id={id}
|
|
81
|
+
className={[
|
|
82
|
+
|
|
83
|
+
baseClassName,
|
|
84
|
+
|
|
85
|
+
componentClassName,
|
|
86
|
+
userClassName,
|
|
87
|
+
]
|
|
88
|
+
.filter((e) => e)
|
|
89
|
+
.join(' ')}
|
|
90
|
+
style={style}
|
|
91
|
+
>
|
|
92
|
+
<div className="drag-icon">
|
|
93
|
+
<span className="ai-icon">
|
|
94
|
+
H
|
|
95
|
+
</span>
|
|
96
|
+
</div>
|
|
97
|
+
<div className="input-options-container">
|
|
98
|
+
<div className="controls-container">
|
|
99
|
+
<SelectInput
|
|
100
|
+
name={`sections.${sectionIndex}.inputs.${inputIndex}.type`}
|
|
101
|
+
options={[
|
|
102
|
+
{
|
|
103
|
+
value :'',
|
|
104
|
+
label :'Select an option',
|
|
105
|
+
disabled:true,
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
value:'text',
|
|
109
|
+
label:'Basic input',
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
value:'textarea',
|
|
113
|
+
label:'Long paragraph',
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
value:'select',
|
|
117
|
+
label:'Dropdown select',
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
value:'editor',
|
|
121
|
+
label:'Editor input',
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
value:'multiple',
|
|
125
|
+
label:'Checkboxes',
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
value:'choices',
|
|
129
|
+
label:'Radio buttons',
|
|
130
|
+
},
|
|
131
|
+
]}
|
|
132
|
+
/>
|
|
133
|
+
<div className="controls">
|
|
134
|
+
{/* TODO */}
|
|
135
|
+
{/* <button type="button" onClick={() => onCopy(inputIndex)}>
|
|
136
|
+
<span className="ai-icon x-ui-icons c-x">I</span>
|
|
137
|
+
</button> */}
|
|
138
|
+
<button type="button" onClick={() => onDelete(inputIndex)}>
|
|
139
|
+
<span className="icon x-ui-icons c-x">D</span>
|
|
140
|
+
</button>
|
|
141
|
+
<div className="is-required">
|
|
142
|
+
<span className="s0">
|
|
143
|
+
Required
|
|
144
|
+
</span>
|
|
145
|
+
<ToggleSwitch
|
|
146
|
+
handleOnChange={handleToggleRequired}
|
|
147
|
+
checked={input?.required}
|
|
148
|
+
style={toggleSwitchStyles}
|
|
149
|
+
inputId={`sections_${sectionIndex}_inputs.${inputIndex}_toggle`}
|
|
150
|
+
/>
|
|
151
|
+
</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
|
|
165
|
+
&& <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>
|
|
185
|
+
</div>
|
|
186
|
+
</div>
|
|
187
|
+
<div className="input-name-description">
|
|
188
|
+
<TextInput
|
|
189
|
+
label="Input name"
|
|
190
|
+
name={`sections.${sectionIndex}.inputs.${inputIndex}.label`}
|
|
191
|
+
placeholder="Question"
|
|
192
|
+
/>
|
|
193
|
+
{hasDescription && (
|
|
194
|
+
<TextInput
|
|
195
|
+
label="Description(optional)"
|
|
196
|
+
name={`sections.${sectionIndex}.inputs.${inputIndex}.description`}
|
|
197
|
+
placeholder="Describe details for the question"
|
|
198
|
+
/>
|
|
199
|
+
)}
|
|
200
|
+
</div>
|
|
201
|
+
{shouldRenderOptions && (
|
|
202
|
+
<FieldArray name={`sections.${sectionIndex}.inputs.${inputIndex}.options`}>
|
|
203
|
+
{({ push, remove }) => (
|
|
204
|
+
<div className="input-options">
|
|
205
|
+
<p>Options</p>
|
|
206
|
+
{input?.options.map((option, optionIndex) => (
|
|
207
|
+
<div key={option.key} className="option-container">
|
|
208
|
+
{input.type !== 'select' && <div className={`input-icon-sample ${input.type}`} />}
|
|
209
|
+
|
|
210
|
+
<TextInput
|
|
211
|
+
name={`sections.${sectionIndex}.inputs.${inputIndex}.options.${optionIndex}.value`}
|
|
212
|
+
placeholder={`Option ${optionIndex + 1}`}
|
|
213
|
+
onBlur={(e) => handleSelectOptionBlur(e, optionIndex)}
|
|
214
|
+
/>
|
|
215
|
+
|
|
216
|
+
{input?.conditionalNavigation && (
|
|
217
|
+
<>
|
|
218
|
+
<SelectInput
|
|
219
|
+
options={[{ label: 'Select section', value: '', disabled: true }, ...availableSections]}
|
|
220
|
+
name={`sections.${sectionIndex}.inputs.${inputIndex}.options.${optionIndex}.nextSection`}
|
|
221
|
+
/>
|
|
222
|
+
</>
|
|
223
|
+
)}
|
|
224
|
+
<button className="icon" type="button" onClick={() => remove(optionIndex)}>Y</button>
|
|
225
|
+
</div>
|
|
226
|
+
))}
|
|
227
|
+
<button
|
|
228
|
+
className="add-option-cta"
|
|
229
|
+
type="button"
|
|
230
|
+
onClick={() => push({
|
|
231
|
+
key :`sections-${sectionIndex}-inputs-${inputIndex}-options-${input.options.length - 1}`,
|
|
232
|
+
value :'',
|
|
233
|
+
label :'',
|
|
234
|
+
nextSection:'',
|
|
235
|
+
})}
|
|
236
|
+
>
|
|
237
|
+
<div className="icon-container">
|
|
238
|
+
<span className="icon">
|
|
239
|
+
+
|
|
240
|
+
</span>
|
|
241
|
+
</div>
|
|
242
|
+
<span className="text x-paragraph c-x">Add Option</span>
|
|
243
|
+
</button>
|
|
244
|
+
</div>
|
|
245
|
+
)}
|
|
246
|
+
</FieldArray>
|
|
247
|
+
)}
|
|
248
|
+
</div>
|
|
249
|
+
</div>
|
|
250
|
+
)
|
|
251
|
+
}
|
|
252
|
+
InputBuilder.propTypes = {
|
|
253
|
+
/**
|
|
254
|
+
* The HTML id for this element
|
|
255
|
+
*/
|
|
256
|
+
id:PropTypes.string,
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* The HTML class names for this element
|
|
260
|
+
*/
|
|
261
|
+
className:PropTypes.string,
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* The React-written, css properties for this element.
|
|
265
|
+
*/
|
|
266
|
+
style:PropTypes.objectOf(PropTypes.string),
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* The preferred primary order of the popover
|
|
270
|
+
*/
|
|
271
|
+
preferredPopoverOrder:PropTypes.arrayOf(PropTypes.string),
|
|
272
|
+
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
InputBuilder.defaultProps = {
|
|
276
|
+
preferredPopoverOrder:['right', 'bottom', 'left', 'top'],
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
export default InputBuilder
|
|
@@ -0,0 +1,192 @@
|
|
|
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}.input-builder {
|
|
10
|
+
border: var(--theme-default-border-style) var(--ui-lines);
|
|
11
|
+
border-radius: calc(var(--theme-default-border-radius) / 2);
|
|
12
|
+
display: flex;
|
|
13
|
+
margin-top: $default-margin;
|
|
14
|
+
padding: $default-padding;
|
|
15
|
+
|
|
16
|
+
> .drag-icon {
|
|
17
|
+
margin-right: $default-margin;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
> .input-options-container {
|
|
21
|
+
flex: auto;
|
|
22
|
+
|
|
23
|
+
> .controls-container {
|
|
24
|
+
display: flex;
|
|
25
|
+
justify-content: space-between;
|
|
26
|
+
margin-bottom: $default-margin;
|
|
27
|
+
|
|
28
|
+
.#{bem.$base}.select-input {
|
|
29
|
+
flex: .3;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
>.controls {
|
|
33
|
+
display: flex;
|
|
34
|
+
gap: var(--gap);
|
|
35
|
+
|
|
36
|
+
/* stylelint-disable selector-max-compound-selectors -- required */
|
|
37
|
+
> .is-required {
|
|
38
|
+
display: flex;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/* stylelint-disable selector-max-universal -- required */
|
|
42
|
+
> * {
|
|
43
|
+
height: fit-content;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
> button {
|
|
47
|
+
background-color: transparent;
|
|
48
|
+
border: 0;
|
|
49
|
+
cursor: pointer;
|
|
50
|
+
|
|
51
|
+
/* stylelint-disable max-nesting-depth -- required */
|
|
52
|
+
> .ai-icon,
|
|
53
|
+
.icon {
|
|
54
|
+
font-size: calc(var(--s1) * 1rem);
|
|
55
|
+
}
|
|
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
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
> .input-name-description {
|
|
110
|
+
display: flex;
|
|
111
|
+
flex-direction: column;
|
|
112
|
+
gap: var(--gap);
|
|
113
|
+
margin-bottom: $default-margin;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
> .input-options {
|
|
117
|
+
display: flex;
|
|
118
|
+
flex-direction: column;
|
|
119
|
+
gap: var(--gap);
|
|
120
|
+
|
|
121
|
+
> p {
|
|
122
|
+
margin: 0;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
> .option-container {
|
|
126
|
+
align-items: center;
|
|
127
|
+
display: flex;
|
|
128
|
+
gap: calc(var(--gap) / 2);
|
|
129
|
+
|
|
130
|
+
> .input-icon-sample {
|
|
131
|
+
border: var(--theme-default-border-style) var(--outline-inputs);
|
|
132
|
+
border-radius: var(--theme-default-border-radius);
|
|
133
|
+
cursor: default;
|
|
134
|
+
height: 1.6rem;
|
|
135
|
+
width: 1.6rem;
|
|
136
|
+
|
|
137
|
+
&.checkbox {
|
|
138
|
+
border-radius: calc(var(--theme-default-border-radius) / 4);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
> .#{bem.$base}.text-input {
|
|
144
|
+
flex: .5;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
> .#{bem.$base}.select-input {
|
|
148
|
+
flex: .3;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
> button {
|
|
152
|
+
background-color: transparent;
|
|
153
|
+
border: 0;
|
|
154
|
+
color: var(--ui-icons);
|
|
155
|
+
cursor: pointer;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
>.add-option-cta {
|
|
160
|
+
--color: var(--interactive);
|
|
161
|
+
--border-color: var(--interactive);
|
|
162
|
+
align-items: center;
|
|
163
|
+
align-self: flex-start;
|
|
164
|
+
background-color: transparent;
|
|
165
|
+
border: 0;
|
|
166
|
+
color: var(--color);
|
|
167
|
+
cursor: pointer;
|
|
168
|
+
display: flex;
|
|
169
|
+
gap: calc(var(--gap) / 1.5);
|
|
170
|
+
padding: 0;
|
|
171
|
+
transition: all .2s;
|
|
172
|
+
|
|
173
|
+
&:hover {
|
|
174
|
+
--color: var(--soft-interactive);
|
|
175
|
+
--border-color: var(--soft-interactive);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
> .icon-container {
|
|
179
|
+
align-items: center;
|
|
180
|
+
border: 2px solid var(--border-color);
|
|
181
|
+
border-radius: 50%;
|
|
182
|
+
display: flex;
|
|
183
|
+
height: 1.6rem;
|
|
184
|
+
justify-content: center;
|
|
185
|
+
width: 1.6rem;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/* @pareto-engineering/generator-front 1.1.1-alpha.2 */
|
|
2
|
+
import * as React from 'react'
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
useState, useEffect,
|
|
6
|
+
} from 'react'
|
|
7
|
+
|
|
8
|
+
import { Form, FieldArray, useFormikContext } from 'formik'
|
|
9
|
+
|
|
10
|
+
import PropTypes from 'prop-types'
|
|
11
|
+
|
|
12
|
+
// Local Definitions
|
|
13
|
+
|
|
14
|
+
import styleNames from '@pareto-engineering/bem/exports'
|
|
15
|
+
|
|
16
|
+
import { TextInput, EditorInput } from 'ui/f'
|
|
17
|
+
|
|
18
|
+
import { DragAndDrop } from 'ui/g'
|
|
19
|
+
|
|
20
|
+
import { InputBuilder } from '../InputBuilder'
|
|
21
|
+
|
|
22
|
+
const baseClassName = styleNames.base
|
|
23
|
+
|
|
24
|
+
const componentClassName = 'section'
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* This is the component description.
|
|
28
|
+
*/
|
|
29
|
+
const Section = ({
|
|
30
|
+
id,
|
|
31
|
+
className:userClassName,
|
|
32
|
+
style,
|
|
33
|
+
index,
|
|
34
|
+
// ...otherProps
|
|
35
|
+
}) => {
|
|
36
|
+
const { values, setFieldValue } = useFormikContext()
|
|
37
|
+
const section = values.sections[index]
|
|
38
|
+
|
|
39
|
+
const handleDeleteInput = (inputIndex) => {
|
|
40
|
+
const newInputs = [...section.inputs]
|
|
41
|
+
newInputs.splice(inputIndex, 1)
|
|
42
|
+
setFieldValue(`sections.${index}.inputs`, newInputs)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const handleCopyInput = (inputIndex) => {
|
|
46
|
+
const inputToCopy = section.inputs[inputIndex]
|
|
47
|
+
|
|
48
|
+
const newInputs = [
|
|
49
|
+
...section.inputs,
|
|
50
|
+
{ ...inputToCopy, name: `section_${index}_input_${section.inputs.length}` },
|
|
51
|
+
]
|
|
52
|
+
setFieldValue(`sections.${index}.inputs`, newInputs)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const [draggableInputs, setDraggableInputs] = useState([])
|
|
56
|
+
|
|
57
|
+
const { inputs } = section
|
|
58
|
+
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
const items = inputs.map((input, indx) => ({
|
|
61
|
+
Content:<InputBuilder
|
|
62
|
+
key={input.name}
|
|
63
|
+
sectionIndex={index}
|
|
64
|
+
inputIndex={indx}
|
|
65
|
+
onDelete={handleDeleteInput}
|
|
66
|
+
onCopy={handleCopyInput}
|
|
67
|
+
/>,
|
|
68
|
+
identifier:input.name,
|
|
69
|
+
}))
|
|
70
|
+
setDraggableInputs(items)
|
|
71
|
+
}, [inputs.length, index])
|
|
72
|
+
|
|
73
|
+
return (
|
|
74
|
+
<div
|
|
75
|
+
id={id}
|
|
76
|
+
className={[
|
|
77
|
+
|
|
78
|
+
baseClassName,
|
|
79
|
+
|
|
80
|
+
componentClassName,
|
|
81
|
+
userClassName,
|
|
82
|
+
]
|
|
83
|
+
.filter((e) => e)
|
|
84
|
+
.join(' ')}
|
|
85
|
+
style={style}
|
|
86
|
+
>
|
|
87
|
+
<p className="h4">
|
|
88
|
+
{index === 0 ? 'Form title' : `Section ${index + 1}`}
|
|
89
|
+
</p>
|
|
90
|
+
<TextInput
|
|
91
|
+
name={`sections.${index}.title`}
|
|
92
|
+
placeholder={`Title of the ${index === 0 ? 'form' : 'section'}`}
|
|
93
|
+
/>
|
|
94
|
+
<EditorInput
|
|
95
|
+
name={`sections.${index}.description`}
|
|
96
|
+
label={`${index === 0 ? 'Form' : 'Section'} description`}
|
|
97
|
+
/>
|
|
98
|
+
|
|
99
|
+
<FieldArray name={`sections.${index}.inputs`}>
|
|
100
|
+
{({ push }) => (
|
|
101
|
+
<Form>
|
|
102
|
+
<DragAndDrop
|
|
103
|
+
items={draggableInputs}
|
|
104
|
+
onOrderChange={(reOrderedItems) => {
|
|
105
|
+
setDraggableInputs(reOrderedItems)
|
|
106
|
+
const ids = reOrderedItems.map((e) => e.identifier)
|
|
107
|
+
setFieldValue(`sections.${index}.orderedInputDragIds`, ids)
|
|
108
|
+
}}
|
|
109
|
+
key={draggableInputs.length}
|
|
110
|
+
/>
|
|
111
|
+
<button
|
|
112
|
+
type="button"
|
|
113
|
+
className="add-question-cta"
|
|
114
|
+
onClick={() => push({
|
|
115
|
+
name :`section_${index}_input_${section.inputs.length}`,
|
|
116
|
+
label :'',
|
|
117
|
+
type :'text',
|
|
118
|
+
required :false,
|
|
119
|
+
options :[],
|
|
120
|
+
conditionalLogic:null,
|
|
121
|
+
description :'',
|
|
122
|
+
})}
|
|
123
|
+
>
|
|
124
|
+
<div className="icon-container">
|
|
125
|
+
<span className="icon ">+</span>
|
|
126
|
+
</div>
|
|
127
|
+
Add question
|
|
128
|
+
</button>
|
|
129
|
+
</Form>
|
|
130
|
+
)}
|
|
131
|
+
</FieldArray>
|
|
132
|
+
</div>
|
|
133
|
+
)
|
|
134
|
+
}
|
|
135
|
+
Section.propTypes = {
|
|
136
|
+
/**
|
|
137
|
+
* The HTML id for this element
|
|
138
|
+
*/
|
|
139
|
+
id:PropTypes.string,
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* The HTML class names for this element
|
|
143
|
+
*/
|
|
144
|
+
className:PropTypes.string,
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* The React-written, css properties for this element.
|
|
148
|
+
*/
|
|
149
|
+
style:PropTypes.objectOf(PropTypes.string),
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
Section.defaultProps = {
|
|
153
|
+
// someProp:false
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export default Section
|