@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,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,120 @@
|
|
|
1
|
+
/* @pareto-engineering/generator-front 1.1.1-alpha.2 */
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { useState, useEffect } from 'react';
|
|
4
|
+
import { Form, FieldArray, useFormikContext } from 'formik';
|
|
5
|
+
import PropTypes from 'prop-types';
|
|
6
|
+
|
|
7
|
+
// Local Definitions
|
|
8
|
+
|
|
9
|
+
import styleNames from '@pareto-engineering/bem/exports';
|
|
10
|
+
import { TextInput, EditorInput } from "../../../../../../f";
|
|
11
|
+
import { DragAndDrop } from "../../../../..";
|
|
12
|
+
import { InputBuilder } from "../InputBuilder";
|
|
13
|
+
const baseClassName = styleNames.base;
|
|
14
|
+
const componentClassName = 'section';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* This is the component description.
|
|
18
|
+
*/
|
|
19
|
+
const Section = ({
|
|
20
|
+
id,
|
|
21
|
+
className: userClassName,
|
|
22
|
+
style,
|
|
23
|
+
index
|
|
24
|
+
// ...otherProps
|
|
25
|
+
}) => {
|
|
26
|
+
const {
|
|
27
|
+
values,
|
|
28
|
+
setFieldValue
|
|
29
|
+
} = useFormikContext();
|
|
30
|
+
const section = values.sections[index];
|
|
31
|
+
const handleDeleteInput = inputIndex => {
|
|
32
|
+
const newInputs = [...section.inputs];
|
|
33
|
+
newInputs.splice(inputIndex, 1);
|
|
34
|
+
setFieldValue(`sections.${index}.inputs`, newInputs);
|
|
35
|
+
};
|
|
36
|
+
const handleCopyInput = inputIndex => {
|
|
37
|
+
const inputToCopy = section.inputs[inputIndex];
|
|
38
|
+
const newInputs = [...section.inputs, {
|
|
39
|
+
...inputToCopy,
|
|
40
|
+
name: `section_${index}_input_${section.inputs.length}`
|
|
41
|
+
}];
|
|
42
|
+
setFieldValue(`sections.${index}.inputs`, newInputs);
|
|
43
|
+
};
|
|
44
|
+
const [draggableInputs, setDraggableInputs] = useState([]);
|
|
45
|
+
const {
|
|
46
|
+
inputs
|
|
47
|
+
} = section;
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
const items = inputs.map((input, indx) => ({
|
|
50
|
+
Content: /*#__PURE__*/React.createElement(InputBuilder, {
|
|
51
|
+
key: input.name,
|
|
52
|
+
sectionIndex: index,
|
|
53
|
+
inputIndex: indx,
|
|
54
|
+
onDelete: handleDeleteInput,
|
|
55
|
+
onCopy: handleCopyInput
|
|
56
|
+
}),
|
|
57
|
+
identifier: input.name
|
|
58
|
+
}));
|
|
59
|
+
setDraggableInputs(items);
|
|
60
|
+
}, [inputs.length, index]);
|
|
61
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
62
|
+
id: id,
|
|
63
|
+
className: [baseClassName, componentClassName, userClassName].filter(e => e).join(' '),
|
|
64
|
+
style: style
|
|
65
|
+
}, /*#__PURE__*/React.createElement("p", {
|
|
66
|
+
className: "h4"
|
|
67
|
+
}, index === 0 ? 'Form title' : `Section ${index + 1}`), /*#__PURE__*/React.createElement(TextInput, {
|
|
68
|
+
name: `sections.${index}.title`,
|
|
69
|
+
placeholder: `Title of the ${index === 0 ? 'form' : 'section'}`
|
|
70
|
+
}), /*#__PURE__*/React.createElement(EditorInput, {
|
|
71
|
+
name: `sections.${index}.description`,
|
|
72
|
+
label: `${index === 0 ? 'Form' : 'Section'} description`
|
|
73
|
+
}), /*#__PURE__*/React.createElement(FieldArray, {
|
|
74
|
+
name: `sections.${index}.inputs`
|
|
75
|
+
}, ({
|
|
76
|
+
push
|
|
77
|
+
}) => /*#__PURE__*/React.createElement(Form, null, /*#__PURE__*/React.createElement(DragAndDrop, {
|
|
78
|
+
items: draggableInputs,
|
|
79
|
+
onOrderChange: reOrderedItems => {
|
|
80
|
+
setDraggableInputs(reOrderedItems);
|
|
81
|
+
const ids = reOrderedItems.map(e => e.identifier);
|
|
82
|
+
setFieldValue(`sections.${index}.orderedInputDragIds`, ids);
|
|
83
|
+
},
|
|
84
|
+
key: draggableInputs.length
|
|
85
|
+
}), /*#__PURE__*/React.createElement("button", {
|
|
86
|
+
type: "button",
|
|
87
|
+
className: "add-question-cta",
|
|
88
|
+
onClick: () => push({
|
|
89
|
+
name: `section_${index}_input_${section.inputs.length}`,
|
|
90
|
+
label: '',
|
|
91
|
+
type: 'text',
|
|
92
|
+
required: false,
|
|
93
|
+
options: [],
|
|
94
|
+
conditionalLogic: null,
|
|
95
|
+
description: ''
|
|
96
|
+
})
|
|
97
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
98
|
+
className: "icon-container"
|
|
99
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
100
|
+
className: "icon "
|
|
101
|
+
}, "+")), "Add question"))));
|
|
102
|
+
};
|
|
103
|
+
Section.propTypes = {
|
|
104
|
+
/**
|
|
105
|
+
* The HTML id for this element
|
|
106
|
+
*/
|
|
107
|
+
id: PropTypes.string,
|
|
108
|
+
/**
|
|
109
|
+
* The HTML class names for this element
|
|
110
|
+
*/
|
|
111
|
+
className: PropTypes.string,
|
|
112
|
+
/**
|
|
113
|
+
* The React-written, css properties for this element.
|
|
114
|
+
*/
|
|
115
|
+
style: PropTypes.objectOf(PropTypes.string)
|
|
116
|
+
};
|
|
117
|
+
Section.defaultProps = {
|
|
118
|
+
// someProp:false
|
|
119
|
+
};
|
|
120
|
+
export default Section;
|
|
@@ -0,0 +1,106 @@
|
|
|
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 {
|
|
8
|
+
> form {
|
|
9
|
+
> .section-footer {
|
|
10
|
+
align-items: center;
|
|
11
|
+
display: flex;
|
|
12
|
+
justify-content: space-between;
|
|
13
|
+
margin-top: calc($default-margin * 1.5);
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
>.add-section-cta {
|
|
17
|
+
--color: var(--interactive);
|
|
18
|
+
--border-color: var(--interactive);
|
|
19
|
+
align-items: center;
|
|
20
|
+
background-color: transparent;
|
|
21
|
+
border: 0;
|
|
22
|
+
color: var(--color);
|
|
23
|
+
cursor: pointer;
|
|
24
|
+
display: flex;
|
|
25
|
+
gap: calc(var(--gap) / 1.5);
|
|
26
|
+
padding: 0;
|
|
27
|
+
transition: all .2s;
|
|
28
|
+
|
|
29
|
+
&:hover {
|
|
30
|
+
--color: var(--soft-interactive);
|
|
31
|
+
--border-color: var(--soft-interactive);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/* stylelint-disable-next-line selector-max-compound-selectors -- required */
|
|
35
|
+
> .icon-container {
|
|
36
|
+
align-items: center;
|
|
37
|
+
border: 2px solid var(--border-color);
|
|
38
|
+
border-radius: 50%;
|
|
39
|
+
display: flex;
|
|
40
|
+
height: 1.6rem;
|
|
41
|
+
justify-content: center;
|
|
42
|
+
width: 1.6rem;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
> .section-navigation {
|
|
47
|
+
align-items: center;
|
|
48
|
+
display: flex;
|
|
49
|
+
flex: .4;
|
|
50
|
+
gap: var(--gap);
|
|
51
|
+
|
|
52
|
+
> .#{bem.$base}.select-input {
|
|
53
|
+
flex: auto;
|
|
54
|
+
}
|
|
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
|
+
|
|
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
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
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
|
+
/* @pareto-engineering/generator-front 1.1.1-alpha.2 */
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { Formik, Form } from 'formik';
|
|
5
|
+
import { useState } from 'react';
|
|
6
|
+
import PropTypes from 'prop-types';
|
|
7
|
+
import styleNames from '@pareto-engineering/bem/exports';
|
|
8
|
+
import { Button } from "../../../../b";
|
|
9
|
+
import "./styles.scss";
|
|
10
|
+
|
|
11
|
+
// Local Definitions
|
|
12
|
+
|
|
13
|
+
import { Section } from "./common";
|
|
14
|
+
const baseClassName = styleNames.base;
|
|
15
|
+
const componentClassName = 'renderer';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* This is the component description.
|
|
19
|
+
*/
|
|
20
|
+
const Renderer = ({
|
|
21
|
+
id,
|
|
22
|
+
className: userClassName,
|
|
23
|
+
style,
|
|
24
|
+
formData,
|
|
25
|
+
onSave
|
|
26
|
+
// ...otherProps
|
|
27
|
+
}) => {
|
|
28
|
+
const [currentSectionIndex, setCurrentSectionIndex] = useState(0);
|
|
29
|
+
const [sectionHistory, setSectionHistory] = useState([]);
|
|
30
|
+
const initialValues = formData.sections.reduce((acc, section) => {
|
|
31
|
+
section.inputs.forEach(input => {
|
|
32
|
+
acc[input.name] = '';
|
|
33
|
+
});
|
|
34
|
+
return acc;
|
|
35
|
+
}, {});
|
|
36
|
+
const handleSubmit = values => {
|
|
37
|
+
const currentSection = formData.sections[currentSectionIndex];
|
|
38
|
+
// by default, 'next' section is the immediate section after the current one
|
|
39
|
+
let nextSectionIndex = currentSectionIndex + 1;
|
|
40
|
+
|
|
41
|
+
// Any other value is either submit or an index to a section
|
|
42
|
+
if (currentSection.navigation.nextSection !== 'next') {
|
|
43
|
+
nextSectionIndex = currentSection.navigation.nextSection === 'submit' ? formData.sections.length // submit
|
|
44
|
+
: parseInt(currentSection.navigation.nextSection, 10); // go to specific section
|
|
45
|
+
}
|
|
46
|
+
if (nextSectionIndex >= formData.sections.length) {
|
|
47
|
+
// submit
|
|
48
|
+
onSave(values);
|
|
49
|
+
} else {
|
|
50
|
+
// Record index history to navigate back
|
|
51
|
+
setSectionHistory([...sectionHistory, currentSectionIndex]);
|
|
52
|
+
// go to evaluated next section
|
|
53
|
+
setCurrentSectionIndex(nextSectionIndex);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
const handlePrevious = () => {
|
|
57
|
+
if (sectionHistory.length > 0) {
|
|
58
|
+
// get the last index of array(the immediate last section)
|
|
59
|
+
const previousSectionIndex = sectionHistory.pop();
|
|
60
|
+
// set the immediate last section indx as current
|
|
61
|
+
setCurrentSectionIndex(previousSectionIndex);
|
|
62
|
+
setSectionHistory([...sectionHistory]);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
66
|
+
id: id,
|
|
67
|
+
className: [baseClassName, componentClassName, userClassName].filter(e => e).join(' '),
|
|
68
|
+
style: style
|
|
69
|
+
}, /*#__PURE__*/React.createElement(Formik, {
|
|
70
|
+
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')))));
|
|
87
|
+
};
|
|
88
|
+
Renderer.propTypes = {
|
|
89
|
+
/**
|
|
90
|
+
* The HTML id for this element
|
|
91
|
+
*/
|
|
92
|
+
id: PropTypes.string,
|
|
93
|
+
/**
|
|
94
|
+
* The HTML class names for this element
|
|
95
|
+
*/
|
|
96
|
+
className: PropTypes.string,
|
|
97
|
+
/**
|
|
98
|
+
* The React-written, css properties for this element.
|
|
99
|
+
*/
|
|
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
|
+
})
|
|
109
|
+
};
|
|
110
|
+
Renderer.defaultProps = {
|
|
111
|
+
// someProp:false
|
|
112
|
+
};
|
|
113
|
+
export default Renderer;
|
|
@@ -0,0 +1,52 @@
|
|
|
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
|
+
/* @pareto-engineering/generator-front 1.1.1-alpha.2 */
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import PropTypes from 'prop-types';
|
|
5
|
+
|
|
6
|
+
// Local Definitions
|
|
7
|
+
|
|
8
|
+
import { FormInput } from "../../../../../../f";
|
|
9
|
+
import { ExpandableLexicalPreview } from "../../../../..";
|
|
10
|
+
import styleNames from '@pareto-engineering/bem/exports';
|
|
11
|
+
const baseClassName = styleNames.base;
|
|
12
|
+
const componentClassName = 'section';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* This is the component description.
|
|
16
|
+
*/
|
|
17
|
+
const Section = ({
|
|
18
|
+
id,
|
|
19
|
+
className: userClassName,
|
|
20
|
+
style,
|
|
21
|
+
title,
|
|
22
|
+
description,
|
|
23
|
+
inputs
|
|
24
|
+
// ...otherProps
|
|
25
|
+
}) => /*#__PURE__*/React.createElement("div", {
|
|
26
|
+
id: id,
|
|
27
|
+
className: [baseClassName, componentClassName, userClassName].filter(e => e).join(' '),
|
|
28
|
+
style: style
|
|
29
|
+
}, /*#__PURE__*/React.createElement("h3", null, title), /*#__PURE__*/React.createElement(ExpandableLexicalPreview, {
|
|
30
|
+
nodes: description,
|
|
31
|
+
name: "instructions"
|
|
32
|
+
}), inputs.map(input => /*#__PURE__*/React.createElement(FormInput, _extends({
|
|
33
|
+
key: input.name
|
|
34
|
+
}, input))));
|
|
35
|
+
Section.propTypes = {
|
|
36
|
+
/**
|
|
37
|
+
* The HTML id for this element
|
|
38
|
+
*/
|
|
39
|
+
id: PropTypes.string,
|
|
40
|
+
/**
|
|
41
|
+
* The HTML class names for this element
|
|
42
|
+
*/
|
|
43
|
+
className: PropTypes.string,
|
|
44
|
+
/**
|
|
45
|
+
* The React-written, css properties for this element.
|
|
46
|
+
*/
|
|
47
|
+
style: PropTypes.objectOf(PropTypes.string)
|
|
48
|
+
};
|
|
49
|
+
Section.defaultProps = {
|
|
50
|
+
// someProp:false
|
|
51
|
+
};
|
|
52
|
+
export default Section;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Section } from "./Section";
|
|
@@ -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
|
+
}
|
package/dist/es/g/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pareto-engineering/design-system",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.1.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.
|
|
62
|
+
"@pareto-engineering/assets": "^4.1.0",
|
|
63
63
|
"@pareto-engineering/bem": "^4.0.0",
|
|
64
64
|
"@pareto-engineering/styles": "^4.0.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": "
|
|
85
|
+
"gitHead": "2f5a8c44673dbc2a2cfed253b643a11edeaf4821"
|
|
86
86
|
}
|
|
@@ -17,6 +17,12 @@ export default {
|
|
|
17
17
|
},
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
export const
|
|
21
|
-
|
|
20
|
+
export const Single = () => <ToggleSwitch />
|
|
21
|
+
|
|
22
|
+
export const Multiple = () => (
|
|
23
|
+
<>
|
|
24
|
+
<ToggleSwitch inputId="option1" />
|
|
25
|
+
<ToggleSwitch inputId="option2" />
|
|
26
|
+
<ToggleSwitch inputId="option3" />
|
|
27
|
+
</>
|
|
22
28
|
)
|