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.
- package/components/Accordion/Accordion.js +4 -2
- package/components/Accordion/index.d.ts +1 -0
- package/components/Accordion/propTypes.js +1 -0
- package/components/AccordionPanel/AccordionPanel.js +2 -1
- package/components/Anchor/Anchor.js +3 -2
- package/components/Box/Box.js +14 -4
- package/components/Box/stories/Border.js +15 -1
- package/components/Button/Badge.js +42 -43
- package/components/Button/BusyAnimation.js +51 -0
- package/components/Button/Button.js +78 -15
- package/components/Button/StyledButton.js +7 -3
- package/components/Button/StyledButtonKind.js +12 -6
- package/components/Button/index.d.ts +9 -0
- package/components/Button/propTypes.js +7 -0
- package/components/Button/stories/Busy.js +45 -0
- package/components/Calendar/stories/Dual.js +4 -6
- package/components/CheckBox/index.d.ts +1 -1
- package/components/Data/DataForm.js +45 -35
- package/components/Data/filter.js +9 -1
- package/components/Data/stories/Complex.js +63 -6
- package/components/Data/stories/Inline.js +19 -2
- package/components/DataFilter/DataFilter.js +11 -1
- package/components/DataFilters/DataFilters.js +13 -10
- package/components/DataTable/Body.js +16 -13
- package/components/DataTable/DataTable.js +4 -1
- package/components/DataTable/GroupedBody.js +1 -0
- package/components/DataTable/Header.js +1 -0
- package/components/DataTable/buildState.js +12 -10
- package/components/DataTable/stories/Controlled.js +2 -1
- package/components/DataTable/stories/ControlledGrouped.js +2 -1
- package/components/DataTable/stories/CustomThemed/Custom.js +0 -1
- package/components/DataTable/stories/CustomThemed/Fill.js +2 -1
- package/components/DataTable/stories/GroupedOnSelect.js +2 -1
- package/components/DataTable/stories/NoPrimary.js +0 -1
- package/components/DataTable/stories/OnUpdate.js +2 -1
- package/components/DataTable/stories/Served.js +2 -1
- package/components/DataTable/stories/Tunable.js +2 -1
- package/components/DataTable/stories/rowDetails.js +2 -1
- package/components/DataTableColumns/DataTableColumns.js +5 -0
- package/components/DataTableColumns/stories/Simple.js +4 -3
- package/components/DataTableGroupBy/DataTableGroupBy.js +67 -0
- package/components/DataTableGroupBy/README.md +2 -0
- package/components/DataTableGroupBy/index.d.ts +20 -0
- package/components/DataTableGroupBy/index.js +6 -0
- package/components/DataTableGroupBy/propTypes.js +17 -0
- package/components/DataTableGroupBy/stories/Simple.js +50 -0
- package/components/DataView/DataView.js +1 -1
- package/components/DateInput/DateInput.js +3 -2
- package/components/Drop/DropContainer.js +2 -2
- package/components/DropButton/DropButton.js +2 -2
- package/components/FileInput/FileInput.js +82 -53
- package/components/Form/Form.js +95 -44
- package/components/Form/stories/TriggerValidationUsingFormField.js +109 -0
- package/components/FormField/FormField.js +4 -3
- package/components/FormField/index.d.ts +1 -0
- package/components/FormField/propTypes.js +2 -1
- package/components/Grid/stories/CustomThemed/Responsive.js +0 -1
- package/components/InfiniteScroll/InfiniteScroll.js +1 -0
- package/components/Layer/Layer.js +1 -1
- package/components/Layer/LayerContainer.js +2 -2
- package/components/List/index.d.ts +2 -2
- package/components/MaskedInput/MaskedInput.js +3 -2
- package/components/MaskedInput/StyledMaskedInput.js +2 -1
- package/components/NameValueList/NameValueList.js +1 -1
- package/components/Notification/Notification.js +7 -3
- package/components/PageHeader/PageHeader.js +6 -4
- package/components/Pagination/StyledPageControl.js +3 -1
- package/components/Paragraph/Paragraph.js +2 -2
- package/components/Paragraph/stories/All.js +5 -1
- package/components/SelectMultiple/SelectMultiple.js +24 -20
- package/components/SelectMultiple/SelectMultipleContainer.js +16 -13
- package/components/SelectMultiple/SelectMultipleValue.js +1 -1
- package/components/SelectMultiple/stories/Help.js +49 -0
- package/components/Text/Text.js +2 -2
- package/components/TextInput/StyledTextInput.js +2 -1
- package/components/TextInput/TextInput.js +3 -2
- package/components/Tip/stories/HeaderActions.js +0 -1
- package/components/index.d.ts +1 -0
- package/components/index.js +6 -0
- package/es6/components/Accordion/Accordion.js +4 -2
- package/es6/components/Accordion/index.d.ts +1 -0
- package/es6/components/Accordion/propTypes.js +1 -0
- package/es6/components/AccordionPanel/AccordionPanel.js +2 -1
- package/es6/components/Anchor/Anchor.js +4 -3
- package/es6/components/Box/Box.js +14 -4
- package/es6/components/Box/stories/Border.js +15 -1
- package/es6/components/Button/Badge.js +43 -44
- package/es6/components/Button/BusyAnimation.js +41 -0
- package/es6/components/Button/Button.js +79 -17
- package/es6/components/Button/StyledButton.js +8 -4
- package/es6/components/Button/StyledButtonKind.js +13 -7
- package/es6/components/Button/index.d.ts +9 -0
- package/es6/components/Button/propTypes.js +8 -1
- package/es6/components/Button/stories/Busy.js +37 -0
- package/es6/components/Calendar/stories/Dual.js +4 -6
- package/es6/components/CheckBox/index.d.ts +1 -1
- package/es6/components/Data/DataForm.js +43 -34
- package/es6/components/Data/filter.js +9 -1
- package/es6/components/Data/stories/Complex.js +64 -7
- package/es6/components/Data/stories/Inline.js +20 -3
- package/es6/components/DataFilter/DataFilter.js +11 -1
- package/es6/components/DataFilters/DataFilters.js +13 -10
- package/es6/components/DataTable/Body.js +15 -13
- package/es6/components/DataTable/DataTable.js +4 -1
- package/es6/components/DataTable/GroupedBody.js +1 -0
- package/es6/components/DataTable/buildState.js +12 -10
- package/es6/components/DataTableColumns/DataTableColumns.js +5 -0
- package/es6/components/DataTableColumns/stories/Simple.js +5 -4
- package/es6/components/DataTableGroupBy/DataTableGroupBy.js +60 -0
- package/es6/components/DataTableGroupBy/README.md +2 -0
- package/es6/components/DataTableGroupBy/index.d.ts +20 -0
- package/es6/components/DataTableGroupBy/index.js +1 -0
- package/es6/components/DataTableGroupBy/propTypes.js +11 -0
- package/es6/components/DataTableGroupBy/stories/Simple.js +45 -0
- package/es6/components/DataView/DataView.js +1 -1
- package/es6/components/DateInput/DateInput.js +3 -2
- package/es6/components/Drop/DropContainer.js +2 -2
- package/es6/components/DropButton/DropButton.js +2 -2
- package/es6/components/FileInput/FileInput.js +83 -53
- package/es6/components/Form/Form.js +95 -44
- package/es6/components/Form/stories/TriggerValidationUsingFormField.js +102 -0
- package/es6/components/FormField/FormField.js +4 -3
- package/es6/components/FormField/index.d.ts +1 -0
- package/es6/components/FormField/propTypes.js +2 -1
- package/es6/components/InfiniteScroll/InfiniteScroll.js +1 -0
- package/es6/components/Layer/Layer.js +1 -1
- package/es6/components/Layer/LayerContainer.js +2 -2
- package/es6/components/List/index.d.ts +2 -2
- package/es6/components/MaskedInput/MaskedInput.js +4 -3
- package/es6/components/MaskedInput/StyledMaskedInput.js +2 -1
- package/es6/components/NameValueList/NameValueList.js +1 -1
- package/es6/components/Notification/Notification.js +7 -3
- package/es6/components/PageHeader/PageHeader.js +6 -4
- package/es6/components/Pagination/StyledPageControl.js +3 -1
- package/es6/components/Paragraph/Paragraph.js +2 -2
- package/es6/components/Paragraph/stories/All.js +5 -1
- package/es6/components/SelectMultiple/SelectMultiple.js +24 -20
- package/es6/components/SelectMultiple/SelectMultipleContainer.js +16 -13
- package/es6/components/SelectMultiple/SelectMultipleValue.js +1 -1
- package/es6/components/SelectMultiple/stories/Help.js +42 -0
- package/es6/components/Text/Text.js +2 -2
- package/es6/components/TextInput/StyledTextInput.js +2 -1
- package/es6/components/TextInput/TextInput.js +4 -3
- package/es6/components/index.d.ts +1 -0
- package/es6/components/index.js +1 -0
- package/es6/index.d.ts +1 -0
- package/es6/languages/default.json +15 -2
- package/es6/themes/base.d.ts +3 -0
- package/es6/themes/base.js +7 -1
- package/es6/utils/icon.js +7 -0
- package/es6/utils/index.js +1 -0
- package/es6/utils/styles.js +10 -0
- package/grommet.min.js +1 -1
- package/grommet.min.js.map +1 -1
- package/index.d.ts +1 -0
- package/languages/default.json +15 -2
- package/package.json +49 -48
- package/themes/base.d.ts +3 -0
- package/themes/base.js +7 -1
- package/utils/icon.js +12 -0
- package/utils/index.js +6 -0
- 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
|
|
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 (
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
58
|
-
|
|
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,
|
|
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
|
|
78
|
-
|
|
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 =
|
|
85
|
-
stackRef.current.children[1].style.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
|
|
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
|
|
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
|
+
};
|