grommet 2.54.0 → 2.56.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 (177) hide show
  1. package/components/Button/Button.js +7 -4
  2. package/components/Button/stories/CustomThemed/ChildrenPlainOption.stories.js +86 -0
  3. package/components/Calendar/Calendar.js +24 -16
  4. package/components/Calendar/index.d.ts +1 -1
  5. package/components/Calendar/stories/CustomHeader.stories.js +6 -1
  6. package/components/Calendar/stories/CustomThemed/CustomSizeHeading.stories.js +6 -1
  7. package/components/Calendar/stories/Dual.stories.js +23 -11
  8. package/components/Calendar/stories/HeaderLevel.stories.js +6 -1
  9. package/components/Calendar/stories/Multiple.stories.js +8 -3
  10. package/components/Calendar/stories/Simple.stories.js +6 -1
  11. package/components/Cards/Cards.js +164 -10
  12. package/components/Cards/StyledCellContainer.js +29 -0
  13. package/components/Cards/index.d.ts +4 -1
  14. package/components/Cards/propTypes.js +2 -0
  15. package/components/Cards/stories/Sizable.stories.js +70 -0
  16. package/components/Cards/stories/onOrder.stories.js +69 -0
  17. package/components/DataFilter/DataFilter.js +21 -28
  18. package/components/DateInput/DateInput.js +57 -24
  19. package/components/DateInput/index.d.ts +1 -0
  20. package/components/DateInput/utils.js +2 -2
  21. package/components/Drop/DropContainer.js +59 -3
  22. package/components/FileInput/FileInput.js +3 -0
  23. package/components/Form/stories/CustomThemed/FieldCustomStates.stories.js +7 -1
  24. package/components/Form/stories/FieldStates.stories.js +7 -1
  25. package/components/FormField/FormField.js +1 -1
  26. package/components/Grommet/Grommet.js +2 -1
  27. package/components/Grommet/index.d.ts +27 -0
  28. package/components/Grommet/propTypes.js +33 -1
  29. package/components/Layer/LayerContainer.d.ts +40 -0
  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/Stepper/StepConnector.js +68 -0
  34. package/components/Stepper/Stepper.js +309 -0
  35. package/components/Stepper/StepperContext.js +43 -0
  36. package/components/Stepper/StepperDescription.js +26 -0
  37. package/components/Stepper/StepperHelperText.js +44 -0
  38. package/components/Stepper/StepperIndicator.js +74 -0
  39. package/components/Stepper/StepperLabel.js +41 -0
  40. package/components/Stepper/StepperStep.js +127 -0
  41. package/components/Stepper/StyledStepper.js +124 -0
  42. package/components/Stepper/index.d.ts +80 -0
  43. package/components/Stepper/index.js +18 -0
  44. package/components/Stepper/propTypes.js +35 -0
  45. package/components/Stepper/stories/DisabledSteps.stories.js +45 -0
  46. package/components/Stepper/stories/ErrorStates.stories.js +45 -0
  47. package/components/Stepper/stories/HorizontalSteps.stories.js +50 -0
  48. package/components/Stepper/stories/Interactive.stories.js +60 -0
  49. package/components/Stepper/stories/KeyboardNavigation.stories.js +64 -0
  50. package/components/Stepper/stories/NestedSubSteps.stories.js +70 -0
  51. package/components/Stepper/stories/ReadOnly.stories.js +43 -0
  52. package/components/Stepper/stories/ThemingLightDark.stories.js +58 -0
  53. package/components/Stepper/stories/VerticalSteps.stories.js +67 -0
  54. package/components/Tab/Tab.js +19 -6
  55. package/components/Tabs/Tabs.js +156 -22
  56. package/components/Tag/Tag.js +4 -3
  57. package/components/Tag/index.d.ts +5 -4
  58. package/components/Tag/propTypes.js +3 -2
  59. package/components/TextInput/StyledTextInput.js +4 -2
  60. package/components/TextInput/TextInput.js +1 -0
  61. package/components/TimeInput/README.md +2 -0
  62. package/components/TimeInput/StyledTimeInput.js +73 -0
  63. package/components/TimeInput/TimeInput.js +689 -0
  64. package/components/TimeInput/TimeInputPopup.js +393 -0
  65. package/components/TimeInput/index.d.ts +41 -0
  66. package/components/TimeInput/index.js +6 -0
  67. package/components/TimeInput/propTypes.js +35 -0
  68. package/components/TimeInput/stories/Controlled.stories.tsx +29 -0
  69. package/components/TimeInput/stories/Disabled.stories.tsx +13 -0
  70. package/components/TimeInput/stories/Form.stories.tsx +38 -0
  71. package/components/TimeInput/stories/ReadOnly.stories.tsx +13 -0
  72. package/components/TimeInput/stories/Simple.stories.tsx +19 -0
  73. package/components/TimeInput/stories/Step.stories.tsx +14 -0
  74. package/components/TimeInput/stories/ThemingLightDark.stories.tsx +22 -0
  75. package/components/TimeInput/stories/Uncontrolled.stories.tsx +22 -0
  76. package/components/TimeInput/useSectionedTimeField.js +359 -0
  77. package/components/TimeInput/utils.js +187 -0
  78. package/components/index.d.ts +2 -0
  79. package/components/index.js +12 -0
  80. package/es6/components/Button/Button.js +7 -4
  81. package/es6/components/Button/stories/CustomThemed/ChildrenPlainOption.stories.js +81 -0
  82. package/es6/components/Calendar/Calendar.js +24 -16
  83. package/es6/components/Calendar/index.d.ts +1 -1
  84. package/es6/components/Calendar/stories/CustomHeader.stories.js +6 -1
  85. package/es6/components/Calendar/stories/CustomThemed/CustomSizeHeading.stories.js +6 -1
  86. package/es6/components/Calendar/stories/Dual.stories.js +23 -11
  87. package/es6/components/Calendar/stories/HeaderLevel.stories.js +6 -1
  88. package/es6/components/Calendar/stories/Multiple.stories.js +8 -3
  89. package/es6/components/Calendar/stories/Simple.stories.js +6 -1
  90. package/es6/components/Cards/Cards.js +165 -12
  91. package/es6/components/Cards/StyledCellContainer.js +24 -0
  92. package/es6/components/Cards/index.d.ts +4 -1
  93. package/es6/components/Cards/propTypes.js +2 -0
  94. package/es6/components/Cards/stories/Sizable.stories.js +65 -0
  95. package/es6/components/Cards/stories/onOrder.stories.js +64 -0
  96. package/es6/components/DataFilter/DataFilter.js +21 -28
  97. package/es6/components/DateInput/DateInput.js +57 -24
  98. package/es6/components/DateInput/index.d.ts +1 -0
  99. package/es6/components/DateInput/utils.js +2 -2
  100. package/es6/components/Drop/DropContainer.js +59 -3
  101. package/es6/components/FileInput/FileInput.js +3 -0
  102. package/es6/components/Form/stories/CustomThemed/FieldCustomStates.stories.js +7 -1
  103. package/es6/components/Form/stories/FieldStates.stories.js +7 -1
  104. package/es6/components/FormField/FormField.js +1 -1
  105. package/es6/components/Grommet/Grommet.js +2 -1
  106. package/es6/components/Grommet/index.d.ts +27 -0
  107. package/es6/components/Grommet/propTypes.js +33 -1
  108. package/es6/components/Layer/LayerContainer.d.ts +40 -0
  109. package/es6/components/Select/stories/ChildrenRender.stories.js +29 -56
  110. package/es6/components/SelectMultiple/stories/typescript/Children.stories.tsx +24 -48
  111. package/es6/components/SelectMultiple/stories/typescript/ValueLabel.stories.tsx +88 -0
  112. package/es6/components/Stepper/StepConnector.js +63 -0
  113. package/es6/components/Stepper/Stepper.js +306 -0
  114. package/es6/components/Stepper/StepperContext.js +39 -0
  115. package/es6/components/Stepper/StepperDescription.js +21 -0
  116. package/es6/components/Stepper/StepperHelperText.js +39 -0
  117. package/es6/components/Stepper/StepperIndicator.js +69 -0
  118. package/es6/components/Stepper/StepperLabel.js +36 -0
  119. package/es6/components/Stepper/StepperStep.js +122 -0
  120. package/es6/components/Stepper/StyledStepper.js +120 -0
  121. package/es6/components/Stepper/index.d.ts +80 -0
  122. package/es6/components/Stepper/index.js +6 -0
  123. package/es6/components/Stepper/propTypes.js +30 -0
  124. package/es6/components/Stepper/stories/DisabledSteps.stories.js +41 -0
  125. package/es6/components/Stepper/stories/ErrorStates.stories.js +41 -0
  126. package/es6/components/Stepper/stories/HorizontalSteps.stories.js +46 -0
  127. package/es6/components/Stepper/stories/Interactive.stories.js +56 -0
  128. package/es6/components/Stepper/stories/KeyboardNavigation.stories.js +60 -0
  129. package/es6/components/Stepper/stories/NestedSubSteps.stories.js +66 -0
  130. package/es6/components/Stepper/stories/ReadOnly.stories.js +39 -0
  131. package/es6/components/Stepper/stories/ThemingLightDark.stories.js +54 -0
  132. package/es6/components/Stepper/stories/VerticalSteps.stories.js +63 -0
  133. package/es6/components/Tab/Tab.js +19 -6
  134. package/es6/components/Tabs/Tabs.js +157 -23
  135. package/es6/components/Tag/Tag.js +4 -3
  136. package/es6/components/Tag/index.d.ts +5 -4
  137. package/es6/components/Tag/propTypes.js +3 -2
  138. package/es6/components/TextInput/StyledTextInput.js +4 -2
  139. package/es6/components/TextInput/TextInput.js +1 -0
  140. package/es6/components/TimeInput/README.md +2 -0
  141. package/es6/components/TimeInput/StyledTimeInput.js +68 -0
  142. package/es6/components/TimeInput/TimeInput.js +685 -0
  143. package/es6/components/TimeInput/TimeInputPopup.js +389 -0
  144. package/es6/components/TimeInput/index.d.ts +41 -0
  145. package/es6/components/TimeInput/index.js +1 -0
  146. package/es6/components/TimeInput/propTypes.js +30 -0
  147. package/es6/components/TimeInput/stories/Controlled.stories.tsx +29 -0
  148. package/es6/components/TimeInput/stories/Disabled.stories.tsx +13 -0
  149. package/es6/components/TimeInput/stories/Form.stories.tsx +38 -0
  150. package/es6/components/TimeInput/stories/ReadOnly.stories.tsx +13 -0
  151. package/es6/components/TimeInput/stories/Simple.stories.tsx +19 -0
  152. package/es6/components/TimeInput/stories/Step.stories.tsx +14 -0
  153. package/es6/components/TimeInput/stories/ThemingLightDark.stories.tsx +22 -0
  154. package/es6/components/TimeInput/stories/Uncontrolled.stories.tsx +22 -0
  155. package/es6/components/TimeInput/useSectionedTimeField.js +356 -0
  156. package/es6/components/TimeInput/utils.js +183 -0
  157. package/es6/components/index.d.ts +2 -0
  158. package/es6/components/index.js +2 -0
  159. package/es6/index.d.ts +2 -0
  160. package/es6/languages/default.json +27 -1
  161. package/es6/themes/base.d.ts +109 -0
  162. package/es6/themes/base.js +208 -0
  163. package/es6/utils/index.d.ts +1 -0
  164. package/es6/utils/styles.js +23 -12
  165. package/grommet.min.js +1 -1
  166. package/grommet.min.js.map +1 -1
  167. package/index.d.ts +2 -0
  168. package/languages/default.json +27 -1
  169. package/package.json +51 -53
  170. package/themes/base.d.ts +109 -0
  171. package/themes/base.js +208 -0
  172. package/utils/index.d.ts +1 -0
  173. package/utils/styles.js +23 -12
  174. package/components/TextInput/stories/CustomThemed/CustomSuggestions.stories.tsx +0 -180
  175. package/components/TextInput/stories/CustomThemed/Themed.stories.js +0 -79
  176. package/es6/components/TextInput/stories/CustomThemed/CustomSuggestions.stories.tsx +0 -180
  177. package/es6/components/TextInput/stories/CustomThemed/Themed.stories.js +0 -74
@@ -0,0 +1,81 @@
1
+ import React from 'react';
2
+ import { Add } from "grommet-icons/es6/icons/Add";
3
+ import { Box, Button, Grommet, Text } from 'grommet';
4
+ export var ChildrenPlainOption = function ChildrenPlainOption() {
5
+ return /*#__PURE__*/React.createElement(Box, {
6
+ pad: "large",
7
+ gap: "large"
8
+ }, /*#__PURE__*/React.createElement(Grommet, {
9
+ options: {
10
+ button: {
11
+ childrenPlain: false
12
+ }
13
+ }
14
+ }, /*#__PURE__*/React.createElement(Box, {
15
+ align: "center",
16
+ gap: "small"
17
+ }, /*#__PURE__*/React.createElement(Text, {
18
+ size: "small",
19
+ color: "text-weak"
20
+ }, "options.button.childrenPlain defaults to true. Setting it to false stops automatically forcing plain when Button has children."), /*#__PURE__*/React.createElement(Button, {
21
+ hoverIndicator: "light-1",
22
+ onClick: function onClick() {}
23
+ }, /*#__PURE__*/React.createElement(Box, {
24
+ pad: "small",
25
+ direction: "row",
26
+ align: "center",
27
+ gap: "small"
28
+ }, /*#__PURE__*/React.createElement(Add, null), /*#__PURE__*/React.createElement(Text, null, "Option false"))), /*#__PURE__*/React.createElement(Button, {
29
+ hoverIndicator: "light-1",
30
+ plain: true,
31
+ onClick: function onClick() {}
32
+ }, /*#__PURE__*/React.createElement(Box, {
33
+ pad: "small",
34
+ direction: "row",
35
+ align: "center",
36
+ gap: "small"
37
+ }, /*#__PURE__*/React.createElement(Add, null), /*#__PURE__*/React.createElement(Text, null, "Explicit plain"))))), /*#__PURE__*/React.createElement(Grommet, {
38
+ options: {
39
+ button: {
40
+ childrenPlain: false
41
+ }
42
+ },
43
+ theme: {
44
+ global: {
45
+ font: {
46
+ family: "-apple-system, BlinkMacSystemFont"
47
+ }
48
+ },
49
+ button: {
50
+ "default": {}
51
+ }
52
+ }
53
+ }, /*#__PURE__*/React.createElement(Box, {
54
+ align: "center",
55
+ gap: "small"
56
+ }, /*#__PURE__*/React.createElement(Text, {
57
+ size: "small",
58
+ color: "text-weak"
59
+ }, "Same behavior applies for kind buttons."), /*#__PURE__*/React.createElement(Button, {
60
+ hoverIndicator: "light-1",
61
+ onClick: function onClick() {}
62
+ }, /*#__PURE__*/React.createElement(Box, {
63
+ pad: "small",
64
+ direction: "row",
65
+ align: "center",
66
+ gap: "small"
67
+ }, /*#__PURE__*/React.createElement(Add, null), /*#__PURE__*/React.createElement(Text, null, "Kind option false"))), /*#__PURE__*/React.createElement(Button, {
68
+ hoverIndicator: "light-1",
69
+ plain: true,
70
+ onClick: function onClick() {}
71
+ }, /*#__PURE__*/React.createElement(Box, {
72
+ pad: "small",
73
+ direction: "row",
74
+ align: "center",
75
+ gap: "small"
76
+ }, /*#__PURE__*/React.createElement(Add, null), /*#__PURE__*/React.createElement(Text, null, "Kind explicit plain"))))));
77
+ };
78
+ ChildrenPlainOption.storyName = 'Children Plain Option';
79
+ export default {
80
+ title: 'Controls/Button/Custom Themed/Children Plain Option'
81
+ };
@@ -90,9 +90,12 @@ var normalizeRange = function normalizeRange(value, activeDate) {
90
90
  if (range instanceof Date) range = activeDate === 'start' ? [[undefined, range]] : [[range, undefined]];else if (Array.isArray(range) && !Array.isArray(range[0])) range = [range];
91
91
  return range;
92
92
  };
93
- var getReference = function getReference(reference, value, activeDate) {
93
+ var getReference = function getReference(reference, onReference, value, activeDate) {
94
94
  var nextReference;
95
- if (value) {
95
+ if (reference && onReference) {
96
+ // controlled component, so use the reference provided
97
+ nextReference = reference;
98
+ } else if (value) {
96
99
  if (Array.isArray(value)) {
97
100
  if (value[0] instanceof Date) {
98
101
  // if we just selected an end date, active date will be 'start'
@@ -295,14 +298,12 @@ var Calendar = /*#__PURE__*/forwardRef(function (_ref4, ref) {
295
298
  var val = dateProp || datesProp;
296
299
  setValue(_normalizeInput(val));
297
300
  }, [dateProp, datesProp]);
298
- var _useState3 = useState(getReference(_normalizeInput(referenceProp), value, activeDate)),
301
+ var _useState3 = useState(getReference(_normalizeInput(referenceProp), onReference, value, activeDate)),
299
302
  reference = _useState3[0],
300
303
  setReference = _useState3[1];
301
304
  useEffect(function () {
302
- if (value) {
303
- setReference(getReference(_normalizeInput(referenceProp), value, activeDate));
304
- }
305
- }, [referenceProp, value, activeDate]);
305
+ setReference(getReference(_normalizeInput(referenceProp), onReference, value, activeDate));
306
+ }, [referenceProp, onReference, value, activeDate]);
306
307
  var _useState4 = useState(_getOutputFormat(dateProp || datesProp)),
307
308
  outputFormat = _useState4[0],
308
309
  setOutputFormat = _useState4[1];
@@ -459,14 +460,15 @@ var Calendar = /*#__PURE__*/forwardRef(function (_ref4, ref) {
459
460
  var handleRange = useCallback(function (selectedDate) {
460
461
  var _priorRange$, _priorRange$2;
461
462
  var result;
463
+ var nextActiveDate = activeDate;
462
464
  var priorRange = normalizeRange(value, activeDate);
463
465
  // deselect when date clicked was the start/end of the range
464
466
  if (selectedDate.getTime() === (priorRange == null || (_priorRange$ = priorRange[0]) == null || (_priorRange$ = _priorRange$[0]) == null ? void 0 : _priorRange$.getTime())) {
465
467
  result = [[undefined, priorRange[0][1]]];
466
- setActiveDate('start');
468
+ nextActiveDate = 'start';
467
469
  } else if (selectedDate.getTime() === (priorRange == null || (_priorRange$2 = priorRange[0]) == null || (_priorRange$2 = _priorRange$2[1]) == null ? void 0 : _priorRange$2.getTime())) {
468
470
  result = [[priorRange[0][0], undefined]];
469
- setActiveDate('end');
471
+ nextActiveDate = 'end';
470
472
  }
471
473
  // selecting start date
472
474
  else if (activeDate === 'start') {
@@ -479,18 +481,18 @@ var Calendar = /*#__PURE__*/forwardRef(function (_ref4, ref) {
479
481
  } else if (selectedDate.getTime() > priorRange[0][1].getTime()) {
480
482
  result = [[selectedDate, undefined]];
481
483
  }
482
- setActiveDate('end');
484
+ nextActiveDate = 'end';
483
485
  }
484
486
  // selecting end date
485
487
  else if (!priorRange) {
486
488
  result = [[undefined, selectedDate]];
487
- setActiveDate('start');
489
+ nextActiveDate = 'start';
488
490
  } else if (selectedDate.getTime() < priorRange[0][0].getTime()) {
489
491
  result = [[selectedDate, undefined]];
490
- setActiveDate('end');
492
+ nextActiveDate = 'end';
491
493
  } else if (selectedDate.getTime() > priorRange[0][0].getTime()) {
492
494
  result = [[priorRange[0][0], selectedDate]];
493
- setActiveDate('start');
495
+ nextActiveDate = 'start';
494
496
  }
495
497
 
496
498
  // If no dates selected, always return undefined; else format
@@ -504,21 +506,27 @@ var Calendar = /*#__PURE__*/forwardRef(function (_ref4, ref) {
504
506
  });
505
507
  }
506
508
  }
509
+ setActiveDate(nextActiveDate);
507
510
  setValue(result);
508
- return result;
511
+ return [result, nextActiveDate];
509
512
  }, [activeDate, value, range]);
510
513
  var selectDate = useCallback(function (selectedDate) {
511
514
  // If no onSelect prop is provided, the calendar should be read-only
512
515
  if (!onSelect) return;
513
516
  var nextValue;
517
+ var nextActiveDate;
518
+ var details = {};
514
519
  if (range || Array.isArray(value == null ? void 0 : value[0])) {
515
- nextValue = handleRange(selectedDate);
520
+ var _handleRange = handleRange(selectedDate);
521
+ nextValue = _handleRange[0];
522
+ nextActiveDate = _handleRange[1];
523
+ details.activeDate = nextActiveDate;
516
524
  } else {
517
525
  nextValue = selectedDate;
518
526
  }
519
527
  if (onSelect) {
520
528
  nextValue = _normalizeOutput(nextValue, outputFormat);
521
- onSelect(nextValue);
529
+ onSelect(nextValue, details);
522
530
  }
523
531
  }, [handleRange, onSelect, outputFormat, range, value]);
524
532
  var onClick = function onClick(selectedDate) {
@@ -46,7 +46,7 @@ export interface CalendarProps {
46
46
  next?: string;
47
47
  };
48
48
  onReference?: (reference: string) => void;
49
- onSelect?: (select: string | string[]) => any;
49
+ onSelect?: (select: string | string[], options?: { activeDate?: 'start' | 'end' }) => any;
50
50
  range?: boolean | 'array';
51
51
  reference?: string;
52
52
  responsive?: boolean;
@@ -2,6 +2,10 @@ import React, { useState } from 'react';
2
2
  import { Box, Button, Calendar, Text } from 'grommet';
3
3
  import { FormPreviousLink } from "grommet-icons/es6/icons/FormPreviousLink";
4
4
  import { FormNextLink } from "grommet-icons/es6/icons/FormNextLink";
5
+ var reference = '2026-04-12T21:09:16.501Z';
6
+ var end = new Date(reference);
7
+ var start = new Date(end.getTime() - 1000 * 60 * 60 * 24 * 90); // 90 days ago
8
+ var bounds = [start.getFullYear() + "-" + (start.getMonth() + 1) + "-" + start.getDate(), end.getFullYear() + "-" + (end.getMonth() + 1) + "-" + end.getDate()];
5
9
  export var CustomHeaderCalendar = function CustomHeaderCalendar() {
6
10
  var _useState = useState(),
7
11
  date = _useState[0],
@@ -20,7 +24,8 @@ export var CustomHeaderCalendar = function CustomHeaderCalendar() {
20
24
  date: date,
21
25
  onSelect: onSelect,
22
26
  size: "small",
23
- bounds: ['2020-09-08', '2025-12-13'],
27
+ bounds: bounds,
28
+ reference: reference,
24
29
  header: function header(_ref) {
25
30
  var currentDate = _ref.date,
26
31
  locale = _ref.locale,
@@ -8,6 +8,10 @@ var customHeading = deepMerge(grommet, {
8
8
  }
9
9
  }
10
10
  });
11
+ var reference = '2026-04-12T21:09:16.501Z';
12
+ var end = new Date(reference);
13
+ var start = new Date(end.getTime() - 1000 * 60 * 60 * 24 * 90); // 90 days ago
14
+ var bounds = [start.getFullYear() + "-" + (start.getMonth() + 1) + "-" + start.getDate(), end.getFullYear() + "-" + (end.getMonth() + 1) + "-" + end.getDate()];
11
15
  export var CustomSizeCalendar = function CustomSizeCalendar() {
12
16
  var _useState = useState(),
13
17
  date = _useState[0],
@@ -23,7 +27,8 @@ export var CustomSizeCalendar = function CustomSizeCalendar() {
23
27
  }, /*#__PURE__*/React.createElement(Calendar, {
24
28
  date: date,
25
29
  onSelect: onSelect,
26
- bounds: ['2020-09-08', '2025-12-13']
30
+ bounds: bounds,
31
+ reference: reference
27
32
  })));
28
33
  };
29
34
  CustomSizeCalendar.storyName = 'Heading size';
@@ -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<