feat: add desktop icon and context menu components

This commit is contained in:
M1ngdaXie
2026-03-26 14:24:35 -07:00
parent 9f46c0697c
commit 0bcfeafdca
4 changed files with 126 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
.context-menu {
position: fixed;
background: rgba(40, 40, 52, 0.82);
backdrop-filter: var(--glass-blur);
-webkit-backdrop-filter: var(--glass-blur);
border: 1px solid var(--glass-border);
border-radius: 8px;
box-shadow: 0 8px 32px rgba(0,0,0,0.4);
padding: 4px;
min-width: 200px;
z-index: 9000;
}
.context-menu-item {
display: flex;
align-items: center;
gap: 8px;
padding: 6px 10px;
border-radius: 5px;
font-size: 13px;
color: rgba(255,255,255,0.9);
cursor: default;
}
.context-menu-item:hover {
background: var(--accent-blue);
}
.context-menu-separator {
height: 1px;
background: var(--glass-border);
margin: 3px 6px;
}

View File

@@ -0,0 +1,38 @@
import { useEffect, useRef } from 'react';
import './ContextMenu.css';
interface Props {
x: number;
y: number;
onClose: () => void;
onChangeWallpaper: () => void;
onAboutThisMac: () => void;
}
export default function ContextMenu({ x, y, onClose, onChangeWallpaper, onAboutThisMac }: Props) {
const ref = useRef<HTMLDivElement>(null);
useEffect(() => {
const handler = (e: MouseEvent) => {
if (ref.current && !ref.current.contains(e.target as Node)) onClose();
};
document.addEventListener('mousedown', handler);
return () => document.removeEventListener('mousedown', handler);
}, [onClose]);
return (
<div ref={ref} className="context-menu" style={{ left: x, top: y }}>
<div className="context-menu-item" onClick={onClose}>
<span>📁</span> New Folder
</div>
<div className="context-menu-separator" />
<div className="context-menu-item" onClick={() => { onChangeWallpaper(); onClose(); }}>
<span>🖼</span> Change Wallpaper
</div>
<div className="context-menu-separator" />
<div className="context-menu-item" onClick={() => { onAboutThisMac(); onClose(); }}>
<span>🍎</span> About This Mac
</div>
</div>
);
}