@longline/aqua-ui 1.0.271 → 1.0.272

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.
@@ -90,6 +90,14 @@ interface IDropdownProps {
90
90
  * A minimum body width can be set for dropdowns that are very narrow.
91
91
  */
92
92
  minBodyWidth?: number;
93
+ /**
94
+ * Item matching strategy. By default, items are matched by converting
95
+ * them to JSON using JSON.stringify, then comparing the results. On some
96
+ * occasions (for example, when the items in `data` have fewer fields than
97
+ * the selected item), a different strategy is required.
98
+ * @default json
99
+ */
100
+ match?: 'equals' | 'json' | 'id' | 'uuid' | ((item1: any, item2: any) => boolean);
93
101
  /**
94
102
  * Fired when the Dropdown value changes.
95
103
  */
@@ -123,7 +131,7 @@ interface IDropdownProps {
123
131
  * ```
124
132
  */
125
133
  declare const Dropdown: {
126
- ({ direction, fluid, clearable, disabled, transparent, error, multiple, resetOnOpen, gap, maxItems, tall, label, ...props }: IDropdownProps): React.JSX.Element;
134
+ ({ direction, fluid, clearable, disabled, transparent, error, multiple, resetOnOpen, gap, maxItems, tall, label, match, ...props }: IDropdownProps): React.JSX.Element;
127
135
  displayName: string;
128
136
  /**
129
137
  * A Dropdown.Column's child is an item formatter function. A column can
@@ -269,6 +269,27 @@ var DropdownBase = function (props) {
269
269
  // Any other key's propagation is not stopped (most importantly
270
270
  // the TAB key to navigate to the next control).
271
271
  };
272
+ //
273
+ // Returns true if two items are equal. Comparison is done using
274
+ // different strategies.
275
+ //
276
+ var match = function (item1, item2) {
277
+ if (props.match === 'json') {
278
+ return JSON.stringify(item1) === JSON.stringify(item2);
279
+ }
280
+ else if (props.match === 'id') {
281
+ return (item1 === null || item1 === void 0 ? void 0 : item1.id) != null && (item2 === null || item2 === void 0 ? void 0 : item2.id) != null && item1.id === item2.id;
282
+ }
283
+ else if (props.match === 'uuid') {
284
+ return (item1 === null || item1 === void 0 ? void 0 : item1.uuid) != null && (item2 === null || item2 === void 0 ? void 0 : item2.uuid) != null && item1.uuid === item2.uuid;
285
+ }
286
+ else if (typeof (props.match) === 'function') {
287
+ return props.match(item1, item2);
288
+ }
289
+ else { // equals}
290
+ return item1 === item2;
291
+ }
292
+ };
272
293
  var updateValue = function (item) {
273
294
  setValue(item);
274
295
  if (props.onChange) {
@@ -288,10 +309,9 @@ var DropdownBase = function (props) {
288
309
  var array = Array.isArray(value) ? value : [];
289
310
  // Compare the new item with the existing selection items
290
311
  // using deep comparision.
291
- var newItem_1 = JSON.stringify(item);
292
- if (array.find(function (x) { return JSON.stringify(x) == newItem_1; })) {
312
+ if (array.find(function (x) { return match(x, item); })) {
293
313
  // Item already in selection. Remove it from the selection.
294
- updateValue(__spreadArray([], array.filter(function (x) { return x !== item; }), true));
314
+ updateValue(__spreadArray([], array.filter(function (x) { return !match(x, item); }), true));
295
315
  }
296
316
  else {
297
317
  // Item not in selection. Add it.
@@ -308,8 +328,7 @@ var DropdownBase = function (props) {
308
328
  var handleDelete = function (item) {
309
329
  // Find item in value array:
310
330
  var array = value;
311
- var toDelete = JSON.stringify(item);
312
- var index = array.findIndex(function (x) { return JSON.stringify(x) == toDelete; });
331
+ var index = array.findIndex(function (x) { return match(x, item); });
313
332
  // Remove item from selection:
314
333
  array.splice(index, 1);
315
334
  // Set new selection:
@@ -343,7 +362,7 @@ var DropdownBase = function (props) {
343
362
  var activeIndex = (props.data || []).indexOf(value);
344
363
  return (props.data || []).map(function (row, index) {
345
364
  return (React.createElement(ListRow, { active: index == activeIndex, key: index + 1, gap: props.gap, onClick: function (e) { return handleClick(e, row); } },
346
- props.multiple && React.createElement(Selector, { locked: true, checked: Array.isArray(value) && value.find(function (x) { return JSON.stringify(x) == JSON.stringify(row); }) }),
365
+ props.multiple && React.createElement(Selector, { locked: true, checked: Array.isArray(value) && value.find(function (x) { return match(x, row); }) }),
347
366
  columns.map(function (child, index) {
348
367
  return (React.createElement(ListCell, { key: index, width: child.props.width, align: child.props.align }, row !== null && child.props.children(row)));
349
368
  })));
@@ -434,8 +453,8 @@ var DropdownStyled = styled(DropdownBase)(templateObject_2 || (templateObject_2
434
453
  * ```
435
454
  */
436
455
  var Dropdown = function (_a) {
437
- var _b = _a.direction, direction = _b === void 0 ? 'down' : _b, _c = _a.fluid, fluid = _c === void 0 ? false : _c, _d = _a.clearable, clearable = _d === void 0 ? false : _d, _e = _a.disabled, disabled = _e === void 0 ? false : _e, _f = _a.transparent, transparent = _f === void 0 ? false : _f, _g = _a.error, error = _g === void 0 ? false : _g, _h = _a.multiple, multiple = _h === void 0 ? false : _h, _j = _a.resetOnOpen, resetOnOpen = _j === void 0 ? false : _j, _k = _a.gap, gap = _k === void 0 ? 16 : _k, _l = _a.maxItems, maxItems = _l === void 0 ? 6 : _l, _m = _a.tall, tall = _m === void 0 ? false : _m, _o = _a.label, label = _o === void 0 ? function (item) { return item; } : _o, props = __rest(_a, ["direction", "fluid", "clearable", "disabled", "transparent", "error", "multiple", "resetOnOpen", "gap", "maxItems", "tall", "label"]);
438
- return React.createElement(DropdownStyled, __assign({ direction: direction, fluid: fluid, clearable: clearable, disabled: disabled, transparent: transparent, error: error, multiple: multiple, resetOnOpen: resetOnOpen, gap: gap, maxItems: maxItems, tall: tall, label: label }, props));
456
+ var _b = _a.direction, direction = _b === void 0 ? 'down' : _b, _c = _a.fluid, fluid = _c === void 0 ? false : _c, _d = _a.clearable, clearable = _d === void 0 ? false : _d, _e = _a.disabled, disabled = _e === void 0 ? false : _e, _f = _a.transparent, transparent = _f === void 0 ? false : _f, _g = _a.error, error = _g === void 0 ? false : _g, _h = _a.multiple, multiple = _h === void 0 ? false : _h, _j = _a.resetOnOpen, resetOnOpen = _j === void 0 ? false : _j, _k = _a.gap, gap = _k === void 0 ? 16 : _k, _l = _a.maxItems, maxItems = _l === void 0 ? 6 : _l, _m = _a.tall, tall = _m === void 0 ? false : _m, _o = _a.label, label = _o === void 0 ? function (item) { return item; } : _o, _p = _a.match, match = _p === void 0 ? 'json' : _p, props = __rest(_a, ["direction", "fluid", "clearable", "disabled", "transparent", "error", "multiple", "resetOnOpen", "gap", "maxItems", "tall", "label", "match"]);
457
+ return React.createElement(DropdownStyled, __assign({ direction: direction, fluid: fluid, clearable: clearable, disabled: disabled, transparent: transparent, error: error, multiple: multiple, resetOnOpen: resetOnOpen, gap: gap, maxItems: maxItems, tall: tall, label: label, match: match }, props));
439
458
  };
440
459
  Dropdown.displayName = 'Dropdown';
441
460
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@longline/aqua-ui",
3
- "version": "1.0.271",
3
+ "version": "1.0.272",
4
4
  "description": "AquaUI",
5
5
  "author": "Alexander van Oostenrijk / Longline Environment",
6
6
  "license": "Commercial",