| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- import { useStorefront } from '../context';
- import type { HeroSection } from '../types';
- import { Container, Eyebrow, ImagePlaceholder, SfButton } from '../ui';
-
- /**
- * The photo for a hero: the one the design names, or else the store's newest product photo.
- * Null when the store has no photos yet.
- */
- function useHeroPhoto(section: HeroSection): string | null {
- const { heroImages } = useStorefront();
- const ref = section.content.image;
-
- return (
- (ref ? heroImages.refs[ref] : undefined) ??
- heroImages.fallback[0] ??
- null
- );
- }
-
- export function Hero({ section }: { section: HeroSection }) {
- const photo = useHeroPhoto(section);
-
- if (section.variant === 'image-full') {
- return <FullPhotoHero section={section} photo={photo} />;
- }
-
- if (section.variant === 'split') {
- return <SplitHero section={section} photo={photo} />;
- }
-
- return <CenteredHero section={section} />;
- }
-
- function Buttons({
- section,
- onPhoto = false,
- }: {
- section: HeroSection;
- onPhoto?: boolean;
- }) {
- const { primaryCta, secondaryCta } = section.content;
-
- return (
- <div className="mt-8 flex flex-wrap gap-3">
- <SfButton href={primaryCta.href}>{primaryCta.label}</SfButton>
- {secondaryCta && (
- <SfButton
- href={secondaryCta.href}
- variant="outline"
- className={
- onPhoto
- ? 'border-white/70 text-white hover:bg-white/10'
- : undefined
- }
- >
- {secondaryCta.label}
- </SfButton>
- )}
- </div>
- );
- }
-
- /** A photo across the whole width, with the words on top of it. */
- function FullPhotoHero({
- section,
- photo,
- }: {
- section: HeroSection;
- photo: string | null;
- }) {
- const { eyebrow, headline, subheadline } = section.content;
-
- return (
- <section
- id={section.id}
- className="sf-on-photo relative isolate scroll-mt-20 overflow-hidden"
- data-hero="image-full"
- >
- {photo ? (
- <img
- src={photo}
- alt=""
- className="absolute inset-0 -z-20 h-full w-full object-cover"
- />
- ) : (
- <div
- className="absolute inset-0 -z-20"
- style={{
- background:
- 'linear-gradient(135deg, var(--sf-primary), color-mix(in srgb, var(--sf-accent) 55%, var(--sf-primary)))',
- }}
- />
- )}
- {/* Darkens the photo where the words sit, so they stay readable on any photo. */}
- <div className="absolute inset-0 -z-10 bg-linear-to-t from-black/75 via-black/35 to-black/5 md:bg-linear-to-r md:from-black/70 md:via-black/35 md:to-transparent" />
-
- <Container className="flex min-h-[480px] items-end py-14 md:min-h-[600px] md:items-center md:py-24">
- <div className="max-w-xl text-white">
- {eyebrow && (
- <p className="text-xs font-semibold tracking-[0.18em] text-white/85 uppercase">
- {eyebrow}
- </p>
- )}
- <h1 className="sf-heading mt-4 text-4xl leading-[1.05] font-semibold text-balance sm:text-5xl lg:text-6xl">
- {headline}
- </h1>
- <p className="mt-5 max-w-md text-lg text-white/85">
- {subheadline}
- </p>
- <Buttons section={section} onPhoto />
- </div>
- </Container>
- </section>
- );
- }
-
- /** Words on one side, a tall photo on the other. */
- function SplitHero({
- section,
- photo,
- }: {
- section: HeroSection;
- photo: string | null;
- }) {
- const { eyebrow, headline, subheadline } = section.content;
-
- return (
- <section id={section.id} className="scroll-mt-20" data-hero="split">
- <Container className="grid items-center gap-10 py-12 md:grid-cols-[1fr_1.1fr] md:gap-14 md:py-20">
- <div className="order-2 md:order-1">
- {eyebrow && <Eyebrow>{eyebrow}</Eyebrow>}
- <h1 className="sf-heading mt-4 text-4xl leading-[1.05] font-semibold text-balance sm:text-5xl lg:text-6xl">
- {headline}
- </h1>
- <p className="mt-5 max-w-md text-lg text-(--sf-muted)">
- {subheadline}
- </p>
- <Buttons section={section} />
- </div>
- <div className="order-1 md:order-2">
- {photo ? (
- <img
- src={photo}
- alt=""
- className="sf-card aspect-[4/5] w-full rounded-(--sf-radius-card) object-cover md:aspect-[5/6]"
- />
- ) : (
- <ImagePlaceholder
- label={headline}
- className="aspect-[4/5] w-full md:aspect-[5/6]"
- />
- )}
- </div>
- </Container>
- </section>
- );
- }
-
- /** Words only, centred on a soft background. */
- function CenteredHero({ section }: { section: HeroSection }) {
- const { eyebrow, headline, subheadline } = section.content;
-
- return (
- <section
- id={section.id}
- className="scroll-mt-20 bg-(--sf-surface)"
- data-hero="centered"
- >
- <Container className="flex flex-col items-center py-20 text-center md:py-28">
- {eyebrow && <Eyebrow>{eyebrow}</Eyebrow>}
- <h1 className="sf-heading mt-4 max-w-3xl text-4xl leading-[1.08] font-semibold text-balance sm:text-5xl lg:text-6xl">
- {headline}
- </h1>
- <p className="mt-5 max-w-xl text-lg text-(--sf-muted)">
- {subheadline}
- </p>
- <div className="flex justify-center">
- <Buttons section={section} />
- </div>
- </Container>
- </section>
- );
- }
|