grommet 2.30.0 → 2.32.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 (162) hide show
  1. package/components/Accordion/Accordion.js +4 -2
  2. package/components/Accordion/index.d.ts +1 -0
  3. package/components/Accordion/propTypes.js +1 -0
  4. package/components/AccordionPanel/AccordionPanel.js +2 -1
  5. package/components/Anchor/Anchor.js +3 -2
  6. package/components/Box/Box.js +14 -4
  7. package/components/Box/stories/Border.js +15 -1
  8. package/components/Button/Badge.js +42 -43
  9. package/components/Button/BusyAnimation.js +51 -0
  10. package/components/Button/Button.js +78 -15
  11. package/components/Button/StyledButton.js +7 -3
  12. package/components/Button/StyledButtonKind.js +12 -6
  13. package/components/Button/index.d.ts +9 -0
  14. package/components/Button/propTypes.js +7 -0
  15. package/components/Button/stories/Busy.js +45 -0
  16. package/components/Calendar/stories/Dual.js +4 -6
  17. package/components/CheckBox/index.d.ts +1 -1
  18. package/components/Data/DataForm.js +45 -35
  19. package/components/Data/filter.js +9 -1
  20. package/components/Data/stories/Complex.js +63 -6
  21. package/components/Data/stories/Inline.js +19 -2
  22. package/components/DataFilter/DataFilter.js +11 -1
  23. package/components/DataFilters/DataFilters.js +13 -10
  24. package/components/DataTable/Body.js +16 -13
  25. package/components/DataTable/DataTable.js +4 -1
  26. package/components/DataTable/GroupedBody.js +1 -0
  27. package/components/DataTable/Header.js +1 -0
  28. package/components/DataTable/buildState.js +12 -10
  29. package/components/DataTable/stories/Controlled.js +2 -1
  30. package/components/DataTable/stories/ControlledGrouped.js +2 -1
  31. package/components/DataTable/stories/CustomThemed/Custom.js +0 -1
  32. package/components/DataTable/stories/CustomThemed/Fill.js +2 -1
  33. package/components/DataTable/stories/GroupedOnSelect.js +2 -1
  34. package/components/DataTable/stories/NoPrimary.js +0 -1
  35. package/components/DataTable/stories/OnUpdate.js +2 -1
  36. package/components/DataTable/stories/Served.js +2 -1
  37. package/components/DataTable/stories/Tunable.js +2 -1
  38. package/components/DataTable/stories/rowDetails.js +2 -1
  39. package/components/DataTableColumns/DataTableColumns.js +5 -0
  40. package/components/DataTableColumns/stories/Simple.js +4 -3
  41. package/components/DataTableGroupBy/DataTableGroupBy.js +67 -0
  42. package/components/DataTableGroupBy/README.md +2 -0
  43. package/components/DataTableGroupBy/index.d.ts +20 -0
  44. package/components/DataTableGroupBy/index.js +6 -0
  45. package/components/DataTableGroupBy/propTypes.js +17 -0
  46. package/components/DataTableGroupBy/stories/Simple.js +50 -0
  47. package/components/DataView/DataView.js +1 -1
  48. package/components/DateInput/DateInput.js +3 -2
  49. package/components/Drop/DropContainer.js +2 -2
  50. package/components/DropButton/DropButton.js +2 -2
  51. package/components/FileInput/FileInput.js +82 -53
  52. package/components/Form/Form.js +95 -44
  53. package/components/Form/stories/TriggerValidationUsingFormField.js +109 -0
  54. package/components/FormField/FormField.js +4 -3
  55. package/components/FormField/index.d.ts +1 -0
  56. package/components/FormField/propTypes.js +2 -1
  57. package/components/Grid/stories/CustomThemed/Responsive.js +0 -1
  58. package/components/InfiniteScroll/InfiniteScroll.js +1 -0
  59. package/components/Layer/Layer.js +1 -1
  60. package/components/Layer/LayerContainer.js +2 -2
  61. package/components/List/index.d.ts +2 -2
  62. package/components/MaskedInput/MaskedInput.js +3 -2
  63. package/components/MaskedInput/StyledMaskedInput.js +2 -1
  64. package/components/NameValueList/NameValueList.js +1 -1
  65. package/components/Notification/Notification.js +7 -3
  66. package/components/PageHeader/PageHeader.js +6 -4
  67. package/components/Pagination/StyledPageControl.js +3 -1
  68. package/components/Paragraph/Paragraph.js +2 -2
  69. package/components/Paragraph/stories/All.js +5 -1
  70. package/components/SelectMultiple/SelectMultiple.js +24 -20
  71. package/components/SelectMultiple/SelectMultipleContainer.js +16 -13
  72. package/components/SelectMultiple/SelectMultipleValue.js +1 -1
  73. package/components/SelectMultiple/stories/Help.js +49 -0
  74. package/components/Text/Text.js +2 -2
  75. package/components/TextInput/StyledTextInput.js +2 -1
  76. package/components/TextInput/TextInput.js +3 -2
  77. package/components/Tip/stories/HeaderActions.js +0 -1
  78. package/components/index.d.ts +1 -0
  79. package/components/index.js +6 -0
  80. package/es6/components/Accordion/Accordion.js +4 -2
  81. package/es6/components/Accordion/index.d.ts +1 -0
  82. package/es6/components/Accordion/propTypes.js +1 -0
  83. package/es6/components/AccordionPanel/AccordionPanel.js +2 -1
  84. package/es6/components/Anchor/Anchor.js +4 -3
  85. package/es6/components/Box/Box.js +14 -4
  86. package/es6/components/Box/stories/Border.js +15 -1
  87. package/es6/components/Button/Badge.js +43 -44
  88. package/es6/components/Button/BusyAnimation.js +41 -0
  89. package/es6/components/Button/Button.js +79 -17
  90. package/es6/components/Button/StyledButton.js +8 -4
  91. package/es6/components/Button/StyledButtonKind.js +13 -7
  92. package/es6/components/Button/index.d.ts +9 -0
  93. package/es6/components/Button/propTypes.js +8 -1
  94. package/es6/components/Button/stories/Busy.js +37 -0
  95. package/es6/components/Calendar/stories/Dual.js +4 -6
  96. package/es6/components/CheckBox/index.d.ts +1 -1
  97. package/es6/components/Data/DataForm.js +43 -34
  98. package/es6/components/Data/filter.js +9 -1
  99. package/es6/components/Data/stories/Complex.js +64 -7
  100. package/es6/components/Data/stories/Inline.js +20 -3
  101. package/es6/components/DataFilter/DataFilter.js +11 -1
  102. package/es6/components/DataFilters/DataFilters.js +13 -10
  103. package/es6/components/DataTable/Body.js +15 -13
  104. package/es6/components/DataTable/DataTable.js +4 -1
  105. package/es6/components/DataTable/GroupedBody.js +1 -0
  106. package/es6/components/DataTable/buildState.js +12 -10
  107. package/es6/components/DataTableColumns/DataTableColumns.js +5 -0
  108. package/es6/components/DataTableColumns/stories/Simple.js +5 -4
  109. package/es6/components/DataTableGroupBy/DataTableGroupBy.js +60 -0
  110. package/es6/components/DataTableGroupBy/README.md +2 -0
  111. package/es6/components/DataTableGroupBy/index.d.ts +20 -0
  112. package/es6/components/DataTableGroupBy/index.js +1 -0
  113. package/es6/components/DataTableGroupBy/propTypes.js +11 -0
  114. package/es6/components/DataTableGroupBy/stories/Simple.js +45 -0
  115. package/es6/components/DataView/DataView.js +1 -1
  116. package/es6/components/DateInput/DateInput.js +3 -2
  117. package/es6/components/Drop/DropContainer.js +2 -2
  118. package/es6/components/DropButton/DropButton.js +2 -2
  119. package/es6/components/FileInput/FileInput.js +83 -53
  120. package/es6/components/Form/Form.js +95 -44
  121. package/es6/components/Form/stories/TriggerValidationUsingFormField.js +102 -0
  122. package/es6/components/FormField/FormField.js +4 -3
  123. package/es6/components/FormField/index.d.ts +1 -0
  124. package/es6/components/FormField/propTypes.js +2 -1
  125. package/es6/components/InfiniteScroll/InfiniteScroll.js +1 -0
  126. package/es6/components/Layer/Layer.js +1 -1
  127. package/es6/components/Layer/LayerContainer.js +2 -2
  128. package/es6/components/List/index.d.ts +2 -2
  129. package/es6/components/MaskedInput/MaskedInput.js +4 -3
  130. package/es6/components/MaskedInput/StyledMaskedInput.js +2 -1
  131. package/es6/components/NameValueList/NameValueList.js +1 -1
  132. package/es6/components/Notification/Notification.js +7 -3
  133. package/es6/components/PageHeader/PageHeader.js +6 -4
  134. package/es6/components/Pagination/StyledPageControl.js +3 -1
  135. package/es6/components/Paragraph/Paragraph.js +2 -2
  136. package/es6/components/Paragraph/stories/All.js +5 -1
  137. package/es6/components/SelectMultiple/SelectMultiple.js +24 -20
  138. package/es6/components/SelectMultiple/SelectMultipleContainer.js +16 -13
  139. package/es6/components/SelectMultiple/SelectMultipleValue.js +1 -1
  140. package/es6/components/SelectMultiple/stories/Help.js +42 -0
  141. package/es6/components/Text/Text.js +2 -2
  142. package/es6/components/TextInput/StyledTextInput.js +2 -1
  143. package/es6/components/TextInput/TextInput.js +4 -3
  144. package/es6/components/index.d.ts +1 -0
  145. package/es6/components/index.js +1 -0
  146. package/es6/index.d.ts +1 -0
  147. package/es6/languages/default.json +15 -2
  148. package/es6/themes/base.d.ts +3 -0
  149. package/es6/themes/base.js +7 -1
  150. package/es6/utils/icon.js +7 -0
  151. package/es6/utils/index.js +1 -0
  152. package/es6/utils/styles.js +10 -0
  153. package/grommet.min.js +1 -1
  154. package/grommet.min.js.map +1 -1
  155. package/index.d.ts +1 -0
  156. package/languages/default.json +15 -2
  157. package/package.json +49 -48
  158. package/themes/base.d.ts +3 -0
  159. package/themes/base.js +7 -1
  160. package/utils/icon.js +12 -0
  161. package/utils/index.js +6 -0
  162. package/utils/styles.js +12 -1
@@ -6,7 +6,7 @@ var _react = _interopRequireWildcard(require("react"));
6
6
  var _propTypes = require("./propTypes");
7
7
  var _Box = require("../Box");
8
8
  var _AccordionContext = require("./AccordionContext");
9
- var _excluded = ["activeIndex", "animate", "children", "multiple", "onActive"];
9
+ var _excluded = ["activeIndex", "animate", "children", "level", "multiple", "onActive"];
10
10
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
11
11
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
12
12
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
@@ -19,6 +19,7 @@ var Accordion = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
19
19
  _ref$animate = _ref.animate,
20
20
  animate = _ref$animate === void 0 ? true : _ref$animate,
21
21
  children = _ref.children,
22
+ level = _ref.level,
22
23
  multiple = _ref.multiple,
23
24
  onActive = _ref.onActive,
24
25
  rest = _objectWithoutPropertiesLoose(_ref, _excluded);
@@ -55,11 +56,12 @@ var Accordion = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
55
56
  return {
56
57
  active: activeIndexes.indexOf(index) > -1,
57
58
  animate: animate,
59
+ level: level,
58
60
  onPanelChange: function onPanelChange() {
59
61
  return _onPanelChange(index);
60
62
  }
61
63
  };
62
- }, [activeIndexes, animate, multiple, onActive]);
64
+ }, [activeIndexes, animate, level, multiple, onActive]);
63
65
  return /*#__PURE__*/_react["default"].createElement(_Box.Box, _extends({
64
66
  ref: ref
65
67
  }, rest), _react.Children.toArray(children).filter(function (child) {
@@ -5,6 +5,7 @@ import { BoxProps } from '../Box/index';
5
5
  export interface AccordionProps {
6
6
  activeIndex?: number | number[];
7
7
  animate?: AnimateType;
8
+ level?: number;
8
9
  onActive?: (activeIndexes: number[]) => void;
9
10
  multiple?: boolean;
10
11
  messages?: { tabContents?: string };
@@ -12,6 +12,7 @@ if (process.env.NODE_ENV !== 'production') {
12
12
  activeIndex: _propTypes["default"].oneOfType([_propTypes["default"].number, _propTypes["default"].arrayOf(_propTypes["default"].number)]),
13
13
  animate: _propTypes["default"].bool,
14
14
  children: _propTypes["default"].node,
15
+ level: _propTypes["default"].number,
15
16
  onActive: _propTypes["default"].func,
16
17
  multiple: _propTypes["default"].bool,
17
18
  messages: _propTypes["default"].shape({
@@ -31,6 +31,7 @@ var AccordionPanel = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
31
31
  var _useContext = (0, _react.useContext)(_AccordionContext.AccordionContext),
32
32
  active = _useContext.active,
33
33
  animate = _useContext.animate,
34
+ level = _useContext.level,
34
35
  onPanelChange = _useContext.onPanelChange;
35
36
  var _useState = (0, _react.useState)(undefined),
36
37
  hover = _useState[0],
@@ -110,7 +111,7 @@ var AccordionPanel = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
110
111
  horizontal: 'xsmall'
111
112
  }
112
113
  }, /*#__PURE__*/_react["default"].createElement(_Heading.Heading, {
113
- level: theme.accordion.heading && theme.accordion.heading.level || 4,
114
+ level: level || theme.accordion.heading && theme.accordion.heading.level || 4,
114
115
  margin: theme.accordion.heading && theme.accordion.heading.margin || undefined,
115
116
  color: hover
116
117
  }, label)) : label, AccordionIcon && /*#__PURE__*/_react["default"].createElement(_Box.Box, {
@@ -61,8 +61,9 @@ var Anchor = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
61
61
  color: (0, _utils.normalizeColor)(color || ((_theme$anchor = theme.anchor) == null ? void 0 : (_theme$anchor$size = _theme$anchor.size) == null ? void 0 : (_theme$anchor$size2 = _theme$anchor$size[sizeProp || size]) == null ? void 0 : _theme$anchor$size2.color) || theme.anchor.color, theme)
62
62
  });
63
63
  }
64
- var first = reverse ? label : coloredIcon;
65
- var second = reverse ? coloredIcon : label;
64
+ var anchorIcon = (0, _utils.useSizedIcon)(coloredIcon, sizeProp || size, theme);
65
+ var first = reverse ? label : anchorIcon;
66
+ var second = reverse ? anchorIcon : label;
66
67
  return /*#__PURE__*/_react["default"].createElement(_StyledAnchor.StyledAnchor, _extends({}, rest, {
67
68
  ref: ref,
68
69
  "aria-label": ariaLabel || a11yTitle,
@@ -91,13 +91,21 @@ var Box = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
91
91
  if (focusable) return 0;
92
92
  return undefined;
93
93
  }, [focusable, tabIndex]);
94
- if ((border === 'between' || border && border.side === 'between') && !gap) {
94
+ if ((border === 'between' || border && border.side === 'between' || Array.isArray(border) && border.find(function (b) {
95
+ return b.side === 'between';
96
+ })) && !gap) {
95
97
  console.warn('Box must have a gap to use border between');
96
98
  }
97
99
  var contents = children;
98
100
  if (gap && gap !== 'none' && (!(boxOptions != null && boxOptions.cssGap || cssGap) ||
99
101
  // need this approach to show border between
100
- border === 'between' || (border == null ? void 0 : border.side) === 'between')) {
102
+ border === 'between' || (border == null ? void 0 : border.side) === 'between' || Array.isArray(border) && border.find(function (b) {
103
+ return b.side === 'between';
104
+ }))) {
105
+ // if border is an array, we need to extract the border between object
106
+ var styledBoxGapBorder = Array.isArray(border) ? border.find(function (b) {
107
+ return b.side === 'between';
108
+ }) : border;
101
109
  var boxAs = !as && tag ? tag : as;
102
110
  contents = [];
103
111
  var firstIndex;
@@ -114,7 +122,7 @@ var Box = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
114
122
  gap: gap,
115
123
  directionProp: direction,
116
124
  responsive: responsive,
117
- border: border
125
+ border: styledBoxGapBorder
118
126
  }));
119
127
  }
120
128
  }
@@ -183,7 +191,9 @@ var Box = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
183
191
  elevationProp: elevation,
184
192
  fillProp: fill,
185
193
  focus: focus,
186
- gap: ((boxOptions == null ? void 0 : boxOptions.cssGap) || cssGap) && gap && gap !== 'none' && border !== 'between' && (border == null ? void 0 : border.side) !== 'between' && gap,
194
+ gap: ((boxOptions == null ? void 0 : boxOptions.cssGap) || cssGap) && gap && gap !== 'none' && border !== 'between' && (border == null ? void 0 : border.side) !== 'between' && (!Array.isArray(border) || !border.find(function (b) {
195
+ return b.side === 'between';
196
+ })) && gap,
187
197
  kindProp: kind,
188
198
  overflowProp: overflow,
189
199
  wrapProp: wrap,
@@ -98,7 +98,21 @@ var BorderBox = function BorderBox() {
98
98
  size: 'large'
99
99
  }
100
100
  }, /*#__PURE__*/_react["default"].createElement(_grommet.Text, null, "between"), /*#__PURE__*/_react["default"].createElement(_grommet.Text, null, direction));
101
- })))
101
+ })), /*#__PURE__*/_react["default"].createElement(_grommet.Box, {
102
+ direction: "row",
103
+ gap: "small",
104
+ border: [{
105
+ side: 'between'
106
+ }, {
107
+ side: 'top'
108
+ }, {
109
+ side: 'right'
110
+ }, {
111
+ side: 'bottom'
112
+ }, {
113
+ side: 'left'
114
+ }]
115
+ }, /*#__PURE__*/_react["default"].createElement(_grommet.Text, null, "Multiple Border"), /*#__PURE__*/_react["default"].createElement(_grommet.Text, null, "With Between")))
102
116
  // </Grommet>
103
117
  );
104
118
  };
@@ -21,21 +21,13 @@ var Badge = function Badge(_ref) {
21
21
  var children = _ref.children,
22
22
  content = _ref.content;
23
23
  var theme = (0, _react.useContext)(_styledComponents.ThemeContext);
24
+ var containerRef = (0, _react.useRef)();
24
25
  var contentRef = (0, _react.useRef)();
25
26
  var stackRef = (0, _react.useRef)();
26
27
  var defaultBadgeDimension = typeof content === 'boolean' || content && content.value && typeof content.value === 'boolean' ? // empty badge should be smaller. this value was chosen as a default
27
28
  // after experimenting with various values
28
29
  (0, _utils.parseMetricToNum)(theme.button.badge.size.medium) / 2 + "px" : theme.button.badge.size.medium;
29
30
 
30
- // size should drive height, match width to height by default
31
- // allow width to grow when content is wide
32
- var _useState = (0, _react.useState)(defaultBadgeDimension),
33
- height = _useState[0],
34
- setHeight = _useState[1];
35
- var _useState2 = (0, _react.useState)(height),
36
- width = _useState2[0],
37
- setWidth = _useState2[1];
38
-
39
31
  // scale badge to fit its contents, leaving space horizontally
40
32
  // that is proportional to vertical space
41
33
  (0, _useIsomorphicLayoutEffect.useLayoutEffect)(function () {
@@ -43,26 +35,38 @@ var Badge = function Badge(_ref) {
43
35
  // can change (because pad is responsive, etc.). we want to recalculate
44
36
  // width since badge offset is reliant on its dimensions.
45
37
  var onResize = function onResize() {
46
- if (contentRef && contentRef.current) {
47
- if (typeof content === 'number' || typeof content === 'object' && content.value) {
48
- var _contentRef$current$g = contentRef.current.getBoundingClientRect(),
49
- contentHeight = _contentRef$current$g.height,
50
- contentWidth = _contentRef$current$g.width;
38
+ if (containerRef != null && containerRef.current) {
39
+ containerRef.current.style.minHeight = '';
40
+ containerRef.current.style.minWidth = '';
41
+ if (contentRef != null && contentRef.current) {
42
+ if (typeof content === 'number' || typeof content === 'object' && content.value) {
43
+ containerRef.current.style.minHeight = defaultBadgeDimension;
44
+ containerRef.current.style.minWidth = defaultBadgeDimension;
45
+ var _contentRef$current$g = contentRef.current.getBoundingClientRect(),
46
+ contentHeight = _contentRef$current$g.height,
47
+ contentWidth = _contentRef$current$g.width;
51
48
 
52
- // only adjust the width if contentHeight > 0
53
- // jest returns 0 for all getBoundingClientRect values,
54
- // so this ensures snapshots are closer to correct values
55
- if (contentHeight) {
56
- // height of content includes extra space around font from
57
- // line-height. account for this extra space with 2.5 multiplier
58
- // to add proportional horizontal space
59
- var verticalSpace = ((0, _utils.parseMetricToNum)(height) - contentHeight) * 2.5;
60
- setWidth(Math.max((0, _utils.parseMetricToNum)(width), Math.ceil(contentWidth + verticalSpace)) + "px");
49
+ // only adjust the width if contentHeight > 0
50
+ // jest returns 0 for all getBoundingClientRect values,
51
+ // so this ensures snapshots are closer to correct values
52
+ if (contentHeight) {
53
+ // height of content includes extra space around font from
54
+ // line-height. account for this extra space with 2.5 multiplier
55
+ // to add proportional horizontal space
56
+ var height = defaultBadgeDimension;
57
+ var width = defaultBadgeDimension;
58
+ var verticalSpace = ((0, _utils.parseMetricToNum)(height) - contentHeight) * 2.5;
59
+ containerRef.current.style.minHeight = height;
60
+ containerRef.current.style.minWidth = Math.max((0, _utils.parseMetricToNum)(width), Math.ceil(contentWidth + verticalSpace)) + "px";
61
+ }
62
+ } else {
63
+ // caller has provided custom JSX
64
+ containerRef.current.style.minHeight = contentRef.current.getBoundingClientRect().width;
65
+ containerRef.current.style.minWidth = contentRef.current.getBoundingClientRect().height;
61
66
  }
62
67
  } else {
63
- // caller has provided custom JSX
64
- setWidth(contentRef.current.getBoundingClientRect().width + "px");
65
- setHeight(contentRef.current.getBoundingClientRect().height + "px");
68
+ containerRef.current.style.minHeight = defaultBadgeDimension;
69
+ containerRef.current.style.minWidth = defaultBadgeDimension;
66
70
  }
67
71
  }
68
72
  };
@@ -71,26 +75,26 @@ var Badge = function Badge(_ref) {
71
75
  return function () {
72
76
  window.removeEventListener('resize', onResize);
73
77
  };
74
- }, [content, height, width]);
78
+ }, [content, defaultBadgeDimension]);
75
79
 
76
80
  // offset the badge so it overlaps content
77
81
  (0, _useIsomorphicLayoutEffect.useLayoutEffect)(function () {
78
- if (stackRef && stackRef.current) {
82
+ if (stackRef != null && stackRef.current) {
79
83
  // when badge has content, offset should be 50%.
80
84
  // when badge is empty, offset by a smaller amount to keep the badge
81
85
  // closer to the content. this value was chosen as a reasonable default
82
86
  // after testing with various grommet icons.
83
- var divisor = typeof content === 'boolean' || content && content.value === true ? 3.5 : 2;
84
- var offset = {
85
- right: "-" + Math.round((0, _utils.parseMetricToNum)(width) / divisor) + "px",
86
- top: "-" + Math.round((0, _utils.parseMetricToNum)(height) / divisor) + "px"
87
- };
87
+ var offset = typeof content === 'boolean' || content && content.value === true ? '25%' : '50%';
88
+
88
89
  // second child of Stack is the div that receives absolute positioning
89
90
  // and contains our badge content
90
- stackRef.current.children[1].style.top = offset.top;
91
- stackRef.current.children[1].style.right = offset.right;
91
+ stackRef.current.children[1].style.top = 0;
92
+ stackRef.current.children[1].style.right = 0;
93
+ // eslint-disable-next-line max-len
94
+ stackRef.current.children[1].style.transform = "translate(" + offset + ", -" + offset + ")";
95
+ stackRef.current.children[1].style.transformOrigin = '100% 0%';
92
96
  }
93
- }, [content, height, width]);
97
+ }, [content]);
94
98
  var value;
95
99
  if (typeof content === 'number') value = content;else if (typeof content === 'object') value = content.value;
96
100
  var badge;
@@ -105,18 +109,13 @@ var Badge = function Badge(_ref) {
105
109
  }, value > max ? max + "+" : value);
106
110
  }
107
111
  badge = /*#__PURE__*/_react["default"].createElement(StyledBadgeContainer, {
112
+ ref: containerRef,
108
113
  align: "center",
109
114
  background: content.background || theme.button.badge.container.background,
110
115
  flex: false,
111
- height: {
112
- min: height
113
- },
114
116
  justify: "center",
115
117
  round: true,
116
- pad: !(typeof value === 'boolean' || typeof content === 'boolean') ? theme.button.badge.container.pad : undefined,
117
- width: {
118
- min: width
119
- }
118
+ pad: !(typeof value === 'boolean' || typeof content === 'boolean') ? theme.button.badge.container.pad : undefined
120
119
  }, badge);
121
120
  // caller has provided their own JSX and we will just render that
122
121
  } else badge = /*#__PURE__*/_react["default"].createElement(_Box.Box, {
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.StyledBusyContents = exports.GrowCheckmark = exports.EllipsisAnimation = void 0;
5
+ var _react = _interopRequireDefault(require("react"));
6
+ var _styledComponents = _interopRequireWildcard(require("styled-components"));
7
+ var _Checkmark = require("grommet-icons/icons/Checkmark");
8
+ var _Box = require("../Box");
9
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
10
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
11
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
12
+ var bounceDelay = (0, _styledComponents.keyframes)(["0%,80%,100%{transform:scale(0.4);}40%{transform:scale(0.8);}"]);
13
+ var bounceDelayRule = (0, _styledComponents.css)(["animation:", " 1.4s infinite ease-in-out both;"], bounceDelay);
14
+ var Dot = (0, _styledComponents["default"])(_Box.Box).withConfig({
15
+ displayName: "BusyAnimation__Dot",
16
+ componentId: "sc-feuivs-0"
17
+ })(["background-color:currentColor;width:8px;height:8px;border-radius:100%;display:inline-block;", " ", ""], bounceDelayRule, function (props) {
18
+ return props.delay && "animation-delay: " + props.delay + ";";
19
+ });
20
+ var EllipsisAnimation = function EllipsisAnimation() {
21
+ return /*#__PURE__*/_react["default"].createElement(_Box.Box, {
22
+ style: {
23
+ position: 'absolute'
24
+ },
25
+ fill: true,
26
+ alignContent: "center",
27
+ justify: "center"
28
+ }, /*#__PURE__*/_react["default"].createElement(_Box.Box, {
29
+ alignSelf: "center",
30
+ direction: "row",
31
+ gap: "small"
32
+ }, /*#__PURE__*/_react["default"].createElement(Dot, {
33
+ delay: "-0.32s"
34
+ }), /*#__PURE__*/_react["default"].createElement(Dot, {
35
+ delay: "-0.16s"
36
+ }), /*#__PURE__*/_react["default"].createElement(Dot, null)));
37
+ };
38
+ exports.EllipsisAnimation = EllipsisAnimation;
39
+ var grow = (0, _styledComponents.keyframes)(["0%{opacity:0;transform:scale(.3);}20%{opacity:1;transform:scale(1.15);}30%{transform:scale(.9);}45%{transform:scale(1.05);}55%{transform:scale(1);}100%{transform:scale(1);}"]);
40
+ var GrowCheckmark = (0, _styledComponents["default"])(_Checkmark.Checkmark).withConfig({
41
+ displayName: "BusyAnimation__GrowCheckmark",
42
+ componentId: "sc-feuivs-1"
43
+ })(["position:absolute;align-self:center;animation:", " 0.9s ease-in-out;"], grow);
44
+ exports.GrowCheckmark = GrowCheckmark;
45
+ var StyledBusyContents = _styledComponents["default"].div.withConfig({
46
+ displayName: "BusyAnimation__StyledBusyContents",
47
+ componentId: "sc-feuivs-2"
48
+ })(["opacity:", ";}"], function (props) {
49
+ return props.animating ? 0 : 1;
50
+ });
51
+ exports.StyledBusyContents = StyledBusyContents;
@@ -3,10 +3,12 @@
3
3
  exports.__esModule = true;
4
4
  exports.Button = void 0;
5
5
  var _react = _interopRequireWildcard(require("react"));
6
- var _styledComponents = require("styled-components");
6
+ var _styledComponents = _interopRequireWildcard(require("styled-components"));
7
7
  var _utils = require("../../utils");
8
8
  var _defaultProps = require("../../default-props");
9
9
  var _propTypes = require("./propTypes");
10
+ var _AnnounceContext = require("../../contexts/AnnounceContext");
11
+ var _MessageContext = require("../../contexts/MessageContext");
10
12
  var _Box = require("../Box");
11
13
  var _Tip = require("../Tip");
12
14
  var _Badge = require("./Badge");
@@ -14,11 +16,17 @@ var _StyledButton = require("./StyledButton");
14
16
  var _StyledButtonKind = require("./StyledButtonKind");
15
17
  var _AnalyticsContext = require("../../contexts/AnalyticsContext");
16
18
  var _Skeleton = require("../Skeleton");
17
- var _excluded = ["active", "align", "aria-label", "badge", "color", "children", "disabled", "icon", "focusIndicator", "gap", "fill", "href", "justify", "kind", "label", "onBlur", "onClick", "onFocus", "onMouseOut", "onMouseOver", "plain", "primary", "reverse", "secondary", "selected", "size", "tip", "type", "a11yTitle", "as"];
19
+ var _BusyAnimation = require("./BusyAnimation");
20
+ var _excluded = ["active", "align", "aria-label", "badge", "busy", "color", "children", "disabled", "icon", "focusIndicator", "gap", "fill", "href", "justify", "kind", "label", "messages", "onBlur", "onClick", "onFocus", "onMouseOut", "onMouseOver", "pad", "plain", "primary", "reverse", "secondary", "selected", "size", "success", "tip", "type", "a11yTitle", "as"];
18
21
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
19
22
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
20
23
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
21
24
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
25
+ var RelativeBox = (0, _styledComponents["default"])(_Box.Box).withConfig({
26
+ displayName: "Button__RelativeBox",
27
+ componentId: "sc-zuqsuw-0"
28
+ })(["position:relative;"]);
29
+
22
30
  // We have two Styled* components to separate
23
31
  // the newer default|primary|secondary approach,
24
32
  // which we use the term "kind" to refer to,
@@ -137,12 +145,13 @@ var getPropertyColor = function getPropertyColor(property, paths, theme, kind, p
137
145
  return result;
138
146
  };
139
147
  var Button = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
140
- var _theme$button$kind;
148
+ var _theme$button$kind, _theme$button2, _theme$button2$badge;
141
149
  var active = _ref.active,
142
150
  _ref$align = _ref.align,
143
151
  align = _ref$align === void 0 ? 'center' : _ref$align,
144
152
  ariaLabel = _ref['aria-label'],
145
153
  badgeProp = _ref.badge,
154
+ busy = _ref.busy,
146
155
  color = _ref.color,
147
156
  children = _ref.children,
148
157
  disabled = _ref.disabled,
@@ -155,17 +164,20 @@ var Button = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
155
164
  justify = _ref.justify,
156
165
  kindArg = _ref.kind,
157
166
  label = _ref.label,
167
+ messages = _ref.messages,
158
168
  _onBlur = _ref.onBlur,
159
169
  onClickProp = _ref.onClick,
160
170
  _onFocus = _ref.onFocus,
161
171
  onMouseOut = _ref.onMouseOut,
162
172
  onMouseOver = _ref.onMouseOver,
173
+ pad = _ref.pad,
163
174
  plain = _ref.plain,
164
175
  primary = _ref.primary,
165
176
  reverseProp = _ref.reverse,
166
177
  secondary = _ref.secondary,
167
178
  selected = _ref.selected,
168
179
  sizeProp = _ref.size,
180
+ success = _ref.success,
169
181
  tip = _ref.tip,
170
182
  _ref$type = _ref.type,
171
183
  type = _ref$type === void 0 ? 'button' : _ref$type,
@@ -180,6 +192,21 @@ var Button = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
180
192
  var _useState2 = (0, _react.useState)(false),
181
193
  hover = _useState2[0],
182
194
  setHover = _useState2[1];
195
+ var announce = (0, _react.useContext)(_AnnounceContext.AnnounceContext);
196
+ var _useContext = (0, _react.useContext)(_MessageContext.MessageContext),
197
+ format = _useContext.format;
198
+ if (busy && success) {
199
+ console.warn('Button cannot have both busy and success set to true.');
200
+ }
201
+ (0, _react.useEffect)(function () {
202
+ if (busy) announce(format({
203
+ id: 'button.busy',
204
+ messages: messages
205
+ }));else if (success) announce(format({
206
+ id: 'button.success',
207
+ messages: messages
208
+ }));
209
+ }, [announce, busy, format, messages, success]);
183
210
  if ((icon || label) && children) {
184
211
  console.warn('Button should not have children if icon or label is provided');
185
212
  }
@@ -250,14 +277,6 @@ var Button = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
250
277
  }
251
278
  return result;
252
279
  }, [active, disabled, kind, kindObj, plain, selected]);
253
- if (skeleton) {
254
- var _theme$text, _theme$button$size;
255
- return /*#__PURE__*/_react["default"].createElement(_Skeleton.Skeleton, _extends({
256
- ref: ref,
257
- height: ((_theme$text = theme.text[size || 'medium']) == null ? void 0 : _theme$text.height) || size,
258
- a11yTitle: a11yTitle
259
- }, rest, (_theme$button$size = theme.button.size) == null ? void 0 : _theme$button$size[size || 'medium'], theme.button.skeleton));
260
- }
261
280
 
262
281
  // only used when theme does not have button.default
263
282
  var isDarkBackground = function isDarkBackground() {
@@ -299,6 +318,15 @@ var Button = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
299
318
  color: _iconColor
300
319
  });
301
320
  }
321
+ buttonIcon = (0, _utils.useSizedIcon)(buttonIcon, size, theme);
322
+ if (skeleton) {
323
+ var _theme$text, _theme$button$size;
324
+ return /*#__PURE__*/_react["default"].createElement(_Skeleton.Skeleton, _extends({
325
+ ref: ref,
326
+ height: ((_theme$text = theme.text[size || 'medium']) == null ? void 0 : _theme$text.height) || size,
327
+ a11yTitle: a11yTitle
328
+ }, rest, (_theme$button$size = theme.button.size) == null ? void 0 : _theme$button$size[size || 'medium'], theme.button.skeleton));
329
+ }
302
330
  var reverse = reverseProp != null ? reverseProp : (_theme$button$kind = theme.button[kind]) == null ? void 0 : _theme$button$kind.reverse;
303
331
  var domTag = !as && href ? 'a' : as;
304
332
  var first = reverse ? label : buttonIcon;
@@ -329,12 +357,42 @@ var Button = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
329
357
  // (!kind && icon && !label) is necessary because for old button logic,
330
358
  // if button has icon but not label, it will be considered "plain",
331
359
  // so no border or background will be applied
332
- var innerBadge = !background && !border || !kind && icon && !label;
360
+ var innerBadge = ((_theme$button2 = theme.button) == null ? void 0 : (_theme$button2$badge = _theme$button2.badge) == null ? void 0 : _theme$button2$badge.align) !== 'container' && (!background && !border || !kind && icon && !label);
333
361
  if (badgeProp && innerBadge) {
334
362
  contents = /*#__PURE__*/_react["default"].createElement(_Badge.Badge, {
335
363
  content: badgeProp
336
364
  }, contents);
337
365
  }
366
+ if (busy || success) {
367
+ // match what the label will use
368
+ var animationColor;
369
+ if (kind) {
370
+ if (!plain) {
371
+ animationColor = hover && getIconColor(themePaths.hover, theme) || getIconColor(themePaths.base, theme, color, kind);
372
+ }
373
+ } else if (primary) {
374
+ animationColor = theme.global.colors.text[isDarkBackground() ? 'dark' : 'light'];
375
+ }
376
+ contents =
377
+ /*#__PURE__*/
378
+ // position relative is necessary to have the animation
379
+ // display over the button content
380
+ _react["default"].createElement(RelativeBox, {
381
+ flex: false
382
+ }, busy && /*#__PURE__*/_react["default"].createElement(_BusyAnimation.EllipsisAnimation, null), success && /*#__PURE__*/_react["default"].createElement(_Box.Box, {
383
+ style: {
384
+ position: 'absolute'
385
+ },
386
+ fill: true,
387
+ alignContent: "center",
388
+ justify: "center"
389
+ }, /*#__PURE__*/_react["default"].createElement(_BusyAnimation.GrowCheckmark, {
390
+ color: animationColor,
391
+ "aria-hidden": true
392
+ })), /*#__PURE__*/_react["default"].createElement(_BusyAnimation.StyledBusyContents, {
393
+ animating: busy || success
394
+ }, contents));
395
+ }
338
396
  var styledButtonResult;
339
397
  if (kind) {
340
398
  styledButtonResult = /*#__PURE__*/_react["default"].createElement(_StyledButtonKind.StyledButtonKind, _extends({}, rest, {
@@ -343,6 +401,7 @@ var Button = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
343
401
  active: active,
344
402
  align: align,
345
403
  "aria-label": ariaLabel || a11yTitle,
404
+ busy: busy,
346
405
  badge: badgeProp,
347
406
  colorValue: color,
348
407
  disabled: disabled,
@@ -356,7 +415,7 @@ var Button = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
356
415
  href: href,
357
416
  kind: kind,
358
417
  themePaths: themePaths,
359
- onClick: onClick,
418
+ onClick: !busy && !success ? onClick : undefined,
360
419
  onFocus: function onFocus(event) {
361
420
  setFocus(true);
362
421
  if (_onFocus) _onFocus(event);
@@ -367,9 +426,11 @@ var Button = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
367
426
  },
368
427
  onMouseOver: onMouseOverButton,
369
428
  onMouseOut: onMouseOutButton,
429
+ pad: pad,
370
430
  plain: plain || _react.Children.count(children) > 0,
371
431
  primary: primary,
372
432
  sizeProp: size,
433
+ success: success,
373
434
  type: !href ? type : undefined
374
435
  }), contents);
375
436
  } else {
@@ -377,6 +438,7 @@ var Button = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
377
438
  as: domTag,
378
439
  ref: ref,
379
440
  "aria-label": ariaLabel || a11yTitle,
441
+ busy: busy,
380
442
  colorValue: color,
381
443
  active: active,
382
444
  selected: selected,
@@ -390,7 +452,7 @@ var Button = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
390
452
  href: href,
391
453
  kind: kind,
392
454
  themePaths: themePaths,
393
- onClick: onClick,
455
+ onClick: !busy && !success ? onClick : undefined,
394
456
  onFocus: function onFocus(event) {
395
457
  setFocus(true);
396
458
  if (_onFocus) _onFocus(event);
@@ -401,10 +463,11 @@ var Button = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
401
463
  },
402
464
  onMouseOver: onMouseOverButton,
403
465
  onMouseOut: onMouseOutButton,
404
- pad: !plain,
466
+ pad: pad || !plain,
405
467
  plain: typeof plain !== 'undefined' ? plain : _react.Children.count(children) > 0 || icon && !label,
406
468
  primary: primary,
407
469
  sizeProp: size,
470
+ success: success,
408
471
  type: !href ? type : undefined
409
472
  }), contents);
410
473
  }
@@ -77,14 +77,14 @@ var disabledButtonStyle = function disabledButtonStyle(props) {
77
77
  var StyledButton = _styledComponents["default"].button.withConfig({
78
78
  displayName: "StyledButton",
79
79
  componentId: "sc-323bzc-0"
80
- })(["display:inline-block;box-sizing:border-box;cursor:pointer;font:inherit;text-decoration:none;margin:0;background:transparent;overflow:visible;text-transform:none;", " ", " ", " ", " ", " ", " ", " &:focus{", "}&:focus:not(:focus-visible){", "}", " ", " ", " ", " ", ""], _utils.genericStyles, function (props) {
80
+ })(["display:inline-block;box-sizing:border-box;cursor:pointer;font:inherit;text-decoration:none;margin:0;background:transparent;overflow:visible;text-transform:none;", " ", " ", " ", " ", " ", " ", " &:focus{", "}&:focus:not(:focus-visible){", "}", " ", " ", " ", " ", " ", " ", ""], _utils.genericStyles, function (props) {
81
81
  return props.plain && plainStyle(props);
82
82
  }, function (props) {
83
83
  return !props.plain && basicStyle(props);
84
84
  }, function (props) {
85
85
  return props.primary && primaryStyle(props);
86
86
  }, function (props) {
87
- return !props.disabled && !props.selected && !props.focus && hoverStyle;
87
+ return !props.disabled && !props.selected && !props.focus && !props.busy && !props.success && hoverStyle;
88
88
  }, function (props) {
89
89
  return !props.disabled && props.active && activeButtonStyle(props);
90
90
  }, function (props) {
@@ -98,9 +98,13 @@ var StyledButton = _styledComponents["default"].button.withConfig({
98
98
  }, function (props) {
99
99
  return props.hasIcon && !props.hasLabel && "\n line-height: 0;\n ";
100
100
  }, function (props) {
101
- return props.pad && props.hasIcon && !props.hasLabel && "\n padding: " + props.theme.global.edgeSize.small + ";\n ";
101
+ return props.pad === true && props.hasIcon && !props.hasLabel && "\n padding: " + props.theme.global.edgeSize.small + ";\n ";
102
+ }, function (props) {
103
+ return !props.plain && props.pad && (0, _utils.edgeStyle)('padding', props.pad, false, undefined, props.theme);
102
104
  }, function (props) {
103
105
  return props.theme.button && props.theme.button.extend;
106
+ }, function (props) {
107
+ return (props.busy || props.success) && "\n cursor: default;\n ";
104
108
  });
105
109
  exports.StyledButton = StyledButton;
106
110
  StyledButton.defaultProps = {};