Files
ai-platform/src/modules/bomx-reuse-analyzer/components/Drawer.tsx
T
dongskandClaude Sonnet 4.6 noreply@anthropic.com> 8699798ea5 feat: 模组全维度独立,消除全局 DOM/Portal/存储污染
- jieya-ibp/welltrust-qap ThemeContext 改为作用域容器承载 CSS 变量与背景色,不再写 document
- 删除 order-cost CostCockpit 对 documentElement 的死变量写入
- bomx Drawer createPortal 挂载点内移到 .bomx-app,移除 document.body 兜底
- knowledge-graph 拖拽 cursor 改为根容器 ref
- 新增 check-module-independence 门禁并接入 build
- SOP 与融合技能文档补充「模组完全独立互不影响」章节

Co-Authored-By: Claude Sonnet 4.6 noreply@anthropic.com>
2026-10-19 09:10:30 +08:00

43 lines
1.6 KiB
TypeScript

import { useEffect } from 'react';
import { createPortal } from 'react-dom';
import { IconX } from './Icons';
// Portal 渲染到模块根容器内的挂载点(必传 portalMount),
// 保持 DOM 节点位于模块作用域内,禁止挂到 document.body
export default function Drawer({ open, title, onClose, children, width = 540, portalMount }: {
open: boolean; title?: React.ReactNode; onClose: () => void;
children?: React.ReactNode; width?: number;
portalMount: HTMLDivElement;
}) {
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(
// 模块根容器包裹层:为 portal 内容提供 .bomx-app 作用域下的 CSS 变量;
// overlay/panel 均 position:fixed,且平台 body 为 overflow:hidden,包裹层不影响布局
<div className="bomx-app">
{/* 遮罩:覆盖全屏(含导航条),点击任意非抽屉区域关闭 */}
{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>
</div>,
portalMount
);
}