@pingux/astro 1.10.1-alpha.2 → 1.11.0-alpha.0
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/lib/cjs/components/MultivaluesField/MultivaluesField.js +36 -20
- package/lib/cjs/components/MultivaluesField/MultivaluesField.stories.js +16 -2
- package/lib/cjs/components/MultivaluesField/MultivaluesField.test.js +22 -1
- package/lib/cjs/styles/variants/boxes.js +23 -0
- package/lib/components/MultivaluesField/MultivaluesField.js +37 -20
- package/lib/components/MultivaluesField/MultivaluesField.stories.js +11 -0
- package/lib/components/MultivaluesField/MultivaluesField.test.js +16 -1
- package/lib/styles/variants/boxes.js +23 -0
- package/package.json +1 -1
@@ -114,6 +114,8 @@ var MultivaluesField = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref)
|
|
114
114
|
onOpenChange = props.onOpenChange,
|
115
115
|
onSelectionChange = props.onSelectionChange,
|
116
116
|
placeholder = props.placeholder,
|
117
|
+
_props$readOnlyKeys = props.readOnlyKeys,
|
118
|
+
readOnlyKeys = _props$readOnlyKeys === void 0 ? [] : _props$readOnlyKeys,
|
117
119
|
selectedKeys = props.selectedKeys,
|
118
120
|
scrollBoxProps = props.scrollBoxProps;
|
119
121
|
var hasCustomValue = mode === 'non-restrictive';
|
@@ -162,7 +164,10 @@ var MultivaluesField = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref)
|
|
162
164
|
return contains(item.textValue, filterString);
|
163
165
|
});
|
164
166
|
},
|
165
|
-
items: items,
|
167
|
+
items: (0, _filter["default"])(items).call(items, function (_ref) {
|
168
|
+
var key = _ref.key;
|
169
|
+
return !(0, _includes["default"])(readOnlyKeys).call(readOnlyKeys, key);
|
170
|
+
}),
|
166
171
|
onSelectionChange: toggleItems,
|
167
172
|
selectionMode: 'multiple'
|
168
173
|
}));
|
@@ -309,10 +314,8 @@ var MultivaluesField = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref)
|
|
309
314
|
selectionManager.toggleSelection(key);
|
310
315
|
};
|
311
316
|
|
312
|
-
var
|
313
|
-
var
|
314
|
-
|
315
|
-
var item = (0, _find["default"])(_context5 = (0, _concat["default"])(_context6 = []).call(_context6, initialItems, customItems)).call(_context5, function (el) {
|
317
|
+
var readOnlyItems = (0, _react2.jsx)(_react["default"].Fragment, null, (0, _map["default"])(readOnlyKeys).call(readOnlyKeys, function (key) {
|
318
|
+
var item = (0, _find["default"])(initialItems).call(initialItems, function (el) {
|
316
319
|
return el.key === key;
|
317
320
|
});
|
318
321
|
|
@@ -320,25 +323,33 @@ var MultivaluesField = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref)
|
|
320
323
|
return (0, _react2.jsx)(_.Chip, {
|
321
324
|
key: item.key,
|
322
325
|
role: "presentation",
|
323
|
-
bg: "active",
|
324
|
-
color: "white",
|
325
326
|
label: item.name,
|
326
|
-
|
327
|
-
|
328
|
-
cursor: 'default',
|
329
|
-
height: '100%',
|
330
|
-
m: 5,
|
331
|
-
mr: 10,
|
332
|
-
ml: 0,
|
333
|
-
py: 3,
|
334
|
-
pr: 0
|
335
|
-
},
|
327
|
+
variant: "boxes.readOnlyChip",
|
328
|
+
bg: "white",
|
336
329
|
textProps: {
|
337
330
|
sx: {
|
338
|
-
|
339
|
-
textTransform: 'none'
|
331
|
+
color: 'text.primary'
|
340
332
|
}
|
341
333
|
}
|
334
|
+
});
|
335
|
+
}
|
336
|
+
|
337
|
+
return null;
|
338
|
+
}));
|
339
|
+
var selectedItems = (0, _react2.jsx)(_react["default"].Fragment, null, (0, _map["default"])(_context4 = (0, _from["default"])(selectionManager.selectedKeys)).call(_context4, function (key) {
|
340
|
+
var _context5, _context6;
|
341
|
+
|
342
|
+
var item = (0, _find["default"])(_context5 = (0, _concat["default"])(_context6 = []).call(_context6, initialItems, customItems)).call(_context5, function (el) {
|
343
|
+
return el.key === key;
|
344
|
+
});
|
345
|
+
|
346
|
+
if (item) {
|
347
|
+
return (0, _react2.jsx)(_.Chip, {
|
348
|
+
key: item.key,
|
349
|
+
role: "presentation",
|
350
|
+
variant: "boxes.selectedItemChip",
|
351
|
+
bg: "active",
|
352
|
+
label: item.name
|
342
353
|
}, (0, _react2.jsx)(_.IconButton, {
|
343
354
|
"aria-label": "delete",
|
344
355
|
onPress: function onPress() {
|
@@ -406,7 +417,7 @@ var MultivaluesField = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref)
|
|
406
417
|
return _onKeyUp && _onKeyUp(e.nativeEvent);
|
407
418
|
},
|
408
419
|
slots: {
|
409
|
-
beforeInput: selectedItems
|
420
|
+
beforeInput: (0, _react2.jsx)(_react["default"].Fragment, null, readOnlyItems, " ", selectedItems)
|
410
421
|
},
|
411
422
|
value: filterString
|
412
423
|
}, inputProps)), (0, _react2.jsx)(_.PopoverContainer, {
|
@@ -517,6 +528,11 @@ MultivaluesField.propTypes = {
|
|
517
528
|
/** Temporary text that occupies the text input when it is empty. */
|
518
529
|
placeholder: _propTypes["default"].string,
|
519
530
|
|
531
|
+
/**
|
532
|
+
* The item keys that are readonly. These items cannot be changed or selected.
|
533
|
+
*/
|
534
|
+
readOnlyKeys: _propTypes["default"].arrayOf(_propTypes["default"].string),
|
535
|
+
|
520
536
|
/** The currently selected keys in the collection (controlled). */
|
521
537
|
selectedKeys: _isIterable.isIterableProp,
|
522
538
|
// /** Props object that is spread directly into the ScrollBox element. */
|
@@ -14,7 +14,7 @@ _Object$defineProperty(exports, "__esModule", {
|
|
14
14
|
value: true
|
15
15
|
});
|
16
16
|
|
17
|
-
exports["default"] = exports.WithDisabledKeys = exports.WithCustomValues = exports.WithCustomSize = exports.Uncontrolled = exports.Default = exports.Controlled = void 0;
|
17
|
+
exports["default"] = exports.WithReadOnlyValues = exports.WithDisabledKeys = exports.WithCustomValues = exports.WithCustomSize = exports.Uncontrolled = exports.Default = exports.Controlled = void 0;
|
18
18
|
|
19
19
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/slicedToArray"));
|
20
20
|
|
@@ -217,4 +217,18 @@ var WithCustomSize = function WithCustomSize(args) {
|
|
217
217
|
}))));
|
218
218
|
};
|
219
219
|
|
220
|
-
exports.WithCustomSize = WithCustomSize;
|
220
|
+
exports.WithCustomSize = WithCustomSize;
|
221
|
+
|
222
|
+
var WithReadOnlyValues = function WithReadOnlyValues(args) {
|
223
|
+
return (0, _react2.jsx)(_.OverlayProvider, null, (0, _react2.jsx)(_.MultivaluesField, (0, _extends2["default"])({
|
224
|
+
readOnlyKeys: ['Aardvark', 'Snake'],
|
225
|
+
items: items
|
226
|
+
}, args), function (item) {
|
227
|
+
return (0, _react2.jsx)(_.Item, {
|
228
|
+
key: item.key,
|
229
|
+
"data-id": item.name
|
230
|
+
}, item.name);
|
231
|
+
}));
|
232
|
+
};
|
233
|
+
|
234
|
+
exports.WithReadOnlyValues = WithReadOnlyValues;
|
@@ -458,4 +458,25 @@ test('should have no accessibility violations', /*#__PURE__*/(0, _asyncToGenerat
|
|
458
458
|
}
|
459
459
|
}
|
460
460
|
}, _callee);
|
461
|
-
})));
|
461
|
+
})));
|
462
|
+
test('read only keys', function () {
|
463
|
+
getComponent({
|
464
|
+
readOnlyKeys: [items[1].key, items[2].key]
|
465
|
+
});
|
466
|
+
|
467
|
+
var listbox = _testWrapper.screen.queryByRole('listbox');
|
468
|
+
|
469
|
+
expect(listbox).not.toBeInTheDocument();
|
470
|
+
|
471
|
+
var firstChip = _testWrapper.screen.getByText(items[1].name);
|
472
|
+
|
473
|
+
var deleteButton1 = firstChip.nextSibling;
|
474
|
+
expect(firstChip).toBeInTheDocument();
|
475
|
+
expect(deleteButton1).toBeNull();
|
476
|
+
|
477
|
+
var secondChip = _testWrapper.screen.getByText(items[2].name);
|
478
|
+
|
479
|
+
expect(secondChip).toBeInTheDocument();
|
480
|
+
var deleteButton2 = firstChip.nextSibling;
|
481
|
+
expect(deleteButton2).toBeNull();
|
482
|
+
});
|
@@ -133,6 +133,27 @@ var chip = {
|
|
133
133
|
}
|
134
134
|
};
|
135
135
|
exports.chip = chip;
|
136
|
+
|
137
|
+
var multivaluesChip = _objectSpread(_objectSpread({}, chip), {}, {
|
138
|
+
alignSelf: 'center',
|
139
|
+
cursor: 'default',
|
140
|
+
height: '100%',
|
141
|
+
m: 5,
|
142
|
+
mr: 10,
|
143
|
+
ml: 0
|
144
|
+
});
|
145
|
+
|
146
|
+
var selectedItemChip = _objectSpread(_objectSpread({}, multivaluesChip), {}, {
|
147
|
+
py: 3,
|
148
|
+
pr: 0
|
149
|
+
});
|
150
|
+
|
151
|
+
var readOnlyChip = _objectSpread(_objectSpread({}, multivaluesChip), {}, {
|
152
|
+
p: 3,
|
153
|
+
border: '1px solid',
|
154
|
+
borderColor: 'neutral.80'
|
155
|
+
});
|
156
|
+
|
136
157
|
var inputInContainerSlot = {
|
137
158
|
position: 'absolute',
|
138
159
|
bg: 'transparent',
|
@@ -309,6 +330,8 @@ var _default = {
|
|
309
330
|
base: base,
|
310
331
|
card: card,
|
311
332
|
chip: chip,
|
333
|
+
selectedItemChip: selectedItemChip,
|
334
|
+
readOnlyChip: readOnlyChip,
|
312
335
|
copy: copy,
|
313
336
|
datePicker: datePicker,
|
314
337
|
environmentChip: environmentChip,
|
@@ -67,6 +67,8 @@ var MultivaluesField = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
67
67
|
onOpenChange = props.onOpenChange,
|
68
68
|
onSelectionChange = props.onSelectionChange,
|
69
69
|
placeholder = props.placeholder,
|
70
|
+
_props$readOnlyKeys = props.readOnlyKeys,
|
71
|
+
readOnlyKeys = _props$readOnlyKeys === void 0 ? [] : _props$readOnlyKeys,
|
70
72
|
selectedKeys = props.selectedKeys,
|
71
73
|
scrollBoxProps = props.scrollBoxProps;
|
72
74
|
var hasCustomValue = mode === 'non-restrictive';
|
@@ -115,7 +117,10 @@ var MultivaluesField = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
115
117
|
return contains(item.textValue, filterString);
|
116
118
|
});
|
117
119
|
},
|
118
|
-
items: items,
|
120
|
+
items: _filterInstanceProperty(items).call(items, function (_ref) {
|
121
|
+
var key = _ref.key;
|
122
|
+
return !_includesInstanceProperty(readOnlyKeys).call(readOnlyKeys, key);
|
123
|
+
}),
|
119
124
|
onSelectionChange: toggleItems,
|
120
125
|
selectionMode: 'multiple'
|
121
126
|
}));
|
@@ -262,10 +267,8 @@ var MultivaluesField = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
262
267
|
selectionManager.toggleSelection(key);
|
263
268
|
};
|
264
269
|
|
265
|
-
var
|
266
|
-
var
|
267
|
-
|
268
|
-
var item = _findInstanceProperty(_context5 = _concatInstanceProperty(_context6 = []).call(_context6, initialItems, customItems)).call(_context5, function (el) {
|
270
|
+
var readOnlyItems = ___EmotionJSX(React.Fragment, null, _mapInstanceProperty(readOnlyKeys).call(readOnlyKeys, function (key) {
|
271
|
+
var item = _findInstanceProperty(initialItems).call(initialItems, function (el) {
|
269
272
|
return el.key === key;
|
270
273
|
});
|
271
274
|
|
@@ -273,25 +276,34 @@ var MultivaluesField = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
273
276
|
return ___EmotionJSX(Chip, {
|
274
277
|
key: item.key,
|
275
278
|
role: "presentation",
|
276
|
-
bg: "active",
|
277
|
-
color: "white",
|
278
279
|
label: item.name,
|
279
|
-
|
280
|
-
|
281
|
-
cursor: 'default',
|
282
|
-
height: '100%',
|
283
|
-
m: 5,
|
284
|
-
mr: 10,
|
285
|
-
ml: 0,
|
286
|
-
py: 3,
|
287
|
-
pr: 0
|
288
|
-
},
|
280
|
+
variant: "boxes.readOnlyChip",
|
281
|
+
bg: "white",
|
289
282
|
textProps: {
|
290
283
|
sx: {
|
291
|
-
|
292
|
-
textTransform: 'none'
|
284
|
+
color: 'text.primary'
|
293
285
|
}
|
294
286
|
}
|
287
|
+
});
|
288
|
+
}
|
289
|
+
|
290
|
+
return null;
|
291
|
+
}));
|
292
|
+
|
293
|
+
var selectedItems = ___EmotionJSX(React.Fragment, null, _mapInstanceProperty(_context4 = _Array$from(selectionManager.selectedKeys)).call(_context4, function (key) {
|
294
|
+
var _context5, _context6;
|
295
|
+
|
296
|
+
var item = _findInstanceProperty(_context5 = _concatInstanceProperty(_context6 = []).call(_context6, initialItems, customItems)).call(_context5, function (el) {
|
297
|
+
return el.key === key;
|
298
|
+
});
|
299
|
+
|
300
|
+
if (item) {
|
301
|
+
return ___EmotionJSX(Chip, {
|
302
|
+
key: item.key,
|
303
|
+
role: "presentation",
|
304
|
+
variant: "boxes.selectedItemChip",
|
305
|
+
bg: "active",
|
306
|
+
label: item.name
|
295
307
|
}, ___EmotionJSX(IconButton, {
|
296
308
|
"aria-label": "delete",
|
297
309
|
onPress: function onPress() {
|
@@ -360,7 +372,7 @@ var MultivaluesField = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
360
372
|
return _onKeyUp && _onKeyUp(e.nativeEvent);
|
361
373
|
},
|
362
374
|
slots: {
|
363
|
-
beforeInput: selectedItems
|
375
|
+
beforeInput: ___EmotionJSX(React.Fragment, null, readOnlyItems, " ", selectedItems)
|
364
376
|
},
|
365
377
|
value: filterString
|
366
378
|
}, inputProps)), ___EmotionJSX(PopoverContainer, {
|
@@ -471,6 +483,11 @@ MultivaluesField.propTypes = {
|
|
471
483
|
/** Temporary text that occupies the text input when it is empty. */
|
472
484
|
placeholder: PropTypes.string,
|
473
485
|
|
486
|
+
/**
|
487
|
+
* The item keys that are readonly. These items cannot be changed or selected.
|
488
|
+
*/
|
489
|
+
readOnlyKeys: PropTypes.arrayOf(PropTypes.string),
|
490
|
+
|
474
491
|
/** The currently selected keys in the collection (controlled). */
|
475
492
|
selectedKeys: isIterableProp,
|
476
493
|
// /** Props object that is spread directly into the ScrollBox element. */
|
@@ -171,4 +171,15 @@ export var WithCustomSize = function WithCustomSize(args) {
|
|
171
171
|
"data-id": item.name
|
172
172
|
}, item.name);
|
173
173
|
}))));
|
174
|
+
};
|
175
|
+
export var WithReadOnlyValues = function WithReadOnlyValues(args) {
|
176
|
+
return ___EmotionJSX(OverlayProvider, null, ___EmotionJSX(MultivaluesField, _extends({
|
177
|
+
readOnlyKeys: ['Aardvark', 'Snake'],
|
178
|
+
items: items
|
179
|
+
}, args), function (item) {
|
180
|
+
return ___EmotionJSX(Item, {
|
181
|
+
key: item.key,
|
182
|
+
"data-id": item.name
|
183
|
+
}, item.name);
|
184
|
+
}));
|
174
185
|
};
|
@@ -342,4 +342,19 @@ test('should have no accessibility violations', /*#__PURE__*/_asyncToGenerator(
|
|
342
342
|
}
|
343
343
|
}
|
344
344
|
}, _callee);
|
345
|
-
})));
|
345
|
+
})));
|
346
|
+
test('read only keys', function () {
|
347
|
+
getComponent({
|
348
|
+
readOnlyKeys: [items[1].key, items[2].key]
|
349
|
+
});
|
350
|
+
var listbox = screen.queryByRole('listbox');
|
351
|
+
expect(listbox).not.toBeInTheDocument();
|
352
|
+
var firstChip = screen.getByText(items[1].name);
|
353
|
+
var deleteButton1 = firstChip.nextSibling;
|
354
|
+
expect(firstChip).toBeInTheDocument();
|
355
|
+
expect(deleteButton1).toBeNull();
|
356
|
+
var secondChip = screen.getByText(items[2].name);
|
357
|
+
expect(secondChip).toBeInTheDocument();
|
358
|
+
var deleteButton2 = firstChip.nextSibling;
|
359
|
+
expect(deleteButton2).toBeNull();
|
360
|
+
});
|
@@ -113,6 +113,27 @@ export var chip = {
|
|
113
113
|
}
|
114
114
|
}
|
115
115
|
};
|
116
|
+
|
117
|
+
var multivaluesChip = _objectSpread(_objectSpread({}, chip), {}, {
|
118
|
+
alignSelf: 'center',
|
119
|
+
cursor: 'default',
|
120
|
+
height: '100%',
|
121
|
+
m: 5,
|
122
|
+
mr: 10,
|
123
|
+
ml: 0
|
124
|
+
});
|
125
|
+
|
126
|
+
var selectedItemChip = _objectSpread(_objectSpread({}, multivaluesChip), {}, {
|
127
|
+
py: 3,
|
128
|
+
pr: 0
|
129
|
+
});
|
130
|
+
|
131
|
+
var readOnlyChip = _objectSpread(_objectSpread({}, multivaluesChip), {}, {
|
132
|
+
p: 3,
|
133
|
+
border: '1px solid',
|
134
|
+
borderColor: 'neutral.80'
|
135
|
+
});
|
136
|
+
|
116
137
|
var inputInContainerSlot = {
|
117
138
|
position: 'absolute',
|
118
139
|
bg: 'transparent',
|
@@ -289,6 +310,8 @@ export default {
|
|
289
310
|
base: base,
|
290
311
|
card: card,
|
291
312
|
chip: chip,
|
313
|
+
selectedItemChip: selectedItemChip,
|
314
|
+
readOnlyChip: readOnlyChip,
|
292
315
|
copy: copy,
|
293
316
|
datePicker: datePicker,
|
294
317
|
environmentChip: environmentChip,
|