import { CircleAlert, Inbox, LoaderCircle, X } from 'lucide-react'; import { AlertDialog, Dialog as RDialog, DropdownMenu, Popover as RPopover, Switch as RSwitch, Tooltip as RTooltip } from 'radix-ui'; import { createContext, forwardRef, useCallback, useContext, useEffect, useId, useRef, useState, type ButtonHTMLAttributes, type InputHTMLAttributes, type ReactNode, type SelectHTMLAttributes, type TextareaHTMLAttributes } from 'react'; import { Link } from 'react-router'; import { cx } from '@/lib/util'; /* ------------------------------ Button ------------------------------ */ type Variant = 'primary' | 'secondary' | 'ghost' | 'danger' | 'marker'; type Size = 'sm' | 'md' | 'lg'; const VARIANT: Record = { primary: 'bg-ink text-paper hover:bg-ink/88 active:bg-ink shadow-1', secondary: 'bg-surface text-ink border border-line-strong hover:bg-sunken active:bg-sunken shadow-1', ghost: 'text-ink-2 hover:bg-ink/6 hover:text-ink active:bg-ink/10', danger: 'bg-bad text-white hover:bg-bad/90 shadow-1 dark:text-[#1b1a17]', marker: 'bg-marker text-marker-ink hover:brightness-95 active:brightness-90 shadow-1', }; const SIZE: Record = { sm: 'h-8 px-2.5 text-[13px] gap-1.5 rounded-[8px]', md: 'h-10 px-3.5 text-sm gap-2 rounded-[10px]', lg: 'h-12 px-5 text-[15px] gap-2 rounded-[12px]', }; export interface ButtonProps extends ButtonHTMLAttributes { variant?: Variant; size?: Size; loading?: boolean; icon?: ReactNode; block?: boolean; /** Renders a link to a page inside the app that looks like a button. */ to?: string; /** Renders an ordinary link (downloads, external pages) that looks like a button. */ href?: string; target?: string; download?: string | boolean; } export const Button = forwardRef(function Button( { variant = 'secondary', size = 'md', loading, icon, block, className, children, disabled, type = 'button', to, href, target, download, ...rest }, ref, ) { const classes = cx( 'inline-flex shrink-0 select-none items-center justify-center font-medium whitespace-nowrap transition-[background,color,filter,transform] duration-100 active:scale-[0.985] disabled:pointer-events-none disabled:opacity-50', VARIANT[variant], SIZE[size], block && 'w-full', className, ); const content = ( <> {loading ? : icon ? {icon} : null} {children} ); // A disabled link is not a thing: fall through to a disabled button. if (!disabled && !loading && to) { return ( {content} ); } if (!disabled && !loading && href) { return ( {content} ); } return ( ); }); export const IconButton = forwardRef & { label: string; size?: 'sm' | 'md'; active?: boolean; tooltip?: boolean }>(function IconButton( { label, size = 'md', active, tooltip = true, className, children, type = 'button', ...rest }, ref, ) { const button = ( ); return tooltip ? {button} : button; }); /* ------------------------------ Tooltip ------------------------------ */ export function Tooltip({ label, children, side = 'bottom' }: { label: ReactNode; children: ReactNode; side?: 'top' | 'bottom' | 'left' | 'right' }) { return ( {children} {label} ); } export const TooltipProvider = RTooltip.Provider; /* ------------------------------ Form controls ------------------------------ */ const CONTROL = 'w-full rounded-[10px] border border-line-strong bg-surface px-3 text-sm text-ink shadow-1 outline-none transition-colors placeholder:text-ink-3 hover:border-ink-3 focus:border-accent focus:ring-2 focus:ring-accent/20 disabled:opacity-60 aria-[invalid=true]:border-bad aria-[invalid=true]:ring-bad/15'; export const Input = forwardRef>(function Input({ className, ...rest }, ref) { return ; }); export const Textarea = forwardRef & { autoGrow?: boolean; maxRows?: number }>(function Textarea( { className, autoGrow, maxRows = 16, onChange, value, rows = 3, ...rest }, ref, ) { const inner = useRef(null); const resize = useCallback(() => { const el = inner.current; if (!el || !autoGrow) return; el.style.height = 'auto'; const line = parseFloat(getComputedStyle(el).lineHeight) || 22; el.style.height = `${Math.min(el.scrollHeight + 2, line * maxRows + 20)}px`; }, [autoGrow, maxRows]); useEffect(resize, [resize, value]); return (