feat(components): add BlockingOverlay component for modal interactions

Introduce a new BlockingOverlay component to handle modal overlays with click handling and visibility control. The component includes click event propagation prevention and supports custom styling through className.
This commit is contained in:
icarus 2025-10-22 05:45:54 +08:00
parent 578cf38072
commit 91cf5d2e7d
2 changed files with 45 additions and 0 deletions

View File

@ -87,6 +87,8 @@ export { HelpTooltip, type IconTooltipProps, InfoTooltip, WarnTooltip } from './
export { default as ImageToolButton } from './interactive/ImageToolButton'
// Sortable
export { Sortable } from './interactive/Sortable'
// BlockingOverlay
export { BlockingOverlay } from './interactive/BlockingOverlay'
// Composite Components (复合组件)
// 暂无复合组件

View File

@ -0,0 +1,43 @@
import { cn } from '@heroui/react'
import type { ReactNode } from 'react'
import React, { useCallback } from 'react'
// 定义组件的 props 类型
interface BlockingOverlayProps {
isVisible: boolean
onClick?: () => void
children?: ReactNode
className?: string
}
export const BlockingOverlay = ({ isVisible, onClick, children, className }: BlockingOverlayProps) => {
const handleClick = useCallback(
(event: React.MouseEvent) => {
event.stopPropagation()
event.preventDefault()
if (onClick) {
onClick()
}
},
[onClick]
)
if (!isVisible) {
return null
}
return (
<div
className={cn(
'fixed inset-0',
'bg-black/50',
'z-[9999]',
'flex items-center justify-center',
'pointer-events-auto',
className
)}
onClick={handleClick}>
{children}
</div>
)
}