@k-int/stripes-kint-components 2.7.0 → 2.8.1
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 +13 -0
- package/es/index.js +14 -0
- package/es/lib/ActionList/ActionList.js +7 -2
- package/es/lib/ActionList/ActionListFieldArray.js +12 -6
- package/es/lib/CustomProperties/View/CustomPropertiesViewCtx.js +1 -1
- package/es/lib/CycleButton/CycleButton.js +2 -1
- package/es/lib/EditableRefdataCategoryList/EditableRefdataCategoryList.js +8 -1
- package/es/lib/EditableRefdataList/EditableRefdataList.js +8 -1
- 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/package.json +1 -1
- package/src/index.js +1 -0
- package/src/lib/ActionList/ActionList.js +8 -1
- package/src/lib/ActionList/ActionListFieldArray.js +14 -6
- package/src/lib/ActionList/README.md +3 -0
- package/src/lib/CustomProperties/View/CustomPropertiesViewCtx.js +1 -1
- package/src/lib/CycleButton/CycleButton.js +3 -2
- package/src/lib/EditableRefdataCategoryList/EditableRefdataCategoryList.js +8 -1
- package/src/lib/EditableRefdataList/EditableRefdataList.js +8 -1
- 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/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
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
|
|
10
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
+
|
|
12
|
+
var _reactIntl = require("react-intl");
|
|
13
|
+
|
|
14
|
+
var _components = require("@folio/stripes/components");
|
|
15
|
+
|
|
16
|
+
var _RichSelect = _interopRequireDefault(require("../../../styles/RichSelect.css"));
|
|
17
|
+
|
|
18
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
19
|
+
|
|
20
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
|
+
|
|
22
|
+
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; }
|
|
23
|
+
|
|
24
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
25
|
+
|
|
26
|
+
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; }
|
|
27
|
+
|
|
28
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
29
|
+
|
|
30
|
+
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."); }
|
|
31
|
+
|
|
32
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
33
|
+
|
|
34
|
+
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; }
|
|
35
|
+
|
|
36
|
+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
37
|
+
|
|
38
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
39
|
+
|
|
40
|
+
var RichSelect = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
41
|
+
var _ref2, _meta$initial, _findSelectedOptionBy, _meta$initial2;
|
|
42
|
+
|
|
43
|
+
var ariaLabel = _ref.ariaLabel,
|
|
44
|
+
_ref$disabled = _ref.disabled,
|
|
45
|
+
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
|
|
46
|
+
_ref$dropdownProps = _ref.dropdownProps,
|
|
47
|
+
dropdownProps = _ref$dropdownProps === void 0 ? {} : _ref$dropdownProps,
|
|
48
|
+
id = _ref.id,
|
|
49
|
+
_ref$input = _ref.input,
|
|
50
|
+
formInput = _ref$input === void 0 ? {} : _ref$input,
|
|
51
|
+
label = _ref.label,
|
|
52
|
+
meta = _ref.meta,
|
|
53
|
+
onChange = _ref.onChange,
|
|
54
|
+
_ref$options = _ref.options,
|
|
55
|
+
userOptions = _ref$options === void 0 ? [] : _ref$options,
|
|
56
|
+
placeholder = _ref.placeholder,
|
|
57
|
+
_renderMenu = _ref.renderMenu,
|
|
58
|
+
renderOption = _ref.renderOption,
|
|
59
|
+
_renderTrigger = _ref.renderTrigger,
|
|
60
|
+
_ref$required = _ref.required,
|
|
61
|
+
required = _ref$required === void 0 ? false : _ref$required,
|
|
62
|
+
value = _ref.value;
|
|
63
|
+
var hiddenInput = (0, _react.useRef)(null);
|
|
64
|
+
|
|
65
|
+
var _useState = (0, _react.useState)((_ref2 = (_meta$initial = meta === null || meta === void 0 ? void 0 : meta.initial) !== null && _meta$initial !== void 0 ? _meta$initial : value) !== null && _ref2 !== void 0 ? _ref2 : ''),
|
|
66
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
67
|
+
internalValue = _useState2[0],
|
|
68
|
+
setInternalValue = _useState2[1];
|
|
69
|
+
|
|
70
|
+
var findSelectedOptionByValue = (0, _react.useCallback)(function (val) {
|
|
71
|
+
return userOptions.find(function (opt) {
|
|
72
|
+
return opt.value === val;
|
|
73
|
+
});
|
|
74
|
+
}, [userOptions]);
|
|
75
|
+
|
|
76
|
+
var _useState3 = (0, _react.useState)((_findSelectedOptionBy = findSelectedOptionByValue((_meta$initial2 = meta === null || meta === void 0 ? void 0 : meta.initial) !== null && _meta$initial2 !== void 0 ? _meta$initial2 : '')) !== null && _findSelectedOptionBy !== void 0 ? _findSelectedOptionBy : {}),
|
|
77
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
78
|
+
selectedOption = _useState4[0],
|
|
79
|
+
setSelectedOption = _useState4[1];
|
|
80
|
+
|
|
81
|
+
(0, _react.useEffect)(function () {
|
|
82
|
+
// We treat non-undefined value/formInput values as valid values, whereas undefined is only relevant when prop has not been provided
|
|
83
|
+
if (value !== undefined && !(value === (selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.value) && value === internalValue)) {
|
|
84
|
+
setSelectedOption(findSelectedOptionByValue(value));
|
|
85
|
+
setInternalValue(value);
|
|
86
|
+
} else if ((formInput === null || formInput === void 0 ? void 0 : formInput.value) !== undefined && !(value === (selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.value) && value === internalValue)) {
|
|
87
|
+
setSelectedOption(findSelectedOptionByValue(formInput.value));
|
|
88
|
+
setInternalValue(formInput.value);
|
|
89
|
+
}
|
|
90
|
+
}, [formInput, value, internalValue, selectedOption, findSelectedOptionByValue]); // Way to grab internal selectedOption state, thereby avoiding having to reparse options for it
|
|
91
|
+
|
|
92
|
+
(0, _react.useImperativeHandle)(ref, function () {
|
|
93
|
+
return {
|
|
94
|
+
selectedOption: selectedOption
|
|
95
|
+
};
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
var defaultRenderTrigger = function defaultRenderTrigger(_ref3) {
|
|
99
|
+
var _ref4, _ref5, _ref6, _selectedOption$label;
|
|
100
|
+
|
|
101
|
+
var onToggle = _ref3.onToggle,
|
|
102
|
+
triggerRef = _ref3.triggerRef,
|
|
103
|
+
keyHandler = _ref3.keyHandler,
|
|
104
|
+
open = _ref3.open,
|
|
105
|
+
ariaProps = _ref3.ariaProps,
|
|
106
|
+
getTriggerProps = _ref3.getTriggerProps;
|
|
107
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, _objectSpread(_objectSpread(_objectSpread({
|
|
108
|
+
ref: triggerRef,
|
|
109
|
+
buttonClass: _RichSelect.default.iconButtonText,
|
|
110
|
+
buttonStyle: "none",
|
|
111
|
+
disabled: disabled,
|
|
112
|
+
marginBottom0: true,
|
|
113
|
+
onClick: onToggle,
|
|
114
|
+
onKeyDown: keyHandler,
|
|
115
|
+
paddingSide0: true,
|
|
116
|
+
type: "button"
|
|
117
|
+
}, getTriggerProps()), ariaProps), {}, {
|
|
118
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Icon, {
|
|
119
|
+
icon: open ? 'caret-up' : 'caret-down',
|
|
120
|
+
iconPosition: "end",
|
|
121
|
+
children: (_ref4 = (_ref5 = (_ref6 = (_selectedOption$label = selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.label) !== null && _selectedOption$label !== void 0 ? _selectedOption$label : selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.value) !== null && _ref6 !== void 0 ? _ref6 : internalValue || null) !== null && _ref5 !== void 0 ? _ref5 : placeholder) !== null && _ref4 !== void 0 ? _ref4 : /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactIntl.FormattedMessage, {
|
|
122
|
+
id: "stripes-kint-components.richSelect.placeholder"
|
|
123
|
+
})
|
|
124
|
+
})
|
|
125
|
+
})) // Awaiting result of conversation about whether we want to allow labels on IconButtons
|
|
126
|
+
|
|
127
|
+
/* <IconButton
|
|
128
|
+
ref={triggerRef}
|
|
129
|
+
disabled={disabled}
|
|
130
|
+
icon={open ? 'caret-up' : 'caret-down'}
|
|
131
|
+
iconPosition="end"
|
|
132
|
+
marginBottom0
|
|
133
|
+
onClick={onToggle}
|
|
134
|
+
onKeyDown={keyHandler}
|
|
135
|
+
type="button"
|
|
136
|
+
{...getTriggerProps()}
|
|
137
|
+
{...ariaProps}
|
|
138
|
+
>
|
|
139
|
+
{
|
|
140
|
+
selectedOption?.label ??
|
|
141
|
+
selectedOption?.value ??
|
|
142
|
+
(internalValue ? internalValue : null) ??
|
|
143
|
+
placeholder ??
|
|
144
|
+
<FormattedMessage id="stripes-kint-components.richSelect.placeholder" />
|
|
145
|
+
}
|
|
146
|
+
</IconButton> */
|
|
147
|
+
;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
var handleChange = function handleChange(e) {
|
|
151
|
+
// Actually set the value in the form (If formInput exists)
|
|
152
|
+
if (formInput !== null && formInput !== void 0 && formInput.onChange) {
|
|
153
|
+
formInput.onChange(e);
|
|
154
|
+
} // If the user has set up an onChange, this will ensure that that fires
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
if (onChange) {
|
|
158
|
+
onChange(e, e.target.value);
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
var changeField = function changeField(val) {
|
|
163
|
+
(0, _components.nativeChangeFieldValue)(hiddenInput, false, val);
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
var defaultRenderOption = function defaultRenderOption(opt) {
|
|
167
|
+
var _opt$label;
|
|
168
|
+
|
|
169
|
+
return (_opt$label = opt.label) !== null && _opt$label !== void 0 ? _opt$label : opt.value;
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
var defaultRenderMenu = function defaultRenderMenu(_ref7) {
|
|
173
|
+
var onToggle = _ref7.onToggle;
|
|
174
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.DropdownMenu, {
|
|
175
|
+
children: userOptions.map(function (opt) {
|
|
176
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
|
|
177
|
+
autoFocus: (selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.value) === opt.value,
|
|
178
|
+
buttonStyle: "dropdownItem",
|
|
179
|
+
id: "".concat(id, "-").concat(formInput.name, "-option-").concat(opt.value),
|
|
180
|
+
marginBottom0: true,
|
|
181
|
+
onClick: function onClick() {
|
|
182
|
+
// Trigger change event
|
|
183
|
+
changeField(opt.value); // Close the menu on select
|
|
184
|
+
|
|
185
|
+
onToggle();
|
|
186
|
+
},
|
|
187
|
+
children: renderOption ? renderOption(opt) : defaultRenderOption(opt)
|
|
188
|
+
});
|
|
189
|
+
})
|
|
190
|
+
});
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
194
|
+
children: [label || ariaLabel ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Label, {
|
|
195
|
+
className: ariaLabel && 'sr-only',
|
|
196
|
+
htmlFor: id,
|
|
197
|
+
id: "".concat(id, "-label"),
|
|
198
|
+
required: required,
|
|
199
|
+
children: ariaLabel || label
|
|
200
|
+
}) : '', /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Dropdown, _objectSpread({
|
|
201
|
+
hasPadding: true,
|
|
202
|
+
placement: "bottom-start",
|
|
203
|
+
renderMenu: function renderMenu(menuProps) {
|
|
204
|
+
if (_renderMenu) {
|
|
205
|
+
return _renderMenu(_objectSpread(_objectSpread({}, menuProps), {}, {
|
|
206
|
+
selectedOption: selectedOption,
|
|
207
|
+
changeField: changeField
|
|
208
|
+
}));
|
|
209
|
+
} else {
|
|
210
|
+
return defaultRenderMenu(menuProps);
|
|
211
|
+
}
|
|
212
|
+
},
|
|
213
|
+
renderTrigger: function renderTrigger(triggerProps) {
|
|
214
|
+
if (_renderTrigger) {
|
|
215
|
+
return _renderTrigger(_objectSpread(_objectSpread({}, triggerProps), {}, {
|
|
216
|
+
selectedOption: selectedOption
|
|
217
|
+
}));
|
|
218
|
+
} else {
|
|
219
|
+
return defaultRenderTrigger(triggerProps);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}, dropdownProps)), /*#__PURE__*/(0, _jsxRuntime.jsx)("input", _objectSpread(_objectSpread({}, formInput), {}, {
|
|
223
|
+
ref: hiddenInput,
|
|
224
|
+
hidden: true,
|
|
225
|
+
onChange: handleChange,
|
|
226
|
+
type: "text",
|
|
227
|
+
value: internalValue
|
|
228
|
+
}))]
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
RichSelect.propTypes = {
|
|
232
|
+
ariaLabel: _propTypes.default.string,
|
|
233
|
+
disabled: _propTypes.default.bool,
|
|
234
|
+
dropdownProps: _propTypes.default.object,
|
|
235
|
+
id: _propTypes.default.string,
|
|
236
|
+
input: _propTypes.default.object,
|
|
237
|
+
label: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.func, _propTypes.default.node]),
|
|
238
|
+
meta: _propTypes.default.object,
|
|
239
|
+
onChange: _propTypes.default.func,
|
|
240
|
+
options: _propTypes.default.arrayOf(_propTypes.default.shape({
|
|
241
|
+
value: _propTypes.default.string.isRequired,
|
|
242
|
+
label: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.node])
|
|
243
|
+
})),
|
|
244
|
+
placeholder: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.node]),
|
|
245
|
+
renderMenu: _propTypes.default.func,
|
|
246
|
+
renderOption: _propTypes.default.func,
|
|
247
|
+
renderTrigger: _propTypes.default.func,
|
|
248
|
+
required: _propTypes.default.bool,
|
|
249
|
+
value: _propTypes.default.string
|
|
250
|
+
};
|
|
251
|
+
var _default = RichSelect;
|
|
252
|
+
exports.default = _default;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "default", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _RichSelect.default;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "useSelectedOption", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function get() {
|
|
15
|
+
return _useSelectedOption.default;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
var _RichSelect = _interopRequireDefault(require("./RichSelect"));
|
|
20
|
+
|
|
21
|
+
var _useSelectedOption = _interopRequireDefault(require("./useSelectedOption"));
|
|
22
|
+
|
|
23
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
|
|
10
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
11
|
+
|
|
12
|
+
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."); }
|
|
13
|
+
|
|
14
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
15
|
+
|
|
16
|
+
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; }
|
|
17
|
+
|
|
18
|
+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
19
|
+
|
|
20
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
21
|
+
|
|
22
|
+
var useSelectedOption = function useSelectedOption() {
|
|
23
|
+
var _useState = (0, _react.useState)(),
|
|
24
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
25
|
+
selectedOption = _useState2[0],
|
|
26
|
+
setSelectedOption = _useState2[1];
|
|
27
|
+
|
|
28
|
+
var ref = (0, _react.useCallback)(function (node) {
|
|
29
|
+
var _node$selectedOption;
|
|
30
|
+
|
|
31
|
+
if (node !== null && (selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.value) !== ((_node$selectedOption = node.selectedOption) === null || _node$selectedOption === void 0 ? void 0 : _node$selectedOption.value)) {
|
|
32
|
+
setSelectedOption(node.selectedOption);
|
|
33
|
+
}
|
|
34
|
+
}, [selectedOption]);
|
|
35
|
+
return [ref, selectedOption];
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
var _default = useSelectedOption;
|
|
39
|
+
exports.default = _default;
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -125,3 +125,4 @@ export * as customPropertyContants from './lib/constants/customProperties';
|
|
|
125
125
|
|
|
126
126
|
export { default as CycleButton } from './lib/CycleButton';
|
|
127
127
|
export { default as IconSelect } from './lib/IconSelect';
|
|
128
|
+
export { default as RichSelect, useSelectedOption } from './lib/RichSelect';
|
|
@@ -14,10 +14,15 @@ const propTypes = {
|
|
|
14
14
|
contentData: PropTypes.arrayOf(PropTypes.object),
|
|
15
15
|
creatableFields: PropTypes.object,
|
|
16
16
|
createCallback: PropTypes.func,
|
|
17
|
+
defaultNewObject: PropTypes.object,
|
|
17
18
|
editableFields: PropTypes.object,
|
|
18
19
|
fieldComponents: PropTypes.object,
|
|
19
20
|
hideCreateButton: PropTypes.bool,
|
|
20
|
-
label: PropTypes.
|
|
21
|
+
label: PropTypes.oneOfType([
|
|
22
|
+
PropTypes.string,
|
|
23
|
+
PropTypes.node
|
|
24
|
+
]),
|
|
25
|
+
validateFields: PropTypes.object,
|
|
21
26
|
visibleFields: PropTypes.arrayOf(PropTypes.string)
|
|
22
27
|
};
|
|
23
28
|
|
|
@@ -28,6 +33,7 @@ const ActionList = forwardRef(({
|
|
|
28
33
|
contentData,
|
|
29
34
|
creatableFields = {},
|
|
30
35
|
createCallback,
|
|
36
|
+
defaultNewObject = {},
|
|
31
37
|
editableFields = {},
|
|
32
38
|
fieldComponents = {},
|
|
33
39
|
hideCreateButton,
|
|
@@ -58,6 +64,7 @@ const ActionList = forwardRef(({
|
|
|
58
64
|
component={ActionListFieldArrayWithRef}
|
|
59
65
|
creatableFields={creatableFields}
|
|
60
66
|
createCallback={createCallback}
|
|
67
|
+
defaultNewObject={defaultNewObject}
|
|
61
68
|
editableFields={editableFields}
|
|
62
69
|
fieldComponents={fieldComponents}
|
|
63
70
|
hideCreateButton={hideCreateButton}
|
|
@@ -2,6 +2,7 @@ import React, { forwardRef, useImperativeHandle, useState } from 'react';
|
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import { FormattedMessage } from 'react-intl';
|
|
4
4
|
import get from 'lodash/get';
|
|
5
|
+
import cloneDeep from 'lodash/cloneDeep';
|
|
5
6
|
|
|
6
7
|
import { Field, useForm, useFormState } from 'react-final-form';
|
|
7
8
|
import { Button, Headline, IconButton, MultiColumnList, TextField } from '@folio/stripes/components';
|
|
@@ -17,12 +18,18 @@ const propTypes = {
|
|
|
17
18
|
columnMapping: PropTypes.object,
|
|
18
19
|
creatableFields: PropTypes.object,
|
|
19
20
|
createCallback: PropTypes.func,
|
|
21
|
+
defaultNewObject: PropTypes.object,
|
|
20
22
|
editableFields: PropTypes.object,
|
|
21
23
|
fields: PropTypes.object,
|
|
22
24
|
fieldComponents: PropTypes.object,
|
|
23
25
|
formatter: PropTypes.object,
|
|
24
26
|
hideCreateButton: PropTypes.bool,
|
|
25
|
-
label: PropTypes.
|
|
27
|
+
label: PropTypes.oneOfType([
|
|
28
|
+
PropTypes.string,
|
|
29
|
+
PropTypes.node
|
|
30
|
+
]),
|
|
31
|
+
triggerFormSubmit: PropTypes.func.isRequired,
|
|
32
|
+
validateFields: PropTypes.object,
|
|
26
33
|
visibleFields: PropTypes.arrayOf(PropTypes.string)
|
|
27
34
|
};
|
|
28
35
|
|
|
@@ -32,6 +39,7 @@ const ActionListFieldArray = forwardRef(({
|
|
|
32
39
|
columnMapping,
|
|
33
40
|
creatableFields,
|
|
34
41
|
createCallback,
|
|
42
|
+
defaultNewObject,
|
|
35
43
|
editableFields,
|
|
36
44
|
fields,
|
|
37
45
|
fieldComponents,
|
|
@@ -95,7 +103,7 @@ const ActionListFieldArray = forwardRef(({
|
|
|
95
103
|
|
|
96
104
|
const handleClickCreate = () => {
|
|
97
105
|
toggleEditing('NEW_ROW');
|
|
98
|
-
fields.unshift(
|
|
106
|
+
fields.unshift(defaultNewObject);
|
|
99
107
|
};
|
|
100
108
|
|
|
101
109
|
// Way to go into create mode from external component, and way to tell internal editing state
|
|
@@ -135,7 +143,7 @@ const ActionListFieldArray = forwardRef(({
|
|
|
135
143
|
<Button
|
|
136
144
|
key={`save[${data.rowIndex}]`}
|
|
137
145
|
buttonStyle="primary"
|
|
138
|
-
disabled={submitting || pristine}
|
|
146
|
+
disabled={hasValidationErrors || submitting || pristine}
|
|
139
147
|
marginBottom0
|
|
140
148
|
onClick={() => {
|
|
141
149
|
triggerFormSubmit(); // This is set up as () => null in ActionList, so essentially only acts here to force validation
|
|
@@ -237,7 +245,7 @@ const ActionListFieldArray = forwardRef(({
|
|
|
237
245
|
return (
|
|
238
246
|
fields.map((fieldName, fieldIndex) => {
|
|
239
247
|
// Fetch the content from the field Values
|
|
240
|
-
const cd = get(values, fieldName);
|
|
248
|
+
const cd = cloneDeep(get(values, fieldName));
|
|
241
249
|
cd.actionListActions = actionAssigner(cd);
|
|
242
250
|
return { ...cd, fieldName, fieldIndex };
|
|
243
251
|
})
|
|
@@ -277,10 +285,10 @@ const ActionListFieldArray = forwardRef(({
|
|
|
277
285
|
*/
|
|
278
286
|
if (
|
|
279
287
|
(!cd.id && createFunction(cd)) ||
|
|
280
|
-
(editFunction(cd))
|
|
288
|
+
(!!cd.id && editFunction(cd))
|
|
281
289
|
) {
|
|
282
290
|
const validateFunction = validateFields?.[key] ? validateFields?.[key](cd) : null;
|
|
283
|
-
|
|
291
|
+
|
|
284
292
|
returnValue =
|
|
285
293
|
fieldComponents[key] ?
|
|
286
294
|
fieldComponents[key]({
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
A component designed to render a list of objects, along with actions for each item.
|
|
3
3
|
Special actions are reserved for `create` and `edit`. Currently `edit` can only deal with scalar properties.
|
|
4
4
|
|
|
5
|
+
It is assumed that a unique `id` is present on each object in the contentData, as this is used internally to work out when a row is being edited/created.
|
|
6
|
+
|
|
5
7
|
## Basic Usage
|
|
6
8
|
```
|
|
7
9
|
import { useState } from 'react';
|
|
@@ -95,6 +97,7 @@ columnMapping | object | An object which will act on the rendered MultiColumnLis
|
|
|
95
97
|
contentData | array | An array of objects to render along with their actions | | ✓ |
|
|
96
98
|
creatableFields | object\<function> | An object with keys from the `visibleFields` array, and values of functions which take the entire row object and return a boolean indicating whether that field is fillable on create or not. | | ✕ |
|
|
97
99
|
createCallback | function | A callback to be used for the built in "create" action (ie "save" on a new row). Will be prioritised ahead of a `create` entry in the deprecated actionCalls prop. | {} | ✕ |
|
|
100
|
+
defaultNewObject | object | An object to use when pushing a new entry into the ActionList fields, acting as a way to bootstrap defaults into new items | {} | ✕ |
|
|
98
101
|
editableFields | object\<function> | An object with keys from the `visibleFields` array, and values of functions which take the entire row object and return a boolean indicating whether that field is editable or not. No key for a given field will be interpreted as () => true, so a field is editable by default. | | ✕ |
|
|
99
102
|
fieldComponents | object\<function> | An object with keys from the `visibleFields` array, and values of functions which take some `fieldProps` (currently only the name of the field `name`), and returns a Field component to be used in "edit mode" for the visible field specified. | | ✕ |
|
|
100
103
|
formatter | object\<function> | A "formatter" object that takes the same shape as an MCL formatter, and is used in the same way whilst a row is NOT being edited. While editing a given row, this formatter entry is ignored. | | ✕ |
|
|
@@ -51,7 +51,7 @@ const CustomPropertiesViewCtx = ({
|
|
|
51
51
|
{ path: 'retired' }, // Place retired custprops at the end
|
|
52
52
|
{ path: 'primary', direction: 'desc' }, // Primary properties should display before optional
|
|
53
53
|
{ path: 'weight' }, // Within those groups, sort by weight
|
|
54
|
-
{ path: 'label' } //For those with the same weight, sort by label
|
|
54
|
+
{ path: 'label' } // For those with the same weight, sort by label
|
|
55
55
|
]
|
|
56
56
|
}
|
|
57
57
|
});
|
|
@@ -26,7 +26,7 @@ const CycleButton = ({
|
|
|
26
26
|
onClick(e);
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
setIndex(index !== (buttons?.length -1) ? index + 1 : 0);
|
|
29
|
+
setIndex(index !== (buttons?.length - 1) ? index + 1 : 0);
|
|
30
30
|
}}
|
|
31
31
|
/>
|
|
32
32
|
);
|
|
@@ -37,7 +37,8 @@ CycleButton.propTypes = {
|
|
|
37
37
|
className: PropTypes.object,
|
|
38
38
|
icon: PropTypes.string.isRequired,
|
|
39
39
|
onClick: PropTypes.func.isRequired,
|
|
40
|
-
}))
|
|
40
|
+
})),
|
|
41
|
+
startIndex: PropTypes.number
|
|
41
42
|
};
|
|
42
43
|
|
|
43
44
|
export default CycleButton;
|
|
@@ -8,11 +8,15 @@ import { CalloutContext } from '@folio/stripes/core';
|
|
|
8
8
|
import { useMutateRefdataCategory, useRefdata } from '../hooks';
|
|
9
9
|
|
|
10
10
|
import ActionList from '../ActionList';
|
|
11
|
+
import { required } from '../utils/validators';
|
|
11
12
|
|
|
12
13
|
const propTypes = {
|
|
13
14
|
afterQueryCalls: PropTypes.object,
|
|
14
15
|
catchQueryCalls: PropTypes.object,
|
|
15
|
-
label: PropTypes.
|
|
16
|
+
label: PropTypes.oneOfType([
|
|
17
|
+
PropTypes.string,
|
|
18
|
+
PropTypes.node
|
|
19
|
+
]),
|
|
16
20
|
labelOverrides: PropTypes.object,
|
|
17
21
|
refdataEndpoint: PropTypes.string
|
|
18
22
|
};
|
|
@@ -134,6 +138,9 @@ const EditableRefdataCategoryList = ({
|
|
|
134
138
|
values: (rowData) => rowData?.values?.length
|
|
135
139
|
}}
|
|
136
140
|
label={label}
|
|
141
|
+
validateFields={{
|
|
142
|
+
desc: () => required
|
|
143
|
+
}}
|
|
137
144
|
visibleFields={['desc', 'values']}
|
|
138
145
|
/>
|
|
139
146
|
<ConfirmationModal
|
|
@@ -8,12 +8,16 @@ import { CalloutContext } from '@folio/stripes/core';
|
|
|
8
8
|
import { useMutateRefdataValue, useRefdata } from '../hooks';
|
|
9
9
|
|
|
10
10
|
import ActionList from '../ActionList';
|
|
11
|
+
import { required } from '../utils/validators';
|
|
11
12
|
|
|
12
13
|
const propTypes = {
|
|
13
14
|
afterQueryCalls: PropTypes.object,
|
|
14
15
|
catchQueryCalls: PropTypes.object,
|
|
15
16
|
desc: PropTypes.string,
|
|
16
|
-
label: PropTypes.
|
|
17
|
+
label: PropTypes.oneOfType([
|
|
18
|
+
PropTypes.string,
|
|
19
|
+
PropTypes.node
|
|
20
|
+
]),
|
|
17
21
|
labelOverrides: PropTypes.object,
|
|
18
22
|
refdataEndpoint: PropTypes.string
|
|
19
23
|
};
|
|
@@ -150,6 +154,9 @@ const EditableRefdataList = ({
|
|
|
150
154
|
value: () => false
|
|
151
155
|
}}
|
|
152
156
|
label={label}
|
|
157
|
+
validateFields={{
|
|
158
|
+
label: () => required
|
|
159
|
+
}}
|
|
153
160
|
visibleFields={['label', 'value']}
|
|
154
161
|
/>
|
|
155
162
|
<ConfirmationModal
|