AbiirSkincare/Hydrogen/web/app/components/SkinRitual.tsx

208 lines
6.9 KiB
TypeScript

import {Link} from 'react-router';
import {motion} from 'motion/react';
import type {SkinRitualSectionCms} from '~/lib/skinRitual';
import {MOCK_SKIN_RITUAL_SECTION_CMS} from '~/lib/skinRitual';
import {PAGE_TITLE_TYPOGRAPHY_CLASS} from '~/lib/pageTitle';
/**
* GROQ: `home` singleton → skin ritual module.
* Use with `context.sanity.loadQuery(SKIN_RITUAL_SECTION_GROQ)` or `useQuery` in the browser.
*/
export const SKIN_RITUAL_SECTION_GROQ = `*[_type == "home" && _id == "home"][0].skinRitualSection{
eyebrow,
headlinePrefix,
headlineItalic,
intro,
steps[]{
num,
kicker,
title,
body,
duration
},
footerText,
primaryCtaLabel,
primaryCtaHref,
sectionBackground,
burgundy,
gold,
charcoal,
muted,
gridLine,
numMuted
}` as const;
export {MOCK_SKIN_RITUAL_SECTION_CMS};
export type {SkinRitualSectionCms};
function isExternalHref(href: string) {
return /^https?:\/\//i.test(href);
}
function PrimaryCta({
href,
background,
children,
}: {
href: string;
background: string;
children: React.ReactNode;
}) {
const className =
'inline-flex min-h-[51.844px] w-[min(100%,278.555px)] cursor-pointer items-center justify-center px-[34px] py-[17px] font-["Raleway",sans-serif] text-[14px] font-bold uppercase leading-[19.89px] tracking-[2.3868px] text-white no-underline transition-opacity duration-200 box-border hover:opacity-90';
const style = {
boxSizing: 'border-box' as const,
background,
};
if (isExternalHref(href)) {
return (
<a href={href} className={className} style={style}>
{children}
</a>
);
}
return (
<Link to={href} className={className} style={style}>
{children}
</Link>
);
}
export type SkinRitualProps = {
cms: SkinRitualSectionCms;
};
/**
* `React/src/app/components/SkinRitual.tsx` — no raster images in reference; CMS-driven copy + grid.
*/
export function SkinRitual({cms}: SkinRitualProps) {
const sectionBg = cms.sectionBackground;
const burgundy = cms.burgundy;
const gold = cms.gold;
const charcoal = cms.charcoal;
const muted = cms.muted;
const gridLine = cms.gridLine;
const numMuted = cms.numMuted;
return (
<section className="w-full" style={{background: sectionBg}}>
<div className="mx-auto max-w-[1710px] px-6 pt-16 pb-16 sm:px-10 sm:pt-20 sm:pb-20 lg:px-16 lg:pt-[119px] lg:pb-[94px] xl:px-24 2xl:px-[206px]">
<div className="flex flex-col items-center gap-5 lg:gap-10">
<header className="mx-auto flex w-full max-w-[1298px] flex-col items-center gap-3 text-center lg:gap-6" style={{marginBottom: '-20px'}}>
<motion.p
initial={false}
whileInView={{opacity: 1, y: 0}}
viewport={{once: true}}
transition={{duration: 0.5}}
className="m-0 font-['Jost',sans-serif] text-[12px] font-medium uppercase leading-[16.575px] tracking-[2.7625px] not-italic"
style={{color: burgundy}}
>
{cms.eyebrow}
</motion.p>
<motion.h2
initial={false}
whileInView={{opacity: 1, y: 0}}
viewport={{once: true}}
transition={{duration: 0.6, delay: 0.05}}
className={`m-0 ${PAGE_TITLE_TYPOGRAPHY_CLASS}`}
style={{color: charcoal}}
>
{cms.headlinePrefix}
<span style={{fontStyle: 'italic', fontWeight: 300}}>
{cms.headlineItalic}
</span>
</motion.h2>
<motion.p
initial={false}
whileInView={{opacity: 1, y: 0}}
viewport={{once: true}}
transition={{duration: 0.55, delay: 0.1}}
className="m-0 max-w-[476px] font-['Raleway',sans-serif] text-[16px] font-medium leading-[23.698px] not-italic"
style={{color: muted}}
>
{cms.intro}
</motion.p>
</header>
<div
className="grid w-full max-w-[1298px] grid-cols-1 gap-px sm:grid-cols-2 lg:min-h-[458px] lg:grid-cols-4"
style={{background: gridLine}}
>
{cms.steps.map((step, index) => (
<motion.article
key={step.num}
initial={false}
whileInView={{opacity: 1, y: 0}}
viewport={{once: true, margin: '-40px'}}
transition={{duration: 0.55, delay: index * 0.07}}
className="flex h-full flex-col gap-[17px] p-6 sm:p-8 lg:p-[34px]"
style={{background: sectionBg}}
>
<p
className="m-0 font-['Cormorant_Garamond',serif] text-[51px] font-light leading-[51px] not-italic"
style={{color: numMuted}}
>
{step.num}
</p>
<p
className="m-0 font-['Jost',sans-serif] text-[10.2px] font-medium uppercase leading-[15.3px] tracking-[2.04px] not-italic"
style={{color: burgundy}}
>
{step.kicker}
</p>
<h3
className="m-0 font-['Cormorant_Garamond',serif] text-[24px] font-medium leading-[25.5px] tracking-[-0.204px] not-italic"
style={{color: charcoal}}
>
{step.title}
</h3>
<p
className="m-0 flex-1 font-['Raleway',sans-serif] text-[16px] font-medium leading-[23.698px] not-italic"
style={{color: muted}}
>
{step.body}
</p>
<div className="mt-auto flex items-center gap-[8.5px]">
<span
className="size-[4.25px] shrink-0 rounded-full"
style={{background: gold}}
aria-hidden
/>
<span
className="font-['Jost',sans-serif] text-[11.05px] font-normal leading-[16.575px] not-italic"
style={{color: muted}}
>
{step.duration}
</span>
</div>
</motion.article>
))}
</div>
<motion.p
initial={false}
whileInView={{opacity: 1, y: 0}}
viewport={{once: true}}
transition={{duration: 0.5, delay: 0.15}}
className="m-0 px-2 text-center font-['Raleway',sans-serif] text-[16px] font-medium leading-[23.698px] not-italic"
style={{color: muted}}
>
{cms.footerText}
</motion.p>
<motion.div
initial={false}
whileInView={{opacity: 1, y: 0}}
viewport={{once: true}}
transition={{duration: 0.5, delay: 0.2}}
>
<PrimaryCta href={cms.primaryCtaHref} background={gold}>
{cms.primaryCtaLabel}
</PrimaryCta>
</motion.div>
</div>
</div>
</section>
);
}