-
Notifications
You must be signed in to change notification settings - Fork 247
/
Image.tsx
73 lines (68 loc) · 1.75 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
import * as React 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] = React.useState(false);
const { width, height, loader, storyStyles } = config;
let computedStyles = {
...styles.storyContent,
...(storyStyles || {}),
};
const imageLoaded = () => {
setLoaded(true);
action("play");
};
return (
<WithHeader {...{ story, globalHeader: config.header }}>
<WithSeeMore {...{ story, 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,
};