Louis Studios

Fortune Cookie

Component 9

About

A cookie consent card where visitors crack a fortune cookie to read their fortune, then accept for a bite or decline and watch it crumble. More like this, plus a designer your coding agent can use, at studios.lou15.com/?ref=21st

Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds Fortune Cookie to your project and fits it to your theme.

Code

How Fortune Cookie is used: the demo's code. The component's own source comes with a free account.

Usage.tsx

"use client";

import * as React from "react";
import { FortuneCookie, type FortuneCookieChoice } from "@/components/ui/fortune-cookie";

/** True while the page (or any ancestor) carries the `dark` class, so the card can take a dark palette. */
function useDarkClass(ref: React.RefObject<HTMLElement | null>) {
  const [dark, setDark] = React.useState(false);
  React.useEffect(() => {
    const read = () => setDark(!!ref.current?.closest(".dark"));
    read();
    const mo = new MutationObserver(read);
    mo.observe(document.documentElement, { attributes: true, attributeFilter: ["class"] });
    mo.observe(document.body, { attributes: true, attributeFilter: ["class"] });
    return () => mo.disconnect();
  }, [ref]);
  return dark;
}

const DARK_CARD = {
  card: "#1d1b18",
  surface: "#2b2722",
  surfaceEdge: "#221f1b",
  paper: "#f7f1e4",
  ink: "#f3eee4",
  paperInk: "#1b1712",
  muted: "#a59f94",
  accent: "#c4574d",
  button: "#2d2a26",
  buttonPrimary: "#f3eee4",
  buttonPrimaryText: "#16130f",
};

const STATUS: Record<FortuneCookieChoice, { text: string; dot: string }> = {
  pending: { text: "Cookies: waiting", dot: "#d9a441" },
  accepted: { text: "Cookies: accepted", dot: "#3fa66b" },
  declined: { text: "Cookies: essentials only", dot: "#c4574d" },
};

const RECIPES = [
  { name: "Shortbread", meta: "40 min", from: "#f3c98b", to: "#c9853f" },
  { name: "Morning buns", meta: "2 h 10 min", from: "#f1d7b0", to: "#b7774a" },
];

/**
 * The consent card where it lives: on a recipe page that follows the light or dark theme. Drag the
 * cookie apart (or click it) to read the fortune, then accept or decline; the status pill in the
 * header listens to onChoiceChange. The card plays its own demo loop until you touch it.
 */
export default function FortuneCookieDemo() {
  const ref = React.useRef<HTMLElement>(null);
  const dark = useDarkClass(ref);
  const [choice, setChoice] = React.useState<FortuneCookieChoice>("pending");
  const status = STATUS[choice];

  return (
    <main ref={ref} className="relative flex h-screen min-h-[340px] w-full items-center justify-center overflow-hidden bg-background text-foreground">
      <div className="relative h-full max-h-[500px] w-full max-w-[900px]">
      {/* the page behind the card */}
      <div className="absolute inset-0 flex flex-col px-6 pb-6 pt-4 sm:px-8">
        <header className="flex items-center justify-between gap-4">
          <div className="flex items-center gap-2">
            <span aria-hidden className="grid h-7 w-7 place-items-center rounded-full" style={{ background: "linear-gradient(140deg, #f2c27f, #b9733a)" }}>
              <span className="h-2.5 w-2.5 rounded-full" style={{ background: "#4f2a12" }} />
            </span>
            <span className="text-[15px] font-semibold tracking-tight">Crumb Journal</span>
          </div>
          <nav className="hidden items-center gap-5 text-[13px] text-muted-foreground md:flex">
            <span>Recipes</span>
            <span>Techniques</span>
            <span>Notes</span>
          </nav>
          <span className="inline-flex items-center gap-2 rounded-full border border-border px-3 py-1 text-[12px] text-muted-foreground" aria-live="polite">
            <span className="h-1.5 w-1.5 rounded-full" style={{ background: status.dot }} />
            {status.text}
          </span>
        </header>

        <section className="hidden flex-1 flex-col justify-center pb-2 sm:flex" style={{ maxWidth: "min(380px, calc(100% - 500px))" }}>
          <p className="text-[12px] font-medium uppercase tracking-[0.14em] text-muted-foreground">Weekend baking</p>
          <h1 className="mt-2 text-[clamp(22px,5vh,32px)] font-semibold leading-[1.1] tracking-tight">Slow bakes for quiet weekends</h1>
          <p className="mt-3 text-[14px] leading-relaxed text-muted-foreground">
            Fourteen recipes that reward patience, from laminated buns to a shortbread that keeps for a week.
          </p>
          <div className="mt-5 grid grid-cols-2 gap-3">
            {RECIPES.map((r) => (
              <div key={r.name} className="overflow-hidden rounded-xl border border-border">
                <div className="h-[clamp(36px,10vh,64px)]" style={{ background: `linear-gradient(135deg, ${r.from}, ${r.to})` }} />
                <div className="px-3 py-2">
                  <p className="truncate text-[12.5px] font-medium">{r.name}</p>
                  <p className="text-[11.5px] text-muted-foreground">{r.meta}</p>
                </div>
              </div>
            ))}
          </div>
        </section>
      </div>

      {/* the consent card, docked to the right on wide frames and centred on narrow ones */}
      <div className="absolute bottom-0 right-0 top-10 w-full sm:w-[min(480px,62%)]">
        <FortuneCookie
          title="Fresh from the oven"
          hint="Break the cookie to choose"
          readyTitle="Your fortune is ready"
          fortune="A small risk today turns into a good story by Friday."
          luckyLine="Lucky numbers 4 9 16 27"
          acceptLabel="Accept all"
          declineLabel="Essentials only"
          acceptedTitle="Enjoy, it is still warm"
          declinedTitle="Crumbs it is, then"
          changeLabel="Change my mind"
          onChoiceChange={setChoice}
          background="transparent"
          {...(dark ? DARK_CARD : {})}
          style={{ minHeight: 0 }}
        />
      </div>
      </div>
    </main>
  );
}

More by Louis Studios

View all
  • Warp Carousel

    Warp Carousel

    1.4K
  • Peak Chart

    Peak Chart

    1.2K
  • Dot Tiles

    Dot Tiles

    197
  • Glow Rocker

    Glow Rocker

    188
  • Chrome Arcs

    Chrome Arcs

    180
  • Cover Flow

    Cover Flow

    177
  • Market Card

    Market Card

    146
  • Chapter Player

    Chapter Player

    140