@pareto-engineering/design-system 4.0.0-alpha.73 → 4.0.0-alpha.75

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 (46) hide show
  1. package/dist/cjs/a/DatePicker/DatePicker.js +162 -0
  2. package/dist/cjs/a/DatePicker/index.js +13 -0
  3. package/dist/cjs/a/DatePicker/styles.scss +380 -0
  4. package/dist/cjs/a/XMLEditor/XMLEditor.js +5 -0
  5. package/dist/cjs/a/index.js +8 -1
  6. package/dist/cjs/f/fields/SelectInput/SelectInput.js +33 -42
  7. package/dist/cjs/f/fields/SelectInput/common/Menu/Menu.js +83 -0
  8. package/dist/cjs/f/fields/SelectInput/common/Menu/index.js +13 -0
  9. package/dist/cjs/f/fields/SelectInput/common/Multiple/Multiple.js +244 -0
  10. package/dist/cjs/f/fields/SelectInput/common/Multiple/index.js +13 -0
  11. package/dist/cjs/f/fields/SelectInput/common/Single/Single.js +104 -0
  12. package/dist/cjs/f/fields/SelectInput/common/Single/index.js +13 -0
  13. package/dist/cjs/f/fields/SelectInput/common/index.js +26 -0
  14. package/dist/cjs/f/fields/SelectInput/styles.scss +149 -45
  15. package/dist/es/a/DatePicker/DatePicker.js +154 -0
  16. package/dist/es/a/DatePicker/index.js +2 -0
  17. package/dist/es/a/DatePicker/styles.scss +380 -0
  18. package/dist/es/a/XMLEditor/XMLEditor.js +5 -0
  19. package/dist/es/a/index.js +2 -1
  20. package/dist/es/f/fields/SelectInput/SelectInput.js +31 -42
  21. package/dist/es/f/fields/SelectInput/common/Menu/Menu.js +73 -0
  22. package/dist/es/f/fields/SelectInput/common/Menu/index.js +2 -0
  23. package/dist/es/f/fields/SelectInput/common/Multiple/Multiple.js +235 -0
  24. package/dist/es/f/fields/SelectInput/common/Multiple/index.js +2 -0
  25. package/dist/es/f/fields/SelectInput/common/Single/Single.js +96 -0
  26. package/dist/es/f/fields/SelectInput/common/Single/index.js +2 -0
  27. package/dist/es/f/fields/SelectInput/common/index.js +3 -0
  28. package/dist/es/f/fields/SelectInput/styles.scss +149 -45
  29. package/package.json +3 -2
  30. package/src/stories/a/DatePicker.stories.jsx +88 -0
  31. package/src/stories/f/SelectInput.stories.jsx +15 -0
  32. package/src/ui/a/DatePicker/DatePicker.jsx +201 -0
  33. package/src/ui/a/DatePicker/index.js +2 -0
  34. package/src/ui/a/DatePicker/styles.scss +380 -0
  35. package/src/ui/a/XMLEditor/XMLEditor.jsx +6 -0
  36. package/src/ui/a/index.js +1 -0
  37. package/src/ui/f/fields/SelectInput/SelectInput.jsx +34 -47
  38. package/src/ui/f/fields/SelectInput/common/Menu/Menu.jsx +103 -0
  39. package/src/ui/f/fields/SelectInput/common/Menu/index.js +2 -0
  40. package/src/ui/f/fields/SelectInput/common/Multiple/Multiple.jsx +288 -0
  41. package/src/ui/f/fields/SelectInput/common/Multiple/index.js +2 -0
  42. package/src/ui/f/fields/SelectInput/common/Single/Single.jsx +125 -0
  43. package/src/ui/f/fields/SelectInput/common/Single/index.js +2 -0
  44. package/src/ui/f/fields/SelectInput/common/index.js +3 -0
  45. package/src/ui/f/fields/SelectInput/styles.scss +149 -45
  46. package/tests/__snapshots__/Storyshots.test.js.snap +7559 -398
@@ -0,0 +1,103 @@
1
+ /* @pareto-engineering/generator-front 1.0.12 */
2
+ import * as React from 'react'
3
+
4
+ import PropTypes from 'prop-types'
5
+
6
+ import styleNames from '@pareto-engineering/bem/exports'
7
+
8
+ // Local Definitions
9
+
10
+ const baseClassName = styleNames.base
11
+
12
+ const componentClassName = 'menu'
13
+
14
+ /**
15
+ * This is the component description.
16
+ */
17
+ const Menu = React.forwardRef(({
18
+ id,
19
+ className:userClassName,
20
+ style,
21
+ items,
22
+ isOpen,
23
+ highlightedIndex,
24
+ getItemProps,
25
+ ...otherProps
26
+ }, ref) => (
27
+ <ul
28
+ id={id}
29
+ className={[
30
+
31
+ baseClassName,
32
+
33
+ componentClassName,
34
+ userClassName,
35
+ ]
36
+ .filter((e) => e)
37
+ .join(' ')}
38
+ style={style}
39
+ ref={ref}
40
+ {...otherProps}
41
+ >
42
+ {isOpen && items.map((item, index) => (
43
+ <li
44
+ key={item.label}
45
+ {...getItemProps({ item, index })}
46
+ className={[
47
+ 'item',
48
+ highlightedIndex === index && styleNames.modifierActive,
49
+ ].filter(Boolean)
50
+ .join(' ')}
51
+ >
52
+ <p>
53
+ {item.label}
54
+ </p>
55
+ </li>
56
+ ))}
57
+ </ul>
58
+ ))
59
+ Menu.propTypes = {
60
+ /**
61
+ * The HTML id for this element
62
+ */
63
+ id:PropTypes.string,
64
+
65
+ /**
66
+ * The HTML class names for this element
67
+ */
68
+ className:PropTypes.string,
69
+
70
+ /**
71
+ * The React-written, css properties for this element.
72
+ */
73
+ style:PropTypes.objectOf(PropTypes.string),
74
+
75
+ /**
76
+ * The items to be displayed in the menu
77
+ */
78
+ items:PropTypes.arrayOf(PropTypes.shape({
79
+ value:PropTypes.string,
80
+ label:PropTypes.string,
81
+ })),
82
+
83
+ /**
84
+ * Whether or not the menu is open
85
+ */
86
+ isOpen:PropTypes.bool,
87
+
88
+ /**
89
+ * The index of the highlighted item
90
+ */
91
+ highlightedIndex:PropTypes.number,
92
+
93
+ /**
94
+ * The function to get the item props
95
+ */
96
+ getItemProps:PropTypes.func,
97
+ }
98
+
99
+ Menu.defaultProps = {
100
+ // someProp:false
101
+ }
102
+
103
+ export default Menu
@@ -0,0 +1,2 @@
1
+ /* @pareto-engineering/generator-front 1.0.12 */
2
+ export { default as Menu } from './Menu'
@@ -0,0 +1,288 @@
1
+ /* @pareto-engineering/generator-front 1.0.12 */
2
+ import * as React from 'react'
3
+
4
+ import {
5
+ useState, useEffect, useMemo, useRef,
6
+ } from 'react'
7
+
8
+ import { useField } from 'formik'
9
+
10
+ import PropTypes from 'prop-types'
11
+
12
+ import { useCombobox, useMultipleSelection } from 'downshift'
13
+
14
+ import styleNames from '@pareto-engineering/bem/exports'
15
+
16
+ import { Button } from 'ui/b'
17
+
18
+ import { Popover } from 'ui/a'
19
+
20
+ import { FormDescription, FormLabel } from 'ui/f'
21
+
22
+ import { Menu } from '../Menu'
23
+
24
+ // Local Definitions
25
+
26
+ const baseClassName = styleNames.base
27
+
28
+ const componentClassName = 'multiple'
29
+
30
+ /**
31
+ * @param {Array[Object]} first - first array to check if it has an item not in the second array.
32
+ * @param {Array[Object]} second - second array to check against the first array.
33
+ *
34
+ * @returns {Boolean} - true if the first array has an item not in the second array.
35
+ */
36
+ const testIfArraysAreUnique = (first, second) => first
37
+ .filter((objInFirstArray) => !second
38
+ .some((objInSecondArray) => objInFirstArray.value === objInSecondArray.value))
39
+ .length > 0
40
+
41
+ /**
42
+ * This is the component description.
43
+ */
44
+ const Multiple = ({
45
+ id,
46
+ className:userClassName,
47
+ style,
48
+ name,
49
+ label,
50
+ labelColor,
51
+ color,
52
+ options,
53
+ validate,
54
+ optional,
55
+ description,
56
+ disabled,
57
+ autoComplete,
58
+ transformSearch,
59
+ getTagColor,
60
+ placeholder,
61
+ // ...otherProps
62
+ }) => {
63
+ const [, meta, helpers] = useField({ name, validate })
64
+
65
+ const { setValue } = helpers
66
+
67
+ const { value } = meta
68
+
69
+ const [searchInputValue, setSearchInputValue] = useState('')
70
+
71
+ const {
72
+ getSelectedItemProps,
73
+ getDropdownProps,
74
+ addSelectedItem,
75
+ removeSelectedItem,
76
+ setSelectedItems,
77
+ selectedItems,
78
+ } = useMultipleSelection({
79
+ initialSelectedItems:value || [],
80
+ })
81
+
82
+ /**
83
+ * @returns {Boolean} - Unique items from the options array so that the combobox
84
+ * shows only the options that are not yet selected.
85
+ */
86
+
87
+ const items = useMemo(() => {
88
+ const lowerCasedInputValue = searchInputValue.toLowerCase()
89
+
90
+ return options.filter((option) => {
91
+ const lowerCasedOption = option.label.toLowerCase()
92
+
93
+ return lowerCasedOption.includes(lowerCasedInputValue)
94
+ && !selectedItems.includes(option)
95
+ })
96
+ }, [searchInputValue, selectedItems])
97
+
98
+ const {
99
+ isOpen,
100
+ getLabelProps,
101
+ getMenuProps,
102
+ getInputProps,
103
+ getComboboxProps,
104
+ highlightedIndex,
105
+ getItemProps,
106
+ } = useCombobox({
107
+ inputValue :searchInputValue,
108
+ defaultHighlightedIndex:0, // after selection, highlight the first item.
109
+ selectedItem :null,
110
+ items,
111
+ circularNavigation :true,
112
+ stateReducer :(state, actionAndChanges) => {
113
+ const { changes, type } = actionAndChanges
114
+ switch (type) {
115
+ case useCombobox.stateChangeTypes.InputKeyDownEnter:
116
+ case useCombobox.stateChangeTypes.ItemClick:
117
+ return {
118
+ ...changes,
119
+ isOpen:true, // keep the menu open after selection.
120
+ }
121
+ default:
122
+ break
123
+ }
124
+ return changes
125
+ },
126
+ onStateChange:({ inputValue:newSearchInputValue, type, selectedItem }) => {
127
+ switch (type) {
128
+ case useCombobox.stateChangeTypes.InputChange: {
129
+ const transformedInput = transformSearch(newSearchInputValue)
130
+ setSearchInputValue(transformedInput)
131
+ break
132
+ }
133
+ case useCombobox.stateChangeTypes.InputKeyDownEnter:
134
+ case useCombobox.stateChangeTypes.ItemClick:
135
+ case useCombobox.stateChangeTypes.InputBlur:
136
+ if (selectedItem) {
137
+ setSearchInputValue('')
138
+ addSelectedItem(selectedItem)
139
+ }
140
+ break
141
+ default:
142
+ break
143
+ }
144
+ },
145
+ })
146
+
147
+ useEffect(() => {
148
+ if (selectedItems?.length > 0) {
149
+ setValue(selectedItems)
150
+ }
151
+ }, [selectedItems])
152
+
153
+ useEffect(() => {
154
+ if (value?.length > 0 && (
155
+ testIfArraysAreUnique(value, selectedItems)
156
+ || testIfArraysAreUnique(selectedItems, value)
157
+ )) {
158
+ setSelectedItems(value)
159
+ }
160
+ }, [value])
161
+
162
+ const parentRef = useRef(null)
163
+
164
+ return (
165
+ <div
166
+ id={id}
167
+ className={[
168
+
169
+ baseClassName,
170
+
171
+ componentClassName,
172
+ userClassName,
173
+ ]
174
+ .filter((e) => e)
175
+ .join(' ')}
176
+ style={style}
177
+ ref={parentRef}
178
+ {...getComboboxProps()}
179
+ // {...otherProps}
180
+ >
181
+ <FormLabel
182
+ className={[
183
+ baseClassName,
184
+ componentClassName,
185
+ ]
186
+ .filter((e) => e)
187
+ .join(' ')}
188
+ {...getLabelProps()}
189
+ name={name}
190
+ optional={optional}
191
+ color={labelColor}
192
+ >
193
+ {label}
194
+ </FormLabel>
195
+
196
+ {selectedItems?.length > 0 && (
197
+ <div className="selected-items">
198
+ {selectedItems.map((selectedItem, index) => (
199
+ <div
200
+ key={selectedItem.label}
201
+ {...getSelectedItemProps({ selectedItem, index })}
202
+ className="item"
203
+ >
204
+ <Button
205
+ onClick={(e) => {
206
+ e.stopPropagation()
207
+ removeSelectedItem(selectedItem)
208
+ }}
209
+ isCompact
210
+ color={getTagColor ? getTagColor(selectedItem) : color}
211
+ >
212
+ <span>{selectedItem.label}</span>
213
+ <span className="icon close">Y</span>
214
+ </Button>
215
+ </div>
216
+ ))}
217
+ </div>
218
+ )}
219
+ <div className="input-container">
220
+ <input
221
+ {...getInputProps(
222
+ getDropdownProps({ preventKeyAction: isOpen }),
223
+ )}
224
+ className="input"
225
+ disabled={disabled}
226
+ placeholder={placeholder}
227
+ autoComplete={autoComplete}
228
+ />
229
+ </div>
230
+
231
+ <FormDescription className="s-1" description={description} name={name} />
232
+ <Popover
233
+ isOpen={isOpen}
234
+ parentRef={parentRef}
235
+ >
236
+ <Menu
237
+ className={`y-${color}`}
238
+ isOpen={isOpen}
239
+ getItemProps={getItemProps}
240
+ highlightedIndex={highlightedIndex}
241
+ items={items}
242
+ {...getMenuProps()}
243
+ />
244
+ </Popover>
245
+
246
+ </div>
247
+ )
248
+ }
249
+
250
+ Multiple.propTypes = {
251
+ /**
252
+ * The HTML id for this element
253
+ */
254
+ id:PropTypes.string,
255
+
256
+ /**
257
+ * The HTML class names for this element
258
+ */
259
+ className:PropTypes.string,
260
+
261
+ /**
262
+ * The React-written, css properties for this element.
263
+ */
264
+ style:PropTypes.objectOf(PropTypes.string),
265
+
266
+ /**
267
+ * A function that transforms the search input value
268
+ */
269
+ transformSearch:PropTypes.func,
270
+
271
+ /**
272
+ * The minimum length of the search input value
273
+ */
274
+ minLength:PropTypes.number,
275
+
276
+ /**
277
+ * The base color of the component
278
+ */
279
+ color:PropTypes.string,
280
+ }
281
+
282
+ Multiple.defaultProps = {
283
+ transformSearch:(e) => e,
284
+ minLength :2,
285
+ color :'interactive',
286
+ }
287
+
288
+ export default Multiple
@@ -0,0 +1,2 @@
1
+ /* @pareto-engineering/generator-front 1.0.12 */
2
+ export { default as Multiple } from './Multiple'
@@ -0,0 +1,125 @@
1
+ /* @pareto-engineering/generator-front 1.0.12 */
2
+ import * as React from 'react'
3
+
4
+ import { useField } from 'formik'
5
+
6
+ import PropTypes from 'prop-types'
7
+
8
+ import styleNames from '@pareto-engineering/bem/exports'
9
+
10
+ import { LoadingCircle } from 'ui/a'
11
+
12
+ import { FormLabel, FormDescription } from 'ui/f'
13
+
14
+ // Local Definitions
15
+
16
+ const baseClassName = styleNames.base
17
+
18
+ const componentClassName = 'single'
19
+
20
+ /**
21
+ * This is the component description.
22
+ */
23
+ const Single = ({
24
+ id,
25
+ className:userClassName,
26
+ style,
27
+ name,
28
+ label,
29
+ labelColor,
30
+ color,
31
+ options,
32
+ validate,
33
+ optional,
34
+ description,
35
+ disabled,
36
+ isLoading,
37
+ autoComplete,
38
+ // ...otherProps
39
+ }) => {
40
+ const [field] = useField({ name, validate })
41
+
42
+ return (
43
+ <div
44
+ id={id}
45
+ className={[
46
+
47
+ baseClassName,
48
+
49
+ componentClassName,
50
+ userClassName,
51
+ ]
52
+ .filter((e) => e)
53
+ .join(' ')}
54
+ style={style}
55
+ >
56
+ <FormLabel
57
+ name={name}
58
+ color={labelColor}
59
+ optional={optional}
60
+ >
61
+ {label}
62
+ </FormLabel>
63
+ <div className={`select-wrapper${disabled ? ' disabled' : ''}`}>
64
+ <select
65
+ className={`input y-${color}`}
66
+ {...field}
67
+ value={field.value || ''}
68
+ id={name}
69
+ disabled={disabled}
70
+ autoComplete={autoComplete}
71
+ >
72
+ {
73
+ options.map((option) => {
74
+ // i.e if option is a string like "blah", return { value: "blah", label: "blah" }
75
+ const newOption = typeof option === 'string' ? { value: option, label: option } : option
76
+
77
+ return (
78
+ <option
79
+ key={newOption.value}
80
+ value={newOption.value}
81
+ disabled={newOption?.disabled || false}
82
+ >
83
+ {newOption.label}
84
+ </option>
85
+ )
86
+ })
87
+ }
88
+ </select>
89
+ {isLoading && (
90
+ <LoadingCircle className="x-main" />
91
+ )}
92
+ </div>
93
+ <FormDescription className="s-1" description={description} name={name} />
94
+ </div>
95
+ )
96
+ }
97
+
98
+ Single.propTypes = {
99
+ /**
100
+ * The HTML id for this element
101
+ */
102
+ id:PropTypes.string,
103
+
104
+ /**
105
+ * The HTML class names for this element
106
+ */
107
+ className:PropTypes.string,
108
+
109
+ /**
110
+ * The React-written, css properties for this element.
111
+ */
112
+ style:PropTypes.objectOf(PropTypes.string),
113
+
114
+ /**
115
+ * The base color of the component
116
+ */
117
+ color:PropTypes.string,
118
+
119
+ }
120
+
121
+ Single.defaultProps = {
122
+ color:'paragraph',
123
+ }
124
+
125
+ export default Single
@@ -0,0 +1,2 @@
1
+ /* @pareto-engineering/generator-front 1.0.12 */
2
+ export { default as Single } from './Single'
@@ -0,0 +1,3 @@
1
+ export { Multiple } from './Multiple'
2
+ export { Single } from './Single'
3
+ export { Menu } from './Menu'