-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathExplainerImages.astro
More file actions
113 lines (96 loc) · 2.46 KB
/
ExplainerImages.astro
File metadata and controls
113 lines (96 loc) · 2.46 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
---
import { ImageMetadata } from "astro";
import { Image } from "astro:assets";
export interface ExplainerAction {
href: string;
text: string;
}
export interface ExplainerImageData {
alt: string;
src: ImageMetadata;
}
export interface ExplainerPhotos {
primary: ExplainerImageData;
secondary: [ExplainerImageData, ExplainerImageData];
}
export interface Props {
action?: ExplainerAction;
body: string;
direction: string;
heading: string;
photos: ExplainerPhotos;
}
function computeImageSizes(
{ height, width }: { height: number; width: number },
bound: number,
): { height: string; width: string } {
if (height < width) {
const opposite = computeImageSizes({ height: width, width: height }, bound);
return { height: opposite.width, width: opposite.height };
}
return {
height: `${bound}rem`,
width: (width * bound) / height + "rem",
};
}
---
<div
class:list={["explainer-images", `explainer-images-${Astro.props.direction}`]}
>
<Image class="explainer-image-primary" {...Astro.props.photos.primary} />
{
Astro.props.photos.secondary.map((secondary, i) => (
<Image
class="explainer-image-secondary"
{...secondary}
style={computeImageSizes(secondary.src, 16 - i * 4)}
/>
))
}
</div>
<style>
.explainer-images {
--offsetHorizontal: 2rem;
--offsetVertical: 1rem;
margin: auto;
position: relative;
user-select: none;
}
.explainer-image-primary {
width: 100%;
}
.explainer-image-secondary {
display: none;
}
@media (width >= 1017px) {
.explainer-images {
width: calc(56rem - (2 * var(--offsetHorizontal)));
}
.explainer-image-primary {
display: block;
height: 22.5rem;
margin: auto;
width: 41.25rem;
}
.explainer-image-secondary {
display: initial;
position: absolute;
}
.explainer-images-down .explainer-image-secondary:nth-child(2),
.explainer-images-up .explainer-image-secondary:nth-child(2) {
left: calc(var(--offsetHorizontal) * -1);
}
.explainer-images-down .explainer-image-secondary:nth-child(3),
.explainer-images-up .explainer-image-secondary:nth-child(3) {
right: calc(var(--offsetHorizontal) * -1);
}
.explainer-images-down .explainer-image-secondary:nth-child(2),
.explainer-images-up .explainer-image-secondary:nth-child(3) {
top: calc(var(--offsetVertical) * -1);
}
.explainer-images-down .explainer-image-secondary:nth-child(3),
.explainer-images-up .explainer-image-secondary:nth-child(2) {
bottom: calc(var(--offsetVertical) * -1);
}
}
</style>