@pareto-engineering/design-system 2.0.0-alpha.46 → 2.0.0-alpha.49
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/f/FormInput/FormInput.js +7 -0
- package/dist/cjs/f/fields/QueryCombobox/QueryCombobox.js +33 -11
- package/dist/cjs/f/fields/QueryCombobox/common/Combobox/Combobox.js +20 -9
- package/dist/cjs/f/fields/QueryCombobox/common/MultipleCombobox/MultipleCombobox.js +40 -17
- package/dist/cjs/f/fields/QueryCombobox/common/index.js +9 -1
- package/dist/cjs/f/fields/QueryCombobox/styles.scss +11 -5
- package/dist/cjs/f/fields/QuerySelect/QuerySelect.js +201 -0
- package/dist/cjs/f/fields/QuerySelect/index.js +15 -0
- package/dist/cjs/f/fields/QuerySelect/styles.scss +21 -0
- package/dist/cjs/f/fields/SelectInput/SelectInput.js +15 -3
- package/dist/cjs/f/fields/SelectInput/styles.scss +27 -14
- package/dist/cjs/f/fields/index.js +9 -1
- package/dist/es/f/FormInput/FormInput.js +8 -1
- package/dist/es/f/fields/QueryCombobox/QueryCombobox.js +34 -12
- package/dist/es/f/fields/QueryCombobox/common/Combobox/Combobox.js +20 -9
- package/dist/es/f/fields/QueryCombobox/common/MultipleCombobox/MultipleCombobox.js +40 -17
- package/dist/es/f/fields/QueryCombobox/common/index.js +2 -1
- package/dist/es/f/fields/QueryCombobox/styles.scss +11 -5
- package/dist/es/f/fields/QuerySelect/QuerySelect.js +179 -0
- package/dist/es/f/fields/QuerySelect/index.js +2 -0
- package/dist/es/f/fields/QuerySelect/styles.scss +21 -0
- package/dist/es/f/fields/SelectInput/SelectInput.js +14 -3
- package/dist/es/f/fields/SelectInput/styles.scss +27 -14
- package/dist/es/f/fields/index.js +2 -1
- package/package.json +2 -2
- package/src/__snapshots__/Storyshots.test.js.snap +783 -237
- package/src/local.scss +3 -3
- package/src/stories/f/FormInput.stories.jsx +122 -4
- package/src/stories/f/QueryCombobox.stories.jsx +59 -10
- package/src/stories/f/QuerySelect.stories.jsx +134 -0
- package/src/stories/f/__generated__/FormInputAllTaskStatusesQuery.graphql.js +122 -0
- package/src/stories/f/__generated__/QuerySelectAllTaskStatusesQuery.graphql.js +122 -0
- package/src/ui/f/FormInput/FormInput.jsx +10 -0
- package/src/ui/f/fields/QueryCombobox/QueryCombobox.jsx +34 -14
- package/src/ui/f/fields/QueryCombobox/common/Combobox/Combobox.jsx +15 -7
- package/src/ui/f/fields/QueryCombobox/common/MultipleCombobox/MultipleCombobox.jsx +318 -0
- package/src/ui/f/fields/QueryCombobox/common/MultipleCombobox/index.js +2 -0
- package/src/ui/f/fields/QueryCombobox/common/index.js +1 -0
- package/src/ui/f/fields/QueryCombobox/styles.scss +11 -5
- package/src/ui/f/fields/QuerySelect/QuerySelect.jsx +200 -0
- package/src/ui/f/fields/QuerySelect/index.js +2 -0
- package/src/ui/f/fields/SelectInput/SelectInput.jsx +16 -3
- package/src/ui/f/fields/SelectInput/styles.scss +27 -14
- package/src/ui/f/fields/index.js +1 -0
|
@@ -74,6 +74,13 @@ var FormInput = _ref => {
|
|
|
74
74
|
}, otherProps));
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
if (type === 'query-select') {
|
|
78
|
+
return /*#__PURE__*/React.createElement(_fields.QuerySelect, _extends({
|
|
79
|
+
className: newClassName,
|
|
80
|
+
disabled: disabled
|
|
81
|
+
}, otherProps));
|
|
82
|
+
}
|
|
83
|
+
|
|
77
84
|
if (extraTypes !== null && extraTypes !== void 0 && extraTypes[type]) {
|
|
78
85
|
var Component = extraTypes[type];
|
|
79
86
|
return /*#__PURE__*/React.createElement(Component, _extends({
|
|
@@ -36,17 +36,18 @@ var QueryCombobox = _ref => {
|
|
|
36
36
|
style,
|
|
37
37
|
className,
|
|
38
38
|
query,
|
|
39
|
-
|
|
39
|
+
multiple,
|
|
40
40
|
name,
|
|
41
41
|
label,
|
|
42
42
|
color,
|
|
43
43
|
description,
|
|
44
44
|
disabled,
|
|
45
45
|
debounceMs,
|
|
46
|
-
graphQlNode,
|
|
47
46
|
searchVariable,
|
|
48
47
|
extraVariables,
|
|
49
|
-
optionsKeyMap
|
|
48
|
+
optionsKeyMap,
|
|
49
|
+
minLength,
|
|
50
|
+
transformSearch // ...otherProps
|
|
50
51
|
|
|
51
52
|
} = _ref;
|
|
52
53
|
(0, React.useLayoutEffect)(() => {
|
|
@@ -64,6 +65,10 @@ var QueryCombobox = _ref => {
|
|
|
64
65
|
var environment = (0, _reactRelay.useRelayEnvironment)();
|
|
65
66
|
var [isFetching, setIsFetching] = (0, React.useState)(false);
|
|
66
67
|
var [options, setOptions] = (0, React.useState)([]);
|
|
68
|
+
var {
|
|
69
|
+
graphql,
|
|
70
|
+
accessor
|
|
71
|
+
} = query;
|
|
67
72
|
|
|
68
73
|
var getOptions = inputValue => {
|
|
69
74
|
if (isFetching) return;
|
|
@@ -75,7 +80,7 @@ var QueryCombobox = _ref => {
|
|
|
75
80
|
variables = _objectSpread(_objectSpread({}, variables), extraVariables);
|
|
76
81
|
}
|
|
77
82
|
|
|
78
|
-
(0, _reactRelay.fetchQuery)(environment,
|
|
83
|
+
(0, _reactRelay.fetchQuery)(environment, graphql, variables).subscribe({
|
|
79
84
|
start: () => {
|
|
80
85
|
setIsFetching(true);
|
|
81
86
|
},
|
|
@@ -87,7 +92,7 @@ var QueryCombobox = _ref => {
|
|
|
87
92
|
if (setError) setError(fetchError.message);
|
|
88
93
|
},
|
|
89
94
|
next: data => {
|
|
90
|
-
setOptions(data[
|
|
95
|
+
setOptions(data[accessor].edges.map(_ref2 => {
|
|
91
96
|
var {
|
|
92
97
|
node
|
|
93
98
|
} = _ref2;
|
|
@@ -115,9 +120,11 @@ var QueryCombobox = _ref => {
|
|
|
115
120
|
value,
|
|
116
121
|
color,
|
|
117
122
|
isFetching,
|
|
118
|
-
className
|
|
123
|
+
className,
|
|
124
|
+
minLength,
|
|
125
|
+
transformSearch
|
|
119
126
|
};
|
|
120
|
-
var Input = _common.Combobox;
|
|
127
|
+
var Input = multiple ? _common.MultipleCombobox : _common.Combobox;
|
|
121
128
|
return /*#__PURE__*/React.createElement(Input, comboboxProps);
|
|
122
129
|
};
|
|
123
130
|
|
|
@@ -168,9 +175,12 @@ QueryCombobox.propTypes = {
|
|
|
168
175
|
debounceMs: _propTypes.default.number,
|
|
169
176
|
|
|
170
177
|
/**
|
|
171
|
-
* The query to fetch the options
|
|
178
|
+
* The graphql query to fetch the options and the accessor to destructure the results from
|
|
172
179
|
*/
|
|
173
|
-
query: _propTypes.default.
|
|
180
|
+
query: _propTypes.default.shape({
|
|
181
|
+
accessor: _propTypes.default.string,
|
|
182
|
+
graphql: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.object]).isRequired
|
|
183
|
+
}),
|
|
174
184
|
|
|
175
185
|
/**
|
|
176
186
|
* The extra variables required to be used in the query.
|
|
@@ -199,7 +209,17 @@ QueryCombobox.propTypes = {
|
|
|
199
209
|
/**
|
|
200
210
|
* The variable to be used to search the data
|
|
201
211
|
*/
|
|
202
|
-
searchVariable: _propTypes.default.string
|
|
212
|
+
searchVariable: _propTypes.default.string,
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* The minimum length of the search input to start fetching the options
|
|
216
|
+
*/
|
|
217
|
+
minLength: _propTypes.default.number,
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* The function to transform the search input
|
|
221
|
+
*/
|
|
222
|
+
transformSearch: _propTypes.default.func
|
|
203
223
|
};
|
|
204
224
|
QueryCombobox.defaultProps = {
|
|
205
225
|
optionsKeyMap: {
|
|
@@ -208,7 +228,9 @@ QueryCombobox.defaultProps = {
|
|
|
208
228
|
},
|
|
209
229
|
multiple: false,
|
|
210
230
|
color: 'background2',
|
|
211
|
-
searchVariable: 'search'
|
|
231
|
+
searchVariable: 'search',
|
|
232
|
+
transformSearch: search => search,
|
|
233
|
+
minLength: 2
|
|
212
234
|
};
|
|
213
235
|
var _default = QueryCombobox;
|
|
214
236
|
exports.default = _default;
|
|
@@ -47,8 +47,9 @@ var Combobox = _ref => {
|
|
|
47
47
|
description,
|
|
48
48
|
value,
|
|
49
49
|
color,
|
|
50
|
-
|
|
51
|
-
isFetching
|
|
50
|
+
minLength,
|
|
51
|
+
isFetching,
|
|
52
|
+
transformSearch // ...otherProps
|
|
52
53
|
|
|
53
54
|
} = _ref;
|
|
54
55
|
var {
|
|
@@ -69,7 +70,11 @@ var Combobox = _ref => {
|
|
|
69
70
|
var {
|
|
70
71
|
inputValue
|
|
71
72
|
} = _ref2;
|
|
72
|
-
|
|
73
|
+
var transformedInput = transformSearch(inputValue);
|
|
74
|
+
|
|
75
|
+
if (transformedInput.length > minLength) {
|
|
76
|
+
getOptions(transformedInput);
|
|
77
|
+
}
|
|
73
78
|
}
|
|
74
79
|
}); // If the user has selected an item, we'll set the value of the field
|
|
75
80
|
// or if the combobox state has a selected item, we'll set the value to the formik state
|
|
@@ -88,7 +93,7 @@ var Combobox = _ref => {
|
|
|
88
93
|
var parentRef = (0, React.useRef)(null);
|
|
89
94
|
return /*#__PURE__*/React.createElement("div", {
|
|
90
95
|
id: id,
|
|
91
|
-
className: [baseClassName, componentClassName, userClassName, "y-".concat(color)
|
|
96
|
+
className: [baseClassName, componentClassName, userClassName, "y-".concat(color)].filter(e => e).join(' '),
|
|
92
97
|
style: style,
|
|
93
98
|
ref: parentRef
|
|
94
99
|
}, /*#__PURE__*/React.createElement(_.FormLabel, _extends({}, getLabelProps(), {
|
|
@@ -97,7 +102,9 @@ var Combobox = _ref => {
|
|
|
97
102
|
className: "input-wrapper"
|
|
98
103
|
}), /*#__PURE__*/React.createElement("input", _extends({}, getInputProps(), {
|
|
99
104
|
className: "input"
|
|
100
|
-
})), isFetching && /*#__PURE__*/React.createElement(_a.LoadingCircle,
|
|
105
|
+
})), isFetching && /*#__PURE__*/React.createElement(_a.LoadingCircle, {
|
|
106
|
+
className: "x-main2"
|
|
107
|
+
})), /*#__PURE__*/React.createElement(_a.Popover, {
|
|
101
108
|
isOpen: isOpen,
|
|
102
109
|
parentRef: parentRef
|
|
103
110
|
}, /*#__PURE__*/React.createElement(_Menu.Menu, _extends({
|
|
@@ -183,12 +190,16 @@ Combobox.propTypes = {
|
|
|
183
190
|
isFetching: _propTypes.default.bool.isRequired,
|
|
184
191
|
|
|
185
192
|
/**
|
|
186
|
-
* The
|
|
193
|
+
* The minimum length of the search input to start fetching the options
|
|
194
|
+
*/
|
|
195
|
+
minLength: _propTypes.default.number,
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* The function to transform the search input
|
|
187
199
|
*/
|
|
188
|
-
|
|
200
|
+
transformSearch: _propTypes.default.func
|
|
189
201
|
};
|
|
190
|
-
Combobox.defaultProps = {
|
|
191
|
-
loadingCircleColor: 'main2'
|
|
202
|
+
Combobox.defaultProps = {// someProp: false
|
|
192
203
|
};
|
|
193
204
|
var _default = Combobox;
|
|
194
205
|
exports.default = _default;
|
|
@@ -65,7 +65,8 @@ var MultipleCombobox = _ref => {
|
|
|
65
65
|
value,
|
|
66
66
|
color,
|
|
67
67
|
isFetching,
|
|
68
|
-
|
|
68
|
+
minLength,
|
|
69
|
+
transformSearch // ...otherProps
|
|
69
70
|
|
|
70
71
|
} = _ref;
|
|
71
72
|
var [searchInputValue, setSearchInputValue] = (0, React.useState)('');
|
|
@@ -79,8 +80,12 @@ var MultipleCombobox = _ref => {
|
|
|
79
80
|
} = (0, _downshift.useMultipleSelection)({
|
|
80
81
|
initialSelectedItems: value || []
|
|
81
82
|
});
|
|
83
|
+
/**
|
|
84
|
+
* @returns {Boolean} - Unique items from the options array so that the combobox
|
|
85
|
+
* shows only the options that are not yet selected.
|
|
86
|
+
*/
|
|
82
87
|
|
|
83
|
-
var getFilteredItems = () => items.filter(item => selectedItems.findIndex(e => e.label === item.label) < 0
|
|
88
|
+
var getFilteredItems = () => items.filter(item => selectedItems.findIndex(e => e.label === item.label) < 0);
|
|
84
89
|
|
|
85
90
|
var {
|
|
86
91
|
isOpen,
|
|
@@ -126,9 +131,16 @@ var MultipleCombobox = _ref => {
|
|
|
126
131
|
|
|
127
132
|
switch (type) {
|
|
128
133
|
case _downshift.useCombobox.stateChangeTypes.InputChange:
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
134
|
+
{
|
|
135
|
+
var transformedInput = transformSearch(newSearchInputValue);
|
|
136
|
+
|
|
137
|
+
if (transformedInput.length > minLength) {
|
|
138
|
+
getOptions(transformedInput);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
setSearchInputValue(newSearchInputValue);
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
132
144
|
|
|
133
145
|
case _downshift.useCombobox.stateChangeTypes.InputKeyDownEnter:
|
|
134
146
|
case _downshift.useCombobox.stateChangeTypes.ItemClick:
|
|
@@ -158,33 +170,40 @@ var MultipleCombobox = _ref => {
|
|
|
158
170
|
var parentRef = (0, React.useRef)(null);
|
|
159
171
|
return /*#__PURE__*/React.createElement("div", {
|
|
160
172
|
id: id,
|
|
161
|
-
className: [baseClassName, componentClassName, userClassName, "y-".concat(color)
|
|
173
|
+
className: [baseClassName, componentClassName, userClassName, "y-".concat(color)].filter(e => e).join(' '),
|
|
162
174
|
style: style
|
|
163
175
|
}, /*#__PURE__*/React.createElement(_.FormLabel, _extends({}, getLabelProps(), {
|
|
164
176
|
name: name
|
|
165
|
-
}), label), /*#__PURE__*/React.createElement("div", {
|
|
177
|
+
}), label), (selectedItems === null || selectedItems === void 0 ? void 0 : selectedItems.length) > 0 && /*#__PURE__*/React.createElement("div", {
|
|
166
178
|
className: "selected-items"
|
|
167
|
-
}, selectedItems
|
|
179
|
+
}, selectedItems.map((selectedItem, index) => /*#__PURE__*/React.createElement("div", _extends({
|
|
168
180
|
key: selectedItem.label
|
|
169
181
|
}, getSelectedItemProps({
|
|
170
182
|
selectedItem,
|
|
171
183
|
index
|
|
172
|
-
})
|
|
173
|
-
className: "
|
|
184
|
+
}), {
|
|
185
|
+
className: "item"
|
|
186
|
+
}), /*#__PURE__*/React.createElement(_b.Button, {
|
|
174
187
|
onClick: e => {
|
|
175
188
|
e.stopPropagation();
|
|
176
189
|
removeSelectedItem(selectedItem);
|
|
177
190
|
},
|
|
178
191
|
isCompact: true,
|
|
179
192
|
isSimple: true,
|
|
180
|
-
color:
|
|
181
|
-
},
|
|
193
|
+
color: color
|
|
194
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
195
|
+
className: "v25 mr-v"
|
|
196
|
+
}, selectedItem.label), /*#__PURE__*/React.createElement("span", {
|
|
197
|
+
className: "f-icons close"
|
|
198
|
+
}, "Y"))))), /*#__PURE__*/React.createElement("div", _extends({}, getComboboxProps(), {
|
|
182
199
|
className: "input-wrapper"
|
|
183
200
|
}), /*#__PURE__*/React.createElement("input", _extends({}, getInputProps(getDropdownProps({
|
|
184
201
|
preventKeyAction: isOpen
|
|
185
202
|
})), {
|
|
186
203
|
className: "input"
|
|
187
|
-
})), isFetching && /*#__PURE__*/React.createElement(_a.LoadingCircle,
|
|
204
|
+
})), isFetching && /*#__PURE__*/React.createElement(_a.LoadingCircle, {
|
|
205
|
+
className: "x-main2"
|
|
206
|
+
})), /*#__PURE__*/React.createElement(_a.Popover, {
|
|
188
207
|
isOpen: isOpen,
|
|
189
208
|
parentRef: parentRef
|
|
190
209
|
}, /*#__PURE__*/React.createElement(_Menu.Menu, _extends({
|
|
@@ -270,12 +289,16 @@ MultipleCombobox.propTypes = {
|
|
|
270
289
|
isFetching: _propTypes.default.bool.isRequired,
|
|
271
290
|
|
|
272
291
|
/**
|
|
273
|
-
* The
|
|
292
|
+
* The minimum length of the search input to start fetching the options
|
|
293
|
+
*/
|
|
294
|
+
minLength: _propTypes.default.number,
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* The function to transform the search input
|
|
274
298
|
*/
|
|
275
|
-
|
|
299
|
+
transformSearch: _propTypes.default.func
|
|
276
300
|
};
|
|
277
|
-
MultipleCombobox.defaultProps = {
|
|
278
|
-
loadingCircleColor: 'main2'
|
|
301
|
+
MultipleCombobox.defaultProps = {// someProp: false
|
|
279
302
|
};
|
|
280
303
|
var _default = MultipleCombobox;
|
|
281
304
|
exports.default = _default;
|
|
@@ -15,7 +15,15 @@ Object.defineProperty(exports, "Combobox", {
|
|
|
15
15
|
return _Combobox.Combobox;
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
|
+
Object.defineProperty(exports, "MultipleCombobox", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function get() {
|
|
21
|
+
return _MultipleCombobox.MultipleCombobox;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
18
24
|
|
|
19
25
|
var _Menu = require("./Menu");
|
|
20
26
|
|
|
21
|
-
var _Combobox = require("./Combobox");
|
|
27
|
+
var _Combobox = require("./Combobox");
|
|
28
|
+
|
|
29
|
+
var _MultipleCombobox = require("./MultipleCombobox");
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
$default-input-padding: .75em .75em .55em;
|
|
6
6
|
$default-padding: 1em;
|
|
7
7
|
$default-margin: 1em;
|
|
8
|
+
$default-gap: 1em;
|
|
8
9
|
$default-loading-circle-displacement: 1em;
|
|
9
10
|
|
|
10
11
|
.#{bem.$base}.combobox,
|
|
@@ -73,12 +74,17 @@ $default-loading-circle-displacement: 1em;
|
|
|
73
74
|
.#{bem.$base}.multiple-combobox {
|
|
74
75
|
>.selected-items {
|
|
75
76
|
display: flex;
|
|
77
|
+
gap: $default-gap / 2;
|
|
78
|
+
flex-wrap: wrap;
|
|
79
|
+
margin-bottom: $default-margin / 2;
|
|
76
80
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
+
>.item {
|
|
82
|
+
background-color: var(--main2);
|
|
83
|
+
padding: $default-padding / 4;
|
|
81
84
|
|
|
82
|
-
|
|
85
|
+
.close {
|
|
86
|
+
font-size: calc(var(--s-3) * 1em);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
83
89
|
}
|
|
84
90
|
}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var React = _interopRequireWildcard(require("react"));
|
|
9
|
+
|
|
10
|
+
var _reactRelay = require("react-relay");
|
|
11
|
+
|
|
12
|
+
var _formik = require("formik");
|
|
13
|
+
|
|
14
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
15
|
+
|
|
16
|
+
var _ = require("../..");
|
|
17
|
+
|
|
18
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
+
|
|
20
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
21
|
+
|
|
22
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
23
|
+
|
|
24
|
+
/* @pareto-engineering/generator-front 1.0.12 */
|
|
25
|
+
// Local Definitions
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* This is the component description.
|
|
29
|
+
*/
|
|
30
|
+
var QuerySelect = _ref => {
|
|
31
|
+
var {
|
|
32
|
+
id,
|
|
33
|
+
className: userClassName,
|
|
34
|
+
style,
|
|
35
|
+
name,
|
|
36
|
+
label,
|
|
37
|
+
query,
|
|
38
|
+
variables,
|
|
39
|
+
optionsKeyMap,
|
|
40
|
+
description,
|
|
41
|
+
disabled,
|
|
42
|
+
color,
|
|
43
|
+
loadingOption,
|
|
44
|
+
defaultOption // ...otherProps
|
|
45
|
+
|
|
46
|
+
} = _ref;
|
|
47
|
+
var [,, helpers] = (0, _formik.useField)(name);
|
|
48
|
+
var {
|
|
49
|
+
setError
|
|
50
|
+
} = helpers;
|
|
51
|
+
var environment = (0, _reactRelay.useRelayEnvironment)();
|
|
52
|
+
var [isFetching, setIsFetching] = (0, React.useState)(false);
|
|
53
|
+
var [options, setOptions] = (0, React.useState)([]);
|
|
54
|
+
var {
|
|
55
|
+
graphql,
|
|
56
|
+
accessor
|
|
57
|
+
} = query;
|
|
58
|
+
|
|
59
|
+
var getOptions = () => {
|
|
60
|
+
if (isFetching) return;
|
|
61
|
+
(0, _reactRelay.fetchQuery)(environment, graphql, variables).subscribe({
|
|
62
|
+
start: () => {
|
|
63
|
+
setIsFetching(true);
|
|
64
|
+
setOptions([loadingOption]);
|
|
65
|
+
},
|
|
66
|
+
complete: () => {
|
|
67
|
+
setIsFetching(false);
|
|
68
|
+
},
|
|
69
|
+
error: fetchError => {
|
|
70
|
+
setIsFetching(false);
|
|
71
|
+
if (setError) setError(fetchError.message);
|
|
72
|
+
},
|
|
73
|
+
next: data => {
|
|
74
|
+
setOptions([defaultOption, ...data[accessor].edges.map(_ref2 => {
|
|
75
|
+
var {
|
|
76
|
+
node
|
|
77
|
+
} = _ref2;
|
|
78
|
+
return {
|
|
79
|
+
value: node[optionsKeyMap.value],
|
|
80
|
+
label: node[optionsKeyMap.label]
|
|
81
|
+
};
|
|
82
|
+
})]);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
(0, React.useEffect)(() => {
|
|
88
|
+
getOptions();
|
|
89
|
+
}, [variables]);
|
|
90
|
+
return /*#__PURE__*/React.createElement(_.SelectInput, {
|
|
91
|
+
id: id,
|
|
92
|
+
className: userClassName,
|
|
93
|
+
style: style,
|
|
94
|
+
name: name,
|
|
95
|
+
label: label,
|
|
96
|
+
color: color,
|
|
97
|
+
description: description,
|
|
98
|
+
disabled: isFetching || disabled,
|
|
99
|
+
options: options,
|
|
100
|
+
isLoading: isFetching
|
|
101
|
+
});
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
QuerySelect.propTypes = {
|
|
105
|
+
/**
|
|
106
|
+
* The HTML id for this element
|
|
107
|
+
*/
|
|
108
|
+
id: _propTypes.default.string,
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* The HTML class names for this element
|
|
112
|
+
*/
|
|
113
|
+
className: _propTypes.default.string,
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* The React-written, css properties for this element.
|
|
117
|
+
*/
|
|
118
|
+
style: _propTypes.default.objectOf(_propTypes.default.string),
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* The name of the custom select input
|
|
122
|
+
*/
|
|
123
|
+
name: _propTypes.default.string,
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* The label of the custom select input
|
|
127
|
+
*/
|
|
128
|
+
label: _propTypes.default.string,
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* The custom select input description
|
|
132
|
+
*/
|
|
133
|
+
description: _propTypes.default.string,
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Whether the input should be disabled
|
|
137
|
+
*/
|
|
138
|
+
disabled: _propTypes.default.bool,
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* The base color of the custom select input
|
|
142
|
+
*/
|
|
143
|
+
color: _propTypes.default.string,
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* The graphql query to fetch the options and the accessor to destructure the results from
|
|
147
|
+
*/
|
|
148
|
+
query: _propTypes.default.shape({
|
|
149
|
+
accessor: _propTypes.default.string,
|
|
150
|
+
graphql: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.object]).isRequired
|
|
151
|
+
}),
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* The variables that might be required to be used in the query to fetch
|
|
155
|
+
* select options.
|
|
156
|
+
*/
|
|
157
|
+
variables: _propTypes.default.objectOf(_propTypes.default.string),
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* The select option keys to be used to map the data to the select options.
|
|
161
|
+
* i.e `{ value: 'id', label: 'name' }`
|
|
162
|
+
*/
|
|
163
|
+
optionsKeyMap: _propTypes.default.shape({
|
|
164
|
+
value: _propTypes.default.string.isRequired,
|
|
165
|
+
label: _propTypes.default.string.isRequired
|
|
166
|
+
}),
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* The default select option for the query select
|
|
170
|
+
*/
|
|
171
|
+
defaultOption: _propTypes.default.shape({
|
|
172
|
+
value: _propTypes.default.string.isRequired,
|
|
173
|
+
label: _propTypes.default.string.isRequired,
|
|
174
|
+
disabled: _propTypes.default.bool.isRequired
|
|
175
|
+
}),
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* The option to dipslayed when the select options are being fetched
|
|
179
|
+
*/
|
|
180
|
+
loadingOption: _propTypes.default.shape({
|
|
181
|
+
value: _propTypes.default.string.isRequired,
|
|
182
|
+
label: _propTypes.default.string.isRequired,
|
|
183
|
+
disabled: _propTypes.default.bool.isRequired
|
|
184
|
+
})
|
|
185
|
+
};
|
|
186
|
+
QuerySelect.defaultProps = {
|
|
187
|
+
disabled: false,
|
|
188
|
+
color: 'background2',
|
|
189
|
+
defaultOption: {
|
|
190
|
+
value: '',
|
|
191
|
+
label: 'Select an option',
|
|
192
|
+
disabled: true
|
|
193
|
+
},
|
|
194
|
+
loadingOption: {
|
|
195
|
+
value: '',
|
|
196
|
+
label: 'Fetching Options',
|
|
197
|
+
disabled: true
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
var _default = QuerySelect;
|
|
201
|
+
exports.default = _default;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "QuerySelect", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _QuerySelect.default;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
var _QuerySelect = _interopRequireDefault(require("./QuerySelect"));
|
|
14
|
+
|
|
15
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/* @pareto-engineering/generator-front 1.0.12 */
|
|
2
|
+
@use "@pareto-engineering/bem";
|
|
3
|
+
|
|
4
|
+
$default-loading-circle-displacement: .8em;
|
|
5
|
+
|
|
6
|
+
.#{bem.$base}.query-select {
|
|
7
|
+
position: relative;
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
>.#{bem.$base}.select-input {
|
|
11
|
+
select:disabled {
|
|
12
|
+
appearance: none;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
>.#{bem.$base}.loading-circle {
|
|
17
|
+
position: absolute;
|
|
18
|
+
right: $default-loading-circle-displacement;
|
|
19
|
+
bottom: $default-loading-circle-displacement;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -13,6 +13,8 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
|
13
13
|
|
|
14
14
|
var _bem = _interopRequireDefault(require("@pareto-engineering/bem"));
|
|
15
15
|
|
|
16
|
+
var _a = require("../../../a");
|
|
17
|
+
|
|
16
18
|
var _common = require("../../common");
|
|
17
19
|
|
|
18
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -41,7 +43,8 @@ var SelectInput = _ref => {
|
|
|
41
43
|
options,
|
|
42
44
|
validate,
|
|
43
45
|
description,
|
|
44
|
-
disabled
|
|
46
|
+
disabled,
|
|
47
|
+
isLoading // ...otherProps
|
|
45
48
|
|
|
46
49
|
} = _ref;
|
|
47
50
|
(0, React.useLayoutEffect)(() => {
|
|
@@ -58,7 +61,9 @@ var SelectInput = _ref => {
|
|
|
58
61
|
|
|
59
62
|
}, /*#__PURE__*/React.createElement(_common.FormLabel, {
|
|
60
63
|
name: name
|
|
61
|
-
}, label), /*#__PURE__*/React.createElement("
|
|
64
|
+
}, label), /*#__PURE__*/React.createElement("div", {
|
|
65
|
+
className: "select-wrapper"
|
|
66
|
+
}, /*#__PURE__*/React.createElement("select", _extends({
|
|
62
67
|
className: "input"
|
|
63
68
|
}, field, {
|
|
64
69
|
value: field.value || '',
|
|
@@ -75,6 +80,8 @@ var SelectInput = _ref => {
|
|
|
75
80
|
value: newOption.value,
|
|
76
81
|
disabled: (newOption === null || newOption === void 0 ? void 0 : newOption.disabled) || false
|
|
77
82
|
}, newOption.label);
|
|
83
|
+
})), isLoading && /*#__PURE__*/React.createElement(_a.LoadingCircle, {
|
|
84
|
+
className: "x-main2"
|
|
78
85
|
})), (description || meta.touched && meta.error) && /*#__PURE__*/React.createElement(_common.FormDescription, {
|
|
79
86
|
isError: !!meta.error,
|
|
80
87
|
className: "v50 mt-v s-1"
|
|
@@ -134,7 +141,12 @@ SelectInput.propTypes = {
|
|
|
134
141
|
/**
|
|
135
142
|
* The color of the select input
|
|
136
143
|
*/
|
|
137
|
-
color: _propTypes.default.string
|
|
144
|
+
color: _propTypes.default.string,
|
|
145
|
+
|
|
146
|
+
/*
|
|
147
|
+
* Whether the query that is fetching the select options is still in flight
|
|
148
|
+
*/
|
|
149
|
+
isLoading: _propTypes.default.bool
|
|
138
150
|
};
|
|
139
151
|
SelectInput.defaultProps = {
|
|
140
152
|
disabled: false,
|
|
@@ -16,22 +16,35 @@ $default-margin: 1em;
|
|
|
16
16
|
margin-bottom: $default-margin
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
19
|
+
.select-wrapper {
|
|
20
|
+
position: relative;
|
|
21
|
+
|
|
22
|
+
>.#{bem.$base}.loading-circle {
|
|
23
|
+
position: absolute;
|
|
24
|
+
right: 0;
|
|
25
|
+
top: 50%;
|
|
26
|
+
transform: translateY(-50%);
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
>.input {
|
|
30
|
+
width: 100%;
|
|
31
|
+
border: var(--theme-border-style) var(--dark-y);
|
|
32
|
+
background: var(--light-y);
|
|
33
|
+
color: var(--on-y);
|
|
34
|
+
padding: $default-padding;
|
|
35
|
+
|
|
36
|
+
&:not(:disabled):hover {
|
|
37
|
+
border: var(--theme-border-style) var(--light-background4);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
&:disabled {
|
|
41
|
+
background-color: var(--dark-y);
|
|
42
|
+
appearance: none;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
&:focus {
|
|
46
|
+
background: var(--y);
|
|
47
|
+
}
|
|
35
48
|
}
|
|
36
49
|
}
|
|
37
50
|
}
|