import { Dialog as BaseDialog } from "@base-ui/react/dialog";
import { Menu } from "@base-ui/react/menu";
import { Popover as BasePopover } from "@base-ui/react/popover";
import { Tooltip as BaseTooltip } from "@base-ui/react/tooltip";
import { CheckIcon } from "../icons";
import { useRef, type ComponentProps, type ReactElement, type ReactNode } from "react";
import { Link } from "../provider";
import { cn } from "./cn";
const SURFACE = "material-popup rounded-panel text-ink shadow-surface";
const SHEET = "rounded-sheet bg-raised text-ink shadow-surface";
const ROW = "flex w-full cursor-pointer items-center gap-2 rounded-control px-2 py-1.5 pointer-coarse:py-2.5 text-left text-compact text-ink outline-none select-none data-[highlighted]:bg-hover data-[disabled]:cursor-not-allowed data-[disabled]:opacity-50 [&_svg]:size-4 [&_svg]:shrink-0 [&_svg]:text-muted";
type Align = "start" | "center" | "end";
function MenuRoot({ children, onOpenChange }: { children: ReactNode; onOpenChange?: (open: boolean) => void }) {
return
onOpenChange?.(open)}>{children};
}
function MenuTrigger({ render, children, ...props }: { render?: ReactElement; children?: ReactNode } & Omit, "render">) {
return (
{children}
);
}
function MenuContent({ align = "start", side = "bottom", className, children }: { align?: Align; side?: "top" | "bottom"; className?: string; children: ReactNode }) {
return (
{children}
);
}
function MenuItem({ icon, variant, className, children, ...props }: { icon?: ReactNode; variant?: "danger" } & ComponentProps) {
return (
{icon}
{children}
);
}
function MenuLinkItem({ href, icon, className, children }: { href: string; icon?: ReactNode; className?: string; children: ReactNode }) {
return (
} className={cn(ROW, className)}>
{icon}
{children}
);
}
function MenuSeparator() {
return ;
}
function MenuCheckboxItem({ checked, onCheckedChange, closeOnClick = false, children }: { checked: boolean; onCheckedChange: (checked: boolean) => void; closeOnClick?: boolean; children: ReactNode }) {
return (
onCheckedChange(next)} closeOnClick={closeOnClick} className={cn(ROW, "pl-7 relative")}>
{children}
);
}
function MenuRadioGroup({ value, onValueChange, children }: { value: string; onValueChange: (value: string) => void; children: ReactNode }) {
return (
onValueChange(next as string)}>
{children}
);
}
function MenuRadioItem({ value, children }: { value: string; children: ReactNode }) {
return (
{children}
);
}
function MenuLabel({ children }: { children: ReactNode }) {
return {children}
;
}
/** A menu of actions or links that opens from its trigger. */
export const DropdownMenu = Object.assign(MenuRoot, {
Trigger: MenuTrigger,
Content: MenuContent,
Item: MenuItem,
LinkItem: MenuLinkItem,
Separator: MenuSeparator,
CheckboxItem: MenuCheckboxItem,
RadioGroup: MenuRadioGroup,
RadioItem: MenuRadioItem,
Label: MenuLabel,
});
const DIALOG_SIZE = { sm: "w-[min(26rem,calc(100vw-2rem))]", base: "w-[min(32rem,calc(100vw-2rem))]", lg: "w-[min(40rem,calc(100vw-2rem))]" };
function DialogPopup({ size = "base", className, children }: { size?: keyof typeof DIALOG_SIZE; className?: string; children: ReactNode }) {
const popup = useRef(null);
/** No button is the default, so Return cannot confirm or cancel by accident. A field takes focus when there is one. */
const firstFocus = () => popup.current?.querySelector("input:not([type='hidden']), textarea") ?? popup.current;
return (
{children}
);
}
/** A modal that asks for a deliberate decision, such as deleting a repository. On a phone it is a bottom sheet. */
export const Dialog = Object.assign(DialogPopup, {
Root: BaseDialog.Root,
Trigger: BaseDialog.Trigger,
Close: BaseDialog.Close,
Title: ({ className, ...props }: ComponentProps) => ,
Description: ({ className, ...props }: ComponentProps) => ,
});
function PopoverContent({ align = "center", side = "bottom", className, children }: { align?: Align; side?: "top" | "bottom"; className?: string; children: ReactNode }) {
return (
{children}
);
}
/** Non-modal content anchored to a trigger, such as clone instructions. */
export const Popover = Object.assign(BasePopover.Root, {
Trigger: BasePopover.Trigger,
Content: PopoverContent,
Title: ({ className, ...props }: ComponentProps) => ,
Description: ({ className, ...props }: ComponentProps) => ,
});
/** A short label on hover or focus. A tooltip opened next to another one appears at once. */
export function Tooltip({ content, side = "top", align = "center", render, className, children }: { content: ReactNode; side?: "top" | "bottom" | "left" | "right"; align?: Align; render?: ReactElement; className?: string; children?: ReactNode }) {
return (
{children}
{content}
);
}
export const TooltipProvider = BaseTooltip.Provider;