-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathrandom-image.tsx
60 lines (55 loc) · 1.48 KB
/
random-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
import React from "react";
import {
Actions,
Button,
Confirm,
Divider,
ImageBlock,
PheliaMessageProps,
Text,
Message
} from "../../core";
const imageUrls = [
"https://cdn.pixabay.com/photo/2015/06/08/15/02/pug-801826__480.jpg",
"https://cdn.pixabay.com/photo/2015/03/26/09/54/pug-690566__480.jpg",
"https://cdn.pixabay.com/photo/2018/03/31/06/31/dog-3277416__480.jpg",
"https://cdn.pixabay.com/photo/2016/02/26/16/32/dog-1224267__480.jpg"
];
function randomImage(): string {
const index = Math.floor(Math.random() * imageUrls.length);
return imageUrls[index];
}
export function RandomImage({ useState }: PheliaMessageProps) {
const [imageUrl, setImageUrl] = useState("imageUrl", randomImage());
return (
<Message text="Choose a dog">
<ImageBlock
emoji
title={"an adorable :dog:"}
alt={"a very adorable doggy dog"}
imageUrl={imageUrl}
/>
<Divider />
<Actions>
<Button
style="primary"
action="randomImage"
onClick={() => setImageUrl(randomImage())}
confirm={
<Confirm
title={"Are you sure?"}
confirm={"Yes, gimmey that doggy!"}
deny={"No, I hate doggies"}
>
<Text type="mrkdwn">
Are you certain you want to see the _cutest_ doggy ever?
</Text>
</Confirm>
}
>
New doggy
</Button>
</Actions>
</Message>
);
}