@pingux/astro 1.12.0-alpha.0 → 1.12.0-alpha.3
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/lib/cjs/components/Avatar/Avatar.js +8 -3
- package/lib/cjs/components/Avatar/Avatar.test.js +10 -0
- package/lib/cjs/components/Button/Button.js +9 -3
- package/lib/cjs/components/CodeView/CodeView.test.js +4 -4
- package/lib/cjs/components/ComboBox/ComboBoxInput.js +2 -1
- package/lib/cjs/components/CopyText/CopyButton.js +1 -1
- package/lib/cjs/components/CopyText/CopyText.js +5 -1
- package/lib/cjs/components/CopyText/CopyText.test.js +11 -20
- package/lib/cjs/components/Image/Image.js +17 -8
- package/lib/cjs/components/Image/Image.stories.js +46 -3
- package/lib/cjs/components/Image/Image.test.js +26 -1
- package/lib/cjs/components/Menu/Menu.js +4 -1
- package/lib/cjs/components/Menu/Menu.test.js +3 -0
- package/lib/components/Avatar/Avatar.js +8 -3
- package/lib/components/Avatar/Avatar.test.js +8 -0
- package/lib/components/Button/Button.js +9 -3
- package/lib/components/CodeView/CodeView.test.js +4 -4
- package/lib/components/ComboBox/ComboBoxInput.js +2 -1
- package/lib/components/CopyText/CopyButton.js +1 -1
- package/lib/components/CopyText/CopyText.js +5 -1
- package/lib/components/CopyText/CopyText.test.js +11 -16
- package/lib/components/Image/Image.js +18 -9
- package/lib/components/Image/Image.stories.js +29 -1
- package/lib/components/Image/Image.test.js +26 -1
- package/lib/components/Menu/Menu.js +3 -1
- package/lib/components/Menu/Menu.test.js +2 -0
- package/package.json +1 -1
@@ -36,13 +36,18 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
36
36
|
*/
|
37
37
|
var Avatar = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
38
38
|
return (0, _react2.jsx)(_themeUi.Avatar, (0, _extends2["default"])({
|
39
|
-
ref: ref
|
40
|
-
alt: "Avatar"
|
39
|
+
ref: ref
|
41
40
|
}, props));
|
42
41
|
});
|
43
42
|
Avatar.propTypes = {
|
44
43
|
/** Source of avatar. */
|
45
|
-
src: _propTypes["default"].string.isRequired
|
44
|
+
src: _propTypes["default"].string.isRequired,
|
45
|
+
|
46
|
+
/** Alternative text for avatar. */
|
47
|
+
alt: _propTypes["default"].string
|
48
|
+
};
|
49
|
+
Avatar.defaultProps = {
|
50
|
+
alt: 'Avatar'
|
46
51
|
};
|
47
52
|
Avatar.displayName = 'Avatar';
|
48
53
|
var _default = Avatar;
|
@@ -34,4 +34,14 @@ test('an avatar is rendered', function () {
|
|
34
34
|
|
35
35
|
expect(img).toBeInstanceOf(HTMLImageElement);
|
36
36
|
expect(img).toBeInTheDocument();
|
37
|
+
expect(img).toHaveAttribute('alt', 'Avatar');
|
38
|
+
});
|
39
|
+
test('an avatar is rendered with custom alt', function () {
|
40
|
+
getComponent({
|
41
|
+
alt: 'Custom Alt'
|
42
|
+
});
|
43
|
+
|
44
|
+
var img = _testWrapper.screen.getByRole('img');
|
45
|
+
|
46
|
+
expect(img).toHaveAttribute('alt', 'Custom Alt');
|
37
47
|
});
|
@@ -54,7 +54,7 @@ var _Loader = _interopRequireDefault(require("../Loader"));
|
|
54
54
|
|
55
55
|
var _react2 = require("@emotion/react");
|
56
56
|
|
57
|
-
var _excluded = ["className", "isDisabled", "isLoading", "onHoverStart", "onHoverChange", "onHoverEnd", "onPress", "onPressStart", "onPressEnd", "onPressChange", "onPressUp", "children", "variant"];
|
57
|
+
var _excluded = ["className", "isDisabled", "isLoading", "onHoverStart", "onHoverChange", "onHoverEnd", "onPress", "onPressStart", "onPressEnd", "onPressChange", "onPressUp", "children", "variant", "tabIndex"];
|
58
58
|
|
59
59
|
function _getRequireWildcardCache(nodeInterop) { if (typeof _WeakMap !== "function") return null; var cacheBabelInterop = new _WeakMap(); var cacheNodeInterop = new _WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
60
60
|
|
@@ -78,6 +78,7 @@ var Button = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
78
78
|
onPressUp = props.onPressUp,
|
79
79
|
children = props.children,
|
80
80
|
variant = props.variant,
|
81
|
+
tabIndex = props.tabIndex,
|
81
82
|
others = (0, _objectWithoutProperties2["default"])(props, _excluded);
|
82
83
|
var buttonRef = (0, _react.useRef)();
|
83
84
|
(0, _hooks.usePropWarning)(props, 'disabled', 'isDisabled');
|
@@ -132,7 +133,9 @@ var Button = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
132
133
|
alignItems: 'center'
|
133
134
|
},
|
134
135
|
variant: variant
|
135
|
-
}, others, (0, _utils.mergeProps)(hoverProps, focusProps,
|
136
|
+
}, others, (0, _utils.mergeProps)(hoverProps, focusProps, _objectSpread(_objectSpread({}, buttonProps), {}, {
|
137
|
+
tabIndex: tabIndex
|
138
|
+
}))), isLoading ? (0, _react2.jsx)("span", {
|
136
139
|
style: {
|
137
140
|
visibility: 'hidden'
|
138
141
|
}
|
@@ -204,7 +207,10 @@ Button.propTypes = {
|
|
204
207
|
onPressUp: _propTypes["default"].func,
|
205
208
|
|
206
209
|
/** The styling variation of the button. */
|
207
|
-
variant: _propTypes["default"].string
|
210
|
+
variant: _propTypes["default"].string,
|
211
|
+
|
212
|
+
/** The focus variation of the button. */
|
213
|
+
tabIndex: _propTypes["default"].number
|
208
214
|
};
|
209
215
|
Button.defaultProps = {
|
210
216
|
isDisabled: false,
|
@@ -85,7 +85,7 @@ test('renders component in the default state', function () {
|
|
85
85
|
test('copy button is hovered and renders tooltip via mouse', function () {
|
86
86
|
getComponent();
|
87
87
|
|
88
|
-
var copyBtn = _testWrapper.screen.getByLabelText('copy');
|
88
|
+
var copyBtn = _testWrapper.screen.getByLabelText('copy to clipboard');
|
89
89
|
|
90
90
|
expect(copyBtn).not.toHaveFocus();
|
91
91
|
|
@@ -98,7 +98,7 @@ test('copy button is hovered and renders tooltip via mouse', function () {
|
|
98
98
|
test('copy button is focused and renders tooltip via keyboard', function () {
|
99
99
|
getComponent();
|
100
100
|
|
101
|
-
var copyBtn = _testWrapper.screen.getByLabelText('copy');
|
101
|
+
var copyBtn = _testWrapper.screen.getByLabelText('copy to clipboard');
|
102
102
|
|
103
103
|
expect(copyBtn).not.toHaveFocus();
|
104
104
|
|
@@ -141,7 +141,7 @@ test('click on copy button copies data to the clipboard', /*#__PURE__*/(0, _asyn
|
|
141
141
|
switch (_context2.prev = _context2.next) {
|
142
142
|
case 0:
|
143
143
|
getComponent();
|
144
|
-
button = _testWrapper.screen.getByLabelText('copy');
|
144
|
+
button = _testWrapper.screen.getByLabelText('copy to clipboard');
|
145
145
|
_context2.next = 4;
|
146
146
|
return (0, _testWrapper.act)( /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
|
147
147
|
return _regenerator["default"].wrap(function _callee$(_context) {
|
@@ -176,7 +176,7 @@ test('after button click, the tooltip renders with the text "Copied!"', /*#__PUR
|
|
176
176
|
switch (_context4.prev = _context4.next) {
|
177
177
|
case 0:
|
178
178
|
getComponent();
|
179
|
-
button = _testWrapper.screen.getByLabelText('copy');
|
179
|
+
button = _testWrapper.screen.getByLabelText('copy to clipboard');
|
180
180
|
_context4.next = 4;
|
181
181
|
return (0, _testWrapper.act)( /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3() {
|
182
182
|
return _regenerator["default"].wrap(function _callee3$(_context3) {
|
@@ -159,7 +159,8 @@ var ComboBoxInput = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
159
159
|
variant: "comboBox"
|
160
160
|
}, triggerProps, {
|
161
161
|
ref: triggerRef,
|
162
|
-
isDisabled: isDisabled || isReadOnly
|
162
|
+
isDisabled: isDisabled || isReadOnly,
|
163
|
+
tabIndex: -1
|
163
164
|
}), (0, _react2.jsx)(_index.Icon, {
|
164
165
|
icon: _MenuDownIcon["default"],
|
165
166
|
sx: isOpen ? {
|
@@ -39,7 +39,7 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
39
39
|
var CopyButton = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
40
40
|
return (0, _react2.jsx)(_IconButton["default"], (0, _extends2["default"])({
|
41
41
|
ref: ref,
|
42
|
-
"aria-label": "copy",
|
42
|
+
"aria-label": "copy to clipboard",
|
43
43
|
variant: "buttons.copy"
|
44
44
|
}, (0, _lodash.omit)(props, 'iconProps')), (0, _react2.jsx)(_Icon["default"], (0, _extends2["default"])({
|
45
45
|
icon: _ContentCopyIcon["default"],
|
@@ -34,6 +34,8 @@ var _interactions = require("@react-aria/interactions");
|
|
34
34
|
|
35
35
|
var _utils = require("@react-aria/utils");
|
36
36
|
|
37
|
+
var _liveAnnouncer = require("@react-aria/live-announcer");
|
38
|
+
|
37
39
|
var _index = require("../../index");
|
38
40
|
|
39
41
|
var _CopyButton = _interopRequireDefault(require("./CopyButton"));
|
@@ -101,6 +103,7 @@ var CopyText = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
101
103
|
|
102
104
|
(0, _react.useEffect)(function () {
|
103
105
|
if (isCopied) {
|
106
|
+
(0, _liveAnnouncer.announce)('Copied!', 'polite');
|
104
107
|
var timer = (0, _setTimeout2["default"])(function () {
|
105
108
|
setIsCopied(false);
|
106
109
|
}, 1000);
|
@@ -115,7 +118,8 @@ var CopyText = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
115
118
|
var content = mode === 'link' || mode === 'nonClickableContent' ? children : (0, _react2.jsx)(_index.Button, (0, _extends2["default"])({
|
116
119
|
variant: "quiet",
|
117
120
|
onPress: copyToClipboard,
|
118
|
-
"aria-label": "copy-content"
|
121
|
+
"aria-label": "copy-content",
|
122
|
+
tabIndex: -1
|
119
123
|
}, focusProps), children);
|
120
124
|
var tooltip = isCopied ? 'Copied!' : tooltipText;
|
121
125
|
var isTooltipOpen = isFocusVisible || isHovered || isCopied;
|
@@ -88,19 +88,10 @@ describe('Text mode', function () {
|
|
88
88
|
expect(_testWrapper.screen.queryByRole('tooltip')).toBeInTheDocument();
|
89
89
|
expect(_testWrapper.screen.queryByRole('tooltip')).toHaveTextContent('Copy to clipboard');
|
90
90
|
});
|
91
|
-
test('
|
91
|
+
test('copy button is focused with keyboard', function () {
|
92
92
|
getComponent();
|
93
93
|
|
94
|
-
var
|
95
|
-
|
96
|
-
expect(contentBtn).not.toHaveFocus();
|
97
|
-
|
98
|
-
_userEvent["default"].tab();
|
99
|
-
|
100
|
-
expect(contentBtn).toHaveFocus();
|
101
|
-
expect(contentBtn).toHaveClass('is-focused');
|
102
|
-
|
103
|
-
var copyBtn = _testWrapper.screen.getByLabelText('copy');
|
94
|
+
var copyBtn = _testWrapper.screen.getByLabelText('copy to clipboard');
|
104
95
|
|
105
96
|
expect(copyBtn).not.toHaveFocus();
|
106
97
|
|
@@ -164,7 +155,7 @@ describe('Text mode', function () {
|
|
164
155
|
switch (_context4.prev = _context4.next) {
|
165
156
|
case 0:
|
166
157
|
getComponent();
|
167
|
-
button = _testWrapper.screen.getByLabelText('copy');
|
158
|
+
button = _testWrapper.screen.getByLabelText('copy to clipboard');
|
168
159
|
_context4.next = 4;
|
169
160
|
return (0, _testWrapper.act)( /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3() {
|
170
161
|
return _regenerator["default"].wrap(function _callee3$(_context3) {
|
@@ -202,7 +193,7 @@ describe('Text mode', function () {
|
|
202
193
|
getComponent({
|
203
194
|
textToCopy: textToCopy
|
204
195
|
});
|
205
|
-
button = _testWrapper.screen.getByLabelText('copy');
|
196
|
+
button = _testWrapper.screen.getByLabelText('copy to clipboard');
|
206
197
|
_context6.next = 5;
|
207
198
|
return (0, _testWrapper.act)( /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee5() {
|
208
199
|
return _regenerator["default"].wrap(function _callee5$(_context5) {
|
@@ -238,7 +229,7 @@ describe('Text mode', function () {
|
|
238
229
|
case 0:
|
239
230
|
global.navigator.clipboard = undefined;
|
240
231
|
getComponent();
|
241
|
-
button = _testWrapper.screen.getByLabelText('copy');
|
232
|
+
button = _testWrapper.screen.getByLabelText('copy to clipboard');
|
242
233
|
_context8.next = 5;
|
243
234
|
return (0, _testWrapper.act)( /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee7() {
|
244
235
|
return _regenerator["default"].wrap(function _callee7$(_context7) {
|
@@ -283,7 +274,7 @@ describe('Text mode', function () {
|
|
283
274
|
getComponent();
|
284
275
|
spy = jest.spyOn(console, 'error');
|
285
276
|
expect(spy).not.toHaveBeenCalled();
|
286
|
-
button = _testWrapper.screen.getByLabelText('copy');
|
277
|
+
button = _testWrapper.screen.getByLabelText('copy to clipboard');
|
287
278
|
_context10.next = 9;
|
288
279
|
return (0, _testWrapper.act)( /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee9() {
|
289
280
|
return _regenerator["default"].wrap(function _callee9$(_context9) {
|
@@ -319,7 +310,7 @@ describe('Text mode', function () {
|
|
319
310
|
switch (_context12.prev = _context12.next) {
|
320
311
|
case 0:
|
321
312
|
getComponent();
|
322
|
-
button = _testWrapper.screen.getByLabelText('copy');
|
313
|
+
button = _testWrapper.screen.getByLabelText('copy to clipboard');
|
323
314
|
_context12.next = 4;
|
324
315
|
return (0, _testWrapper.act)( /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee11() {
|
325
316
|
return _regenerator["default"].wrap(function _callee11$(_context11) {
|
@@ -354,7 +345,7 @@ describe('Text mode', function () {
|
|
354
345
|
switch (_context14.prev = _context14.next) {
|
355
346
|
case 0:
|
356
347
|
getComponent();
|
357
|
-
button = _testWrapper.screen.getByLabelText('copy');
|
348
|
+
button = _testWrapper.screen.getByLabelText('copy to clipboard');
|
358
349
|
_context14.next = 4;
|
359
350
|
return (0, _testWrapper.act)( /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee13() {
|
360
351
|
return _regenerator["default"].wrap(function _callee13$(_context13) {
|
@@ -415,7 +406,7 @@ describe('Link mode', function () {
|
|
415
406
|
|
416
407
|
expect(_testWrapper.screen.queryByRole('tooltip')).not.toBeInTheDocument();
|
417
408
|
|
418
|
-
var button = _testWrapper.screen.getByLabelText('copy');
|
409
|
+
var button = _testWrapper.screen.getByLabelText('copy to clipboard');
|
419
410
|
|
420
411
|
_testWrapper.fireEvent.mouseMove(button);
|
421
412
|
|
@@ -426,7 +417,7 @@ describe('Link mode', function () {
|
|
426
417
|
test('copy button is focused with keyboard', function () {
|
427
418
|
getComponent();
|
428
419
|
|
429
|
-
var copyBtn = _testWrapper.screen.getByLabelText('copy');
|
420
|
+
var copyBtn = _testWrapper.screen.getByLabelText('copy to clipboard');
|
430
421
|
|
431
422
|
expect(copyBtn).not.toHaveFocus();
|
432
423
|
|
@@ -454,7 +445,7 @@ describe('Link mode', function () {
|
|
454
445
|
switch (_context16.prev = _context16.next) {
|
455
446
|
case 0:
|
456
447
|
getComponent();
|
457
|
-
button = _testWrapper.screen.getByLabelText('copy');
|
448
|
+
button = _testWrapper.screen.getByLabelText('copy to clipboard');
|
458
449
|
_context16.next = 4;
|
459
450
|
return (0, _testWrapper.act)( /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee15() {
|
460
451
|
return _regenerator["default"].wrap(function _callee15$(_context15) {
|
@@ -88,7 +88,12 @@ var Image = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
88
88
|
var _useState3 = (0, _react.useState)(false),
|
89
89
|
_useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
|
90
90
|
loadedSuccessfully = _useState4[0],
|
91
|
-
setLoadedSuccessfully = _useState4[1];
|
91
|
+
setLoadedSuccessfully = _useState4[1];
|
92
|
+
|
93
|
+
var _useState5 = (0, _react.useState)(false),
|
94
|
+
_useState6 = (0, _slicedToArray2["default"])(_useState5, 2),
|
95
|
+
hasTimedOut = _useState6[0],
|
96
|
+
setHasTimedOut = _useState6[1]; // we need to use useRef here with useState so it will be updated in setTimeout and onload
|
92
97
|
// https://github.com/facebook/react/issues/14010#issuecomment-433788147
|
93
98
|
|
94
99
|
|
@@ -99,11 +104,17 @@ var Image = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
99
104
|
isLoadingRef.current = newState;
|
100
105
|
};
|
101
106
|
|
102
|
-
var
|
103
|
-
|
104
|
-
|
105
|
-
|
107
|
+
var setImgSrc = function setImgSrc() {
|
108
|
+
if (!loadedSuccessfully && !(isLoadingRef !== null && isLoadingRef !== void 0 && isLoadingRef.current) || hasTimedOut) {
|
109
|
+
return fallbackImage;
|
110
|
+
}
|
111
|
+
|
112
|
+
return src;
|
113
|
+
};
|
106
114
|
|
115
|
+
var imgSrc = (0, _react.useMemo)(function () {
|
116
|
+
return setImgSrc();
|
117
|
+
}, [src, isLoading, hasTimedOut]);
|
107
118
|
var imgRef = (0, _react.useRef)();
|
108
119
|
/* istanbul ignore next */
|
109
120
|
|
@@ -126,20 +137,18 @@ var Image = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
126
137
|
var onImageLoad = function onImageLoad() {
|
127
138
|
if (isLoadingRef !== null && isLoadingRef !== void 0 && isLoadingRef.current) {
|
128
139
|
setIsLoadingWithRef(false);
|
129
|
-
setImgSrc(src);
|
130
140
|
setLoadedSuccessfully(true);
|
131
141
|
}
|
132
142
|
};
|
133
143
|
|
134
144
|
var onImageError = function onImageError() {
|
135
145
|
setIsLoadingWithRef(false);
|
136
|
-
setImgSrc(fallbackImage || null);
|
137
146
|
};
|
138
147
|
|
139
148
|
var onFallbackTimeout = function onFallbackTimeout() {
|
140
149
|
if (isLoadingRef !== null && isLoadingRef !== void 0 && isLoadingRef.current) {
|
141
150
|
setIsLoadingWithRef(false);
|
142
|
-
|
151
|
+
setHasTimedOut(true);
|
143
152
|
}
|
144
153
|
};
|
145
154
|
|
@@ -2,17 +2,25 @@
|
|
2
2
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
4
4
|
|
5
|
+
var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor");
|
6
|
+
|
5
7
|
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
6
8
|
|
9
|
+
var _typeof = require("@babel/runtime-corejs3/helpers/typeof");
|
10
|
+
|
11
|
+
var _WeakMap = require("@babel/runtime-corejs3/core-js-stable/weak-map");
|
12
|
+
|
7
13
|
_Object$defineProperty(exports, "__esModule", {
|
8
14
|
value: true
|
9
15
|
});
|
10
16
|
|
11
|
-
exports["default"] = exports.WithSkeletonLoadTimeout = exports.WithSkeletonLoadSuccess = exports.FallbackImage = exports.Disabled = exports.Default = exports.CustomSizeAndRadius = exports.Avatar = void 0;
|
17
|
+
exports["default"] = exports.WithSkeletonLoadTimeout = exports.WithSkeletonLoadSuccess = exports.UpdatingImageSrc = exports.FallbackImage = exports.Disabled = exports.Default = exports.CustomSizeAndRadius = exports.Avatar = void 0;
|
18
|
+
|
19
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/slicedToArray"));
|
12
20
|
|
13
21
|
var _extends2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/extends"));
|
14
22
|
|
15
|
-
var _react =
|
23
|
+
var _react = _interopRequireWildcard(require("react"));
|
16
24
|
|
17
25
|
var _isChromatic = _interopRequireDefault(require("chromatic/isChromatic"));
|
18
26
|
|
@@ -22,8 +30,14 @@ var _imageConstants = require("./imageConstants");
|
|
22
30
|
|
23
31
|
var _htmlElements = require("../../utils/devUtils/constants/htmlElements");
|
24
32
|
|
33
|
+
var _index = require("../../index");
|
34
|
+
|
25
35
|
var _react2 = require("@emotion/react");
|
26
36
|
|
37
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof _WeakMap !== "function") return null; var cacheBabelInterop = new _WeakMap(); var cacheNodeInterop = new _WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
38
|
+
|
39
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = _Object$defineProperty && _Object$getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? _Object$getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { _Object$defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
40
|
+
|
27
41
|
var _default = {
|
28
42
|
title: 'Image',
|
29
43
|
component: _["default"],
|
@@ -130,4 +144,33 @@ var WithSkeletonLoadTimeout = function WithSkeletonLoadTimeout() {
|
|
130
144
|
});
|
131
145
|
};
|
132
146
|
|
133
|
-
exports.WithSkeletonLoadTimeout = WithSkeletonLoadTimeout;
|
147
|
+
exports.WithSkeletonLoadTimeout = WithSkeletonLoadTimeout;
|
148
|
+
|
149
|
+
var UpdatingImageSrc = function UpdatingImageSrc() {
|
150
|
+
var _useState = (0, _react.useState)(_imageConstants.chiefIdentityChampions),
|
151
|
+
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
152
|
+
image = _useState2[0],
|
153
|
+
setImage = _useState2[1];
|
154
|
+
|
155
|
+
var handleButtonPress = function handleButtonPress() {
|
156
|
+
var src = image === _imageConstants.pingImg ? _imageConstants.chiefIdentityChampions : _imageConstants.pingImg;
|
157
|
+
setImage(src);
|
158
|
+
};
|
159
|
+
|
160
|
+
return (0, _react2.jsx)(_index.Box, {
|
161
|
+
sx: {
|
162
|
+
width: '200px'
|
163
|
+
}
|
164
|
+
}, (0, _react2.jsx)(_index.Button, {
|
165
|
+
onPress: handleButtonPress
|
166
|
+
}, "Change Image"), (0, _react2.jsx)(_["default"], {
|
167
|
+
src: image,
|
168
|
+
sx: {
|
169
|
+
width: '200px',
|
170
|
+
height: '200px',
|
171
|
+
mt: '25px'
|
172
|
+
}
|
173
|
+
}));
|
174
|
+
};
|
175
|
+
|
176
|
+
exports.UpdatingImageSrc = UpdatingImageSrc;
|
@@ -48,7 +48,12 @@ var defaultProps = {
|
|
48
48
|
|
49
49
|
var getComponent = function getComponent() {
|
50
50
|
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
51
|
-
|
51
|
+
|
52
|
+
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
53
|
+
_ref$renderFn = _ref.renderFn,
|
54
|
+
renderFn = _ref$renderFn === void 0 ? _testWrapper.render : _ref$renderFn;
|
55
|
+
|
56
|
+
return renderFn((0, _react3.jsx)(_["default"], (0, _extends2["default"])({}, defaultProps, props)));
|
52
57
|
}; // Need to be added to each test file to test accessibility using axe.
|
53
58
|
|
54
59
|
|
@@ -96,6 +101,26 @@ test('image shows disabled status', function () {
|
|
96
101
|
|
97
102
|
expect(img).toHaveClass('is-disabled');
|
98
103
|
});
|
104
|
+
test('image source is able to be changed', function () {
|
105
|
+
var src2 = 'second-src';
|
106
|
+
|
107
|
+
var _getComponent = getComponent(),
|
108
|
+
rerender = _getComponent.rerender;
|
109
|
+
|
110
|
+
(0, _react2.act)(function () {
|
111
|
+
fallbackImageObj.onImageLoad();
|
112
|
+
});
|
113
|
+
expect(_testWrapper.screen.getByRole('img')).toHaveAttribute('src', testSrc);
|
114
|
+
getComponent({
|
115
|
+
src: src2
|
116
|
+
}, {
|
117
|
+
renderFn: rerender
|
118
|
+
});
|
119
|
+
(0, _react2.act)(function () {
|
120
|
+
fallbackImageObj.onImageLoad();
|
121
|
+
});
|
122
|
+
expect(_testWrapper.screen.getByRole('img')).toHaveAttribute('src', src2);
|
123
|
+
});
|
99
124
|
describe('test Image component with useFallbackImage hook', function () {
|
100
125
|
test('image component will use src if loaded correctly', function () {
|
101
126
|
getComponent();
|
@@ -58,6 +58,8 @@ var _MenuItem = _interopRequireDefault(require("../MenuItem"));
|
|
58
58
|
|
59
59
|
var _Box = _interopRequireDefault(require("../Box"));
|
60
60
|
|
61
|
+
var _orientation = _interopRequireDefault(require("../../utils/devUtils/constants/orientation"));
|
62
|
+
|
61
63
|
var _react2 = require("@emotion/react");
|
62
64
|
|
63
65
|
var _excluded = ["isDisabled", "onAction", "onSelectionChange", "isNotFocusedOnHover"];
|
@@ -111,7 +113,8 @@ var Menu = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
111
113
|
return (0, _react2.jsx)(_Box["default"], (0, _extends2["default"])({
|
112
114
|
as: "ul",
|
113
115
|
ref: menuRef,
|
114
|
-
variant: "menu"
|
116
|
+
variant: "menu",
|
117
|
+
"aria-orientation": _orientation["default"].VERTICAL
|
115
118
|
}, others, (0, _utils.mergeProps)(focusProps, menuProps)), (0, _map["default"])(_context = (0, _from["default"])(state.collection)).call(_context, function (item) {
|
116
119
|
return (0, _react2.jsx)(_MenuItem["default"], {
|
117
120
|
key: item.key,
|
@@ -20,6 +20,8 @@ var _testWrapper = require("../../utils/testUtils/testWrapper");
|
|
20
20
|
|
21
21
|
var _index = require("../../index");
|
22
22
|
|
23
|
+
var _orientation = _interopRequireDefault(require("../../utils/devUtils/constants/orientation"));
|
24
|
+
|
23
25
|
var _react2 = require("@emotion/react");
|
24
26
|
|
25
27
|
var testTitle = 'Test Title';
|
@@ -59,6 +61,7 @@ test('should render basic menu with children', function () {
|
|
59
61
|
var menuItems = _testWrapper.screen.queryAllByRole('menuitem');
|
60
62
|
|
61
63
|
expect(menuItems).toHaveLength(3);
|
64
|
+
expect(menu).toHaveAttribute('aria-orientation', _orientation["default"].VERTICAL);
|
62
65
|
});
|
63
66
|
test('should render items when selectionMode is set to single', function () {
|
64
67
|
getComponent({
|
@@ -10,13 +10,18 @@ import { Avatar as ThemeUIAvatar } from 'theme-ui';
|
|
10
10
|
import { jsx as ___EmotionJSX } from "@emotion/react";
|
11
11
|
var Avatar = /*#__PURE__*/forwardRef(function (props, ref) {
|
12
12
|
return ___EmotionJSX(ThemeUIAvatar, _extends({
|
13
|
-
ref: ref
|
14
|
-
alt: "Avatar"
|
13
|
+
ref: ref
|
15
14
|
}, props));
|
16
15
|
});
|
17
16
|
Avatar.propTypes = {
|
18
17
|
/** Source of avatar. */
|
19
|
-
src: PropTypes.string.isRequired
|
18
|
+
src: PropTypes.string.isRequired,
|
19
|
+
|
20
|
+
/** Alternative text for avatar. */
|
21
|
+
alt: PropTypes.string
|
22
|
+
};
|
23
|
+
Avatar.defaultProps = {
|
24
|
+
alt: 'Avatar'
|
20
25
|
};
|
21
26
|
Avatar.displayName = 'Avatar';
|
22
27
|
export default Avatar;
|
@@ -21,4 +21,12 @@ test('an avatar is rendered', function () {
|
|
21
21
|
var img = screen.getByRole('img');
|
22
22
|
expect(img).toBeInstanceOf(HTMLImageElement);
|
23
23
|
expect(img).toBeInTheDocument();
|
24
|
+
expect(img).toHaveAttribute('alt', 'Avatar');
|
25
|
+
});
|
26
|
+
test('an avatar is rendered with custom alt', function () {
|
27
|
+
getComponent({
|
28
|
+
alt: 'Custom Alt'
|
29
|
+
});
|
30
|
+
var img = screen.getByRole('img');
|
31
|
+
expect(img).toHaveAttribute('alt', 'Custom Alt');
|
24
32
|
});
|
@@ -9,7 +9,7 @@ import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
|
|
9
9
|
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
10
10
|
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
11
11
|
import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
|
12
|
-
var _excluded = ["className", "isDisabled", "isLoading", "onHoverStart", "onHoverChange", "onHoverEnd", "onPress", "onPressStart", "onPressEnd", "onPressChange", "onPressUp", "children", "variant"];
|
12
|
+
var _excluded = ["className", "isDisabled", "isLoading", "onHoverStart", "onHoverChange", "onHoverEnd", "onPress", "onPressStart", "onPressEnd", "onPressChange", "onPressUp", "children", "variant", "tabIndex"];
|
13
13
|
|
14
14
|
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
15
15
|
|
@@ -39,6 +39,7 @@ var Button = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
39
39
|
onPressUp = props.onPressUp,
|
40
40
|
children = props.children,
|
41
41
|
variant = props.variant,
|
42
|
+
tabIndex = props.tabIndex,
|
42
43
|
others = _objectWithoutProperties(props, _excluded);
|
43
44
|
|
44
45
|
var buttonRef = useRef();
|
@@ -94,7 +95,9 @@ var Button = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
94
95
|
alignItems: 'center'
|
95
96
|
},
|
96
97
|
variant: variant
|
97
|
-
}, others, mergeProps(hoverProps, focusProps, buttonProps)
|
98
|
+
}, others, mergeProps(hoverProps, focusProps, _objectSpread(_objectSpread({}, buttonProps), {}, {
|
99
|
+
tabIndex: tabIndex
|
100
|
+
}))), isLoading ? ___EmotionJSX("span", {
|
98
101
|
style: {
|
99
102
|
visibility: 'hidden'
|
100
103
|
}
|
@@ -166,7 +169,10 @@ Button.propTypes = {
|
|
166
169
|
onPressUp: PropTypes.func,
|
167
170
|
|
168
171
|
/** The styling variation of the button. */
|
169
|
-
variant: PropTypes.string
|
172
|
+
variant: PropTypes.string,
|
173
|
+
|
174
|
+
/** The focus variation of the button. */
|
175
|
+
tabIndex: PropTypes.number
|
170
176
|
};
|
171
177
|
Button.defaultProps = {
|
172
178
|
isDisabled: false,
|
@@ -60,7 +60,7 @@ test('renders component in the default state', function () {
|
|
60
60
|
});
|
61
61
|
test('copy button is hovered and renders tooltip via mouse', function () {
|
62
62
|
getComponent();
|
63
|
-
var copyBtn = screen.getByLabelText('copy');
|
63
|
+
var copyBtn = screen.getByLabelText('copy to clipboard');
|
64
64
|
expect(copyBtn).not.toHaveFocus();
|
65
65
|
userEvent.hover(copyBtn);
|
66
66
|
expect(copyBtn).toHaveClass('is-hovered');
|
@@ -69,7 +69,7 @@ test('copy button is hovered and renders tooltip via mouse', function () {
|
|
69
69
|
});
|
70
70
|
test('copy button is focused and renders tooltip via keyboard', function () {
|
71
71
|
getComponent();
|
72
|
-
var copyBtn = screen.getByLabelText('copy');
|
72
|
+
var copyBtn = screen.getByLabelText('copy to clipboard');
|
73
73
|
expect(copyBtn).not.toHaveFocus();
|
74
74
|
userEvent.tab();
|
75
75
|
expect(copyBtn).toHaveFocus();
|
@@ -105,7 +105,7 @@ test('click on copy button copies data to the clipboard', /*#__PURE__*/_asyncToG
|
|
105
105
|
switch (_context2.prev = _context2.next) {
|
106
106
|
case 0:
|
107
107
|
getComponent();
|
108
|
-
button = screen.getByLabelText('copy');
|
108
|
+
button = screen.getByLabelText('copy to clipboard');
|
109
109
|
_context2.next = 4;
|
110
110
|
return act( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
111
111
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
@@ -140,7 +140,7 @@ test('after button click, the tooltip renders with the text "Copied!"', /*#__PUR
|
|
140
140
|
switch (_context4.prev = _context4.next) {
|
141
141
|
case 0:
|
142
142
|
getComponent();
|
143
|
-
button = screen.getByLabelText('copy');
|
143
|
+
button = screen.getByLabelText('copy to clipboard');
|
144
144
|
_context4.next = 4;
|
145
145
|
return act( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
|
146
146
|
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
@@ -117,7 +117,8 @@ var ComboBoxInput = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
117
117
|
variant: "comboBox"
|
118
118
|
}, triggerProps, {
|
119
119
|
ref: triggerRef,
|
120
|
-
isDisabled: isDisabled || isReadOnly
|
120
|
+
isDisabled: isDisabled || isReadOnly,
|
121
|
+
tabIndex: -1
|
121
122
|
}), ___EmotionJSX(Icon, {
|
122
123
|
icon: MenuDown,
|
123
124
|
sx: isOpen ? {
|
@@ -9,7 +9,7 @@ import { jsx as ___EmotionJSX } from "@emotion/react";
|
|
9
9
|
var CopyButton = /*#__PURE__*/forwardRef(function (props, ref) {
|
10
10
|
return ___EmotionJSX(IconButton, _extends({
|
11
11
|
ref: ref,
|
12
|
-
"aria-label": "copy",
|
12
|
+
"aria-label": "copy to clipboard",
|
13
13
|
variant: "buttons.copy"
|
14
14
|
}, omit(props, 'iconProps')), ___EmotionJSX(Icon, _extends({
|
15
15
|
icon: ContentCopy,
|
@@ -9,6 +9,7 @@ import PropTypes from 'prop-types';
|
|
9
9
|
import { useFocusRing } from '@react-aria/focus';
|
10
10
|
import { Pressable, useHover } from '@react-aria/interactions';
|
11
11
|
import { mergeProps } from '@react-aria/utils';
|
12
|
+
import { announce } from '@react-aria/live-announcer';
|
12
13
|
import { Box, Button, Tooltip, TooltipTrigger } from '../../index';
|
13
14
|
import CopyButton from './CopyButton';
|
14
15
|
import useCopyToClipboard from '../../hooks/useCopyToClipboard';
|
@@ -68,6 +69,8 @@ var CopyText = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
68
69
|
|
69
70
|
useEffect(function () {
|
70
71
|
if (isCopied) {
|
72
|
+
announce('Copied!', 'polite');
|
73
|
+
|
71
74
|
var timer = _setTimeout(function () {
|
72
75
|
setIsCopied(false);
|
73
76
|
}, 1000);
|
@@ -83,7 +86,8 @@ var CopyText = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
83
86
|
var content = mode === 'link' || mode === 'nonClickableContent' ? children : ___EmotionJSX(Button, _extends({
|
84
87
|
variant: "quiet",
|
85
88
|
onPress: copyToClipboard,
|
86
|
-
"aria-label": "copy-content"
|
89
|
+
"aria-label": "copy-content",
|
90
|
+
tabIndex: -1
|
87
91
|
}, focusProps), children);
|
88
92
|
var tooltip = isCopied ? 'Copied!' : tooltipText;
|
89
93
|
var isTooltipOpen = isFocusVisible || isHovered || isCopied;
|
@@ -60,14 +60,9 @@ describe('Text mode', function () {
|
|
60
60
|
expect(screen.queryByRole('tooltip')).toBeInTheDocument();
|
61
61
|
expect(screen.queryByRole('tooltip')).toHaveTextContent('Copy to clipboard');
|
62
62
|
});
|
63
|
-
test('
|
63
|
+
test('copy button is focused with keyboard', function () {
|
64
64
|
getComponent();
|
65
|
-
var
|
66
|
-
expect(contentBtn).not.toHaveFocus();
|
67
|
-
userEvent.tab();
|
68
|
-
expect(contentBtn).toHaveFocus();
|
69
|
-
expect(contentBtn).toHaveClass('is-focused');
|
70
|
-
var copyBtn = screen.getByLabelText('copy');
|
65
|
+
var copyBtn = screen.getByLabelText('copy to clipboard');
|
71
66
|
expect(copyBtn).not.toHaveFocus();
|
72
67
|
userEvent.tab();
|
73
68
|
expect(copyBtn).toHaveFocus();
|
@@ -128,7 +123,7 @@ describe('Text mode', function () {
|
|
128
123
|
switch (_context4.prev = _context4.next) {
|
129
124
|
case 0:
|
130
125
|
getComponent();
|
131
|
-
button = screen.getByLabelText('copy');
|
126
|
+
button = screen.getByLabelText('copy to clipboard');
|
132
127
|
_context4.next = 4;
|
133
128
|
return act( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
|
134
129
|
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
@@ -166,7 +161,7 @@ describe('Text mode', function () {
|
|
166
161
|
getComponent({
|
167
162
|
textToCopy: textToCopy
|
168
163
|
});
|
169
|
-
button = screen.getByLabelText('copy');
|
164
|
+
button = screen.getByLabelText('copy to clipboard');
|
170
165
|
_context6.next = 5;
|
171
166
|
return act( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
|
172
167
|
return _regeneratorRuntime.wrap(function _callee5$(_context5) {
|
@@ -202,7 +197,7 @@ describe('Text mode', function () {
|
|
202
197
|
case 0:
|
203
198
|
global.navigator.clipboard = undefined;
|
204
199
|
getComponent();
|
205
|
-
button = screen.getByLabelText('copy');
|
200
|
+
button = screen.getByLabelText('copy to clipboard');
|
206
201
|
_context8.next = 5;
|
207
202
|
return act( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7() {
|
208
203
|
return _regeneratorRuntime.wrap(function _callee7$(_context7) {
|
@@ -247,7 +242,7 @@ describe('Text mode', function () {
|
|
247
242
|
getComponent();
|
248
243
|
spy = jest.spyOn(console, 'error');
|
249
244
|
expect(spy).not.toHaveBeenCalled();
|
250
|
-
button = screen.getByLabelText('copy');
|
245
|
+
button = screen.getByLabelText('copy to clipboard');
|
251
246
|
_context10.next = 9;
|
252
247
|
return act( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9() {
|
253
248
|
return _regeneratorRuntime.wrap(function _callee9$(_context9) {
|
@@ -283,7 +278,7 @@ describe('Text mode', function () {
|
|
283
278
|
switch (_context12.prev = _context12.next) {
|
284
279
|
case 0:
|
285
280
|
getComponent();
|
286
|
-
button = screen.getByLabelText('copy');
|
281
|
+
button = screen.getByLabelText('copy to clipboard');
|
287
282
|
_context12.next = 4;
|
288
283
|
return act( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11() {
|
289
284
|
return _regeneratorRuntime.wrap(function _callee11$(_context11) {
|
@@ -318,7 +313,7 @@ describe('Text mode', function () {
|
|
318
313
|
switch (_context14.prev = _context14.next) {
|
319
314
|
case 0:
|
320
315
|
getComponent();
|
321
|
-
button = screen.getByLabelText('copy');
|
316
|
+
button = screen.getByLabelText('copy to clipboard');
|
322
317
|
_context14.next = 4;
|
323
318
|
return act( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee13() {
|
324
319
|
return _regeneratorRuntime.wrap(function _callee13$(_context13) {
|
@@ -374,14 +369,14 @@ describe('Link mode', function () {
|
|
374
369
|
fireEvent.mouseMove(container);
|
375
370
|
fireEvent.mouseEnter(container);
|
376
371
|
expect(screen.queryByRole('tooltip')).not.toBeInTheDocument();
|
377
|
-
var button = screen.getByLabelText('copy');
|
372
|
+
var button = screen.getByLabelText('copy to clipboard');
|
378
373
|
fireEvent.mouseMove(button);
|
379
374
|
fireEvent.mouseEnter(button);
|
380
375
|
expect(screen.queryByRole('tooltip')).toBeInTheDocument();
|
381
376
|
});
|
382
377
|
test('copy button is focused with keyboard', function () {
|
383
378
|
getComponent();
|
384
|
-
var copyBtn = screen.getByLabelText('copy');
|
379
|
+
var copyBtn = screen.getByLabelText('copy to clipboard');
|
385
380
|
expect(copyBtn).not.toHaveFocus();
|
386
381
|
userEvent.tab();
|
387
382
|
userEvent.tab();
|
@@ -405,7 +400,7 @@ describe('Link mode', function () {
|
|
405
400
|
switch (_context16.prev = _context16.next) {
|
406
401
|
case 0:
|
407
402
|
getComponent();
|
408
|
-
button = screen.getByLabelText('copy');
|
403
|
+
button = screen.getByLabelText('copy to clipboard');
|
409
404
|
_context16.next = 4;
|
410
405
|
return act( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee15() {
|
411
406
|
return _regeneratorRuntime.wrap(function _callee15$(_context15) {
|
@@ -20,7 +20,7 @@ function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (
|
|
20
20
|
|
21
21
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context = ownKeys(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context2 = ownKeys(Object(source))).call(_context2, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
22
22
|
|
23
|
-
import React, { forwardRef, useRef, useImperativeHandle, useState } from 'react';
|
23
|
+
import React, { forwardRef, useRef, useImperativeHandle, useState, useMemo } from 'react';
|
24
24
|
import PropTypes from 'prop-types';
|
25
25
|
import { Image as ThemeUIImage } from 'theme-ui';
|
26
26
|
import { useHover } from '@react-aria/interactions';
|
@@ -52,7 +52,12 @@ var Image = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
52
52
|
var _useState3 = useState(false),
|
53
53
|
_useState4 = _slicedToArray(_useState3, 2),
|
54
54
|
loadedSuccessfully = _useState4[0],
|
55
|
-
setLoadedSuccessfully = _useState4[1];
|
55
|
+
setLoadedSuccessfully = _useState4[1];
|
56
|
+
|
57
|
+
var _useState5 = useState(false),
|
58
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
59
|
+
hasTimedOut = _useState6[0],
|
60
|
+
setHasTimedOut = _useState6[1]; // we need to use useRef here with useState so it will be updated in setTimeout and onload
|
56
61
|
// https://github.com/facebook/react/issues/14010#issuecomment-433788147
|
57
62
|
|
58
63
|
|
@@ -63,11 +68,17 @@ var Image = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
63
68
|
isLoadingRef.current = newState;
|
64
69
|
};
|
65
70
|
|
66
|
-
var
|
67
|
-
|
68
|
-
|
69
|
-
|
71
|
+
var setImgSrc = function setImgSrc() {
|
72
|
+
if (!loadedSuccessfully && !(isLoadingRef !== null && isLoadingRef !== void 0 && isLoadingRef.current) || hasTimedOut) {
|
73
|
+
return fallbackImage;
|
74
|
+
}
|
75
|
+
|
76
|
+
return src;
|
77
|
+
};
|
70
78
|
|
79
|
+
var imgSrc = useMemo(function () {
|
80
|
+
return setImgSrc();
|
81
|
+
}, [src, isLoading, hasTimedOut]);
|
71
82
|
var imgRef = useRef();
|
72
83
|
/* istanbul ignore next */
|
73
84
|
|
@@ -90,20 +101,18 @@ var Image = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
90
101
|
var onImageLoad = function onImageLoad() {
|
91
102
|
if (isLoadingRef !== null && isLoadingRef !== void 0 && isLoadingRef.current) {
|
92
103
|
setIsLoadingWithRef(false);
|
93
|
-
setImgSrc(src);
|
94
104
|
setLoadedSuccessfully(true);
|
95
105
|
}
|
96
106
|
};
|
97
107
|
|
98
108
|
var onImageError = function onImageError() {
|
99
109
|
setIsLoadingWithRef(false);
|
100
|
-
setImgSrc(fallbackImage || null);
|
101
110
|
};
|
102
111
|
|
103
112
|
var onFallbackTimeout = function onFallbackTimeout() {
|
104
113
|
if (isLoadingRef !== null && isLoadingRef !== void 0 && isLoadingRef.current) {
|
105
114
|
setIsLoadingWithRef(false);
|
106
|
-
|
115
|
+
setHasTimedOut(true);
|
107
116
|
}
|
108
117
|
};
|
109
118
|
|
@@ -1,9 +1,11 @@
|
|
1
|
+
import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
|
1
2
|
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
2
|
-
import React from 'react';
|
3
|
+
import React, { useState } from 'react';
|
3
4
|
import isChromatic from 'chromatic/isChromatic';
|
4
5
|
import Image from '.';
|
5
6
|
import { chiefIdentityChampions, pingImg } from './imageConstants';
|
6
7
|
import { htmlElements } from '../../utils/devUtils/constants/htmlElements';
|
8
|
+
import { Box, Button } from '../../index';
|
7
9
|
import { jsx as ___EmotionJSX } from "@emotion/react";
|
8
10
|
export default {
|
9
11
|
title: 'Image',
|
@@ -90,4 +92,30 @@ export var WithSkeletonLoadTimeout = function WithSkeletonLoadTimeout() {
|
|
90
92
|
height: '150px'
|
91
93
|
}
|
92
94
|
});
|
95
|
+
};
|
96
|
+
export var UpdatingImageSrc = function UpdatingImageSrc() {
|
97
|
+
var _useState = useState(chiefIdentityChampions),
|
98
|
+
_useState2 = _slicedToArray(_useState, 2),
|
99
|
+
image = _useState2[0],
|
100
|
+
setImage = _useState2[1];
|
101
|
+
|
102
|
+
var handleButtonPress = function handleButtonPress() {
|
103
|
+
var src = image === pingImg ? chiefIdentityChampions : pingImg;
|
104
|
+
setImage(src);
|
105
|
+
};
|
106
|
+
|
107
|
+
return ___EmotionJSX(Box, {
|
108
|
+
sx: {
|
109
|
+
width: '200px'
|
110
|
+
}
|
111
|
+
}, ___EmotionJSX(Button, {
|
112
|
+
onPress: handleButtonPress
|
113
|
+
}, "Change Image"), ___EmotionJSX(Image, {
|
114
|
+
src: image,
|
115
|
+
sx: {
|
116
|
+
width: '200px',
|
117
|
+
height: '200px',
|
118
|
+
mt: '25px'
|
119
|
+
}
|
120
|
+
}));
|
93
121
|
};
|
@@ -29,7 +29,12 @@ var defaultProps = {
|
|
29
29
|
|
30
30
|
var getComponent = function getComponent() {
|
31
31
|
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
32
|
-
|
32
|
+
|
33
|
+
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
34
|
+
_ref$renderFn = _ref.renderFn,
|
35
|
+
renderFn = _ref$renderFn === void 0 ? render : _ref$renderFn;
|
36
|
+
|
37
|
+
return renderFn(___EmotionJSX(Image, _extends({}, defaultProps, props)));
|
33
38
|
}; // Need to be added to each test file to test accessibility using axe.
|
34
39
|
|
35
40
|
|
@@ -71,6 +76,26 @@ test('image shows disabled status', function () {
|
|
71
76
|
var img = screen.getByRole('img');
|
72
77
|
expect(img).toHaveClass('is-disabled');
|
73
78
|
});
|
79
|
+
test('image source is able to be changed', function () {
|
80
|
+
var src2 = 'second-src';
|
81
|
+
|
82
|
+
var _getComponent = getComponent(),
|
83
|
+
rerender = _getComponent.rerender;
|
84
|
+
|
85
|
+
act(function () {
|
86
|
+
fallbackImageObj.onImageLoad();
|
87
|
+
});
|
88
|
+
expect(screen.getByRole('img')).toHaveAttribute('src', testSrc);
|
89
|
+
getComponent({
|
90
|
+
src: src2
|
91
|
+
}, {
|
92
|
+
renderFn: rerender
|
93
|
+
});
|
94
|
+
act(function () {
|
95
|
+
fallbackImageObj.onImageLoad();
|
96
|
+
});
|
97
|
+
expect(screen.getByRole('img')).toHaveAttribute('src', src2);
|
98
|
+
});
|
74
99
|
describe('test Image component with useFallbackImage hook', function () {
|
75
100
|
test('image component will use src if loaded correctly', function () {
|
76
101
|
getComponent();
|
@@ -27,6 +27,7 @@ import { MenuContext } from '../../context/MenuContext';
|
|
27
27
|
import { usePropWarning } from '../../hooks';
|
28
28
|
import MenuItem from '../MenuItem';
|
29
29
|
import Box from '../Box';
|
30
|
+
import ORIENTATION from '../../utils/devUtils/constants/orientation';
|
30
31
|
/**
|
31
32
|
* Menu component intended to be used as a wrapper for MenuItem.
|
32
33
|
* This component is typically used alongside others such as PopoverMenu.
|
@@ -71,7 +72,8 @@ var Menu = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
71
72
|
return ___EmotionJSX(Box, _extends({
|
72
73
|
as: "ul",
|
73
74
|
ref: menuRef,
|
74
|
-
variant: "menu"
|
75
|
+
variant: "menu",
|
76
|
+
"aria-orientation": ORIENTATION.VERTICAL
|
75
77
|
}, others, mergeProps(focusProps, menuProps)), _mapInstanceProperty(_context = _Array$from(state.collection)).call(_context, function (item) {
|
76
78
|
return ___EmotionJSX(MenuItem, {
|
77
79
|
key: item.key,
|
@@ -7,6 +7,7 @@ import userEvent from '@testing-library/user-event';
|
|
7
7
|
import axeTest from '../../utils/testUtils/testAxe';
|
8
8
|
import { render, screen, fireEvent } from '../../utils/testUtils/testWrapper';
|
9
9
|
import { Menu, Item } from '../../index';
|
10
|
+
import ORIENTATION from '../../utils/devUtils/constants/orientation';
|
10
11
|
import { jsx as ___EmotionJSX } from "@emotion/react";
|
11
12
|
var testTitle = 'Test Title';
|
12
13
|
var defaultProps = {
|
@@ -41,6 +42,7 @@ test('should render basic menu with children', function () {
|
|
41
42
|
expect(menu).toBeInTheDocument();
|
42
43
|
var menuItems = screen.queryAllByRole('menuitem');
|
43
44
|
expect(menuItems).toHaveLength(3);
|
45
|
+
expect(menu).toHaveAttribute('aria-orientation', ORIENTATION.VERTICAL);
|
44
46
|
});
|
45
47
|
test('should render items when selectionMode is set to single', function () {
|
46
48
|
getComponent({
|