@pareto-engineering/design-system 4.0.0-alpha.81 → 4.0.0-alpha.83
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/People/styles.scss +1 -1
- package/dist/cjs/f/fields/SelectInput/common/Multiple/Multiple.js +1 -1
- package/dist/cjs/f/fields/SelectInput/common/Single/Single.js +1 -1
- package/dist/cjs/f/fields/TextInput/TextInput.js +1 -2
- package/dist/cjs/f/fields/TextareaInput/TextareaInput.js +1 -2
- package/dist/cjs/g/DragAndDrop/DragAndDrop.js +97 -0
- package/dist/cjs/g/DragAndDrop/common/DraggableItem/DraggableItem.js +80 -0
- package/dist/cjs/g/DragAndDrop/common/DraggableItem/index.js +13 -0
- package/dist/cjs/g/DragAndDrop/common/DraggableItem/styles.scss +12 -0
- package/dist/cjs/g/DragAndDrop/common/index.js +12 -0
- package/dist/cjs/g/DragAndDrop/index.js +13 -0
- package/dist/cjs/g/DragAndDrop/styles.scss +8 -0
- package/dist/cjs/g/index.js +8 -1
- package/dist/es/a/People/styles.scss +1 -1
- package/dist/es/f/fields/SelectInput/common/Multiple/Multiple.js +1 -1
- package/dist/es/f/fields/SelectInput/common/Single/Single.js +1 -1
- package/dist/es/f/fields/TextInput/TextInput.js +1 -2
- package/dist/es/f/fields/TextareaInput/TextareaInput.js +1 -2
- package/dist/es/g/DragAndDrop/DragAndDrop.js +88 -0
- package/dist/es/g/DragAndDrop/common/DraggableItem/DraggableItem.js +72 -0
- package/dist/es/g/DragAndDrop/common/DraggableItem/index.js +2 -0
- package/dist/es/g/DragAndDrop/common/DraggableItem/styles.scss +12 -0
- package/dist/es/g/DragAndDrop/common/index.js +1 -0
- package/dist/es/g/DragAndDrop/index.js +2 -0
- package/dist/es/g/DragAndDrop/styles.scss +8 -0
- package/dist/es/g/index.js +2 -1
- package/package.json +3 -3
- package/src/stories/g/DragAndDrop.stories.jsx +114 -0
- package/src/ui/a/People/styles.scss +1 -1
- package/src/ui/f/fields/SelectInput/common/Multiple/Multiple.jsx +16 -14
- package/src/ui/f/fields/SelectInput/common/Single/Single.jsx +9 -7
- package/src/ui/f/fields/TextInput/TextInput.jsx +9 -8
- package/src/ui/f/fields/TextareaInput/TextareaInput.jsx +9 -9
- package/src/ui/g/DragAndDrop/DragAndDrop.jsx +118 -0
- package/src/ui/g/DragAndDrop/common/DraggableItem/DraggableItem.jsx +98 -0
- package/src/ui/g/DragAndDrop/common/DraggableItem/index.js +2 -0
- package/src/ui/g/DragAndDrop/common/DraggableItem/styles.scss +12 -0
- package/src/ui/g/DragAndDrop/common/index.js +1 -0
- package/src/ui/g/DragAndDrop/index.js +2 -0
- package/src/ui/g/DragAndDrop/styles.scss +8 -0
- package/src/ui/g/index.js +1 -0
- package/tests/__snapshots__/Storyshots.test.js.snap +695 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/* @pareto-engineering/generator-front 1.0.12 */
|
|
2
|
+
import * as React from 'react'
|
|
3
|
+
|
|
4
|
+
import { useRef } from 'react'
|
|
5
|
+
|
|
6
|
+
import { TextInput, DragAndDrop, FormDebugger } from 'ui'
|
|
7
|
+
|
|
8
|
+
import { Formik, Form } from 'formik'
|
|
9
|
+
|
|
10
|
+
export default {
|
|
11
|
+
title :'g/DragAndDrop',
|
|
12
|
+
component :DragAndDrop,
|
|
13
|
+
subcomponents:{
|
|
14
|
+
// Item:DragAndDrop.Item
|
|
15
|
+
},
|
|
16
|
+
decorators:[
|
|
17
|
+
// storyfn => <div className="">{ storyfn() }</div>,
|
|
18
|
+
],
|
|
19
|
+
argTypes:{
|
|
20
|
+
backgroundColor:{ control: 'color' },
|
|
21
|
+
},
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const DummyContent = ({ children }) => (
|
|
25
|
+
<div
|
|
26
|
+
style={{
|
|
27
|
+
padding :'1rem',
|
|
28
|
+
backgroundColor:'white',
|
|
29
|
+
border :'1px solid black',
|
|
30
|
+
}}
|
|
31
|
+
>
|
|
32
|
+
{children}
|
|
33
|
+
</div>
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
export const Base = {
|
|
37
|
+
args:{
|
|
38
|
+
items:Array(8).fill().map((_, index) => ({
|
|
39
|
+
disabled:index === 0,
|
|
40
|
+
Content :(
|
|
41
|
+
<DummyContent>
|
|
42
|
+
Item
|
|
43
|
+
{index + 1}
|
|
44
|
+
</DummyContent>
|
|
45
|
+
),
|
|
46
|
+
key:`Item ${index + 1}`,
|
|
47
|
+
})),
|
|
48
|
+
},
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const DummyContentWithInput = ({ index }) => (
|
|
52
|
+
<div
|
|
53
|
+
style={{
|
|
54
|
+
display :'flex',
|
|
55
|
+
alignItems:'center',
|
|
56
|
+
width :'100%',
|
|
57
|
+
gap :'var(--gap)',
|
|
58
|
+
}}
|
|
59
|
+
>
|
|
60
|
+
<span className="ai-icon">H</span>
|
|
61
|
+
<div
|
|
62
|
+
style={{
|
|
63
|
+
borderBottom:'1px solid var(--ui-lines)',
|
|
64
|
+
padding :'calc(var(--theme-default-padding) / 2)',
|
|
65
|
+
display :'flex',
|
|
66
|
+
alignItems :'center',
|
|
67
|
+
width :'100%',
|
|
68
|
+
gap :'var(--gap)',
|
|
69
|
+
}}
|
|
70
|
+
>
|
|
71
|
+
<p
|
|
72
|
+
style={{
|
|
73
|
+
margin:'0',
|
|
74
|
+
}}
|
|
75
|
+
>
|
|
76
|
+
Input
|
|
77
|
+
{index + 1}
|
|
78
|
+
</p>
|
|
79
|
+
<TextInput name={`input-${index + 1}`} />
|
|
80
|
+
</div>
|
|
81
|
+
</div>
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
export const WithFormikInputs = {
|
|
85
|
+
render:({ items }) => {
|
|
86
|
+
const formikRef = useRef()
|
|
87
|
+
|
|
88
|
+
const handleReorder = (orderedItems) => {
|
|
89
|
+
const { values, setFieldValue } = formikRef.current || {}
|
|
90
|
+
const orderedInputValues = orderedItems.map(({ identifier }) => values?.[identifier])
|
|
91
|
+
|
|
92
|
+
setFieldValue('items', orderedInputValues)
|
|
93
|
+
}
|
|
94
|
+
return (
|
|
95
|
+
<Formik
|
|
96
|
+
initialValues={{ items: [] }}
|
|
97
|
+
innerRef={formikRef}
|
|
98
|
+
>
|
|
99
|
+
<Form>
|
|
100
|
+
<DragAndDrop onOrderChange={handleReorder} items={items} />
|
|
101
|
+
<FormDebugger />
|
|
102
|
+
</Form>
|
|
103
|
+
</Formik>
|
|
104
|
+
)
|
|
105
|
+
},
|
|
106
|
+
args:{
|
|
107
|
+
items:Array(8).fill().map((_, index) => ({
|
|
108
|
+
Content:(
|
|
109
|
+
<DummyContentWithInput index={index} />
|
|
110
|
+
),
|
|
111
|
+
identifier:`input-${index + 1}`,
|
|
112
|
+
})),
|
|
113
|
+
},
|
|
114
|
+
}
|
|
@@ -11,7 +11,7 @@ $default-padding:var(--u);
|
|
|
11
11
|
$default-horizontal-margin: .5em;
|
|
12
12
|
|
|
13
13
|
$default-grid-gap: 1em;
|
|
14
|
-
$default-margin:
|
|
14
|
+
$default-margin: 1em;
|
|
15
15
|
$default-image-margin: var(--default-image-margin, #{$default-margin});
|
|
16
16
|
$default-color: var(--default-color, var(--paragraph));
|
|
17
17
|
|
|
@@ -176,20 +176,22 @@ const Multiple = ({
|
|
|
176
176
|
{...getComboboxProps()}
|
|
177
177
|
// {...otherProps}
|
|
178
178
|
>
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
179
|
+
{label && (
|
|
180
|
+
<FormLabel
|
|
181
|
+
className={[
|
|
182
|
+
baseClassName,
|
|
183
|
+
componentClassName,
|
|
184
|
+
]
|
|
185
|
+
.filter((e) => e)
|
|
186
|
+
.join(' ')}
|
|
187
|
+
{...getLabelProps()}
|
|
188
|
+
name={name}
|
|
189
|
+
optional={optional}
|
|
190
|
+
color={labelColor}
|
|
191
|
+
>
|
|
192
|
+
{label}
|
|
193
|
+
</FormLabel>
|
|
194
|
+
)}
|
|
193
195
|
|
|
194
196
|
{selectedItems?.length > 0 && (
|
|
195
197
|
<div className="selected-items">
|
|
@@ -65,13 +65,15 @@ const Single = ({
|
|
|
65
65
|
.join(' ')}
|
|
66
66
|
style={style}
|
|
67
67
|
>
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
68
|
+
{label && (
|
|
69
|
+
<FormLabel
|
|
70
|
+
name={name}
|
|
71
|
+
color={labelColor}
|
|
72
|
+
optional={optional}
|
|
73
|
+
>
|
|
74
|
+
{label}
|
|
75
|
+
</FormLabel>
|
|
76
|
+
)}
|
|
75
77
|
<div className={`select-wrapper${disabled ? ' disabled' : ''}`}>
|
|
76
78
|
<select
|
|
77
79
|
className={`input y-${color}`}
|
|
@@ -64,14 +64,15 @@ const TextInput = ({
|
|
|
64
64
|
...style,
|
|
65
65
|
}}
|
|
66
66
|
>
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
67
|
+
{label && (
|
|
68
|
+
<FormLabel
|
|
69
|
+
name={name}
|
|
70
|
+
color={labelColor}
|
|
71
|
+
optional={optional}
|
|
72
|
+
>
|
|
73
|
+
{label}
|
|
74
|
+
</FormLabel>
|
|
75
|
+
)}
|
|
75
76
|
<InputWrapper {...inputWrapperProps}>
|
|
76
77
|
<input
|
|
77
78
|
id={name}
|
|
@@ -55,15 +55,15 @@ const TextareaInput = ({
|
|
|
55
55
|
.join(' ')}
|
|
56
56
|
style={style}
|
|
57
57
|
>
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
58
|
+
{label && (
|
|
59
|
+
<FormLabel
|
|
60
|
+
name={name}
|
|
61
|
+
color={labelColor}
|
|
62
|
+
optional={optional}
|
|
63
|
+
>
|
|
64
|
+
{label}
|
|
65
|
+
</FormLabel>
|
|
66
|
+
)}
|
|
67
67
|
<textarea
|
|
68
68
|
id={name}
|
|
69
69
|
className="textarea"
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/* @pareto-engineering/generator-front 1.0.12 */
|
|
2
|
+
import * as React from 'react'
|
|
3
|
+
|
|
4
|
+
import { useState } from 'react'
|
|
5
|
+
|
|
6
|
+
import PropTypes from 'prop-types'
|
|
7
|
+
|
|
8
|
+
import styleNames from '@pareto-engineering/bem/exports'
|
|
9
|
+
|
|
10
|
+
import { DraggableItem } from './common'
|
|
11
|
+
|
|
12
|
+
// Local Definitions
|
|
13
|
+
|
|
14
|
+
import './styles.scss'
|
|
15
|
+
|
|
16
|
+
const baseClassName = styleNames.base
|
|
17
|
+
|
|
18
|
+
const componentClassName = 'drag-and-drop'
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* This is the component description.
|
|
22
|
+
*/
|
|
23
|
+
const DragAndDrop = ({
|
|
24
|
+
id,
|
|
25
|
+
className:userClassName,
|
|
26
|
+
style,
|
|
27
|
+
as:Wrapper,
|
|
28
|
+
onOrderChange,
|
|
29
|
+
items,
|
|
30
|
+
// ...otherProps
|
|
31
|
+
}) => {
|
|
32
|
+
const [draggableItems, setDraggableItems] = useState(items)
|
|
33
|
+
|
|
34
|
+
const handleDrop = (e, dragOverItemIndex) => {
|
|
35
|
+
e.preventDefault()
|
|
36
|
+
const dragItemIndex = e.dataTransfer.getData('text')
|
|
37
|
+
const orderedItems = [...draggableItems]
|
|
38
|
+
const [reorderedItem] = orderedItems.splice(dragItemIndex, 1)
|
|
39
|
+
orderedItems.splice(dragOverItemIndex, 0, reorderedItem)
|
|
40
|
+
setDraggableItems(orderedItems)
|
|
41
|
+
onOrderChange?.(orderedItems)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<Wrapper
|
|
46
|
+
id={id}
|
|
47
|
+
className={[
|
|
48
|
+
|
|
49
|
+
baseClassName,
|
|
50
|
+
|
|
51
|
+
componentClassName,
|
|
52
|
+
userClassName,
|
|
53
|
+
]
|
|
54
|
+
.filter((e) => e)
|
|
55
|
+
.join(' ')}
|
|
56
|
+
style={style}
|
|
57
|
+
// {...otherProps}
|
|
58
|
+
>
|
|
59
|
+
{draggableItems.map(({
|
|
60
|
+
identifier, disabled, Content, ...rest
|
|
61
|
+
}, index) => (
|
|
62
|
+
<DraggableItem
|
|
63
|
+
draggable
|
|
64
|
+
onDrop={(e) => handleDrop(e, index)}
|
|
65
|
+
index={index}
|
|
66
|
+
key={identifier}
|
|
67
|
+
{...rest}
|
|
68
|
+
>
|
|
69
|
+
{Content}
|
|
70
|
+
</DraggableItem>
|
|
71
|
+
))}
|
|
72
|
+
</Wrapper>
|
|
73
|
+
)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
DragAndDrop.propTypes = {
|
|
77
|
+
/**
|
|
78
|
+
* The HTML id for this element
|
|
79
|
+
*/
|
|
80
|
+
id:PropTypes.string,
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* The HTML class names for this element
|
|
84
|
+
*/
|
|
85
|
+
className:PropTypes.string,
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* The React-written, css properties for this element.
|
|
89
|
+
*/
|
|
90
|
+
style:PropTypes.objectOf(PropTypes.string),
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* The html element to use to display this component.
|
|
94
|
+
*/
|
|
95
|
+
as:PropTypes.string,
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* The node list of items to be dragged around
|
|
99
|
+
*/
|
|
100
|
+
items:PropTypes.arrayOf(PropTypes.shape({
|
|
101
|
+
Content :PropTypes.node.isRequired,
|
|
102
|
+
identifier:PropTypes.string.isRequired,
|
|
103
|
+
as :PropTypes.string,
|
|
104
|
+
})).isRequired,
|
|
105
|
+
|
|
106
|
+
/*
|
|
107
|
+
* A function to be called when the draggable items are re-ordered
|
|
108
|
+
*/
|
|
109
|
+
onOrderChange:PropTypes.func,
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
DragAndDrop.defaultProps = {
|
|
113
|
+
as:'ul',
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
DragAndDrop.DraggableItem = DraggableItem
|
|
117
|
+
|
|
118
|
+
export default DragAndDrop
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/* @pareto-engineering/generator-front 1.0.12 */
|
|
2
|
+
import * as React from 'react'
|
|
3
|
+
|
|
4
|
+
import { useState } 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
|
+
const baseClassName = styleNames.base
|
|
15
|
+
|
|
16
|
+
const componentClassName = 'draggable-item'
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* This is the component description.
|
|
20
|
+
*/
|
|
21
|
+
const DraggableItem = ({
|
|
22
|
+
id,
|
|
23
|
+
className:userClassName,
|
|
24
|
+
style,
|
|
25
|
+
as:Wrapper,
|
|
26
|
+
children,
|
|
27
|
+
index,
|
|
28
|
+
...otherProps
|
|
29
|
+
}) => {
|
|
30
|
+
const [isDragging, setIsDragging] = useState(false)
|
|
31
|
+
|
|
32
|
+
const handleDragStart = (e) => {
|
|
33
|
+
setIsDragging(true)
|
|
34
|
+
e.dataTransfer.effectAllowed = 'move'
|
|
35
|
+
e.dataTransfer.setData('text/plain', index)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const handleDragEnd = () => {
|
|
39
|
+
setIsDragging(false)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const handleDragOver = (e) => {
|
|
43
|
+
e.preventDefault()
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<Wrapper
|
|
48
|
+
id={id}
|
|
49
|
+
className={[
|
|
50
|
+
baseClassName,
|
|
51
|
+
componentClassName,
|
|
52
|
+
userClassName,
|
|
53
|
+
isDragging && 'dragging',
|
|
54
|
+
]
|
|
55
|
+
.filter((e) => e)
|
|
56
|
+
.join(' ')}
|
|
57
|
+
style={style}
|
|
58
|
+
onDragStart={(e) => handleDragStart(e)}
|
|
59
|
+
onDragOver={(e) => handleDragOver(e)}
|
|
60
|
+
onDragEnd={(e) => handleDragEnd(e)}
|
|
61
|
+
{...otherProps}
|
|
62
|
+
>
|
|
63
|
+
{children}
|
|
64
|
+
</Wrapper>
|
|
65
|
+
)
|
|
66
|
+
}
|
|
67
|
+
DraggableItem.propTypes = {
|
|
68
|
+
/**
|
|
69
|
+
* The HTML id for this element
|
|
70
|
+
*/
|
|
71
|
+
id:PropTypes.string,
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* The HTML class names for this element
|
|
75
|
+
*/
|
|
76
|
+
className:PropTypes.string,
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* The React-written, css properties for this element.
|
|
80
|
+
*/
|
|
81
|
+
style:PropTypes.objectOf(PropTypes.string),
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* The children JSX
|
|
85
|
+
*/
|
|
86
|
+
children:PropTypes.node,
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* The html element to use to display this component.
|
|
90
|
+
*/
|
|
91
|
+
as:PropTypes.string,
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
DraggableItem.defaultProps = {
|
|
95
|
+
as:'li',
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export default DraggableItem
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DraggableItem } from './DraggableItem'
|
package/src/ui/g/index.js
CHANGED