"use client";
import { AnimatePresence, motion } from "motion/react";
import { useRef, useState } from "react";
import { Copy, Link2, Plus, SlidersHorizontal, Workflow } from "lucide-react";
import { cn } from "@/lib/utils";
/**
* Action Node — an original take inspired by bencho.dev's "Action node".
* A workflow card that keeps its tools out of the way. Hover or focus it and
* four round actions spring out of the top-right corner along an arc, one
* after another; leave and they fold back in reverse.
*/
const ACTIONS = [
{ id: "link", label: "Copy link", Icon: Link2 },
{ id: "add", label: "Add step", Icon: Plus },
{ id: "dup", label: "Duplicate", Icon: Copy },
{ id: "tune", label: "Settings", Icon: SlidersHorizontal },
] as const;
const FACES = [
"linear-gradient(135deg,#3b82f6,#22d3ee)",
"linear-gradient(135deg,#f97316,#ef4444)",
"linear-gradient(135deg,#ec4899,#a855f7)",
];
export function ActionNode({
title = "Node 07",
body = "Picks up new rows from the sheet, tags each one, and routes it to the right queue.",
radius = 60,
spread = 47,
stagger = 45,
corner = 20,
outlined = false,
onAction,
}: {
title?: string;
body?: string;
/** Distance of the actions from the arc's centre, px. */
radius?: number;
/** Degrees between neighbouring actions. */
spread?: number;
/** Milliseconds between each action coming out. */
stagger?: number;
corner?: number;
outlined?: boolean;
onAction?: (id: (typeof ACTIONS)[number]["id"]) => void;
}) {
const [open, setOpen] = useState(false);
const root = useRef<HTMLDivElement>(null);
const ARC = 26; // arc centre sits this far inside the corner
return (
<div
ref={root}
className="relative"
onPointerEnter={() => setOpen(true)}
onPointerLeave={() => setOpen(false)}
onFocus={() => setOpen(true)}
onBlur={(e) => {
if (!root.current?.contains(e.relatedTarget as Node)) setOpen(false);
}}
onKeyDown={(e) => {
if (e.key === "Escape") {
setOpen(false);
(document.activeElement as HTMLElement | null)?.blur();
}
}}
>
{/* the pointer can travel from card to actions without the menu closing */}
{open && <div className="absolute -right-[70px] -top-[70px] h-[160px] w-[160px]" aria-hidden />}
<div
tabIndex={0}
role="group"
aria-label={`${title}. Actions are revealed on hover or focus.`}
className={cn(
"relative w-[271px] bg-[var(--b-surface)] p-[18px] text-[var(--b-fg)] shadow-[var(--b-shadow)] outline-none focus-visible:ring-2 focus-visible:ring-[var(--b-fg)]/30",
outlined && "ring-1 ring-[var(--b-line)]"
)}
style={{ borderRadius: corner }}
>
<div className="flex items-center gap-[10px]">
<span className="flex size-[30px] items-center justify-center rounded-[9px] bg-[var(--b-surface-2)]">
<Workflow className="size-[15px]" strokeWidth={2} />
</span>
<span className="text-[16px] font-medium">{title}</span>
</div>
<p className="mt-[14px] text-[14px] leading-[19px] text-[var(--b-fg-muted)]">{body}</p>
<div className="mt-[16px] flex items-center">
{FACES.map((g, i) => (
<span
key={i}
className="size-[24px] rounded-full ring-2 ring-[var(--b-surface)]"
style={{ background: g, marginLeft: i ? -6 : 0 }}
/>
))}
<span className="ml-[8px] text-[12px] text-[var(--b-fg-muted)]">+3</span>
</div>
</div>
<div className="absolute right-0 top-0" style={{ width: 0, height: 0 }}>
<AnimatePresence>
{open &&
ACTIONS.map(({ id, label, Icon }, i) => {
const deg = 45 + (1.5 - i) * spread;
const rad = (deg * Math.PI) / 180;
const x = -ARC + Math.cos(rad) * radius;
const y = ARC - Math.sin(rad) * radius;
return (
<motion.button
key={id}
type="button"
aria-label={label}
onClick={() => onAction?.(id)}
className="absolute -ml-[18px] -mt-[18px] flex size-[36px] items-center justify-center rounded-full bg-[var(--b-surface)] text-[var(--b-fg)] shadow-[var(--b-shadow)] outline-none hover:bg-[var(--b-surface-2)] focus-visible:ring-2 focus-visible:ring-[var(--b-fg)]/40"
initial={{ x: -ARC, y: ARC, scale: 0.3, opacity: 0 }}
animate={{
x,
y,
scale: 1,
opacity: 1,
transition: { type: "spring", stiffness: 420, damping: 24, delay: (i * stagger) / 1000 },
}}
exit={{
x: -ARC,
y: ARC,
scale: 0.3,
opacity: 0,
transition: { duration: 0.18, ease: "easeIn", delay: ((ACTIONS.length - 1 - i) * stagger * 0.5) / 1000 },
}}
whileTap={{ scale: 0.9 }}
>
<Icon className="size-[16px]" strokeWidth={2} />
</motion.button>
);
})}
</AnimatePresence>
</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;
}