-
Notifications
You must be signed in to change notification settings - Fork 0
/
Image.tsx
78 lines (71 loc) · 2.14 KB
/
Image.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import React, {useState, useEffect} from 'react';
import Spinner from '../components/Spinner';
import { Renderer, Tester } from './../interfaces';
import WithHeader from './wrappers/withHeader';
import WithSeeMore from './wrappers/withSeeMore';
export const renderer: Renderer = ({ story, action, isPaused, config }) => {
const [loaded, setLoaded] = useState(false);
const { width, height, loader, storyStyles } = config;
let computedStyles = {
...styles.storyContent,
...(storyStyles || {})
}
useEffect(() => {
if (!loaded) {
action('pause', true)
}
}, [loaded])
const imageLoaded = () => {
setLoaded(true);
action('play');
}
return <WithHeader story={story} globalHeader={config.header}>
<WithSeeMore story={story} action={action}>
<div>
<img style={computedStyles} src={story.url} onLoad={imageLoaded} />
{!loaded && (
<div
style={{
width: width,
height: height,
position: "absolute",
left: 0,
top: 0,
background: "rgba(0, 0, 0, 0.9)",
zIndex: 9,
display: "flex",
justifyContent: "center",
alignItems: "center",
color: "#ccc"
}}
>
{loader || <Spinner />}
</div>
)}
</div>
</WithSeeMore>
</WithHeader>
}
const styles = {
story: {
display: "flex",
position: "relative",
overflow: "hidden"
},
storyContent: {
width: "auto",
maxWidth: "100%",
maxHeight: "100%",
margin: "auto"
}
};
export const tester: Tester = (story) => {
return {
condition: !story.content && (!story.type || story.type === 'image'),
priority: 2
}
}
export default {
renderer,
tester
}