# Feature Bento
*URL: https://www.grettech.com/components/feature-bento*

A feature bento where each card plays a small live scene. Use the built-in deploy, speed, build and growth scenes by name, or drop in your own.

- Built-in scenes by name: deploy, speed, build and growth
- Your own cards and scenes: a skeleton is any React node
- Tall and wide cards; the grid fills itself
- Animated with Motion, only on screen; still for reduced motion

## Install with the shadcn CLI
```bash
npx shadcn@latest add https://www.grettech.com/api/registry/feature-bento
```
With its demo: `npx shadcn@latest add https://www.grettech.com/api/registry/feature-bento-demo`

**Dependencies:** npm: motion, clsx, tailwind-merge

## Manual installation
**Step 1: Install dependencies**
Install the packages this component uses. It also needs the `cn` helper in `lib/utils.ts`, which `npx shadcn@latest init` adds.

```bash
npm install motion clsx tailwind-merge
```

**Step 2: Copy the source code**
Add these files to your project components directory.

File: `components/ui/feature-bento.tsx`
```tsx
"use client"

import { cn } from "@/lib/utils"
import {
  AnimatePresence,
  animate,
  motion,
  useInView,
  useMotionValue,
  useReducedMotion,
  useTransform,
  type TargetAndTransition,
  type Transition,
} from "motion/react"
import * as React from "react"

/* ─── Types ─────────────────────────────────────────────────────────── */

/** The scenes that come with the bento; pass any React node for your own */
export type FeatureSkeleton = "deploy" | "speed" | "build" | "growth"

export type FeatureBentoFeature = {
  title: string
  description: string
  /** The scene at the top of the card: a built-in one by name, or any
   * React node of your own */
  skeleton?: FeatureSkeleton | React.ReactNode
  /** An image for the top of the card, in place of a skeleton */
  image?: string
  imageAlt?: string
  /** default: one cell; tall: two rows; wide: two columns */
  span?: "default" | "tall" | "wide"
}

export type DeployCommit = { message: string; author: string; avatar?: string }
export type SpeedMetric = { label: string; value: string }
export type BuildPerson = { name: string; color: string; avatar?: string }
export type GrowthQuote = {
  quote: string
  name: string
  role?: string
  avatar?: string
}

/* ─── Motion ────────────────────────────────────────────────────────── */

/**
 * Whether scenes should play: a FeatureCard turns this off while it's off
 * screen. Outside a card, scenes always play.
 */
const PlayContext = React.createContext(true)

/** Plays unless off screen or the visitor prefers reduced motion */
function usePlaying() {
  const onScreen = React.useContext(PlayContext)
  const reduced = useReducedMotion() ?? false
  return onScreen && !reduced
}

type Frames = Record<string, (number | string)[]>

/**
 * A looping keyframe animation for a motion element. While it can't play
 * (off screen, or reduced motion) the element rests in its finished pose.
 */
function loop(
  on: boolean,
  frames: Frames,
  rest: TargetAndTransition,
  {
    duration,
    times,
    delay = 0,
    ease = "easeOut",
  }: {
    duration: number
    times: number[]
    delay?: number
    ease?: Transition["ease"]
  }
) {
  return {
    initial: false as const,
    animate: on ? (frames as TargetAndTransition) : rest,
    transition: on
      ? { duration, times, delay, ease, repeat: Infinity }
      : { duration: 0.3 },
  }
}

/* ─── Shared bits ───────────────────────────────────────────────────── */

/** Hairline, softly shadowed surface used throughout the scenes */
const surface =
  "bg-card shadow-sm shadow-black/[0.06] ring-1 ring-black/[0.08] dark:shadow-black/40 dark:ring-white/10"

function Avatar({
  src,
  name,
  color,
  className,
}: {
  src?: string
  name: string
  color?: string
  className?: string
}) {
  return src ? (
    // eslint-disable-next-line @next/next/no-img-element
    <img
      src={src}
      alt=""
      className={cn("shrink-0 rounded-full object-cover", className)}
    />
  ) : (
    <span
      className={cn(
        "flex shrink-0 items-center justify-center rounded-full text-[9px] font-semibold text-white",
        className
      )}
      style={{ backgroundColor: color ?? "#71717a" }}
    >
      {name.slice(0, 1)}
    </span>
  )
}

/** A soft ring that keeps pulsing out of a status dot */
function Ping({ color, className }: { color: string; className?: string }) {
  const on = usePlaying()
  return (
    <motion.span
      className={cn("absolute inset-0 rounded-full", className)}
      style={{ backgroundColor: color }}
      {...loop(
        on,
        { scale: [1, 2.6, 2.6], opacity: [0.55, 0, 0] },
        { scale: 1, opacity: 0 },
        { duration: 1.6, times: [0, 0.7, 1] }
      )}
    />
  )
}

/* ─── Skeletons ─────────────────────────────────────────────────────── */

const DEFAULT_COMMITS: DeployCommit[] = [
  {
    message: "Tighten hero spacing",
    author: "Ana",
    avatar:
      "https://images.unsplash.com/photo-1438761681033-6461ffad8d80?w=200&h=200&fit=crop&crop=faces&q=75",
  },
  {
    message: "Add pricing FAQ",
    author: "Ravi",
    avatar:
      "https://images.unsplash.com/photo-1535713875002-d1d0cf377fde?w=200&h=200&fit=crop&crop=faces&q=75",
  },
  {
    message: "Compress product images",
    author: "Sam",
    avatar:
      "https://images.unsplash.com/photo-1500648767791-00dcc994a43e?w=200&h=200&fit=crop&crop=faces&q=75",
  },
]

// Arrive, hold, leave: shared by the deploy scene's rows and chip
const ROW = {
  frames: {
    opacity: [0, 1, 1, 0, 0],
    y: [8, 0, 0, -4, -4],
    scale: [0.97, 1, 1, 1, 1],
  },
  rest: { opacity: 1, y: 0, scale: 1 },
  times: [0, 0.05, 0.84, 0.92, 1],
}

/** Commits arrive, build and go green, then the site is live */
export function DeploySkeleton({
  commits = DEFAULT_COMMITS,
  domain = "yourbrand.com",
  className,
}: {
  commits?: DeployCommit[]
  domain?: string
  className?: string
}) {
  const on = usePlaying()
  const rows = commits.slice(0, 3)
  const step = 0.9
  return (
    <div className={cn("flex w-full max-w-75 flex-col gap-2.5", className)}>
      {rows.map((c, i) => (
        <motion.div
          key={`${c.message}-${i}`}
          className="flex items-center gap-2"
          {...loop(on, ROW.frames, ROW.rest, {
            duration: 9,
            times: ROW.times,
            delay: i * step,
          })}
        >
          <Avatar
            src={c.avatar}
            name={c.author}
            className="size-6 ring-2 ring-card"
          />
          <div
            className={cn(
              "flex min-w-0 flex-1 items-center gap-2 rounded-lg px-2.5 py-1.5",
              surface
            )}
          >
            <span className="truncate text-xs text-foreground">
              {c.message}
            </span>
            <span className="ml-auto shrink-0 rounded bg-muted px-1 font-mono text-[9px] text-muted-foreground">
              main
            </span>
            <span className="relative flex size-3.5 shrink-0 items-center justify-center">
              {/* Building… */}
              <motion.span
                className="absolute inset-0"
                {...loop(
                  on,
                  { opacity: [0, 0, 1, 1, 0, 0] },
                  { opacity: 0 },
                  {
                    duration: 9,
                    times: [0, 0.04, 0.06, 0.17, 0.2, 1],
                    delay: i * step,
                    ease: "linear",
                  }
                )}
              >
                <motion.span
                  className="block size-3.5 rounded-full border-[1.5px] border-amber-400 border-t-transparent"
                  animate={on ? { rotate: 360 } : { rotate: 0 }}
                  transition={
                    on
                      ? { duration: 0.9, ease: "linear", repeat: Infinity }
                      : { duration: 0 }
                  }
                />
              </motion.span>
              {/* …then done */}
              <motion.svg
                viewBox="0 0 16 16"
                className="size-3.5 text-emerald-500"
                {...loop(
                  on,
                  {
                    opacity: [0, 0, 1, 1, 1, 0, 0],
                    scale: [0.6, 0.6, 1.15, 1, 1, 1, 1],
                  },
                  { opacity: 1, scale: 1 },
                  {
                    duration: 9,
                    times: [0, 0.18, 0.22, 0.25, 0.84, 0.92, 1],
                    delay: i * step,
                  }
                )}
              >
                <circle cx="8" cy="8" r="8" fill="currentColor" />
                <path
                  d="m4.8 8.2 2.1 2.1 4.3-4.6"
                  fill="none"
                  stroke="white"
                  strokeWidth="1.8"
                  strokeLinecap="round"
                  strokeLinejoin="round"
                />
              </motion.svg>
            </span>
          </div>
        </motion.div>
      ))}
      <motion.div
        className={cn(
          "mt-1.5 flex items-center gap-2 self-end rounded-full py-1.5 pr-3 pl-2.5 text-xs font-medium text-foreground",
          surface
        )}
        {...loop(on, ROW.frames, ROW.rest, {
          duration: 9,
          times: ROW.times,
          delay: rows.length * step + 0.5,
        })}
      >
        <span className="relative flex size-2">
          <Ping color="#10b981" />
          <span className="relative size-2 rounded-full bg-emerald-500" />
        </span>
        {domain}
        <span className="rounded-full bg-emerald-500/10 px-1.5 py-0.5 text-[10px] text-emerald-600 dark:text-emerald-400">
          Ready
        </span>
      </motion.div>
    </div>
  )
}

const DEFAULT_METRICS: SpeedMetric[] = [
  { label: "LCP", value: "0.8s" },
  { label: "CLS", value: "0.01" },
]

/** A phone loads a page: shimmer, then content, then the scores */
export function SpeedSkeleton({
  score = 99,
  metrics = DEFAULT_METRICS,
  className,
}: {
  /** The audit score in the ring, 0–100 */
  score?: number
  metrics?: SpeedMetric[]
  className?: string
}) {
  const on = usePlaying()
  const v = Math.max(0, Math.min(100, Math.round(score)))
  const tone = v >= 90 ? "#10b981" : v >= 50 ? "#f59e0b" : "#ef4444"
  const r = 20
  const c = 2 * Math.PI * r
  const to = c * (1 - v / 100)
  const times = [0, 0.28, 0.44, 0.88, 0.96, 1]

  // The score counts up with the ring
  const count = useMotionValue(v)
  const shown = useTransform(count, (n) => Math.round(n))
  React.useEffect(() => {
    if (!on) {
      count.set(v)
      return
    }
    const run = animate(count, [0, 0, v, v, 0, 0], {
      duration: 8,
      times,
      ease: "easeOut",
      repeat: Infinity,
    })
    return () => run.stop()
    // times is a constant
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [on, v, count])

  const chip = (delay: number) =>
    loop(
      on,
      {
        opacity: [0, 0, 1, 1, 0, 0],
        x: [-8, -8, 0, 0, 0, 0],
        scale: [0.95, 0.95, 1, 1, 1, 1],
      },
      { opacity: 1, x: 0, scale: 1 },
      { duration: 8, times: [0, 0.3, 0.36, 0.88, 0.94, 1], delay }
    )

  return (
    // The chips float over the phone's right edge; the padding keeps the
    // pair centred in the card
    <div className={cn("relative pr-20", className)}>
      <div
        className={cn(
          "relative h-52 w-29.5 shrink-0 rounded-3xl p-1.5",
          surface
        )}
      >
        <div className="relative h-full overflow-hidden rounded-[19px] bg-muted/40">
          <span className="absolute top-1.5 left-1/2 z-10 h-1.5 w-8 -translate-x-1/2 rounded-full bg-foreground/80" />
          {/* Loading state, with a shine sweeping across */}
          <motion.div
            className="absolute inset-0 flex flex-col gap-1.5 p-2 pt-5"
            {...loop(
              on,
              { opacity: [1, 1, 0, 0, 1] },
              { opacity: 0 },
              { duration: 8, times: [0, 0.24, 0.3, 0.94, 1], ease: "easeInOut" }
            )}
          >
            {["h-14", "h-2", "h-2 w-3/4", "h-9", "h-9"].map((h, i) => (
              <span
                key={i}
                className={cn(
                  "relative overflow-hidden rounded-md bg-foreground/[0.07]",
                  h
                )}
              >
                <motion.span
                  className="absolute inset-0 bg-linear-to-r from-transparent via-white/60 to-transparent dark:via-white/10"
                  {...loop(
                    on,
                    { x: ["-100%", "100%"] },
                    { x: "-100%" },
                    { duration: 1.2, times: [0, 1], ease: "easeInOut" }
                  )}
                />
              </span>
            ))}
          </motion.div>
          {/* The page */}
          <motion.div
            className="absolute inset-0 flex flex-col gap-1.5 p-2 pt-5"
            {...loop(
              on,
              { opacity: [0, 0, 1, 1, 0, 0], y: [4, 4, 0, 0, 0, 0] },
              { opacity: 1, y: 0 },
              { duration: 8, times: [0, 0.24, 0.32, 0.88, 0.94, 1] }
            )}
          >
            <span className="h-14 rounded-md bg-linear-to-br from-sky-400 via-indigo-400 to-fuchsia-400" />
            <span className="h-2 rounded bg-foreground/70" />
            <span className="h-2 w-3/4 rounded bg-foreground/25" />
            {["bg-amber-300", "bg-emerald-300"].map((tile) => (
              <span
                key={tile}
                className="flex h-9 items-center gap-1.5 rounded-md bg-card p-1.5 ring-1 ring-black/5"
              >
                <span className={cn("size-5 rounded", tile)} />
                <span className="h-1.5 flex-1 rounded bg-foreground/20" />
              </span>
            ))}
          </motion.div>
        </div>
      </div>

      {/* What it scored */}
      <div className="absolute top-1/2 left-20.5 flex w-max -translate-y-1/2 flex-col gap-2">
        <motion.div
          className={cn(
            "flex items-center gap-2.5 rounded-xl p-2 pr-3",
            surface
          )}
          {...chip(0)}
        >
          <span className="relative size-10">
            <svg viewBox="0 0 48 48" className="size-full -rotate-90">
              <circle
                cx="24"
                cy="24"
                r={r}
                fill="none"
                stroke={tone}
                strokeOpacity=".15"
                strokeWidth="3.5"
              />
              <motion.circle
                cx="24"
                cy="24"
                r={r}
                fill="none"
                stroke={tone}
                strokeWidth="3.5"
                strokeLinecap="round"
                strokeDasharray={c}
                {...loop(
                  on,
                  { strokeDashoffset: [c, c, to, to, c, c] },
                  { strokeDashoffset: to },
                  { duration: 8, times }
                )}
              />
            </svg>
            <motion.span
              className="absolute inset-0 flex items-center justify-center font-mono text-xs font-semibold tabular-nums"
              style={{ color: tone }}
            >
              {shown}
            </motion.span>
          </span>
          <span className="text-[11px] leading-tight text-muted-foreground">
            <span className="block font-medium text-foreground">
              Performance
            </span>
            Mobile
          </span>
        </motion.div>
        {metrics.slice(0, 3).map((m, i) => (
          <motion.div
            key={`${m.label}-${i}`}
            className={cn(
              "flex items-center justify-between gap-4 rounded-lg px-2.5 py-1.5 text-[11px]",
              surface
            )}
            {...chip((i + 1) * 0.25)}
          >
            <span className="text-muted-foreground">{m.label}</span>
            <span className="font-mono font-medium text-emerald-600 dark:text-emerald-400">
              {m.value}
            </span>
          </motion.div>
        ))}
      </div>
    </div>
  )
}

const DEFAULT_PEOPLE: BuildPerson[] = [
  { name: "Ana", color: "#ec4899", avatar: "https://images.unsplash.com/photo-1438761681033-6461ffad8d80?w=200&h=200&fit=crop&crop=faces&q=75" },
  { name: "Ravi", color: "#3b82f6", avatar: "https://images.unsplash.com/photo-1535713875002-d1d0cf377fde?w=200&h=200&fit=crop&crop=faces&q=75" },
]

/** Two people carry blocks into a shared page and drop them in place */
export function BuildSkeleton({
  people = DEFAULT_PEOPLE,
  className,
}: {
  /** The two people whose cursors build the page */
  people?: BuildPerson[]
  className?: string
}) {
  const on = usePlaying()
  const a = people[0] ?? DEFAULT_PEOPLE[0]
  const b = people[1] ?? people[0] ?? DEFAULT_PEOPLE[1]
  // Where each block is carried in from, and who carries it
  const from = [
    { fx: 36, fy: -34, who: a },
    { fx: -40, fy: 44, who: b },
    { fx: 30, fy: 52, who: a },
    { fx: -36, fy: 40, who: b },
  ]

  const block = (i: number, slot: string, filled: React.ReactNode) => {
    const { fx, fy, who } = from[i]
    // Each block takes its turn, then they all fade together
    const s = 0.06 + i * 0.15
    return (
      <div className={cn("relative", slot)}>
        <div className="absolute inset-0 rounded-md border border-dashed border-foreground/15" />
        <motion.div
          className="relative h-full"
          {...loop(
            on,
            {
              opacity: [0, 0, 1, 1, 1, 1, 0, 0],
              x: [fx, fx, fx, 0, 0, 0, 0, 0],
              y: [fy, fy, fy, 0, 0, 0, 0, 0],
              scale: [0.96, 0.96, 0.96, 1.03, 1, 1, 1, 1],
            },
            { opacity: 1, x: 0, y: 0, scale: 1 },
            {
              duration: 10,
              times: [0, s, s + 0.03, s + 0.1, s + 0.12, 0.86, 0.93, 1],
              ease: "easeInOut",
            }
          )}
        >
          {filled}
        </motion.div>
        <motion.div
          className="pointer-events-none absolute right-1 -bottom-4 z-10"
          {...loop(
            on,
            {
              opacity: [0, 0, 1, 1, 1, 1, 1, 0, 0],
              x: [fx, fx, fx, 0, 0, 0, fx * 0.35, fx * 0.4, fx * 0.4],
              y: [fy, fy, fy, 0, 0, 0, fy * 0.5, fy * 0.6, fy * 0.6],
              scale: [1, 1, 1, 1, 0.88, 1, 1, 1, 1],
            },
            { opacity: 0 },
            {
              duration: 10,
              times: [
                0,
                s,
                s + 0.03,
                s + 0.1,
                s + 0.11,
                s + 0.12,
                s + 0.16,
                s + 0.19,
                1,
              ],
              ease: "easeInOut",
            }
          )}
        >
          <svg
            viewBox="0 0 16 16"
            className="size-4 drop-shadow-sm"
            style={{ color: who.color }}
          >
            <path
              d="M2 1.5 14 7l-5.2 1.6L6.6 14z"
              fill="currentColor"
              stroke="white"
              strokeWidth="1.2"
              strokeLinejoin="round"
            />
          </svg>
          <span
            className="mt-0.5 ml-3 flex items-center gap-1 rounded-full py-0.5 pr-2 pl-0.5 text-[10px] font-medium whitespace-nowrap text-white shadow-md"
            style={{ backgroundColor: who.color }}
          >
            <Avatar
              src={who.avatar}
              name={who.name}
              color={who.color}
              className="size-4 ring-1 ring-white/70"
            />
            {who.name}
          </span>
        </motion.div>
      </div>
    )
  }

  return (
    <div className={cn("flex w-full max-w-72.5 flex-col gap-4", className)}>
      <div className="flex items-center justify-between">
        <div className="flex -space-x-1.5">
          {[a, b].map((p, i) => (
            <Avatar
              key={`${p.name}-${i}`}
              src={p.avatar}
              name={p.name}
              color={p.color}
              className="size-6 ring-2 ring-card"
            />
          ))}
        </div>
        <span className="flex items-center gap-1.5 rounded-full bg-muted px-2 py-1 text-[10px] font-medium text-muted-foreground ring-1 ring-foreground/5">
          <span className="size-1.5 rounded-full bg-emerald-500" />
          Editing now
        </span>
      </div>
      <div className={cn("overflow-visible rounded-xl", surface)}>
        <div className="flex items-center gap-2 border-b border-foreground/6 px-3 py-2">
          <span className="flex gap-1">
            <span className="size-1.5 rounded-full bg-red-400" />
            <span className="size-1.5 rounded-full bg-amber-400" />
            <span className="size-1.5 rounded-full bg-emerald-400" />
          </span>
          <span className="mx-auto h-3.5 w-28 rounded bg-muted" />
        </div>
        <div className="flex flex-col gap-3 p-3.5">
          {block(
            0,
            "h-5",
            <div className="flex h-full items-center gap-2 rounded-md bg-muted px-2">
              <span className="size-2 rounded-full bg-foreground/70" />
              <span className="ml-auto h-1.5 w-6 rounded bg-foreground/20" />
              <span className="h-1.5 w-6 rounded bg-foreground/20" />
              <span className="h-1.5 w-6 rounded bg-foreground/20" />
            </div>
          )}
          {block(
            1,
            "h-28",
            <div className="flex h-full flex-col justify-center gap-2 rounded-md bg-linear-to-br from-violet-500/15 via-fuchsia-500/10 to-transparent px-3">
              <span className="h-2.5 w-4/5 rounded bg-foreground/80" />
              <span className="h-2.5 w-3/5 rounded bg-foreground/80" />
              <span className="mt-1 h-1.5 w-2/3 rounded bg-foreground/20" />
              <span className="mt-2 h-5 w-16 rounded-md bg-foreground" />
            </div>
          )}
          {block(
            2,
            "h-16",
            <div className="grid h-full grid-cols-3 gap-1.5">
              {["bg-sky-300", "bg-amber-300", "bg-emerald-300"].map((tone) => (
                <div
                  key={tone}
                  className="flex flex-col justify-end gap-1 rounded-md bg-muted p-1.5"
                >
                  <span className={cn("size-2.5 rounded-sm", tone)} />
                  <span className="h-1 w-4/5 rounded bg-foreground/20" />
                </div>
              ))}
            </div>
          )}
          {block(
            3,
            "h-9",
            <div className="flex h-full items-center justify-between rounded-md bg-foreground px-2.5">
              <span className="h-1.5 w-12 rounded bg-background/50" />
              <span className="h-4 w-10 rounded bg-background/90" />
            </div>
          )}
        </div>
      </div>
    </div>
  )
}

const DEFAULT_QUOTES: GrowthQuote[] = [
  {
    quote: "Sign-ups doubled in the month after we relaunched.",
    name: "Ana Ruiz",
    role: "Founder, Fieldnote",
    avatar:
      "https://images.unsplash.com/photo-1438761681033-6461ffad8d80?w=200&h=200&fit=crop&crop=faces&q=75",
  },
  {
    quote: "Our product pages went from four seconds to well under one.",
    name: "Sam Okafor",
    role: "Head of Growth, Kestrel",
    avatar:
      "https://images.unsplash.com/photo-1500648767791-00dcc994a43e?w=200&h=200&fit=crop&crop=faces&q=75",
  },
  {
    quote: "We saw progress every day instead of one big reveal at the end.",
    name: "Ravi Menon",
    role: "Product lead, Halcyon",
    avatar:
      "https://images.unsplash.com/photo-1535713875002-d1d0cf377fde?w=200&h=200&fit=crop&crop=faces&q=75",
  },
]

/** Sign-ups draw past the launch line while client quotes take turns */
export function GrowthSkeleton({
  growth = "+38%",
  growthLabel = "sign-ups in 90 days",
  quotes = DEFAULT_QUOTES,
  accentColor = "#6366f1",
  className,
}: {
  /** The figure at the end of the chart */
  growth?: string
  /** What the figure measures */
  growthLabel?: string
  /** Up to four quotes that take turns beside the chart */
  quotes?: GrowthQuote[]
  accentColor?: string
  className?: string
}) {
  const on = usePlaying()
  const line =
    "M0 118 C30 116 45 122 70 117 S115 112 140 118 S180 114 200 112 C230 108 250 92 275 80 S320 52 345 40 S380 24 400 20"
  const shown = quotes.slice(0, 4)
  const fill = `gb-fill-${React.useId().replace(/:/g, "")}`

  // The quotes take turns while the scene plays
  const [turn, setTurn] = React.useState(0)
  React.useEffect(() => {
    if (!on || shown.length < 2) return
    const timer = setInterval(
      () => setTurn((t) => (t + 1) % shown.length),
      4500
    )
    return () => clearInterval(timer)
  }, [on, shown.length])
  const q = shown[turn % Math.max(1, shown.length)]

  const pop = loop(
    on,
    {
      opacity: [0, 0, 1, 1, 1, 0, 0],
      y: [6, 6, 0, 0, 0, 0, 0],
      scale: [0.9, 0.9, 1.04, 1, 1, 1, 1],
    },
    { opacity: 1, y: 0, scale: 1 },
    { duration: 11, times: [0, 0.32, 0.37, 0.4, 0.9, 0.97, 1] }
  )

  return (
    <div
      className={cn(
        "grid w-full items-center gap-6",
        q && "sm:grid-cols-[1.3fr_1fr]",
        className
      )}
    >
      <div className="relative pt-14">
        <div className="relative">
          <svg viewBox="0 0 400 150" className="h-auto w-full overflow-visible">
            <defs>
              <linearGradient id={fill} x1="0" y1="0" x2="0" y2="1">
                <stop offset="0" stopColor={accentColor} stopOpacity=".25" />
                <stop offset="1" stopColor={accentColor} stopOpacity="0" />
              </linearGradient>
            </defs>
            {[30, 75, 120].map((y) => (
              <line
                key={y}
                x1="0"
                x2="400"
                y1={y}
                y2={y}
                className="stroke-foreground/[0.07]"
                strokeDasharray="3 4"
              />
            ))}
            <line
              x1="200"
              x2="200"
              y1="8"
              y2="140"
              stroke={accentColor}
              strokeOpacity=".45"
              strokeDasharray="2 3"
            />
            <motion.path
              d={`${line} L400 150 L0 150Z`}
              fill={`url(#${fill})`}
              {...loop(
                on,
                { opacity: [0, 0, 1, 1, 0, 0] },
                { opacity: 1 },
                { duration: 11, times: [0, 0.18, 0.38, 0.9, 0.97, 1] }
              )}
            />
            <motion.path
              d={line}
              fill="none"
              stroke={accentColor}
              strokeWidth="2.5"
              strokeLinecap="round"
              {...loop(
                on,
                { pathLength: [0, 1, 1, 1, 1], opacity: [1, 1, 1, 0, 0] },
                { pathLength: 1, opacity: 1 },
                {
                  duration: 11,
                  times: [0, 0.34, 0.9, 0.97, 1],
                  ease: "easeInOut",
                }
              )}
            />
          </svg>
          <span
            className="absolute top-0 left-1/2 -translate-x-1/2 -translate-y-1/2 rounded-full px-2 py-0.5 text-[10px] font-medium text-white shadow-sm"
            style={{ backgroundColor: accentColor }}
          >
            Launch
          </span>
          {/* Where the line ends: a dot, pulsing once it's drawn */}
          <span className="absolute top-[13.3%] right-0 flex size-2.5 translate-x-1/2 -translate-y-1/2">
            <motion.span className="relative flex size-2.5" {...pop}>
              <Ping color={accentColor} />
              <span
                className="relative size-2.5 rounded-full ring-2 ring-card"
                style={{ backgroundColor: accentColor }}
              />
            </motion.span>
          </span>
        </div>
        <motion.div
          className={cn(
            "absolute top-0 right-0 rounded-lg px-2.5 py-1.5 text-right",
            surface
          )}
          {...pop}
        >
          <span
            className="block text-base leading-none font-semibold tracking-tight"
            style={{ color: accentColor }}
          >
            {growth}
          </span>
          <span className="text-[10px] text-muted-foreground">
            {growthLabel}
          </span>
        </motion.div>
      </div>

      {q && (
        <div className="relative min-h-35">
          <AnimatePresence initial={false}>
            <motion.figure
              key={turn}
              className={cn(
                "absolute inset-0 flex flex-col justify-between rounded-xl p-4",
                surface
              )}
              initial={{ opacity: 0, y: 10, scale: 0.98 }}
              animate={{ opacity: 1, y: 0, scale: 1 }}
              exit={{ opacity: 0, y: -8, scale: 0.98 }}
              transition={{ duration: 0.5, ease: [0.2, 0.8, 0.2, 1] }}
            >
              <blockquote className="text-[13px] leading-snug text-pretty text-foreground">
                {q.quote}
              </blockquote>
              <figcaption className="mt-3 flex items-center gap-2">
                <Avatar src={q.avatar} name={q.name} className="size-6" />
                <span className="text-[11px] leading-tight">
                  <span className="block font-medium text-foreground">
                    {q.name}
                  </span>
                  {q.role && (
                    <span className="text-muted-foreground">{q.role}</span>
                  )}
                </span>
              </figcaption>
            </motion.figure>
          </AnimatePresence>
        </div>
      )}
    </div>
  )
}

/** A screenshot or illustration, framed to sit in a card like the scenes */
export function FeatureImage({
  src,
  alt = "",
  className,
}: {
  src: string
  alt?: string
  className?: string
}) {
  return (
    <div className={cn("w-full max-w-md rounded-xl p-1.5", surface, className)}>
      {/* eslint-disable-next-line @next/next/no-img-element */}
      <img
        src={src}
        alt={alt}
        loading="lazy"
        className="aspect-4/3 w-full rounded-lg object-cover"
      />
    </div>
  )
}

/* ─── Card and bento ────────────────────────────────────────────────── */

export interface FeatureCardProps extends Omit<
  React.HTMLAttributes<HTMLDivElement>,
  "title"
> {
  title: React.ReactNode
  description?: React.ReactNode
  /** The scene at the top of the card: a skeleton above, or anything else */
  skeleton?: React.ReactNode
  span?: FeatureBentoFeature["span"]
}

/**
 * One cell of the bento: a scene on top and a title and line below. Its
 * scene only animates while the card is on screen.
 */
export function FeatureCard({
  title,
  description,
  skeleton,
  span = "default",
  className,
  ...props
}: FeatureCardProps) {
  const ref = React.useRef<HTMLDivElement>(null)
  const onScreen = useInView(ref, { amount: 0.25 })
  return (
    <div
      ref={ref}
      className={cn(
        "flex flex-col justify-between overflow-hidden rounded-2xl bg-card p-6 shadow-sm ring-1 shadow-black/4 ring-black/5 md:p-8 dark:ring-white/6",
        span === "tall" && "md:row-span-2",
        span === "wide" && "md:col-span-2",
        className
      )}
      {...props}
    >
      {skeleton && (
        <div
          aria-hidden="true"
          className="relative flex min-h-56 flex-1 items-center justify-center select-none"
        >
          <PlayContext.Provider value={onScreen}>
            {skeleton}
          </PlayContext.Provider>
        </div>
      )}
      <div className={cn(skeleton ? "mt-8" : undefined)}>
        <h3 className="text-base font-semibold tracking-tight text-foreground/90">
          {title}
        </h3>
        {description && (
          <p className="mt-2 max-w-md text-sm text-pretty text-muted-foreground">
            {description}
          </p>
        )}
      </div>
    </div>
  )
}

const DEFAULT_FEATURES: FeatureBentoFeature[] = [
  {
    title: "Ships on every push",
    description:
      "Each change is built, checked and live in a few minutes. No release days.",
    skeleton: "deploy",
  },
  {
    title: "Fast on any phone",
    description:
      "We watch Core Web Vitals from the first commit, not the week before launch.",
    skeleton: "speed",
  },
  {
    title: "Built where you can see it",
    description:
      "Follow along in a shared preview while the pages come together, block by block.",
    skeleton: "build",
    span: "tall",
  },
  {
    title: "Numbers after launch",
    description:
      "See what changed for sign-ups and sales, not just that the site looks nicer.",
    skeleton: "growth",
    span: "wide",
  },
]

const SCENES: string[] = ["deploy", "speed", "build", "growth"]

export interface FeatureBentoProps extends React.HTMLAttributes<HTMLElement> {
  eyebrow?: string
  heading?: string
  description?: string
  /** The cards, in order. Ignored when you pass FeatureCard children */
  features?: FeatureBentoFeature[]
  /** Your own cards: <FeatureCard skeleton={…} />, in place of features */
  children?: React.ReactNode
  /** Commits in the deploy scene */
  commits?: DeployCommit[]
  /** Domain on the deploy scene's ready chip */
  domain?: string
  /** Score in the speed scene's ring, 0–100 */
  score?: number
  /** Metrics under the score */
  metrics?: SpeedMetric[]
  /** The two people in the build scene */
  people?: BuildPerson[]
  /** The figure at the end of the growth chart */
  growth?: string
  growthLabel?: string
  /** Quotes beside the growth chart */
  quotes?: GrowthQuote[]
  /** Colour of the growth chart */
  accentColor?: string
}

/**
 * A feature section as a bento of cards, each topped by a small live
 * scene made of UI shapes and animated with Motion. Use the four scenes
 * that come with it (a deploy going live, a phone loading fast, two people
 * building a page, a chart climbing past launch) by name, give a card an
 * image, or pass your own FeatureCard children with any scene you like.
 * Tall cards take two rows and wide ones two columns. Scenes play only on
 * screen, and reduced motion shows each one finished.
 */
export const FeatureBento = React.forwardRef<HTMLElement, FeatureBentoProps>(
  (
    {
      eyebrow,
      heading,
      description,
      features = DEFAULT_FEATURES,
      children,
      commits,
      domain,
      score,
      metrics,
      people,
      growth,
      growthLabel,
      quotes,
      accentColor,
      className,
      ...props
    },
    ref
  ) => {
    const scene = (f: FeatureBentoFeature): React.ReactNode => {
      if (f.image) return <FeatureImage src={f.image} alt={f.imageAlt} />
      if (typeof f.skeleton !== "string" || !SCENES.includes(f.skeleton))
        return f.skeleton
      switch (f.skeleton as FeatureSkeleton) {
        case "deploy":
          return <DeploySkeleton commits={commits} domain={domain} />
        case "speed":
          return <SpeedSkeleton score={score} metrics={metrics} />
        case "build":
          return <BuildSkeleton people={people} />
        case "growth":
          return (
            <GrowthSkeleton
              growth={growth}
              growthLabel={growthLabel}
              quotes={quotes}
              accentColor={accentColor}
            />
          )
      }
    }

    return (
      <section
        ref={ref}
        className={cn("w-full px-4 py-16 sm:px-6 md:py-24", className)}
        {...props}
      >
        <div className="mx-auto max-w-6xl">
          {(eyebrow || heading || description) && (
            <div className="mb-10 grid gap-4 md:mb-12 md:grid-cols-2 md:items-end">
              <div>
                {eyebrow && (
                  <p className="mb-3 text-sm font-medium text-muted-foreground">
                    {eyebrow}
                  </p>
                )}
                {heading && (
                  <h2 className="max-w-xl text-3xl font-semibold tracking-tight text-balance text-foreground md:text-4xl">
                    {heading}
                  </h2>
                )}
              </div>
              {description && (
                <p className="max-w-md text-base text-pretty text-muted-foreground md:justify-self-end">
                  {description}
                </p>
              )}
            </div>
          )}

          <div className="grid grid-cols-1 gap-1 rounded-3xl bg-muted/60 p-1 md:grid-flow-dense md:auto-rows-[minmax(340px,auto)] md:grid-cols-3">
            {children ??
              features.map((f, i) => (
                <FeatureCard
                  key={`${f.title}-${i}`}
                  title={f.title}
                  description={f.description}
                  span={f.span}
                  skeleton={scene(f)}
                />
              ))}
          </div>
        </div>
      </section>
    )
  }
)
FeatureBento.displayName = "FeatureBento"

```

**Step 3: Framework Adjustments (Optional)**
If you are manually copying this code into a Vite or Remix project (without using the CLI), make sure to remove the `"use client";` directive from the very top of the file.

## Props
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| `eyebrow` | `string` | - | No | Small label above the heading. |
| `heading` | `string` | - | No | Section heading, on the left above the bento. |
| `description` | `string` | - | No | Supporting text, on the right of the heading. |
| `features` | `FeatureBentoFeature[]` | `[{ title: "Ships on every push", description: "Each change is built, checked and live in a few minutes. No release days.", skeleton: "deploy" }, { title: "Fast on any phone", description: "We watch Core Web Vitals from the first commit, not the week before launch.", skeleton: "speed" }, { title: "Built where you can see it", description: "Follow along in a shared preview while the pages come together, block by block.", skeleton: "build", span: "tall" }, { title: "Numbers after launch", description: "See what changed for sign-ups and sales, not just that the site looks nicer.", skeleton: "growth", span: "wide" }]` | No | The cards, in order. The grid fills itself: tall cards take two rows, wide ones two columns. Ignored when you pass FeatureCard children. |
| `features.title` | `string` | - | Yes | Card title. |
| `features.description` | `string` | - | Yes | One line under the title. |
| `features.skeleton` | `"deploy" \| "speed" \| "build" \| "growth"` | - | No | A built-in scene by name. In code it can also be any React node: an illustration, a chart, a video. |
| `features.image` | `string` | - | No | An image URL for the top of the card, in place of a skeleton. |
| `features.imageAlt` | `string` | - | No | Describes the image for screen readers. |
| `features.span` | `"default" \| "tall" \| "wide"` | - | No | One cell, two rows, or two columns. |
| `children` | `React.ReactNode` | - | No | Your own cards (<FeatureCard title skeleton={…} />), in place of features. A skeleton can be any React node. |
| `commits` | `DeployCommit[]` | `[{ message: "Tighten hero spacing", author: "Ana", avatar: "/demo/avatar-ana.webp" }, { message: "Add pricing FAQ", author: "Ravi", avatar: "/demo/avatar-ravi.webp" }, { message: "Compress product images", author: "Sam", avatar: "/demo/avatar-sam.webp" }]` | No | Commits in the deploy scene (up to three). |
| `commits.message` | `string` | - | Yes | Commit message. |
| `commits.author` | `string` | - | Yes | Who made it; their initial shows without an avatar. |
| `commits.avatar` | `string` | - | No | Photo URL. |
| `domain` | `string` | `"yourbrand.com"` | No | Domain on the deploy scene's Ready chip. |
| `score` | `number` | `99` | No | Score in the speed scene's ring, 0–100. |
| `metrics` | `SpeedMetric[]` | `[{ label: "LCP", value: "0.8s" }, { label: "CLS", value: "0.01" }]` | No | Metrics under the score. |
| `metrics.label` | `string` | - | Yes | Metric name. |
| `metrics.value` | `string` | - | Yes | Its value. |
| `people` | `BuildPerson[]` | `[{ name: "Ana", color: "#ec4899", avatar: "/demo/avatar-ana.webp" }, { name: "Ravi", color: "#3b82f6", avatar: "/demo/avatar-ravi.webp" }]` | No | The two people in the build scene. |
| `people.name` | `string` | - | Yes | Shown on the cursor. |
| `people.color` | `string` | - | Yes | Cursor colour. |
| `people.avatar` | `string` | - | No | Photo URL. |
| `growth` | `string` | `"+38%"` | No | The figure at the end of the growth chart. |
| `growthLabel` | `string` | `"sign-ups in 90 days"` | No | What the figure measures. |
| `quotes` | `GrowthQuote[]` | `[{ quote: "Sign-ups doubled in the month after we relaunched.", name: "Ana Ruiz", role: "Founder, Fieldnote", avatar: "/demo/avatar-ana.webp" }, { quote: "Our product pages went from four seconds to well under one.", name: "Sam Okafor", role: "Head of Growth, Kestrel", avatar: "/demo/avatar-sam.webp" }, { quote: "We saw progress every day instead of one big reveal at the end.", name: "Ravi Menon", role: "Product lead, Halcyon", avatar: "/demo/avatar-ravi.webp" }]` | No | Quotes that take turns beside the chart (up to four). |
| `quotes.quote` | `string` | - | Yes | What they said. |
| `quotes.name` | `string` | - | Yes | Who said it. |
| `quotes.role` | `string` | - | No | Their role and company. |
| `quotes.avatar` | `string` | - | No | Photo URL. |
| `accentColor` | `string` | `"#6366f1"` | No | Colour of the growth chart. |
| `className` | `string` | - | No | Extra classes for the section. |

## Usage
```tsx
"use client"

import { FeatureBento } from "@/components/ui/feature-bento"

export default function FeatureBentoDemo() {
  return (
    <FeatureBento
      eyebrow="How we work"
      heading="A studio that ships, measures and keeps you in the loop"
      description="Small senior team, short feedback loops, and a live preview you can open any day of the week."
      domain="fieldnote.app"
    />
  )
}

```
