41 lines
793 B
TypeScript
41 lines
793 B
TypeScript
|
|
import { create } from 'zustand';
|
||
|
|
|
||
|
|
export interface ContextMenuItem {
|
||
|
|
label: string;
|
||
|
|
icon?: React.ReactNode;
|
||
|
|
onClick: () => void;
|
||
|
|
disabled?: boolean;
|
||
|
|
separator?: boolean;
|
||
|
|
danger?: boolean;
|
||
|
|
}
|
||
|
|
|
||
|
|
interface ContextMenuState {
|
||
|
|
isOpen: boolean;
|
||
|
|
position: { x: number; y: number } | null;
|
||
|
|
items: ContextMenuItem[];
|
||
|
|
showContextMenu: (x: number, y: number, items: ContextMenuItem[]) => void;
|
||
|
|
hideContextMenu: () => void;
|
||
|
|
}
|
||
|
|
|
||
|
|
export const useContextMenuStore = create<ContextMenuState>((set) => ({
|
||
|
|
isOpen: false,
|
||
|
|
position: null,
|
||
|
|
items: [],
|
||
|
|
|
||
|
|
showContextMenu: (x, y, items) => {
|
||
|
|
set({
|
||
|
|
isOpen: true,
|
||
|
|
position: { x, y },
|
||
|
|
items,
|
||
|
|
});
|
||
|
|
},
|
||
|
|
|
||
|
|
hideContextMenu: () => {
|
||
|
|
set({
|
||
|
|
isOpen: false,
|
||
|
|
position: null,
|
||
|
|
items: [],
|
||
|
|
});
|
||
|
|
},
|
||
|
|
}));
|