grommet 2.25.3 → 2.26.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/components/Box/stories/BackgroundThemed.js +54 -0
- package/components/Box/stories/CustomThemed/ThemedBackground.tsx +176 -0
- package/components/Calendar/Calendar.js +2 -1
- package/components/CheckBoxGroup/CheckBoxGroup.js +3 -2
- package/components/CheckBoxGroup/index.d.ts +2 -1
- package/components/CheckBoxGroup/propTypes.js +1 -0
- package/components/FormField/FormField.js +1 -1
- package/components/Heading/Heading.js +31 -2
- package/components/Heading/StyledHeading.js +1 -1
- package/components/Heading/index.d.ts +1 -0
- package/components/Heading/propTypes.js +1 -0
- package/components/Heading/stories/All.js +4 -1
- package/components/List/List.js +114 -33
- package/components/List/index.d.ts +1 -0
- package/components/List/propTypes.js +1 -0
- package/components/List/stories/Pinned.js +36 -0
- package/components/Notification/stories/CustomThemed/ThemedNotification.tsx +2 -2
- package/components/Select/DefaultSelectTextInput.js +43 -0
- package/components/Select/EmptySearchOption.js +34 -0
- package/components/Select/Select.js +30 -95
- package/components/Select/SelectContainer.js +19 -59
- package/components/Select/StyledSelect.js +58 -2
- package/components/Select/index.d.ts +11 -9
- package/components/Select/propTypes.js +44 -40
- package/components/Select/utils.js +103 -3
- package/components/SelectMultiple/README.md +2 -0
- package/components/SelectMultiple/SelectMultiple.js +476 -0
- package/components/SelectMultiple/SelectMultipleContainer.js +481 -0
- package/components/SelectMultiple/SelectMultipleValue.js +166 -0
- package/components/SelectMultiple/SelectionSummary.js +104 -0
- package/components/SelectMultiple/index.d.ts +21 -0
- package/components/SelectMultiple/index.js +8 -0
- package/components/SelectMultiple/propTypes.js +28 -0
- package/components/SelectMultiple/stories/Default.js +76 -0
- package/components/SelectMultiple/stories/Disabled.js +84 -0
- package/components/SelectMultiple/stories/FormField.js +66 -0
- package/components/SelectMultiple/stories/Limited.js +68 -0
- package/components/SelectMultiple/stories/LongList.js +76 -0
- package/components/SelectMultiple/stories/ObjectOptions.js +80 -0
- package/components/SelectMultiple/stories/ShowSelectedInline.js +76 -0
- package/components/SelectMultiple/stories/typescript/Children.tsx +106 -0
- package/components/index.d.ts +1 -0
- package/components/index.js +8 -0
- package/es6/components/Box/stories/BackgroundThemed.js +39 -0
- package/es6/components/Box/stories/CustomThemed/ThemedBackground.tsx +176 -0
- package/es6/components/Calendar/Calendar.js +2 -1
- package/es6/components/CheckBoxGroup/CheckBoxGroup.js +3 -2
- package/es6/components/CheckBoxGroup/index.d.ts +2 -1
- package/es6/components/CheckBoxGroup/propTypes.js +1 -0
- package/es6/components/FormField/FormField.js +1 -1
- package/es6/components/Heading/Heading.js +30 -3
- package/es6/components/Heading/StyledHeading.js +1 -1
- package/es6/components/Heading/index.d.ts +1 -0
- package/es6/components/Heading/propTypes.js +1 -0
- package/es6/components/Heading/stories/All.js +4 -1
- package/es6/components/List/List.js +115 -34
- package/es6/components/List/index.d.ts +1 -0
- package/es6/components/List/propTypes.js +1 -0
- package/es6/components/List/stories/Pinned.js +21 -0
- package/es6/components/Notification/stories/CustomThemed/ThemedNotification.tsx +2 -2
- package/es6/components/Select/DefaultSelectTextInput.js +31 -0
- package/es6/components/Select/EmptySearchOption.js +21 -0
- package/es6/components/Select/Select.js +26 -89
- package/es6/components/Select/SelectContainer.js +19 -58
- package/es6/components/Select/StyledSelect.js +45 -1
- package/es6/components/Select/index.d.ts +11 -9
- package/es6/components/Select/propTypes.js +41 -39
- package/es6/components/Select/utils.js +75 -1
- package/es6/components/SelectMultiple/README.md +2 -0
- package/es6/components/SelectMultiple/SelectMultiple.js +447 -0
- package/es6/components/SelectMultiple/SelectMultipleContainer.js +453 -0
- package/es6/components/SelectMultiple/SelectMultipleValue.js +152 -0
- package/es6/components/SelectMultiple/SelectionSummary.js +91 -0
- package/es6/components/SelectMultiple/index.d.ts +21 -0
- package/es6/components/SelectMultiple/index.js +1 -0
- package/es6/components/SelectMultiple/propTypes.js +18 -0
- package/es6/components/SelectMultiple/stories/Default.js +60 -0
- package/es6/components/SelectMultiple/stories/Disabled.js +68 -0
- package/es6/components/SelectMultiple/stories/FormField.js +50 -0
- package/es6/components/SelectMultiple/stories/Limited.js +53 -0
- package/es6/components/SelectMultiple/stories/LongList.js +63 -0
- package/es6/components/SelectMultiple/stories/ObjectOptions.js +64 -0
- package/es6/components/SelectMultiple/stories/ShowSelectedInline.js +61 -0
- package/es6/components/SelectMultiple/stories/typescript/Children.tsx +106 -0
- package/es6/components/index.d.ts +1 -0
- package/es6/components/index.js +1 -0
- package/es6/index.d.ts +1 -0
- package/es6/themes/base.d.ts +8 -2
- package/es6/themes/base.js +54 -38
- package/es6/themes/grommet.js +15 -0
- package/es6/utils/background.js +65 -12
- package/es6/utils/general-prop-types.js +2 -0
- package/es6/utils/index.d.ts +2 -0
- package/grommet.min.js +1 -1
- package/grommet.min.js.map +1 -1
- package/index.d.ts +1 -0
- package/package.json +4 -3
- package/themes/base.d.ts +8 -2
- package/themes/base.js +55 -38
- package/themes/grommet.js +15 -0
- package/utils/background.js +64 -12
- package/utils/general-prop-types.js +2 -0
- package/utils/index.d.ts +2 -0
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
var _excluded = ["a11yTitle", "aria-label", "action", "as", "background", "border", "children", "data", "defaultItemProps", "disabled", "focus", "itemKey", "itemProps", "onActive", "onClickItem", "onKeyDown", "onMore", "onOrder", "pad", "paginate", "primaryKey", "secondaryKey", "show", "step"];
|
|
1
|
+
var _excluded = ["a11yTitle", "aria-label", "action", "as", "background", "border", "children", "data", "defaultItemProps", "disabled", "focus", "itemKey", "itemProps", "onActive", "onClickItem", "onKeyDown", "onMore", "onOrder", "pad", "paginate", "pinned", "primaryKey", "secondaryKey", "show", "step"];
|
|
2
2
|
|
|
3
3
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
4
4
|
|
|
5
5
|
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; }
|
|
6
6
|
|
|
7
|
-
import React, { Fragment, useContext, useRef, useState } from 'react';
|
|
7
|
+
import React, { Fragment, useContext, useMemo, useRef, useState } from 'react';
|
|
8
8
|
import styled, { ThemeContext } from 'styled-components';
|
|
9
9
|
import { Box } from '../Box';
|
|
10
10
|
import { Button } from '../Button';
|
|
@@ -80,7 +80,7 @@ var normalize = function normalize(item, index, property) {
|
|
|
80
80
|
return item[property];
|
|
81
81
|
};
|
|
82
82
|
|
|
83
|
-
var reorder = function reorder(array, source, target) {
|
|
83
|
+
var reorder = function reorder(array, pinnedArray, source, target) {
|
|
84
84
|
var result = array.slice(0);
|
|
85
85
|
var tmp = result[source];
|
|
86
86
|
if (source < target) for (var i = source; i < target; i += 1) {
|
|
@@ -88,7 +88,15 @@ var reorder = function reorder(array, source, target) {
|
|
|
88
88
|
} else for (var _i = source; _i > target; _i -= 1) {
|
|
89
89
|
result[_i] = result[_i - 1];
|
|
90
90
|
}
|
|
91
|
-
result[target] = tmp;
|
|
91
|
+
result[target] = tmp; // insert pinned items into their proper index within the orderable
|
|
92
|
+
// data object to make the complete data set again
|
|
93
|
+
|
|
94
|
+
if (pinnedArray.data.length > 0) {
|
|
95
|
+
pinnedArray.data.forEach(function (pinnedItem, index) {
|
|
96
|
+
result.splice(pinnedArray.indexes[index], 0, pinnedItem);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
92
100
|
return result;
|
|
93
101
|
}; // Determine the primary content for a row. If the List
|
|
94
102
|
// has a primaryKey defined this returns the item data
|
|
@@ -137,7 +145,7 @@ var List = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
137
145
|
defaultItemProps = _ref.defaultItemProps,
|
|
138
146
|
disabledItems = _ref.disabled,
|
|
139
147
|
focus = _ref.focus,
|
|
140
|
-
|
|
148
|
+
defaultItemKey = _ref.itemKey,
|
|
141
149
|
itemProps = _ref.itemProps,
|
|
142
150
|
onActive = _ref.onActive,
|
|
143
151
|
onClickItem = _ref.onClickItem,
|
|
@@ -146,6 +154,8 @@ var List = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
146
154
|
onOrder = _ref.onOrder,
|
|
147
155
|
pad = _ref.pad,
|
|
148
156
|
paginate = _ref.paginate,
|
|
157
|
+
_ref$pinned = _ref.pinned,
|
|
158
|
+
pinned = _ref$pinned === void 0 ? [] : _ref$pinned,
|
|
149
159
|
primaryKey = _ref.primaryKey,
|
|
150
160
|
secondaryKey = _ref.secondaryKey,
|
|
151
161
|
showProp = _ref.show,
|
|
@@ -154,7 +164,9 @@ var List = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
154
164
|
rest = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
155
165
|
|
|
156
166
|
var listRef = useForwardedRef(ref);
|
|
157
|
-
var theme = useContext(ThemeContext); //
|
|
167
|
+
var theme = useContext(ThemeContext); // fixes issue where itemKey is undefined when only primaryKey is provided
|
|
168
|
+
|
|
169
|
+
var itemKey = defaultItemKey || primaryKey || null; // active will be the index of the current 'active'
|
|
158
170
|
// control in the list. If the onOrder property is defined
|
|
159
171
|
// this will be the index of up or down control for ordering
|
|
160
172
|
// items in the list. In this case the item index of that
|
|
@@ -184,7 +196,34 @@ var List = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
184
196
|
|
|
185
197
|
var _useState4 = useState(),
|
|
186
198
|
dragging = _useState4[0],
|
|
187
|
-
setDragging = _useState4[1];
|
|
199
|
+
setDragging = _useState4[1]; // store a reference to the pinned and the data that is orderable
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
var _useMemo = useMemo(function () {
|
|
203
|
+
var orderable = [];
|
|
204
|
+
var pinnedData = [];
|
|
205
|
+
var pinnedIndexes = [];
|
|
206
|
+
if (pinned.length === 0) return [data, {
|
|
207
|
+
data: pinnedData,
|
|
208
|
+
indexes: pinnedIndexes
|
|
209
|
+
}];
|
|
210
|
+
data.forEach(function (item, index) {
|
|
211
|
+
var key = typeof item === 'object' ? item[itemKey] : item;
|
|
212
|
+
|
|
213
|
+
if (pinned.includes(key)) {
|
|
214
|
+
pinnedData.push(item);
|
|
215
|
+
pinnedIndexes.push(index);
|
|
216
|
+
} else {
|
|
217
|
+
orderable.push(item);
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
return [orderable, {
|
|
221
|
+
data: pinnedData,
|
|
222
|
+
indexes: pinnedIndexes
|
|
223
|
+
}];
|
|
224
|
+
}, [data, itemKey, pinned]),
|
|
225
|
+
orderableData = _useMemo[0],
|
|
226
|
+
pinnedInfo = _useMemo[1];
|
|
188
227
|
|
|
189
228
|
var _usePagination = usePagination(_extends({
|
|
190
229
|
data: data,
|
|
@@ -216,10 +255,10 @@ var List = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
216
255
|
// figure out which arrow button will be the active one.
|
|
217
256
|
var buttonId = active % 2 ? 'MoveDown' : 'MoveUp';
|
|
218
257
|
var itemIndex = Math.trunc(active / 2);
|
|
219
|
-
activeId = "" + getItemId(
|
|
258
|
+
activeId = "" + getItemId(orderableData[itemIndex], itemIndex, primaryKey) + buttonId;
|
|
220
259
|
} else if (onClickItem) {
|
|
221
260
|
// The whole list item is active. Figure out an id
|
|
222
|
-
activeId = getItemId(
|
|
261
|
+
activeId = getItemId(orderableData[active], active, primaryKey);
|
|
223
262
|
}
|
|
224
263
|
|
|
225
264
|
ariaProps['aria-activedescendant'] = activeId;
|
|
@@ -234,10 +273,10 @@ var List = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
234
273
|
// even though it moved up or down.
|
|
235
274
|
|
|
236
275
|
if (active % 2) {
|
|
237
|
-
onOrder(reorder(
|
|
238
|
-
updateActive(Math.min(active + 2,
|
|
276
|
+
onOrder(reorder(orderableData, pinnedInfo, index, index + 1));
|
|
277
|
+
updateActive(Math.min(active + 2, orderableData.length * 2 - 2));
|
|
239
278
|
} else {
|
|
240
|
-
onOrder(reorder(
|
|
279
|
+
onOrder(reorder(orderableData, pinnedInfo, index, index - 1));
|
|
241
280
|
updateActive(Math.max(active - 2, 1));
|
|
242
281
|
}
|
|
243
282
|
} else if (disabledItems != null && disabledItems.includes(typeof itemKey === 'function' ? itemKey(data[active]) : data[active])) {
|
|
@@ -261,9 +300,9 @@ var List = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
261
300
|
var min = onOrder ? 1 : 0;
|
|
262
301
|
updateActive(Math.max(active - 1, min));
|
|
263
302
|
} : undefined,
|
|
264
|
-
onDown: (onClickItem || onOrder) &&
|
|
303
|
+
onDown: (onClickItem || onOrder) && orderableData && orderableData.length ? function () {
|
|
265
304
|
var min = onOrder ? 1 : 0;
|
|
266
|
-
var max = onOrder ?
|
|
305
|
+
var max = onOrder ? orderableData.length * 2 - 2 : data.length - 1;
|
|
267
306
|
updateActive(active >= min ? Math.min(active + 1, max) : min);
|
|
268
307
|
} : undefined,
|
|
269
308
|
onKeyDown: onKeyDown
|
|
@@ -348,6 +387,10 @@ var List = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
348
387
|
}
|
|
349
388
|
|
|
350
389
|
var key = itemKey ? itemId : getKey(item, index, itemId);
|
|
390
|
+
var orderableIndex = orderableData.findIndex(function (ordItem) {
|
|
391
|
+
var ordItemKey = typeof ordItem === 'object' ? ordItem[itemKey] : ordItem;
|
|
392
|
+
return ordItemKey === key;
|
|
393
|
+
});
|
|
351
394
|
var isDisabled;
|
|
352
395
|
|
|
353
396
|
if (disabledItems) {
|
|
@@ -359,6 +402,17 @@ var List = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
359
402
|
isDisabled = disabledItems == null ? void 0 : disabledItems.includes(key);
|
|
360
403
|
}
|
|
361
404
|
|
|
405
|
+
var isPinned;
|
|
406
|
+
|
|
407
|
+
if (pinned.length > 0) {
|
|
408
|
+
if (typeof item === 'object' && !itemKey) {
|
|
409
|
+
console.error( // eslint-disable-next-line max-len
|
|
410
|
+
"Warning: Missing prop itemKey. Prop pin requires itemKey to be specified when data is of type 'object'.");
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
isPinned = pinned == null ? void 0 : pinned.includes(key);
|
|
414
|
+
}
|
|
415
|
+
|
|
362
416
|
if (action) {
|
|
363
417
|
content = [/*#__PURE__*/React.createElement(Box, {
|
|
364
418
|
align: "start",
|
|
@@ -378,6 +432,8 @@ var List = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
378
432
|
adjustedBackground = theme.global.hover.background;
|
|
379
433
|
} else if (Array.isArray(adjustedBackground)) {
|
|
380
434
|
adjustedBackground = adjustedBackground[index % adjustedBackground.length];
|
|
435
|
+
} else if (isPinned) {
|
|
436
|
+
adjustedBackground = theme.list.item.pinned.background;
|
|
381
437
|
}
|
|
382
438
|
|
|
383
439
|
var adjustedBorder = border !== undefined ? border : theme.list.item.border;
|
|
@@ -438,7 +494,7 @@ var List = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
438
494
|
var orderProps;
|
|
439
495
|
var orderControls;
|
|
440
496
|
|
|
441
|
-
if (onOrder) {
|
|
497
|
+
if (onOrder && !isPinned) {
|
|
442
498
|
orderProps = {
|
|
443
499
|
draggable: true,
|
|
444
500
|
onDragStart: function onDragStart(event) {
|
|
@@ -447,7 +503,7 @@ var List = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
447
503
|
// eslint-disable-next-line no-param-reassign
|
|
448
504
|
|
|
449
505
|
event.dataTransfer.effectAllowed = 'move';
|
|
450
|
-
setDragging(
|
|
506
|
+
setDragging(orderableIndex);
|
|
451
507
|
updateActive(undefined);
|
|
452
508
|
},
|
|
453
509
|
onDragEnd: function onDragEnd() {
|
|
@@ -458,11 +514,11 @@ var List = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
458
514
|
if (dragging !== undefined) {
|
|
459
515
|
event.preventDefault();
|
|
460
516
|
|
|
461
|
-
if (dragging !==
|
|
517
|
+
if (dragging !== orderableIndex) {
|
|
462
518
|
// eslint-disable-next-line no-param-reassign
|
|
463
519
|
event.dataTransfer.dropEffect = 'move';
|
|
464
|
-
setOrderingData(reorder(
|
|
465
|
-
setDragging(
|
|
520
|
+
setOrderingData(reorder(orderableData, pinnedInfo, dragging, orderableIndex));
|
|
521
|
+
setDragging(orderableIndex);
|
|
466
522
|
}
|
|
467
523
|
}
|
|
468
524
|
},
|
|
@@ -471,35 +527,35 @@ var List = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
471
527
|
onOrder(orderingData);
|
|
472
528
|
}
|
|
473
529
|
},
|
|
474
|
-
ref: dragging ===
|
|
530
|
+
ref: dragging === orderableIndex ? draggingRef : undefined
|
|
475
531
|
};
|
|
476
532
|
var Up = theme.list.icons.up;
|
|
477
533
|
var Down = theme.list.icons.down;
|
|
478
|
-
orderControls = /*#__PURE__*/React.createElement(Box, {
|
|
534
|
+
orderControls = !isPinned && /*#__PURE__*/React.createElement(Box, {
|
|
479
535
|
direction: "row",
|
|
480
536
|
align: "center",
|
|
481
537
|
justify: "end"
|
|
482
538
|
}, /*#__PURE__*/React.createElement(Button, {
|
|
483
539
|
id: key + "MoveUp",
|
|
484
|
-
a11yTitle:
|
|
540
|
+
a11yTitle: orderableIndex + 1 + " " + key + " move up",
|
|
485
541
|
icon: /*#__PURE__*/React.createElement(Up, null),
|
|
486
542
|
hoverIndicator: true,
|
|
487
543
|
focusIndicator: false,
|
|
488
|
-
disabled: !
|
|
489
|
-
active: active ===
|
|
544
|
+
disabled: !orderableIndex,
|
|
545
|
+
active: active === orderableIndex * 2,
|
|
490
546
|
onClick: function onClick(event) {
|
|
491
547
|
event.stopPropagation();
|
|
492
|
-
onOrder(reorder(
|
|
548
|
+
onOrder(reorder(orderableData, pinnedInfo, orderableIndex, orderableIndex - 1));
|
|
493
549
|
},
|
|
494
550
|
tabIndex: -1,
|
|
495
551
|
onMouseOver: function onMouseOver() {
|
|
496
|
-
return updateActive(
|
|
552
|
+
return updateActive(orderableIndex * 2);
|
|
497
553
|
},
|
|
498
554
|
onMouseOut: function onMouseOut() {
|
|
499
555
|
return updateActive(undefined);
|
|
500
556
|
},
|
|
501
557
|
onFocus: function onFocus() {
|
|
502
|
-
updateActive(
|
|
558
|
+
updateActive(orderableIndex * 2);
|
|
503
559
|
setItemFocus(true);
|
|
504
560
|
},
|
|
505
561
|
onBlur: function onBlur() {
|
|
@@ -508,25 +564,25 @@ var List = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
508
564
|
}
|
|
509
565
|
}), /*#__PURE__*/React.createElement(Button, {
|
|
510
566
|
id: key + "MoveDown",
|
|
511
|
-
a11yTitle:
|
|
567
|
+
a11yTitle: orderableIndex + 1 + " " + key + " move down",
|
|
512
568
|
icon: /*#__PURE__*/React.createElement(Down, null),
|
|
513
569
|
hoverIndicator: true,
|
|
514
570
|
focusIndicator: false,
|
|
515
|
-
disabled:
|
|
516
|
-
active: active ===
|
|
571
|
+
disabled: orderableIndex >= orderableData.length - 1,
|
|
572
|
+
active: active === orderableIndex * 2 + 1,
|
|
517
573
|
onClick: function onClick(event) {
|
|
518
574
|
event.stopPropagation();
|
|
519
|
-
onOrder(reorder(
|
|
575
|
+
onOrder(reorder(orderableData, pinnedInfo, orderableIndex, orderableIndex + 1));
|
|
520
576
|
},
|
|
521
577
|
tabIndex: -1,
|
|
522
578
|
onMouseOver: function onMouseOver() {
|
|
523
|
-
return updateActive(
|
|
579
|
+
return updateActive(orderableIndex * 2 + 1);
|
|
524
580
|
},
|
|
525
581
|
onMouseOut: function onMouseOut() {
|
|
526
582
|
return updateActive(undefined);
|
|
527
583
|
},
|
|
528
584
|
onFocus: function onFocus() {
|
|
529
|
-
updateActive(
|
|
585
|
+
updateActive(orderableIndex * 2 + 1);
|
|
530
586
|
setItemFocus(true);
|
|
531
587
|
},
|
|
532
588
|
onBlur: function onBlur() {
|
|
@@ -558,6 +614,31 @@ var List = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
558
614
|
}
|
|
559
615
|
}
|
|
560
616
|
|
|
617
|
+
var displayPinned;
|
|
618
|
+
|
|
619
|
+
if (isPinned) {
|
|
620
|
+
// Pinned icon and settings
|
|
621
|
+
var Pin = theme.list.icons.pin;
|
|
622
|
+
var pinSize = theme.list.item.pinned.icon.size;
|
|
623
|
+
var pinPad = theme.list.item.pinned.icon.pad;
|
|
624
|
+
boxProps = {
|
|
625
|
+
direction: 'row',
|
|
626
|
+
align: defaultItemProps && defaultItemProps.align || 'center',
|
|
627
|
+
gap: 'medium'
|
|
628
|
+
};
|
|
629
|
+
displayPinned = /*#__PURE__*/React.createElement(Box, {
|
|
630
|
+
direction: "row",
|
|
631
|
+
align: "center",
|
|
632
|
+
justify: "end",
|
|
633
|
+
pad: pinPad
|
|
634
|
+
}, /*#__PURE__*/React.createElement(Pin, {
|
|
635
|
+
size: pinSize
|
|
636
|
+
}));
|
|
637
|
+
content = /*#__PURE__*/React.createElement(Box, {
|
|
638
|
+
flex: true
|
|
639
|
+
}, content);
|
|
640
|
+
}
|
|
641
|
+
|
|
561
642
|
if (itemProps && itemProps[index]) {
|
|
562
643
|
boxProps = _extends({}, boxProps, itemProps[index]);
|
|
563
644
|
}
|
|
@@ -570,7 +651,7 @@ var List = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
570
651
|
isDisabled: isDisabled,
|
|
571
652
|
flex: false,
|
|
572
653
|
pad: pad || theme.list.item.pad
|
|
573
|
-
}, defaultItemProps, boxProps, clickProps, orderProps, itemAriaProps), onOrder && /*#__PURE__*/React.createElement(Text, null, index + 1), content, orderControls);
|
|
654
|
+
}, defaultItemProps, boxProps, clickProps, orderProps, itemAriaProps), onOrder && /*#__PURE__*/React.createElement(Text, null, index + 1), content, displayPinned, orderControls);
|
|
574
655
|
}))), paginate && data.length > step && items && items.length ? /*#__PURE__*/React.createElement(Pagination, _extends({
|
|
575
656
|
alignSelf: "end"
|
|
576
657
|
}, paginationProps)) : null);
|
|
@@ -61,6 +61,7 @@ export interface ListProps<ListItemType> {
|
|
|
61
61
|
onOrder?: (orderedData: ListItemType[]) => void;
|
|
62
62
|
pad?: PadType;
|
|
63
63
|
paginate?: boolean | PaginationType;
|
|
64
|
+
pinned?: (string | number)[];
|
|
64
65
|
primaryKey?: string | ((item: ListItemType) => React.ReactElement);
|
|
65
66
|
secondaryKey?: string | ((item: ListItemType) => React.ReactElement);
|
|
66
67
|
show?: number | { page?: number };
|
|
@@ -37,6 +37,7 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
37
37
|
onOrder: PropTypes.func,
|
|
38
38
|
pad: PropTypes.oneOfType([padPropType]),
|
|
39
39
|
paginate: PropTypes.oneOfType([PropTypes.bool, PropTypes.object]),
|
|
40
|
+
pinned: PropTypes.arrayOf(PropTypes.string),
|
|
40
41
|
primaryKey: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
|
41
42
|
secondaryKey: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
|
42
43
|
show: PropTypes.oneOfType([PropTypes.number, PropTypes.shape({
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { Box, List } from 'grommet';
|
|
3
|
+
var locations = ['Los Angelos', 'Boise', 'Fort Collins', 'Los Gatos', 'Palo Alto', 'Pheonix', 'San Francisco', 'Trenton'];
|
|
4
|
+
var pinnedLocations = ['Los Angelos', 'Fort Collins', 'Palo Alto', 'Pheonix', 'Trenton'];
|
|
5
|
+
export var Pinned = function Pinned() {
|
|
6
|
+
var _useState = useState(locations),
|
|
7
|
+
ordered = _useState[0],
|
|
8
|
+
setOrder = _useState[1];
|
|
9
|
+
|
|
10
|
+
return /*#__PURE__*/React.createElement(Box, {
|
|
11
|
+
align: "center",
|
|
12
|
+
pad: "large"
|
|
13
|
+
}, /*#__PURE__*/React.createElement(List, {
|
|
14
|
+
data: ordered,
|
|
15
|
+
onOrder: setOrder,
|
|
16
|
+
pinned: pinnedLocations
|
|
17
|
+
}));
|
|
18
|
+
};
|
|
19
|
+
export default {
|
|
20
|
+
title: 'Visualizations/List/Pinned'
|
|
21
|
+
};
|
|
@@ -4,7 +4,7 @@ import { Box, Grommet, Notification } from 'grommet';
|
|
|
4
4
|
|
|
5
5
|
import { deepMerge } from 'grommet/utils';
|
|
6
6
|
import { grommet, ThemeType } from 'grommet/themes';
|
|
7
|
-
import {
|
|
7
|
+
import { CircleQuestion } from 'grommet-icons';
|
|
8
8
|
|
|
9
9
|
// Type annotations can only be used in TypeScript files.
|
|
10
10
|
// Remove ': ThemeType' if you are not using Typescript.
|
|
@@ -18,7 +18,6 @@ const customTheme: ThemeType = deepMerge(grommet, {
|
|
|
18
18
|
container: {
|
|
19
19
|
// any BoxProps
|
|
20
20
|
pad: { horizontal: 'large', vertical: '36px' },
|
|
21
|
-
background: '#87a200',
|
|
22
21
|
border: { color: '#000000', size: 'large' },
|
|
23
22
|
},
|
|
24
23
|
iconContainer: {
|
|
@@ -46,6 +45,7 @@ const customTheme: ThemeType = deepMerge(grommet, {
|
|
|
46
45
|
},
|
|
47
46
|
unknown: {
|
|
48
47
|
icon: CircleQuestion,
|
|
48
|
+
background: '#87a200',
|
|
49
49
|
},
|
|
50
50
|
},
|
|
51
51
|
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
var _excluded = ["disabled", "id"];
|
|
2
|
+
|
|
3
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
4
|
+
|
|
5
|
+
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; }
|
|
6
|
+
|
|
7
|
+
import React, { forwardRef } from 'react';
|
|
8
|
+
import { SelectTextInput } from './StyledSelect';
|
|
9
|
+
export var DefaultSelectTextInput = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
10
|
+
var disabled = _ref.disabled,
|
|
11
|
+
id = _ref.id,
|
|
12
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
13
|
+
|
|
14
|
+
return /*#__PURE__*/React.createElement(SelectTextInput // When Select is disabled, we want to show a default cursor
|
|
15
|
+
// but not have disabled styling come from TextInput
|
|
16
|
+
// Disabled can be a bool or an array of options to disable.
|
|
17
|
+
// We only want to disable the TextInput if the control
|
|
18
|
+
// button should be disabled which occurs when disabled
|
|
19
|
+
// equals true.
|
|
20
|
+
, _extends({
|
|
21
|
+
defaultCursor: disabled === true || undefined,
|
|
22
|
+
focusIndicator: false,
|
|
23
|
+
id: id ? id + "__input" : undefined,
|
|
24
|
+
ref: ref
|
|
25
|
+
}, rest, {
|
|
26
|
+
tabIndex: "-1",
|
|
27
|
+
type: "text",
|
|
28
|
+
plain: true,
|
|
29
|
+
readOnly: true
|
|
30
|
+
}));
|
|
31
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
+
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { Box } from '../Box';
|
|
5
|
+
import { Text } from '../Text';
|
|
6
|
+
import { SelectOption } from './StyledSelect';
|
|
7
|
+
export var EmptySearchOption = function EmptySearchOption(_ref) {
|
|
8
|
+
var emptySearchMessage = _ref.emptySearchMessage,
|
|
9
|
+
selectOptionsStyle = _ref.selectOptionsStyle,
|
|
10
|
+
theme = _ref.theme;
|
|
11
|
+
return /*#__PURE__*/React.createElement(SelectOption, {
|
|
12
|
+
key: "search_empty",
|
|
13
|
+
tabIndex: "0",
|
|
14
|
+
role: "menuitem",
|
|
15
|
+
hoverIndicator: "background",
|
|
16
|
+
disabled: true
|
|
17
|
+
}, /*#__PURE__*/React.createElement(Box, selectOptionsStyle, /*#__PURE__*/React.createElement(Text, _extends({
|
|
18
|
+
"aria-live": "polite",
|
|
19
|
+
role: "alert"
|
|
20
|
+
}, theme.select.container.text), emptySearchMessage)));
|
|
21
|
+
};
|
|
@@ -5,38 +5,18 @@ function _extends() { _extends = Object.assign ? Object.assign.bind() : function
|
|
|
5
5
|
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; }
|
|
6
6
|
|
|
7
7
|
import React, { forwardRef, isValidElement, useCallback, useContext, useMemo, useState, useRef, useEffect } from 'react';
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
8
|
+
import { ThemeContext } from 'styled-components';
|
|
9
|
+
import { useKeyboard } from '../../utils';
|
|
10
10
|
import { defaultProps } from '../../default-props';
|
|
11
11
|
import { Box } from '../Box';
|
|
12
|
-
import { DropButton } from '../DropButton';
|
|
13
12
|
import { Keyboard } from '../Keyboard';
|
|
14
13
|
import { FormContext } from '../Form/FormContext';
|
|
15
|
-
import { TextInput } from '../TextInput';
|
|
16
14
|
import { SelectContainer } from './SelectContainer';
|
|
17
|
-
import {
|
|
15
|
+
import { HiddenInput, StyledSelectDropButton } from './StyledSelect';
|
|
16
|
+
import { applyKey, getNormalizedValue, changeEvent, getSelectIcon, getDisplayLabelKey, getIconColor } from './utils';
|
|
17
|
+
import { DefaultSelectTextInput } from './DefaultSelectTextInput';
|
|
18
18
|
import { MessageContext } from '../../contexts/MessageContext';
|
|
19
19
|
import { SelectPropTypes } from './propTypes';
|
|
20
|
-
var SelectTextInput = styled(TextInput).withConfig({
|
|
21
|
-
displayName: "Select__SelectTextInput",
|
|
22
|
-
componentId: "sc-17idtfo-0"
|
|
23
|
-
})(["cursor:", ";"], function (props) {
|
|
24
|
-
return props.defaultCursor ? 'default' : 'pointer';
|
|
25
|
-
});
|
|
26
|
-
var HiddenInput = styled.input.withConfig({
|
|
27
|
-
displayName: "Select__HiddenInput",
|
|
28
|
-
componentId: "sc-17idtfo-1"
|
|
29
|
-
})(["display:none;"]);
|
|
30
|
-
var StyledSelectDropButton = styled(DropButton).withConfig({
|
|
31
|
-
displayName: "Select__StyledSelectDropButton",
|
|
32
|
-
componentId: "sc-17idtfo-2"
|
|
33
|
-
})(["", ";", ";", ";"], function (props) {
|
|
34
|
-
return !props.callerPlain && controlBorderStyle;
|
|
35
|
-
}, function (props) {
|
|
36
|
-
return props.theme.select && props.theme.select.control && props.theme.select.control.extend;
|
|
37
|
-
}, function (props) {
|
|
38
|
-
return props.open && props.theme.select.control.open;
|
|
39
|
-
});
|
|
40
20
|
StyledSelectDropButton.defaultProps = {};
|
|
41
21
|
Object.setPrototypeOf(StyledSelectDropButton.defaultProps, defaultProps);
|
|
42
22
|
var defaultDropAlign = {
|
|
@@ -115,7 +95,7 @@ var Select = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
115
95
|
initialValue: defaultValue || ''
|
|
116
96
|
}),
|
|
117
97
|
value = _formContext$useFormI[0],
|
|
118
|
-
setValue = _formContext$useFormI[1]; //
|
|
98
|
+
setValue = _formContext$useFormI[1]; // normalizedValue is the value mapped with any valueKey applied
|
|
119
99
|
// When the options array contains objects, this property indicates how
|
|
120
100
|
// to retrieve the value of each option.
|
|
121
101
|
// If a string is provided, it is used as the key to retrieve a
|
|
@@ -126,11 +106,8 @@ var Select = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
126
106
|
// delivered via 'onChange'.
|
|
127
107
|
|
|
128
108
|
|
|
129
|
-
var
|
|
130
|
-
|
|
131
|
-
return valueKey && valueKey.reduce ? v : applyKey(v, valueKey);
|
|
132
|
-
});
|
|
133
|
-
return valueKey && valueKey.reduce ? value : applyKey(value, valueKey);
|
|
109
|
+
var normalizedValue = useMemo(function () {
|
|
110
|
+
return getNormalizedValue(value, valueKey);
|
|
134
111
|
}, [value, valueKey]); // search input value
|
|
135
112
|
|
|
136
113
|
var _useState = useState(),
|
|
@@ -158,18 +135,18 @@ var Select = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
158
135
|
} else if (index === selected) {
|
|
159
136
|
result.push(index);
|
|
160
137
|
}
|
|
161
|
-
} else if (Array.isArray(
|
|
162
|
-
if (
|
|
138
|
+
} else if (Array.isArray(normalizedValue)) {
|
|
139
|
+
if (normalizedValue.some(function (v) {
|
|
163
140
|
return v === applyKey(option, valueKey);
|
|
164
141
|
})) {
|
|
165
142
|
result.push(index);
|
|
166
143
|
}
|
|
167
|
-
} else if (
|
|
144
|
+
} else if (normalizedValue === applyKey(option, valueKey)) {
|
|
168
145
|
result.push(index);
|
|
169
146
|
}
|
|
170
147
|
});
|
|
171
148
|
return result;
|
|
172
|
-
}, [allOptions, selected, valueKey,
|
|
149
|
+
}, [allOptions, selected, valueKey, normalizedValue]);
|
|
173
150
|
|
|
174
151
|
var _useState3 = useState(propOpen),
|
|
175
152
|
open = _useState3[0],
|
|
@@ -189,16 +166,7 @@ var Select = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
189
166
|
setSearch();
|
|
190
167
|
}, [onClose]);
|
|
191
168
|
var triggerChangeEvent = useCallback(function (nextValue) {
|
|
192
|
-
|
|
193
|
-
// overrides setter `event.target.value =` and loses original event
|
|
194
|
-
// target fidelity.
|
|
195
|
-
// https://stackoverflow.com/a/46012210
|
|
196
|
-
var nativeInputValueSetter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, 'value').set;
|
|
197
|
-
nativeInputValueSetter.call(inputRef.current, nextValue);
|
|
198
|
-
var event = new Event('input', {
|
|
199
|
-
bubbles: true
|
|
200
|
-
});
|
|
201
|
-
inputRef.current.dispatchEvent(event);
|
|
169
|
+
return changeEvent(inputRef, nextValue);
|
|
202
170
|
}, []);
|
|
203
171
|
var onSelectChange = useCallback(function (event, _ref2) {
|
|
204
172
|
var option = _ref2.option,
|
|
@@ -208,7 +176,7 @@ var Select = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
208
176
|
// input. if it is an object, then the user has not provided necessary
|
|
209
177
|
// props to reduce object option
|
|
210
178
|
|
|
211
|
-
if (typeof nextValue !== 'object' && nextValue !== event.target.value && inputRef.current) {
|
|
179
|
+
if ((typeof nextValue !== 'object' || multiple) && nextValue !== event.target.value && inputRef.current) {
|
|
212
180
|
// select registers changing option as a click event or keydown.
|
|
213
181
|
// when in a form, we need to programatically trigger a change
|
|
214
182
|
// event in order for the change event to be registered upstream
|
|
@@ -248,22 +216,8 @@ var Select = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
248
216
|
|
|
249
217
|
onChange(adjustedEvent);
|
|
250
218
|
}
|
|
251
|
-
}, [closeOnChange, onChange, onRequestClose, setValue, triggerChangeEvent]);
|
|
252
|
-
var SelectIcon;
|
|
253
|
-
|
|
254
|
-
switch (icon) {
|
|
255
|
-
case false:
|
|
256
|
-
break;
|
|
257
|
-
|
|
258
|
-
case true:
|
|
259
|
-
case undefined:
|
|
260
|
-
SelectIcon = open && theme.select.icons.up ? theme.select.icons.up : theme.select.icons.down;
|
|
261
|
-
break;
|
|
262
|
-
|
|
263
|
-
default:
|
|
264
|
-
SelectIcon = icon;
|
|
265
|
-
} // element to show, trumps inputValue
|
|
266
|
-
|
|
219
|
+
}, [closeOnChange, multiple, onChange, onRequestClose, setValue, triggerChangeEvent]);
|
|
220
|
+
var SelectIcon = getSelectIcon(icon, theme, open); // element to show, trumps inputValue
|
|
267
221
|
|
|
268
222
|
var selectValue = useMemo(function () {
|
|
269
223
|
if (valueLabel instanceof Function) {
|
|
@@ -272,14 +226,9 @@ var Select = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
272
226
|
|
|
273
227
|
|
|
274
228
|
return undefined;
|
|
275
|
-
}, [value, valueLabel]);
|
|
276
|
-
// we should use the labelKey function to display the
|
|
277
|
-
// selected value
|
|
278
|
-
|
|
229
|
+
}, [value, valueLabel]);
|
|
279
230
|
var displayLabelKey = useMemo(function () {
|
|
280
|
-
|
|
281
|
-
if (!selectValue && optionIndexesInValue.length === 1 && typeof optionLabelKey === 'object') return optionLabelKey;
|
|
282
|
-
return undefined;
|
|
231
|
+
return getDisplayLabelKey(labelKey, allOptions, optionIndexesInValue, selectValue);
|
|
283
232
|
}, [labelKey, allOptions, optionIndexesInValue, selectValue]); // text to show
|
|
284
233
|
// When the options array contains objects, this property indicates how
|
|
285
234
|
// to retrieve the value of each option.
|
|
@@ -302,7 +251,7 @@ var Select = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
302
251
|
|
|
303
252
|
return undefined;
|
|
304
253
|
}, [labelKey, messages, format, optionIndexesInValue, allOptions, selectValue]);
|
|
305
|
-
var iconColor =
|
|
254
|
+
var iconColor = getIconColor(theme);
|
|
306
255
|
return /*#__PURE__*/React.createElement(Keyboard, {
|
|
307
256
|
onDown: onRequestOpen,
|
|
308
257
|
onUp: onRequestOpen
|
|
@@ -358,7 +307,7 @@ var Select = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
358
307
|
valueKey: valueKey
|
|
359
308
|
}, children) // StyledDropButton needs to know if the border should be shown
|
|
360
309
|
,
|
|
361
|
-
|
|
310
|
+
plainSelect: plain,
|
|
362
311
|
plain: true // Button should be plain
|
|
363
312
|
,
|
|
364
313
|
dropProps: dropProps,
|
|
@@ -379,29 +328,17 @@ var Select = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
379
328
|
value: inputValue,
|
|
380
329
|
ref: inputRef,
|
|
381
330
|
readOnly: true
|
|
382
|
-
})) : /*#__PURE__*/React.createElement(
|
|
383
|
-
a11yTitle: (ariaLabel || a11yTitle) && "" + (ariaLabel || a11yTitle) + (value && typeof value === 'string' ? ", " + value : '')
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
// We only want to disable the TextInput if the control
|
|
387
|
-
// button should be disabled which occurs when disabled
|
|
388
|
-
// equals true.
|
|
389
|
-
,
|
|
390
|
-
defaultCursor: disabled === true || undefined,
|
|
391
|
-
focusIndicator: false,
|
|
392
|
-
id: id ? id + "__input" : undefined,
|
|
331
|
+
})) : /*#__PURE__*/React.createElement(DefaultSelectTextInput, _extends({
|
|
332
|
+
a11yTitle: (ariaLabel || a11yTitle) && "" + (ariaLabel || a11yTitle) + (value && typeof value === 'string' ? ", " + value : ''),
|
|
333
|
+
disabled: disabled,
|
|
334
|
+
id: id,
|
|
393
335
|
name: name,
|
|
394
|
-
ref: inputRef
|
|
395
|
-
}, rest, {
|
|
396
|
-
tabIndex: "-1",
|
|
397
|
-
type: "text",
|
|
336
|
+
ref: inputRef,
|
|
398
337
|
placeholder: placeholder,
|
|
399
|
-
plain: true,
|
|
400
|
-
readOnly: true,
|
|
401
338
|
value: inputValue,
|
|
402
339
|
size: size,
|
|
403
340
|
theme: theme
|
|
404
|
-
}))), SelectIcon && /*#__PURE__*/React.createElement(Box, {
|
|
341
|
+
}, rest))), SelectIcon && /*#__PURE__*/React.createElement(Box, {
|
|
405
342
|
margin: theme.select.icons.margin,
|
|
406
343
|
flex: false,
|
|
407
344
|
style: {
|