{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"auto-cycling-expanding-flower-panels-that-pause","type":"registry:block","title":"Auto Cycling Expanding Flower Panels That Pause","description":"","dependencies":["framer-motion"],"files":[{"path":"components/we-inc/auto-cycling-expanding-flower-panels-that-pause.tsx","type":"registry:component","content":"import { useEffect, useRef, useState, type CSSProperties, type PointerEvent } from \"react\";\nimport { useReducedMotion } from \"framer-motion\";\n\n// Panels open one after another on their own. A thin bar fills while each one waits;\n// when it finishes, the next panel slides open. Any hover, focus or tap stops the cycle\n// for good, and the cycle also pauses whenever the block is off screen.\nconst BUNCHES = [\n  { name: \"The Garden Party\", stems: \"Gerberas, pale roses, asters\", price: \"$64\", img: \"https://images.pexels.com/photos/38551722/pexels-photo-38551722.jpeg?auto=compress&cs=tinysrgb&w=1200\", alt: \"A hand-tied bunch of red gerberas, pale roses and purple asters\" },\n  { name: \"Tulip Bundle\", stems: \"Forty red and white tulips\", price: \"$42\", img: \"https://images.pexels.com/photos/20491660/pexels-photo-20491660.jpeg?auto=compress&cs=tinysrgb&w=1200\", alt: \"Tightly packed red and white tulips seen from above\" },\n  { name: \"Market Armful\", stems: \"Chrysanthemums, roses, berries\", price: \"$78\", img: \"https://images.pexels.com/photos/34658018/pexels-photo-34658018.jpeg?auto=compress&cs=tinysrgb&w=1200\", alt: \"Orange chrysanthemums, roses, small chillies and berries in a bright mix\" },\n  { name: \"Peony Wrap\", stems: \"Pink peonies in black paper\", price: \"$85\", img: \"https://images.pexels.com/photos/36399737/pexels-photo-36399737.jpeg?auto=compress&cs=tinysrgb&w=1200\", alt: \"Pink peonies wrapped in black paper on a dark table\" },\n  { name: \"Dried Ember\", stems: \"Dried grasses and everlasting flowers\", price: \"$56\", img: \"https://images.pexels.com/photos/31046064/pexels-photo-31046064.jpeg?auto=compress&cs=tinysrgb&w=1200\", alt: \"Dried flowers in red, blue and orange standing against a dark wall\" },\n];\nconst CYCLE_MS = 3000; // how long each bunch stays open before the next one\nconst HOVER_DELAY = 80; // ms before a hovered strip opens\n\nconst CSS = `\n.w5cyc-stage{--c:72px;--n:5;--ow:calc(100% - (var(--n) - 1) * var(--c));position:relative;height:540px;overflow:hidden;border-radius:4px;background:#0d0c0a}\n.w5cyc-panel{position:absolute;inset:0;z-index:var(--i);transform:translateX(calc(var(--i) * var(--c)));transition:transform .9s cubic-bezier(.65,0,.25,1);box-shadow:-14px 0 30px rgba(0,0,0,.5)}\n.w5cyc-panel.is-after{transform:translateX(calc(100% - (var(--n) - var(--i)) * var(--c)))}\n.w5cyc-media{position:absolute;top:0;left:0;bottom:0;width:var(--ow);overflow:hidden;background:#24211c}\n.w5cyc-media img{display:block;width:100%;height:100%;object-fit:cover;transform:translateX(calc(var(--c) / 2 - 50%)) scale(1.12);transition:transform 1.2s cubic-bezier(.65,0,.25,1)}\n.is-open .w5cyc-media img{transform:scale(1.02)}\n.w5cyc-shade{position:absolute;inset:0;background:linear-gradient(to top,rgba(13,12,10,.9),rgba(13,12,10,.1) 50%,rgba(13,12,10,0))}\n.w5cyc-dim{position:absolute;inset:0;background:rgba(13,12,10,.55);transition:opacity .6s}\n.is-open .w5cyc-dim{opacity:0}\n.w5cyc-tab{position:absolute;top:0;left:0;bottom:0;width:var(--c);display:flex;flex-direction:column;align-items:center;justify-content:space-between;padding:24px 0;box-sizing:border-box;color:#f3ece0;pointer-events:none;transition:opacity .3s}\n.is-open .w5cyc-tab{opacity:0}\n.w5cyc-name{writing-mode:vertical-rl;transform:rotate(180deg);font-family:Georgia,'Times New Roman',serif;font-size:17px;white-space:nowrap}\n.w5cyc-cap{position:absolute;left:0;bottom:0;width:var(--ow);box-sizing:border-box;padding:34px;color:#f3ece0;opacity:0;transform:translateY(14px);transition:opacity .3s,transform .3s;pointer-events:none}\n.is-open .w5cyc-cap{opacity:1;transform:none;transition:opacity .6s .4s,transform .7s .4s cubic-bezier(.22,1,.36,1)}\n.w5cyc-cap a{pointer-events:auto}\n.w5cyc-track{display:block;width:160px;height:2px;margin-top:22px;background:rgba(243,236,224,.25);overflow:hidden;opacity:0;transition:opacity .3s}\n.w5cyc-fill{display:block;height:100%;background:#e3b7a3;transform:scaleX(0);transform-origin:0 50%}\n.is-auto .is-open .w5cyc-track{opacity:1}\n.is-auto .is-open .w5cyc-fill{animation:w5cyc-fill var(--dur) linear forwards}\n.w5cyc-root[data-paused] .w5cyc-fill{animation-play-state:paused}\n@keyframes w5cyc-fill{to{transform:scaleX(1)}}\n.w5cyc-hit{position:absolute;top:0;left:0;bottom:0;width:var(--c);padding:0;border:0;background:transparent;cursor:pointer}\n.is-open .w5cyc-hit{width:var(--ow);cursor:default}\n.w5cyc-hit:focus-visible{outline:3px solid #e3b7a3;outline-offset:-7px}\n@media (max-width:640px){\n.w5cyc-stage{--c:56px;height:600px}\n.w5cyc-panel{transform:translateY(calc(var(--i) * var(--c)));box-shadow:0 -14px 30px rgba(0,0,0,.5)}\n.w5cyc-panel.is-after{transform:translateY(calc(100% - (var(--n) - var(--i)) * var(--c)))}\n.w5cyc-media{right:0;bottom:auto;width:auto;height:var(--ow)}\n.w5cyc-media img{transform:translateY(calc(var(--c) / 2 - 50%)) scale(1.12)}\n.w5cyc-tab{right:0;bottom:auto;width:auto;height:var(--c);flex-direction:row;padding:0 20px}\n.w5cyc-name{writing-mode:horizontal-tb;transform:none}\n.w5cyc-cap{width:auto;right:0;bottom:calc((var(--n) - 1) * var(--c));padding:22px}\n.w5cyc-hit{right:0;bottom:auto;width:auto;height:var(--c)}\n.is-open .w5cyc-hit{width:auto;height:var(--ow)}\n}\n@media (prefers-reduced-motion:reduce){.w5cyc-panel,.w5cyc-media img,.w5cyc-dim,.w5cyc-tab,.w5cyc-cap,.is-open .w5cyc-cap{transition:none}.w5cyc-track{display:none}}\n`;\n\nexport default function AutoCyclingExpandingFlowerPanelsThatPause() {\n  const reduce = useReducedMotion();\n  const [open, setOpen] = useState(0);\n  const [auto, setAuto] = useState(true);\n  const [onScreen, setOnScreen] = useState(true);\n  const root = useRef<HTMLElement>(null);\n  const timer = useRef(0);\n  const playing = auto && !reduce;\n\n  useEffect(() => {\n    const el = root.current;\n    if (!el) return;\n    const io = new IntersectionObserver(([e]) => setOnScreen(e.isIntersecting));\n    io.observe(el);\n    return () => { io.disconnect(); window.clearTimeout(timer.current); };\n  }, []);\n\n  const take = (i: number) => { setAuto(false); setOpen(i); };\n  const onEnter = (i: number) => (e: PointerEvent) => {\n    if (e.pointerType !== \"mouse\") return;\n    setAuto(false);\n    window.clearTimeout(timer.current);\n    timer.current = window.setTimeout(() => setOpen(i), HOVER_DELAY);\n  };\n  const b = BUNCHES[open];\n\n  return (\n    <section ref={root} className=\"w5cyc-root bg-[#161512] px-4 py-14 sm:px-8 sm:py-16\" data-paused={onScreen ? undefined : \"\"}>\n      <style>{CSS}</style>\n      <div className=\"mx-auto max-w-6xl\">\n        <div className=\"mb-8 flex flex-wrap items-end justify-between gap-4\">\n          <div>\n            <p className=\"text-xs font-semibold uppercase tracking-[0.24em] text-[#e3b7a3]\">Ashby Flower Room</p>\n            <h2 className=\"mt-3 font-serif text-3xl text-[#f3ece0] sm:text-4xl\">This week&rsquo;s bunches</h2>\n          </div>\n          {!reduce && (\n            <button type=\"button\" onClick={() => setAuto((a) => !a)} className=\"inline-flex h-11 items-center gap-2 rounded-full border border-[#5b544a] px-5 text-sm font-semibold text-[#f3ece0] transition hover:border-[#e3b7a3] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#e3b7a3]\">\n              <svg width=\"14\" height=\"14\" viewBox=\"0 0 14 14\" fill=\"currentColor\" aria-hidden=\"true\">{playing ? <path d=\"M3 2h3v10H3zM8 2h3v10H8z\" /> : <path d=\"M3 1.5v11L12 7z\" />}</svg>\n              {playing ? \"Pause slideshow\" : \"Play slideshow\"}\n            </button>\n          )}\n        </div>\n        <div className={`w5cyc-stage${playing ? \" is-auto\" : \"\"}`} onFocusCapture={() => setAuto(false)}>\n          {BUNCHES.map((f, i) => (\n            <div key={f.name} className={`w5cyc-panel${i === open ? \" is-open\" : \"\"}${i > open ? \" is-after\" : \"\"}`} style={{ \"--i\": i, \"--dur\": `${CYCLE_MS}ms` } as CSSProperties}>\n              <div className=\"w5cyc-media\">\n                <img src={f.img} alt={f.alt} loading={i === 0 ? \"eager\" : \"lazy\"} />\n                <div className=\"w5cyc-shade\" />\n                <div className=\"w5cyc-dim\" />\n              </div>\n              <div className=\"w5cyc-tab\" aria-hidden=\"true\">\n                <span className=\"text-xs font-semibold tabular-nums\">0{i + 1}</span>\n                <span className=\"w5cyc-name\">{f.name}</span>\n                <span className=\"h-1.5 w-1.5 rounded-full bg-[#e3b7a3]\" />\n              </div>\n              <button type=\"button\" className=\"w5cyc-hit\" aria-expanded={i === open} onPointerEnter={onEnter(i)} onPointerLeave={() => window.clearTimeout(timer.current)} onFocus={() => take(i)} onClick={() => take(i)}>\n                <span className=\"sr-only\">{f.name}, {f.price}</span>\n              </button>\n              <div className=\"w5cyc-cap\">\n                <h3 className=\"font-serif text-3xl leading-tight\">{f.name}</h3>\n                <p className=\"mt-2 text-sm text-[#d9d0c2]\">{f.stems} · <span className=\"tabular-nums\">{f.price}</span></p>\n                <a href=\"#\" tabIndex={i === open ? 0 : -1} className=\"mt-5 inline-flex h-10 items-center rounded-full bg-[#f3ece0] px-5 text-sm font-semibold text-[#161512] transition hover:bg-white focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#e3b7a3] focus-visible:ring-offset-2 focus-visible:ring-offset-[#161512]\">Order for Friday</a>\n                <span className=\"w5cyc-track\" aria-hidden=\"true\">\n                  <span key={`${open}-${playing}`} className=\"w5cyc-fill\" onAnimationEnd={() => setOpen((o) => (o + 1) % BUNCHES.length)} />\n                </span>\n              </div>\n            </div>\n          ))}\n        </div>\n        <p className=\"sr-only\" aria-live=\"polite\">{playing ? \"\" : `Showing ${b.name}`}</p>\n      </div>\n    </section>\n  );\n}\n"}]}
