-
Notifications
You must be signed in to change notification settings - Fork 273
Expand file tree
/
Copy pathindex.tsx
More file actions
257 lines (250 loc) · 7.63 KB
/
index.tsx
File metadata and controls
257 lines (250 loc) · 7.63 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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
import { useState, use, useContext } from 'react';
import { ScrollableNavigation } from '#app/legacy/psammead/psammead-navigation/src/ScrollableNavigation';
import { css, Theme } from '@emotion/react';
import { Summary } from '#app/models/types/curationData';
import SectionLabel from '#psammead/psammead-section-label/src';
import { GREY_2 } from '#app/components/ThemeProvider/palette';
import { ServiceContext } from '#app/contexts/ServiceContext';
import CurationGrid from '../Curation/CurationGrid';
const tabStyles = {
container: css({
display: 'flex',
borderBottom: '1px solid #ccc',
marginBottom: '1rem',
gap: '0.25rem',
minHeight: '3.5rem',
width: '100%',
overflowX: 'auto',
overflowY: 'hidden',
position: 'relative',
scrollBehavior: 'smooth',
touchAction: 'pan-x',
// Hide scrollbars
scrollbarWidth: 'none',
'-ms-overflow-style': 'none',
'&::-webkit-scrollbar': {
display: 'none',
},
// Remove white-space: nowrap here, handled by ScrollableNavigation
}),
wrapper: css({
backgroundColor: '#fff',
padding: '1rem 0',
marginLeft: '1rem',
marginRight: '1rem',
}),
tab: (theme: Theme) =>
css({
padding: '0.5rem 1.5rem',
cursor: 'pointer',
border: '1px solid #ccc',
borderBottom: 'none',
background: '#fff',
fontWeight: 600,
color: '#222',
outline: 'none',
borderTopLeftRadius: '6px',
borderTopRightRadius: '6px',
marginBottom: '-1px',
zIndex: 1,
position: 'relative',
flex: '0 0 auto',
whiteSpace: 'normal',
overflow: 'visible',
textOverflow: 'unset',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
textAlign: 'center',
lineHeight: '1.2',
height: 'auto',
fontSize: '1rem',
overflowWrap: 'break-word',
wordBreak: 'break-word',
':focus': {
borderColor: theme.palette.POSTBOX,
},
}),
activeTab: (theme: Theme) =>
css({
borderBottom: `4px solid ${theme.palette.POSTBOX}`,
color: theme.palette.POSTBOX,
fontWeight: 700,
zIndex: 2,
}),
};
interface TopicCuration {
title: string;
summaries: Summary[];
link?: string;
}
interface TabbedTopicsProps {
topics: TopicCuration[];
css?: import('@emotion/react').Interpolation<import('@emotion/react').Theme>;
}
const TabbedTopics = ({ topics }: TabbedTopicsProps) => {
const [activeIndex, setActiveIndex] = useState(0);
const { translations, dir } = useContext(ServiceContext);
const heading = translations?.relatedTopics ?? 'Related Topics';
if (!topics || topics.length === 0) return null;
return (
<section
role="region"
aria-labelledby={`topic-tab-${activeIndex}`}
css={css({ backgroundColor: '#fff' })}
>
<div css={tabStyles.wrapper}>
<div css={css({ marginTop: 0 })}>
<SectionLabel
bar
dir={dir}
labelId="related-topics"
mobileDivider={false}
backgroundColor="#fff"
css={css({
marginBottom: '1rem',
backgroundColor: '#fff',
marginTop: 0,
})}
>
{heading}
</SectionLabel>
</div>
<div style={{ position: 'relative' }}>
<ScrollableNavigation dir={dir} navPosition="bottom">
<div css={tabStyles.container}>
{topics.map((topic, idx) => (
<button
key={topic.title}
css={theme => [
tabStyles.tab(theme),
idx === activeIndex && tabStyles.activeTab(theme),
]}
id={`topic-tab-${idx}`}
aria-controls={`topic-panel-${idx}`}
tabIndex={idx === activeIndex ? 0 : -1}
type="button"
onClick={() => setActiveIndex(idx)}
>
{/* Allow one line break, show full topic title */}
{topic.title
.split('\n')
.slice(0, 2)
.map((line, i) => (
<span
key={i}
css={css({
display: 'block',
whiteSpace: 'normal',
fontSize: '1rem',
fontWeight: 600,
color: '#222',
lineHeight: '1.2',
overflowWrap: 'break-word',
wordBreak: 'break-word',
})}
>
{line}
</span>
))}
</button>
))}
</div>
</ScrollableNavigation>
{/* Gradient overlay for scroll indication, border grey */}
<div
css={css({
position: 'absolute',
top: 0,
right: 0,
width: '3rem',
height: '100%',
pointerEvents: 'none',
background:
'linear-gradient(to right, rgba(204,204,204,0) 0%, #ccc 100%)',
zIndex: 3,
})}
/>
{/* Red ellipsis icon above scroll edge */}
<div
css={css({
position: 'absolute',
top: '-1.5rem',
right: '1.5rem',
width: '1.5rem',
height: '1.5rem',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
zIndex: 4,
})}
>
<svg
viewBox="0 0 24 24"
width="24"
height="24"
aria-hidden="true"
focusable="false"
>
<circle cx="5" cy="12" r="2" fill="#bb1919" />
<circle cx="12" cy="12" r="2" fill="#bb1919" />
<circle cx="19" cy="12" r="2" fill="#bb1919" />
</svg>
</div>
</div>
<div
id={`topic-panel-${activeIndex}`}
role="tabpanel"
aria-labelledby={`topic-tab-${activeIndex}`}
>
<CurationGrid
summaries={topics[activeIndex].summaries}
headingLevel={2}
isFirstCuration
eventTrackingData={{
componentName: 'tabbed-topics',
groupTracker: { name: topics[activeIndex].title },
}}
/>
<div
css={css({
marginTop: '1rem',
display: 'flex',
alignItems: 'center',
})}
>
<a
href={`${topics[activeIndex].link}`}
css={css({
display: 'inline-flex',
alignItems: 'center',
fontWeight: 700,
color: '#222',
textDecoration: 'none',
fontSize: '1.15rem',
lineHeight: 1.4,
':hover': { color: '#007BBC', textDecoration: 'underline' },
})}
>
See all from this topic
<svg
viewBox="0 0 32 32"
focusable="false"
aria-hidden="true"
width="16"
height="16"
style={{ marginLeft: 4 }}
>
<path
d="M21.6 14.3L5.5 31h6.4l14.6-15L11.9 1H5.5l16.1 16.7v-3.4z"
fill="currentColor"
/>
</svg>
</a>
</div>
</div>
</div>
</section>
);
};
export default TabbedTopics;