diff --git a/src/components/contextMenu/index.tsx b/src/components/contextMenu/index.tsx index 1b9382525..8648c6ff5 100644 --- a/src/components/contextMenu/index.tsx +++ b/src/components/contextMenu/index.tsx @@ -15,7 +15,9 @@ export function useContextMenu(props: IContextMenu) { return; } - const contextView = useContextView(); + const contextView = useContextView({ + render + }); const onContextMenu = (e: MouseEvent) => { e.preventDefault(); @@ -35,5 +37,5 @@ export function useContextMenu(props: IContextMenu) { anchor.removeEventListener('contextmenu', onContextMenu); }; - return { contextView, dispose }; + return { ...contextView, dispose }; } diff --git a/src/components/contextview/style.scss b/src/components/contextview/style.scss index c8411ecd2..ee5a79817 100644 --- a/src/components/contextview/style.scss +++ b/src/components/contextview/style.scss @@ -8,6 +8,11 @@ $name: 'context-view'; width: initial; z-index: 2500; + .context-view-content { + box-shadow: rgb(0, 0, 0) 0 2px 4px; + overflow: hidden; + } + .#{$name}-block { bottom: 0; height: 100%; diff --git a/src/model/workbench/activityBar.ts b/src/model/workbench/activityBar.ts index 4c5f3aefc..3152adb7c 100644 --- a/src/model/workbench/activityBar.ts +++ b/src/model/workbench/activityBar.ts @@ -3,6 +3,7 @@ import 'reflect-metadata'; import { EventBus } from 'mo/common/event'; import { observable } from 'mo/common/observable'; import { container, inject, injectable } from 'tsyringe'; +import { IMenuItem } from 'mo/components/menu'; /** * The activity bar event definition @@ -21,12 +22,13 @@ export enum ActivityBarEvent { } export interface IActivityBarItem { - id?: string; + id: string; name?: string; data?: any; iconName?: string; checked?: boolean; type?: 'normal' | 'global'; + contextMenu?: IMenuItem[]; render?: () => React.ReactNode | JSX.Element; onClick?: (event: React.MouseEvent, item: IActivityBarItem) => void; } diff --git a/src/services/workbench/activityBarService.ts b/src/services/workbench/activityBarService.ts index 463f9f7d7..a0d68d400 100644 --- a/src/services/workbench/activityBarService.ts +++ b/src/services/workbench/activityBarService.ts @@ -15,8 +15,8 @@ export interface IActivityBarService extends Component { * Add click event listener * @param callback */ - onClick(callback: Function); - onSelect(callback: Function); + onClick(callback: (key: React.MouseEvent) => void); + onSelect(callback: (key: React.MouseEvent, item: IActivityBarItem) => void); } @singleton() @@ -60,7 +60,7 @@ export class ActivityBarService this.subscribe(ActivityBarEvent.OnClick, callback); } - public onSelect(callback: Function) { + public onSelect(callback: (key: React.MouseEvent, item: IActivityBarItem) => void) { this.subscribe(ActivityBarEvent.Selected, (args) => { const key = args[0]; const item: IActivityBarItem = args[1]; diff --git a/src/workbench/activityBar/activityBar.tsx b/src/workbench/activityBar/activityBar.tsx index d6c66a51d..c6711e9cc 100644 --- a/src/workbench/activityBar/activityBar.tsx +++ b/src/workbench/activityBar/activityBar.tsx @@ -3,7 +3,6 @@ import * as React from 'react'; import { prefixClaName } from 'mo/common/className'; import { ID_ACTIVITY_BAR } from 'mo/common/id'; import { IActivityBar, IActivityBarItem } from 'mo/model/workbench/activityBar'; - import ActivityBarItem from './activityBarItem'; export function ActivityBar(props: IActivityBar) { @@ -14,7 +13,6 @@ export function ActivityBar(props: IActivityBar) { } const onClickBar = (e: React.MouseEvent, item: IActivityBarItem) => { - console.log('ActivityBar onClick:', e); if (onClick) onClick(e, item); if (onSelect) { onSelect(item.id || '', item); @@ -31,6 +29,7 @@ export function ActivityBar(props: IActivityBar) { ) || []; const renderItems = (item: IActivityBarItem, index: number) => { + return ( ; + let contextViewMenu; + + useEffect(() => { + if (contextMenu.length > 0) { + contextViewMenu = useContextMenu({ + anchor: select(`#${id}`), + render: renderContextMenu + }); + } + return function cleanup() { + contextViewMenu?.dispose(); + }; + }); + const onClickItem = function (event) { if (onClick) { onClick(event, props); } + if (contextMenu.length > 0 && contextViewMenu) { + contextViewMenu.show({ + x: event.clientX, + y: event.clientY, + }); + } }; return (