-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
ContextualMenu.Basic.Example.tsx
89 lines (85 loc) · 2.31 KB
/
ContextualMenu.Basic.Example.tsx
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import * as React from 'react';
import { ContextualMenu, ContextualMenuItemType, IContextualMenuItem } from 'office-ui-fabric-react/lib/ContextualMenu';
import { useConstCallback } from '@uifabric/react-hooks';
export interface IContextualMenuBasicExampleState {
showContextualMenu?: boolean;
}
export const ContextualMenuBasicExample: React.FunctionComponent = () => {
const linkRef = React.useRef(null);
const [showContextualMenu, setShowContextualMenu] = React.useState(false);
const onShowContextualMenu = useConstCallback(() => setShowContextualMenu(true));
const onHideContextualMenu = useConstCallback(() => setShowContextualMenu(false));
return (
<div>
This example directly uses ContextualMenu to show how it can be attached to arbitrary elements. The remaining examples use
ContextualMenu through Fabric Button components.
<p>
<b>
<a ref={linkRef} onClick={onShowContextualMenu}>
Click for ContextualMenu
</a>
</b>
</p>
<ContextualMenu
items={menuItems}
hidden={!showContextualMenu}
target={linkRef}
onItemClick={onHideContextualMenu}
onDismiss={onHideContextualMenu}
/>
</div>
);
};
const menuItems: IContextualMenuItem[] = [
{
key: 'newItem',
text: 'New',
onClick: () => console.log('New clicked')
},
{
key: 'divider_1',
itemType: ContextualMenuItemType.Divider
},
{
key: 'rename',
text: 'Rename',
onClick: () => console.log('Rename clicked')
},
{
key: 'edit',
text: 'Edit',
onClick: () => console.log('Edit clicked')
},
{
key: 'properties',
text: 'Properties',
onClick: () => console.log('Properties clicked')
},
{
key: 'linkNoTarget',
text: 'Link same window',
href: 'http://bing.com'
},
{
key: 'linkWithTarget',
text: 'Link new window',
href: 'http://bing.com',
target: '_blank'
},
{
key: 'linkWithOnClick',
name: 'Link click',
href: 'http://bing.com',
onClick: (ev: React.MouseEvent<HTMLAnchorElement | HTMLButtonElement>) => {
alert('Link clicked');
ev.preventDefault();
},
target: '_blank'
},
{
key: 'disabled',
text: 'Disabled item',
disabled: true,
onClick: () => console.error('Disabled item should not be clickable.')
}
];