-
-
Notifications
You must be signed in to change notification settings - Fork 131
Expand file tree
/
Copy pathuseContextMenu.ts
More file actions
40 lines (35 loc) · 935 Bytes
/
Copy pathuseContextMenu.ts
File metadata and controls
40 lines (35 loc) · 935 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { contextMenu, ShowContextMenuParams } from '../core';
import { MenuId } from '../types';
export interface UseContextMenuParams<TProps = unknown> {
id: MenuId;
props?: TProps;
}
export type MakeOptional<Type, Key extends keyof Type> = Omit<Type, Key> &
Partial<Pick<Type, Key>>;
export function useContextMenu<TProps>(
params: UseContextMenuParams<TProps>
): {
show: (params: MakeOptional<ShowContextMenuParams, 'id'>) => void;
hideAll: () => void;
};
export function useContextMenu<TProps>(
params?: Partial<UseContextMenuParams<TProps>>
): {
show: (params: ShowContextMenuParams) => void;
hideAll: () => void;
};
export function useContextMenu(
props?: UseContextMenuParams | Partial<UseContextMenuParams>
) {
return {
show(params: ShowContextMenuParams) {
contextMenu.show({
...props,
...params,
});
},
hideAll() {
contextMenu.hideAll();
},
};
}