@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,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,145 @@
|
|
|
1
|
+
/* @pareto-engineering/generator-front 1.1.1-alpha.2 */
|
|
2
|
+
import * as React from 'react'
|
|
3
|
+
|
|
4
|
+
import { Formik, Form } from 'formik'
|
|
5
|
+
|
|
6
|
+
import { useState } from 'react'
|
|
7
|
+
|
|
8
|
+
import PropTypes from 'prop-types'
|
|
9
|
+
|
|
10
|
+
import styleNames from '@pareto-engineering/bem/exports'
|
|
11
|
+
|
|
12
|
+
import { Button } from 'ui/b'
|
|
13
|
+
|
|
14
|
+
import './styles.scss'
|
|
15
|
+
|
|
16
|
+
// Local Definitions
|
|
17
|
+
|
|
18
|
+
import { Section } from './common'
|
|
19
|
+
|
|
20
|
+
const baseClassName = styleNames.base
|
|
21
|
+
|
|
22
|
+
const componentClassName = 'renderer'
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* This is the component description.
|
|
26
|
+
*/
|
|
27
|
+
const Renderer = ({
|
|
28
|
+
id,
|
|
29
|
+
className:userClassName,
|
|
30
|
+
style,
|
|
31
|
+
formData,
|
|
32
|
+
onSave,
|
|
33
|
+
// ...otherProps
|
|
34
|
+
}) => {
|
|
35
|
+
const [currentSectionIndex, setCurrentSectionIndex] = useState(0)
|
|
36
|
+
const [sectionHistory, setSectionHistory] = useState([])
|
|
37
|
+
|
|
38
|
+
const initialValues = formData.sections.reduce((acc, section) => {
|
|
39
|
+
section.inputs.forEach((input) => {
|
|
40
|
+
acc[input.name] = ''
|
|
41
|
+
})
|
|
42
|
+
return acc
|
|
43
|
+
}, {})
|
|
44
|
+
|
|
45
|
+
const handleSubmit = (values) => {
|
|
46
|
+
const currentSection = formData.sections[currentSectionIndex]
|
|
47
|
+
// by default, 'next' section is the immediate section after the current one
|
|
48
|
+
let nextSectionIndex = currentSectionIndex + 1
|
|
49
|
+
|
|
50
|
+
// Any other value is either submit or an index to a section
|
|
51
|
+
if (currentSection.navigation.nextSection !== 'next') {
|
|
52
|
+
nextSectionIndex = currentSection.navigation.nextSection === 'submit'
|
|
53
|
+
? formData.sections.length // submit
|
|
54
|
+
: parseInt(currentSection.navigation.nextSection, 10) // go to specific section
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (nextSectionIndex >= formData.sections.length) {
|
|
58
|
+
// submit
|
|
59
|
+
onSave(values)
|
|
60
|
+
} else {
|
|
61
|
+
// Record index history to navigate back
|
|
62
|
+
setSectionHistory([...sectionHistory, currentSectionIndex])
|
|
63
|
+
// go to evaluated next section
|
|
64
|
+
setCurrentSectionIndex(nextSectionIndex)
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const handlePrevious = () => {
|
|
69
|
+
if (sectionHistory.length > 0) {
|
|
70
|
+
// get the last index of array(the immediate last section)
|
|
71
|
+
const previousSectionIndex = sectionHistory.pop()
|
|
72
|
+
// set the immediate last section indx as current
|
|
73
|
+
setCurrentSectionIndex(previousSectionIndex)
|
|
74
|
+
setSectionHistory([...sectionHistory])
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
<div
|
|
80
|
+
id={id}
|
|
81
|
+
className={[
|
|
82
|
+
baseClassName,
|
|
83
|
+
componentClassName,
|
|
84
|
+
userClassName,
|
|
85
|
+
]
|
|
86
|
+
.filter((e) => e)
|
|
87
|
+
.join(' ')}
|
|
88
|
+
style={style}
|
|
89
|
+
|
|
90
|
+
>
|
|
91
|
+
<Formik
|
|
92
|
+
initialValues={initialValues}
|
|
93
|
+
onSubmit={handleSubmit}
|
|
94
|
+
>
|
|
95
|
+
<Form>
|
|
96
|
+
{formData.sections.map((section, sectionIndex) => (
|
|
97
|
+
sectionIndex === currentSectionIndex && (
|
|
98
|
+
<Section key={`${section.title}`} {...section} />
|
|
99
|
+
)
|
|
100
|
+
))}
|
|
101
|
+
<div className="navigator-container">
|
|
102
|
+
<Button color="interactive" isGradient isGhost onClick={handlePrevious} disabled={sectionHistory.length === 0}>
|
|
103
|
+
Previous
|
|
104
|
+
</Button>
|
|
105
|
+
<Button color="interactive" isGradient type="submit">
|
|
106
|
+
{formData.sections[currentSectionIndex].navigation.nextSection === 'submit' ? 'Submit' : 'Next'}
|
|
107
|
+
</Button>
|
|
108
|
+
</div>
|
|
109
|
+
</Form>
|
|
110
|
+
</Formik>
|
|
111
|
+
</div>
|
|
112
|
+
)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
Renderer.propTypes = {
|
|
116
|
+
/**
|
|
117
|
+
* The HTML id for this element
|
|
118
|
+
*/
|
|
119
|
+
id:PropTypes.string,
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* The HTML class names for this element
|
|
123
|
+
*/
|
|
124
|
+
className:PropTypes.string,
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* The React-written, css properties for this element.
|
|
128
|
+
*/
|
|
129
|
+
style:PropTypes.objectOf(PropTypes.string),
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* The children JSX
|
|
133
|
+
*/
|
|
134
|
+
formData:PropTypes.shape({
|
|
135
|
+
formTitle :PropTypes.string.isRequired,
|
|
136
|
+
formDescription:PropTypes.string.isRequired,
|
|
137
|
+
sections :PropTypes.arrayOf(PropTypes.objectOf(PropTypes.any)),
|
|
138
|
+
}),
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
Renderer.defaultProps = {
|
|
142
|
+
// someProp:false
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export default Renderer
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/* @pareto-engineering/generator-front 1.1.1-alpha.2 */
|
|
2
|
+
import * as React from 'react'
|
|
3
|
+
|
|
4
|
+
import PropTypes from 'prop-types'
|
|
5
|
+
|
|
6
|
+
// Local Definitions
|
|
7
|
+
|
|
8
|
+
import { FormInput } from 'ui/f'
|
|
9
|
+
|
|
10
|
+
import { ExpandableLexicalPreview } from 'ui/g'
|
|
11
|
+
|
|
12
|
+
import styleNames from '@pareto-engineering/bem/exports'
|
|
13
|
+
|
|
14
|
+
const baseClassName = styleNames.base
|
|
15
|
+
|
|
16
|
+
const componentClassName = 'section'
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* This is the component description.
|
|
20
|
+
*/
|
|
21
|
+
const Section = ({
|
|
22
|
+
id,
|
|
23
|
+
className:userClassName,
|
|
24
|
+
style,
|
|
25
|
+
title,
|
|
26
|
+
description,
|
|
27
|
+
inputs,
|
|
28
|
+
// ...otherProps
|
|
29
|
+
}) => (
|
|
30
|
+
<div
|
|
31
|
+
id={id}
|
|
32
|
+
className={[
|
|
33
|
+
|
|
34
|
+
baseClassName,
|
|
35
|
+
|
|
36
|
+
componentClassName,
|
|
37
|
+
userClassName,
|
|
38
|
+
]
|
|
39
|
+
.filter((e) => e)
|
|
40
|
+
.join(' ')}
|
|
41
|
+
style={style}
|
|
42
|
+
>
|
|
43
|
+
<h3>{title}</h3>
|
|
44
|
+
<ExpandableLexicalPreview
|
|
45
|
+
nodes={description}
|
|
46
|
+
name="instructions"
|
|
47
|
+
/>
|
|
48
|
+
{inputs.map((input) => (
|
|
49
|
+
<FormInput key={input.name} {...input} />
|
|
50
|
+
))}
|
|
51
|
+
</div>
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
Section.propTypes = {
|
|
55
|
+
/**
|
|
56
|
+
* The HTML id for this element
|
|
57
|
+
*/
|
|
58
|
+
id:PropTypes.string,
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* The HTML class names for this element
|
|
62
|
+
*/
|
|
63
|
+
className:PropTypes.string,
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* The React-written, css properties for this element.
|
|
67
|
+
*/
|
|
68
|
+
style:PropTypes.objectOf(PropTypes.string),
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
Section.defaultProps = {
|
|
72
|
+
// someProp:false
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
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/src/ui/g/index.js
CHANGED