@automattic/vip-design-system 0.28.6 → 0.28.7
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/build/system/Button/Button.js +3 -3
- package/build/system/Button/Button.stories.js +3 -1
- package/build/system/Button/ButtonSubmit.js +99 -0
- package/build/system/Button/ButtonSubmit.stories.js +71 -0
- package/build/system/Button/ButtonSubmit.test.js +82 -0
- package/build/system/Button/index.js +12 -1
- package/build/system/Spinner/Spinner.js +6 -3
- package/build/system/index.js +1 -0
- package/build/system/theme/index.js +13 -0
- package/package.json +1 -1
- package/src/system/Button/Button.js +2 -2
- package/src/system/Button/Button.stories.jsx +2 -1
- package/src/system/Button/ButtonSubmit.js +74 -0
- package/src/system/Button/ButtonSubmit.stories.jsx +41 -0
- package/src/system/Button/ButtonSubmit.test.js +36 -0
- package/src/system/Button/index.js +14 -1
- package/src/system/Spinner/Spinner.js +15 -12
- package/src/system/index.js +2 -1
- package/src/system/theme/index.js +15 -0
|
@@ -62,11 +62,11 @@ var Button = /*#__PURE__*/_react["default"].forwardRef(function (_ref, forwardRe
|
|
|
62
62
|
cursor: 'not-allowed',
|
|
63
63
|
pointerEvents: 'all'
|
|
64
64
|
}
|
|
65
|
-
}, sx)
|
|
65
|
+
}, sx)
|
|
66
|
+
}, props, {
|
|
66
67
|
"aria-disabled": disabled,
|
|
68
|
+
onClick: handleOnClick,
|
|
67
69
|
className: (0, _classnames["default"])('vip-button-component', props.className),
|
|
68
|
-
onClick: handleOnClick
|
|
69
|
-
}, props, {
|
|
70
70
|
ref: forwardRef
|
|
71
71
|
}));
|
|
72
72
|
});
|
|
@@ -15,6 +15,8 @@ var _ScreenReaderText = _interopRequireDefault(require("../ScreenReaderText"));
|
|
|
15
15
|
|
|
16
16
|
var _ = require("..");
|
|
17
17
|
|
|
18
|
+
var _2 = require(".");
|
|
19
|
+
|
|
18
20
|
var _jsxRuntime = require("theme-ui/jsx-runtime");
|
|
19
21
|
|
|
20
22
|
/**
|
|
@@ -36,7 +38,7 @@ var _default = {
|
|
|
36
38
|
},
|
|
37
39
|
variant: {
|
|
38
40
|
type: 'select',
|
|
39
|
-
options:
|
|
41
|
+
options: _2.variants
|
|
40
42
|
}
|
|
41
43
|
}
|
|
42
44
|
};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
exports.__esModule = true;
|
|
6
|
+
exports.ButtonSubmit = void 0;
|
|
7
|
+
|
|
8
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
|
+
|
|
10
|
+
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
|
11
|
+
|
|
12
|
+
var _react = _interopRequireDefault(require("react"));
|
|
13
|
+
|
|
14
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
15
|
+
|
|
16
|
+
var _Button = require("./Button");
|
|
17
|
+
|
|
18
|
+
var _Spinner = require("../Spinner");
|
|
19
|
+
|
|
20
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
|
21
|
+
|
|
22
|
+
var _ = require(".");
|
|
23
|
+
|
|
24
|
+
var _jsxRuntime = require("theme-ui/jsx-runtime");
|
|
25
|
+
|
|
26
|
+
var _excluded = ["show", "variant", "label", "loading", "disabled", "loadingIcon", "loadingIconSize", "loadingIconColor"];
|
|
27
|
+
|
|
28
|
+
var DefaultSpinner = function DefaultSpinner(_ref) {
|
|
29
|
+
var size = _ref.size,
|
|
30
|
+
_ref$color = _ref.color,
|
|
31
|
+
color = _ref$color === void 0 ? 'link' : _ref$color;
|
|
32
|
+
return (0, _jsxRuntime.jsx)(_Spinner.Spinner, {
|
|
33
|
+
size: size,
|
|
34
|
+
sx: {
|
|
35
|
+
ml: 2,
|
|
36
|
+
color: color
|
|
37
|
+
},
|
|
38
|
+
className: "vip-button-submit-spinner"
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
DefaultSpinner.propTypes = {
|
|
43
|
+
size: _propTypes["default"].number,
|
|
44
|
+
color: _propTypes["default"].string
|
|
45
|
+
};
|
|
46
|
+
DefaultSpinner.displayName = 'DefaultSpinner';
|
|
47
|
+
|
|
48
|
+
var ButtonSubmit = /*#__PURE__*/_react["default"].forwardRef(function (_ref2, forwardRef) {
|
|
49
|
+
var _ref2$show = _ref2.show,
|
|
50
|
+
show = _ref2$show === void 0 ? true : _ref2$show,
|
|
51
|
+
_ref2$variant = _ref2.variant,
|
|
52
|
+
variant = _ref2$variant === void 0 ? 'secondary' : _ref2$variant,
|
|
53
|
+
label = _ref2.label,
|
|
54
|
+
_ref2$loading = _ref2.loading,
|
|
55
|
+
loading = _ref2$loading === void 0 ? false : _ref2$loading,
|
|
56
|
+
_ref2$disabled = _ref2.disabled,
|
|
57
|
+
disabled = _ref2$disabled === void 0 ? false : _ref2$disabled,
|
|
58
|
+
_ref2$loadingIcon = _ref2.loadingIcon,
|
|
59
|
+
loadingIcon = _ref2$loadingIcon === void 0 ? DefaultSpinner : _ref2$loadingIcon,
|
|
60
|
+
_ref2$loadingIconSize = _ref2.loadingIconSize,
|
|
61
|
+
loadingIconSize = _ref2$loadingIconSize === void 0 ? 20 : _ref2$loadingIconSize,
|
|
62
|
+
_ref2$loadingIconColo = _ref2.loadingIconColor,
|
|
63
|
+
loadingIconColor = _ref2$loadingIconColo === void 0 ? undefined : _ref2$loadingIconColo,
|
|
64
|
+
rest = (0, _objectWithoutPropertiesLoose2["default"])(_ref2, _excluded);
|
|
65
|
+
|
|
66
|
+
if (!show) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (!loadingIconColor && variant === 'display') {
|
|
71
|
+
loadingIconColor = 'button.display.label.default';
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return (0, _jsxRuntime.jsxs)(_Button.Button, (0, _extends2["default"])({
|
|
75
|
+
ref: forwardRef,
|
|
76
|
+
className: (0, _classnames["default"])('vip-button-submit-component', "vip-button-submit-" + variant),
|
|
77
|
+
disabled: disabled || loading,
|
|
78
|
+
variant: variant,
|
|
79
|
+
"aria-busy": loading
|
|
80
|
+
}, rest, {
|
|
81
|
+
children: [label, ' ', !!loading && loadingIcon({
|
|
82
|
+
size: loadingIconSize,
|
|
83
|
+
color: loadingIconColor
|
|
84
|
+
})]
|
|
85
|
+
}));
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
exports.ButtonSubmit = ButtonSubmit;
|
|
89
|
+
ButtonSubmit.displayName = 'ButtonSubmit';
|
|
90
|
+
ButtonSubmit.propTypes = {
|
|
91
|
+
label: _propTypes["default"].string.isRequired,
|
|
92
|
+
disabled: _propTypes["default"].bool,
|
|
93
|
+
loading: _propTypes["default"].bool,
|
|
94
|
+
variant: _propTypes["default"].oneOf(_.variants),
|
|
95
|
+
show: _propTypes["default"].bool,
|
|
96
|
+
loadingIcon: _propTypes["default"].any,
|
|
97
|
+
loadingIconSize: _propTypes["default"].number,
|
|
98
|
+
loadingIconColor: _propTypes["default"].string
|
|
99
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
exports.__esModule = true;
|
|
6
|
+
exports["default"] = exports.Default = void 0;
|
|
7
|
+
|
|
8
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
|
+
|
|
10
|
+
var _react = _interopRequireDefault(require("react"));
|
|
11
|
+
|
|
12
|
+
var _ = require("..");
|
|
13
|
+
|
|
14
|
+
var _2 = require(".");
|
|
15
|
+
|
|
16
|
+
var _jsxRuntime = require("theme-ui/jsx-runtime");
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* External dependencies
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Internal dependencies
|
|
24
|
+
*/
|
|
25
|
+
var _default = {
|
|
26
|
+
title: 'ButtonSubmit',
|
|
27
|
+
component: _.ButtonSubmit,
|
|
28
|
+
argTypes: {
|
|
29
|
+
label: {
|
|
30
|
+
defaultValue: 'Load more items'
|
|
31
|
+
},
|
|
32
|
+
loading: {
|
|
33
|
+
control: {
|
|
34
|
+
type: 'boolean',
|
|
35
|
+
defaultValue: true
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
disabled: {
|
|
39
|
+
control: {
|
|
40
|
+
type: 'boolean'
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
show: {
|
|
44
|
+
control: {
|
|
45
|
+
type: 'boolean',
|
|
46
|
+
"default": true
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
variant: {
|
|
50
|
+
type: 'select',
|
|
51
|
+
options: _2.variants
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
exports["default"] = _default;
|
|
56
|
+
|
|
57
|
+
var Template = function Template(args) {
|
|
58
|
+
return (0, _jsxRuntime.jsx)(_react["default"].Fragment, {
|
|
59
|
+
children: _2.variants.map(function (v) {
|
|
60
|
+
return (0, _jsxRuntime.jsx)(_.ButtonSubmit, (0, _extends2["default"])({
|
|
61
|
+
sx: {
|
|
62
|
+
m: 3
|
|
63
|
+
},
|
|
64
|
+
variant: v
|
|
65
|
+
}, args), v);
|
|
66
|
+
})
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
var Default = Template.bind({});
|
|
71
|
+
exports.Default = Default;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
6
|
+
|
|
7
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
8
|
+
|
|
9
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
10
|
+
|
|
11
|
+
var _react = require("@testing-library/react");
|
|
12
|
+
|
|
13
|
+
var _jestAxe = require("jest-axe");
|
|
14
|
+
|
|
15
|
+
var _ButtonSubmit = require("./ButtonSubmit");
|
|
16
|
+
|
|
17
|
+
var _jsxRuntime = require("theme-ui/jsx-runtime");
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* External dependencies
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Internal dependencies
|
|
25
|
+
*/
|
|
26
|
+
var defaultProps = {
|
|
27
|
+
label: 'Load more items'
|
|
28
|
+
};
|
|
29
|
+
describe('<ButtonSubmit />', function () {
|
|
30
|
+
it('renders the ButtonSubmit component', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
|
|
31
|
+
var _render, container;
|
|
32
|
+
|
|
33
|
+
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
34
|
+
while (1) {
|
|
35
|
+
switch (_context.prev = _context.next) {
|
|
36
|
+
case 0:
|
|
37
|
+
_render = (0, _react.render)((0, _jsxRuntime.jsx)(_ButtonSubmit.ButtonSubmit, (0, _extends2["default"])({}, defaultProps))), container = _render.container;
|
|
38
|
+
expect(_react.screen.getByRole('button', {
|
|
39
|
+
label: 'Load more items'
|
|
40
|
+
})).toBeInTheDocument(); // Check for accessibility issues
|
|
41
|
+
|
|
42
|
+
_context.t0 = expect;
|
|
43
|
+
_context.next = 5;
|
|
44
|
+
return (0, _jestAxe.axe)(container);
|
|
45
|
+
|
|
46
|
+
case 5:
|
|
47
|
+
_context.t1 = _context.sent;
|
|
48
|
+
_context.next = 8;
|
|
49
|
+
return (0, _context.t0)(_context.t1).toHaveNoViolations();
|
|
50
|
+
|
|
51
|
+
case 8:
|
|
52
|
+
case "end":
|
|
53
|
+
return _context.stop();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}, _callee);
|
|
57
|
+
})));
|
|
58
|
+
it('renders the ButtonSubmit loading', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2() {
|
|
59
|
+
var button;
|
|
60
|
+
return _regenerator["default"].wrap(function _callee2$(_context2) {
|
|
61
|
+
while (1) {
|
|
62
|
+
switch (_context2.prev = _context2.next) {
|
|
63
|
+
case 0:
|
|
64
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_ButtonSubmit.ButtonSubmit, (0, _extends2["default"])({}, defaultProps, {
|
|
65
|
+
loading: true
|
|
66
|
+
})));
|
|
67
|
+
button = _react.screen.getByRole('button', {
|
|
68
|
+
label: 'Load more items'
|
|
69
|
+
}); // Button
|
|
70
|
+
|
|
71
|
+
expect(button).toHaveAttribute('aria-disabled', 'true'); // Spinner
|
|
72
|
+
|
|
73
|
+
expect(_react.screen.getByTitle('Loading...')).toBeInTheDocument();
|
|
74
|
+
|
|
75
|
+
case 4:
|
|
76
|
+
case "end":
|
|
77
|
+
return _context2.stop();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}, _callee2);
|
|
81
|
+
})));
|
|
82
|
+
});
|
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
|
+
exports.variants = void 0;
|
|
4
5
|
|
|
5
6
|
var _Button = require("./Button");
|
|
6
7
|
|
|
7
|
-
exports.Button = _Button.Button;
|
|
8
|
+
exports.Button = _Button.Button;
|
|
9
|
+
|
|
10
|
+
var _ButtonSubmit = require("./ButtonSubmit");
|
|
11
|
+
|
|
12
|
+
exports.ButtonSubmit = _ButtonSubmit.ButtonSubmit;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Internal dependencies
|
|
16
|
+
*/
|
|
17
|
+
var variants = ['primary', 'secondary', 'text', 'icon', 'tertiary', 'ghost', 'danger', 'display'];
|
|
18
|
+
exports.variants = variants;
|
|
@@ -19,18 +19,20 @@ var _classnames = _interopRequireDefault(require("classnames"));
|
|
|
19
19
|
|
|
20
20
|
var _jsxRuntime = require("theme-ui/jsx-runtime");
|
|
21
21
|
|
|
22
|
-
var _excluded = ["sx", "className"];
|
|
22
|
+
var _excluded = ["sx", "className", "color"];
|
|
23
23
|
|
|
24
24
|
var Spinner = /*#__PURE__*/_react["default"].forwardRef(function (_ref, forwardRef) {
|
|
25
25
|
var sx = _ref.sx,
|
|
26
26
|
_ref$className = _ref.className,
|
|
27
27
|
className = _ref$className === void 0 ? null : _ref$className,
|
|
28
|
+
_ref$color = _ref.color,
|
|
29
|
+
color = _ref$color === void 0 ? 'icon.helper' : _ref$color,
|
|
28
30
|
props = (0, _objectWithoutPropertiesLoose2["default"])(_ref, _excluded);
|
|
29
31
|
return (0, _jsxRuntime.jsx)(_themeUi.Spinner, (0, _extends2["default"])({
|
|
30
32
|
strokeWidth: 2,
|
|
31
33
|
sx: {
|
|
32
34
|
fill: 'none',
|
|
33
|
-
color:
|
|
35
|
+
color: color
|
|
34
36
|
},
|
|
35
37
|
className: (0, _classnames["default"])('vip-spinner-component', className),
|
|
36
38
|
ref: forwardRef
|
|
@@ -41,5 +43,6 @@ exports.Spinner = Spinner;
|
|
|
41
43
|
Spinner.displayName = 'Spinner';
|
|
42
44
|
Spinner.propTypes = {
|
|
43
45
|
sx: _propTypes["default"].object,
|
|
44
|
-
className: _propTypes["default"].any
|
|
46
|
+
className: _propTypes["default"].any,
|
|
47
|
+
color: _propTypes["default"].string
|
|
45
48
|
};
|
package/build/system/index.js
CHANGED
|
@@ -235,6 +235,19 @@ var _default = {
|
|
|
235
235
|
borderColor: 'button.tertiary.border.hover'
|
|
236
236
|
}
|
|
237
237
|
},
|
|
238
|
+
display: {
|
|
239
|
+
variant: 'buttons.primary',
|
|
240
|
+
color: 'button.display.label.default',
|
|
241
|
+
bg: 'button.display.background.default',
|
|
242
|
+
border: '1px solid',
|
|
243
|
+
borderColor: 'transparent',
|
|
244
|
+
'&:hover, &:focus': {
|
|
245
|
+
backgroundColor: 'button.display.background.hover',
|
|
246
|
+
color: 'button.display.label.hover',
|
|
247
|
+
border: '1px solid',
|
|
248
|
+
borderColor: 'transparent'
|
|
249
|
+
}
|
|
250
|
+
},
|
|
238
251
|
ghost: {
|
|
239
252
|
variant: 'buttons.primary',
|
|
240
253
|
color: 'button.ghost.label.default',
|
package/package.json
CHANGED
|
@@ -43,10 +43,10 @@ const Button = React.forwardRef( ( { disabled, onClick, sx, ...props }, forwardR
|
|
|
43
43
|
},
|
|
44
44
|
...sx,
|
|
45
45
|
} }
|
|
46
|
+
{ ...props }
|
|
46
47
|
aria-disabled={ disabled }
|
|
47
|
-
className={ classNames( 'vip-button-component', props.className ) }
|
|
48
48
|
onClick={ handleOnClick }
|
|
49
|
-
{
|
|
49
|
+
className={ classNames( 'vip-button-component', props.className ) }
|
|
50
50
|
ref={ forwardRef }
|
|
51
51
|
/>
|
|
52
52
|
);
|
|
@@ -9,6 +9,7 @@ import { BiCalendarHeart } from 'react-icons/bi';
|
|
|
9
9
|
*/
|
|
10
10
|
import ScreenReaderText from '../ScreenReaderText';
|
|
11
11
|
import { Button } from '..';
|
|
12
|
+
import { variants } from '.';
|
|
12
13
|
|
|
13
14
|
export default {
|
|
14
15
|
title: 'Button',
|
|
@@ -20,7 +21,7 @@ export default {
|
|
|
20
21
|
},
|
|
21
22
|
variant: {
|
|
22
23
|
type: 'select',
|
|
23
|
-
options:
|
|
24
|
+
options: variants,
|
|
24
25
|
},
|
|
25
26
|
},
|
|
26
27
|
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/** @jsxImportSource theme-ui */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* External dependencies
|
|
5
|
+
*/
|
|
6
|
+
import React from 'react';
|
|
7
|
+
import PropTypes from 'prop-types';
|
|
8
|
+
import { Button } from './Button';
|
|
9
|
+
import { Spinner } from '../Spinner';
|
|
10
|
+
import classNames from 'classnames';
|
|
11
|
+
import { variants } from '.';
|
|
12
|
+
|
|
13
|
+
const DefaultSpinner = ( { size, color = 'link' } ) => (
|
|
14
|
+
<Spinner size={ size } sx={ { ml: 2, color } } className="vip-button-submit-spinner" />
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
DefaultSpinner.propTypes = {
|
|
18
|
+
size: PropTypes.number,
|
|
19
|
+
color: PropTypes.string,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
DefaultSpinner.displayName = 'DefaultSpinner';
|
|
23
|
+
|
|
24
|
+
export const ButtonSubmit = React.forwardRef(
|
|
25
|
+
(
|
|
26
|
+
{
|
|
27
|
+
show = true,
|
|
28
|
+
variant = 'secondary',
|
|
29
|
+
label,
|
|
30
|
+
loading = false,
|
|
31
|
+
disabled = false,
|
|
32
|
+
loadingIcon = DefaultSpinner,
|
|
33
|
+
loadingIconSize = 20,
|
|
34
|
+
loadingIconColor = undefined,
|
|
35
|
+
...rest
|
|
36
|
+
},
|
|
37
|
+
forwardRef
|
|
38
|
+
) => {
|
|
39
|
+
if ( ! show ) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if ( ! loadingIconColor && variant === 'display' ) {
|
|
44
|
+
loadingIconColor = 'button.display.label.default';
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<Button
|
|
49
|
+
ref={ forwardRef }
|
|
50
|
+
className={ classNames( 'vip-button-submit-component', `vip-button-submit-${ variant }` ) }
|
|
51
|
+
disabled={ disabled || loading }
|
|
52
|
+
variant={ variant }
|
|
53
|
+
aria-busy={ loading }
|
|
54
|
+
{ ...rest }
|
|
55
|
+
>
|
|
56
|
+
{ label }{ ' ' }
|
|
57
|
+
{ !! loading && loadingIcon( { size: loadingIconSize, color: loadingIconColor } ) }
|
|
58
|
+
</Button>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
ButtonSubmit.displayName = 'ButtonSubmit';
|
|
64
|
+
|
|
65
|
+
ButtonSubmit.propTypes = {
|
|
66
|
+
label: PropTypes.string.isRequired,
|
|
67
|
+
disabled: PropTypes.bool,
|
|
68
|
+
loading: PropTypes.bool,
|
|
69
|
+
variant: PropTypes.oneOf( variants ),
|
|
70
|
+
show: PropTypes.bool,
|
|
71
|
+
loadingIcon: PropTypes.any,
|
|
72
|
+
loadingIconSize: PropTypes.number,
|
|
73
|
+
loadingIconColor: PropTypes.string,
|
|
74
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import React from 'react';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Internal dependencies
|
|
8
|
+
*/
|
|
9
|
+
import { ButtonSubmit } from '..';
|
|
10
|
+
import { variants } from '.';
|
|
11
|
+
|
|
12
|
+
export default {
|
|
13
|
+
title: 'ButtonSubmit',
|
|
14
|
+
component: ButtonSubmit,
|
|
15
|
+
argTypes: {
|
|
16
|
+
label: { defaultValue: 'Load more items' },
|
|
17
|
+
loading: {
|
|
18
|
+
control: { type: 'boolean', defaultValue: true },
|
|
19
|
+
},
|
|
20
|
+
disabled: {
|
|
21
|
+
control: { type: 'boolean' },
|
|
22
|
+
},
|
|
23
|
+
show: {
|
|
24
|
+
control: { type: 'boolean', default: true },
|
|
25
|
+
},
|
|
26
|
+
variant: {
|
|
27
|
+
type: 'select',
|
|
28
|
+
options: variants,
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const Template = args => (
|
|
34
|
+
<React.Fragment>
|
|
35
|
+
{ variants.map( v => (
|
|
36
|
+
<ButtonSubmit sx={ { m: 3 } } key={ v } variant={ v } { ...args } />
|
|
37
|
+
) ) }
|
|
38
|
+
</React.Fragment>
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
export const Default = Template.bind( {} );
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { render, screen } from '@testing-library/react';
|
|
5
|
+
import { axe } from 'jest-axe';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Internal dependencies
|
|
9
|
+
*/
|
|
10
|
+
import { ButtonSubmit } from './ButtonSubmit';
|
|
11
|
+
|
|
12
|
+
const defaultProps = {
|
|
13
|
+
label: 'Load more items',
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
describe( '<ButtonSubmit />', () => {
|
|
17
|
+
it( 'renders the ButtonSubmit component', async () => {
|
|
18
|
+
const { container } = render( <ButtonSubmit { ...defaultProps } /> );
|
|
19
|
+
|
|
20
|
+
expect( screen.getByRole( 'button', { label: 'Load more items' } ) ).toBeInTheDocument();
|
|
21
|
+
|
|
22
|
+
// Check for accessibility issues
|
|
23
|
+
await expect( await axe( container ) ).toHaveNoViolations();
|
|
24
|
+
} );
|
|
25
|
+
|
|
26
|
+
it( 'renders the ButtonSubmit loading', async () => {
|
|
27
|
+
render( <ButtonSubmit { ...defaultProps } loading={ true } /> );
|
|
28
|
+
const button = screen.getByRole( 'button', { label: 'Load more items' } );
|
|
29
|
+
|
|
30
|
+
// Button
|
|
31
|
+
expect( button ).toHaveAttribute( 'aria-disabled', 'true' );
|
|
32
|
+
|
|
33
|
+
// Spinner
|
|
34
|
+
expect( screen.getByTitle( 'Loading...' ) ).toBeInTheDocument();
|
|
35
|
+
} );
|
|
36
|
+
} );
|
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Internal dependencies
|
|
3
3
|
*/
|
|
4
|
+
|
|
5
|
+
const variants = [
|
|
6
|
+
'primary',
|
|
7
|
+
'secondary',
|
|
8
|
+
'text',
|
|
9
|
+
'icon',
|
|
10
|
+
'tertiary',
|
|
11
|
+
'ghost',
|
|
12
|
+
'danger',
|
|
13
|
+
'display',
|
|
14
|
+
];
|
|
15
|
+
|
|
4
16
|
import { Button } from './Button';
|
|
17
|
+
import { ButtonSubmit } from './ButtonSubmit';
|
|
5
18
|
|
|
6
|
-
export { Button };
|
|
19
|
+
export { Button, ButtonSubmit, variants };
|
|
@@ -8,24 +8,27 @@ import { Spinner as ThemeSpinner } from 'theme-ui';
|
|
|
8
8
|
import PropTypes from 'prop-types';
|
|
9
9
|
import classNames from 'classnames';
|
|
10
10
|
|
|
11
|
-
const Spinner = React.forwardRef(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
11
|
+
const Spinner = React.forwardRef(
|
|
12
|
+
( { sx, className = null, color = 'icon.helper', ...props }, forwardRef ) => (
|
|
13
|
+
<ThemeSpinner
|
|
14
|
+
strokeWidth={ 2 }
|
|
15
|
+
sx={ {
|
|
16
|
+
fill: 'none',
|
|
17
|
+
color,
|
|
18
|
+
} }
|
|
19
|
+
className={ classNames( 'vip-spinner-component', className ) }
|
|
20
|
+
ref={ forwardRef }
|
|
21
|
+
{ ...props }
|
|
22
|
+
/>
|
|
23
|
+
)
|
|
24
|
+
);
|
|
23
25
|
|
|
24
26
|
Spinner.displayName = 'Spinner';
|
|
25
27
|
|
|
26
28
|
Spinner.propTypes = {
|
|
27
29
|
sx: PropTypes.object,
|
|
28
30
|
className: PropTypes.any,
|
|
31
|
+
color: PropTypes.string,
|
|
29
32
|
};
|
|
30
33
|
|
|
31
34
|
export { Spinner };
|
package/src/system/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import { Avatar } from './Avatar';
|
|
|
5
5
|
import { Badge } from './Badge';
|
|
6
6
|
import { BlankState } from './BlankState';
|
|
7
7
|
import { Box } from './Box';
|
|
8
|
-
import { Button } from './Button';
|
|
8
|
+
import { Button, ButtonSubmit } from './Button';
|
|
9
9
|
import { Card } from './Card';
|
|
10
10
|
import { Code } from './Code';
|
|
11
11
|
import {
|
|
@@ -63,6 +63,7 @@ export {
|
|
|
63
63
|
Box,
|
|
64
64
|
BlankState,
|
|
65
65
|
Button,
|
|
66
|
+
ButtonSubmit,
|
|
66
67
|
Card,
|
|
67
68
|
Checkbox,
|
|
68
69
|
Code,
|
|
@@ -291,6 +291,21 @@ export default {
|
|
|
291
291
|
},
|
|
292
292
|
},
|
|
293
293
|
|
|
294
|
+
display: {
|
|
295
|
+
variant: 'buttons.primary',
|
|
296
|
+
color: 'button.display.label.default',
|
|
297
|
+
bg: 'button.display.background.default',
|
|
298
|
+
border: '1px solid',
|
|
299
|
+
borderColor: 'transparent',
|
|
300
|
+
|
|
301
|
+
'&:hover, &:focus': {
|
|
302
|
+
backgroundColor: 'button.display.background.hover',
|
|
303
|
+
color: 'button.display.label.hover',
|
|
304
|
+
border: '1px solid',
|
|
305
|
+
borderColor: 'transparent',
|
|
306
|
+
},
|
|
307
|
+
},
|
|
308
|
+
|
|
294
309
|
ghost: {
|
|
295
310
|
variant: 'buttons.primary',
|
|
296
311
|
color: 'button.ghost.label.default',
|