grommet 2.25.2 → 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.
Files changed (111) hide show
  1. package/components/Anchor/Anchor.js +1 -1
  2. package/components/Box/stories/BackgroundThemed.js +54 -0
  3. package/components/Box/stories/CustomThemed/ThemedBackground.tsx +176 -0
  4. package/components/Button/Button.js +2 -2
  5. package/components/Calendar/Calendar.js +2 -1
  6. package/components/CheckBoxGroup/CheckBoxGroup.js +3 -2
  7. package/components/CheckBoxGroup/index.d.ts +2 -1
  8. package/components/CheckBoxGroup/propTypes.js +1 -0
  9. package/components/FormField/FormField.js +1 -1
  10. package/components/Heading/Heading.js +31 -2
  11. package/components/Heading/StyledHeading.js +1 -1
  12. package/components/Heading/index.d.ts +1 -0
  13. package/components/Heading/propTypes.js +1 -0
  14. package/components/Heading/stories/All.js +4 -1
  15. package/components/Layer/LayerContainer.js +16 -9
  16. package/components/List/List.js +131 -33
  17. package/components/List/index.d.ts +1 -0
  18. package/components/List/propTypes.js +1 -0
  19. package/components/List/stories/Pinned.js +36 -0
  20. package/components/Notification/stories/CustomThemed/ThemedNotification.tsx +2 -2
  21. package/components/Select/DefaultSelectTextInput.js +43 -0
  22. package/components/Select/EmptySearchOption.js +34 -0
  23. package/components/Select/Select.js +30 -95
  24. package/components/Select/SelectContainer.js +19 -59
  25. package/components/Select/StyledSelect.js +58 -2
  26. package/components/Select/index.d.ts +11 -9
  27. package/components/Select/propTypes.js +44 -40
  28. package/components/Select/utils.js +103 -3
  29. package/components/SelectMultiple/README.md +2 -0
  30. package/components/SelectMultiple/SelectMultiple.js +476 -0
  31. package/components/SelectMultiple/SelectMultipleContainer.js +481 -0
  32. package/components/SelectMultiple/SelectMultipleValue.js +166 -0
  33. package/components/SelectMultiple/SelectionSummary.js +104 -0
  34. package/components/SelectMultiple/index.d.ts +21 -0
  35. package/components/SelectMultiple/index.js +8 -0
  36. package/components/SelectMultiple/propTypes.js +28 -0
  37. package/components/SelectMultiple/stories/Default.js +76 -0
  38. package/components/SelectMultiple/stories/Disabled.js +84 -0
  39. package/components/SelectMultiple/stories/FormField.js +66 -0
  40. package/components/SelectMultiple/stories/Limited.js +68 -0
  41. package/components/SelectMultiple/stories/LongList.js +76 -0
  42. package/components/SelectMultiple/stories/ObjectOptions.js +80 -0
  43. package/components/SelectMultiple/stories/ShowSelectedInline.js +76 -0
  44. package/components/SelectMultiple/stories/typescript/Children.tsx +106 -0
  45. package/components/index.d.ts +1 -0
  46. package/components/index.js +8 -0
  47. package/es6/components/Anchor/Anchor.js +2 -2
  48. package/es6/components/Box/stories/BackgroundThemed.js +39 -0
  49. package/es6/components/Box/stories/CustomThemed/ThemedBackground.tsx +176 -0
  50. package/es6/components/Button/Button.js +3 -3
  51. package/es6/components/Calendar/Calendar.js +2 -1
  52. package/es6/components/CheckBoxGroup/CheckBoxGroup.js +3 -2
  53. package/es6/components/CheckBoxGroup/index.d.ts +2 -1
  54. package/es6/components/CheckBoxGroup/propTypes.js +1 -0
  55. package/es6/components/FormField/FormField.js +1 -1
  56. package/es6/components/Heading/Heading.js +30 -3
  57. package/es6/components/Heading/StyledHeading.js +1 -1
  58. package/es6/components/Heading/index.d.ts +1 -0
  59. package/es6/components/Heading/propTypes.js +1 -0
  60. package/es6/components/Heading/stories/All.js +4 -1
  61. package/es6/components/Layer/LayerContainer.js +16 -9
  62. package/es6/components/List/List.js +131 -34
  63. package/es6/components/List/index.d.ts +1 -0
  64. package/es6/components/List/propTypes.js +1 -0
  65. package/es6/components/List/stories/Pinned.js +21 -0
  66. package/es6/components/Notification/stories/CustomThemed/ThemedNotification.tsx +2 -2
  67. package/es6/components/Select/DefaultSelectTextInput.js +31 -0
  68. package/es6/components/Select/EmptySearchOption.js +21 -0
  69. package/es6/components/Select/Select.js +26 -89
  70. package/es6/components/Select/SelectContainer.js +19 -58
  71. package/es6/components/Select/StyledSelect.js +45 -1
  72. package/es6/components/Select/index.d.ts +11 -9
  73. package/es6/components/Select/propTypes.js +41 -39
  74. package/es6/components/Select/utils.js +75 -1
  75. package/es6/components/SelectMultiple/README.md +2 -0
  76. package/es6/components/SelectMultiple/SelectMultiple.js +447 -0
  77. package/es6/components/SelectMultiple/SelectMultipleContainer.js +453 -0
  78. package/es6/components/SelectMultiple/SelectMultipleValue.js +152 -0
  79. package/es6/components/SelectMultiple/SelectionSummary.js +91 -0
  80. package/es6/components/SelectMultiple/index.d.ts +21 -0
  81. package/es6/components/SelectMultiple/index.js +1 -0
  82. package/es6/components/SelectMultiple/propTypes.js +18 -0
  83. package/es6/components/SelectMultiple/stories/Default.js +60 -0
  84. package/es6/components/SelectMultiple/stories/Disabled.js +68 -0
  85. package/es6/components/SelectMultiple/stories/FormField.js +50 -0
  86. package/es6/components/SelectMultiple/stories/Limited.js +53 -0
  87. package/es6/components/SelectMultiple/stories/LongList.js +63 -0
  88. package/es6/components/SelectMultiple/stories/ObjectOptions.js +64 -0
  89. package/es6/components/SelectMultiple/stories/ShowSelectedInline.js +61 -0
  90. package/es6/components/SelectMultiple/stories/typescript/Children.tsx +106 -0
  91. package/es6/components/index.d.ts +1 -0
  92. package/es6/components/index.js +1 -0
  93. package/es6/index.d.ts +1 -0
  94. package/es6/themes/base.d.ts +8 -2
  95. package/es6/themes/base.js +54 -38
  96. package/es6/themes/grommet.js +15 -0
  97. package/es6/utils/DOM.js +4 -0
  98. package/es6/utils/background.js +65 -12
  99. package/es6/utils/general-prop-types.js +2 -0
  100. package/es6/utils/index.d.ts +2 -0
  101. package/grommet.min.js +1 -1
  102. package/grommet.min.js.map +1 -1
  103. package/index.d.ts +1 -0
  104. package/package.json +7 -6
  105. package/themes/base.d.ts +8 -2
  106. package/themes/base.js +55 -38
  107. package/themes/grommet.js +15 -0
  108. package/utils/DOM.js +9 -2
  109. package/utils/background.js +64 -12
  110. package/utils/general-prop-types.js +2 -0
  111. package/utils/index.d.ts +2 -0
@@ -62,18 +62,25 @@ var LayerContainer = /*#__PURE__*/forwardRef(function (_ref, ref) {
62
62
  useEffect(function () {
63
63
  var start = new Date();
64
64
  var element = layerRef.current;
65
- sendAnalytics({
66
- type: 'layerOpen',
67
- element: element
68
- });
69
- return function () {
65
+ var isHidden = position === 'hidden';
66
+
67
+ if (!isHidden) {
70
68
  sendAnalytics({
71
- type: 'layerClose',
72
- element: element,
73
- elapsed: new Date().getTime() - start.getTime()
69
+ type: 'layerOpen',
70
+ element: element
74
71
  });
72
+ }
73
+
74
+ return function () {
75
+ if (!isHidden) {
76
+ sendAnalytics({
77
+ type: 'layerClose',
78
+ element: element,
79
+ elapsed: new Date().getTime() - start.getTime()
80
+ });
81
+ }
75
82
  };
76
- }, [sendAnalytics, layerRef]);
83
+ }, [sendAnalytics, layerRef, position]);
77
84
  useEffect(function () {
78
85
  if (position !== 'hidden') {
79
86
  var node = layerRef.current || containerRef.current || ref.current;
@@ -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';
@@ -13,6 +13,7 @@ import { Keyboard } from '../Keyboard';
13
13
  import { Pagination } from '../Pagination';
14
14
  import { Text } from '../Text';
15
15
  import { focusStyle, genericStyles, normalizeColor, normalizeShow, unfocusStyle, useForwardedRef, usePagination } from '../../utils';
16
+ import { useAnalytics } from '../../contexts/AnalyticsContext';
16
17
  import { ListPropTypes } from './propTypes';
17
18
  var StyledList = styled.ul.withConfig({
18
19
  displayName: "List__StyledList",
@@ -79,7 +80,7 @@ var normalize = function normalize(item, index, property) {
79
80
  return item[property];
80
81
  };
81
82
 
82
- var reorder = function reorder(array, source, target) {
83
+ var reorder = function reorder(array, pinnedArray, source, target) {
83
84
  var result = array.slice(0);
84
85
  var tmp = result[source];
85
86
  if (source < target) for (var i = source; i < target; i += 1) {
@@ -87,7 +88,15 @@ var reorder = function reorder(array, source, target) {
87
88
  } else for (var _i = source; _i > target; _i -= 1) {
88
89
  result[_i] = result[_i - 1];
89
90
  }
90
- 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
+
91
100
  return result;
92
101
  }; // Determine the primary content for a row. If the List
93
102
  // has a primaryKey defined this returns the item data
@@ -136,7 +145,7 @@ var List = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
136
145
  defaultItemProps = _ref.defaultItemProps,
137
146
  disabledItems = _ref.disabled,
138
147
  focus = _ref.focus,
139
- itemKey = _ref.itemKey,
148
+ defaultItemKey = _ref.itemKey,
140
149
  itemProps = _ref.itemProps,
141
150
  onActive = _ref.onActive,
142
151
  onClickItem = _ref.onClickItem,
@@ -145,6 +154,8 @@ var List = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
145
154
  onOrder = _ref.onOrder,
146
155
  pad = _ref.pad,
147
156
  paginate = _ref.paginate,
157
+ _ref$pinned = _ref.pinned,
158
+ pinned = _ref$pinned === void 0 ? [] : _ref$pinned,
148
159
  primaryKey = _ref.primaryKey,
149
160
  secondaryKey = _ref.secondaryKey,
150
161
  showProp = _ref.show,
@@ -153,7 +164,9 @@ var List = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
153
164
  rest = _objectWithoutPropertiesLoose(_ref, _excluded);
154
165
 
155
166
  var listRef = useForwardedRef(ref);
156
- var theme = useContext(ThemeContext); // active will be the index of the current 'active'
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'
157
170
  // control in the list. If the onOrder property is defined
158
171
  // this will be the index of up or down control for ordering
159
172
  // items in the list. In this case the item index of that
@@ -183,7 +196,34 @@ var List = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
183
196
 
184
197
  var _useState4 = useState(),
185
198
  dragging = _useState4[0],
186
- 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];
187
227
 
188
228
  var _usePagination = usePagination(_extends({
189
229
  data: data,
@@ -201,6 +241,7 @@ var List = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
201
241
  setOrderingData = _useState5[1];
202
242
 
203
243
  var draggingRef = useRef();
244
+ var sendAnalytics = useAnalytics();
204
245
  var ariaProps = {
205
246
  role: onClickItem || onOrder ? 'listbox' : 'list'
206
247
  };
@@ -214,10 +255,10 @@ var List = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
214
255
  // figure out which arrow button will be the active one.
215
256
  var buttonId = active % 2 ? 'MoveDown' : 'MoveUp';
216
257
  var itemIndex = Math.trunc(active / 2);
217
- activeId = "" + getItemId(data[itemIndex], itemIndex, primaryKey) + buttonId;
258
+ activeId = "" + getItemId(orderableData[itemIndex], itemIndex, primaryKey) + buttonId;
218
259
  } else if (onClickItem) {
219
260
  // The whole list item is active. Figure out an id
220
- activeId = getItemId(data[active], active, primaryKey);
261
+ activeId = getItemId(orderableData[active], active, primaryKey);
221
262
  }
222
263
 
223
264
  ariaProps['aria-activedescendant'] = activeId;
@@ -232,10 +273,10 @@ var List = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
232
273
  // even though it moved up or down.
233
274
 
234
275
  if (active % 2) {
235
- onOrder(reorder(data, index, index + 1));
236
- updateActive(Math.min(active + 2, data.length * 2 - 2));
276
+ onOrder(reorder(orderableData, pinnedInfo, index, index + 1));
277
+ updateActive(Math.min(active + 2, orderableData.length * 2 - 2));
237
278
  } else {
238
- onOrder(reorder(data, index, index - 1));
279
+ onOrder(reorder(orderableData, pinnedInfo, index, index - 1));
239
280
  updateActive(Math.max(active - 2, 1));
240
281
  }
241
282
  } else if (disabledItems != null && disabledItems.includes(typeof itemKey === 'function' ? itemKey(data[active]) : data[active])) {
@@ -246,15 +287,22 @@ var List = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
246
287
  adjustedEvent.item = data[active];
247
288
  adjustedEvent.index = active;
248
289
  onClickItem(adjustedEvent);
290
+ sendAnalytics({
291
+ type: 'listItemClick',
292
+ element: listRef.current,
293
+ event: adjustedEvent,
294
+ item: data[active],
295
+ index: active
296
+ });
249
297
  }
250
298
  } : undefined,
251
299
  onUp: (onClickItem || onOrder) && active ? function () {
252
300
  var min = onOrder ? 1 : 0;
253
301
  updateActive(Math.max(active - 1, min));
254
302
  } : undefined,
255
- onDown: (onClickItem || onOrder) && data && data.length ? function () {
303
+ onDown: (onClickItem || onOrder) && orderableData && orderableData.length ? function () {
256
304
  var min = onOrder ? 1 : 0;
257
- var max = onOrder ? data.length * 2 - 2 : data.length - 1;
305
+ var max = onOrder ? orderableData.length * 2 - 2 : data.length - 1;
258
306
  updateActive(active >= min ? Math.min(active + 1, max) : min);
259
307
  } : undefined,
260
308
  onKeyDown: onKeyDown
@@ -339,6 +387,10 @@ var List = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
339
387
  }
340
388
 
341
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
+ });
342
394
  var isDisabled;
343
395
 
344
396
  if (disabledItems) {
@@ -350,6 +402,17 @@ var List = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
350
402
  isDisabled = disabledItems == null ? void 0 : disabledItems.includes(key);
351
403
  }
352
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
+
353
416
  if (action) {
354
417
  content = [/*#__PURE__*/React.createElement(Box, {
355
418
  align: "start",
@@ -369,6 +432,8 @@ var List = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
369
432
  adjustedBackground = theme.global.hover.background;
370
433
  } else if (Array.isArray(adjustedBackground)) {
371
434
  adjustedBackground = adjustedBackground[index % adjustedBackground.length];
435
+ } else if (isPinned) {
436
+ adjustedBackground = theme.list.item.pinned.background;
372
437
  }
373
438
 
374
439
  var adjustedBorder = border !== undefined ? border : theme.list.item.border;
@@ -400,6 +465,13 @@ var List = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
400
465
  // accessibility guidelines that focus remains on `ul`
401
466
 
402
467
  listRef.current.focus();
468
+ sendAnalytics({
469
+ type: 'listItemClick',
470
+ element: listRef.current,
471
+ event: adjustedEvent,
472
+ item: item,
473
+ index: index
474
+ });
403
475
  }
404
476
  },
405
477
  onMouseOver: function onMouseOver() {
@@ -422,7 +494,7 @@ var List = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
422
494
  var orderProps;
423
495
  var orderControls;
424
496
 
425
- if (onOrder) {
497
+ if (onOrder && !isPinned) {
426
498
  orderProps = {
427
499
  draggable: true,
428
500
  onDragStart: function onDragStart(event) {
@@ -431,7 +503,7 @@ var List = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
431
503
  // eslint-disable-next-line no-param-reassign
432
504
 
433
505
  event.dataTransfer.effectAllowed = 'move';
434
- setDragging(index);
506
+ setDragging(orderableIndex);
435
507
  updateActive(undefined);
436
508
  },
437
509
  onDragEnd: function onDragEnd() {
@@ -442,11 +514,11 @@ var List = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
442
514
  if (dragging !== undefined) {
443
515
  event.preventDefault();
444
516
 
445
- if (dragging !== index) {
517
+ if (dragging !== orderableIndex) {
446
518
  // eslint-disable-next-line no-param-reassign
447
519
  event.dataTransfer.dropEffect = 'move';
448
- setOrderingData(reorder(orderingData || data, dragging, index));
449
- setDragging(index);
520
+ setOrderingData(reorder(orderableData, pinnedInfo, dragging, orderableIndex));
521
+ setDragging(orderableIndex);
450
522
  }
451
523
  }
452
524
  },
@@ -455,35 +527,35 @@ var List = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
455
527
  onOrder(orderingData);
456
528
  }
457
529
  },
458
- ref: dragging === index ? draggingRef : undefined
530
+ ref: dragging === orderableIndex ? draggingRef : undefined
459
531
  };
460
532
  var Up = theme.list.icons.up;
461
533
  var Down = theme.list.icons.down;
462
- orderControls = /*#__PURE__*/React.createElement(Box, {
534
+ orderControls = !isPinned && /*#__PURE__*/React.createElement(Box, {
463
535
  direction: "row",
464
536
  align: "center",
465
537
  justify: "end"
466
538
  }, /*#__PURE__*/React.createElement(Button, {
467
539
  id: key + "MoveUp",
468
- a11yTitle: index + 1 + " " + key + " move up",
540
+ a11yTitle: orderableIndex + 1 + " " + key + " move up",
469
541
  icon: /*#__PURE__*/React.createElement(Up, null),
470
542
  hoverIndicator: true,
471
543
  focusIndicator: false,
472
- disabled: !index,
473
- active: active === index * 2,
544
+ disabled: !orderableIndex,
545
+ active: active === orderableIndex * 2,
474
546
  onClick: function onClick(event) {
475
547
  event.stopPropagation();
476
- onOrder(reorder(data, index, index - 1));
548
+ onOrder(reorder(orderableData, pinnedInfo, orderableIndex, orderableIndex - 1));
477
549
  },
478
550
  tabIndex: -1,
479
551
  onMouseOver: function onMouseOver() {
480
- return updateActive(index * 2);
552
+ return updateActive(orderableIndex * 2);
481
553
  },
482
554
  onMouseOut: function onMouseOut() {
483
555
  return updateActive(undefined);
484
556
  },
485
557
  onFocus: function onFocus() {
486
- updateActive(index * 2);
558
+ updateActive(orderableIndex * 2);
487
559
  setItemFocus(true);
488
560
  },
489
561
  onBlur: function onBlur() {
@@ -492,25 +564,25 @@ var List = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
492
564
  }
493
565
  }), /*#__PURE__*/React.createElement(Button, {
494
566
  id: key + "MoveDown",
495
- a11yTitle: index + 1 + " " + key + " move down",
567
+ a11yTitle: orderableIndex + 1 + " " + key + " move down",
496
568
  icon: /*#__PURE__*/React.createElement(Down, null),
497
569
  hoverIndicator: true,
498
570
  focusIndicator: false,
499
- disabled: index >= data.length - 1,
500
- active: active === index * 2 + 1,
571
+ disabled: orderableIndex >= orderableData.length - 1,
572
+ active: active === orderableIndex * 2 + 1,
501
573
  onClick: function onClick(event) {
502
574
  event.stopPropagation();
503
- onOrder(reorder(data, index, index + 1));
575
+ onOrder(reorder(orderableData, pinnedInfo, orderableIndex, orderableIndex + 1));
504
576
  },
505
577
  tabIndex: -1,
506
578
  onMouseOver: function onMouseOver() {
507
- return updateActive(index * 2 + 1);
579
+ return updateActive(orderableIndex * 2 + 1);
508
580
  },
509
581
  onMouseOut: function onMouseOut() {
510
582
  return updateActive(undefined);
511
583
  },
512
584
  onFocus: function onFocus() {
513
- updateActive(index * 2 + 1);
585
+ updateActive(orderableIndex * 2 + 1);
514
586
  setItemFocus(true);
515
587
  },
516
588
  onBlur: function onBlur() {
@@ -542,6 +614,31 @@ var List = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
542
614
  }
543
615
  }
544
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
+
545
642
  if (itemProps && itemProps[index]) {
546
643
  boxProps = _extends({}, boxProps, itemProps[index]);
547
644
  }
@@ -554,7 +651,7 @@ var List = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
554
651
  isDisabled: isDisabled,
555
652
  flex: false,
556
653
  pad: pad || theme.list.item.pad
557
- }, 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);
558
655
  }))), paginate && data.length > step && items && items.length ? /*#__PURE__*/React.createElement(Pagination, _extends({
559
656
  alignSelf: "end"
560
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 { DisabledOutline, CircleQuestion } from 'grommet-icons';
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
+ };