-
Notifications
You must be signed in to change notification settings - Fork 15
/
BottomLeftImages.tsx
59 lines (55 loc) · 1.75 KB
/
BottomLeftImages.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
import { useEffect, useState } from "react";
import { Button, Card, Collapse } from "react-bootstrap";
type Props = {
imageNames: string[];
collapsed: boolean;
};
export function BottomLeftImages({ imageNames, collapsed }: Props) {
const [images, setImages] = useState<{ title: string; src: string }[]>([]);
const [open, setOpen] = useState(!collapsed);
useEffect(() => {
(async () => {
const importedImages = await Promise.all(
imageNames.map(async (imageName) => {
const title = imageName.replace(/\.[^.]+$/, "");
const image = await import(`../images/${imageName}`);
return { title: title, src: image.default };
})
);
setImages(importedImages);
})();
}, [imageNames]);
return (
<div className="leaflet-bottom leaflet-left">
<div className="leaflet-control">
<Button
variant="light"
onClick={() => setOpen(!open)}
aria-controls="collapse-images"
aria-expanded={open}
className="mb-1"
>
{open ? "説明を隠す" : "説明を表示"}
</Button>
<Collapse in={open}>
<div id="collapse-images">
<div className="d-flex align-items-start flex-wrap">
{images.map(({ title, src }) => (
<Card
key={title}
className="shadow opacity-75 me-1 mb-1"
style={{ width: "12rem" }}
>
<Card.Header as="h2" className="h6 text-center">
{title}
</Card.Header>
<Card.Img variant="bottom" src={src} />
</Card>
))}
</div>
</div>
</Collapse>
</div>
</div>
);
}