"use client";
import { AnimatePresence, motion } from "motion/react";
import { useId, useRef, useState } from "react";
import { Check, ChevronUp } from "lucide-react";
import { cn } from "@/lib/utils";
/**
* Assignees — an original take inspired by bencho.dev's "Assignees" picker.
* Tick people in the list and their faces slide into the pill above, which
* grows or shrinks to fit. The list is a real multi-select listbox.
*/
export type Person = { id: string; name: string; role: string; face: string };
const PEOPLE: Person[] = [
{ id: "lena", name: "Lena Ortiz", role: "Design", face: "radial-gradient(circle at 30% 30%,#ff8ad8,#e64fb0 55%,#b83cf0)" },
{ id: "sam", name: "Sam Okafor", role: "Research", face: "radial-gradient(circle at 30% 30%,#3ad6ff,#3b6cf6 55%,#7c3aed)" },
{ id: "ivy", name: "Ivy Chen", role: "Engineering", face: "radial-gradient(circle at 30% 30%,#c6f66b,#32d77a 55%,#18b6a8)" },
{ id: "theo", name: "Theo Grant", role: "Product", face: "radial-gradient(circle at 30% 30%,#ff9a6b,#f2464f 55%,#e0336f)" },
];
const FACE = 28;
const OVERLAP = 10;
export function Assignees({
people = PEOPLE,
defaultSelected = ["lena", "sam"],
stack = "row",
defaultOpen = true,
outlined = false,
onChange,
}: {
people?: Person[];
defaultSelected?: string[];
/** "row" overlaps faces in a line, "grid" packs up to four into a 2×2. */
stack?: "row" | "grid";
defaultOpen?: boolean;
outlined?: boolean;
onChange?: (ids: string[]) => void;
}) {
const [sel, setSel] = useState<string[]>(defaultSelected);
const [open, setOpen] = useState(defaultOpen);
const [active, setActive] = useState(-1);
const listId = useId();
const list = useRef<HTMLUListElement>(null);
const toggle = (id: string) => {
// keep selection in list order so faces line up with the rows
const next = sel.includes(id) ? sel.filter((s) => s !== id) : people.map((p) => p.id).filter((p) => p === id || sel.includes(p));
setSel(next);
onChange?.(next);
};
const chosen = people.filter((p) => sel.includes(p.id));
const railW =
stack === "grid"
? chosen.length > 1 ? 2 * 18 + 2 : chosen.length ? FACE : 0
: chosen.length ? FACE + (chosen.length - 1) * (FACE - OVERLAP) : 0;
return (
<div className="flex h-[261px] w-[264px] flex-col items-start gap-[10px] text-[var(--b-fg)]">
<button
type="button"
aria-expanded={open}
aria-controls={listId}
aria-label={`Assignees: ${chosen.map((c) => c.name).join(", ") || "none"}`}
onClick={() => setOpen((o) => !o)}
className={cn(
"flex h-[43px] items-center gap-[10px] rounded-full bg-[var(--b-surface)] pl-[7px] pr-[14px] outline-none focus-visible:ring-2 focus-visible:ring-[var(--b-fg)]/30",
outlined && "ring-1 ring-[var(--b-line)]"
)}
>
<motion.span
className="relative block h-[28px]"
initial={false}
animate={{ width: Math.max(railW, chosen.length ? 0 : 0) }}
transition={{ duration: 0.3, ease: [0.3, 0, 0.2, 1] }}
>
<AnimatePresence initial={false}>
{chosen.map((p, i) => {
const grid = stack === "grid" && chosen.length > 1;
const s = grid ? 18 : FACE;
const x = grid ? (i % 2) * 20 : i * (FACE - OVERLAP);
const y = grid ? (chosen.length > 2 ? Math.floor(i / 2) * 10 - 1 : 5) : 0;
return (
<motion.span
key={p.id}
className="absolute left-0 top-0 rounded-full ring-2 ring-[var(--b-surface)]"
style={{ background: p.face, zIndex: 10 - i }}
initial={{ x, y, width: s, height: s, scale: 0.4, opacity: 0, filter: "blur(4px)" }}
animate={{ x, y, width: s, height: s, scale: 1, opacity: 1, filter: "blur(0px)" }}
exit={{ scale: 0.4, opacity: 0, filter: "blur(4px)" }}
transition={{ type: "spring", stiffness: 380, damping: 28 }}
/>
);
})}
</AnimatePresence>
</motion.span>
<motion.span animate={{ rotate: open ? 0 : 180 }} transition={{ duration: 0.25 }} className="text-[var(--b-fg-muted)]">
<ChevronUp className="size-[15px]" strokeWidth={2.2} />
</motion.span>
</button>
<AnimatePresence initial={false}>
{open && (
<motion.ul
ref={list}
id={listId}
role="listbox"
aria-multiselectable
aria-label="Assignees"
tabIndex={0}
aria-activedescendant={active >= 0 ? `${listId}-${active}` : undefined}
onFocus={() => active < 0 && setActive(0)}
onKeyDown={(e) => {
if (e.key === "ArrowDown") setActive((a) => Math.min(people.length - 1, a + 1));
else if (e.key === "ArrowUp") setActive((a) => Math.max(0, a - 1));
else if (e.key === "Home") setActive(0);
else if (e.key === "End") setActive(people.length - 1);
else if ((e.key === " " || e.key === "Enter") && active >= 0) toggle(people[active].id);
else if (e.key === "Escape") setOpen(false);
else return;
e.preventDefault();
}}
initial={{ opacity: 0, y: -6, scale: 0.97, filter: "blur(4px)" }}
animate={{ opacity: 1, y: 0, scale: 1, filter: "blur(0px)" }}
exit={{ opacity: 0, y: -6, scale: 0.97, filter: "blur(4px)" }}
transition={{ duration: 0.2 }}
className={cn(
"w-full origin-top rounded-[20px] bg-[var(--b-surface)] p-[8px] shadow-[var(--b-shadow)] outline-none focus-visible:ring-2 focus-visible:ring-[var(--b-fg)]/30",
outlined && "ring-1 ring-[var(--b-line)]"
)}
onPointerLeave={() => setActive(-1)}
>
{people.map((p, i) => {
const on = sel.includes(p.id);
return (
<li
key={p.id}
id={`${listId}-${i}`}
role="option"
aria-selected={on}
onPointerEnter={() => setActive(i)}
onPointerDown={(e) => e.preventDefault()}
onClick={() => toggle(p.id)}
className="relative flex h-[48px] cursor-pointer items-center gap-[12px] rounded-[12px] px-[8px]"
>
{active === i && (
<motion.span
layoutId={`${listId}-hl`}
className="absolute inset-0 rounded-[12px] bg-[var(--b-surface-2)]"
transition={{ type: "spring", stiffness: 500, damping: 40 }}
/>
)}
<span className="relative size-[32px] shrink-0 rounded-full" style={{ background: p.face }} />
<span className="relative flex min-w-0 flex-1 flex-col">
<span className="text-[14px] font-medium leading-[18px]">{p.name}</span>
<span className="text-[12px] leading-[16px] text-[var(--b-fg-muted)]">{p.role}</span>
</span>
<span
className={cn(
"relative flex size-[18px] items-center justify-center rounded-[5px] transition-colors duration-150",
on ? "bg-[var(--b-invert)] text-[var(--b-invert-fg)]" : "ring-[1.5px] ring-inset ring-[var(--b-fg)]/25"
)}
>
<AnimatePresence initial={false}>
{on && (
<motion.span initial={{ scale: 0.4, opacity: 0 }} animate={{ scale: 1, opacity: 1 }} exit={{ scale: 0.4, opacity: 0 }} transition={{ duration: 0.16 }}>
<Check className="size-[12px]" strokeWidth={3} />
</motion.span>
)}
</AnimatePresence>
</span>
</li>
);
})}
</motion.ul>
)}
</AnimatePresence>
</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;
}