import * as React from "react" import * as DialogPrimitive from "@radix-ui/react-dialog" import { cn } from "@/lib/utils" import { X } from "lucide-react" import { isEditableTarget, matchesShortcut } from "@/lib/keyboard" import { ScrollArea } from "@/components/ui/scroll-area" const Dialog = DialogPrimitive.Root const DialogTrigger = DialogPrimitive.Trigger const DialogPortal = DialogPrimitive.Portal const DialogClose = DialogPrimitive.Close const DialogOverlay = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef >(({ className, ...props }, ref) => ( )) DialogOverlay.displayName = DialogPrimitive.Overlay.displayName interface DialogContentProps extends React.ComponentPropsWithoutRef { /** 阻止点击外部关闭(用于 Tour 运行时) */ preventOutsideClose?: boolean /** 隐藏默认关闭按钮(当使用自定义关闭按钮时) */ hideCloseButton?: boolean /** 回车触发主操作按钮 */ confirmOnEnter?: boolean } interface DialogBodyProps extends React.ComponentPropsWithoutRef { allowHorizontalScroll?: boolean } const DialogContent = React.forwardRef< React.ElementRef, DialogContentProps >(({ className, children, preventOutsideClose = false, hideCloseButton = false, confirmOnEnter = false, onKeyDownCapture, ...props }, ref) => ( e.preventDefault() : undefined} onInteractOutside={preventOutsideClose ? (e) => e.preventDefault() : undefined} onKeyDownCapture={(event) => { onKeyDownCapture?.(event) if ( !confirmOnEnter || event.defaultPrevented || !matchesShortcut(event, ['enter']) || event.nativeEvent.isComposing || isEditableTarget(event.target) ) { return } const confirmButton = event.currentTarget.querySelector('[data-dialog-action="confirm"]:not([disabled])') if (!confirmButton) { return } event.preventDefault() confirmButton.click() }} {...props} > {children} {!hideCloseButton && ( 关闭 )} )) DialogContent.displayName = DialogPrimitive.Content.displayName const DialogBody = React.forwardRef( ({ className, children, allowHorizontalScroll = false, contentClassName, scrollbars, viewportClassName, ...props }, ref) => ( {children} ) ) DialogBody.displayName = "DialogBody" const DialogHeader = ({ className, ...props }: React.HTMLAttributes) => (
) DialogHeader.displayName = "DialogHeader" const DialogFooter = ({ className, ...props }: React.HTMLAttributes) => (
) DialogFooter.displayName = "DialogFooter" const DialogTitle = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef >(({ className, ...props }, ref) => ( )) DialogTitle.displayName = DialogPrimitive.Title.displayName const DialogDescription = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef >(({ className, ...props }, ref) => ( )) DialogDescription.displayName = DialogPrimitive.Description.displayName export { Dialog, DialogPortal, DialogOverlay, DialogTrigger, DialogClose, DialogContent, DialogHeader, DialogBody, DialogFooter, DialogTitle, DialogDescription, }