akeneo-design-system 0.1.239 → 0.1.240
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/components/Image/Image.d.ts +3 -1
- package/lib/components/Image/Image.js +8 -4
- package/lib/components/Image/Image.js.map +1 -1
- package/package.json +1 -1
- package/src/__image_snapshots__/all-visual-tsx-visual-tests-renders-components-image-background-correctly-1-snap.png +0 -0
- package/src/components/Image/Image.stories.mdx +18 -0
- package/src/components/Image/Image.tsx +27 -2
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
declare type Fit = 'cover' | 'contain';
|
|
3
|
-
declare
|
|
3
|
+
declare type Background = 'white' | 'checkerboard';
|
|
4
|
+
declare const Image: React.ForwardRefExoticComponent<Omit<React.ImgHTMLAttributes<HTMLImageElement>, "height" | "width" | "alt" | "src" | "fit" | "isStacked" | "background"> & {
|
|
4
5
|
src: string | null;
|
|
5
6
|
alt: string;
|
|
6
7
|
width?: number | undefined;
|
|
7
8
|
height?: number | undefined;
|
|
8
9
|
fit?: Fit | undefined;
|
|
9
10
|
isStacked?: boolean | undefined;
|
|
11
|
+
background?: Background | undefined;
|
|
10
12
|
} & React.RefAttributes<HTMLImageElement>>;
|
|
11
13
|
export { Image };
|
|
@@ -53,7 +53,7 @@ var react_1 = __importDefault(require("react"));
|
|
|
53
53
|
var styled_components_1 = __importStar(require("styled-components"));
|
|
54
54
|
var theme_1 = require("../../theme");
|
|
55
55
|
var EMPTY_IMAGE = 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg"/>';
|
|
56
|
-
var ImageContainer = styled_components_1.default.img(
|
|
56
|
+
var ImageContainer = styled_components_1.default.img(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n border: 1px solid ", ";\n object-fit: ", ";\n box-sizing: border-box;\n\n ", "\n\n ", "\n \n ", "\n"], ["\n border: 1px solid ", ";\n object-fit: ", ";\n box-sizing: border-box;\n\n ", "\n\n ", "\n \n ", "\n"])), (0, theme_1.getColor)('grey', 80), function (_a) {
|
|
57
57
|
var fit = _a.fit;
|
|
58
58
|
return fit;
|
|
59
59
|
}, function (_a) {
|
|
@@ -62,11 +62,15 @@ var ImageContainer = styled_components_1.default.img(templateObject_2 || (templa
|
|
|
62
62
|
}, function (_a) {
|
|
63
63
|
var isLoading = _a.isLoading;
|
|
64
64
|
return isLoading && theme_1.placeholderStyle;
|
|
65
|
+
}, function (_a) {
|
|
66
|
+
var background = _a.background;
|
|
67
|
+
return background === 'checkerboard'
|
|
68
|
+
? (0, styled_components_1.css)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n background-image: linear-gradient(45deg, ", " 25%, transparent 25%),\n linear-gradient(135deg, ", " 25%, transparent 25%),\n linear-gradient(45deg, transparent 75%, ", " 75%),\n linear-gradient(135deg, transparent 75%, ", " 75%);\n background-size: 25px 25px; /* Must be a square */\n background-position: 0 0, 12.5px 0, 12.5px -12.5px, 0px 12.5px; /* Must be half of one side of the square */\n "], ["\n background-image: linear-gradient(45deg, ", " 25%, transparent 25%),\n linear-gradient(135deg, ", " 25%, transparent 25%),\n linear-gradient(45deg, transparent 75%, ", " 75%),\n linear-gradient(135deg, transparent 75%, ", " 75%);\n background-size: 25px 25px; /* Must be a square */\n background-position: 0 0, 12.5px 0, 12.5px -12.5px, 0px 12.5px; /* Must be half of one side of the square */\n "])), (0, theme_1.getColor)('grey', 60), (0, theme_1.getColor)('grey', 60), (0, theme_1.getColor)('grey', 60), (0, theme_1.getColor)('grey', 60)) : (0, styled_components_1.css)(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n background: ", ";\n "], ["\n background: ", ";\n "])), (0, theme_1.getColor)(background));
|
|
65
69
|
});
|
|
66
70
|
var Image = react_1.default.forwardRef(function (_a, forwardedRef) {
|
|
67
|
-
var _b = _a.fit, fit = _b === void 0 ? 'cover' : _b, _c = _a.isStacked, isStacked = _c === void 0 ? false : _c, src = _a.src, rest = __rest(_a, ["fit", "isStacked", "src"]);
|
|
68
|
-
return (react_1.default.createElement(ImageContainer, __assign({ isLoading: null === src, src: src !== null && src !== void 0 ? src : EMPTY_IMAGE, ref: forwardedRef, fit: fit, isStacked: isStacked }, rest)));
|
|
71
|
+
var _b = _a.fit, fit = _b === void 0 ? 'cover' : _b, _c = _a.isStacked, isStacked = _c === void 0 ? false : _c, _d = _a.background, background = _d === void 0 ? 'white' : _d, src = _a.src, rest = __rest(_a, ["fit", "isStacked", "background", "src"]);
|
|
72
|
+
return (react_1.default.createElement(ImageContainer, __assign({ isLoading: null === src, src: src !== null && src !== void 0 ? src : EMPTY_IMAGE, ref: forwardedRef, fit: fit, isStacked: isStacked, background: background }, rest)));
|
|
69
73
|
});
|
|
70
74
|
exports.Image = Image;
|
|
71
|
-
var templateObject_1, templateObject_2;
|
|
75
|
+
var templateObject_1, templateObject_2, templateObject_3, templateObject_4;
|
|
72
76
|
//# sourceMappingURL=Image.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Image.js","sourceRoot":"","sources":["../../../src/components/Image/Image.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAAiC;AACjC,qEAA8C;AAC9C,qCAAuD;AAIvD,IAAM,WAAW,GAAG,8DAA8D,CAAC;
|
|
1
|
+
{"version":3,"file":"Image.js","sourceRoot":"","sources":["../../../src/components/Image/Image.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAAiC;AACjC,qEAA8C;AAC9C,qCAAuD;AAIvD,IAAM,WAAW,GAAG,8DAA8D,CAAC;AAMnF,IAAM,cAAc,GAAG,2BAAM,CAAC,GAAG,kLAOhC,wBACqB,EAAoB,mBAC1B,EAAc,oCAG1B,EAKC,QAED,EAA8C,UAE9C,EAYK,IACR,KA1BqB,IAAA,gBAAQ,EAAC,MAAM,EAAE,EAAE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IAAI,cAArE,yCAAsE,CAAD;IAGrE,OAAO,CACL,8BAAC,cAAc,aACb,SAAS,EAAE,IAAI,KAAK,GAAG,EACvB,GAAG,EAAE,GAAG,aAAH,GAAG,cAAH,GAAG,GAAI,WAAW,EACvB,GAAG,EAAE,YAAY,EACjB,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,SAAS,EACpB,UAAU,EAAE,UAAU,IAClB,IAAI,EACR,CACH,CAAC;AACJ,CAAC,CACF,CAAC;AAEM,sBAAK"}
|
package/package.json
CHANGED
|
Binary file
|
|
@@ -71,3 +71,21 @@ When the `src` prop is set to `null`, the Image will display itself as loading.
|
|
|
71
71
|
}}
|
|
72
72
|
</Story>
|
|
73
73
|
</Canvas>
|
|
74
|
+
|
|
75
|
+
## Variation on background
|
|
76
|
+
|
|
77
|
+
When the `background` prop is set to `checkerboard`, the Image will display a checkerboard background behind the transparent image.
|
|
78
|
+
The background will be white otherwise.
|
|
79
|
+
|
|
80
|
+
<Canvas>
|
|
81
|
+
<Story name="Background">
|
|
82
|
+
{args => {
|
|
83
|
+
return (
|
|
84
|
+
<>
|
|
85
|
+
<Image {...args} background="white" src="https://doodleipsum.com/200x140/outline?i=63527485e69dea481bb541d7f1da73fe" />
|
|
86
|
+
<Image {...args} background="checkerboard" src="https://doodleipsum.com/200x140/outline?i=63527485e69dea481bb541d7f1da73fe" />
|
|
87
|
+
</>
|
|
88
|
+
);
|
|
89
|
+
}}
|
|
90
|
+
</Story>
|
|
91
|
+
</Canvas>
|
|
@@ -8,14 +8,16 @@ const EMPTY_IMAGE = 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg"/
|
|
|
8
8
|
|
|
9
9
|
type Fit = 'cover' | 'contain';
|
|
10
10
|
|
|
11
|
+
type Background = 'white' | 'checkerboard';
|
|
12
|
+
|
|
11
13
|
const ImageContainer = styled.img<
|
|
12
14
|
{
|
|
13
15
|
fit: Fit;
|
|
14
16
|
isStacked: boolean;
|
|
15
17
|
isLoading: boolean;
|
|
18
|
+
background: Background;
|
|
16
19
|
} & AkeneoThemedProps
|
|
17
20
|
>`
|
|
18
|
-
background: ${getColor('white')};
|
|
19
21
|
border: 1px solid ${getColor('grey', 80)};
|
|
20
22
|
object-fit: ${({fit}) => fit};
|
|
21
23
|
box-sizing: border-box;
|
|
@@ -28,6 +30,20 @@ const ImageContainer = styled.img<
|
|
|
28
30
|
`}
|
|
29
31
|
|
|
30
32
|
${({isLoading}) => isLoading && placeholderStyle}
|
|
33
|
+
|
|
34
|
+
${({background}) =>
|
|
35
|
+
background === 'checkerboard'
|
|
36
|
+
? css`
|
|
37
|
+
background-image: linear-gradient(45deg, ${getColor('grey', 60)} 25%, transparent 25%),
|
|
38
|
+
linear-gradient(135deg, ${getColor('grey', 60)} 25%, transparent 25%),
|
|
39
|
+
linear-gradient(45deg, transparent 75%, ${getColor('grey', 60)} 75%),
|
|
40
|
+
linear-gradient(135deg, transparent 75%, ${getColor('grey', 60)} 75%);
|
|
41
|
+
background-size: 25px 25px; /* Must be a square */
|
|
42
|
+
background-position: 0 0, 12.5px 0, 12.5px -12.5px, 0px 12.5px; /* Must be half of one side of the square */
|
|
43
|
+
`
|
|
44
|
+
: css`
|
|
45
|
+
background: ${getColor(background)};
|
|
46
|
+
`}
|
|
31
47
|
`;
|
|
32
48
|
|
|
33
49
|
type ImageProps = Override<
|
|
@@ -62,6 +78,11 @@ type ImageProps = Override<
|
|
|
62
78
|
* Should the image appear as a stack of multiple images.
|
|
63
79
|
*/
|
|
64
80
|
isStacked?: boolean;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Should the image appear with a background or not
|
|
84
|
+
*/
|
|
85
|
+
background?: Background;
|
|
65
86
|
}
|
|
66
87
|
>;
|
|
67
88
|
|
|
@@ -69,7 +90,10 @@ type ImageProps = Override<
|
|
|
69
90
|
* Image allow to embed an image in a page.
|
|
70
91
|
*/
|
|
71
92
|
const Image = React.forwardRef<HTMLImageElement, ImageProps>(
|
|
72
|
-
(
|
|
93
|
+
(
|
|
94
|
+
{fit = 'cover', isStacked = false, background = 'white', src, ...rest}: ImageProps,
|
|
95
|
+
forwardedRef: Ref<HTMLImageElement>
|
|
96
|
+
) => {
|
|
73
97
|
return (
|
|
74
98
|
<ImageContainer
|
|
75
99
|
isLoading={null === src}
|
|
@@ -77,6 +101,7 @@ const Image = React.forwardRef<HTMLImageElement, ImageProps>(
|
|
|
77
101
|
ref={forwardedRef}
|
|
78
102
|
fit={fit}
|
|
79
103
|
isStacked={isStacked}
|
|
104
|
+
background={background}
|
|
80
105
|
{...rest}
|
|
81
106
|
/>
|
|
82
107
|
);
|