"use client";
import { AnimatePresence, motion } from "motion/react";
import { useEffect, useState } from "react";
/**
* Dynamic Island — an original take inspired by bencho.dev's "Dynamic island".
* A live timer that lives in a black capsule. Tap the capsule to tuck it into
* a compact pill and back; the shape springs while its contents blur across.
*/
const AMBER_TEXT = "#e09a12";
const fmt = (s: number) => `${Math.floor(s / 60)}:${String(s % 60).padStart(2, "0")}`;
export function DynamicIsland({ seconds = 297, defaultOpen = true }: { seconds?: number; defaultOpen?: boolean }) {
const [open, setOpen] = useState(defaultOpen);
const [left, setLeft] = useState(seconds);
const [running, setRunning] = useState(true);
useEffect(() => {
if (!running) return;
const id = window.setInterval(() => setLeft((s) => (s <= 0 ? seconds : s - 1)), 1000);
return () => window.clearInterval(id);
}, [running, seconds]);
const blur = {
initial: { opacity: 0, filter: "blur(6px)", scale: 0.92 },
animate: { opacity: 1, filter: "blur(0px)", scale: 1, transition: { duration: 0.28, delay: 0.06, ease: [0.2, 0, 0, 1] as const } },
exit: { opacity: 0, filter: "blur(6px)", scale: 0.92, transition: { duration: 0.16 } },
};
return (
<div className="flex h-[96px] w-[320px] items-center justify-center">
<motion.div
role="button"
tabIndex={0}
aria-expanded={open}
aria-label={open ? "Collapse timer" : "Expand timer"}
onClick={() => setOpen((o) => !o)}
onKeyDown={(e) => (e.key === "Enter" || e.key === " ") && (e.preventDefault(), setOpen((o) => !o))}
initial={false}
animate={open ? { width: 300, height: 76, borderRadius: 38 } : { width: 146, height: 36, borderRadius: 18 }}
transition={{ type: "spring", stiffness: 380, damping: open ? 24 : 30, mass: 0.9 }}
whileTap={{ scale: 0.97 }}
className="relative cursor-pointer overflow-hidden bg-black text-white outline-none focus-visible:ring-2 focus-visible:ring-white/30"
>
<AnimatePresence initial={false} mode="popLayout">
{open ? (
<motion.span key="open" {...blur} className="absolute inset-0 flex items-center pl-[15px] pr-[20px]">
<motion.span
role="button"
tabIndex={0}
aria-label={running ? "Pause" : "Resume"}
onClick={(e) => {
e.stopPropagation();
setRunning((r) => !r);
}}
onKeyDown={(e) => {
if (e.key !== "Enter" && e.key !== " ") return;
e.preventDefault();
e.stopPropagation();
setRunning((r) => !r);
}}
whileTap={{ scale: 0.9 }}
className="flex size-[46px] items-center justify-center rounded-full"
style={{ background: "rgba(255,159,10,0.24)", color: AMBER_TEXT }}
>
<AnimatePresence initial={false} mode="popLayout">
<motion.svg
key={running ? "pause" : "play"}
width="18"
height="18"
viewBox="0 0 24 24"
fill="currentColor"
aria-hidden
initial={{ scale: 0.5, opacity: 0, filter: "blur(2px)" }}
animate={{ scale: 1, opacity: 1, filter: "blur(0px)" }}
exit={{ scale: 0.5, opacity: 0, filter: "blur(2px)" }}
transition={{ duration: 0.16 }}
>
{running ? (
<>
<rect x="14" y="3" width="5" height="18" rx="1" />
<rect x="5" y="3" width="5" height="18" rx="1" />
</>
) : (
<path d="M6 4.8v14.4a1 1 0 0 0 1.5.86l12-7.2a1 1 0 0 0 0-1.72l-12-7.2A1 1 0 0 0 6 4.8Z" />
)}
</motion.svg>
</AnimatePresence>
</motion.span>
<span className="flex-1" />
<span className="mr-[10px] text-[12px] text-white/55">Timer</span>
<span className="bencho-tabular text-[30px] font-medium tracking-[-0.01em]" style={{ color: AMBER_TEXT }}>
{fmt(left)}
</span>
</motion.span>
) : (
<motion.span key="compact" {...blur} className="absolute inset-0 flex items-center justify-between pl-[12px] pr-[14px]" style={{ color: AMBER_TEXT }}>
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round" aria-hidden>
<path d="M10 2h4" />
<path d="M12 14l3-3" />
<circle cx="12" cy="14" r="8" />
</svg>
<span className="bencho-tabular text-[13px] font-semibold">{fmt(left)}</span>
</motion.span>
)}
</AnimatePresence>
</motion.div>
</div>
);
}
"use client";
import type { ReactNode } from "react";
import { cn } from "@/lib/utils";
/**
* Neutral stage the Bencho Originals sit on. The block renders at its
* natural size and is scaled as a whole (like a device preview), so
* strokes, radii and type keep their proportions at any stage size.
*/
export function BenchoStage({
children,
scale = 1.25,
className,
}: {
children: ReactNode;
scale?: number;
className?: string;
}) {
return (
<div
className={cn(
"bencho bencho-font relative flex items-center justify-center overflow-hidden rounded-2xl text-[var(--b-fg)]",
"bg-[var(--b-stage)]",
className
)}
>
<div style={{ transform: `scale(${scale})` }} className="origin-center">
{children}
</div>
</div>
);
}
/* Bencho Originals — shared surface tokens (light / dark). */
.bencho {
--b-stage: #f1f1f1;
--b-surface: #ffffff;
--b-surface-2: #f1f1f1;
--b-fg: #171717;
--b-fg-muted: rgb(23 23 23 / 0.5);
--b-ink: #171717;
--b-invert: #171717;
--b-invert-fg: #ffffff;
--b-line: rgb(0 0 0 / 0.06);
--b-shadow: 0 1px 2px rgb(0 0 0 / 0.04), 0 0 0 1px rgb(0 0 0 / 0.04);
}
.dark .bencho {
--b-stage: #171717;
--b-surface: #262626;
--b-surface-2: #333333;
--b-fg: #ffffff;
--b-fg-muted: rgb(255 255 255 / 0.55);
--b-ink: #ffffff;
--b-invert: #ffffff;
--b-invert-fg: #262626;
--b-line: rgb(255 255 255 / 0.06);
--b-shadow: none;
}
.bencho-font {
font-family: var(--font-bencho-inter), var(--font-geist-sans), ui-sans-serif, system-ui, sans-serif;
font-feature-settings: "cv11", "ss01";
-webkit-font-smoothing: antialiased;
}
.bencho-tabular { font-variant-numeric: tabular-nums; }
/* Code panel: Shiki dual-theme output, with line numbers */
.bencho-code pre.shiki { background: transparent !important; margin: 0; }
.bencho-code .shiki span { color: var(--shiki-light); }
.dark .bencho-code .shiki span { color: var(--shiki-dark); }
.bencho-code .shiki code { counter-reset: line; display: block; }
.bencho-code .shiki .line::before {
counter-increment: line;
content: counter(line);
display: inline-block;
width: 2.2em;
margin-right: 1.1em;
text-align: right;
opacity: 0.32;
}