Iridescent Ribbon Hero
Left-aligned light-weight headline where the first sentence is dark navy and the remainder is slate blue and picks up a violet-to-magenta gradient where it crosses the artwork. A huge animated silk ribbon in orange, magenta and periwinkle sweeps in from the top right. A purple primary button and an outlined Google sign-up button sit below, and a live counter eyebrow sits above. A logo strip anchors the bottom edge.
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: eyebrow, startValue (live counter start), leadLine (dark first sentence), body (slate/gradient remainder), primaryLabel, secondaryLabel, logos (string[] for the marquee). Renders standalone with defaults; the SVG ribbon drifts via CSS and respects reduced motion.
components/ribbon-hero.tsx
"use client"; import { useLayoutEffect, useRef, type CSSProperties, type ElementType, type ReactNode, type RefObject } from "react"; import { useEffect, useState } from "react"; const defaultLogos = ["Northwind", "Altura", "Lumen", "Kitefield", "Orbitly", "Quanta", "Helix", "Brightfold"]; export default function IridescentRibbonHero({ eyebrow = "Payments volume processed today:", startValue = 2.48193507, leadLine = "Money tools built to move your business forward.", body = "Collect payments, manage accounts and design flexible pricing models, from your first customer to your millionth.", primaryLabel = "Start now", secondaryLabel = "Continue with Google", logos = defaultLogos, }: { eyebrow?: string; startValue?: number; leadLine?: string; body?: string; primaryLabel?: string; secondaryLabel?: string; logos?: string[]; }) { const [v, setV] = useState(startValue); useEffect(() => { const id = setInterval(() => setV((x) => x + Math.random() * 0.00000031), 120); return () => clearInterval(id); }, []); return ( <section className="relative isolate overflow-hidden bg-canvas font-sans text-ink"> <style>{`@keyframes ribbonDrift{0%,100%{transform:translate3d(0,0,0) rotate(0deg)}50%{transform:translate3d(-16px,12px,0) rotate(1.5deg)}}@media (prefers-reduced-motion:reduce){.ribbon-drift{animation:none!important}}`}</style> <div className="pointer-events-none absolute inset-y-0 left-1/2 hidden w-full max-w-[1266px] -translate-x-1/2 border-x border-hairline md:block" aria-hidden="true" /> <svg className="ribbon-drift pointer-events-none absolute -right-24 -top-10 -z-10 h-[780px] w-[900px] max-w-none [animation:ribbonDrift_14s_ease-in-out_infinite] sm:-right-10 lg:right-0" viewBox="0 0 900 780" fill="none" aria-hidden="true"> <defs> <linearGradient id="rb1" x1="150" y1="0" x2="800" y2="700" gradientUnits="userSpaceOnUse"> <stop offset="0" stopColor="#a9c4ff" /> <stop offset="0.3" stopColor="#ffa94d" /> <stop offset="0.6" stopColor="var(--color-signal-orange)" /> <stop offset="0.8" stopColor="var(--color-signal-magenta)" /> <stop offset="1" stopColor="#8b5cf6" /> </linearGradient> <linearGradient id="rb2" x1="300" y1="0" x2="900" y2="600" gradientUnits="userSpaceOnUse"> <stop offset="0" stopColor="#c7d6ff" /> <stop offset="0.5" stopColor="#ff8fd0" /> <stop offset="1" stopColor="#7c5cff" /> </linearGradient> <filter id="rbBlur"><feGaussianBlur stdDeviation="1.2" /></filter> </defs> <g filter="url(#rbBlur)"> <path d="M170 0 L330 0 C520 160 760 330 900 640 L900 780 C760 560 520 400 300 230 C240 180 200 90 170 0Z" fill="url(#rb2)" opacity="0.75" /> <path d="M330 0 L620 0 C760 120 880 260 900 420 L900 700 C820 500 560 300 330 0Z" fill="url(#rb1)" /> {Array.from({ length: 26 }).map((_, i) => ( <path key={i} d={`M${340 + i * 11} 0 C${520 + i * 12} ${130 + i * 6} ${800 + i * 3} ${300 + i * 8} ${900} ${420 + i * 10}`} stroke="#fff" strokeOpacity={0.12 + (i % 3) * 0.06} strokeWidth="1" /> ))} </g> </svg> <div className="relative mx-auto max-w-[1266px] px-6 pb-20 pt-24 md:px-[120px] md:pt-[120px]"> <Reveal from="up" duration={300}> <p className="text-ui font-medium text-ink-deep"> {eyebrow} <span className="font-mono tabular-nums text-ink-faint">{v.toFixed(8)}%</span> </p> </Reveal> <Reveal from="up" delay={80} duration={500}> <h1 className="mt-12 max-w-[1000px] text-[40px] font-light leading-[1.1] tracking-[-0.02em] md:text-[56px]"> <span className="text-ink-deep">{leadLine}</span>{" "} <span className="bg-gradient-to-r from-ink-muted from-40% to-accent bg-clip-text text-transparent">{body}</span> </h1> </Reveal> <Reveal from="up" delay={160} duration={500}> <div className="mt-10 flex flex-wrap gap-2"> <a href="#" className="group inline-flex h-12 items-center gap-2 rounded-sm bg-accent px-6 text-ui font-medium text-surface transition-colors duration-link ease-link hover:bg-ink-deep focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-accent"> {primaryLabel} <svg width="8" height="10" viewBox="0 0 8 10" fill="none" className="transition-transform duration-smooth ease-smooth group-hover:translate-x-[3px]" aria-hidden="true"><path d="M2 1l4 4-4 4" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" /></svg> </a> <a href="#" className="inline-flex h-12 items-center gap-2 rounded-sm border border-hairline bg-surface/70 px-6 text-ui font-medium text-accent transition-colors duration-link ease-link hover:bg-accent-wash focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-accent"> <svg width="14" height="14" viewBox="0 0 14 14" aria-hidden="true"><circle cx="7" cy="7" r="5.5" fill="none" stroke="#4285f4" strokeWidth="2.4" strokeDasharray="9 6" /><circle cx="7" cy="7" r="5.5" fill="none" stroke="#ea4335" strokeWidth="2.4" strokeDasharray="6 30" /></svg> {secondaryLabel} </a> </div> </Reveal> </div> <div className="relative border-t border-hairline bg-canvas/60 py-5"> <Marquee speed={40} gap={72} fade> {logos.map((l, i) => ( <span key={l} className="flex items-center gap-2 text-lead font-semibold tracking-tight text-ink-deep"> <span className={`h-4 w-4 bg-ink-deep ${i % 3 === 0 ? "rounded-full" : i % 3 === 1 ? "rotate-45 rounded-xs" : "rounded-xs"}`} aria-hidden="true" /> {l} </span> ))} </Marquee> </div> </section> ); } // ---- Yoink motion (inlined, no dependencies): Reveal, Marquee ---- 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> ); } const YK_MARQUEE_CSS = `@keyframes yk-marquee-x{to{transform:translate3d(calc(-1 * var(--yk-shift)),0,0)}} @keyframes yk-marquee-y{to{transform:translate3d(0,calc(-1 * var(--yk-shift)),0)}} [data-yk-marquee][data-pause]:hover [data-yk-track]{animation-play-state:paused} @media (prefers-reduced-motion:reduce){[data-yk-track]{animation:none!important}}`; /** An endless, seamless scrolling row (or column) of items: logos, quotes, tags. */ function Marquee({ children, speed = 40, reverse = false, vertical = false, pauseOnHover = true, fade = true, gap = 48, className, style, }: { children?: ReactNode; /** pixels per second */ speed?: number; reverse?: boolean; vertical?: boolean; pauseOnHover?: boolean; fade?: boolean; gap?: number; className?: string; style?: CSSProperties; }) { const box = useRef<HTMLDivElement>(null); const group = useRef<HTMLDivElement>(null); const [m, setM] = useState({ copies: 2, size: 0 }); useEffect(() => { const measure = () => { const b = box.current, g = group.current; if (!b || !g) return; const size = vertical ? g.offsetHeight : g.offsetWidth; const room = vertical ? b.offsetHeight : b.offsetWidth; if (size > 0) setM({ size, copies: Math.max(2, Math.ceil(room / size) + 1) }); }; measure(); const ro = typeof ResizeObserver !== "undefined" ? new ResizeObserver(measure) : null; if (box.current) ro?.observe(box.current); if (group.current) ro?.observe(group.current); return () => ro?.disconnect(); }, [vertical]); // the copies are only there to fill the loop: hide them from screen readers and keyboards useEffect(() => { box.current?.querySelectorAll("[data-yk-copy]").forEach((el) => el.setAttribute("inert", "")); }, [m.copies]); const edge = vertical ? "to bottom" : "to right"; const mask = fade ? `linear-gradient(${edge}, transparent, black 10%, black 90%, transparent)` : undefined; const dir = vertical ? "column" : "row"; const items = (copy: number) => ( <div key={copy} ref={copy === 0 ? group : undefined} data-yk-copy={copy > 0 ? "" : undefined} aria-hidden={copy > 0 || undefined} style={{ display: "flex", flexDirection: dir, flexShrink: 0, alignItems: "center", gap, [vertical ? "paddingBottom" : "paddingRight"]: gap }} > {children} </div> ); return ( <div ref={box} data-yk-marquee="" data-pause={pauseOnHover ? "" : undefined} className={className} style={{ overflow: "hidden", maskImage: mask, WebkitMaskImage: mask, ...style }} > <style>{YK_MARQUEE_CSS}</style> <div data-yk-track="" style={{ display: "flex", flexDirection: dir, width: vertical ? "100%" : "max-content", ["--yk-shift" as string]: `${m.size}px`, animation: m.size ? `yk-marquee-${vertical ? "y" : "x"} ${m.size / Math.max(speed, 1)}s linear infinite${reverse ? " reverse" : ""}` : undefined, }} > {Array.from({ length: m.copies }, (_, i) => items(i))} </div> </div> ); }"use client"; import { useLayoutEffect, useRef, type CSSProperties, type ElementType, type ReactNode, type RefObject } from "react"; import { useEffect, useState } from "react"; const defaultLogos = ["Northwind", "Altura", "Lumen", "Kitefield", "Orbitly", "Quanta", "Helix", "Brightfold"]; export default function IridescentRibbonHero({ eyebrow = "Payments volume processed today:", startValue = 2.48193507, leadLine = "Money tools built to move your business forward.", body = "Collect payments, manage accounts and design flexible pricing models, from your first customer to your millionth.", primaryLabel = "Start now", secondaryLabel = "Continue with Google", logos = defaultLogos, }: { eyebrow?: string; startValue?: number; leadLine?: string; body?: string; primaryLabel?: string; secondaryLabel?: string; logos?: string[]; }) { const [v, setV] = useState(startValue); useEffect(() => { const id = setInterval(() => setV((x) => x + Math.random() * 0.00000031), 120); return () => clearInterval(id); }, []); return ( <section className="relative isolate overflow-hidden bg-background font-sans text-foreground"> <style>{`@keyframes ribbonDrift{0%,100%{transform:translate3d(0,0,0) rotate(0deg)}50%{transform:translate3d(-16px,12px,0) rotate(1.5deg)}}@media (prefers-reduced-motion:reduce){.ribbon-drift{animation:none!important}}`}</style> <div className="pointer-events-none absolute inset-y-0 left-1/2 hidden w-full max-w-[1266px] -translate-x-1/2 border-x border-border md:block" aria-hidden="true" /> <svg className="ribbon-drift pointer-events-none absolute -right-24 -top-10 -z-10 h-[780px] w-[900px] max-w-none [animation:ribbonDrift_14s_ease-in-out_infinite] sm:-right-10 lg:right-0" viewBox="0 0 900 780" fill="none" aria-hidden="true"> <defs> <linearGradient id="rb1" x1="150" y1="0" x2="800" y2="700" gradientUnits="userSpaceOnUse"> <stop offset="0" stopColor="#a9c4ff" /> <stop offset="0.3" stopColor="#ffa94d" /> <stop offset="0.6" stopColor="var(--color-iridescent-signal-orange)" /> <stop offset="0.8" stopColor="var(--color-iridescent-signal-magenta)" /> <stop offset="1" stopColor="#8b5cf6" /> </linearGradient> <linearGradient id="rb2" x1="300" y1="0" x2="900" y2="600" gradientUnits="userSpaceOnUse"> <stop offset="0" stopColor="#c7d6ff" /> <stop offset="0.5" stopColor="#ff8fd0" /> <stop offset="1" stopColor="#7c5cff" /> </linearGradient> <filter id="rbBlur"><feGaussianBlur stdDeviation="1.2" /></filter> </defs> <g filter="url(#rbBlur)"> <path d="M170 0 L330 0 C520 160 760 330 900 640 L900 780 C760 560 520 400 300 230 C240 180 200 90 170 0Z" fill="url(#rb2)" opacity="0.75" /> <path d="M330 0 L620 0 C760 120 880 260 900 420 L900 700 C820 500 560 300 330 0Z" fill="url(#rb1)" /> {Array.from({ length: 26 }).map((_, i) => ( <path key={i} d={`M${340 + i * 11} 0 C${520 + i * 12} ${130 + i * 6} ${800 + i * 3} ${300 + i * 8} ${900} ${420 + i * 10}`} stroke="var(--color-card)" strokeOpacity={0.12 + (i % 3) * 0.06} strokeWidth="1" /> ))} </g> </svg> <div className="relative mx-auto max-w-[1266px] px-6 pb-20 pt-24 md:px-[120px] md:pt-[120px]"> <Reveal from="up" duration={300}> <p className="text-iridescent-ui font-medium text-muted-foreground"> {eyebrow} <span className="font-mono tabular-nums text-muted-foreground">{v.toFixed(8)}%</span> </p> </Reveal> <Reveal from="up" delay={80} duration={500}> <h1 className="mt-12 max-w-[1000px] text-[40px] font-light leading-[1.1] tracking-[-0.02em] md:text-[56px]"> <span className="text-muted-foreground">{leadLine}</span>{" "} <span className="bg-gradient-to-r from-foreground from-40% to-primary bg-clip-text text-transparent">{body}</span> </h1> </Reveal> <Reveal from="up" delay={160} duration={500}> <div className="mt-10 flex flex-wrap gap-2"> <a href="#" className="group inline-flex h-12 items-center gap-2 rounded-sm bg-primary px-6 text-iridescent-ui font-medium text-card transition-colors duration-iridescent-link ease-iridescent-link hover:bg-primary focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary"> {primaryLabel} <svg width="8" height="10" viewBox="0 0 8 10" fill="none" className="transition-transform duration-iridescent-smooth ease-iridescent-smooth group-hover:translate-x-[3px]" aria-hidden="true"><path d="M2 1l4 4-4 4" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" /></svg> </a> <a href="#" className="inline-flex h-12 items-center gap-2 rounded-sm border border-border bg-card/70 px-6 text-iridescent-ui font-medium text-primary transition-colors duration-iridescent-link ease-iridescent-link hover:bg-primary/10 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary"> <svg width="14" height="14" viewBox="0 0 14 14" aria-hidden="true"><circle cx="7" cy="7" r="5.5" fill="none" stroke="#4285f4" strokeWidth="2.4" strokeDasharray="9 6" /><circle cx="7" cy="7" r="5.5" fill="none" stroke="#ea4335" strokeWidth="2.4" strokeDasharray="6 30" /></svg> {secondaryLabel} </a> </div> </Reveal> </div> <div className="relative border-t border-border bg-background/60 py-5"> <Marquee speed={40} gap={72} fade> {logos.map((l, i) => ( <span key={l} className="flex items-center gap-2 text-iridescent-lead font-semibold tracking-tight text-muted-foreground"> <span className={`h-4 w-4 bg-foreground ${i % 3 === 0 ? "rounded-full" : i % 3 === 1 ? "rotate-45 rounded-sm" : "rounded-sm"}`} aria-hidden="true" /> {l} </span> ))} </Marquee> </div> </section> ); } // ---- Yoink motion (inlined, no dependencies): Reveal, Marquee ---- 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> ); } const YK_MARQUEE_CSS = `@keyframes yk-marquee-x{to{transform:translate3d(calc(-1 * var(--yk-shift)),0,0)}} @keyframes yk-marquee-y{to{transform:translate3d(0,calc(-1 * var(--yk-shift)),0)}} [data-yk-marquee][data-pause]:hover [data-yk-track]{animation-play-state:paused} @media (prefers-reduced-motion:reduce){[data-yk-track]{animation:none!important}}`; /** An endless, seamless scrolling row (or column) of items: logos, quotes, tags. */ function Marquee({ children, speed = 40, reverse = false, vertical = false, pauseOnHover = true, fade = true, gap = 48, className, style, }: { children?: ReactNode; /** pixels per second */ speed?: number; reverse?: boolean; vertical?: boolean; pauseOnHover?: boolean; fade?: boolean; gap?: number; className?: string; style?: CSSProperties; }) { const box = useRef<HTMLDivElement>(null); const group = useRef<HTMLDivElement>(null); const [m, setM] = useState({ copies: 2, size: 0 }); useEffect(() => { const measure = () => { const b = box.current, g = group.current; if (!b || !g) return; const size = vertical ? g.offsetHeight : g.offsetWidth; const room = vertical ? b.offsetHeight : b.offsetWidth; if (size > 0) setM({ size, copies: Math.max(2, Math.ceil(room / size) + 1) }); }; measure(); const ro = typeof ResizeObserver !== "undefined" ? new ResizeObserver(measure) : null; if (box.current) ro?.observe(box.current); if (group.current) ro?.observe(group.current); return () => ro?.disconnect(); }, [vertical]); // the copies are only there to fill the loop: hide them from screen readers and keyboards useEffect(() => { box.current?.querySelectorAll("[data-yk-copy]").forEach((el) => el.setAttribute("inert", "")); }, [m.copies]); const edge = vertical ? "to bottom" : "to right"; const mask = fade ? `linear-gradient(${edge}, transparent, black 10%, black 90%, transparent)` : undefined; const dir = vertical ? "column" : "row"; const items = (copy: number) => ( <div key={copy} ref={copy === 0 ? group : undefined} data-yk-copy={copy > 0 ? "" : undefined} aria-hidden={copy > 0 || undefined} style={{ display: "flex", flexDirection: dir, flexShrink: 0, alignItems: "center", gap, [vertical ? "paddingBottom" : "paddingRight"]: gap }} > {children} </div> ); return ( <div ref={box} data-yk-marquee="" data-pause={pauseOnHover ? "" : undefined} className={className} style={{ overflow: "hidden", maskImage: mask, WebkitMaskImage: mask, ...style }} > <style>{YK_MARQUEE_CSS}</style> <div data-yk-track="" style={{ display: "flex", flexDirection: dir, width: vertical ? "100%" : "max-content", ["--yk-shift" as string]: `${m.size}px`, animation: m.size ? `yk-marquee-${vertical ? "y" : "x"} ${m.size / Math.max(speed, 1)}s linear infinite${reverse ? " reverse" : ""}` : undefined, }} > {Array.from({ length: m.copies }, (_, i) => items(i))} </div> </div> ); }
Quality checks
Automated, in a real browser · 5d ago- Accessible: passedNo serious accessibility problems (axe-core): readable contrast, labelled buttons and images.
- Responsive: passedRenders at phone (390px), tablet (768px) and desktop width without sideways scrolling.
- Dark mode: not passedRendered nothing at dark mode
- Themeable: not passed2 hard-coded colours (#4285f4, #ea4335). These ignore the theme and break dark mode.
- Animates cleanly: not passedKeeps animating when reduced motion is turned on