-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathValuesSection.tsx
More file actions
208 lines (177 loc) · 5.38 KB
/
Copy pathValuesSection.tsx
File metadata and controls
208 lines (177 loc) · 5.38 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
import { useRef, useState } from 'react';
import { useIntl } from 'react-intl';
import { css, Theme, useTheme } from '@emotion/react';
import useEmblaCarousel from 'embla-carousel-react';
import Autoplay from 'embla-carousel-autoplay';
import { Markup } from 'interweave';
import { LocalizedLink } from 'gatsby-plugin-i18n-l10n';
import { DividedSection } from '../components/DividedSection';
import { Sprite } from '../components/Sprite';
import { Arrow } from '../components/Arrow';
const sectionStyle = (theme: Theme) => css`
display: flex;
align-items: center;
button {
&:first-of-type {
margin-right: var(${theme.variables.gutter});
}
&:last-of-type {
margin-left: var(${theme.variables.gutter});
}
svg {
width: 1.5rem;
height: auto;
}
}
.slider-content {
display: flex;
flex: 1;
min-width: 0;
}
aside {
display: flex;
margin-block: auto;
width: 30%;
z-index: 1;
.aside-content {
flex: 1;
}
button {
display: none;
}
}
@media screen and (max-width: ${theme.breakpoints.medium}) {
padding-inline: 0;
button {
display: none;
}
.slider-content {
flex-direction: column-reverse;
}
aside {
width: 100%;
button {
margin-inline: calc(var(${theme.variables.gutter}));
display: block;
@media screen and (max-width: ${theme.breakpoints.tiny}) {
margin-inline: calc(var(${theme.variables.gutter}) / 4) !important;
}
}
}
}
`;
const carouselStyle = (theme: Theme) => css`
overflow: hidden;
width: calc(70% + 10rem);
mask-image: linear-gradient(90deg, transparent 0%, black 40%, black 50%, black 60%, transparent 100%);
margin-left: -10rem;
/* magic formula to responsively fit underneath header */
margin-top: calc(-1 * (6rem + 2vw));
margin-bottom: calc(-1 * (5rem + 2vw));
.carousel-container {
display: flex;
.carousel-slide {
--slide-frame-size: clamp(25rem, 60vw, 50rem);
height: var(--slide-frame-size);
width: var(--slide-frame-size);
flex: 0 0 auto;
overflow: hidden;
display: flex;
svg {
height: 100%;
flex: 1;
}
&:nth-child(2),
&:nth-child(5) {
svg {
margin-left: calc(var(--slide-frame-size) * -1);
}
}
&:nth-child(3),
&:nth-child(6) {
svg {
margin-left: calc(var(--slide-frame-size) * -2);
}
}
}
}
@media screen and (max-width: ${theme.breakpoints.medium}) {
width: 100%;
margin-left: 0;
mask-image: linear-gradient(black, black, transparent);
margin-top: calc(-1 * (5.85rem + 3vw));
}
`;
type Props = {
values: Queries.IndexPageQuery['values'];
};
export function ValuesSection({ values }: Props) {
const theme = useTheme();
const autoplay = useRef(Autoplay({ delay: 4000, stopOnInteraction: false, rootNode: emblaRoot => emblaRoot.parentElement }));
const [emblaRef, emblaApi] = useEmblaCarousel({ loop: true }, [autoplay.current]);
const { formatMessage } = useIntl();
const [selectedSnap, setSelectedSnap] = useState(0);
const textBoxContents: { title?: string | null; link?: string | null; text?: JSX.Element }[] = values.nodes.map(node => ({
title: node.frontmatter?.title,
link: node.frontmatter?.link,
text: <Markup content={node.html} />,
}));
emblaApi?.scrollSnapList();
emblaApi?.on('select', () => {
const currentSnap = emblaApi?.selectedScrollSnap();
if (!Number.isNaN(currentSnap)) {
setSelectedSnap(currentSnap % 3 ?? 0);
}
});
const renderPrevButton = () => (
<button aria-label="scroll to the previous" type="button" onClick={() => emblaApi?.scrollPrev()}>
<Arrow rotation={90} />
</button>
);
const renderNextButton = () => (
<button aria-label="scroll to the next" type="button" onClick={() => emblaApi?.scrollNext()}>
<Arrow rotation={270} />
</button>
);
return (
<DividedSection upperColor={theme.backgroundColor} lowerColor={theme.whiteColor} css={sectionStyle}>
{renderPrevButton()}
<div className="slider-content">
<aside>
{renderPrevButton()}
<div className="aside-content">
<h2>{textBoxContents[selectedSnap]?.title}</h2>
{textBoxContents[selectedSnap]?.text}
<LocalizedLink to={textBoxContents[selectedSnap].link ?? ''}>
{formatMessage({ id: 'action.learnMore' })} <Arrow rotation={270} />
</LocalizedLink>
</div>
{renderNextButton()}
</aside>
<div css={carouselStyle} ref={emblaRef}>
<div className="carousel-container">
<div className="carousel-slide">
<Sprite name="illustration" />
</div>
<div className="carousel-slide">
<Sprite name="illustration" />
</div>
<div className="carousel-slide">
<Sprite name="illustration" />
</div>
<div className="carousel-slide">
<Sprite name="illustration" />
</div>
<div className="carousel-slide">
<Sprite name="illustration" />
</div>
<div className="carousel-slide">
<Sprite name="illustration" />
</div>
</div>
</div>
</div>
{renderNextButton()}
</DividedSection>
);
}