import Link from "next/link"; import type { ReactNode } from "react"; import { cn } from "./cn"; export interface SegmentedOption { value: V; label: ReactNode; /** link version (server-friendly URL state) */ href?: string; title?: string; disabled?: boolean; } /** * Compact segmented control (view switchers, radius toggles, density modes). Server-safe when options carry `href`; * pass `onChange` from a client component for local state. 40 px tall under 640 px, 28–32 px from `sm`. */ export function SegmentedControl({ options, value, onChange, label, size = "sm", className, scroll = false }: { options: Array>; value: V; onChange?: (v: V) => void; label: string; size?: "xs" | "sm" | "md"; className?: string; scroll?: boolean }) { const h = size === "md" ? "h-10 sm:h-9 px-3 text-[13px]" : size === "xs" ? "h-10 sm:h-7 px-2 text-[11.5px]" : "h-10 sm:h-8 px-2.5 text-[12.5px]"; return (
{options.map((o) => { const active = o.value === value; const cls = cn("inline-flex shrink-0 items-center justify-center gap-1.5 whitespace-nowrap rounded-xs font-medium transition-colors", h, active ? "bg-ink text-paper" : "text-ink-2 hover:bg-surface-2 hover:text-ink", o.disabled && "pointer-events-none opacity-40"); if (o.href && !onChange) { return ( {o.label} ); } return ( ); })}
); }