Skip to content

Commit 793bdb0

Browse files
committed
feat: implement Portal component for improved dialog management and enhance background styling
1 parent ca2a14d commit 793bdb0

3 files changed

Lines changed: 40 additions & 7 deletions

File tree

src/webui/FE/components/AnimatedBackground.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ const AnimatedBackground: React.FC = () => {
165165
<canvas
166166
ref={canvasRef}
167167
className="fixed inset-0 w-full h-full pointer-events-none"
168-
style={{ zIndex: -1 }}
168+
style={{ zIndex: 0 }}
169169
/>
170170
);
171171
};

src/webui/FE/components/OneBotConfigNew.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { useState } from 'react';
22
import { OB11Config, ConnectConfig, WsConnectConfig, WsReverseConnectConfig, HttpConnectConfig, HttpPostConnectConfig } from '../types';
33
import { Radio, Wifi, Globe, Send, X, Settings, Plus, Trash2, Edit2, Eye, EyeOff } from 'lucide-react';
4+
import Portal from './Portal';
45

56
interface OneBotConfigProps {
67
config: OB11Config;
@@ -251,8 +252,9 @@ const OneBotConfigNew: React.FC<OneBotConfigProps> = ({ config, onChange, onSave
251252

252253
{/* 配置弹窗 */}
253254
{showDialog && selectedAdapter && (
254-
<div className="fixed inset-0 bg-black/30 backdrop-blur-sm z-50 flex items-center justify-center p-4">
255-
<div className="bg-white/90 backdrop-blur-xl rounded-3xl shadow-2xl w-full max-w-2xl max-h-[80vh] flex flex-col">
255+
<Portal>
256+
<div className="fixed inset-0 bg-black/30 backdrop-blur-sm z-50 flex items-center justify-center p-4">
257+
<div className="bg-white/60 backdrop-blur-xl rounded-3xl shadow-2xl w-full max-w-2xl max-h-[80vh] flex flex-col border border-white/50">
256258
{/* Header */}
257259
<div className="flex items-center justify-between p-6 border-b border-white/20">
258260
<div className="flex items-center gap-3 flex-1">
@@ -569,13 +571,15 @@ const OneBotConfigNew: React.FC<OneBotConfigProps> = ({ config, onChange, onSave
569571
</div>
570572
</div>
571573
</div>
572-
</div>
574+
</div>
575+
</Portal>
573576
)}
574577

575578
{/* 添加适配器对话框 */}
576579
{showAddDialog && (
577-
<div className="fixed inset-0 bg-black/30 backdrop-blur-sm z-50 flex items-center justify-center p-4">
578-
<div className="bg-white/90 backdrop-blur-xl rounded-3xl shadow-2xl w-full max-w-md">
580+
<Portal>
581+
<div className="fixed inset-0 bg-black/30 backdrop-blur-sm z-50 flex items-center justify-center p-4">
582+
<div className="bg-white/60 backdrop-blur-xl rounded-3xl shadow-2xl w-full max-w-md border border-white/50">
579583
<div className="flex items-center justify-between p-6 border-b border-white/20">
580584
<h3 className="text-xl font-semibold text-gray-900">选择适配器类型</h3>
581585
<button onClick={() => setShowAddDialog(false)} className="text-gray-400 hover:text-gray-600">
@@ -646,7 +650,8 @@ const OneBotConfigNew: React.FC<OneBotConfigProps> = ({ config, onChange, onSave
646650
</button>
647651
</div>
648652
</div>
649-
</div>
653+
</div>
654+
</Portal>
650655
)}
651656
</div>
652657
);

src/webui/FE/components/Portal.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { useEffect, useRef, ReactNode } from 'react';
2+
import { createPortal } from 'react-dom';
3+
4+
interface PortalProps {
5+
children: ReactNode;
6+
}
7+
8+
const Portal: React.FC<PortalProps> = ({ children }) => {
9+
const elRef = useRef<HTMLDivElement | null>(null);
10+
11+
if (!elRef.current) {
12+
elRef.current = document.createElement('div');
13+
}
14+
15+
useEffect(() => {
16+
const portalRoot = document.body;
17+
const el = elRef.current!;
18+
portalRoot.appendChild(el);
19+
20+
return () => {
21+
portalRoot.removeChild(el);
22+
};
23+
}, []);
24+
25+
return createPortal(children, elRef.current);
26+
};
27+
28+
export default Portal;

0 commit comments

Comments
 (0)