grommet 2.31.0 → 2.32.1
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/Box/Box.js +14 -4
- package/components/Box/stories/Border.js +15 -1
- package/components/Button/BusyAnimation.js +51 -0
- package/components/Button/Button.js +64 -4
- package/components/Button/StyledButton.js +4 -2
- package/components/Button/StyledButtonKind.js +8 -4
- package/components/Button/index.d.ts +7 -0
- package/components/Button/propTypes.js +6 -0
- package/components/Button/stories/Busy.js +45 -0
- package/components/Calendar/stories/Dual.js +4 -6
- package/components/Chart/Chart.js +113 -57
- package/components/Chart/index.d.ts +3 -0
- package/components/Chart/propTypes.js +1 -0
- package/components/Chart/stories/Layout.js +6 -3
- package/components/Chart/stories/Pattern.js +1 -0
- package/components/Chart/stories/Vertical.js +41 -0
- package/components/Chart/utils.js +57 -10
- package/components/Data/Data.js +2 -1
- package/components/Data/DataForm.js +6 -2
- package/components/Data/filter.js +12 -1
- package/components/Data/stories/Complex.js +63 -6
- package/components/Data/stories/Inline.js +19 -2
- package/components/DataFilter/DataFilter.js +37 -22
- 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 +2 -1
- package/components/DataTable/Header.js +1 -0
- package/components/DataTable/buildState.js +13 -11
- 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/DateInput/DateInput.js +1 -1
- package/components/Drop/DropContainer.js +5 -4
- 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 -2
- 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/NameValueList/NameValueList.js +1 -1
- package/components/RadioButtonGroup/RadioButtonGroup.js +19 -4
- package/components/RadioButtonGroup/stories/typescript/Simple.tsx +6 -4
- package/components/SelectMultiple/SelectMultiple.js +13 -10
- package/components/SelectMultiple/SelectMultipleValue.js +1 -1
- package/components/Tip/stories/HeaderActions.js +0 -1
- package/components/index.d.ts +3 -1
- package/components/index.js +6 -0
- package/contexts/DataContext.js +2 -1
- 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/Box/Box.js +14 -4
- package/es6/components/Box/stories/Border.js +15 -1
- package/es6/components/Button/BusyAnimation.js +41 -0
- package/es6/components/Button/Button.js +64 -5
- package/es6/components/Button/StyledButton.js +4 -2
- package/es6/components/Button/StyledButtonKind.js +8 -4
- package/es6/components/Button/index.d.ts +7 -0
- package/es6/components/Button/propTypes.js +6 -0
- package/es6/components/Button/stories/Busy.js +37 -0
- package/es6/components/Calendar/stories/Dual.js +4 -6
- package/es6/components/Chart/Chart.js +113 -57
- package/es6/components/Chart/index.d.ts +3 -0
- package/es6/components/Chart/propTypes.js +1 -0
- package/es6/components/Chart/stories/Layout.js +6 -3
- package/es6/components/Chart/stories/Pattern.js +1 -0
- package/es6/components/Chart/stories/Vertical.js +35 -0
- package/es6/components/Chart/utils.js +57 -10
- package/es6/components/Data/Data.js +2 -1
- package/es6/components/Data/DataForm.js +4 -1
- package/es6/components/Data/filter.js +12 -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 +37 -22
- 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 +2 -1
- package/es6/components/DataTable/buildState.js +13 -11
- 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/DateInput/DateInput.js +1 -1
- package/es6/components/Drop/DropContainer.js +5 -4
- 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 -2
- 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/NameValueList/NameValueList.js +1 -1
- package/es6/components/RadioButtonGroup/RadioButtonGroup.js +19 -4
- package/es6/components/RadioButtonGroup/stories/typescript/Simple.tsx +6 -4
- package/es6/components/SelectMultiple/SelectMultiple.js +13 -10
- package/es6/components/SelectMultiple/SelectMultipleValue.js +1 -1
- package/es6/components/index.d.ts +3 -1
- package/es6/components/index.js +1 -0
- package/es6/contexts/DataContext.js +2 -1
- package/es6/index.d.ts +12 -0
- package/es6/index.js +2 -0
- package/es6/languages/default.json +15 -2
- package/es6/themes/base.js +1 -1
- package/es6/utils/index.d.ts +1 -1
- package/es6/utils/refs.js +1 -1
- package/grommet.min.js +1 -1
- package/grommet.min.js.map +1 -1
- package/index.d.ts +12 -0
- package/index.js +1 -0
- package/languages/default.json +15 -2
- package/package.json +46 -45
- package/themes/base.js +1 -1
- package/utils/index.d.ts +1 -1
- package/utils/refs.js +1 -1
package/components/index.d.ts
CHANGED
|
@@ -25,6 +25,7 @@ export * from './DataSort';
|
|
|
25
25
|
export * from './DataSummary';
|
|
26
26
|
export * from './DataTable';
|
|
27
27
|
export * from './DataTableColumns';
|
|
28
|
+
export * from './DataTableGroupBy';
|
|
28
29
|
export * from './DataView';
|
|
29
30
|
export * from './DateInput';
|
|
30
31
|
export * from './Diagram';
|
|
@@ -84,7 +85,8 @@ export * from './Tag';
|
|
|
84
85
|
export * from './Text';
|
|
85
86
|
export * from './TextArea';
|
|
86
87
|
export * from './TextInput';
|
|
87
|
-
export * from './Tip';
|
|
88
88
|
export * from './ThumbsRating';
|
|
89
|
+
export * from './Tip';
|
|
90
|
+
export * from './Toolbar';
|
|
89
91
|
export * from './Video';
|
|
90
92
|
export * from './WorldMap';
|
package/components/index.js
CHANGED
|
@@ -163,6 +163,12 @@ Object.keys(_DataTableColumns).forEach(function (key) {
|
|
|
163
163
|
if (key in exports && exports[key] === _DataTableColumns[key]) return;
|
|
164
164
|
exports[key] = _DataTableColumns[key];
|
|
165
165
|
});
|
|
166
|
+
var _DataTableGroupBy = require("./DataTableGroupBy");
|
|
167
|
+
Object.keys(_DataTableGroupBy).forEach(function (key) {
|
|
168
|
+
if (key === "default" || key === "__esModule") return;
|
|
169
|
+
if (key in exports && exports[key] === _DataTableGroupBy[key]) return;
|
|
170
|
+
exports[key] = _DataTableGroupBy[key];
|
|
171
|
+
});
|
|
166
172
|
var _DataView = require("./DataView");
|
|
167
173
|
Object.keys(_DataView).forEach(function (key) {
|
|
168
174
|
if (key === "default" || key === "__esModule") return;
|
package/contexts/DataContext.js
CHANGED
|
@@ -5,6 +5,7 @@ exports.DataContext = void 0;
|
|
|
5
5
|
var _react = _interopRequireDefault(require("react"));
|
|
6
6
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
7
7
|
var DataContext = /*#__PURE__*/_react["default"].createContext({
|
|
8
|
-
data: []
|
|
8
|
+
data: [],
|
|
9
|
+
addToolbarKey: function addToolbarKey() {}
|
|
9
10
|
});
|
|
10
11
|
exports.DataContext = DataContext;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var _excluded = ["activeIndex", "animate", "children", "multiple", "onActive"];
|
|
1
|
+
var _excluded = ["activeIndex", "animate", "children", "level", "multiple", "onActive"];
|
|
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
4
|
import React, { Children, forwardRef, useCallback, useState } from 'react';
|
|
@@ -13,6 +13,7 @@ var Accordion = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
13
13
|
_ref$animate = _ref.animate,
|
|
14
14
|
animate = _ref$animate === void 0 ? true : _ref$animate,
|
|
15
15
|
children = _ref.children,
|
|
16
|
+
level = _ref.level,
|
|
16
17
|
multiple = _ref.multiple,
|
|
17
18
|
onActive = _ref.onActive,
|
|
18
19
|
rest = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
@@ -49,11 +50,12 @@ var Accordion = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
49
50
|
return {
|
|
50
51
|
active: activeIndexes.indexOf(index) > -1,
|
|
51
52
|
animate: animate,
|
|
53
|
+
level: level,
|
|
52
54
|
onPanelChange: function onPanelChange() {
|
|
53
55
|
return _onPanelChange(index);
|
|
54
56
|
}
|
|
55
57
|
};
|
|
56
|
-
}, [activeIndexes, animate, multiple, onActive]);
|
|
58
|
+
}, [activeIndexes, animate, level, multiple, onActive]);
|
|
57
59
|
return /*#__PURE__*/React.createElement(Box, _extends({
|
|
58
60
|
ref: ref
|
|
59
61
|
}, rest), Children.toArray(children).filter(function (child) {
|
|
@@ -7,6 +7,7 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
7
7
|
activeIndex: PropTypes.oneOfType([PropTypes.number, PropTypes.arrayOf(PropTypes.number)]),
|
|
8
8
|
animate: PropTypes.bool,
|
|
9
9
|
children: PropTypes.node,
|
|
10
|
+
level: PropTypes.number,
|
|
10
11
|
onActive: PropTypes.func,
|
|
11
12
|
multiple: PropTypes.bool,
|
|
12
13
|
messages: PropTypes.shape({
|
|
@@ -25,6 +25,7 @@ var AccordionPanel = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
25
25
|
var _useContext = useContext(AccordionContext),
|
|
26
26
|
active = _useContext.active,
|
|
27
27
|
animate = _useContext.animate,
|
|
28
|
+
level = _useContext.level,
|
|
28
29
|
onPanelChange = _useContext.onPanelChange;
|
|
29
30
|
var _useState = useState(undefined),
|
|
30
31
|
hover = _useState[0],
|
|
@@ -104,7 +105,7 @@ var AccordionPanel = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
104
105
|
horizontal: 'xsmall'
|
|
105
106
|
}
|
|
106
107
|
}, /*#__PURE__*/React.createElement(Heading, {
|
|
107
|
-
level: theme.accordion.heading && theme.accordion.heading.level || 4,
|
|
108
|
+
level: level || theme.accordion.heading && theme.accordion.heading.level || 4,
|
|
108
109
|
margin: theme.accordion.heading && theme.accordion.heading.margin || undefined,
|
|
109
110
|
color: hover
|
|
110
111
|
}, label)) : label, AccordionIcon && /*#__PURE__*/React.createElement(Box, {
|
|
@@ -85,13 +85,21 @@ var Box = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
85
85
|
if (focusable) return 0;
|
|
86
86
|
return undefined;
|
|
87
87
|
}, [focusable, tabIndex]);
|
|
88
|
-
if ((border === 'between' || border && border.side === 'between') &&
|
|
88
|
+
if ((border === 'between' || border && border.side === 'between' || Array.isArray(border) && border.find(function (b) {
|
|
89
|
+
return b.side === 'between';
|
|
90
|
+
})) && !gap) {
|
|
89
91
|
console.warn('Box must have a gap to use border between');
|
|
90
92
|
}
|
|
91
93
|
var contents = children;
|
|
92
94
|
if (gap && gap !== 'none' && (!(boxOptions != null && boxOptions.cssGap || cssGap) ||
|
|
93
95
|
// need this approach to show border between
|
|
94
|
-
border === 'between' || (border == null ? void 0 : border.side) === 'between')) {
|
|
96
|
+
border === 'between' || (border == null ? void 0 : border.side) === 'between' || Array.isArray(border) && border.find(function (b) {
|
|
97
|
+
return b.side === 'between';
|
|
98
|
+
}))) {
|
|
99
|
+
// if border is an array, we need to extract the border between object
|
|
100
|
+
var styledBoxGapBorder = Array.isArray(border) ? border.find(function (b) {
|
|
101
|
+
return b.side === 'between';
|
|
102
|
+
}) : border;
|
|
95
103
|
var boxAs = !as && tag ? tag : as;
|
|
96
104
|
contents = [];
|
|
97
105
|
var firstIndex;
|
|
@@ -108,7 +116,7 @@ var Box = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
108
116
|
gap: gap,
|
|
109
117
|
directionProp: direction,
|
|
110
118
|
responsive: responsive,
|
|
111
|
-
border:
|
|
119
|
+
border: styledBoxGapBorder
|
|
112
120
|
}));
|
|
113
121
|
}
|
|
114
122
|
}
|
|
@@ -177,7 +185,9 @@ var Box = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
177
185
|
elevationProp: elevation,
|
|
178
186
|
fillProp: fill,
|
|
179
187
|
focus: focus,
|
|
180
|
-
gap: ((boxOptions == null ? void 0 : boxOptions.cssGap) || cssGap) && gap && gap !== 'none' && border !== 'between' && (border == null ? void 0 : border.side) !== 'between' &&
|
|
188
|
+
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) {
|
|
189
|
+
return b.side === 'between';
|
|
190
|
+
})) && gap,
|
|
181
191
|
kindProp: kind,
|
|
182
192
|
overflowProp: overflow,
|
|
183
193
|
wrapProp: wrap,
|
|
@@ -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
|
};
|
|
@@ -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", "pad", "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';
|
|
4
|
+
import React, { cloneElement, Children, forwardRef, useContext, useMemo, useState, useCallback, useEffect } from 'react';
|
|
5
|
+
import styled, { ThemeContext } from 'styled-components';
|
|
6
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,
|
|
@@ -138,6 +145,7 @@ var Button = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
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,6 +158,7 @@ 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,
|
|
@@ -162,6 +171,7 @@ var Button = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
162
171
|
secondary = _ref.secondary,
|
|
163
172
|
selected = _ref.selected,
|
|
164
173
|
sizeProp = _ref.size,
|
|
174
|
+
success = _ref.success,
|
|
165
175
|
tip = _ref.tip,
|
|
166
176
|
_ref$type = _ref.type,
|
|
167
177
|
type = _ref$type === void 0 ? 'button' : _ref$type,
|
|
@@ -176,6 +186,21 @@ var Button = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
176
186
|
var _useState2 = useState(false),
|
|
177
187
|
hover = _useState2[0],
|
|
178
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]);
|
|
179
204
|
if ((icon || label) && children) {
|
|
180
205
|
console.warn('Button should not have children if icon or label is provided');
|
|
181
206
|
}
|
|
@@ -332,6 +357,36 @@ var Button = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
332
357
|
content: badgeProp
|
|
333
358
|
}, contents);
|
|
334
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
|
+
}
|
|
335
390
|
var styledButtonResult;
|
|
336
391
|
if (kind) {
|
|
337
392
|
styledButtonResult = /*#__PURE__*/React.createElement(StyledButtonKind, _extends({}, rest, {
|
|
@@ -340,6 +395,7 @@ var Button = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
340
395
|
active: active,
|
|
341
396
|
align: align,
|
|
342
397
|
"aria-label": ariaLabel || a11yTitle,
|
|
398
|
+
busy: busy,
|
|
343
399
|
badge: badgeProp,
|
|
344
400
|
colorValue: color,
|
|
345
401
|
disabled: disabled,
|
|
@@ -353,7 +409,7 @@ var Button = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
353
409
|
href: href,
|
|
354
410
|
kind: kind,
|
|
355
411
|
themePaths: themePaths,
|
|
356
|
-
onClick: onClick,
|
|
412
|
+
onClick: !busy && !success ? onClick : undefined,
|
|
357
413
|
onFocus: function onFocus(event) {
|
|
358
414
|
setFocus(true);
|
|
359
415
|
if (_onFocus) _onFocus(event);
|
|
@@ -368,6 +424,7 @@ var Button = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
368
424
|
plain: plain || Children.count(children) > 0,
|
|
369
425
|
primary: primary,
|
|
370
426
|
sizeProp: size,
|
|
427
|
+
success: success,
|
|
371
428
|
type: !href ? type : undefined
|
|
372
429
|
}), contents);
|
|
373
430
|
} else {
|
|
@@ -375,6 +432,7 @@ var Button = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
375
432
|
as: domTag,
|
|
376
433
|
ref: ref,
|
|
377
434
|
"aria-label": ariaLabel || a11yTitle,
|
|
435
|
+
busy: busy,
|
|
378
436
|
colorValue: color,
|
|
379
437
|
active: active,
|
|
380
438
|
selected: selected,
|
|
@@ -388,7 +446,7 @@ var Button = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
388
446
|
href: href,
|
|
389
447
|
kind: kind,
|
|
390
448
|
themePaths: themePaths,
|
|
391
|
-
onClick: onClick,
|
|
449
|
+
onClick: !busy && !success ? onClick : undefined,
|
|
392
450
|
onFocus: function onFocus(event) {
|
|
393
451
|
setFocus(true);
|
|
394
452
|
if (_onFocus) _onFocus(event);
|
|
@@ -403,6 +461,7 @@ var Button = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
403
461
|
plain: typeof plain !== 'undefined' ? plain : Children.count(children) > 0 || icon && !label,
|
|
404
462
|
primary: primary,
|
|
405
463
|
sizeProp: size,
|
|
464
|
+
success: success,
|
|
406
465
|
type: !href ? type : undefined
|
|
407
466
|
}), contents);
|
|
408
467
|
}
|
|
@@ -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) {
|
|
@@ -97,6 +97,8 @@ var StyledButton = styled.button.withConfig({
|
|
|
97
97
|
return !props.plain && props.pad && edgeStyle('padding', props.pad, false, undefined, props.theme);
|
|
98
98
|
}, function (props) {
|
|
99
99
|
return props.theme.button && props.theme.button.extend;
|
|
100
|
+
}, function (props) {
|
|
101
|
+
return (props.busy || props.success) && "\n cursor: default;\n ";
|
|
100
102
|
});
|
|
101
103
|
StyledButton.defaultProps = {};
|
|
102
104
|
Object.setPrototypeOf(StyledButton.defaultProps, defaultProps);
|
|
@@ -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
|
}
|
|
@@ -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;
|
|
@@ -184,7 +186,7 @@ var StyledButtonKind = styled.button.withConfig({
|
|
|
184
186
|
}, function (props) {
|
|
185
187
|
return !props.plain && props.align && "\n text-align: " + props.align + ";\n ";
|
|
186
188
|
}, function (props) {
|
|
187
|
-
return !props.disabled && props.hoverIndicator && hoverIndicatorStyle(props);
|
|
189
|
+
return !props.disabled && props.hoverIndicator && !props.busy && !props.success && hoverIndicatorStyle(props);
|
|
188
190
|
}, function (props) {
|
|
189
191
|
return props.disabled && disabledStyle(props.theme.button.disabled.opacity);
|
|
190
192
|
}, function (props) {
|
|
@@ -195,6 +197,8 @@ var StyledButtonKind = styled.button.withConfig({
|
|
|
195
197
|
return props.fillContainer && fillStyle(props.fillContainer);
|
|
196
198
|
}, function (props) {
|
|
197
199
|
return props.theme.button && props.theme.button.extend;
|
|
200
|
+
}, function (props) {
|
|
201
|
+
return (props.busy || props.success) && "\n cursor: default;\n ";
|
|
198
202
|
});
|
|
199
203
|
StyledButtonKind.defaultProps = {};
|
|
200
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,
|
|
@@ -39,6 +40,7 @@ export interface ButtonProps {
|
|
|
39
40
|
hover: boolean;
|
|
40
41
|
focus: boolean;
|
|
41
42
|
}) => React.ReactNode);
|
|
43
|
+
busy?: boolean;
|
|
42
44
|
gridArea?: GridAreaType;
|
|
43
45
|
margin?: MarginType;
|
|
44
46
|
active?: boolean;
|
|
@@ -61,12 +63,17 @@ export interface ButtonProps {
|
|
|
61
63
|
icon?: JSX.Element;
|
|
62
64
|
kind?: string;
|
|
63
65
|
label?: React.ReactNode;
|
|
66
|
+
messages?: {
|
|
67
|
+
busy?: string;
|
|
68
|
+
success?: string;
|
|
69
|
+
};
|
|
64
70
|
pad?: PadType;
|
|
65
71
|
plain?: boolean;
|
|
66
72
|
primary?: boolean;
|
|
67
73
|
reverse?: boolean;
|
|
68
74
|
secondary?: boolean;
|
|
69
75
|
size?: 'small' | 'medium' | 'large' | string;
|
|
76
|
+
success?: boolean;
|
|
70
77
|
tip?: TipProps | string;
|
|
71
78
|
type?: 'button' | 'reset' | 'submit';
|
|
72
79
|
as?: PolymorphicType;
|
|
@@ -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,6 +23,10 @@ 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,
|
|
26
31
|
pad: padPropType,
|
|
27
32
|
plain: PropTypes.bool,
|
|
@@ -29,6 +34,7 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
29
34
|
reverse: PropTypes.bool,
|
|
30
35
|
secondary: PropTypes.bool,
|
|
31
36
|
size: PropTypes.oneOfType([PropTypes.oneOf(['small', 'medium', 'large']), PropTypes.string]),
|
|
37
|
+
success: PropTypes.bool,
|
|
32
38
|
target: PropTypes.oneOfType([PropTypes.oneOf(['_self', '_blank', '_parent', '_top']), PropTypes.string]),
|
|
33
39
|
tip: PropTypes.oneOfType([PropTypes.shape({
|
|
34
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
|
+
};
|
|
@@ -45,11 +45,9 @@ export var Dual = function Dual() {
|
|
|
45
45
|
onReference: function onReference(reference) {
|
|
46
46
|
var refDate = new Date(reference);
|
|
47
47
|
var nextDate = new Date(refDate);
|
|
48
|
-
console.log(refDate);
|
|
49
|
-
console.log(nextDate);
|
|
50
48
|
nextDate.setMonth(refDate.getMonth() + 1, 1);
|
|
51
|
-
setReference1(refDate.
|
|
52
|
-
setReference2(nextDate.
|
|
49
|
+
setReference1(refDate.toISOString());
|
|
50
|
+
setReference2(nextDate.toISOString());
|
|
53
51
|
},
|
|
54
52
|
header: function header(_ref) {
|
|
55
53
|
var currentDate = _ref.date,
|
|
@@ -84,8 +82,8 @@ export var Dual = function Dual() {
|
|
|
84
82
|
var refDate = new Date(reference);
|
|
85
83
|
var priorDate = new Date(refDate);
|
|
86
84
|
priorDate.setMonth(refDate.getMonth() - 1, 1);
|
|
87
|
-
setReference1(priorDate.
|
|
88
|
-
setReference2(refDate.
|
|
85
|
+
setReference1(priorDate.toISOString());
|
|
86
|
+
setReference2(refDate.toISOString());
|
|
89
87
|
},
|
|
90
88
|
header: function header(_ref2) {
|
|
91
89
|
var currentDate = _ref2.date,
|