import { useState, type ReactNode } from 'react'; import { Check, Copy, Search, X, type LucideIcon } from 'lucide-react'; import type { FileKind, SymbolKind } from '../types'; import { KIND_META, SYMBOL_META } from '../lib/colors'; import { copyText } from '../lib/download'; import { basename } from '../lib/format'; import { selectFile } from '../state/store'; export function KindDot({ kind, size = 8 }: { kind: FileKind; size?: number }) { return ; } export function KindBadge({ kind }: { kind: FileKind }) { const meta = KIND_META[kind]; return ( {meta.label} ); } export function SymbolIcon({ kind, method }: { kind: SymbolKind; method?: boolean }) { const meta = SYMBOL_META[method ? 'method' : kind]; return ( {meta.letter} ); } export function Stat({ icon: Icon, value, label, hint, color, onClick, }: { icon: LucideIcon; value: ReactNode; label: string; hint?: ReactNode; color?: string; onClick?: () => void; }) { return (
{value}
{label}
{hint &&
{hint}
}
); } export function Empty({ icon: Icon, title, children }: { icon: LucideIcon; title: string; children?: ReactNode }) { return (

{title}

{children &&

{children}

}
); } export function Segmented({ value, options, onChange, }: { value: T; options: { value: T; label: ReactNode; icon?: LucideIcon; title?: string }[]; onChange: (v: T) => void; }) { return (
{options.map((o) => ( ))}
); } export function Toggle({ checked, onChange, label, title }: { checked: boolean; onChange: (v: boolean) => void; label: ReactNode; title?: string }) { return ( ); } export function Select({ value, options, onChange, title, style, }: { value: T; options: { value: T; label: string }[]; onChange: (v: T) => void; title?: string; style?: React.CSSProperties; }) { return ( ); } export function SearchInput({ value, onChange, placeholder = 'Filter…', style, autoFocus, }: { value: string; onChange: (v: string) => void; placeholder?: string; style?: React.CSSProperties; autoFocus?: boolean; }) { return (
onChange(e.target.value)} autoFocus={autoFocus} spellCheck={false} /> {value && ( )}
); } export function Tabs({ value, tabs, onChange, }: { value: T; tabs: { value: T; label: string; count?: number; icon?: LucideIcon }[]; onChange: (v: T) => void; }) { return (
{tabs.map((t) => ( ))}
); } export function CopyButton({ text, label }: { text: string; label?: string }) { const [done, setDone] = useState(false); return ( ); } export function FileChip({ id, kind, line, label }: { id: string; kind?: FileKind; line?: number; label?: string }) { return ( ); } export function BarList({ items, max, onClick, format = (v) => v.toLocaleString('en-US'), }: { items: { key: string; label: ReactNode; value: number; color?: string }[]; max?: number; onClick?: (key: string) => void; format?: (v: number) => string; }) { const top = max ?? Math.max(1, ...items.map((i) => i.value)); return (
{items.map((item) => (
onClick?.(item.key)} style={{ cursor: onClick ? 'pointer' : 'default' }}>
{item.label}
{format(item.value)}
))}
); } export function SectionTitle({ children, right }: { children: ReactNode; right?: ReactNode }) { return (
{children} {right && {right}}
); }