grommet 2.53.0 → 2.55.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 (89) hide show
  1. package/components/Calendar/Calendar.js +24 -16
  2. package/components/Calendar/index.d.ts +1 -1
  3. package/components/Calendar/stories/CustomHeader.stories.js +6 -1
  4. package/components/Calendar/stories/CustomThemed/CustomSizeHeading.stories.js +6 -1
  5. package/components/Calendar/stories/Dual.stories.js +23 -11
  6. package/components/Calendar/stories/HeaderLevel.stories.js +6 -1
  7. package/components/Calendar/stories/Multiple.stories.js +8 -3
  8. package/components/Calendar/stories/Simple.stories.js +6 -1
  9. package/components/Cards/Cards.js +164 -10
  10. package/components/Cards/StyledCellContainer.js +29 -0
  11. package/components/Cards/index.d.ts +4 -1
  12. package/components/Cards/propTypes.js +2 -0
  13. package/components/Cards/stories/Sizable.stories.js +70 -0
  14. package/components/Cards/stories/onOrder.stories.js +69 -0
  15. package/components/DataFilter/DataFilter.js +21 -28
  16. package/components/DataTable/stories/ResizePinned.stories.js +1 -1
  17. package/components/DateInput/DateInput.js +58 -25
  18. package/components/DateInput/index.d.ts +1 -0
  19. package/components/DateInput/utils.js +2 -2
  20. package/components/Drop/DropContainer.js +59 -3
  21. package/components/FileInput/FileInput.js +3 -0
  22. package/components/Form/stories/CustomThemed/FieldCustomStates.stories.js +7 -1
  23. package/components/Form/stories/FieldStates.stories.js +7 -1
  24. package/components/Grommet/Grommet.js +2 -1
  25. package/components/Grommet/index.d.ts +6 -0
  26. package/components/Grommet/propTypes.js +7 -1
  27. package/components/Header/stories/Sticky.stories.js +1 -1
  28. package/components/Layer/LayerContainer.d.ts +40 -0
  29. package/components/Menu/Menu.js +7 -5
  30. package/components/Select/stories/ChildrenRender.stories.js +28 -55
  31. package/components/SelectMultiple/stories/typescript/Children.stories.tsx +24 -48
  32. package/components/SelectMultiple/stories/typescript/ValueLabel.stories.tsx +88 -0
  33. package/components/Tab/Tab.js +1 -1
  34. package/components/Tag/Tag.js +4 -3
  35. package/components/Tag/index.d.ts +5 -4
  36. package/components/Tag/propTypes.js +3 -2
  37. package/components/TextInput/StyledTextInput.js +4 -2
  38. package/components/TextInput/TextInput.js +4 -3
  39. package/es6/components/Calendar/Calendar.js +24 -16
  40. package/es6/components/Calendar/index.d.ts +1 -1
  41. package/es6/components/Calendar/stories/CustomHeader.stories.js +6 -1
  42. package/es6/components/Calendar/stories/CustomThemed/CustomSizeHeading.stories.js +6 -1
  43. package/es6/components/Calendar/stories/Dual.stories.js +23 -11
  44. package/es6/components/Calendar/stories/HeaderLevel.stories.js +6 -1
  45. package/es6/components/Calendar/stories/Multiple.stories.js +8 -3
  46. package/es6/components/Calendar/stories/Simple.stories.js +6 -1
  47. package/es6/components/Cards/Cards.js +165 -12
  48. package/es6/components/Cards/StyledCellContainer.js +24 -0
  49. package/es6/components/Cards/index.d.ts +4 -1
  50. package/es6/components/Cards/propTypes.js +2 -0
  51. package/es6/components/Cards/stories/Sizable.stories.js +65 -0
  52. package/es6/components/Cards/stories/onOrder.stories.js +64 -0
  53. package/es6/components/DataFilter/DataFilter.js +21 -28
  54. package/es6/components/DataTable/stories/ResizePinned.stories.js +1 -1
  55. package/es6/components/DateInput/DateInput.js +58 -25
  56. package/es6/components/DateInput/index.d.ts +1 -0
  57. package/es6/components/DateInput/utils.js +2 -2
  58. package/es6/components/Drop/DropContainer.js +59 -3
  59. package/es6/components/FileInput/FileInput.js +3 -0
  60. package/es6/components/Form/stories/CustomThemed/FieldCustomStates.stories.js +7 -1
  61. package/es6/components/Form/stories/FieldStates.stories.js +7 -1
  62. package/es6/components/Grommet/Grommet.js +2 -1
  63. package/es6/components/Grommet/index.d.ts +6 -0
  64. package/es6/components/Grommet/propTypes.js +7 -1
  65. package/es6/components/Header/stories/Sticky.stories.js +1 -1
  66. package/es6/components/Layer/LayerContainer.d.ts +40 -0
  67. package/es6/components/Menu/Menu.js +7 -5
  68. package/es6/components/Select/stories/ChildrenRender.stories.js +29 -56
  69. package/es6/components/SelectMultiple/stories/typescript/Children.stories.tsx +24 -48
  70. package/es6/components/SelectMultiple/stories/typescript/ValueLabel.stories.tsx +88 -0
  71. package/es6/components/Tab/Tab.js +2 -2
  72. package/es6/components/Tag/Tag.js +4 -3
  73. package/es6/components/Tag/index.d.ts +5 -4
  74. package/es6/components/Tag/propTypes.js +3 -2
  75. package/es6/components/TextInput/StyledTextInput.js +4 -2
  76. package/es6/components/TextInput/TextInput.js +4 -3
  77. package/es6/languages/default.json +7 -1
  78. package/es6/themes/base.d.ts +6 -0
  79. package/es6/themes/base.js +5 -0
  80. package/es6/utils/index.d.ts +1 -0
  81. package/es6/utils/styles.js +23 -12
  82. package/grommet.min.js +1 -1
  83. package/grommet.min.js.map +1 -1
  84. package/languages/default.json +7 -1
  85. package/package.json +47 -50
  86. package/themes/base.d.ts +6 -0
  87. package/themes/base.js +5 -0
  88. package/utils/index.d.ts +1 -0
  89. package/utils/styles.js +23 -12
@@ -16,7 +16,14 @@ export var Dual = function Dual() {
16
16
  var _useState4 = useState('2020-09-01T15:15:34.916Z'),
17
17
  reference2 = _useState4[0],
18
18
  setReference2 = _useState4[1];
19
- var onSelect = function onSelect(arg) {
19
+
20
+ // We have to track the active date because the Calendars don't know about
21
+ // each other.
22
+ var _useState5 = useState(),
23
+ activeDate = _useState5[0],
24
+ setActiveDate = _useState5[1];
25
+ var onSelect = function onSelect(arg, _ref) {
26
+ var nextActiveDate = _ref.activeDate;
20
27
  if (Array.isArray(arg)) {
21
28
  setDate(undefined);
22
29
  setDates(arg);
@@ -24,6 +31,7 @@ export var Dual = function Dual() {
24
31
  setDate(arg);
25
32
  setDates(undefined);
26
33
  }
34
+ setActiveDate(nextActiveDate);
27
35
  };
28
36
  return (
29
37
  /*#__PURE__*/
@@ -35,6 +43,7 @@ export var Dual = function Dual() {
35
43
  direction: "row",
36
44
  gap: "small"
37
45
  }, /*#__PURE__*/React.createElement(Calendar, {
46
+ activeDate: activeDate,
38
47
  animate: false,
39
48
  showAdjacentDays: false,
40
49
  range: true,
@@ -46,13 +55,14 @@ export var Dual = function Dual() {
46
55
  var refDate = new Date(reference);
47
56
  var nextDate = new Date(refDate);
48
57
  nextDate.setMonth(refDate.getMonth() + 1, 1);
58
+ setReference1(reference);
49
59
  setReference2(nextDate.toISOString());
50
60
  },
51
- header: function header(_ref) {
52
- var currentDate = _ref.date,
53
- locale = _ref.locale,
54
- onPreviousMonth = _ref.onPreviousMonth,
55
- previousInBound = _ref.previousInBound;
61
+ header: function header(_ref2) {
62
+ var currentDate = _ref2.date,
63
+ locale = _ref2.locale,
64
+ onPreviousMonth = _ref2.onPreviousMonth,
65
+ previousInBound = _ref2.previousInBound;
56
66
  return /*#__PURE__*/React.createElement(Box, {
57
67
  direction: "row",
58
68
  align: "center",
@@ -70,6 +80,7 @@ export var Dual = function Dual() {
70
80
  })), /*#__PURE__*/React.createElement(Blank, null));
71
81
  }
72
82
  }), /*#__PURE__*/React.createElement(Calendar, {
83
+ activeDate: activeDate,
73
84
  animate: false,
74
85
  showAdjacentDays: false,
75
86
  date: date,
@@ -82,12 +93,13 @@ export var Dual = function Dual() {
82
93
  var priorDate = new Date(refDate);
83
94
  priorDate.setMonth(refDate.getMonth() - 1, 1);
84
95
  setReference1(priorDate.toISOString());
96
+ setReference2(reference);
85
97
  },
86
- header: function header(_ref2) {
87
- var currentDate = _ref2.date,
88
- locale = _ref2.locale,
89
- onNextMonth = _ref2.onNextMonth,
90
- nextInBound = _ref2.nextInBound;
98
+ header: function header(_ref3) {
99
+ var currentDate = _ref3.date,
100
+ locale = _ref3.locale,
101
+ onNextMonth = _ref3.onNextMonth,
102
+ nextInBound = _ref3.nextInBound;
91
103
  return /*#__PURE__*/React.createElement(Box, {
92
104
  direction: "row",
93
105
  align: "center",
@@ -1,5 +1,9 @@
1
1
  import React, { useState } from 'react';
2
2
  import { Box, Calendar } from 'grommet';
3
+ var reference = '2026-04-12T21:09:16.501Z';
4
+ var end = new Date(reference);
5
+ var start = new Date(end.getTime() - 1000 * 60 * 60 * 24 * 90); // 90 days ago
6
+ var bounds = [start.getFullYear() + "-" + (start.getMonth() + 1) + "-" + start.getDate(), end.getFullYear() + "-" + (end.getMonth() + 1) + "-" + end.getDate()];
3
7
  export var HeaderLevel = function HeaderLevel() {
4
8
  var _useState = useState(),
5
9
  date = _useState[0],
@@ -19,7 +23,8 @@ export var HeaderLevel = function HeaderLevel() {
19
23
  daysOfWeek: true,
20
24
  onSelect: onSelect,
21
25
  level: 2,
22
- bounds: ['2020-09-08', '2025-12-13']
26
+ bounds: bounds,
27
+ reference: reference
23
28
  })))
24
29
  // </Grommet>
25
30
  );
@@ -1,9 +1,13 @@
1
1
  import React, { useState } from 'react';
2
2
  import { Box, Calendar } from 'grommet';
3
+ var initialMonth = '2026-03-12T21:09:16.501Z';
3
4
  export var Multiple = function Multiple() {
4
- var _useState = useState([]),
5
+ var _useState = useState(),
5
6
  dates = _useState[0],
6
7
  setDates = _useState[1];
8
+ var _useState2 = useState(initialMonth),
9
+ reference = _useState2[0],
10
+ setReference = _useState2[1];
7
11
  return (
8
12
  /*#__PURE__*/
9
13
  // Uncomment <Grommet> lines when using outside of storybook
@@ -14,7 +18,7 @@ export var Multiple = function Multiple() {
14
18
  }, /*#__PURE__*/React.createElement(Calendar, {
15
19
  dates: dates,
16
20
  onSelect: function onSelect(date) {
17
- var nextDates = [].concat(dates);
21
+ var nextDates = dates ? [].concat(dates) : [];
18
22
  var index = nextDates.indexOf(date);
19
23
  if (index === -1) {
20
24
  nextDates.push(date);
@@ -25,7 +29,8 @@ export var Multiple = function Multiple() {
25
29
  console.log('Select iso date:', date, nextDates);
26
30
  console.log('Select utc date:', new Date(date));
27
31
  },
28
- bounds: ['2020-09-08', '2025-12-13']
32
+ reference: reference,
33
+ onReference: setReference
29
34
  }))
30
35
  // </Grommet>
31
36
  );
@@ -1,5 +1,9 @@
1
1
  import React, { useState } from 'react';
2
2
  import { Box, Calendar } from 'grommet';
3
+ var reference = '2026-04-12T21:09:16.501Z';
4
+ var end = new Date(reference);
5
+ var start = new Date(end.getTime() - 1000 * 60 * 60 * 24 * 90); // 90 days ago
6
+ var bounds = [start.getFullYear() + "-" + (start.getMonth() + 1) + "-" + start.getDate(), end.getFullYear() + "-" + (end.getMonth() + 1) + "-" + end.getDate()];
3
7
  export var Simple = function Simple() {
4
8
  var _useState = useState(),
5
9
  date = _useState[0],
@@ -19,7 +23,8 @@ export var Simple = function Simple() {
19
23
  daysOfWeek: true,
20
24
  onSelect: onSelect,
21
25
  size: "small",
22
- bounds: ['2020-09-08', '2025-12-13']
26
+ bounds: bounds,
27
+ reference: reference
23
28
  })))
24
29
  // </Grommet>
25
30
  );
@@ -1,18 +1,47 @@
1
- var _excluded = ["as", "children", "data", "margin", "onMore", "pad", "paginate", "show", "size", "step"];
1
+ var _excluded = ["as", "children", "data", "margin", "onMore", "pad", "paginate", "show", "size", "step", "sizeKey", "onOrder"],
2
+ _excluded2 = ["keyboard"];
2
3
  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); }
3
4
  function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
4
- import React, { Fragment, useContext } from 'react';
5
+ import React, { Fragment, useContext, useState } from 'react';
6
+ import styled from 'styled-components';
7
+ import { AnnounceContext } from '../../contexts/AnnounceContext';
5
8
  import { DataContext } from '../../contexts/DataContext';
9
+ import { MessageContext } from '../../contexts/MessageContext';
6
10
  import { Box } from '../Box';
7
11
  import { Card } from '../Card';
8
12
  import { CardBody } from '../CardBody';
9
13
  import { Grid } from '../Grid';
10
14
  import { InfiniteScroll } from '../InfiniteScroll';
15
+ import { Keyboard } from '../Keyboard';
11
16
  import { Pagination } from '../Pagination';
12
- import { normalizeShow, usePagination } from '../../utils';
17
+ import { normalizeShow, useId, usePagination } from '../../utils';
13
18
  import { CardsPropTypes } from './propTypes';
14
19
  import { useThemeValue } from '../../utils/useThemeValue';
20
+ import { StyledCellContainer } from './StyledCellContainer';
15
21
  var emptyData = [];
22
+ var HiddenText = styled.span.withConfig({
23
+ displayName: "Cards__HiddenText",
24
+ componentId: "sc-1f9ilr5-0"
25
+ })(["position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0;"]);
26
+ var indexForItem = function indexForItem(data, item) {
27
+ var index = data.indexOf(item);
28
+ if (index === -1) {
29
+ // If the item isn't in the data, try to find it by id. This allows for
30
+ // reordering to work when the items provided to Cards are different objects
31
+ // than those in the data array, as long as they share an id.
32
+ return data.findIndex(function (d) {
33
+ return d.id === item.id;
34
+ });
35
+ }
36
+ return index;
37
+ };
38
+ var reorder = function reorder(array, source, target) {
39
+ var result = array.slice(0);
40
+ var tmp = result[source];
41
+ if (source < target) for (var i = source; i < target; i += 1) result[i] = result[i + 1];else for (var _i = source; _i > target; _i -= 1) result[_i] = result[_i - 1];
42
+ result[target] = tmp;
43
+ return result;
44
+ };
16
45
  var Cards = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
17
46
  var _ref$as = _ref.as,
18
47
  as = _ref$as === void 0 ? 'ul' : _ref$as,
@@ -26,12 +55,19 @@ var Cards = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
26
55
  size = _ref.size,
27
56
  _ref$step = _ref.step,
28
57
  step = _ref$step === void 0 ? paginate ? 50 : undefined : _ref$step,
58
+ sizeKey = _ref.sizeKey,
59
+ onOrder = _ref.onOrder,
29
60
  rest = _objectWithoutPropertiesLoose(_ref, _excluded);
30
61
  var _useThemeValue = useThemeValue(),
31
62
  theme = _useThemeValue.theme;
32
- var _useContext = useContext(DataContext),
33
- contextData = _useContext.data;
63
+ var announce = useContext(AnnounceContext);
64
+ var _useContext = useContext(MessageContext),
65
+ format = _useContext.format;
66
+ var _useContext2 = useContext(DataContext),
67
+ contextData = _useContext2.data,
68
+ unfilteredData = _useContext2.unfilteredData;
34
69
  var data = dataProp || contextData || emptyData;
70
+ var unfiltered = unfilteredData || data;
35
71
  var _usePagination = usePagination(_extends({
36
72
  data: data,
37
73
  page: normalizeShow(showProp, step),
@@ -44,7 +80,128 @@ var Cards = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
44
80
  pad: pad,
45
81
  margin: margin
46
82
  }) : undefined;
47
- return /*#__PURE__*/React.createElement(Container, containerProps, /*#__PURE__*/React.createElement(Grid, _extends({
83
+ var _useState = useState(),
84
+ dragging = _useState[0],
85
+ setDragging = _useState[1];
86
+ var _useState2 = useState(),
87
+ orderedData = _useState2[0],
88
+ setOrderedData = _useState2[1];
89
+ var _useState3 = useState(),
90
+ unfilteredOrder = _useState3[0],
91
+ setUnfilteredOrder = _useState3[1];
92
+ var hintId = useId();
93
+ var currentItems = orderedData || (!paginate ? data : items);
94
+ var renderItem = function renderItem(item, index) {
95
+ var move = function move(count) {
96
+ var newIndex = Math.max(0, Math.min(index + count, currentItems.length - 1));
97
+ onOrder(reorder(unfiltered, indexForItem(unfiltered, item), indexForItem(unfiltered, currentItems[newIndex])));
98
+ announce(format({
99
+ id: 'cards.moved',
100
+ values: {
101
+ source: newIndex + 1,
102
+ target: currentItems.length
103
+ }
104
+ }));
105
+ };
106
+ var onOrderProps = onOrder ? {
107
+ tabIndex: 0,
108
+ 'aria-roledescription': format({
109
+ id: 'cards.description'
110
+ }),
111
+ 'aria-describedby': hintId,
112
+ draggable: true,
113
+ onDragStart: function onDragStart(event) {
114
+ event.dataTransfer.setData('text/plain', '');
115
+ // allowed per
116
+ // https://developer.mozilla.org/en-US/docs/Web/API/HTML_Drag_and_Drop_API#define_the_drag_effect
117
+ // eslint-disable-next-line no-param-reassign
118
+ event.dataTransfer.effectAllowed = 'move';
119
+ setDragging(index);
120
+ },
121
+ onDragEnd: function onDragEnd() {
122
+ setDragging(undefined);
123
+ setOrderedData(undefined);
124
+ setUnfilteredOrder(undefined);
125
+ },
126
+ onDragEnter: function onDragEnter(event) {
127
+ if (dragging !== undefined && dragging !== index) {
128
+ // Ignore synthetic re-fires caused by entering
129
+ // a child of this element
130
+ if (event.currentTarget.contains(event.relatedTarget)) return;
131
+ // eslint-disable-next-line no-param-reassign
132
+ event.dataTransfer.dropEffect = 'move';
133
+ setUnfilteredOrder(reorder(unfiltered, indexForItem(unfiltered, currentItems[dragging]), indexForItem(unfiltered, item)));
134
+ setOrderedData(reorder(currentItems, dragging, index));
135
+ setDragging(index);
136
+ }
137
+ },
138
+ onDragOver: function onDragOver(event) {
139
+ if (dragging !== undefined) {
140
+ // preventDefault is required to allow the drop to occur
141
+ event.preventDefault();
142
+ }
143
+ },
144
+ onDrop: function onDrop() {
145
+ if (unfilteredOrder) {
146
+ onOrder(unfilteredOrder);
147
+ }
148
+ },
149
+ keyboard: {
150
+ onUp: function onUp(event) {
151
+ event.preventDefault();
152
+ move(-1);
153
+ },
154
+ onDown: function onDown(event) {
155
+ event.preventDefault();
156
+ move(1);
157
+ },
158
+ onLeft: function onLeft(event) {
159
+ event.preventDefault();
160
+ move(-1);
161
+ },
162
+ onRight: function onRight(event) {
163
+ event.preventDefault();
164
+ move(1);
165
+ }
166
+ }
167
+ } : {};
168
+ var keyboard = onOrderProps.keyboard,
169
+ wrapperProps = _objectWithoutPropertiesLoose(onOrderProps, _excluded2);
170
+ var content;
171
+ if (children) {
172
+ content = children(item, index);
173
+ } else {
174
+ var _ref2, _ref3;
175
+ content = /*#__PURE__*/React.createElement(Card, {
176
+ key: item.id || index.toString(),
177
+ as: !(onOrder || sizeKey) && as === 'ul' ? 'li' : undefined
178
+ }, /*#__PURE__*/React.createElement(CardBody, null, (_ref2 = (_ref3 = typeof item === 'string' && item) != null ? _ref3 : typeof item === 'object' && Object.values(item)[0]) != null ? _ref2 : index));
179
+ }
180
+
181
+ // If the items are orderable or sized by a property, wrap them in a
182
+ // StyledCellContainer to apply the drag and drop handlers and/or
183
+ // size styles
184
+ if (onOrder || sizeKey) {
185
+ var round = theme.card.container.round;
186
+ content = /*#__PURE__*/React.createElement(StyledCellContainer, _extends({
187
+ key: "_container_" + ((item == null ? void 0 : item.id) || index),
188
+ as: as === 'ul' ? 'li' : undefined
189
+ }, wrapperProps, {
190
+ size: sizeKey ? item[sizeKey] : undefined,
191
+ round: round
192
+ }), content);
193
+ }
194
+
195
+ // Keyboard is only applied if onOrder is provided
196
+ return keyboard ? /*#__PURE__*/React.createElement(Keyboard, _extends({
197
+ key: "_keyboard_" + ((item == null ? void 0 : item.id) || index)
198
+ }, keyboard), content) : content;
199
+ };
200
+ return /*#__PURE__*/React.createElement(Container, containerProps, onOrder && /*#__PURE__*/React.createElement(HiddenText, {
201
+ id: hintId
202
+ }, format({
203
+ id: 'cards.reorderHint'
204
+ })), /*#__PURE__*/React.createElement(Grid, _extends({
48
205
  ref: ref,
49
206
  as: as,
50
207
  gap: theme.cards.grid.gap,
@@ -52,7 +209,7 @@ var Cards = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
52
209
  margin: !paginate && margin || 'none',
53
210
  pad: !paginate && pad || 'none'
54
211
  }, rest), /*#__PURE__*/React.createElement(InfiniteScroll, {
55
- items: !paginate ? data : items,
212
+ items: currentItems,
56
213
  onMore: onMore,
57
214
  show: !paginate ? showProp : undefined,
58
215
  step: step,
@@ -63,11 +220,7 @@ var Cards = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
63
220
  }, marker);
64
221
  }
65
222
  }, function (item, index) {
66
- var _ref2, _ref3;
67
- return children ? children(item, index) : /*#__PURE__*/React.createElement(Card, {
68
- key: index.toString(),
69
- as: as === 'ul' ? 'li' : undefined
70
- }, /*#__PURE__*/React.createElement(CardBody, null, (_ref2 = (_ref3 = typeof item === 'string' && item) != null ? _ref3 : typeof item === 'object' && Object.values(item)[0]) != null ? _ref2 : index));
223
+ return renderItem(item, index);
71
224
  })), paginate && data.length > step && items && items.length ? /*#__PURE__*/React.createElement(Pagination, _extends({
72
225
  alignSelf: "end"
73
226
  }, paginationProps)) : null);
@@ -0,0 +1,24 @@
1
+ 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); }
2
+ import styled from 'styled-components';
3
+ import { focusStyle, roundStyle, styledComponentsConfig, unfocusStyle } from '../../utils';
4
+ var sizeStyles = function sizeStyles(size) {
5
+ return size && typeof size === 'object' ? "\n " + (size != null && size.columns ? "grid-column: span " + size.columns + ";" : '') + "\n " + (size != null && size.rows ? "grid-row: span " + size.rows + ";" : '') + "\n " : '';
6
+ };
7
+
8
+ // display: grid makes the single child fill the wrapper (stretch in both axes)
9
+ export var StyledCellContainer = styled.div.withConfig(_extends({}, styledComponentsConfig, {
10
+ // 'size' passes isPropValid (valid for input/select), filter it to
11
+ // prevent the object value from reaching the DOM as an attribute.
12
+ shouldForwardProp: function shouldForwardProp(prop) {
13
+ return prop !== 'size' && styledComponentsConfig.shouldForwardProp(prop);
14
+ }
15
+ })).withConfig({
16
+ displayName: "StyledCellContainer",
17
+ componentId: "sc-183y88f-0"
18
+ })(["display:grid;", " ", " ", " &:focus{", "}&:focus:not(:focus-visible){", "}"], function (props) {
19
+ return props.size ? sizeStyles(props.size) : undefined;
20
+ }, function (props) {
21
+ return props.draggable ? 'cursor: move;' : undefined;
22
+ }, function (props) {
23
+ return props.round && roundStyle(props.round, props.responsive, props.theme);
24
+ }, focusStyle(), unfocusStyle());
@@ -6,7 +6,7 @@ import {
6
6
  MarginType,
7
7
  PadType,
8
8
  } from '../../utils';
9
- import { GridSizeType } from '../Grid';
9
+ import { GridProps, GridSizeType } from '../Grid';
10
10
  import { PaginationType } from '../Pagination';
11
11
 
12
12
  export interface CardsProps<CardType = any> {
@@ -18,10 +18,12 @@ export interface CardsProps<CardType = any> {
18
18
  gridArea?: GridAreaType;
19
19
  margin?: MarginType;
20
20
  onMore?: () => void;
21
+ onOrder?: () => void;
21
22
  pad?: PadType;
22
23
  paginate?: boolean | PaginationType;
23
24
  show?: number | { page?: number };
24
25
  size?: GridSizeType;
26
+ sizeKey?: string;
25
27
  step?: number;
26
28
  }
27
29
 
@@ -35,6 +37,7 @@ type ulProps = Omit<
35
37
 
36
38
  export interface CardsExtendedProps<CardType>
37
39
  extends CardsProps<CardType>,
40
+ Omit<GridProps, keyof CardsProps<CardType>>,
38
41
  ulProps {}
39
42
 
40
43
  declare class Cards<CardType = any> extends React.Component<
@@ -8,10 +8,12 @@ if (process.env.NODE_ENV !== 'production') {
8
8
  data: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.shape({})])),
9
9
  children: PropTypes.func,
10
10
  onMore: PropTypes.func,
11
+ onOrder: PropTypes.func,
11
12
  paginate: PropTypes.oneOfType([PropTypes.bool, PropTypes.object]),
12
13
  show: PropTypes.oneOfType([PropTypes.number, PropTypes.shape({
13
14
  page: PropTypes.number
14
15
  })]),
16
+ sizeKey: PropTypes.string,
15
17
  step: PropTypes.number
16
18
  });
17
19
  }
@@ -0,0 +1,65 @@
1
+ import React from 'react';
2
+ import { Box, Card, CardBody, Heading, Text } from 'grommet';
3
+ import { Cards } from '../Cards';
4
+ var data = [{
5
+ city: 'Boise',
6
+ state: 'Idaho',
7
+ size: {
8
+ columns: 2,
9
+ rows: 1
10
+ }
11
+ }, {
12
+ city: 'Fort Collins',
13
+ state: 'Colorado'
14
+ }, {
15
+ city: 'Bay Area',
16
+ state: 'California'
17
+ }, {
18
+ city: 'San Diego',
19
+ state: 'California',
20
+ size: {
21
+ columns: 2,
22
+ rows: 1
23
+ }
24
+ }, {
25
+ city: 'San Francisco',
26
+ state: 'California',
27
+ size: {
28
+ columns: 1,
29
+ rows: 2
30
+ }
31
+ }, {
32
+ city: 'Los Angeles',
33
+ state: 'California'
34
+ }, {
35
+ city: 'Portland',
36
+ state: 'Oregon'
37
+ }, {
38
+ city: 'Seattle',
39
+ state: 'Washington'
40
+ }];
41
+ export var Sizable = function Sizable() {
42
+ return /*#__PURE__*/React.createElement(Box, {
43
+ fill: true
44
+ }, /*#__PURE__*/React.createElement(Cards, {
45
+ id: "myGrid",
46
+ data: data,
47
+ pad: "medium",
48
+ columns: ['flex', 'flex', 'flex'],
49
+ rows: "xsmall",
50
+ sizeKey: "size"
51
+ }, function (datum) {
52
+ return /*#__PURE__*/React.createElement(Card, {
53
+ key: datum.city,
54
+ pad: "small",
55
+ elevation: "medium"
56
+ }, /*#__PURE__*/React.createElement(CardBody, null, /*#__PURE__*/React.createElement(Heading, {
57
+ level: 2,
58
+ size: "small",
59
+ margin: "none"
60
+ }, datum.city), /*#__PURE__*/React.createElement(Text, null, datum.state)));
61
+ }));
62
+ };
63
+ export default {
64
+ title: 'Visualizations/Cards/Sizable'
65
+ };
@@ -0,0 +1,64 @@
1
+ import React from 'react';
2
+ import { Box, Card, CardBody, Heading, Text } from 'grommet';
3
+ import { Cards } from '../Cards';
4
+ var data = [{
5
+ id: 'bo',
6
+ city: 'Boise',
7
+ state: 'Idaho'
8
+ }, {
9
+ id: 'fc',
10
+ city: 'Fort Collins',
11
+ state: 'Colorado'
12
+ }, {
13
+ id: 'ba',
14
+ city: 'Bay Area',
15
+ state: 'California'
16
+ }, {
17
+ id: 'sd',
18
+ city: 'San Diego',
19
+ state: 'California'
20
+ }, {
21
+ id: 'sf',
22
+ city: 'San Francisco',
23
+ state: 'California'
24
+ }, {
25
+ id: 'la',
26
+ city: 'Los Angeles',
27
+ state: 'California'
28
+ }, {
29
+ id: 'pt',
30
+ city: 'Portland',
31
+ state: 'Oregon'
32
+ }, {
33
+ id: 'se',
34
+ city: 'Seattle',
35
+ state: 'Washington'
36
+ }];
37
+ export var OnOrder = function OnOrder() {
38
+ var _React$useState = React.useState(data),
39
+ orderedData = _React$useState[0],
40
+ setOrderedData = _React$useState[1];
41
+ return /*#__PURE__*/React.createElement(Box, {
42
+ fill: true
43
+ }, /*#__PURE__*/React.createElement(Cards, {
44
+ id: "myGrid",
45
+ data: orderedData,
46
+ pad: "medium",
47
+ columns: ['flex', 'flex', 'flex'],
48
+ onOrder: setOrderedData
49
+ }, function (datum) {
50
+ return /*#__PURE__*/React.createElement(Card, {
51
+ key: datum.city,
52
+ pad: "medium",
53
+ elevation: "medium"
54
+ }, /*#__PURE__*/React.createElement(CardBody, null, /*#__PURE__*/React.createElement(Heading, {
55
+ level: 2,
56
+ size: "small",
57
+ margin: "none"
58
+ }, datum.city), /*#__PURE__*/React.createElement(Text, null, datum.state)));
59
+ }));
60
+ };
61
+ OnOrder.storyName = 'onOrder';
62
+ export default {
63
+ title: 'Visualizations/Cards/onOrder'
64
+ };
@@ -39,26 +39,6 @@ var generateOptions = function generateOptions(data, property) {
39
39
  return 0;
40
40
  });
41
41
  };
42
-
43
- // ensure floating point calculations are in integers
44
- var alignMax = function alignMax(value, interval) {
45
- var multiplier = Math.pow(10, Math.max(getDecimalCount(value), getDecimalCount(interval)));
46
- var integerValue = value * multiplier;
47
- var integerInterval = interval * multiplier;
48
- if (value > 0) return (integerValue - integerValue % integerInterval + integerInterval) / multiplier;
49
- if (value < 0) return (integerValue + integerValue % integerInterval) / multiplier;
50
- return value;
51
- };
52
-
53
- // ensure floating point calculations are in integers
54
- var alignMin = function alignMin(value, interval) {
55
- var multiplier = Math.pow(10, Math.max(getDecimalCount(value), getDecimalCount(interval)));
56
- var integerValue = value * multiplier;
57
- var integerInterval = interval * multiplier;
58
- if (value > 0) return (integerValue - integerValue % integerInterval) / multiplier;
59
- if (value < 0) return (integerValue - integerValue % integerInterval - integerInterval) / multiplier;
60
- return value;
61
- };
62
42
  var booleanOptions = [{
63
43
  label: 'true',
64
44
  value: true
@@ -96,21 +76,24 @@ export var DataFilter = function DataFilter(_ref) {
96
76
 
97
77
  // generate options from all values for property
98
78
  var uniqueValues = generateOptions(unfilteredData || data, property);
99
- // if less than two values, nothing to filter
100
- if (uniqueValues.length < 2) return [undefined, undefined];
79
+ // if no values, nothing to filter
80
+ // uniqueValues.length === 0 allows single item/value filters to render
81
+ if (uniqueValues.length === 0) return [undefined, undefined];
101
82
  // if any values aren't numeric, treat as options
102
83
  if (uniqueValues.some(function (v) {
103
84
  return v !== undefined && typeof v !== 'number';
104
85
  })) return [uniqueValues, undefined];
105
86
  // all values are numeric, treat as range
106
- var delta = uniqueValues[uniqueValues.length - 1] - uniqueValues[0];
107
- var interval = Number.parseFloat((delta / 3).toPrecision(1));
108
87
  var min = uniqueValues[0];
109
88
  var max = uniqueValues[uniqueValues.length - 1];
110
- // normalize to make it friendler, so [1.3, 4.895] becomes [1, 5]
111
- if (getDecimalCount(min) > 0 || getDecimalCount(max) > 0) {
112
- min = alignMin(min, interval);
113
- max = alignMax(max, interval);
89
+ // Clean up floating-point precision artifacts, capped to 2 decimal places.
90
+ // Use floor for min and ceil for max so actual data values always fall
91
+ // within the computed range (e.g. -4.859 stays inside [-19.99, -4.85]).
92
+ var maxDecimalPlaces = Math.max(getDecimalCount(uniqueValues[0]), getDecimalCount(uniqueValues[uniqueValues.length - 1]));
93
+ if (maxDecimalPlaces > 0) {
94
+ var multiplier = Math.pow(10, Math.min(maxDecimalPlaces, 2));
95
+ min = Math.floor(min * multiplier) / multiplier;
96
+ max = Math.ceil(max * multiplier) / multiplier;
114
97
  }
115
98
  return [undefined, [min, max]];
116
99
  }, [children, data, optionsProp, properties, property, rangeProp, unfilteredData]),
@@ -158,6 +141,16 @@ export var DataFilter = function DataFilter(_ref) {
158
141
  var multiplier = Math.pow(10, decimalCount);
159
142
  step = multiplier * delta / (multiplier * defaultRangeSteps);
160
143
  } else step = delta / defaultRangeSteps;
144
+
145
+ // Cap step to maximum 2 decimal places to avoid long
146
+ // precision artifacts
147
+ var stepMultiplier = Math.pow(10, 2);
148
+ step = Math.round(step * stepMultiplier) / stepMultiplier;
149
+
150
+ // Ensure step is never 0 or negative (required for RangeSelector)
151
+ if (step <= 0) {
152
+ step = Math.pow(10, -(Math.max(getDecimalCount(range[0]), getDecimalCount(range[1])) || 1));
153
+ }
161
154
  }
162
155
  content = /*#__PURE__*/React.createElement(RangeSelector, _extends({
163
156
  "aria-label": ariaLabel,
@@ -308,7 +308,7 @@ export var ResizablePinnedDataTable = function ResizablePinnedDataTable() {
308
308
  resizeable: true
309
309
  })))
310
310
  // </Grommet>
311
- ;
311
+ ;
312
312
  };
313
313
  ResizablePinnedDataTable.storyName = 'Resizable pinned columns';
314
314
  export default {