@pushwoosh/dumb-components 1.1.82 → 1.1.83
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/ExternalImagePreview/ExternalImagePreview.d.ts +3 -0
- package/ExternalImagePreview/ExternalImagePreview.js +50 -0
- package/ExternalImagePreview/index.d.ts +1 -0
- package/ExternalImagePreview/index.js +1 -0
- package/ExternalImagePreview/styles.d.ts +13 -0
- package/ExternalImagePreview/styles.js +29 -0
- package/ExternalImagePreview/types.d.ts +9 -0
- package/ExternalImagePreview/types.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import React, { useState, useEffect } from 'react';
|
|
2
|
+
import { Color } from '@pushwoosh/kit-constants';
|
|
3
|
+
import { Spinner } from '../Spinner';
|
|
4
|
+
import { RootBox, ImgPreview, PlaceholderWrapper } from './styles';
|
|
5
|
+
export function ExternalImagePreview(props) {
|
|
6
|
+
const {
|
|
7
|
+
src,
|
|
8
|
+
alt = 'External image preview',
|
|
9
|
+
width,
|
|
10
|
+
height,
|
|
11
|
+
placeholder,
|
|
12
|
+
onError
|
|
13
|
+
} = props;
|
|
14
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
15
|
+
const [isError, setIsError] = useState(false);
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
if (src) {
|
|
18
|
+
setIsLoading(true);
|
|
19
|
+
setIsError(false);
|
|
20
|
+
}
|
|
21
|
+
}, [src]);
|
|
22
|
+
const handleOnError = error => {
|
|
23
|
+
setIsLoading(false);
|
|
24
|
+
setIsError(true);
|
|
25
|
+
if (onError) {
|
|
26
|
+
onError(error);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
return React.createElement(RootBox, {
|
|
30
|
+
width: width,
|
|
31
|
+
height: height
|
|
32
|
+
}, (!src || isError) && React.createElement(PlaceholderWrapper, {
|
|
33
|
+
width: width,
|
|
34
|
+
height: height
|
|
35
|
+
}, placeholder), isLoading && React.createElement(PlaceholderWrapper, {
|
|
36
|
+
width: width,
|
|
37
|
+
height: height
|
|
38
|
+
}, React.createElement(Spinner, {
|
|
39
|
+
size: "small",
|
|
40
|
+
color: Color.CLEAR
|
|
41
|
+
})), React.createElement(ImgPreview, {
|
|
42
|
+
width: width,
|
|
43
|
+
height: height,
|
|
44
|
+
isHide: !src || isLoading || isError,
|
|
45
|
+
alt: alt,
|
|
46
|
+
src: src,
|
|
47
|
+
onError: handleOnError,
|
|
48
|
+
onLoad: () => setIsLoading(false)
|
|
49
|
+
}));
|
|
50
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ExternalImagePreview } from './ExternalImagePreview';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ExternalImagePreview } from './ExternalImagePreview';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare const RootBox: import("styled-components").StyledComponent<"div", any, {
|
|
2
|
+
width: string | number;
|
|
3
|
+
height: string | number;
|
|
4
|
+
}, never>;
|
|
5
|
+
export declare const ImgPreview: import("styled-components").StyledComponent<"img", any, {
|
|
6
|
+
width: string | number;
|
|
7
|
+
height: string | number;
|
|
8
|
+
isHide: boolean;
|
|
9
|
+
}, never>;
|
|
10
|
+
export declare const PlaceholderWrapper: import("styled-components").StyledComponent<"div", any, {
|
|
11
|
+
width: string | number;
|
|
12
|
+
height: string | number;
|
|
13
|
+
}, never>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import styled from 'styled-components';
|
|
2
|
+
import { Color, ShapeRadius } from '@pushwoosh/kit-constants';
|
|
3
|
+
import { toCssValue } from '@pushwoosh/kit-helpers';
|
|
4
|
+
export const RootBox = styled.div.withConfig({
|
|
5
|
+
displayName: "RootBox",
|
|
6
|
+
componentId: "sc-irvho3-0"
|
|
7
|
+
})(["position:relative;width:", ";height:", ";"], ({
|
|
8
|
+
width
|
|
9
|
+
}) => toCssValue(width), ({
|
|
10
|
+
height
|
|
11
|
+
}) => toCssValue(height));
|
|
12
|
+
export const ImgPreview = styled.img.withConfig({
|
|
13
|
+
displayName: "ImgPreview",
|
|
14
|
+
componentId: "sc-irvho3-1"
|
|
15
|
+
})(["width:", ";height:", ";border-radius:", ";opacity:", ";z-index:1;"], ({
|
|
16
|
+
width
|
|
17
|
+
}) => toCssValue(width), ({
|
|
18
|
+
height
|
|
19
|
+
}) => toCssValue(height), ShapeRadius.CONTROL, ({
|
|
20
|
+
isHide
|
|
21
|
+
}) => isHide ? 0 : 1);
|
|
22
|
+
export const PlaceholderWrapper = styled.div.withConfig({
|
|
23
|
+
displayName: "PlaceholderWrapper",
|
|
24
|
+
componentId: "sc-irvho3-2"
|
|
25
|
+
})(["width:", ";height:", ";display:flex;align-items:center;justify-content:center;border-radius:", ";position:absolute;top:0;left:0;z-index:2;background:", ";"], ({
|
|
26
|
+
width
|
|
27
|
+
}) => toCssValue(width), ({
|
|
28
|
+
height
|
|
29
|
+
}) => toCssValue(height), ShapeRadius.CONTROL, Color.MAIN);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ReactElement, ReactEventHandler } from 'react';
|
|
2
|
+
export interface ExternalImagePreviewProps {
|
|
3
|
+
src: string;
|
|
4
|
+
alt?: string;
|
|
5
|
+
width: string | number;
|
|
6
|
+
height: string | number;
|
|
7
|
+
placeholder: ReactElement;
|
|
8
|
+
onError?: (error: ReactEventHandler<HTMLImageElement>) => void;
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|