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
@@ -93,7 +93,21 @@ export var BorderBox = function BorderBox() {
93
93
  size: 'large'
94
94
  }
95
95
  }, /*#__PURE__*/React.createElement(Text, null, "between"), /*#__PURE__*/React.createElement(Text, null, direction));
96
- })))
96
+ })), /*#__PURE__*/React.createElement(Box, {
97
+ direction: "row",
98
+ gap: "small",
99
+ border: [{
100
+ side: 'between'
101
+ }, {
102
+ side: 'top'
103
+ }, {
104
+ side: 'right'
105
+ }, {
106
+ side: 'bottom'
107
+ }, {
108
+ side: 'left'
109
+ }]
110
+ }, /*#__PURE__*/React.createElement(Text, null, "Multiple Border"), /*#__PURE__*/React.createElement(Text, null, "With Between")))
97
111
  // </Grommet>
98
112
  );
99
113
  };
@@ -1,4 +1,4 @@
1
- import React, { useContext, useRef, useState } from 'react';
1
+ import React, { useContext, useRef } from 'react';
2
2
  import styled, { ThemeContext } from 'styled-components';
3
3
  import { parseMetricToNum } from '../../utils';
4
4
  import { useLayoutEffect } from '../../utils/use-isomorphic-layout-effect';
@@ -15,21 +15,13 @@ export var Badge = function Badge(_ref) {
15
15
  var children = _ref.children,
16
16
  content = _ref.content;
17
17
  var theme = useContext(ThemeContext);
18
+ var containerRef = useRef();
18
19
  var contentRef = useRef();
19
20
  var stackRef = useRef();
20
21
  var defaultBadgeDimension = typeof content === 'boolean' || content && content.value && typeof content.value === 'boolean' ? // empty badge should be smaller. this value was chosen as a default
21
22
  // after experimenting with various values
22
23
  parseMetricToNum(theme.button.badge.size.medium) / 2 + "px" : theme.button.badge.size.medium;
23
24
 
24
- // size should drive height, match width to height by default
25
- // allow width to grow when content is wide
26
- var _useState = useState(defaultBadgeDimension),
27
- height = _useState[0],
28
- setHeight = _useState[1];
29
- var _useState2 = useState(height),
30
- width = _useState2[0],
31
- setWidth = _useState2[1];
32
-
33
25
  // scale badge to fit its contents, leaving space horizontally
34
26
  // that is proportional to vertical space
35
27
  useLayoutEffect(function () {
@@ -37,26 +29,38 @@ export var Badge = function Badge(_ref) {
37
29
  // can change (because pad is responsive, etc.). we want to recalculate
38
30
  // width since badge offset is reliant on its dimensions.
39
31
  var onResize = function onResize() {
40
- if (contentRef && contentRef.current) {
41
- if (typeof content === 'number' || typeof content === 'object' && content.value) {
42
- var _contentRef$current$g = contentRef.current.getBoundingClientRect(),
43
- contentHeight = _contentRef$current$g.height,
44
- contentWidth = _contentRef$current$g.width;
32
+ if (containerRef != null && containerRef.current) {
33
+ containerRef.current.style.minHeight = '';
34
+ containerRef.current.style.minWidth = '';
35
+ if (contentRef != null && contentRef.current) {
36
+ if (typeof content === 'number' || typeof content === 'object' && content.value) {
37
+ containerRef.current.style.minHeight = defaultBadgeDimension;
38
+ containerRef.current.style.minWidth = defaultBadgeDimension;
39
+ var _contentRef$current$g = contentRef.current.getBoundingClientRect(),
40
+ contentHeight = _contentRef$current$g.height,
41
+ contentWidth = _contentRef$current$g.width;
45
42
 
46
- // only adjust the width if contentHeight > 0
47
- // jest returns 0 for all getBoundingClientRect values,
48
- // so this ensures snapshots are closer to correct values
49
- if (contentHeight) {
50
- // height of content includes extra space around font from
51
- // line-height. account for this extra space with 2.5 multiplier
52
- // to add proportional horizontal space
53
- var verticalSpace = (parseMetricToNum(height) - contentHeight) * 2.5;
54
- setWidth(Math.max(parseMetricToNum(width), Math.ceil(contentWidth + verticalSpace)) + "px");
43
+ // only adjust the width if contentHeight > 0
44
+ // jest returns 0 for all getBoundingClientRect values,
45
+ // so this ensures snapshots are closer to correct values
46
+ if (contentHeight) {
47
+ // height of content includes extra space around font from
48
+ // line-height. account for this extra space with 2.5 multiplier
49
+ // to add proportional horizontal space
50
+ var height = defaultBadgeDimension;
51
+ var width = defaultBadgeDimension;
52
+ var verticalSpace = (parseMetricToNum(height) - contentHeight) * 2.5;
53
+ containerRef.current.style.minHeight = height;
54
+ containerRef.current.style.minWidth = Math.max(parseMetricToNum(width), Math.ceil(contentWidth + verticalSpace)) + "px";
55
+ }
56
+ } else {
57
+ // caller has provided custom JSX
58
+ containerRef.current.style.minHeight = contentRef.current.getBoundingClientRect().width;
59
+ containerRef.current.style.minWidth = contentRef.current.getBoundingClientRect().height;
55
60
  }
56
61
  } else {
57
- // caller has provided custom JSX
58
- setWidth(contentRef.current.getBoundingClientRect().width + "px");
59
- setHeight(contentRef.current.getBoundingClientRect().height + "px");
62
+ containerRef.current.style.minHeight = defaultBadgeDimension;
63
+ containerRef.current.style.minWidth = defaultBadgeDimension;
60
64
  }
61
65
  }
62
66
  };
@@ -65,26 +69,26 @@ export var Badge = function Badge(_ref) {
65
69
  return function () {
66
70
  window.removeEventListener('resize', onResize);
67
71
  };
68
- }, [content, height, width]);
72
+ }, [content, defaultBadgeDimension]);
69
73
 
70
74
  // offset the badge so it overlaps content
71
75
  useLayoutEffect(function () {
72
- if (stackRef && stackRef.current) {
76
+ if (stackRef != null && stackRef.current) {
73
77
  // when badge has content, offset should be 50%.
74
78
  // when badge is empty, offset by a smaller amount to keep the badge
75
79
  // closer to the content. this value was chosen as a reasonable default
76
80
  // after testing with various grommet icons.
77
- var divisor = typeof content === 'boolean' || content && content.value === true ? 3.5 : 2;
78
- var offset = {
79
- right: "-" + Math.round(parseMetricToNum(width) / divisor) + "px",
80
- top: "-" + Math.round(parseMetricToNum(height) / divisor) + "px"
81
- };
81
+ var offset = typeof content === 'boolean' || content && content.value === true ? '25%' : '50%';
82
+
82
83
  // second child of Stack is the div that receives absolute positioning
83
84
  // and contains our badge content
84
- stackRef.current.children[1].style.top = offset.top;
85
- stackRef.current.children[1].style.right = offset.right;
85
+ stackRef.current.children[1].style.top = 0;
86
+ stackRef.current.children[1].style.right = 0;
87
+ // eslint-disable-next-line max-len
88
+ stackRef.current.children[1].style.transform = "translate(" + offset + ", -" + offset + ")";
89
+ stackRef.current.children[1].style.transformOrigin = '100% 0%';
86
90
  }
87
- }, [content, height, width]);
91
+ }, [content]);
88
92
  var value;
89
93
  if (typeof content === 'number') value = content;else if (typeof content === 'object') value = content.value;
90
94
  var badge;
@@ -99,18 +103,13 @@ export var Badge = function Badge(_ref) {
99
103
  }, value > max ? max + "+" : value);
100
104
  }
101
105
  badge = /*#__PURE__*/React.createElement(StyledBadgeContainer, {
106
+ ref: containerRef,
102
107
  align: "center",
103
108
  background: content.background || theme.button.badge.container.background,
104
109
  flex: false,
105
- height: {
106
- min: height
107
- },
108
110
  justify: "center",
109
111
  round: true,
110
- pad: !(typeof value === 'boolean' || typeof content === 'boolean') ? theme.button.badge.container.pad : undefined,
111
- width: {
112
- min: width
113
- }
112
+ pad: !(typeof value === 'boolean' || typeof content === 'boolean') ? theme.button.badge.container.pad : undefined
114
113
  }, badge);
115
114
  // caller has provided their own JSX and we will just render that
116
115
  } else badge = /*#__PURE__*/React.createElement(Box, {
@@ -0,0 +1,41 @@
1
+ import React from 'react';
2
+ import styled, { css, keyframes } from 'styled-components';
3
+ import { Checkmark } from 'grommet-icons/icons/Checkmark';
4
+ import { Box } from '../Box';
5
+ var bounceDelay = keyframes(["0%,80%,100%{transform:scale(0.4);}40%{transform:scale(0.8);}"]);
6
+ var bounceDelayRule = css(["animation:", " 1.4s infinite ease-in-out both;"], bounceDelay);
7
+ var Dot = styled(Box).withConfig({
8
+ displayName: "BusyAnimation__Dot",
9
+ componentId: "sc-feuivs-0"
10
+ })(["background-color:currentColor;width:8px;height:8px;border-radius:100%;display:inline-block;", " ", ""], bounceDelayRule, function (props) {
11
+ return props.delay && "animation-delay: " + props.delay + ";";
12
+ });
13
+ export var EllipsisAnimation = function EllipsisAnimation() {
14
+ return /*#__PURE__*/React.createElement(Box, {
15
+ style: {
16
+ position: 'absolute'
17
+ },
18
+ fill: true,
19
+ alignContent: "center",
20
+ justify: "center"
21
+ }, /*#__PURE__*/React.createElement(Box, {
22
+ alignSelf: "center",
23
+ direction: "row",
24
+ gap: "small"
25
+ }, /*#__PURE__*/React.createElement(Dot, {
26
+ delay: "-0.32s"
27
+ }), /*#__PURE__*/React.createElement(Dot, {
28
+ delay: "-0.16s"
29
+ }), /*#__PURE__*/React.createElement(Dot, null)));
30
+ };
31
+ var grow = 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);}"]);
32
+ export var GrowCheckmark = styled(Checkmark).withConfig({
33
+ displayName: "BusyAnimation__GrowCheckmark",
34
+ componentId: "sc-feuivs-1"
35
+ })(["position:absolute;align-self:center;animation:", " 0.9s ease-in-out;"], grow);
36
+ export var StyledBusyContents = styled.div.withConfig({
37
+ displayName: "BusyAnimation__StyledBusyContents",
38
+ componentId: "sc-feuivs-2"
39
+ })(["opacity:", ";}"], function (props) {
40
+ return props.animating ? 0 : 1;
41
+ });
@@ -1,11 +1,13 @@
1
- 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"];
1
+ 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"];
2
2
  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); }
3
3
  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; }
4
- import React, { cloneElement, Children, forwardRef, useContext, useMemo, useState, useCallback } from 'react';
5
- import { ThemeContext } from 'styled-components';
6
- import { backgroundAndTextColors, colorIsDark, findButtonParent, normalizeBackground, normalizeColor } from '../../utils';
4
+ import React, { cloneElement, Children, forwardRef, useContext, useMemo, useState, useCallback, useEffect } from 'react';
5
+ import styled, { ThemeContext } from 'styled-components';
6
+ import { backgroundAndTextColors, colorIsDark, findButtonParent, useSizedIcon, normalizeBackground, normalizeColor } from '../../utils';
7
7
  import { defaultProps } from '../../default-props';
8
8
  import { ButtonPropTypes } from './propTypes';
9
+ import { AnnounceContext } from '../../contexts/AnnounceContext';
10
+ import { MessageContext } from '../../contexts/MessageContext';
9
11
  import { Box } from '../Box';
10
12
  import { Tip } from '../Tip';
11
13
  import { Badge } from './Badge';
@@ -13,6 +15,11 @@ import { StyledButton } from './StyledButton';
13
15
  import { StyledButtonKind } from './StyledButtonKind';
14
16
  import { useAnalytics } from '../../contexts/AnalyticsContext';
15
17
  import { Skeleton, useSkeleton } from '../Skeleton';
18
+ import { EllipsisAnimation, GrowCheckmark, StyledBusyContents } from './BusyAnimation';
19
+ var RelativeBox = styled(Box).withConfig({
20
+ displayName: "Button__RelativeBox",
21
+ componentId: "sc-zuqsuw-0"
22
+ })(["position:relative;"]);
16
23
 
17
24
  // We have two Styled* components to separate
18
25
  // the newer default|primary|secondary approach,
@@ -132,12 +139,13 @@ var getPropertyColor = function getPropertyColor(property, paths, theme, kind, p
132
139
  return result;
133
140
  };
134
141
  var Button = /*#__PURE__*/forwardRef(function (_ref, ref) {
135
- var _theme$button$kind;
142
+ var _theme$button$kind, _theme$button2, _theme$button2$badge;
136
143
  var active = _ref.active,
137
144
  _ref$align = _ref.align,
138
145
  align = _ref$align === void 0 ? 'center' : _ref$align,
139
146
  ariaLabel = _ref['aria-label'],
140
147
  badgeProp = _ref.badge,
148
+ busy = _ref.busy,
141
149
  color = _ref.color,
142
150
  children = _ref.children,
143
151
  disabled = _ref.disabled,
@@ -150,17 +158,20 @@ var Button = /*#__PURE__*/forwardRef(function (_ref, ref) {
150
158
  justify = _ref.justify,
151
159
  kindArg = _ref.kind,
152
160
  label = _ref.label,
161
+ messages = _ref.messages,
153
162
  _onBlur = _ref.onBlur,
154
163
  onClickProp = _ref.onClick,
155
164
  _onFocus = _ref.onFocus,
156
165
  onMouseOut = _ref.onMouseOut,
157
166
  onMouseOver = _ref.onMouseOver,
167
+ pad = _ref.pad,
158
168
  plain = _ref.plain,
159
169
  primary = _ref.primary,
160
170
  reverseProp = _ref.reverse,
161
171
  secondary = _ref.secondary,
162
172
  selected = _ref.selected,
163
173
  sizeProp = _ref.size,
174
+ success = _ref.success,
164
175
  tip = _ref.tip,
165
176
  _ref$type = _ref.type,
166
177
  type = _ref$type === void 0 ? 'button' : _ref$type,
@@ -175,6 +186,21 @@ var Button = /*#__PURE__*/forwardRef(function (_ref, ref) {
175
186
  var _useState2 = useState(false),
176
187
  hover = _useState2[0],
177
188
  setHover = _useState2[1];
189
+ var announce = useContext(AnnounceContext);
190
+ var _useContext = useContext(MessageContext),
191
+ format = _useContext.format;
192
+ if (busy && success) {
193
+ console.warn('Button cannot have both busy and success set to true.');
194
+ }
195
+ useEffect(function () {
196
+ if (busy) announce(format({
197
+ id: 'button.busy',
198
+ messages: messages
199
+ }));else if (success) announce(format({
200
+ id: 'button.success',
201
+ messages: messages
202
+ }));
203
+ }, [announce, busy, format, messages, success]);
178
204
  if ((icon || label) && children) {
179
205
  console.warn('Button should not have children if icon or label is provided');
180
206
  }
@@ -245,14 +271,6 @@ var Button = /*#__PURE__*/forwardRef(function (_ref, ref) {
245
271
  }
246
272
  return result;
247
273
  }, [active, disabled, kind, kindObj, plain, selected]);
248
- if (skeleton) {
249
- var _theme$text, _theme$button$size;
250
- return /*#__PURE__*/React.createElement(Skeleton, _extends({
251
- ref: ref,
252
- height: ((_theme$text = theme.text[size || 'medium']) == null ? void 0 : _theme$text.height) || size,
253
- a11yTitle: a11yTitle
254
- }, rest, (_theme$button$size = theme.button.size) == null ? void 0 : _theme$button$size[size || 'medium'], theme.button.skeleton));
255
- }
256
274
 
257
275
  // only used when theme does not have button.default
258
276
  var isDarkBackground = function isDarkBackground() {
@@ -294,6 +312,15 @@ var Button = /*#__PURE__*/forwardRef(function (_ref, ref) {
294
312
  color: _iconColor
295
313
  });
296
314
  }
315
+ buttonIcon = useSizedIcon(buttonIcon, size, theme);
316
+ if (skeleton) {
317
+ var _theme$text, _theme$button$size;
318
+ return /*#__PURE__*/React.createElement(Skeleton, _extends({
319
+ ref: ref,
320
+ height: ((_theme$text = theme.text[size || 'medium']) == null ? void 0 : _theme$text.height) || size,
321
+ a11yTitle: a11yTitle
322
+ }, rest, (_theme$button$size = theme.button.size) == null ? void 0 : _theme$button$size[size || 'medium'], theme.button.skeleton));
323
+ }
297
324
  var reverse = reverseProp != null ? reverseProp : (_theme$button$kind = theme.button[kind]) == null ? void 0 : _theme$button$kind.reverse;
298
325
  var domTag = !as && href ? 'a' : as;
299
326
  var first = reverse ? label : buttonIcon;
@@ -324,12 +351,42 @@ var Button = /*#__PURE__*/forwardRef(function (_ref, ref) {
324
351
  // (!kind && icon && !label) is necessary because for old button logic,
325
352
  // if button has icon but not label, it will be considered "plain",
326
353
  // so no border or background will be applied
327
- var innerBadge = !background && !border || !kind && icon && !label;
354
+ 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);
328
355
  if (badgeProp && innerBadge) {
329
356
  contents = /*#__PURE__*/React.createElement(Badge, {
330
357
  content: badgeProp
331
358
  }, contents);
332
359
  }
360
+ if (busy || success) {
361
+ // match what the label will use
362
+ var animationColor;
363
+ if (kind) {
364
+ if (!plain) {
365
+ animationColor = hover && getIconColor(themePaths.hover, theme) || getIconColor(themePaths.base, theme, color, kind);
366
+ }
367
+ } else if (primary) {
368
+ animationColor = theme.global.colors.text[isDarkBackground() ? 'dark' : 'light'];
369
+ }
370
+ contents =
371
+ /*#__PURE__*/
372
+ // position relative is necessary to have the animation
373
+ // display over the button content
374
+ React.createElement(RelativeBox, {
375
+ flex: false
376
+ }, busy && /*#__PURE__*/React.createElement(EllipsisAnimation, null), success && /*#__PURE__*/React.createElement(Box, {
377
+ style: {
378
+ position: 'absolute'
379
+ },
380
+ fill: true,
381
+ alignContent: "center",
382
+ justify: "center"
383
+ }, /*#__PURE__*/React.createElement(GrowCheckmark, {
384
+ color: animationColor,
385
+ "aria-hidden": true
386
+ })), /*#__PURE__*/React.createElement(StyledBusyContents, {
387
+ animating: busy || success
388
+ }, contents));
389
+ }
333
390
  var styledButtonResult;
334
391
  if (kind) {
335
392
  styledButtonResult = /*#__PURE__*/React.createElement(StyledButtonKind, _extends({}, rest, {
@@ -338,6 +395,7 @@ var Button = /*#__PURE__*/forwardRef(function (_ref, ref) {
338
395
  active: active,
339
396
  align: align,
340
397
  "aria-label": ariaLabel || a11yTitle,
398
+ busy: busy,
341
399
  badge: badgeProp,
342
400
  colorValue: color,
343
401
  disabled: disabled,
@@ -351,7 +409,7 @@ var Button = /*#__PURE__*/forwardRef(function (_ref, ref) {
351
409
  href: href,
352
410
  kind: kind,
353
411
  themePaths: themePaths,
354
- onClick: onClick,
412
+ onClick: !busy && !success ? onClick : undefined,
355
413
  onFocus: function onFocus(event) {
356
414
  setFocus(true);
357
415
  if (_onFocus) _onFocus(event);
@@ -362,9 +420,11 @@ var Button = /*#__PURE__*/forwardRef(function (_ref, ref) {
362
420
  },
363
421
  onMouseOver: onMouseOverButton,
364
422
  onMouseOut: onMouseOutButton,
423
+ pad: pad,
365
424
  plain: plain || Children.count(children) > 0,
366
425
  primary: primary,
367
426
  sizeProp: size,
427
+ success: success,
368
428
  type: !href ? type : undefined
369
429
  }), contents);
370
430
  } else {
@@ -372,6 +432,7 @@ var Button = /*#__PURE__*/forwardRef(function (_ref, ref) {
372
432
  as: domTag,
373
433
  ref: ref,
374
434
  "aria-label": ariaLabel || a11yTitle,
435
+ busy: busy,
375
436
  colorValue: color,
376
437
  active: active,
377
438
  selected: selected,
@@ -385,7 +446,7 @@ var Button = /*#__PURE__*/forwardRef(function (_ref, ref) {
385
446
  href: href,
386
447
  kind: kind,
387
448
  themePaths: themePaths,
388
- onClick: onClick,
449
+ onClick: !busy && !success ? onClick : undefined,
389
450
  onFocus: function onFocus(event) {
390
451
  setFocus(true);
391
452
  if (_onFocus) _onFocus(event);
@@ -396,10 +457,11 @@ var Button = /*#__PURE__*/forwardRef(function (_ref, ref) {
396
457
  },
397
458
  onMouseOver: onMouseOverButton,
398
459
  onMouseOut: onMouseOutButton,
399
- pad: !plain,
460
+ pad: pad || !plain,
400
461
  plain: typeof plain !== 'undefined' ? plain : Children.count(children) > 0 || icon && !label,
401
462
  primary: primary,
402
463
  sizeProp: size,
464
+ success: success,
403
465
  type: !href ? type : undefined
404
466
  }), contents);
405
467
  }
@@ -1,5 +1,5 @@
1
1
  import styled, { css } from 'styled-components';
2
- import { activeStyle, backgroundStyle, disabledStyle, focusStyle, unfocusStyle, genericStyles, getHoverIndicatorStyle, normalizeColor } from '../../utils';
2
+ import { activeStyle, backgroundStyle, disabledStyle, edgeStyle, focusStyle, unfocusStyle, genericStyles, getHoverIndicatorStyle, normalizeColor } from '../../utils';
3
3
  import { defaultProps } from '../../default-props';
4
4
  var radiusStyle = function radiusStyle(props) {
5
5
  // border.radius shouldn't impact an only-icon rendering.
@@ -71,14 +71,14 @@ var disabledButtonStyle = function disabledButtonStyle(props) {
71
71
  var StyledButton = styled.button.withConfig({
72
72
  displayName: "StyledButton",
73
73
  componentId: "sc-323bzc-0"
74
- })(["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){", "}", " ", " ", " ", " ", ""], genericStyles, function (props) {
74
+ })(["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){", "}", " ", " ", " ", " ", " ", " ", ""], genericStyles, function (props) {
75
75
  return props.plain && plainStyle(props);
76
76
  }, function (props) {
77
77
  return !props.plain && basicStyle(props);
78
78
  }, function (props) {
79
79
  return props.primary && primaryStyle(props);
80
80
  }, function (props) {
81
- return !props.disabled && !props.selected && !props.focus && hoverStyle;
81
+ return !props.disabled && !props.selected && !props.focus && !props.busy && !props.success && hoverStyle;
82
82
  }, function (props) {
83
83
  return !props.disabled && props.active && activeButtonStyle(props);
84
84
  }, function (props) {
@@ -92,9 +92,13 @@ var StyledButton = styled.button.withConfig({
92
92
  }, function (props) {
93
93
  return props.hasIcon && !props.hasLabel && "\n line-height: 0;\n ";
94
94
  }, function (props) {
95
- return props.pad && props.hasIcon && !props.hasLabel && "\n padding: " + props.theme.global.edgeSize.small + ";\n ";
95
+ return props.pad === true && props.hasIcon && !props.hasLabel && "\n padding: " + props.theme.global.edgeSize.small + ";\n ";
96
+ }, function (props) {
97
+ return !props.plain && props.pad && edgeStyle('padding', props.pad, false, undefined, props.theme);
96
98
  }, function (props) {
97
99
  return props.theme.button && props.theme.button.extend;
100
+ }, function (props) {
101
+ return (props.busy || props.success) && "\n cursor: default;\n ";
98
102
  });
99
103
  StyledButton.defaultProps = {};
100
104
  Object.setPrototypeOf(StyledButton.defaultProps, defaultProps);
@@ -1,5 +1,5 @@
1
1
  import styled, { css } from 'styled-components';
2
- import { activeStyle, disabledStyle, focusStyle, unfocusStyle, genericStyles, kindPartStyles, parseMetricToNum } from '../../utils';
2
+ import { activeStyle, disabledStyle, edgeStyle, focusStyle, unfocusStyle, genericStyles, kindPartStyles, parseMetricToNum } from '../../utils';
3
3
  import { defaultProps } from '../../default-props';
4
4
  var radiusStyle = function radiusStyle(props) {
5
5
  var size = props.sizeProp;
@@ -13,7 +13,7 @@ var radiusStyle = function radiusStyle(props) {
13
13
  var fontStyle = function fontStyle(props) {
14
14
  var size = props.sizeProp || 'medium';
15
15
  var data = props.theme.text[size];
16
- return css(["font-size:", ";line-height:", ";"], data.size, data.height);
16
+ return css(["font-size:", ";line-height:", ";"], data.size, props.hasIcon && !props.hasLabel ? 0 : data.height);
17
17
  };
18
18
  var padFromTheme = function padFromTheme(size, theme, themeObj, kind, iconOnly) {
19
19
  var _themeObj$size, _themeObj$size$size, _themeObj$size$size$i, _themeObj$size3, _themeObj$size3$size, _themeObj$size3$size$;
@@ -77,11 +77,13 @@ var adjustPadStyle = function adjustPadStyle(pad, width) {
77
77
 
78
78
  // build up CSS from basic to specific based on the supplied sub-object paths
79
79
  var kindStyle = function kindStyle(_ref2) {
80
- var colorValue = _ref2.colorValue,
80
+ var busy = _ref2.busy,
81
+ colorValue = _ref2.colorValue,
81
82
  hasIcon = _ref2.hasIcon,
82
83
  hasLabel = _ref2.hasLabel,
83
84
  kind = _ref2.kind,
84
85
  size = _ref2.sizeProp,
86
+ success = _ref2.success,
85
87
  themePaths = _ref2.themePaths,
86
88
  theme = _ref2.theme;
87
89
  var styles = [];
@@ -128,7 +130,7 @@ var kindStyle = function kindStyle(_ref2) {
128
130
  // padding in the hover or hover.kind itself for backward compatibility
129
131
  adjPadStyles = adjustPadStyle(pad, obj.border.width);
130
132
  }
131
- if (partStyles.length > 0) {
133
+ if (partStyles.length > 0 && !busy && !success) {
132
134
  styles.push(css(["&:hover{", " ", "}"], partStyles, adjPadStyles));
133
135
  }
134
136
  }
@@ -160,7 +162,7 @@ var fillStyle = function fillStyle(fillContainer) {
160
162
  return undefined;
161
163
  };
162
164
  var plainStyle = function plainStyle(props) {
163
- return css(["outline:none;border:none;padding:0;text-align:inherit;color:inherit;", ""], props.icon && "\n > svg {\n display: flex;\n align-self: center;\n vertical-align: middle;\n }\n ");
165
+ return css(["outline:none;border:none;padding:0;text-align:inherit;color:inherit;", " ", ""], props.icon && "\n > svg {\n display: flex;\n align-self: center;\n vertical-align: middle;\n }\n ", props.hasIcon && !props.hasLabel && "line-height: 0;");
164
166
  };
165
167
  var StyledButtonKind = styled.button.withConfig({
166
168
  // don't let kind attribute leak to DOM
@@ -171,7 +173,7 @@ var StyledButtonKind = styled.button.withConfig({
171
173
  }).withConfig({
172
174
  displayName: "StyledButtonKind",
173
175
  componentId: "sc-1vhfpnt-0"
174
- })(["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){", "}", " ", " ", ""], genericStyles, function (props) {
176
+ })(["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){", "}", " ", " ", " ", ""], genericStyles, function (props) {
175
177
  return props.plain && plainStyle(props);
176
178
  }, function (props) {
177
179
  return !props.disabled && props.active && activeStyle;
@@ -179,10 +181,12 @@ var StyledButtonKind = styled.button.withConfig({
179
181
  return !props.plain && basicStyle(props);
180
182
  }, function (props) {
181
183
  return !props.plain && kindStyle(props);
184
+ }, function (props) {
185
+ return !props.plain && props.pad && edgeStyle('padding', props.pad, false, undefined, props.theme);
182
186
  }, function (props) {
183
187
  return !props.plain && props.align && "\n text-align: " + props.align + ";\n ";
184
188
  }, function (props) {
185
- return !props.disabled && props.hoverIndicator && hoverIndicatorStyle(props);
189
+ return !props.disabled && props.hoverIndicator && !props.busy && !props.success && hoverIndicatorStyle(props);
186
190
  }, function (props) {
187
191
  return props.disabled && disabledStyle(props.theme.button.disabled.opacity);
188
192
  }, function (props) {
@@ -193,6 +197,8 @@ var StyledButtonKind = styled.button.withConfig({
193
197
  return props.fillContainer && fillStyle(props.fillContainer);
194
198
  }, function (props) {
195
199
  return props.theme.button && props.theme.button.extend;
200
+ }, function (props) {
201
+ return (props.busy || props.success) && "\n cursor: default;\n ";
196
202
  });
197
203
  StyledButtonKind.defaultProps = {};
198
204
  Object.setPrototypeOf(StyledButtonKind.defaultProps, defaultProps);
@@ -1,3 +1,4 @@
1
+ import { string } from 'prop-types';
1
2
  import * as React from 'react';
2
3
  import {
3
4
  A11yTitleType,
@@ -10,6 +11,7 @@ import {
10
11
  HoverIndicatorType,
11
12
  MarginType,
12
13
  Omit,
14
+ PadType,
13
15
  PolymorphicType,
14
16
  } from '../../utils';
15
17
 
@@ -38,6 +40,7 @@ export interface ButtonProps {
38
40
  hover: boolean;
39
41
  focus: boolean;
40
42
  }) => React.ReactNode);
43
+ busy?: boolean;
41
44
  gridArea?: GridAreaType;
42
45
  margin?: MarginType;
43
46
  active?: boolean;
@@ -60,11 +63,17 @@ export interface ButtonProps {
60
63
  icon?: JSX.Element;
61
64
  kind?: string;
62
65
  label?: React.ReactNode;
66
+ messages?: {
67
+ busy?: string;
68
+ success?: string;
69
+ };
70
+ pad?: PadType;
63
71
  plain?: boolean;
64
72
  primary?: boolean;
65
73
  reverse?: boolean;
66
74
  secondary?: boolean;
67
75
  size?: 'small' | 'medium' | 'large' | string;
76
+ success?: boolean;
68
77
  tip?: TipProps | string;
69
78
  type?: 'button' | 'reset' | 'submit';
70
79
  as?: PolymorphicType;
@@ -1,6 +1,6 @@
1
1
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
2
  import PropTypes from 'prop-types';
3
- import { backgroundPropType, genericProps, colorPropType, hoverIndicatorPropType } from '../../utils/general-prop-types';
3
+ import { backgroundPropType, genericProps, colorPropType, hoverIndicatorPropType, padPropType } from '../../utils/general-prop-types';
4
4
  var PropType = {};
5
5
  if (process.env.NODE_ENV !== 'production') {
6
6
  PropType = _extends({}, genericProps, {
@@ -12,6 +12,7 @@ if (process.env.NODE_ENV !== 'production') {
12
12
  max: PropTypes.number,
13
13
  value: PropTypes.oneOfType([PropTypes.bool, PropTypes.number])
14
14
  })]),
15
+ busy: PropTypes.bool,
15
16
  color: colorPropType,
16
17
  disabled: PropTypes.bool,
17
18
  fill: PropTypes.oneOfType([PropTypes.oneOf(['horizontal', 'vertical']), PropTypes.bool]),
@@ -22,12 +23,18 @@ if (process.env.NODE_ENV !== 'production') {
22
23
  icon: PropTypes.element,
23
24
  justify: PropTypes.oneOf(['around', 'between', 'center', 'end', 'evenly', 'start', 'stretch']),
24
25
  label: PropTypes.node,
26
+ messages: PropTypes.shape({
27
+ busy: PropTypes.string,
28
+ success: PropTypes.string
29
+ }),
25
30
  onClick: PropTypes.func,
31
+ pad: padPropType,
26
32
  plain: PropTypes.bool,
27
33
  primary: PropTypes.bool,
28
34
  reverse: PropTypes.bool,
29
35
  secondary: PropTypes.bool,
30
36
  size: PropTypes.oneOfType([PropTypes.oneOf(['small', 'medium', 'large']), PropTypes.string]),
37
+ success: PropTypes.bool,
31
38
  target: PropTypes.oneOfType([PropTypes.oneOf(['_self', '_blank', '_parent', '_top']), PropTypes.string]),
32
39
  tip: PropTypes.oneOfType([PropTypes.shape({
33
40
  content: PropTypes.oneOfType([PropTypes.node, PropTypes.string]),
@@ -0,0 +1,37 @@
1
+ import React, { useState } from 'react';
2
+ import { Box, Button } from 'grommet';
3
+ export var Busy = function Busy() {
4
+ var _useState = useState(),
5
+ busy = _useState[0],
6
+ setBusy = _useState[1];
7
+ var _useState2 = useState(),
8
+ success = _useState2[0],
9
+ setSuccess = _useState2[1];
10
+ return /*#__PURE__*/React.createElement(Box, {
11
+ align: "center",
12
+ pad: "medium"
13
+ }, /*#__PURE__*/React.createElement(Button, {
14
+ primary: true,
15
+ busy: busy,
16
+ success: success,
17
+ label: "Button Busy",
18
+ onClick: function onClick() {
19
+ setBusy(true);
20
+ setTimeout(function () {
21
+ setBusy(false);
22
+ setSuccess(true);
23
+ }, 2000);
24
+ setTimeout(function () {
25
+ setSuccess(false);
26
+ }, 4000);
27
+ }
28
+ }));
29
+ };
30
+ Busy.parameters = {
31
+ chromatic: {
32
+ disable: true
33
+ }
34
+ };
35
+ export default {
36
+ title: 'Controls/Button/Busy'
37
+ };