feat: init ai-platform - 源码 + 配置
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import { useEffect } from 'react';
|
||||
import { createPortal } from 'react-dom';
|
||||
import { IconX } from './Icons';
|
||||
|
||||
// 使用 Portal 渲染到 body,避免被父级层叠上下文/导航条遮挡
|
||||
export default function Drawer({ open, title, onClose, children, width = 540 }: any) {
|
||||
useEffect(() => {
|
||||
if (!open) return;
|
||||
const onKey = (e: KeyboardEvent) => { if (e.key === 'Escape') onClose(); };
|
||||
window.addEventListener('keydown', onKey);
|
||||
return () => window.removeEventListener('keydown', onKey);
|
||||
}, [open, onClose]);
|
||||
|
||||
return createPortal(
|
||||
<>
|
||||
{/* 遮罩:覆盖全屏(含导航条),点击任意非抽屉区域关闭 */}
|
||||
{open && <div className="drawer-overlay" onClick={onClose} />}
|
||||
|
||||
<div
|
||||
className={`drawer ${open ? 'drawer-open' : 'drawer-closed'}`}
|
||||
style={{ width }}
|
||||
aria-hidden={!open}
|
||||
>
|
||||
<div className="drawer-header">
|
||||
<span className="drawer-title">{title}</span>
|
||||
<button type="button" className="drawer-close" onClick={onClose} aria-label="关闭" title="关闭">
|
||||
<IconX />
|
||||
</button>
|
||||
</div>
|
||||
<div className="drawer-content">{children}</div>
|
||||
</div>
|
||||
</>,
|
||||
document.body
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user