grommet 2.40.2 → 2.42.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 (139) hide show
  1. package/components/AccordionPanel/AccordionPanel.js +1 -7
  2. package/components/Box/Box.js +1 -1
  3. package/components/Box/StyledBox.js +1 -6
  4. package/components/Box/index.d.ts +1 -0
  5. package/components/Box/propTypes.js +1 -0
  6. package/components/Button/Button.js +1 -0
  7. package/components/Button/StyledButton.js +3 -2
  8. package/components/Button/StyledButtonKind.js +12 -6
  9. package/components/Calendar/Calendar.js +90 -56
  10. package/components/Calendar/StyledCalendar.js +89 -7
  11. package/components/Calendar/utils.js +16 -2
  12. package/components/Carousel/Carousel.js +1 -1
  13. package/components/Chart/Chart.js +3 -3
  14. package/components/CheckBox/CheckBox.js +3 -2
  15. package/components/CheckBoxGroup/CheckBoxGroup.js +1 -1
  16. package/components/Clock/Digital.js +1 -1
  17. package/components/Data/stories/Infinite.js +2 -2
  18. package/components/Data/stories/OnSelect.js +2 -2
  19. package/components/Data/stories/SpaceX.js +2 -2
  20. package/components/Data/stories/StarWars.js +1 -1
  21. package/components/DataChart/Detail.js +19 -4
  22. package/components/DataFilter/DataFilter.js +6 -1
  23. package/components/DataSort/DataSort.js +46 -14
  24. package/components/DataSort/stories/Simple.js +10 -1
  25. package/components/DataTable/Body.js +14 -8
  26. package/components/DataTable/GroupedBody.js +3 -3
  27. package/components/DataTable/buildState.js +5 -1
  28. package/components/DataTable/stories/SpaceX.js +2 -2
  29. package/components/DataTable/stories/SpaceXUngrouped.js +1 -1
  30. package/components/Drop/DropContainer.js +51 -3
  31. package/components/FileInput/index.d.ts +2 -3
  32. package/components/FocusedContainer.js +134 -17
  33. package/components/Grommet/Grommet.js +11 -5
  34. package/components/Layer/Layer.js +1 -1
  35. package/components/Layer/index.d.ts +2 -0
  36. package/components/List/List.js +18 -12
  37. package/components/MaskedInput/MaskedInput.js +3 -0
  38. package/components/Menu/Menu.js +3 -3
  39. package/components/Meter/Circle.js +2 -2
  40. package/components/Notification/Notification.js +18 -6
  41. package/components/Notification/index.d.ts +1 -0
  42. package/components/Notification/propTypes.js +1 -0
  43. package/components/Pagination/Pagination.js +4 -2
  44. package/components/RadioButtonGroup/RadioButtonGroup.js +1 -1
  45. package/components/Select/Select.js +29 -18
  46. package/components/Select/SelectContainer.js +41 -34
  47. package/components/Select/index.d.ts +1 -1
  48. package/components/Select/stories/ChildrenRender.js +7 -8
  49. package/components/Select/utils.js +13 -2
  50. package/components/SelectMultiple/SelectMultiple.js +18 -6
  51. package/components/SelectMultiple/SelectMultipleContainer.js +28 -2
  52. package/components/SelectMultiple/SelectMultipleValue.js +14 -1
  53. package/components/SkipLinks/index.d.ts +1 -0
  54. package/components/SkipLinks/propTypes.js +1 -0
  55. package/components/Tab/Tab.js +1 -1
  56. package/components/Tag/Tag.js +11 -7
  57. package/components/TextInput/TextInput.js +3 -0
  58. package/components/ToggleGroup/StyledToggleGroup.js +12 -5
  59. package/components/ToggleGroup/ToggleGroup.js +21 -10
  60. package/components/WorldMap/WorldMap.js +1 -1
  61. package/contexts/RootsContext.js +23 -5
  62. package/es6/components/AccordionPanel/AccordionPanel.js +2 -9
  63. package/es6/components/Box/Box.js +1 -1
  64. package/es6/components/Box/StyledBox.js +1 -6
  65. package/es6/components/Box/index.d.ts +1 -0
  66. package/es6/components/Box/propTypes.js +1 -0
  67. package/es6/components/Button/Button.js +1 -0
  68. package/es6/components/Button/StyledButton.js +4 -3
  69. package/es6/components/Button/StyledButtonKind.js +12 -6
  70. package/es6/components/Calendar/Calendar.js +89 -56
  71. package/es6/components/Calendar/StyledCalendar.js +90 -8
  72. package/es6/components/Calendar/utils.js +15 -1
  73. package/es6/components/Carousel/Carousel.js +1 -1
  74. package/es6/components/Chart/Chart.js +3 -3
  75. package/es6/components/CheckBox/CheckBox.js +3 -2
  76. package/es6/components/CheckBoxGroup/CheckBoxGroup.js +1 -1
  77. package/es6/components/Clock/Digital.js +1 -1
  78. package/es6/components/Data/stories/Infinite.js +2 -2
  79. package/es6/components/Data/stories/OnSelect.js +2 -2
  80. package/es6/components/Data/stories/SpaceX.js +2 -2
  81. package/es6/components/Data/stories/StarWars.js +1 -1
  82. package/es6/components/DataChart/Detail.js +20 -5
  83. package/es6/components/DataFilter/DataFilter.js +6 -1
  84. package/es6/components/DataSort/DataSort.js +46 -14
  85. package/es6/components/DataSort/stories/Simple.js +10 -1
  86. package/es6/components/DataTable/Body.js +14 -8
  87. package/es6/components/DataTable/GroupedBody.js +3 -3
  88. package/es6/components/DataTable/buildState.js +5 -1
  89. package/es6/components/DataTable/stories/SpaceX.js +2 -2
  90. package/es6/components/DataTable/stories/SpaceXUngrouped.js +1 -1
  91. package/es6/components/Drop/DropContainer.js +51 -3
  92. package/es6/components/FileInput/index.d.ts +2 -3
  93. package/es6/components/FocusedContainer.js +136 -19
  94. package/es6/components/Grommet/Grommet.js +12 -6
  95. package/es6/components/Layer/Layer.js +1 -1
  96. package/es6/components/Layer/index.d.ts +2 -0
  97. package/es6/components/List/List.js +18 -12
  98. package/es6/components/MaskedInput/MaskedInput.js +3 -0
  99. package/es6/components/Menu/Menu.js +3 -3
  100. package/es6/components/Meter/Circle.js +2 -2
  101. package/es6/components/Notification/Notification.js +18 -6
  102. package/es6/components/Notification/index.d.ts +1 -0
  103. package/es6/components/Notification/propTypes.js +1 -0
  104. package/es6/components/Pagination/Pagination.js +4 -2
  105. package/es6/components/RadioButtonGroup/RadioButtonGroup.js +1 -1
  106. package/es6/components/Select/Select.js +30 -19
  107. package/es6/components/Select/SelectContainer.js +41 -34
  108. package/es6/components/Select/index.d.ts +1 -1
  109. package/es6/components/Select/stories/ChildrenRender.js +7 -8
  110. package/es6/components/Select/utils.js +15 -3
  111. package/es6/components/SelectMultiple/SelectMultiple.js +18 -6
  112. package/es6/components/SelectMultiple/SelectMultipleContainer.js +28 -2
  113. package/es6/components/SelectMultiple/SelectMultipleValue.js +14 -1
  114. package/es6/components/SkipLinks/index.d.ts +1 -0
  115. package/es6/components/SkipLinks/propTypes.js +1 -0
  116. package/es6/components/Tab/Tab.js +1 -1
  117. package/es6/components/Tag/Tag.js +11 -7
  118. package/es6/components/TextInput/TextInput.js +3 -0
  119. package/es6/components/ToggleGroup/StyledToggleGroup.js +12 -5
  120. package/es6/components/ToggleGroup/ToggleGroup.js +22 -11
  121. package/es6/components/WorldMap/WorldMap.js +1 -1
  122. package/es6/contexts/RootsContext.js +20 -3
  123. package/es6/themes/base.d.ts +205 -6
  124. package/es6/themes/base.js +166 -1
  125. package/es6/utils/DOM.js +2 -1
  126. package/es6/utils/background.js +1 -1
  127. package/es6/utils/index.js +2 -1
  128. package/es6/utils/styles.js +8 -0
  129. package/es6/utils/useId.js +16 -0
  130. package/grommet.min.js +1 -1
  131. package/grommet.min.js.map +1 -1
  132. package/package.json +40 -40
  133. package/themes/base.d.ts +205 -6
  134. package/themes/base.js +166 -1
  135. package/utils/DOM.js +2 -1
  136. package/utils/background.js +1 -1
  137. package/utils/index.js +6 -0
  138. package/utils/styles.js +9 -1
  139. package/utils/useId.js +19 -0
@@ -9,7 +9,7 @@ var _propTypes = require("./propTypes");
9
9
  var _StyledCheckBox = require("./StyledCheckBox");
10
10
  var _utils = require("../../utils");
11
11
  var _useThemeValue2 = require("../../utils/useThemeValue");
12
- var _excluded = ["a11yTitle", "aria-label", "checked", "children", "defaultChecked", "disabled", "fill", "focus", "focusIndicator", "id", "label", "name", "onBlur", "onChange", "onFocus", "onMouseEnter", "onMouseLeave", "onMouseOut", "onMouseOver", "pad", "reverse", "toggle", "indeterminate"];
12
+ var _excluded = ["a11yTitle", "aria-label", "checked", "children", "containerProps", "defaultChecked", "disabled", "fill", "focus", "focusIndicator", "id", "label", "name", "onBlur", "onChange", "onFocus", "onMouseEnter", "onMouseLeave", "onMouseOut", "onMouseOver", "pad", "reverse", "toggle", "indeterminate"];
13
13
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
14
14
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
15
15
  function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
@@ -27,6 +27,7 @@ var CheckBox = exports.CheckBox = /*#__PURE__*/(0, _react.forwardRef)(function (
27
27
  ariaLabel = _ref['aria-label'],
28
28
  checkedProp = _ref.checked,
29
29
  children = _ref.children,
30
+ containerProps = _ref.containerProps,
30
31
  _ref$defaultChecked = _ref.defaultChecked,
31
32
  defaultChecked = _ref$defaultChecked === void 0 ? false : _ref$defaultChecked,
32
33
  disabled = _ref.disabled,
@@ -193,7 +194,7 @@ var CheckBox = exports.CheckBox = /*#__PURE__*/(0, _react.forwardRef)(function (
193
194
  onMouseOut: function onMouseOut(event) {
194
195
  return _onMouseOut == null ? void 0 : _onMouseOut(event);
195
196
  }
196
- }, passThemeFlag, themeableProps), first, second);
197
+ }, passThemeFlag, themeableProps, containerProps), first, second);
197
198
  });
198
199
  CheckBox.displayName = 'CheckBox';
199
200
  CheckBox.propTypes = _propTypes.CheckBoxPropTypes;
@@ -81,7 +81,7 @@ var CheckBoxGroup = exports.CheckBoxGroup = /*#__PURE__*/(0, _react.forwardRef)(
81
81
  var checked = value.indexOf(valueOption) >= 0;
82
82
  var disabled = disabledProp || option.disabled;
83
83
  var key = label + "-" + valueOption;
84
- if (option.checked) console.warn( // eslint-disable-next-line max-len
84
+ if (option.checked) console.warn(// eslint-disable-next-line max-len
85
85
  "'checked' prop of an individual CheckBox shouldn't be used in a CheckBoxGroup component. Use the CheckBoxGroup 'value' prop instead.");
86
86
  // value shouldn't propagate the input field and the onChange option
87
87
  var omit = option.value,
@@ -71,7 +71,7 @@ var Element = function Element(_ref2) {
71
71
  number: ones
72
72
  })];
73
73
  if (sep) {
74
- result.unshift( /*#__PURE__*/_react["default"].createElement(_StyledClock.StyledDigitalDigit, _extends({
74
+ result.unshift(/*#__PURE__*/_react["default"].createElement(_StyledClock.StyledDigitalDigit, _extends({
75
75
  key: "sep",
76
76
  size: size
77
77
  }, passThemeFlag), ":"));
@@ -35,7 +35,7 @@ var buildQuery = function buildQuery(view) {
35
35
  return query;
36
36
  };
37
37
  var fetchLaunches = /*#__PURE__*/function () {
38
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(view) {
38
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(view) {
39
39
  var _view$sort, _view$sort2, _sort;
40
40
  var query, sort, body;
41
41
  return _regeneratorRuntime().wrap(function _callee$(_context) {
@@ -77,7 +77,7 @@ var fetchLaunches = /*#__PURE__*/function () {
77
77
  };
78
78
  }();
79
79
  var fetchRockets = /*#__PURE__*/function () {
80
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
80
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
81
81
  var body;
82
82
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
83
83
  while (1) switch (_context2.prev = _context2.next) {
@@ -35,7 +35,7 @@ var buildQuery = function buildQuery(view) {
35
35
  return query;
36
36
  };
37
37
  var fetchLaunches = /*#__PURE__*/function () {
38
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(view) {
38
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(view) {
39
39
  var _view$sort, _view$sort2, _sort;
40
40
  var query, sort, body;
41
41
  return _regeneratorRuntime().wrap(function _callee$(_context) {
@@ -78,7 +78,7 @@ var fetchLaunches = /*#__PURE__*/function () {
78
78
  };
79
79
  }();
80
80
  var fetchRockets = /*#__PURE__*/function () {
81
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
81
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
82
82
  var body;
83
83
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
84
84
  while (1) switch (_context2.prev = _context2.next) {
@@ -35,7 +35,7 @@ var buildQuery = function buildQuery(view) {
35
35
  return query;
36
36
  };
37
37
  var fetchLaunches = /*#__PURE__*/function () {
38
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(view) {
38
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(view) {
39
39
  var _view$sort, _view$sort2, _sort;
40
40
  var query, sort, body;
41
41
  return _regeneratorRuntime().wrap(function _callee$(_context) {
@@ -78,7 +78,7 @@ var fetchLaunches = /*#__PURE__*/function () {
78
78
  };
79
79
  }();
80
80
  var fetchRockets = /*#__PURE__*/function () {
81
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
81
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
82
82
  var body;
83
83
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
84
84
  while (1) switch (_context2.prev = _context2.next) {
@@ -14,7 +14,7 @@ function _asyncToGenerator(n) { return function () { var t = this, e = arguments
14
14
  var step = 10; // default for https://swapi.dev
15
15
 
16
16
  var fetchData = /*#__PURE__*/function () {
17
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(view, signal) {
17
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(view, signal) {
18
18
  var params, url;
19
19
  return _regeneratorRuntime().wrap(function _callee$(_context) {
20
20
  while (1) switch (_context.prev = _context.next) {
@@ -4,6 +4,7 @@ exports.__esModule = true;
4
4
  exports.Detail = void 0;
5
5
  var _react = _interopRequireWildcard(require("react"));
6
6
  var _styledComponents = _interopRequireDefault(require("styled-components"));
7
+ var _contexts = require("../../contexts");
7
8
  var _Box = require("../Box");
8
9
  var _Drop = require("../Drop");
9
10
  var _Grid = require("../Grid");
@@ -30,6 +31,7 @@ var Detail = exports.Detail = function Detail(_ref) {
30
31
  seriesStyles = _ref.seriesStyles,
31
32
  renderValue = _ref.renderValue,
32
33
  thickness = _ref.thickness;
34
+ var announce = (0, _react.useContext)(_contexts.AnnounceContext);
33
35
  var _useThemeValue = (0, _useThemeValue2.useThemeValue)(),
34
36
  theme = _useThemeValue.theme;
35
37
  var _useState = (0, _react.useState)(),
@@ -78,6 +80,19 @@ var Detail = exports.Detail = function Detail(_ref) {
78
80
  };
79
81
  return res;
80
82
  }, [data.length, detailIndex, horizontalProp]);
83
+ (0, _react.useEffect)(function () {
84
+ if (detailIndex !== undefined) {
85
+ var content = series.filter(function (_ref2) {
86
+ var _data$detailIndex;
87
+ var property = _ref2.property;
88
+ return (!activeProperty || activeProperty === property) && (data == null || (_data$detailIndex = data[detailIndex]) == null ? void 0 : _data$detailIndex[property]) !== undefined || axis && axis.x && axis.x.property === property;
89
+ }).map(function (serie) {
90
+ var axisValue = horizontalProp ? data[detailIndex][serie.property] : detailIndex;
91
+ return (serie.label || serie.property) + " " + renderValue(serie, axisValue);
92
+ }).join(' ');
93
+ announce(content);
94
+ }
95
+ }, [activeProperty, announce, axis, data, detailIndex, horizontalProp, renderValue, series]);
81
96
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_Keyboard.Keyboard, {
82
97
  onLeft: function onLeft() {
83
98
  if (detailIndex === undefined) setDetailIndex(data.length - 1);else if (detailIndex > 0) setDetailIndex(detailIndex - 1);
@@ -154,10 +169,10 @@ var Detail = exports.Detail = function Detail(_ref) {
154
169
  columns: ['auto', 'auto', 'auto'],
155
170
  gap: "xsmall",
156
171
  align: "center"
157
- }, series.filter(function (_ref2) {
158
- var _data$detailIndex;
159
- var property = _ref2.property;
160
- return (!activeProperty || activeProperty === property) && (data == null || (_data$detailIndex = data[detailIndex]) == null ? void 0 : _data$detailIndex[property]) !== undefined || axis && axis.x && axis.x.property === property;
172
+ }, series.filter(function (_ref3) {
173
+ var _data$detailIndex2;
174
+ var property = _ref3.property;
175
+ return (!activeProperty || activeProperty === property) && (data == null || (_data$detailIndex2 = data[detailIndex]) == null ? void 0 : _data$detailIndex2[property]) !== undefined || axis && axis.x && axis.x.property === property;
161
176
  }).map(function (serie) {
162
177
  var propertyStyle = seriesStyles[serie.property];
163
178
  var axisValue = horizontalProp ? data[detailIndex][serie.property] : detailIndex;
@@ -140,7 +140,7 @@ var DataFilter = exports.DataFilter = function DataFilter(_ref) {
140
140
  var _properties$property4;
141
141
  var step =
142
142
  // from `range` on DataFilter
143
- (rangeProp == null ? void 0 : rangeProp.step) || ( // from range in Data `properties`
143
+ (rangeProp == null ? void 0 : rangeProp.step) || (// from range in Data `properties`
144
144
  properties == null || (_properties$property4 = properties[property]) == null || (_properties$property4 = _properties$property4.range) == null ? void 0 : _properties$property4.step);
145
145
  if (!step) {
146
146
  // avoid floating point issues where 4.4 - 2 returns 2.4000000000000004
@@ -198,6 +198,11 @@ var DataFilter = exports.DataFilter = function DataFilter(_ref) {
198
198
  onSearch: options.length >= minSelectSearchOptions ? setSearchText : undefined,
199
199
  onClose: function onClose() {
200
200
  return setSearchText('');
201
+ },
202
+ labelKey: "label",
203
+ valueKey: {
204
+ key: 'value',
205
+ reduce: true
201
206
  }
202
207
  });
203
208
  }
@@ -18,8 +18,8 @@ var _useThemeValue2 = require("../../utils/useThemeValue");
18
18
  var _excluded = ["drop", "options"];
19
19
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
20
20
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
21
- function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
22
21
  function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
22
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
23
23
  var dropProps = {
24
24
  align: {
25
25
  top: 'bottom',
@@ -35,11 +35,44 @@ var Content = function Content(_ref) {
35
35
  properties = _useContext.properties;
36
36
  var _useContext2 = (0, _react.useContext)(_MessageContext.MessageContext),
37
37
  format = _useContext2.format;
38
- var options = (0, _react.useMemo)(function () {
39
- return optionsArg || properties && Object.keys(properties).sort().filter(function (property) {
40
- var _properties$property;
41
- return !((properties == null || (_properties$property = properties[property]) == null ? void 0 : _properties$property.sort) === false);
42
- }) || data.length > 0 && Object.keys(data[0]).sort() || data;
38
+ var selectProps = (0, _react.useMemo)(function () {
39
+ var props = {};
40
+ if (optionsArg) {
41
+ props = {
42
+ options: optionsArg
43
+ };
44
+ }
45
+ if (properties && Array.isArray(properties)) {
46
+ props = {
47
+ options: properties
48
+ };
49
+ } else if (properties && typeof properties === 'object') {
50
+ props = {
51
+ options: Object.entries(properties).filter(function (_ref2) {
52
+ var sort = _ref2[1].sort;
53
+ return !(sort === false);
54
+ }).map(function (_ref3) {
55
+ var key = _ref3[0],
56
+ label = _ref3[1].label;
57
+ return {
58
+ key: key,
59
+ label: label || key
60
+ };
61
+ }).sort(function (a, b) {
62
+ return a.label.localeCompare(b.label);
63
+ }),
64
+ valueKey: {
65
+ key: 'key',
66
+ reduce: true
67
+ },
68
+ labelKey: 'label'
69
+ };
70
+ } else {
71
+ props = {
72
+ options: data.length > 0 && Object.keys(data[0]).sort() || data
73
+ };
74
+ }
75
+ return props;
43
76
  }, [data, optionsArg, properties]);
44
77
  var directionOptions = [{
45
78
  label: format({
@@ -63,11 +96,10 @@ var Content = function Content(_ref) {
63
96
  id: 'dataSort.by',
64
97
  messages: messages == null ? void 0 : messages.dataSort
65
98
  })
66
- }, /*#__PURE__*/_react["default"].createElement(_Select.Select, {
99
+ }, /*#__PURE__*/_react["default"].createElement(_Select.Select, _extends({
67
100
  id: sortPropertyId,
68
- name: "_sort.property",
69
- options: options
70
- })), /*#__PURE__*/_react["default"].createElement(_FormField.FormField, {
101
+ name: "_sort.property"
102
+ }, selectProps))), /*#__PURE__*/_react["default"].createElement(_FormField.FormField, {
71
103
  key: "dir",
72
104
  htmlFor: sortDirectionId,
73
105
  label: format({
@@ -80,11 +112,11 @@ var Content = function Content(_ref) {
80
112
  options: directionOptions
81
113
  }))];
82
114
  };
83
- var DataSort = exports.DataSort = function DataSort(_ref2) {
115
+ var DataSort = exports.DataSort = function DataSort(_ref4) {
84
116
  var _theme$data$button;
85
- var drop = _ref2.drop,
86
- options = _ref2.options,
87
- rest = _objectWithoutPropertiesLoose(_ref2, _excluded);
117
+ var drop = _ref4.drop,
118
+ options = _ref4.options,
119
+ rest = _objectWithoutPropertiesLoose(_ref4, _excluded);
88
120
  var _useContext3 = (0, _react.useContext)(_DataContext.DataContext),
89
121
  dataId = _useContext3.id,
90
122
  messages = _useContext3.messages;
@@ -6,6 +6,14 @@ var _react = _interopRequireDefault(require("react"));
6
6
  var _grommet = require("grommet");
7
7
  var _data = require("../../DataTable/stories/data");
8
8
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
9
+ var properties = {};
10
+ _data.columns.forEach(function (_ref) {
11
+ var property = _ref.property,
12
+ header = _ref.header;
13
+ properties[property] = {
14
+ label: typeof header === 'string' ? header : property
15
+ };
16
+ });
9
17
  var Simple = exports.Simple = function Simple() {
10
18
  return (
11
19
  /*#__PURE__*/
@@ -17,7 +25,8 @@ var Simple = exports.Simple = function Simple() {
17
25
  pad: "large",
18
26
  gap: "medium"
19
27
  }, /*#__PURE__*/_react["default"].createElement(_grommet.Data, {
20
- data: _data.DATA
28
+ data: _data.DATA,
29
+ properties: properties
21
30
  }, /*#__PURE__*/_react["default"].createElement(_grommet.DataSort, null), /*#__PURE__*/_react["default"].createElement(_grommet.DataTable, {
22
31
  columns: _data.columns
23
32
  })))
@@ -73,7 +73,7 @@ var Row = /*#__PURE__*/(0, _react.memo)(function (_ref) {
73
73
  return setActive(undefined);
74
74
  } : undefined
75
75
  }, (selected || onSelect) && /*#__PURE__*/_react["default"].createElement(_Cell.Cell, {
76
- background: (pinnedOffset == null ? void 0 : pinnedOffset._grommetDataTableSelect) && cellProps.pinned.background || cellProps.background,
76
+ background: isSelected && cellProps.selected.background || (pinnedOffset == null ? void 0 : pinnedOffset._grommetDataTableSelect) && cellProps.pinned.background || cellProps.background,
77
77
  border: cellProps.pinned.border || cellProps.border,
78
78
  pinnedOffset: pinnedOffset == null ? void 0 : pinnedOffset._grommetDataTableSelect,
79
79
  "aria-disabled": isDisabled || !onSelect || undefined,
@@ -100,6 +100,7 @@ var Row = /*#__PURE__*/(0, _react.memo)(function (_ref) {
100
100
  },
101
101
  verticalAlign: verticalAlign
102
102
  }), rowDetails && /*#__PURE__*/_react["default"].createElement(_ExpanderCell.ExpanderCell, {
103
+ background: isSelected && cellProps.selected.background,
103
104
  context: isRowExpanded ? 'groupHeader' : 'body',
104
105
  expanded: isRowExpanded,
105
106
  onToggle: function onToggle() {
@@ -116,11 +117,12 @@ var Row = /*#__PURE__*/(0, _react.memo)(function (_ref) {
116
117
  }), columns.map(function (column) {
117
118
  return /*#__PURE__*/_react["default"].createElement(_Cell.Cell, {
118
119
  key: column.property,
119
- background: column.pin && cellProps.pinned.background || cellProps.background,
120
+ background: isSelected && cellProps.selected.background || column.pin && cellProps.pinned.background || cellProps.background,
120
121
  border: column.pin && cellProps.pinned.border || cellProps.border,
121
122
  context: "body",
122
123
  column: column,
123
124
  datum: datum,
125
+ isSelected: isSelected,
124
126
  pad: column.pin && cellProps.pinned.pad || cellProps.pad,
125
127
  pinnedOffset: pinnedOffset && pinnedOffset[column.property],
126
128
  primaryProperty: primaryProperty,
@@ -194,13 +196,17 @@ var Body = exports.Body = /*#__PURE__*/(0, _react.forwardRef)(function (_ref2, r
194
196
  } : undefined
195
197
  // The WCAG recommendation for checkboxes is to select them with "Space"
196
198
  ,
197
- onSpace: function onSpace() {
198
- if (clickableRow) {
199
- if (onClickRow === 'select') {
200
- selectRow();
201
- }
199
+ onSpace: clickableRow ? function (event) {
200
+ event.preventDefault();
201
+ if (typeof onClickRow === 'function') {
202
+ event.persist();
203
+ var adjustedEvent = event;
204
+ adjustedEvent.datum = data == null ? void 0 : data[active];
205
+ onClickRow(adjustedEvent);
206
+ } else if (onClickRow === 'select') {
207
+ selectRow();
202
208
  }
203
- },
209
+ } : undefined,
204
210
  onUp: onClickRow && active ? function () {
205
211
  return setActive(active - 1);
206
212
  } : undefined,
@@ -139,7 +139,7 @@ var GroupedBody = exports.GroupedBody = /*#__PURE__*/(0, _react.forwardRef)(func
139
139
  key: key,
140
140
  size: size
141
141
  }, /*#__PURE__*/_react["default"].createElement(_ExpanderCell.ExpanderCell, {
142
- background: cellProps.background,
142
+ background: isSelected && cellProps.selected.background || cellProps.background,
143
143
  border: cellProps.border,
144
144
  context: context,
145
145
  pad: cellProps.pad,
@@ -147,7 +147,7 @@ var GroupedBody = exports.GroupedBody = /*#__PURE__*/(0, _react.forwardRef)(func
147
147
  expanded: expanded,
148
148
  verticalAlign: verticalAlign
149
149
  }), (selected || onSelect) && /*#__PURE__*/_react["default"].createElement(_TableCell.TableCell, {
150
- background: cellProps.background,
150
+ background: isSelected && cellProps.selected.background || cellProps.background,
151
151
  border: cellProps.pinned.border || cellProps.border,
152
152
  plain: "noPad",
153
153
  size: "auto",
@@ -169,7 +169,7 @@ var GroupedBody = exports.GroupedBody = /*#__PURE__*/(0, _react.forwardRef)(func
169
169
  }
170
170
  return /*#__PURE__*/_react["default"].createElement(_Cell.Cell, {
171
171
  key: column.property,
172
- background: cellProps.background,
172
+ background: isSelected && cellProps.selected.background || cellProps.background,
173
173
  border: cellProps.border,
174
174
  context: context,
175
175
  column: column,
@@ -2,6 +2,7 @@
2
2
 
3
3
  exports.__esModule = true;
4
4
  exports.set = exports.normalizeRowProp = exports.normalizeRowCellProps = exports.normalizePrimaryProperty = exports.normalizeCellProps = exports.normalizeBackgroundColor = exports.initializeFilters = exports.filterAndSortData = exports.datumValue = exports.buildGroups = exports.buildGroupState = exports.buildFooterValues = void 0;
5
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
5
6
  // This file contains helper functions for DataTable, to keep the component
6
7
  // files simpler.
7
8
 
@@ -265,6 +266,7 @@ var cellPropertyNames = ['background', 'border', 'pad'];
265
266
  // For example, background={{ header: { background } }}
266
267
  // will become cellProps.header.background
267
268
  var normalizeCellProps = exports.normalizeCellProps = function normalizeCellProps(props, theme) {
269
+ var _theme$dataTable3;
268
270
  var result = {};
269
271
  tableContextNames.forEach(function (context) {
270
272
  result[context] = {
@@ -300,11 +302,13 @@ var normalizeCellProps = exports.normalizeCellProps = function normalizeCellProp
300
302
  }
301
303
  });
302
304
  });
305
+ result.body.selected = _extends({}, theme == null || (_theme$dataTable3 = theme.dataTable) == null || (_theme$dataTable3 = _theme$dataTable3.body) == null ? void 0 : _theme$dataTable3.selected);
303
306
  return result;
304
307
  };
305
308
  var normalizeRowCellProps = exports.normalizeRowCellProps = function normalizeRowCellProps(rowProps, cellProps, primaryKey, index) {
306
309
  var result = {
307
- pinned: {}
310
+ pinned: {},
311
+ selected: cellProps.selected
308
312
  };
309
313
  ['background', 'border', 'pad'].forEach(function (propName) {
310
314
  var _rowProps$primaryKey;
@@ -120,7 +120,7 @@ var SpaceX = exports.SpaceX = function SpaceX() {
120
120
  }, [groups]);
121
121
  (0, _react.useEffect)(function () {
122
122
  var fetchData = /*#__PURE__*/function () {
123
- var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
123
+ var _ref5 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
124
124
  var query;
125
125
  return _regeneratorRuntime().wrap(function _callee$(_context) {
126
126
  while (1) switch (_context.prev = _context.next) {
@@ -157,7 +157,7 @@ var SpaceX = exports.SpaceX = function SpaceX() {
157
157
  }, []);
158
158
  (0, _react.useEffect)(function () {
159
159
  var fetchData = /*#__PURE__*/function () {
160
- var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
160
+ var _ref6 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
161
161
  var _sort;
162
162
  var query;
163
163
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
@@ -70,7 +70,7 @@ var SpaceXUngrouped = exports.SpaceXUngrouped = function SpaceXUngrouped() {
70
70
  setLimit = _useState3[1];
71
71
  (0, _react.useEffect)(function () {
72
72
  var fetchData = /*#__PURE__*/function () {
73
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
73
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
74
74
  var _sort;
75
75
  var query;
76
76
  return _regeneratorRuntime().wrap(function _callee$(_context) {
@@ -182,12 +182,50 @@ var DropContainer = exports.DropContainer = /*#__PURE__*/(0, _react.forwardRef)(
182
182
  direction, change the Drop to display above/below. If there is
183
183
  less room in the other direction leave the Drop in its current
184
184
  position. */
185
- if (responsive && (align.top === 'top' && targetRect.top < 0 || align.bottom === 'top' && targetRect.top - containerRect.height <= 0 && targetRect.bottom + containerRect.height < windowHeight)) {
185
+ if (responsive &&
186
+ // drop is above target
187
+ align.bottom === 'top' &&
188
+ // drop is overflowing above window
189
+ targetRect.top - containerRect.height <= 0 &&
190
+ // there is room to display the drop below the target
191
+ targetRect.bottom + containerRect.height < windowHeight) {
192
+ // top of drop is aligned to bottom of target
186
193
  top = targetRect.bottom;
187
194
  maxHeight = top;
188
- } else if (responsive && (align.bottom === 'bottom' && targetRect.bottom > windowHeight || align.top === 'bottom' && targetRect.bottom + containerRect.height >= windowHeight && targetRect.top - containerRect.height > 0)) {
195
+ } else if (responsive &&
196
+ // top of drop is aligned to top of target
197
+ align.top === 'top' &&
198
+ // drop is overflowing below window
199
+ targetRect.top + containerRect.height >= windowHeight &&
200
+ // height of the drop is larger than the target.
201
+ targetRect.top + containerRect.height > targetRect.bottom &&
202
+ // there is room to display the drop above the target
203
+ targetRect.bottom - containerRect.height > 0) {
204
+ // bottom of drop is aligned to bottom of target
205
+ bottom = targetRect.bottom;
206
+ maxHeight = top;
207
+ } else if (responsive &&
208
+ // top of drop is aligned to bottom of target
209
+ align.top === 'bottom' &&
210
+ // drop is overflowing below window
211
+ targetRect.bottom + containerRect.height >= windowHeight &&
212
+ // there is room to display the drop above the target
213
+ targetRect.top - containerRect.height > 0) {
214
+ // bottom of drop is aligned to top of target
189
215
  bottom = targetRect.top;
190
216
  maxHeight = bottom;
217
+ } else if (responsive &&
218
+ // bottom of drop is aligned to bottom of target
219
+ align.bottom === 'bottom' &&
220
+ // drop is overflowing above window
221
+ targetRect.bottom - containerRect.height <= 0 &&
222
+ // height of the drop is larger than the target.
223
+ targetRect.bottom - containerRect.height > targetRect.top &&
224
+ // there is room to display the drop below the target
225
+ targetRect.top + containerRect.height > 0) {
226
+ // top of drop is aligned to top of target
227
+ top = targetRect.top;
228
+ maxHeight = bottom;
191
229
  } else if (align.top === 'top') {
192
230
  top = targetRect.top;
193
231
  maxHeight = windowHeight - top;
@@ -270,9 +308,19 @@ var DropContainer = exports.DropContainer = /*#__PURE__*/(0, _react.forwardRef)(
270
308
  window.removeEventListener('resize', onResize);
271
309
  };
272
310
  }, [align, containerTarget, onAlign, dropTarget, portalContext, portalId, responsive, restrictFocus, stretch, theme.drop, dropRef, dropOptions]);
311
+
312
+ // Once drop is open the focus will be put on the drop container
313
+ // if restrictFocus is true. If the caller put focus
314
+ // on an element already, we honor that. Otherwise, we put
315
+ // the focus on the drop container.
273
316
  (0, _react.useEffect)(function () {
274
317
  if (restrictFocus) {
275
- dropRef.current.focus();
318
+ var dropContainer = dropRef.current;
319
+ if (dropContainer) {
320
+ if (!dropContainer.contains(document.activeElement)) {
321
+ dropContainer.focus();
322
+ }
323
+ }
276
324
  }
277
325
  }, [dropRef, restrictFocus]);
278
326
  var content = /*#__PURE__*/_react["default"].createElement(_StyledDrop.StyledDrop, _extends({
@@ -23,9 +23,8 @@ export interface FileInputProps {
23
23
  multiple?: boolean | { aggregateThreshold?: number; max?: number };
24
24
  name?: string;
25
25
  onChange?: (
26
- event?: React.ChangeEvent<HTMLInputElement>,
27
- { files }?: { files: File[] },
28
- { target }?: { target: { files: FileList } },
26
+ event: React.ChangeEvent<HTMLInputElement>,
27
+ { files }: { files: File[] },
29
28
  ) => void;
30
29
  renderFile?: (...args: any[]) => void;
31
30
  }