-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathHero.tsx
More file actions
227 lines (201 loc) · 6.99 KB
/
Hero.tsx
File metadata and controls
227 lines (201 loc) · 6.99 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
import { TableCellValue } from 'mobx-lark';
import { FC } from 'react';
import { Container } from 'react-bootstrap';
import { Agenda } from '../../../models/Hackathon';
import { LarkImage } from '../../LarkImage';
import { AgendaCountdown } from './AgendaCountdown';
import { TimeUnit } from '../../Base/Countdown';
import styles from './Hero.module.less';
export type HackathonHeroNavItem = Record<'label' | 'href', string>;
export interface HackathonHeroAction extends HackathonHeroNavItem {
external?: boolean;
}
export type HackathonHeroCard = Record<'title' | 'description' | 'eyebrow', string>;
export interface HackathonHeroProps extends Record<
| `visual${'Kicker' | 'Title' | 'Copy' | 'Chip'}`
| 'name'
| 'subtitle'
| 'description'
| 'locationText'
| 'imageFallback',
string
> {
agendaItems: Agenda[];
badges: string[];
bottomCard?: HackathonHeroCard;
chips?: string[];
countdownUnits: TimeUnit[];
endTime?: TableCellValue;
image?: TableCellValue;
startTime?: TableCellValue;
navigation: HackathonHeroNavItem[];
primaryAction: HackathonHeroAction;
secondaryAction: HackathonHeroAction;
topCard?: HackathonHeroCard;
}
const BadgeToneClass = [
styles.heroBadgeCyan,
styles.heroBadgeGold,
styles.heroBadgeGreen,
styles.heroBadgeRose,
];
const HeroLink: FC<{
action: HackathonHeroAction;
variant: 'ghost' | 'primary';
}> = ({ action, variant }) => (
<a
className={variant === 'primary' ? styles.actionButton : styles.actionButtonGhost}
href={action.href}
{...(action.external && { target: '_blank', rel: 'noreferrer' })}
>
{action.label}
</a>
);
const NavLink: FC<{ item: HackathonHeroNavItem }> = ({ item }) => (
<a className={`${styles.headerNavLink} d-none d-lg-inline`} href={item.href}>
{item.label}
</a>
);
const FloatingCard: FC<{
card: HackathonHeroCard;
position: 'bottom' | 'top';
}> = ({ card, position }) => (
<div
className={`${styles.heroFloatingCard} mt-3 mt-md-0 ${position === 'top' ? styles.heroFloatingCardTop : styles.heroFloatingCardBottom}`}
>
<span className={styles.floatingLabel}>{card.eyebrow}</span>
<strong>{card.title}</strong>
<p>{card.description}</p>
</div>
);
const splitHeroTitle = (name: string, subtitle: string) => {
const segments = name.split(/\s+/).filter(Boolean);
if (segments.length < 3)
return {
primary: name,
secondary: subtitle,
};
return {
primary: segments.slice(0, Math.max(1, segments.length - 2)).join(' '),
secondary: segments.slice(-2).join(' '),
};
};
export const HackathonHero: FC<HackathonHeroProps> = ({
agendaItems,
badges,
bottomCard,
chips,
countdownUnits,
description,
endTime,
image,
imageFallback,
locationText,
name,
navigation,
primaryAction,
secondaryAction,
startTime,
subtitle,
topCard,
visualChip,
visualCopy,
visualKicker,
visualTitle,
}) => {
const title = splitHeroTitle(name, subtitle);
return (
<section id="top" className={styles.hero}>
<header className={styles.siteHeader}>
<Container>
<div
className={`${styles.headerContainer} d-flex flex-wrap flex-md-nowrap justify-content-between align-items-center gap-3 py-3`}
>
<a className={`${styles.logoText} text-nowrap`} href="#top">
{name}
</a>
<nav
className={`${styles.headerNav} d-flex justify-content-between justify-content-md-start align-items-center gap-3`}
aria-label={subtitle}
>
{navigation.map(item => (
<NavLink key={`${item.label}-${item.href}`} item={item} />
))}
<HeroLink action={primaryAction} variant="primary" />
</nav>
</div>
</Container>
</header>
<Container>
<div className={styles.heroInner}>
<div className={`${styles.heroContent} d-flex flex-column pt-3 pt-xl-4`}>
<ul className={`list-unstyled ${styles.heroEyebrow} d-flex flex-wrap gap-3 m-0`}>
{badges.map((badge, index) => (
<li
key={`${badge}-${index}`}
className={`${styles.heroBadge} d-inline-flex align-items-center ${BadgeToneClass[index % BadgeToneClass.length]}`}
>
{badge}
</li>
))}
</ul>
<h1 className={`${styles.title} d-flex flex-column mb-0`}>
<span className={styles.heroTitlePrimary}>{title.primary}</span>
<span className={styles.heroTitleAccent}>{title.secondary}</span>
<span className={styles.heroTitleSecondary}>{subtitle}</span>
</h1>
<p className={styles.description}>{description}</p>
<AgendaCountdown
agendaItems={agendaItems}
endTime={endTime}
startTime={startTime}
units={countdownUnits}
/>
<nav className="d-flex flex-wrap gap-2 gap-md-3" aria-label={subtitle}>
<HeroLink action={primaryAction} variant="primary" />
<HeroLink action={secondaryAction} variant="ghost" />
</nav>
{chips?.[0] && (
<ul
className={`list-unstyled ${styles.heroStats} d-flex flex-wrap gap-2 gap-md-3 m-0`}
>
{chips.map(chip => (
<li key={chip} className={`${styles.statChip} d-inline-flex align-items-center`}>
{chip}
</li>
))}
</ul>
)}
</div>
<div className={`${styles.heroVisual} pt-3 pt-xl-4 d-flex d-md-block flex-column`}>
<div className={styles.heroVisualCard}>
<div className={`${styles.heroVisualHead} d-flex justify-content-between gap-3`}>
<span className={styles.visualKicker}>{visualKicker}</span>
<span className={styles.visualChip}>{visualChip}</span>
</div>
<figure className={styles.heroImageFrame}>
<div className={styles.mascotGlow} />
{image ? (
<LarkImage src={image} alt={name} className="w-100 h-100 object-fit-cover" />
) : (
<div
className={`${styles.heroImageFallback} d-flex justify-content-center align-items-center`}
>
{imageFallback}
</div>
)}
</figure>
<div className={styles.heroVisualFoot}>
<p className={styles.heroVisualTitle}>{locationText}</p>
<p className={`${styles.heroVisualCopy} m-0`}>{visualTitle}</p>
<p className={`${styles.heroVisualDescription} m-0`}>{visualCopy}</p>
</div>
</div>
{topCard && <FloatingCard card={topCard} position="top" />}
{bottomCard && <FloatingCard card={bottomCard} position="bottom" />}
</div>
</div>
</Container>
</section>
);
};