@k-int/stripes-kint-components 2.7.1 → 2.8.2
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/CHANGELOG.md +14 -1
- package/es/index.js +20 -0
- package/es/lib/ActionList/ActionList.js +7 -2
- package/es/lib/ActionList/ActionListFieldArray.js +11 -5
- package/es/lib/CustomProperties/Config/CustomPropertiesSettings.js +3 -1
- package/es/lib/CustomProperties/View/CustomPropertiesViewCtx.js +1 -1
- package/es/lib/CycleButton/CycleButton.js +2 -1
- package/es/lib/EditableRefdataCategoryList/EditableRefdataCategoryList.js +11 -2
- package/es/lib/EditableRefdataList/EditableRefdataList.js +11 -2
- package/es/lib/IconSelect/IconSelect.js +105 -110
- package/es/lib/RichSelect/RichSelect.js +252 -0
- package/es/lib/RichSelect/index.js +23 -0
- package/es/lib/RichSelect/useSelectedOption.js +39 -0
- package/es/lib/utils/index.js +8 -0
- package/es/lib/utils/parseErrorResponse.js +91 -0
- package/package.json +1 -1
- package/src/index.js +2 -0
- package/src/lib/ActionList/ActionList.js +8 -1
- package/src/lib/ActionList/ActionListFieldArray.js +13 -5
- package/src/lib/ActionList/README.md +1 -0
- package/src/lib/CustomProperties/Config/CustomPropertiesSettings.js +3 -1
- package/src/lib/CustomProperties/View/CustomPropertiesViewCtx.js +1 -1
- package/src/lib/CycleButton/CycleButton.js +3 -2
- package/src/lib/EditableRefdataCategoryList/EditableRefdataCategoryList.js +10 -2
- package/src/lib/EditableRefdataList/EditableRefdataList.js +10 -2
- package/src/lib/IconSelect/IconSelect.js +94 -113
- package/src/lib/IconSelect/README.md +6 -2
- package/src/lib/RichSelect/README.md +56 -0
- package/src/lib/RichSelect/RichSelect.js +230 -0
- package/src/lib/RichSelect/index.js +2 -0
- package/src/lib/RichSelect/useSelectedOption.js +14 -0
- package/src/lib/hooks/useMutateRefdataCategory.js +3 -3
- package/src/lib/utils/index.js +3 -0
- package/src/lib/utils/parseErrorResponse.js +18 -0
- package/styles/RichSelect.css +7 -0
- package/translations/stripes-kint-components/ar.json +2 -1
- package/translations/stripes-kint-components/cs_CZ.json +2 -1
- package/translations/stripes-kint-components/de.json +2 -1
- package/translations/stripes-kint-components/en.json +2 -1
- package/translations/stripes-kint-components/es.json +2 -1
- package/translations/stripes-kint-components/hi_IN.json +2 -1
- package/translations/stripes-kint-components/hu.json +2 -1
- package/translations/stripes-kint-components/it_IT.json +2 -1
- package/translations/stripes-kint-components/ja.json +2 -1
- package/translations/stripes-kint-components/ko.json +2 -1
- package/translations/stripes-kint-components/pt_PT.json +2 -1
- package/translations/stripes-kint-components/ru.json +2 -1
- package/translations/stripes-kint-components/sv.json +2 -1
- package/translations/stripes-kint-components/zh_CN.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
|
-
## 2.
|
|
1
|
+
## 2.8.2 2022-07-25
|
|
2
|
+
* New util function `parseErrorResponse`, used in places where we catch http errors, allows for text only response bodies
|
|
3
|
+
|
|
4
|
+
## 2.8.1 2022-07-21
|
|
5
|
+
* ActionList previously added actionListItems directly to cached object--sometimes this caused the react-query cache ITSELF to update, although I'm not sure why here and not anywhere else. Fixed by creating a clone internally in ActionListFieldArray and assigning actionListActions on that.
|
|
6
|
+
|
|
7
|
+
## 2.8.0 2022-07-15
|
|
2
8
|
* Fixed bug where non-createable fields which were editable would display a field on creation.
|
|
9
|
+
* RichSelect -- A Select style form component allowing for more custom render behaviour.
|
|
10
|
+
* Refactored IconSelect to use RichSelect under the hood
|
|
11
|
+
* EditableRefdataList/EditableRefdataCategoryList Added validation to prevent attempting null save
|
|
12
|
+
* PropTypes updated
|
|
13
|
+
* ActionList Save button is now disabled if the form has submissionErrors.
|
|
14
|
+
* ActionList Added a prop to bootstrap defaults in while adding new object inline.
|
|
15
|
+
* Linting and refactoring
|
|
3
16
|
|
|
4
17
|
## 2.7.0 2022-07-05
|
|
5
18
|
* Fixed missing translation issue
|
package/es/index.js
CHANGED
|
@@ -155,6 +155,12 @@ Object.defineProperty(exports, "RefdataButtons", {
|
|
|
155
155
|
return _RefdataButtons.default;
|
|
156
156
|
}
|
|
157
157
|
});
|
|
158
|
+
Object.defineProperty(exports, "RichSelect", {
|
|
159
|
+
enumerable: true,
|
|
160
|
+
get: function get() {
|
|
161
|
+
return _RichSelect.default;
|
|
162
|
+
}
|
|
163
|
+
});
|
|
158
164
|
Object.defineProperty(exports, "SASQLookupComponent", {
|
|
159
165
|
enumerable: true,
|
|
160
166
|
get: function get() {
|
|
@@ -258,6 +264,12 @@ Object.defineProperty(exports, "matchString", {
|
|
|
258
264
|
return _utils.matchString;
|
|
259
265
|
}
|
|
260
266
|
});
|
|
267
|
+
Object.defineProperty(exports, "parseErrorResponse", {
|
|
268
|
+
enumerable: true,
|
|
269
|
+
get: function get() {
|
|
270
|
+
return _utils.parseErrorResponse;
|
|
271
|
+
}
|
|
272
|
+
});
|
|
261
273
|
Object.defineProperty(exports, "refdataOptions", {
|
|
262
274
|
enumerable: true,
|
|
263
275
|
get: function get() {
|
|
@@ -384,6 +396,12 @@ Object.defineProperty(exports, "useRefdata", {
|
|
|
384
396
|
return _hooks.useRefdata;
|
|
385
397
|
}
|
|
386
398
|
});
|
|
399
|
+
Object.defineProperty(exports, "useSelectedOption", {
|
|
400
|
+
enumerable: true,
|
|
401
|
+
get: function get() {
|
|
402
|
+
return _RichSelect.useSelectedOption;
|
|
403
|
+
}
|
|
404
|
+
});
|
|
387
405
|
Object.defineProperty(exports, "useSettings", {
|
|
388
406
|
enumerable: true,
|
|
389
407
|
get: function get() {
|
|
@@ -441,6 +459,8 @@ var _CycleButton = _interopRequireDefault(require("./lib/CycleButton"));
|
|
|
441
459
|
|
|
442
460
|
var _IconSelect = _interopRequireDefault(require("./lib/IconSelect"));
|
|
443
461
|
|
|
462
|
+
var _RichSelect = _interopRequireWildcard(require("./lib/RichSelect"));
|
|
463
|
+
|
|
444
464
|
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); }
|
|
445
465
|
|
|
446
466
|
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; }
|
|
@@ -21,7 +21,7 @@ var _ActionListFieldArray = _interopRequireDefault(require("./ActionListFieldArr
|
|
|
21
21
|
|
|
22
22
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
23
23
|
|
|
24
|
-
var _excluded = ["actionAssigner", "actionCalls", "columnMapping", "contentData", "creatableFields", "createCallback", "editableFields", "fieldComponents", "hideCreateButton", "label", "validateFields", "visibleFields"];
|
|
24
|
+
var _excluded = ["actionAssigner", "actionCalls", "columnMapping", "contentData", "creatableFields", "createCallback", "defaultNewObject", "editableFields", "fieldComponents", "hideCreateButton", "label", "validateFields", "visibleFields"];
|
|
25
25
|
|
|
26
26
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
27
27
|
|
|
@@ -46,10 +46,12 @@ var propTypes = {
|
|
|
46
46
|
contentData: _propTypes.default.arrayOf(_propTypes.default.object),
|
|
47
47
|
creatableFields: _propTypes.default.object,
|
|
48
48
|
createCallback: _propTypes.default.func,
|
|
49
|
+
defaultNewObject: _propTypes.default.object,
|
|
49
50
|
editableFields: _propTypes.default.object,
|
|
50
51
|
fieldComponents: _propTypes.default.object,
|
|
51
52
|
hideCreateButton: _propTypes.default.bool,
|
|
52
|
-
label: _propTypes.default.string,
|
|
53
|
+
label: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.node]),
|
|
54
|
+
validateFields: _propTypes.default.object,
|
|
53
55
|
visibleFields: _propTypes.default.arrayOf(_propTypes.default.string)
|
|
54
56
|
};
|
|
55
57
|
var ActionList = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
@@ -61,6 +63,8 @@ var ActionList = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
|
61
63
|
_ref$creatableFields = _ref.creatableFields,
|
|
62
64
|
creatableFields = _ref$creatableFields === void 0 ? {} : _ref$creatableFields,
|
|
63
65
|
createCallback = _ref.createCallback,
|
|
66
|
+
_ref$defaultNewObject = _ref.defaultNewObject,
|
|
67
|
+
defaultNewObject = _ref$defaultNewObject === void 0 ? {} : _ref$defaultNewObject,
|
|
64
68
|
_ref$editableFields = _ref.editableFields,
|
|
65
69
|
editableFields = _ref$editableFields === void 0 ? {} : _ref$editableFields,
|
|
66
70
|
_ref$fieldComponents = _ref.fieldComponents,
|
|
@@ -103,6 +107,7 @@ var ActionList = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
|
103
107
|
component: ActionListFieldArrayWithRef,
|
|
104
108
|
creatableFields: creatableFields,
|
|
105
109
|
createCallback: createCallback,
|
|
110
|
+
defaultNewObject: defaultNewObject,
|
|
106
111
|
editableFields: editableFields,
|
|
107
112
|
fieldComponents: fieldComponents,
|
|
108
113
|
hideCreateButton: hideCreateButton,
|
|
@@ -15,6 +15,8 @@ var _reactIntl = require("react-intl");
|
|
|
15
15
|
|
|
16
16
|
var _get = _interopRequireDefault(require("lodash/get"));
|
|
17
17
|
|
|
18
|
+
var _cloneDeep = _interopRequireDefault(require("lodash/cloneDeep"));
|
|
19
|
+
|
|
18
20
|
var _reactFinalForm = require("react-final-form");
|
|
19
21
|
|
|
20
22
|
var _components = require("@folio/stripes/components");
|
|
@@ -23,7 +25,7 @@ var _ActionListFieldArray = _interopRequireDefault(require("../../../styles/Acti
|
|
|
23
25
|
|
|
24
26
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
25
27
|
|
|
26
|
-
var _excluded = ["actionAssigner", "actionCalls", "columnMapping", "creatableFields", "createCallback", "editableFields", "fields", "fieldComponents", "hideCreateButton", "label", "validateFields", "visibleFields", "triggerFormSubmit"],
|
|
28
|
+
var _excluded = ["actionAssigner", "actionCalls", "columnMapping", "creatableFields", "createCallback", "defaultNewObject", "editableFields", "fields", "fieldComponents", "hideCreateButton", "label", "validateFields", "visibleFields", "triggerFormSubmit"],
|
|
27
29
|
_excluded2 = ["actionListActions", "fieldName", "fieldIndex"],
|
|
28
30
|
_excluded3 = ["actionListActions", "fieldName", "fieldIndex"],
|
|
29
31
|
_excluded4 = ["actionListActions"],
|
|
@@ -74,12 +76,15 @@ var propTypes = {
|
|
|
74
76
|
columnMapping: _propTypes.default.object,
|
|
75
77
|
creatableFields: _propTypes.default.object,
|
|
76
78
|
createCallback: _propTypes.default.func,
|
|
79
|
+
defaultNewObject: _propTypes.default.object,
|
|
77
80
|
editableFields: _propTypes.default.object,
|
|
78
81
|
fields: _propTypes.default.object,
|
|
79
82
|
fieldComponents: _propTypes.default.object,
|
|
80
83
|
formatter: _propTypes.default.object,
|
|
81
84
|
hideCreateButton: _propTypes.default.bool,
|
|
82
|
-
label: _propTypes.default.string,
|
|
85
|
+
label: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.node]),
|
|
86
|
+
triggerFormSubmit: _propTypes.default.func.isRequired,
|
|
87
|
+
validateFields: _propTypes.default.object,
|
|
83
88
|
visibleFields: _propTypes.default.arrayOf(_propTypes.default.string)
|
|
84
89
|
};
|
|
85
90
|
var ActionListFieldArray = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
@@ -88,6 +93,7 @@ var ActionListFieldArray = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, r
|
|
|
88
93
|
columnMapping = _ref.columnMapping,
|
|
89
94
|
creatableFields = _ref.creatableFields,
|
|
90
95
|
createCallback = _ref.createCallback,
|
|
96
|
+
defaultNewObject = _ref.defaultNewObject,
|
|
91
97
|
editableFields = _ref.editableFields,
|
|
92
98
|
fields = _ref.fields,
|
|
93
99
|
fieldComponents = _ref.fieldComponents,
|
|
@@ -166,7 +172,7 @@ var ActionListFieldArray = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, r
|
|
|
166
172
|
|
|
167
173
|
var handleClickCreate = function handleClickCreate() {
|
|
168
174
|
toggleEditing('NEW_ROW');
|
|
169
|
-
fields.unshift(
|
|
175
|
+
fields.unshift(defaultNewObject);
|
|
170
176
|
}; // Way to go into create mode from external component, and way to tell internal editing state
|
|
171
177
|
|
|
172
178
|
|
|
@@ -201,7 +207,7 @@ var ActionListFieldArray = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, r
|
|
|
201
207
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
202
208
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
|
|
203
209
|
buttonStyle: "primary",
|
|
204
|
-
disabled: submitting || pristine,
|
|
210
|
+
disabled: hasValidationErrors || submitting || pristine,
|
|
205
211
|
marginBottom0: true,
|
|
206
212
|
onClick: function onClick() {
|
|
207
213
|
triggerFormSubmit(); // This is set up as () => null in ActionList, so essentially only acts here to force validation
|
|
@@ -312,7 +318,7 @@ var ActionListFieldArray = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, r
|
|
|
312
318
|
var assignActions = function assignActions() {
|
|
313
319
|
return fields.map(function (fieldName, fieldIndex) {
|
|
314
320
|
// Fetch the content from the field Values
|
|
315
|
-
var cd = (0, _get.default)(values, fieldName);
|
|
321
|
+
var cd = (0, _cloneDeep.default)((0, _get.default)(values, fieldName));
|
|
316
322
|
cd.actionListActions = actionAssigner(cd);
|
|
317
323
|
return _objectSpread(_objectSpread({}, cd), {}, {
|
|
318
324
|
fieldName: fieldName,
|
|
@@ -31,6 +31,8 @@ var _CustomPropertyForm = _interopRequireDefault(require("./CustomPropertyForm")
|
|
|
31
31
|
|
|
32
32
|
var _hooks = require("../../hooks");
|
|
33
33
|
|
|
34
|
+
var _utils = require("../../utils");
|
|
35
|
+
|
|
34
36
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
35
37
|
|
|
36
38
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -162,7 +164,7 @@ var CustomPropertiesSettings = function CustomPropertiesSettings(_ref) {
|
|
|
162
164
|
switch (_context.prev = _context.next) {
|
|
163
165
|
case 0:
|
|
164
166
|
_context.next = 2;
|
|
165
|
-
return err.response
|
|
167
|
+
return (0, _utils.parseErrorResponse)(err.response);
|
|
166
168
|
|
|
167
169
|
case 2:
|
|
168
170
|
errorResp = _context.sent;
|
|
@@ -91,7 +91,7 @@ var CustomPropertiesViewCtx = function CustomPropertiesViewCtx(_ref) {
|
|
|
91
91
|
}, // Within those groups, sort by weight
|
|
92
92
|
{
|
|
93
93
|
path: 'label'
|
|
94
|
-
} //For those with the same weight, sort by label
|
|
94
|
+
} // For those with the same weight, sort by label
|
|
95
95
|
]
|
|
96
96
|
}
|
|
97
97
|
}),
|
|
@@ -75,7 +75,8 @@ CycleButton.propTypes = {
|
|
|
75
75
|
className: _propTypes.default.object,
|
|
76
76
|
icon: _propTypes.default.string.isRequired,
|
|
77
77
|
onClick: _propTypes.default.func.isRequired
|
|
78
|
-
}))
|
|
78
|
+
})),
|
|
79
|
+
startIndex: _propTypes.default.number
|
|
79
80
|
};
|
|
80
81
|
var _default = CycleButton;
|
|
81
82
|
exports.default = _default;
|
|
@@ -21,6 +21,10 @@ var _hooks = require("../hooks");
|
|
|
21
21
|
|
|
22
22
|
var _ActionList = _interopRequireDefault(require("../ActionList"));
|
|
23
23
|
|
|
24
|
+
var _validators = require("../utils/validators");
|
|
25
|
+
|
|
26
|
+
var _utils = require("../utils");
|
|
27
|
+
|
|
24
28
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
25
29
|
|
|
26
30
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -56,7 +60,7 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
|
56
60
|
var propTypes = {
|
|
57
61
|
afterQueryCalls: _propTypes.default.object,
|
|
58
62
|
catchQueryCalls: _propTypes.default.object,
|
|
59
|
-
label: _propTypes.default.string,
|
|
63
|
+
label: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.node]),
|
|
60
64
|
labelOverrides: _propTypes.default.object,
|
|
61
65
|
refdataEndpoint: _propTypes.default.string
|
|
62
66
|
};
|
|
@@ -134,7 +138,7 @@ var EditableRefdataCategoryList = function EditableRefdataCategoryList(_ref) {
|
|
|
134
138
|
switch (_context.prev = _context.next) {
|
|
135
139
|
case 0:
|
|
136
140
|
_context.next = 2;
|
|
137
|
-
return err.response
|
|
141
|
+
return (0, _utils.parseErrorResponse)(err.response);
|
|
138
142
|
|
|
139
143
|
case 2:
|
|
140
144
|
errorResp = _context.sent;
|
|
@@ -242,6 +246,11 @@ var EditableRefdataCategoryList = function EditableRefdataCategoryList(_ref) {
|
|
|
242
246
|
}
|
|
243
247
|
},
|
|
244
248
|
label: label,
|
|
249
|
+
validateFields: {
|
|
250
|
+
desc: function desc() {
|
|
251
|
+
return _validators.required;
|
|
252
|
+
}
|
|
253
|
+
},
|
|
245
254
|
visibleFields: ['desc', 'values']
|
|
246
255
|
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.ConfirmationModal, {
|
|
247
256
|
confirmLabel: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactIntl.FormattedMessage, {
|
|
@@ -21,6 +21,10 @@ var _hooks = require("../hooks");
|
|
|
21
21
|
|
|
22
22
|
var _ActionList = _interopRequireDefault(require("../ActionList"));
|
|
23
23
|
|
|
24
|
+
var _validators = require("../utils/validators");
|
|
25
|
+
|
|
26
|
+
var _utils = require("../utils");
|
|
27
|
+
|
|
24
28
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
25
29
|
|
|
26
30
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -57,7 +61,7 @@ var propTypes = {
|
|
|
57
61
|
afterQueryCalls: _propTypes.default.object,
|
|
58
62
|
catchQueryCalls: _propTypes.default.object,
|
|
59
63
|
desc: _propTypes.default.string,
|
|
60
|
-
label: _propTypes.default.string,
|
|
64
|
+
label: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.node]),
|
|
61
65
|
labelOverrides: _propTypes.default.object,
|
|
62
66
|
refdataEndpoint: _propTypes.default.string
|
|
63
67
|
};
|
|
@@ -147,7 +151,7 @@ var EditableRefdataList = function EditableRefdataList(_ref) {
|
|
|
147
151
|
switch (_context.prev = _context.next) {
|
|
148
152
|
case 0:
|
|
149
153
|
_context.next = 2;
|
|
150
|
-
return err.response
|
|
154
|
+
return (0, _utils.parseErrorResponse)(err.response);
|
|
151
155
|
|
|
152
156
|
case 2:
|
|
153
157
|
errorResp = _context.sent;
|
|
@@ -267,6 +271,11 @@ var EditableRefdataList = function EditableRefdataList(_ref) {
|
|
|
267
271
|
}
|
|
268
272
|
},
|
|
269
273
|
label: label,
|
|
274
|
+
validateFields: {
|
|
275
|
+
label: function label() {
|
|
276
|
+
return _validators.required;
|
|
277
|
+
}
|
|
278
|
+
},
|
|
270
279
|
visibleFields: ['label', 'value']
|
|
271
280
|
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.ConfirmationModal, {
|
|
272
281
|
confirmLabel: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactIntl.FormattedMessage, {
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
4
|
+
|
|
3
5
|
Object.defineProperty(exports, "__esModule", {
|
|
4
6
|
value: true
|
|
5
7
|
});
|
|
@@ -7,6 +9,8 @@ exports.default = void 0;
|
|
|
7
9
|
|
|
8
10
|
var _react = require("react");
|
|
9
11
|
|
|
12
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
13
|
+
|
|
10
14
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|
11
15
|
|
|
12
16
|
var _reactIntl = require("react-intl");
|
|
@@ -15,15 +19,17 @@ var _components = require("@folio/stripes/components");
|
|
|
15
19
|
|
|
16
20
|
var _IconSelect = _interopRequireDefault(require("../../../styles/IconSelect.css"));
|
|
17
21
|
|
|
22
|
+
var _RichSelect = _interopRequireWildcard(require("../RichSelect"));
|
|
23
|
+
|
|
18
24
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
19
25
|
|
|
20
26
|
var _excluded = ["className"];
|
|
21
27
|
|
|
22
|
-
function
|
|
28
|
+
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); }
|
|
23
29
|
|
|
24
|
-
function
|
|
30
|
+
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; }
|
|
25
31
|
|
|
26
|
-
function
|
|
32
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
27
33
|
|
|
28
34
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
29
35
|
|
|
@@ -31,6 +37,10 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
31
37
|
|
|
32
38
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
33
39
|
|
|
40
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
41
|
+
|
|
42
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
43
|
+
|
|
34
44
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
35
45
|
|
|
36
46
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
@@ -52,21 +62,20 @@ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToAr
|
|
|
52
62
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
53
63
|
|
|
54
64
|
// A form component which acts as a "Select for states with corresponding icons"
|
|
55
|
-
var IconSelect = function
|
|
56
|
-
var
|
|
65
|
+
var IconSelect = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
66
|
+
var _selectedOption$butto;
|
|
57
67
|
|
|
58
68
|
var ariaLabel = _ref.ariaLabel,
|
|
59
69
|
_ref$disabled = _ref.disabled,
|
|
60
70
|
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
|
|
61
71
|
id = _ref.id,
|
|
62
|
-
|
|
63
|
-
formInput = _ref$input === void 0 ? {} : _ref$input,
|
|
72
|
+
input = _ref.input,
|
|
64
73
|
label = _ref.label,
|
|
65
74
|
meta = _ref.meta,
|
|
66
75
|
_ref$notSet = _ref.notSet,
|
|
67
76
|
notSet = _ref$notSet === void 0 ? {
|
|
68
|
-
icon:
|
|
69
|
-
value:
|
|
77
|
+
icon: 'ellipsis',
|
|
78
|
+
value: '',
|
|
70
79
|
label: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactIntl.FormattedMessage, {
|
|
71
80
|
id: "stripes-kint-components.iconSelect.notSet"
|
|
72
81
|
})
|
|
@@ -75,109 +84,95 @@ var IconSelect = function IconSelect(_ref) {
|
|
|
75
84
|
_ref$options = _ref.options,
|
|
76
85
|
userOptions = _ref$options === void 0 ? [] : _ref$options,
|
|
77
86
|
_ref$required = _ref.required,
|
|
78
|
-
required = _ref$required === void 0 ? false : _ref$required
|
|
87
|
+
required = _ref$required === void 0 ? false : _ref$required,
|
|
88
|
+
value = _ref.value;
|
|
79
89
|
// Options with notSet
|
|
80
|
-
var options = [notSet].concat(_toConsumableArray(userOptions));
|
|
81
|
-
|
|
82
|
-
var
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
return opt.value === val;
|
|
92
|
-
});
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
var _useState3 = (0, _react.useState)(findSelectedOptionByValue((_meta$initial2 = meta.initial) !== null && _meta$initial2 !== void 0 ? _meta$initial2 : '')),
|
|
96
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
|
97
|
-
selectedOption = _useState4[0],
|
|
98
|
-
setSelectedOption = _useState4[1];
|
|
99
|
-
|
|
100
|
-
var handleChange = function handleChange(e) {
|
|
101
|
-
// Actually set the value in the form
|
|
102
|
-
formInput.onChange(e); // If the user has set up an onChange, this will ensure that that fires
|
|
103
|
-
|
|
104
|
-
if (onChange) {
|
|
105
|
-
onChange(e, e.target.value);
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
var renderMenu = function renderMenu(_ref2) {
|
|
110
|
-
var onToggle = _ref2.onToggle;
|
|
111
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.DropdownMenu, {
|
|
112
|
-
children: options.map(function (opt) {
|
|
113
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
|
|
114
|
-
autoFocus: (selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.value) === opt.value,
|
|
115
|
-
buttonStyle: "dropdownItem",
|
|
116
|
-
id: "".concat(id, "-").concat(formInput.name, "-option-").concat(opt.value),
|
|
117
|
-
marginBottom0: true,
|
|
118
|
-
onClick: function onClick() {
|
|
119
|
-
// Trigger change event
|
|
120
|
-
(0, _components.nativeChangeFieldValue)(hiddenInput, false, opt.value); // Set internal states
|
|
121
|
-
|
|
122
|
-
setValue(opt.value);
|
|
123
|
-
setSelectedOption(findSelectedOptionByValue(opt.value)); // Close the menu on select
|
|
124
|
-
|
|
125
|
-
onToggle();
|
|
126
|
-
},
|
|
127
|
-
children: opt.icon ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Icon, _objectSpread(_objectSpread({
|
|
128
|
-
icon: opt.icon
|
|
129
|
-
}, opt.iconProps), {}, {
|
|
130
|
-
children: opt.label
|
|
131
|
-
})) : opt.label
|
|
132
|
-
});
|
|
133
|
-
})
|
|
134
|
-
});
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
var _ref3 = (_selectedOption$butto = selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.buttonProps) !== null && _selectedOption$butto !== void 0 ? _selectedOption$butto : {},
|
|
138
|
-
iconButtonClassName = _ref3.className,
|
|
139
|
-
buttonProps = _objectWithoutProperties(_ref3, _excluded);
|
|
140
|
-
|
|
141
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
142
|
-
children: [label || ariaLabel ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Label, {
|
|
143
|
-
htmlFor: id,
|
|
144
|
-
id: "".concat(id, "-label"),
|
|
145
|
-
required: required,
|
|
146
|
-
className: ariaLabel && 'sr-only',
|
|
147
|
-
children: ariaLabel || label
|
|
148
|
-
}) : '', /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Dropdown, {
|
|
149
|
-
hasPadding: true,
|
|
150
|
-
placement: "bottom-start",
|
|
151
|
-
renderTrigger: function renderTrigger(_ref4) {
|
|
152
|
-
var _selectedOption$icon;
|
|
153
|
-
|
|
154
|
-
var onToggle = _ref4.onToggle,
|
|
155
|
-
triggerRef = _ref4.triggerRef,
|
|
156
|
-
keyHandler = _ref4.keyHandler,
|
|
157
|
-
ariaProps = _ref4.ariaProps,
|
|
158
|
-
getTriggerProps = _ref4.getTriggerProps;
|
|
159
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.IconButton, _objectSpread(_objectSpread(_objectSpread({
|
|
160
|
-
ref: triggerRef,
|
|
161
|
-
disabled: disabled,
|
|
162
|
-
icon: (_selectedOption$icon = selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.icon) !== null && _selectedOption$icon !== void 0 ? _selectedOption$icon : 'ellipsis',
|
|
163
|
-
marginBottom0: true,
|
|
164
|
-
onClick: onToggle,
|
|
165
|
-
onKeyDown: keyHandler,
|
|
166
|
-
type: "button"
|
|
167
|
-
}, _objectSpread({
|
|
168
|
-
className: (0, _classnames.default)(_IconSelect.default.buttonStyle, iconButtonClassName)
|
|
169
|
-
}, buttonProps)), getTriggerProps()), ariaProps));
|
|
170
|
-
},
|
|
171
|
-
renderMenu: renderMenu
|
|
172
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("input", _objectSpread(_objectSpread({}, formInput), {}, {
|
|
173
|
-
ref: hiddenInput,
|
|
174
|
-
hidden: true,
|
|
175
|
-
onChange: handleChange,
|
|
176
|
-
type: "text",
|
|
177
|
-
value: value
|
|
178
|
-
}))]
|
|
90
|
+
var options = [notSet].concat(_toConsumableArray(userOptions));
|
|
91
|
+
|
|
92
|
+
var _useSelectedOption = (0, _RichSelect.useSelectedOption)(),
|
|
93
|
+
_useSelectedOption2 = _slicedToArray(_useSelectedOption, 2),
|
|
94
|
+
richSelectRef = _useSelectedOption2[0],
|
|
95
|
+
selectedOption = _useSelectedOption2[1];
|
|
96
|
+
|
|
97
|
+
(0, _react.useImperativeHandle)(ref, function () {
|
|
98
|
+
return {
|
|
99
|
+
selectedOption: selectedOption
|
|
100
|
+
};
|
|
179
101
|
});
|
|
180
|
-
};
|
|
181
102
|
|
|
103
|
+
var _ref2 = (_selectedOption$butto = selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.buttonProps) !== null && _selectedOption$butto !== void 0 ? _selectedOption$butto : {},
|
|
104
|
+
iconButtonClassName = _ref2.className,
|
|
105
|
+
buttonProps = _objectWithoutProperties(_ref2, _excluded);
|
|
106
|
+
|
|
107
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_RichSelect.default, {
|
|
108
|
+
ref: richSelectRef,
|
|
109
|
+
ariaLabel: ariaLabel,
|
|
110
|
+
disabled: disabled,
|
|
111
|
+
id: id,
|
|
112
|
+
input: input,
|
|
113
|
+
label: label,
|
|
114
|
+
meta: meta,
|
|
115
|
+
onChange: onChange,
|
|
116
|
+
options: options,
|
|
117
|
+
renderOption: function renderOption(opt) {
|
|
118
|
+
var _opt$label2;
|
|
119
|
+
|
|
120
|
+
if (opt.icon) {
|
|
121
|
+
var _opt$label;
|
|
122
|
+
|
|
123
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Icon, _objectSpread(_objectSpread({
|
|
124
|
+
icon: opt.icon
|
|
125
|
+
}, opt.iconProps), {}, {
|
|
126
|
+
children: (_opt$label = opt.label) !== null && _opt$label !== void 0 ? _opt$label : opt.value
|
|
127
|
+
}));
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return (_opt$label2 = opt.label) !== null && _opt$label2 !== void 0 ? _opt$label2 : opt.value;
|
|
131
|
+
},
|
|
132
|
+
renderTrigger: function renderTrigger(_ref3) {
|
|
133
|
+
var _selectedOption$icon;
|
|
134
|
+
|
|
135
|
+
var onToggle = _ref3.onToggle,
|
|
136
|
+
triggerRef = _ref3.triggerRef,
|
|
137
|
+
keyHandler = _ref3.keyHandler,
|
|
138
|
+
ariaProps = _ref3.ariaProps,
|
|
139
|
+
getTriggerProps = _ref3.getTriggerProps;
|
|
140
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.IconButton, _objectSpread(_objectSpread(_objectSpread({
|
|
141
|
+
ref: triggerRef,
|
|
142
|
+
disabled: disabled,
|
|
143
|
+
icon: (_selectedOption$icon = selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.icon) !== null && _selectedOption$icon !== void 0 ? _selectedOption$icon : 'ellipsis',
|
|
144
|
+
marginBottom0: true,
|
|
145
|
+
onClick: onToggle,
|
|
146
|
+
onKeyDown: keyHandler,
|
|
147
|
+
type: "button"
|
|
148
|
+
}, _objectSpread({
|
|
149
|
+
className: (0, _classnames.default)(_IconSelect.default.buttonStyle, iconButtonClassName)
|
|
150
|
+
}, buttonProps)), getTriggerProps()), ariaProps));
|
|
151
|
+
},
|
|
152
|
+
required: required,
|
|
153
|
+
value: value
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
IconSelect.propTypes = {
|
|
157
|
+
ariaLabel: _propTypes.default.string,
|
|
158
|
+
disabled: _propTypes.default.bool,
|
|
159
|
+
id: _propTypes.default.string,
|
|
160
|
+
input: _propTypes.default.object,
|
|
161
|
+
label: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.func, _propTypes.default.node]),
|
|
162
|
+
meta: _propTypes.default.object,
|
|
163
|
+
notSet: _propTypes.default.shape({
|
|
164
|
+
icon: _propTypes.default.string,
|
|
165
|
+
value: _propTypes.default.string.isRequired,
|
|
166
|
+
label: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.node])
|
|
167
|
+
}),
|
|
168
|
+
onChange: _propTypes.default.func,
|
|
169
|
+
options: _propTypes.default.arrayOf(_propTypes.default.shape({
|
|
170
|
+
icon: _propTypes.default.string,
|
|
171
|
+
value: _propTypes.default.string.isRequired,
|
|
172
|
+
label: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.node])
|
|
173
|
+
})),
|
|
174
|
+
required: _propTypes.default.bool,
|
|
175
|
+
value: _propTypes.default.string
|
|
176
|
+
};
|
|
182
177
|
var _default = IconSelect;
|
|
183
178
|
exports.default = _default;
|