Page sections / Feature sections
Mockup Bento Grid
Two-column bento of white hairline-bordered cards with a light-weight heading at the top left and a tiny expand icon chip at the top right. Each card holds a layered product mockup (terminal, checkout, usage meter, card, globe) over a pastel orange-to-violet bloom or grid backdrop.
Rebuilt from stripe.com in the Iridescent Ledger style.
Looks exactly like stripe.com: brings its fonts and colours, namespaced so your own theme stays untouched.
Restyled to your project: uses your shadcn colours, fonts and radius, so it matches the rest of your app. Layout, type sizes and motion stay as designed.
Usage
Props: heading, subheading and cards (title, span class, kind: checkout|meter|form|card|globe). The expand chip on each card toggles a simple detail overlay.
components/solution-bento.tsx
"use client"; import { useEffect, useLayoutEffect, useRef, type CSSProperties, type ElementType, type ReactNode, type RefObject } from "react"; import { useState } from "react"; type Card = { title: string; span: string; kind: "checkout" | "meter" | "form" | "card" | "globe" }; const defaultCards: Card[] = [ { title: "Book and manage reservations across every channel, on site or remote", span: "md:col-span-2", kind: "checkout" }, { title: "Support any pricing plan", span: "", kind: "meter" }, { title: "Catch abuse before it slows you", span: "", kind: "form" }, { title: "Launch a membership pass", span: "", kind: "card" }, { title: "Send funds worldwide in minutes with digital dollars", span: "", kind: "globe" }, ]; function Expand({ label, onClick }: { label: string; onClick: () => void }) { return ( <button type="button" aria-label={label} onClick={onClick} className="absolute right-4 top-4 z-20 grid h-10 w-10 place-items-center rounded-sm bg-accent-wash text-accent transition-colors duration-smooth hover:bg-accent-soft focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent"> <svg width="12" height="12" viewBox="0 0 12 12" fill="none" stroke="currentColor" strokeWidth="1.6"><path d="M1 5V1h4M11 7v4H7" /></svg> </button> ); } function Visual({ kind }: { kind: Card["kind"] }) { if (kind === "checkout") return ( <div className="absolute inset-x-0 bottom-0 top-28 bg-[radial-gradient(70%_80%_at_0%_100%,var(--color-signal-magenta),transparent),radial-gradient(60%_60%_at_100%_0%,var(--color-signal-orange),transparent)] opacity-90"> <div className="absolute bottom-0 left-8 top-10 w-40 rounded-lg border-4 border-ink-deep bg-surface p-3 shadow-floating text-center"> <p className="mt-8 text-micro text-ink-muted">Pay Harbor Studio</p> <p className="text-h3 text-ink-deep">$24.00</p> <div className="mt-4 space-y-2 text-micro text-ink-muted">{["Day pass", "Member credit", "Tax"].map((r) => <div key={r} className="flex justify-between border-b border-hairline pb-1"><span>{r}</span><span>$8.00</span></div>)}</div> <div className="mt-4 rounded-xs bg-accent-wash py-2 text-micro text-accent">Continue</div> </div> <div className="absolute bottom-0 left-56 right-[-40px] top-12 rounded-t-md border border-hairline bg-surface shadow-floating"> <div className="flex gap-1 border-b border-hairline p-3"><i className="h-2 w-2 rounded-pill bg-hairline"/><i className="h-2 w-2 rounded-pill bg-hairline"/><i className="h-2 w-2 rounded-pill bg-hairline"/></div> <div className="grid gap-3 p-5 text-micro text-ink-muted sm:grid-cols-2"> <div className="space-y-2"><div className="rounded-xs border border-hairline p-2">guest@example.com</div><div className="flex gap-2"><div className="h-6 flex-1 rounded-xs bg-[#00d66f]"/><div className="h-6 flex-1 rounded-xs bg-ink-deep"/></div>{["Card","Wallet","Bank transfer"].map((m)=><div key={m} className="rounded-xs border border-hairline p-2">{m}</div>)}</div> <div className="space-y-2"><p className="text-ink">Summary</p><div className="h-12 rounded-xs border border-hairline"/><div className="flex justify-between"><span>Subtotal</span><span>$24.00</span></div><div className="flex justify-between"><span>Total</span><span>$26.40</span></div></div> </div> </div> </div> ); if (kind === "meter") return ( <div className="absolute inset-x-0 bottom-0 top-24 bg-sunrise-bloom"> <div className="mx-auto mt-4 w-[88%] rounded-md border border-hairline bg-surface p-4 shadow-card"> <div className="flex items-center gap-3"><div className="h-9 w-9 rounded-sm bg-accent-wash"/><div><p className="text-ui text-ink-deep">Starter Plan</p><p className="text-caption text-ink-faint">Billed yearly</p></div></div> <p className="mt-4 text-caption text-ink">Requests</p> <p className="text-micro text-ink-muted">$0.02 per 500 calls</p> <div className="mt-3 h-2 rounded-pill bg-canvas"><div className="h-2 w-1/2 rounded-pill bg-gradient-to-r from-accent to-signal-magenta"/></div> </div> <div className="mx-auto mt-3 w-[88%] rounded-md border border-hairline bg-surface p-4 shadow-card"> <p className="text-micro text-ink-muted">Calls this month</p> <div className="mt-3 flex h-24 items-end gap-1">{Array.from({length:28}).map((_,i)=><i key={i} className="w-1.5 rounded-xs bg-accent/70" style={{height:`${10+Math.abs(Math.sin(i*0.7))*85}%`}}/>)}</div> </div> </div> ); if (kind === "form") return ( <div className="absolute inset-x-0 bottom-0 top-24 bg-[linear-gradient(to_right,var(--color-hairline)_1px,transparent_1px),linear-gradient(to_bottom,var(--color-hairline)_1px,transparent_1px)] bg-[size:30px_30px]"> <div className="absolute inset-x-0 bottom-0 h-1/2 bg-gradient-to-t from-signal-orange to-transparent"/> <div className="relative mx-6 mt-12 space-y-2 rounded-md border border-hairline bg-surface p-4 text-micro text-ink-muted shadow-card"> <p>Member details</p><div className="rounded-xs border border-hairline p-2 text-ink">Alex Morgan</div> <p>Account number</p><div className="rounded-xs border border-hairline p-2 text-ink">1111 2222 3333 4444</div> <div className="flex gap-2"><div className="flex-1 rounded-xs border border-hairline p-2">08/29</div><div className="flex-1 rounded-xs border border-signal-magenta p-2">4</div></div> </div> </div> ); if (kind === "card") return ( <div className="absolute inset-x-0 bottom-0 top-24 bg-pastel-bloom"> <div className="mx-auto mt-10 h-[22rem] w-[65%] overflow-hidden rounded-lg bg-[linear-gradient(160deg,var(--color-signal-orange),var(--color-signal-magenta)_35%,var(--color-accent)_55%,#fff_75%)] shadow-floating"> <div className="m-5 h-8 w-10 rounded-xs bg-white/60"/> <p className="absolute bottom-4 right-5 text-h3 italic text-accent">PASS</p> </div> </div> ); return ( <div className="absolute inset-x-0 bottom-0 top-32 overflow-hidden bg-pastel-bloom"> <svg viewBox="0 0 300 300" className="absolute -bottom-16 left-0 h-[110%] w-full" aria-hidden> <defs><radialGradient id="gl"><stop offset="0" stopColor="var(--color-accent)" stopOpacity=".1"/><stop offset="1" stopColor="var(--color-signal-magenta)" stopOpacity=".5"/></radialGradient></defs> <circle cx="150" cy="170" r="140" fill="url(#gl)"/> {Array.from({length:160}).map((_,i)=><circle key={i} cx={20+((i*97)%260)} cy={40+((i*53)%240)} r="1.3" fill="var(--color-accent)" opacity=".6"/>)} <path d="M190 40 Q150 120 160 220" stroke="var(--color-signal-magenta)" fill="none"/> </svg> <span className="absolute bottom-24 left-1/2 rounded-pill bg-surface px-3 py-1 text-micro text-ink shadow-card">$85 USD</span> </div> ); } export default function MockupBentoGrid({ heading = "Adaptable tools for every kind of studio.", subheading = " Run your whole operation with a connected suite of booking and billing features, built to work alone or as one.", cards = defaultCards }: { heading?: string; subheading?: string; cards?: Card[] }) { const [open, setOpen] = useState<string | null>(null); return ( <section className="bg-canvas px-4 py-16 font-sans md:px-6"> <div className="mx-auto max-w-[1232px]"> <Reveal><h2 className="mb-14 max-w-3xl text-h2 font-light text-ink-deep">{heading}<span className="text-ink-muted">{subheading}</span></h2></Reveal> <Stagger className="grid gap-4 md:grid-cols-2" step={90}> {cards.map((c) => ( <article key={c.title} className={`relative min-h-[34rem] overflow-hidden rounded-md border border-hairline bg-surface ${c.span} ${c.kind==="checkout"?"md:min-h-[42rem]":""}`}> <h3 className="relative z-10 max-w-[75%] p-6 text-h3 font-light text-ink-deep">{c.title}</h3> <Expand label={`Expand: ${c.title}`} onClick={() => setOpen(open === c.title ? null : c.title)} /> <Visual kind={c.kind} /> {open === c.title && ( <div role="dialog" aria-label={c.title} className="absolute inset-0 z-30 grid place-items-center bg-surface/90 p-6 text-center backdrop-blur-md"> <div><p className="text-h3 text-ink-deep">{c.title}</p><button type="button" onClick={() => setOpen(null)} className="mt-4 rounded-pill bg-accent px-4 py-2 text-ui text-surface focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent">Close</button></div> </div> )} </article> ))} </Stagger> </div> </section> ); } // ---- Yoink motion (inlined, no dependencies): Reveal, Stagger ---- const YK_EASE = "cubic-bezier(0.16, 1, 0.3, 1)"; const useYkLayoutEffect = typeof window === "undefined" ? useEffect : useLayoutEffect; function ykReducedMotion(): boolean { return typeof window !== "undefined" && !!window.matchMedia?.("(prefers-reduced-motion: reduce)").matches; } // "idle": untouched (visible) · "hidden": waiting below the fold · "shown": play the entrance. // Content is only hidden once we know we can show it again (IntersectionObserver exists, motion allowed, // and there is a box to watch), and a safety net reveals anything on screen that is still hidden. type YkRevealState = "idle" | "hidden" | "shown"; function useYkReveal(ref: RefObject<Element | null>, once = true): YkRevealState { const [state, setState] = useState<YkRevealState>("idle"); useYkLayoutEffect(() => { const el = ref.current; if (!el || ykReducedMotion() || typeof IntersectionObserver === "undefined") return; // watch the element's own box, or its children when it has none (display: contents) const boxes = () => (getComputedStyle(el).display === "contents" ? Array.from(el.children) : [el]); const onScreen = (t: Element) => { const r = t.getBoundingClientRect(); return (r.width > 0 || r.height > 0) && r.bottom > 0 && r.right > 0 && r.top < window.innerHeight && r.left < window.innerWidth; }; if (!boxes().some((t) => t.getBoundingClientRect().width > 0 || t.getBoundingClientRect().height > 0)) return; // e.g. hidden at mount: leave it visible let shown = false; const show = (v: boolean) => { if (v !== shown) (shown = v), setState(v ? "shown" : "hidden"); }; setState("hidden"); const inView = new Set<Element>(); const io = new IntersectionObserver((entries) => { for (const e of entries) { if (e.isIntersecting) inView.add(e.target); else inView.delete(e.target); } if (inView.size) { show(true); if (once) io.disconnect(); } else if (!once) show(false); }); const watched = new Set<Element>(); const watch = () => boxes().forEach((t) => !watched.has(t) && (watched.add(t), io.observe(t))); watch(); // safety net: styles that land after mount (display: contents) get watched too, and nothing // stays hidden for more than a moment while it is actually on screen const start = Date.now(); const net = setInterval(() => { if (shown) return once && clearInterval(net); watch(); if (Date.now() - start > 2400 && boxes().some(onScreen)) show(true); }, 600); return () => { io.disconnect(); clearInterval(net); }; }, [once]); return state; } type YkRevealFrom = "up" | "down" | "left" | "right" | "scale" | "blur" | "none"; /** Fades content in as it scrolls into view. */ function Reveal({ children, from = "up", delay = 0, duration = 700, distance = 24, once = true, as = "div", className, style, }: { children?: ReactNode; from?: YkRevealFrom; delay?: number; duration?: number; distance?: number; once?: boolean; as?: ElementType; className?: string; style?: CSSProperties; }) { const Tag = as; const ref = useRef<HTMLElement>(null); const state = useYkReveal(ref, once); const hidden = state === "hidden"; const offset = { up: `translate3d(0, ${distance}px, 0)`, down: `translate3d(0, ${-distance}px, 0)`, left: `translate3d(${-distance}px, 0, 0)`, right: `translate3d(${distance}px, 0, 0)`, scale: "scale(0.94)", blur: `translate3d(0, ${distance / 2}px, 0)`, none: "none", }[from]; const t = `${duration}ms ${YK_EASE} ${delay}ms`; return ( <Tag ref={ref} className={className} style={{ ...style, ...(hidden && { opacity: 0, transform: offset, filter: from === "blur" ? "blur(12px)" : undefined }), ...(state === "shown" && { transition: `opacity ${t}, transform ${t}, filter ${t}` }), }} > {children} </Tag> ); } /** Reveals each direct child one after another when the group scrolls into view. */ function Stagger({ children, step = 90, from = "up", distance = 20, duration = 650, delay = 0, once = true, as = "div", className, style, }: { children?: ReactNode; step?: number; from?: "up" | "down" | "left" | "right" | "scale" | "fade"; distance?: number; duration?: number; delay?: number; once?: boolean; as?: ElementType; className?: string; style?: CSSProperties; }) { const Tag = as; const ref = useRef<HTMLElement>(null); const state = useYkReveal(ref, once); useYkLayoutEffect(() => { const items = Array.from(ref.current?.children ?? []) as HTMLElement[]; if (state === "idle") return; const offset = { up: `translate3d(0, ${distance}px, 0)`, down: `translate3d(0, ${-distance}px, 0)`, left: `translate3d(${-distance}px, 0, 0)`, right: `translate3d(${distance}px, 0, 0)`, scale: "scale(0.92)", fade: "none", }[from]; if (state === "hidden") { for (const el of items) Object.assign(el.style, { transition: "none", opacity: "0", transform: offset }); return; } items.forEach((el, i) => { const t = `${duration}ms ${YK_EASE} ${delay + i * step}ms`; Object.assign(el.style, { transition: `opacity ${t}, transform ${t}`, opacity: "", transform: "" }); }); // hand the children their own transitions back once everything has landed const done = setTimeout(() => items.forEach((el) => (el.style.transition = "")), delay + items.length * step + duration + 50); return () => clearTimeout(done); }, [state]); return ( <Tag ref={ref} className={className} style={style}> {children} </Tag> ); }"use client"; import { useEffect, useLayoutEffect, useRef, type CSSProperties, type ElementType, type ReactNode, type RefObject } from "react"; import { useState } from "react"; type Card = { title: string; span: string; kind: "checkout" | "meter" | "form" | "card" | "globe" }; const defaultCards: Card[] = [ { title: "Book and manage reservations across every channel, on site or remote", span: "md:col-span-2", kind: "checkout" }, { title: "Support any pricing plan", span: "", kind: "meter" }, { title: "Catch abuse before it slows you", span: "", kind: "form" }, { title: "Launch a membership pass", span: "", kind: "card" }, { title: "Send funds worldwide in minutes with digital dollars", span: "", kind: "globe" }, ]; function Expand({ label, onClick }: { label: string; onClick: () => void }) { return ( <button type="button" aria-label={label} onClick={onClick} className="absolute right-4 top-4 z-20 grid h-10 w-10 place-items-center rounded-sm bg-primary/10 text-primary transition-colors duration-iridescent-smooth hover:bg-iridescent-accent-soft focus-visible:outline focus-visible:outline-2 focus-visible:outline-primary"> <svg width="12" height="12" viewBox="0 0 12 12" fill="none" stroke="currentColor" strokeWidth="1.6"><path d="M1 5V1h4M11 7v4H7" /></svg> </button> ); } function Visual({ kind }: { kind: Card["kind"] }) { if (kind === "checkout") return ( <div className="absolute inset-x-0 bottom-0 top-28 bg-[radial-gradient(70%_80%_at_0%_100%,var(--color-iridescent-signal-magenta),transparent),radial-gradient(60%_60%_at_100%_0%,var(--color-iridescent-signal-orange),transparent)] opacity-90"> <div className="absolute bottom-0 left-8 top-10 w-40 rounded-md border-4 border-muted-foreground bg-card p-3 shadow-iridescent-floating text-center"> <p className="mt-8 text-iridescent-micro text-muted-foreground">Pay Harbor Studio</p> <p className="text-iridescent-h3 text-muted-foreground">$24.00</p> <div className="mt-4 space-y-2 text-iridescent-micro text-muted-foreground">{["Day pass", "Member credit", "Tax"].map((r) => <div key={r} className="flex justify-between border-b border-border pb-1"><span>{r}</span><span>$8.00</span></div>)}</div> <div className="mt-4 rounded-sm bg-primary/10 py-2 text-iridescent-micro text-primary">Continue</div> </div> <div className="absolute bottom-0 left-56 right-[-40px] top-12 rounded-t-md border border-border bg-card shadow-iridescent-floating"> <div className="flex gap-1 border-b border-border p-3"><i className="h-2 w-2 rounded-full bg-border"/><i className="h-2 w-2 rounded-full bg-border"/><i className="h-2 w-2 rounded-full bg-border"/></div> <div className="grid gap-3 p-5 text-iridescent-micro text-muted-foreground sm:grid-cols-2"> <div className="space-y-2"><div className="rounded-sm border border-border p-2">guest@example.com</div><div className="flex gap-2"><div className="h-6 flex-1 rounded-sm bg-[#00d66f]"/><div className="h-6 flex-1 rounded-sm bg-foreground"/></div>{["Card","Wallet","Bank transfer"].map((m)=><div key={m} className="rounded-sm border border-border p-2">{m}</div>)}</div> <div className="space-y-2"><p className="text-foreground">Summary</p><div className="h-12 rounded-sm border border-border"/><div className="flex justify-between"><span>Subtotal</span><span>$24.00</span></div><div className="flex justify-between"><span>Total</span><span>$26.40</span></div></div> </div> </div> </div> ); if (kind === "meter") return ( <div className="absolute inset-x-0 bottom-0 top-24 bg-iridescent-sunrise-bloom"> <div className="mx-auto mt-4 w-[88%] rounded-md border border-border bg-card p-4 shadow-iridescent-card"> <div className="flex items-center gap-3"><div className="h-9 w-9 rounded-sm bg-primary/10"/><div><p className="text-iridescent-ui text-muted-foreground">Starter Plan</p><p className="text-iridescent-caption text-muted-foreground">Billed yearly</p></div></div> <p className="mt-4 text-iridescent-caption text-foreground">Requests</p> <p className="text-iridescent-micro text-muted-foreground">$0.02 per 500 calls</p> <div className="mt-3 h-2 rounded-full bg-background"><div className="h-2 w-1/2 rounded-full bg-gradient-to-r from-primary to-iridescent-signal-magenta"/></div> </div> <div className="mx-auto mt-3 w-[88%] rounded-md border border-border bg-card p-4 shadow-iridescent-card"> <p className="text-iridescent-micro text-muted-foreground">Calls this month</p> <div className="mt-3 flex h-24 items-end gap-1">{Array.from({length:28}).map((_,i)=><i key={i} className="w-1.5 rounded-sm bg-primary/70" style={{height:`${10+Math.abs(Math.sin(i*0.7))*85}%`}}/>)}</div> </div> </div> ); if (kind === "form") return ( <div className="absolute inset-x-0 bottom-0 top-24 bg-[linear-gradient(to_right,var(--color-border)_1px,transparent_1px),linear-gradient(to_bottom,var(--color-border)_1px,transparent_1px)] bg-[size:30px_30px]"> <div className="absolute inset-x-0 bottom-0 h-1/2 bg-gradient-to-t from-iridescent-signal-orange to-transparent"/> <div className="relative mx-6 mt-12 space-y-2 rounded-md border border-border bg-card p-4 text-iridescent-micro text-muted-foreground shadow-iridescent-card"> <p>Member details</p><div className="rounded-sm border border-border p-2 text-foreground">Alex Morgan</div> <p>Account number</p><div className="rounded-sm border border-border p-2 text-foreground">1111 2222 3333 4444</div> <div className="flex gap-2"><div className="flex-1 rounded-sm border border-border p-2">08/29</div><div className="flex-1 rounded-sm border border-iridescent-signal-magenta p-2">4</div></div> </div> </div> ); if (kind === "card") return ( <div className="absolute inset-x-0 bottom-0 top-24 bg-iridescent-pastel-bloom"> <div className="mx-auto mt-10 h-[22rem] w-[65%] overflow-hidden rounded-md bg-[linear-gradient(160deg,var(--color-iridescent-signal-orange),var(--color-iridescent-signal-magenta)_35%,var(--color-primary)_55%,#fff_75%)] shadow-iridescent-floating"> <div className="m-5 h-8 w-10 rounded-sm bg-background/60"/> <p className="absolute bottom-4 right-5 text-iridescent-h3 italic text-primary">PASS</p> </div> </div> ); return ( <div className="absolute inset-x-0 bottom-0 top-32 overflow-hidden bg-iridescent-pastel-bloom"> <svg viewBox="0 0 300 300" className="absolute -bottom-16 left-0 h-[110%] w-full" aria-hidden> <defs><radialGradient id="gl"><stop offset="0" stopColor="var(--color-primary)" stopOpacity=".1"/><stop offset="1" stopColor="var(--color-iridescent-signal-magenta)" stopOpacity=".5"/></radialGradient></defs> <circle cx="150" cy="170" r="140" fill="url(#gl)"/> {Array.from({length:160}).map((_,i)=><circle key={i} cx={20+((i*97)%260)} cy={40+((i*53)%240)} r="1.3" fill="var(--color-primary)" opacity=".6"/>)} <path d="M190 40 Q150 120 160 220" stroke="var(--color-iridescent-signal-magenta)" fill="none"/> </svg> <span className="absolute bottom-24 left-1/2 rounded-full bg-card px-3 py-1 text-iridescent-micro text-foreground shadow-iridescent-card">$85 USD</span> </div> ); } export default function MockupBentoGrid({ heading = "Adaptable tools for every kind of studio.", subheading = " Run your whole operation with a connected suite of booking and billing features, built to work alone or as one.", cards = defaultCards }: { heading?: string; subheading?: string; cards?: Card[] }) { const [open, setOpen] = useState<string | null>(null); return ( <section className="bg-background px-4 py-16 font-sans md:px-6"> <div className="mx-auto max-w-[1232px]"> <Reveal><h2 className="mb-14 max-w-3xl text-iridescent-h2 font-light text-muted-foreground">{heading}<span className="text-muted-foreground">{subheading}</span></h2></Reveal> <Stagger className="grid gap-4 md:grid-cols-2" step={90}> {cards.map((c) => ( <article key={c.title} className={`relative min-h-[34rem] overflow-hidden rounded-md border border-border bg-card ${c.span} ${c.kind==="checkout"?"md:min-h-[42rem]":""}`}> <h3 className="relative z-10 max-w-[75%] p-6 text-iridescent-h3 font-light text-muted-foreground">{c.title}</h3> <Expand label={`Expand: ${c.title}`} onClick={() => setOpen(open === c.title ? null : c.title)} /> <Visual kind={c.kind} /> {open === c.title && ( <div role="dialog" aria-label={c.title} className="absolute inset-0 z-30 grid place-items-center bg-card/90 p-6 text-center backdrop-blur-md"> <div><p className="text-iridescent-h3 text-muted-foreground">{c.title}</p><button type="button" onClick={() => setOpen(null)} className="mt-4 rounded-full bg-primary px-4 py-2 text-iridescent-ui text-card focus-visible:outline focus-visible:outline-2 focus-visible:outline-primary">Close</button></div> </div> )} </article> ))} </Stagger> </div> </section> ); } // ---- Yoink motion (inlined, no dependencies): Reveal, Stagger ---- const YK_EASE = "cubic-bezier(0.16, 1, 0.3, 1)"; const useYkLayoutEffect = typeof window === "undefined" ? useEffect : useLayoutEffect; function ykReducedMotion(): boolean { return typeof window !== "undefined" && !!window.matchMedia?.("(prefers-reduced-motion: reduce)").matches; } // "idle": untouched (visible) · "hidden": waiting below the fold · "shown": play the entrance. // Content is only hidden once we know we can show it again (IntersectionObserver exists, motion allowed, // and there is a box to watch), and a safety net reveals anything on screen that is still hidden. type YkRevealState = "idle" | "hidden" | "shown"; function useYkReveal(ref: RefObject<Element | null>, once = true): YkRevealState { const [state, setState] = useState<YkRevealState>("idle"); useYkLayoutEffect(() => { const el = ref.current; if (!el || ykReducedMotion() || typeof IntersectionObserver === "undefined") return; // watch the element's own box, or its children when it has none (display: contents) const boxes = () => (getComputedStyle(el).display === "contents" ? Array.from(el.children) : [el]); const onScreen = (t: Element) => { const r = t.getBoundingClientRect(); return (r.width > 0 || r.height > 0) && r.bottom > 0 && r.right > 0 && r.top < window.innerHeight && r.left < window.innerWidth; }; if (!boxes().some((t) => t.getBoundingClientRect().width > 0 || t.getBoundingClientRect().height > 0)) return; // e.g. hidden at mount: leave it visible let shown = false; const show = (v: boolean) => { if (v !== shown) (shown = v), setState(v ? "shown" : "hidden"); }; setState("hidden"); const inView = new Set<Element>(); const io = new IntersectionObserver((entries) => { for (const e of entries) { if (e.isIntersecting) inView.add(e.target); else inView.delete(e.target); } if (inView.size) { show(true); if (once) io.disconnect(); } else if (!once) show(false); }); const watched = new Set<Element>(); const watch = () => boxes().forEach((t) => !watched.has(t) && (watched.add(t), io.observe(t))); watch(); // safety net: styles that land after mount (display: contents) get watched too, and nothing // stays hidden for more than a moment while it is actually on screen const start = Date.now(); const net = setInterval(() => { if (shown) return once && clearInterval(net); watch(); if (Date.now() - start > 2400 && boxes().some(onScreen)) show(true); }, 600); return () => { io.disconnect(); clearInterval(net); }; }, [once]); return state; } type YkRevealFrom = "up" | "down" | "left" | "right" | "scale" | "blur" | "none"; /** Fades content in as it scrolls into view. */ function Reveal({ children, from = "up", delay = 0, duration = 700, distance = 24, once = true, as = "div", className, style, }: { children?: ReactNode; from?: YkRevealFrom; delay?: number; duration?: number; distance?: number; once?: boolean; as?: ElementType; className?: string; style?: CSSProperties; }) { const Tag = as; const ref = useRef<HTMLElement>(null); const state = useYkReveal(ref, once); const hidden = state === "hidden"; const offset = { up: `translate3d(0, ${distance}px, 0)`, down: `translate3d(0, ${-distance}px, 0)`, left: `translate3d(${-distance}px, 0, 0)`, right: `translate3d(${distance}px, 0, 0)`, scale: "scale(0.94)", blur: `translate3d(0, ${distance / 2}px, 0)`, none: "none", }[from]; const t = `${duration}ms ${YK_EASE} ${delay}ms`; return ( <Tag ref={ref} className={className} style={{ ...style, ...(hidden && { opacity: 0, transform: offset, filter: from === "blur" ? "blur(12px)" : undefined }), ...(state === "shown" && { transition: `opacity ${t}, transform ${t}, filter ${t}` }), }} > {children} </Tag> ); } /** Reveals each direct child one after another when the group scrolls into view. */ function Stagger({ children, step = 90, from = "up", distance = 20, duration = 650, delay = 0, once = true, as = "div", className, style, }: { children?: ReactNode; step?: number; from?: "up" | "down" | "left" | "right" | "scale" | "fade"; distance?: number; duration?: number; delay?: number; once?: boolean; as?: ElementType; className?: string; style?: CSSProperties; }) { const Tag = as; const ref = useRef<HTMLElement>(null); const state = useYkReveal(ref, once); useYkLayoutEffect(() => { const items = Array.from(ref.current?.children ?? []) as HTMLElement[]; if (state === "idle") return; const offset = { up: `translate3d(0, ${distance}px, 0)`, down: `translate3d(0, ${-distance}px, 0)`, left: `translate3d(${-distance}px, 0, 0)`, right: `translate3d(${distance}px, 0, 0)`, scale: "scale(0.92)", fade: "none", }[from]; if (state === "hidden") { for (const el of items) Object.assign(el.style, { transition: "none", opacity: "0", transform: offset }); return; } items.forEach((el, i) => { const t = `${duration}ms ${YK_EASE} ${delay + i * step}ms`; Object.assign(el.style, { transition: `opacity ${t}, transform ${t}`, opacity: "", transform: "" }); }); // hand the children their own transitions back once everything has landed const done = setTimeout(() => items.forEach((el) => (el.style.transition = "")), delay + items.length * step + duration + 50); return () => clearTimeout(done); }, [state]); return ( <Tag ref={ref} className={className} style={style}> {children} </Tag> ); }
Quality checks
Automated, in a real browser · 5d ago- Accessible: not passedElements must meet minimum color contrast ratio thresholds (1 element)
- Responsive: passedRenders at phone (390px), tablet (768px) and desktop width without sideways scrolling.
- Dark mode: passedStill readable when installed in your theme and switched to dark mode.
- Themeable: not passed1 hard-coded colour (bg-[#00d66f]). These ignore the theme and break dark mode.
- Animates cleanly: passedIts animation plays and finishes with everything visible, and it stays still for people who turn on reduced motion.