@pingux/astro 2.42.0 → 2.43.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/components/Image/Image.d.ts +4 -0
- package/lib/cjs/components/Image/Image.js +12 -50
- package/lib/cjs/components/Image/Image.stories.d.ts +43 -0
- package/lib/cjs/components/Image/Image.stories.js +2 -6
- package/lib/cjs/components/Image/Image.styles.d.ts +9 -0
- package/lib/cjs/components/Image/Image.test.d.ts +1 -0
- package/lib/cjs/components/Image/Image.test.js +50 -24
- package/lib/cjs/components/Image/index.d.ts +1 -0
- package/lib/cjs/types/image.d.ts +18 -0
- package/lib/cjs/types/image.js +6 -0
- package/lib/components/Image/Image.js +10 -50
- package/lib/components/Image/Image.stories.js +2 -6
- package/lib/components/Image/Image.test.js +50 -24
- package/lib/types/image.js +1 -0
- package/package.json +2 -1
@@ -1,15 +1,9 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
3
|
var _typeof = require("@babel/runtime-corejs3/helpers/typeof");
|
4
|
-
var _Object$keys = require("@babel/runtime-corejs3/core-js-stable/object/keys");
|
5
|
-
var _Object$getOwnPropertySymbols = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols");
|
6
|
-
var _filterInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/filter");
|
7
|
-
var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor");
|
8
|
-
var _forEachInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/for-each");
|
9
|
-
var _Object$getOwnPropertyDescriptors = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors");
|
10
|
-
var _Object$defineProperties = require("@babel/runtime-corejs3/core-js-stable/object/define-properties");
|
11
|
-
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
12
4
|
var _WeakMap = require("@babel/runtime-corejs3/core-js-stable/weak-map");
|
5
|
+
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
6
|
+
var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor");
|
13
7
|
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
14
8
|
_Object$defineProperty(exports, "__esModule", {
|
15
9
|
value: true
|
@@ -17,13 +11,11 @@ _Object$defineProperty(exports, "__esModule", {
|
|
17
11
|
exports["default"] = void 0;
|
18
12
|
var _extends2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/extends"));
|
19
13
|
var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/taggedTemplateLiteral"));
|
20
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
|
21
14
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/slicedToArray"));
|
22
15
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/objectWithoutProperties"));
|
23
16
|
var _react = _interopRequireWildcard(require("react"));
|
24
17
|
var _react2 = require("@emotion/react");
|
25
18
|
var _interactions = require("@react-aria/interactions");
|
26
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
27
19
|
var _themeUi = require("theme-ui");
|
28
20
|
var _hooks = require("../../hooks");
|
29
21
|
var _index = require("../../index");
|
@@ -32,12 +24,11 @@ var _templateObject;
|
|
32
24
|
var _excluded = ["className", "fallbackImage", "fallbackTimeout", "isDisabled", "src", "alt", "sx", "fallbackAlt"];
|
33
25
|
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); }
|
34
26
|
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; }
|
35
|
-
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; }
|
36
|
-
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) { (0, _defineProperty2["default"])(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; }
|
37
27
|
var Image = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
38
28
|
var className = props.className,
|
39
29
|
fallbackImage = props.fallbackImage,
|
40
|
-
|
30
|
+
_props$fallbackTimeou = props.fallbackTimeout,
|
31
|
+
fallbackTimeout = _props$fallbackTimeou === void 0 ? 5000 : _props$fallbackTimeou,
|
41
32
|
isDisabled = props.isDisabled,
|
42
33
|
src = props.src,
|
43
34
|
alt = props.alt,
|
@@ -111,29 +102,28 @@ var Image = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
111
102
|
setShouldShowFallback(true);
|
112
103
|
}
|
113
104
|
};
|
114
|
-
(0, _hooks.useFallbackImage)(
|
105
|
+
(0, _hooks.useFallbackImage)({
|
115
106
|
onImageLoad: onImageLoad,
|
116
107
|
onImageError: onImageError,
|
117
|
-
onFallbackTimeout: onFallbackTimeout
|
118
|
-
|
108
|
+
onFallbackTimeout: onFallbackTimeout,
|
109
|
+
fallbackTimeout: fallbackTimeout,
|
110
|
+
src: src || ''
|
111
|
+
});
|
119
112
|
var skeletonFrames = (0, _react2.keyframes)(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2["default"])(["\n 0% {\n background-color: ", ";\n }\n 100% {\n background-color: ", ";\n }\n"])), _colors.neutral[90], _colors.neutral[70]);
|
120
113
|
var skeletonSx = {
|
121
114
|
backgroundImage: !isLoading && 'url("data:image/svg+xml,%3Csvg xmlns=\'http://www.w3.org/2000/svg\' width=\'150\' height=\'150\'%3E%3Crect x=\'0\' y=\'0\' width=\'150\' height=\'150\' fill=\'%23e4e6e9\' /%3E%3C/svg%3E")',
|
122
|
-
// eslint-disable-next-line react/prop-types
|
123
115
|
width: (sx === null || sx === void 0 ? void 0 : sx.width) || '100%',
|
124
|
-
// eslint-disable-next-line react/prop-types
|
125
116
|
height: (sx === null || sx === void 0 ? void 0 : sx.height) || '100%',
|
126
117
|
animation: isLoading && "".concat(skeletonFrames, " 1.5s ease-in-out 0.5s infinite alternate")
|
127
118
|
};
|
128
|
-
var Skeleton = function Skeleton(
|
129
|
-
var children = _ref.children;
|
119
|
+
var Skeleton = function Skeleton() {
|
130
120
|
return (0, _react2.jsx)(_index.Box, {
|
131
121
|
role: "img",
|
132
122
|
sx: skeletonSx,
|
133
123
|
"data-testid": "skeleton-image",
|
134
124
|
"aria-busy": isLoading,
|
135
125
|
"aria-label": isLoading ? 'Image is loading' : 'Loading of image timed out'
|
136
|
-
}
|
126
|
+
});
|
137
127
|
};
|
138
128
|
var themeUiImage = (0, _react2.jsx)(_themeUi.Image, (0, _extends2["default"])({
|
139
129
|
alt: imgAlt,
|
@@ -149,37 +139,9 @@ var Image = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
149
139
|
}
|
150
140
|
return themeUiImage;
|
151
141
|
});
|
152
|
-
Image.propTypes = {
|
153
|
-
/** The styling variation of the image. */
|
154
|
-
variant: _propTypes["default"].string,
|
155
|
-
/** Whether the image is disabled; applies disabled styling. */
|
156
|
-
isDisabled: _propTypes["default"].bool,
|
157
|
-
/** The HTML element used to render the image. */
|
158
|
-
as: _propTypes["default"].string,
|
159
|
-
/** Source of image(Image path). */
|
160
|
-
src: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].object]),
|
161
|
-
/** Load failure fault-tolerant src
|
162
|
-
* We do recommend using JS File or Blob object as an src for the "fallbackImage".
|
163
|
-
* Here is some documentation on how to create a blob image [https://developer.mozilla.org/en-US/docs/Web/API/Blob].
|
164
|
-
* Also please note that URLs are accepted, but if the URL cannot be loaded,
|
165
|
-
* the fallback image will not be rendered so it's not recommended.
|
166
|
-
* */
|
167
|
-
fallbackImage: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].object]),
|
168
|
-
/** Time in milliseconds that component should wait for a response from src address. */
|
169
|
-
fallbackTimeout: _propTypes["default"].number,
|
170
|
-
/** Descriptive text for an image. This is *highly* recommended in most cases.
|
171
|
-
* See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#attr-alt).
|
172
|
-
* */
|
173
|
-
alt: _propTypes["default"].string,
|
174
|
-
/** Load failure fault-tolerant alt */
|
175
|
-
fallbackAlt: _propTypes["default"].string,
|
176
|
-
/** Defines a string value that labels the current element. */
|
177
|
-
'aria-label': _propTypes["default"].string
|
178
|
-
};
|
179
142
|
Image.defaultProps = {
|
180
143
|
isDisabled: false,
|
181
|
-
as: 'img'
|
182
|
-
fallbackTimeout: 5000
|
144
|
+
as: 'img'
|
183
145
|
};
|
184
146
|
Image.displayName = 'Image';
|
185
147
|
var _default = Image;
|
@@ -0,0 +1,43 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { StoryFn } from '@storybook/react';
|
3
|
+
declare const _default: {
|
4
|
+
title: string;
|
5
|
+
component: React.ForwardRefExoticComponent<Omit<import("../../types/image").ImageProps, "ref"> & React.RefAttributes<HTMLImageElement>>;
|
6
|
+
parameters: {
|
7
|
+
docs: {
|
8
|
+
page: () => React.JSX.Element;
|
9
|
+
};
|
10
|
+
};
|
11
|
+
argTypes: {
|
12
|
+
isDisabled: {};
|
13
|
+
variant: {
|
14
|
+
control: {
|
15
|
+
type: string;
|
16
|
+
};
|
17
|
+
};
|
18
|
+
as: {
|
19
|
+
control: {
|
20
|
+
type: string;
|
21
|
+
options: any;
|
22
|
+
};
|
23
|
+
};
|
24
|
+
src: {
|
25
|
+
control: {
|
26
|
+
type: string;
|
27
|
+
};
|
28
|
+
};
|
29
|
+
};
|
30
|
+
args: {
|
31
|
+
as: string;
|
32
|
+
src: string;
|
33
|
+
};
|
34
|
+
};
|
35
|
+
export default _default;
|
36
|
+
export declare const Default: StoryFn;
|
37
|
+
export declare const Avatar: StoryFn;
|
38
|
+
export declare const CustomSizeAndRadius: StoryFn;
|
39
|
+
export declare const Disabled: StoryFn;
|
40
|
+
export declare const FallbackImage: StoryFn;
|
41
|
+
export declare const WithSkeletonLoadSuccess: StoryFn;
|
42
|
+
export declare const WithSkeletonLoadTimeout: StoryFn;
|
43
|
+
export declare const UpdatingImageSrc: StoryFn;
|
@@ -106,9 +106,8 @@ var FallbackImage = function FallbackImage() {
|
|
106
106
|
});
|
107
107
|
};
|
108
108
|
exports.FallbackImage = FallbackImage;
|
109
|
-
var WithSkeletonLoadSuccess = function WithSkeletonLoadSuccess(
|
110
|
-
var
|
111
|
-
var imageSrc = useLocalSrc ? _images.pingImg : 'https://app.requestly.io/delay/3000/https://picsum.photos/150/150';
|
109
|
+
var WithSkeletonLoadSuccess = function WithSkeletonLoadSuccess() {
|
110
|
+
var imageSrc = (0, _isChromatic["default"])() ? _images.pingImg : 'https://app.requestly.io/delay/3000/https://picsum.photos/150/150';
|
112
111
|
return (0, _react2.jsx)(_index.Image, {
|
113
112
|
src: imageSrc,
|
114
113
|
sx: {
|
@@ -119,9 +118,6 @@ var WithSkeletonLoadSuccess = function WithSkeletonLoadSuccess(_ref2) {
|
|
119
118
|
});
|
120
119
|
};
|
121
120
|
exports.WithSkeletonLoadSuccess = WithSkeletonLoadSuccess;
|
122
|
-
WithSkeletonLoadSuccess.args = {
|
123
|
-
useLocalSrc: (0, _isChromatic["default"])()
|
124
|
-
};
|
125
121
|
var WithSkeletonLoadTimeout = function WithSkeletonLoadTimeout() {
|
126
122
|
return (0, _react2.jsx)(_index.Image, {
|
127
123
|
src: "https://app.requestly.io/delay/7000/https://picsum.photos/150/150",
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -53,7 +53,9 @@ jest.mock('../../hooks/useFallbackImage', function () {
|
|
53
53
|
test('an image is rendered', function () {
|
54
54
|
getComponent();
|
55
55
|
(0, _react2.act)(function () {
|
56
|
-
fallbackImageObj
|
56
|
+
if (fallbackImageObj) {
|
57
|
+
fallbackImageObj.onImageLoad();
|
58
|
+
}
|
57
59
|
});
|
58
60
|
var img = _testWrapper.screen.getByRole('img');
|
59
61
|
expect(img).toBeInstanceOf(HTMLImageElement);
|
@@ -61,10 +63,12 @@ test('an image is rendered', function () {
|
|
61
63
|
});
|
62
64
|
test('an image is rendered with no fallback', function () {
|
63
65
|
getComponent({
|
64
|
-
fallbackImage:
|
66
|
+
fallbackImage: undefined
|
65
67
|
});
|
66
68
|
(0, _react2.act)(function () {
|
67
|
-
fallbackImageObj
|
69
|
+
if (fallbackImageObj) {
|
70
|
+
fallbackImageObj.onImageLoad();
|
71
|
+
}
|
68
72
|
});
|
69
73
|
var img = _testWrapper.screen.getByRole('img');
|
70
74
|
expect(img).toBeInstanceOf(HTMLImageElement);
|
@@ -75,7 +79,9 @@ test('image shows disabled status', function () {
|
|
75
79
|
isDisabled: true
|
76
80
|
});
|
77
81
|
(0, _react2.act)(function () {
|
78
|
-
fallbackImageObj
|
82
|
+
if (fallbackImageObj) {
|
83
|
+
fallbackImageObj.onImageLoad();
|
84
|
+
}
|
79
85
|
});
|
80
86
|
var img = _testWrapper.screen.getByRole('img');
|
81
87
|
expect(img).toHaveClass('is-disabled');
|
@@ -85,7 +91,9 @@ test('image with alt text', function () {
|
|
85
91
|
alt: 'Test'
|
86
92
|
});
|
87
93
|
(0, _react2.act)(function () {
|
88
|
-
fallbackImageObj
|
94
|
+
if (fallbackImageObj) {
|
95
|
+
fallbackImageObj.onImageLoad();
|
96
|
+
}
|
89
97
|
});
|
90
98
|
expect(_testWrapper.screen.getByAltText('Test')).toBeInTheDocument();
|
91
99
|
});
|
@@ -94,16 +102,18 @@ test('image source is able to be changed', function () {
|
|
94
102
|
var _getComponent = getComponent(),
|
95
103
|
rerender = _getComponent.rerender;
|
96
104
|
(0, _react2.act)(function () {
|
97
|
-
fallbackImageObj
|
105
|
+
if (fallbackImageObj) {
|
106
|
+
fallbackImageObj.onImageLoad();
|
107
|
+
}
|
98
108
|
});
|
99
109
|
expect(_testWrapper.screen.getByRole('img')).toHaveAttribute('src', testSrc);
|
100
|
-
|
110
|
+
rerender((0, _react3.jsx)(_["default"], (0, _extends2["default"])({}, defaultProps, {
|
101
111
|
src: src2
|
102
|
-
}
|
103
|
-
renderFn: rerender
|
104
|
-
});
|
112
|
+
})));
|
105
113
|
(0, _react2.act)(function () {
|
106
|
-
fallbackImageObj
|
114
|
+
if (fallbackImageObj) {
|
115
|
+
fallbackImageObj.onImageLoad();
|
116
|
+
}
|
107
117
|
});
|
108
118
|
expect(_testWrapper.screen.getByRole('img')).toHaveAttribute('src', src2);
|
109
119
|
});
|
@@ -111,14 +121,18 @@ describe('test Image component with useFallbackImage hook', function () {
|
|
111
121
|
test('image component will use src if loaded correctly', function () {
|
112
122
|
getComponent();
|
113
123
|
(0, _react2.act)(function () {
|
114
|
-
fallbackImageObj
|
124
|
+
if (fallbackImageObj) {
|
125
|
+
fallbackImageObj.onImageLoad();
|
126
|
+
}
|
115
127
|
});
|
116
128
|
expect(_testWrapper.screen.getByRole('img')).toHaveAttribute('src', testSrc);
|
117
129
|
});
|
118
130
|
test('image component will use fallbackImg and fallbackAlt if src loaded with error', function () {
|
119
131
|
getComponent();
|
120
132
|
(0, _react2.act)(function () {
|
121
|
-
fallbackImageObj
|
133
|
+
if (fallbackImageObj) {
|
134
|
+
fallbackImageObj.onImageError();
|
135
|
+
}
|
122
136
|
});
|
123
137
|
var img = _testWrapper.screen.getByRole('img');
|
124
138
|
expect(img).toHaveAttribute('src', testFallbackSrc);
|
@@ -127,7 +141,9 @@ describe('test Image component with useFallbackImage hook', function () {
|
|
127
141
|
test('image component will use fallbackImg and fallbackAlt if src timed out', function () {
|
128
142
|
getComponent();
|
129
143
|
(0, _react2.act)(function () {
|
130
|
-
fallbackImageObj
|
144
|
+
if (fallbackImageObj) {
|
145
|
+
fallbackImageObj.onFallbackTimeout();
|
146
|
+
}
|
131
147
|
});
|
132
148
|
var img = _testWrapper.screen.getByRole('img');
|
133
149
|
expect(img).toHaveAttribute('src', testFallbackSrc);
|
@@ -136,8 +152,10 @@ describe('test Image component with useFallbackImage hook', function () {
|
|
136
152
|
test('if image loads after timeout src and alt still be the fallback', function () {
|
137
153
|
getComponent();
|
138
154
|
(0, _react2.act)(function () {
|
139
|
-
fallbackImageObj
|
140
|
-
|
155
|
+
if (fallbackImageObj) {
|
156
|
+
fallbackImageObj.onFallbackTimeout();
|
157
|
+
fallbackImageObj.onImageLoad();
|
158
|
+
}
|
141
159
|
});
|
142
160
|
var img = _testWrapper.screen.getByRole('img');
|
143
161
|
expect(img).toHaveAttribute('src', testFallbackSrc);
|
@@ -146,36 +164,44 @@ describe('test Image component with useFallbackImage hook', function () {
|
|
146
164
|
test('if image loads before timeout src still be the the origin one', function () {
|
147
165
|
getComponent();
|
148
166
|
(0, _react2.act)(function () {
|
149
|
-
fallbackImageObj
|
150
|
-
|
167
|
+
if (fallbackImageObj) {
|
168
|
+
fallbackImageObj.onImageLoad();
|
169
|
+
fallbackImageObj.onFallbackTimeout();
|
170
|
+
}
|
151
171
|
});
|
152
172
|
expect(_testWrapper.screen.getByRole('img')).toHaveAttribute('src', testSrc);
|
153
173
|
});
|
154
174
|
test('the skeleton loading will appear if no fallback image is given', function () {
|
155
175
|
getComponent({
|
156
|
-
fallbackImage:
|
176
|
+
fallbackImage: undefined
|
157
177
|
});
|
158
178
|
expect(_testWrapper.screen.getByTestId(skeletonImageId)).toBeInTheDocument();
|
159
179
|
(0, _react2.act)(function () {
|
160
|
-
fallbackImageObj
|
180
|
+
if (fallbackImageObj) {
|
181
|
+
fallbackImageObj.onImageLoad();
|
182
|
+
}
|
161
183
|
});
|
162
184
|
expect(_testWrapper.screen.getByRole('img')).toHaveAttribute('src', testSrc);
|
163
185
|
});
|
164
186
|
test('the skeleton will be shown instead of img if no fallback image is given and image load failed', function () {
|
165
187
|
getComponent({
|
166
|
-
fallbackImage:
|
188
|
+
fallbackImage: undefined
|
167
189
|
});
|
168
190
|
(0, _react2.act)(function () {
|
169
|
-
fallbackImageObj
|
191
|
+
if (fallbackImageObj) {
|
192
|
+
fallbackImageObj.onImageError();
|
193
|
+
}
|
170
194
|
});
|
171
195
|
expect(_testWrapper.screen.getByTestId(skeletonImageId)).toBeInTheDocument();
|
172
196
|
});
|
173
197
|
test('the skeleton will be shown instead of img if no fallback image is given and image load timed out', function () {
|
174
198
|
getComponent({
|
175
|
-
fallbackImage:
|
199
|
+
fallbackImage: undefined
|
176
200
|
});
|
177
201
|
(0, _react2.act)(function () {
|
178
|
-
fallbackImageObj
|
202
|
+
if (fallbackImageObj) {
|
203
|
+
fallbackImageObj.onFallbackTimeout();
|
204
|
+
}
|
179
205
|
});
|
180
206
|
expect(_testWrapper.screen.getByTestId(skeletonImageId)).toBeInTheDocument();
|
181
207
|
});
|
@@ -0,0 +1 @@
|
|
1
|
+
export { default } from './Image';
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import { ImageProps as ThemeUIImageProps, ThemeUICSSObject } from 'theme-ui';
|
2
|
+
export interface ImageProps extends ThemeUIImageProps {
|
3
|
+
/** Whether the image is disabled; applies disabled styling. */
|
4
|
+
isDisabled?: boolean;
|
5
|
+
/** Load failure fault-tolerant src
|
6
|
+
* We do recommend using JS File or Blob object as an src for the "fallbackImage".
|
7
|
+
* Here is some documentation on how to create a blob image [https://developer.mozilla.org/en-US/docs/Web/API/Blob].
|
8
|
+
* Also please note that URLs are accepted, but if the URL cannot be loaded,
|
9
|
+
* the fallback image will not be rendered so it's not recommended.
|
10
|
+
* */
|
11
|
+
fallbackImage?: string | object;
|
12
|
+
/** Load failure fault-tolerant alt */
|
13
|
+
fallbackAlt?: string;
|
14
|
+
/** Time in milliseconds that component should wait for a response from src address. */
|
15
|
+
fallbackTimeout?: number;
|
16
|
+
/** Inline styling prop for item */
|
17
|
+
sx?: ThemeUICSSObject;
|
18
|
+
}
|
@@ -1,24 +1,12 @@
|
|
1
|
-
import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
|
2
|
-
import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
|
3
|
-
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
4
|
-
import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor";
|
5
|
-
import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
|
6
|
-
import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
|
7
|
-
import _Object$defineProperties from "@babel/runtime-corejs3/core-js-stable/object/define-properties";
|
8
|
-
import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object/define-property";
|
9
1
|
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
10
2
|
import _taggedTemplateLiteral from "@babel/runtime-corejs3/helpers/esm/taggedTemplateLiteral";
|
11
|
-
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
12
3
|
import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
|
13
4
|
import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
|
14
5
|
var _templateObject;
|
15
6
|
var _excluded = ["className", "fallbackImage", "fallbackTimeout", "isDisabled", "src", "alt", "sx", "fallbackAlt"];
|
16
|
-
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; }
|
17
|
-
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; }
|
18
7
|
import React, { forwardRef, useImperativeHandle, useMemo, useRef, useState } from 'react';
|
19
8
|
import { keyframes } from '@emotion/react';
|
20
9
|
import { useHover } from '@react-aria/interactions';
|
21
|
-
import PropTypes from 'prop-types';
|
22
10
|
import { Image as ThemeUIImage } from 'theme-ui';
|
23
11
|
import { useAriaLabelWarning, useDevelopmentWarning, useFallbackImage, useLocalOrForwardRef, usePropWarning, useStatusClasses } from '../../hooks';
|
24
12
|
import { Box } from '../../index';
|
@@ -27,7 +15,8 @@ import { jsx as ___EmotionJSX } from "@emotion/react";
|
|
27
15
|
var Image = /*#__PURE__*/forwardRef(function (props, ref) {
|
28
16
|
var className = props.className,
|
29
17
|
fallbackImage = props.fallbackImage,
|
30
|
-
|
18
|
+
_props$fallbackTimeou = props.fallbackTimeout,
|
19
|
+
fallbackTimeout = _props$fallbackTimeou === void 0 ? 5000 : _props$fallbackTimeou,
|
31
20
|
isDisabled = props.isDisabled,
|
32
21
|
src = props.src,
|
33
22
|
alt = props.alt,
|
@@ -101,29 +90,28 @@ var Image = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
101
90
|
setShouldShowFallback(true);
|
102
91
|
}
|
103
92
|
};
|
104
|
-
useFallbackImage(
|
93
|
+
useFallbackImage({
|
105
94
|
onImageLoad: onImageLoad,
|
106
95
|
onImageError: onImageError,
|
107
|
-
onFallbackTimeout: onFallbackTimeout
|
108
|
-
|
96
|
+
onFallbackTimeout: onFallbackTimeout,
|
97
|
+
fallbackTimeout: fallbackTimeout,
|
98
|
+
src: src || ''
|
99
|
+
});
|
109
100
|
var skeletonFrames = keyframes(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n 0% {\n background-color: ", ";\n }\n 100% {\n background-color: ", ";\n }\n"])), neutral[90], neutral[70]);
|
110
101
|
var skeletonSx = {
|
111
102
|
backgroundImage: !isLoading && 'url("data:image/svg+xml,%3Csvg xmlns=\'http://www.w3.org/2000/svg\' width=\'150\' height=\'150\'%3E%3Crect x=\'0\' y=\'0\' width=\'150\' height=\'150\' fill=\'%23e4e6e9\' /%3E%3C/svg%3E")',
|
112
|
-
// eslint-disable-next-line react/prop-types
|
113
103
|
width: (sx === null || sx === void 0 ? void 0 : sx.width) || '100%',
|
114
|
-
// eslint-disable-next-line react/prop-types
|
115
104
|
height: (sx === null || sx === void 0 ? void 0 : sx.height) || '100%',
|
116
105
|
animation: isLoading && "".concat(skeletonFrames, " 1.5s ease-in-out 0.5s infinite alternate")
|
117
106
|
};
|
118
|
-
var Skeleton = function Skeleton(
|
119
|
-
var children = _ref.children;
|
107
|
+
var Skeleton = function Skeleton() {
|
120
108
|
return ___EmotionJSX(Box, {
|
121
109
|
role: "img",
|
122
110
|
sx: skeletonSx,
|
123
111
|
"data-testid": "skeleton-image",
|
124
112
|
"aria-busy": isLoading,
|
125
113
|
"aria-label": isLoading ? 'Image is loading' : 'Loading of image timed out'
|
126
|
-
}
|
114
|
+
});
|
127
115
|
};
|
128
116
|
var themeUiImage = ___EmotionJSX(ThemeUIImage, _extends({
|
129
117
|
alt: imgAlt,
|
@@ -139,37 +127,9 @@ var Image = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
139
127
|
}
|
140
128
|
return themeUiImage;
|
141
129
|
});
|
142
|
-
Image.propTypes = {
|
143
|
-
/** The styling variation of the image. */
|
144
|
-
variant: PropTypes.string,
|
145
|
-
/** Whether the image is disabled; applies disabled styling. */
|
146
|
-
isDisabled: PropTypes.bool,
|
147
|
-
/** The HTML element used to render the image. */
|
148
|
-
as: PropTypes.string,
|
149
|
-
/** Source of image(Image path). */
|
150
|
-
src: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
|
151
|
-
/** Load failure fault-tolerant src
|
152
|
-
* We do recommend using JS File or Blob object as an src for the "fallbackImage".
|
153
|
-
* Here is some documentation on how to create a blob image [https://developer.mozilla.org/en-US/docs/Web/API/Blob].
|
154
|
-
* Also please note that URLs are accepted, but if the URL cannot be loaded,
|
155
|
-
* the fallback image will not be rendered so it's not recommended.
|
156
|
-
* */
|
157
|
-
fallbackImage: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
|
158
|
-
/** Time in milliseconds that component should wait for a response from src address. */
|
159
|
-
fallbackTimeout: PropTypes.number,
|
160
|
-
/** Descriptive text for an image. This is *highly* recommended in most cases.
|
161
|
-
* See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#attr-alt).
|
162
|
-
* */
|
163
|
-
alt: PropTypes.string,
|
164
|
-
/** Load failure fault-tolerant alt */
|
165
|
-
fallbackAlt: PropTypes.string,
|
166
|
-
/** Defines a string value that labels the current element. */
|
167
|
-
'aria-label': PropTypes.string
|
168
|
-
};
|
169
130
|
Image.defaultProps = {
|
170
131
|
isDisabled: false,
|
171
|
-
as: 'img'
|
172
|
-
fallbackTimeout: 5000
|
132
|
+
as: 'img'
|
173
133
|
};
|
174
134
|
Image.displayName = 'Image';
|
175
135
|
export default Image;
|
@@ -87,9 +87,8 @@ export var FallbackImage = function FallbackImage() {
|
|
87
87
|
alt: "Random image"
|
88
88
|
});
|
89
89
|
};
|
90
|
-
export var WithSkeletonLoadSuccess = function WithSkeletonLoadSuccess(
|
91
|
-
var
|
92
|
-
var imageSrc = useLocalSrc ? pingImg : 'https://app.requestly.io/delay/3000/https://picsum.photos/150/150';
|
90
|
+
export var WithSkeletonLoadSuccess = function WithSkeletonLoadSuccess() {
|
91
|
+
var imageSrc = isChromatic() ? pingImg : 'https://app.requestly.io/delay/3000/https://picsum.photos/150/150';
|
93
92
|
return ___EmotionJSX(Image, {
|
94
93
|
src: imageSrc,
|
95
94
|
sx: {
|
@@ -99,9 +98,6 @@ export var WithSkeletonLoadSuccess = function WithSkeletonLoadSuccess(_ref2) {
|
|
99
98
|
alt: "Random image"
|
100
99
|
});
|
101
100
|
};
|
102
|
-
WithSkeletonLoadSuccess.args = {
|
103
|
-
useLocalSrc: isChromatic()
|
104
|
-
};
|
105
101
|
export var WithSkeletonLoadTimeout = function WithSkeletonLoadTimeout() {
|
106
102
|
return ___EmotionJSX(Image, {
|
107
103
|
src: "https://app.requestly.io/delay/7000/https://picsum.photos/150/150",
|
@@ -50,7 +50,9 @@ jest.mock('../../hooks/useFallbackImage', function () {
|
|
50
50
|
test('an image is rendered', function () {
|
51
51
|
getComponent();
|
52
52
|
act(function () {
|
53
|
-
fallbackImageObj
|
53
|
+
if (fallbackImageObj) {
|
54
|
+
fallbackImageObj.onImageLoad();
|
55
|
+
}
|
54
56
|
});
|
55
57
|
var img = screen.getByRole('img');
|
56
58
|
expect(img).toBeInstanceOf(HTMLImageElement);
|
@@ -58,10 +60,12 @@ test('an image is rendered', function () {
|
|
58
60
|
});
|
59
61
|
test('an image is rendered with no fallback', function () {
|
60
62
|
getComponent({
|
61
|
-
fallbackImage:
|
63
|
+
fallbackImage: undefined
|
62
64
|
});
|
63
65
|
act(function () {
|
64
|
-
fallbackImageObj
|
66
|
+
if (fallbackImageObj) {
|
67
|
+
fallbackImageObj.onImageLoad();
|
68
|
+
}
|
65
69
|
});
|
66
70
|
var img = screen.getByRole('img');
|
67
71
|
expect(img).toBeInstanceOf(HTMLImageElement);
|
@@ -72,7 +76,9 @@ test('image shows disabled status', function () {
|
|
72
76
|
isDisabled: true
|
73
77
|
});
|
74
78
|
act(function () {
|
75
|
-
fallbackImageObj
|
79
|
+
if (fallbackImageObj) {
|
80
|
+
fallbackImageObj.onImageLoad();
|
81
|
+
}
|
76
82
|
});
|
77
83
|
var img = screen.getByRole('img');
|
78
84
|
expect(img).toHaveClass('is-disabled');
|
@@ -82,7 +88,9 @@ test('image with alt text', function () {
|
|
82
88
|
alt: 'Test'
|
83
89
|
});
|
84
90
|
act(function () {
|
85
|
-
fallbackImageObj
|
91
|
+
if (fallbackImageObj) {
|
92
|
+
fallbackImageObj.onImageLoad();
|
93
|
+
}
|
86
94
|
});
|
87
95
|
expect(screen.getByAltText('Test')).toBeInTheDocument();
|
88
96
|
});
|
@@ -91,16 +99,18 @@ test('image source is able to be changed', function () {
|
|
91
99
|
var _getComponent = getComponent(),
|
92
100
|
rerender = _getComponent.rerender;
|
93
101
|
act(function () {
|
94
|
-
fallbackImageObj
|
102
|
+
if (fallbackImageObj) {
|
103
|
+
fallbackImageObj.onImageLoad();
|
104
|
+
}
|
95
105
|
});
|
96
106
|
expect(screen.getByRole('img')).toHaveAttribute('src', testSrc);
|
97
|
-
|
107
|
+
rerender(___EmotionJSX(Image, _extends({}, defaultProps, {
|
98
108
|
src: src2
|
99
|
-
}
|
100
|
-
renderFn: rerender
|
101
|
-
});
|
109
|
+
})));
|
102
110
|
act(function () {
|
103
|
-
fallbackImageObj
|
111
|
+
if (fallbackImageObj) {
|
112
|
+
fallbackImageObj.onImageLoad();
|
113
|
+
}
|
104
114
|
});
|
105
115
|
expect(screen.getByRole('img')).toHaveAttribute('src', src2);
|
106
116
|
});
|
@@ -108,14 +118,18 @@ describe('test Image component with useFallbackImage hook', function () {
|
|
108
118
|
test('image component will use src if loaded correctly', function () {
|
109
119
|
getComponent();
|
110
120
|
act(function () {
|
111
|
-
fallbackImageObj
|
121
|
+
if (fallbackImageObj) {
|
122
|
+
fallbackImageObj.onImageLoad();
|
123
|
+
}
|
112
124
|
});
|
113
125
|
expect(screen.getByRole('img')).toHaveAttribute('src', testSrc);
|
114
126
|
});
|
115
127
|
test('image component will use fallbackImg and fallbackAlt if src loaded with error', function () {
|
116
128
|
getComponent();
|
117
129
|
act(function () {
|
118
|
-
fallbackImageObj
|
130
|
+
if (fallbackImageObj) {
|
131
|
+
fallbackImageObj.onImageError();
|
132
|
+
}
|
119
133
|
});
|
120
134
|
var img = screen.getByRole('img');
|
121
135
|
expect(img).toHaveAttribute('src', testFallbackSrc);
|
@@ -124,7 +138,9 @@ describe('test Image component with useFallbackImage hook', function () {
|
|
124
138
|
test('image component will use fallbackImg and fallbackAlt if src timed out', function () {
|
125
139
|
getComponent();
|
126
140
|
act(function () {
|
127
|
-
fallbackImageObj
|
141
|
+
if (fallbackImageObj) {
|
142
|
+
fallbackImageObj.onFallbackTimeout();
|
143
|
+
}
|
128
144
|
});
|
129
145
|
var img = screen.getByRole('img');
|
130
146
|
expect(img).toHaveAttribute('src', testFallbackSrc);
|
@@ -133,8 +149,10 @@ describe('test Image component with useFallbackImage hook', function () {
|
|
133
149
|
test('if image loads after timeout src and alt still be the fallback', function () {
|
134
150
|
getComponent();
|
135
151
|
act(function () {
|
136
|
-
fallbackImageObj
|
137
|
-
|
152
|
+
if (fallbackImageObj) {
|
153
|
+
fallbackImageObj.onFallbackTimeout();
|
154
|
+
fallbackImageObj.onImageLoad();
|
155
|
+
}
|
138
156
|
});
|
139
157
|
var img = screen.getByRole('img');
|
140
158
|
expect(img).toHaveAttribute('src', testFallbackSrc);
|
@@ -143,36 +161,44 @@ describe('test Image component with useFallbackImage hook', function () {
|
|
143
161
|
test('if image loads before timeout src still be the the origin one', function () {
|
144
162
|
getComponent();
|
145
163
|
act(function () {
|
146
|
-
fallbackImageObj
|
147
|
-
|
164
|
+
if (fallbackImageObj) {
|
165
|
+
fallbackImageObj.onImageLoad();
|
166
|
+
fallbackImageObj.onFallbackTimeout();
|
167
|
+
}
|
148
168
|
});
|
149
169
|
expect(screen.getByRole('img')).toHaveAttribute('src', testSrc);
|
150
170
|
});
|
151
171
|
test('the skeleton loading will appear if no fallback image is given', function () {
|
152
172
|
getComponent({
|
153
|
-
fallbackImage:
|
173
|
+
fallbackImage: undefined
|
154
174
|
});
|
155
175
|
expect(screen.getByTestId(skeletonImageId)).toBeInTheDocument();
|
156
176
|
act(function () {
|
157
|
-
fallbackImageObj
|
177
|
+
if (fallbackImageObj) {
|
178
|
+
fallbackImageObj.onImageLoad();
|
179
|
+
}
|
158
180
|
});
|
159
181
|
expect(screen.getByRole('img')).toHaveAttribute('src', testSrc);
|
160
182
|
});
|
161
183
|
test('the skeleton will be shown instead of img if no fallback image is given and image load failed', function () {
|
162
184
|
getComponent({
|
163
|
-
fallbackImage:
|
185
|
+
fallbackImage: undefined
|
164
186
|
});
|
165
187
|
act(function () {
|
166
|
-
fallbackImageObj
|
188
|
+
if (fallbackImageObj) {
|
189
|
+
fallbackImageObj.onImageError();
|
190
|
+
}
|
167
191
|
});
|
168
192
|
expect(screen.getByTestId(skeletonImageId)).toBeInTheDocument();
|
169
193
|
});
|
170
194
|
test('the skeleton will be shown instead of img if no fallback image is given and image load timed out', function () {
|
171
195
|
getComponent({
|
172
|
-
fallbackImage:
|
196
|
+
fallbackImage: undefined
|
173
197
|
});
|
174
198
|
act(function () {
|
175
|
-
fallbackImageObj
|
199
|
+
if (fallbackImageObj) {
|
200
|
+
fallbackImageObj.onFallbackTimeout();
|
201
|
+
}
|
176
202
|
});
|
177
203
|
expect(screen.getByTestId(skeletonImageId)).toBeInTheDocument();
|
178
204
|
});
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@pingux/astro",
|
3
|
-
"version": "2.
|
3
|
+
"version": "2.43.0-alpha.0",
|
4
4
|
"description": "React component library for Ping Identity's design system",
|
5
5
|
"repository": {
|
6
6
|
"type": "git",
|
@@ -26,6 +26,7 @@
|
|
26
26
|
"chromatic": "npx chromatic",
|
27
27
|
"coverage": "yarn test --coverage",
|
28
28
|
"coverage-ci": "yarn test --coverage --ci",
|
29
|
+
"coverage-jenkins": "yarn coverage-ci --maxWorkers=25%",
|
29
30
|
"demo": "rm -rf ./demo && storybook build -o demo",
|
30
31
|
"lint": "eslint --ext .js,.jsx,.ts,.tsx .",
|
31
32
|
"start": "storybook dev -p 6006",
|