-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathDropdownMenus.tsx
More file actions
143 lines (132 loc) · 3.31 KB
/
DropdownMenus.tsx
File metadata and controls
143 lines (132 loc) · 3.31 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/* eslint no-alert: "off" */
/* eslint no-console: "off" */
import React, { Component } from 'react';
import {
ContextActions,
DropdownMenu,
KEY,
MODIFIER,
Shortcut,
type DropdownAction,
Button,
} from '@deephaven/components';
import {
vsBell,
dhFilePrint,
vsKebabVertical,
vsQuestion,
} from '@deephaven/icons';
import SampleSection from './SampleSection';
interface DropdownMenus {
button: React.RefObject<HTMLDivElement>;
}
interface DropdownMenusState {
isShown: boolean;
}
class DropdownMenus extends Component<
Record<string, never>,
DropdownMenusState
> {
constructor(props: Record<string, never>) {
super(props);
this.state = {
isShown: false,
};
}
render(): React.ReactElement {
const contextActions = [
{
title: `Show Alert`,
icon: vsBell,
action: () => {
alert(`Alert!`);
},
shortcut: new Shortcut({
id: 'STYLEGUIDE.SHOW_ALERT',
name: 'Show Alert',
shortcut: [MODIFIER.CTRL, KEY.A],
macShortcut: [MODIFIER.CMD, KEY.A],
}),
},
{
title: `Log Message`,
icon: dhFilePrint,
action: () => {
console.log(`Logging a message!`);
},
shortcut: new Shortcut({
id: 'STYLEGUIDE.LOG_MESSAGE',
name: 'Log Message',
shortcut: [MODIFIER.CTRL, KEY.L],
macShortcut: [MODIFIER.CMD, KEY.L],
}),
},
] as DropdownAction[];
const globalActions = [
{
title: 'Show Shortcuts',
icon: vsQuestion,
action: () => {
alert('Show keyboard shortcuts!');
},
shortcut: new Shortcut({
id: 'STYLEGUIDE.SHOW_SHORTCUTS',
name: 'Show Shortcuts',
shortcut: [MODIFIER.CTRL, KEY.SLASH],
macShortcut: [MODIFIER.CMD, KEY.SLASH],
}),
group: ContextActions.groups.global,
},
] as DropdownAction[];
const actions = globalActions.concat(contextActions);
const { isShown } = this.state;
return (
<SampleSection name="dropdown-menus">
<h2 className="ui-title">Dropdown Menu</h2>
<p>
A simple dropdown menu of actions, can open on click of parent
container, or controlled by prop.
</p>
<Button
kind="inline"
className="mx-2"
icon={vsKebabVertical}
onClick={() => undefined}
>
<DropdownMenu actions={actions} />
</Button>
<Button
kind="primary"
style={{
marginRight: '1rem',
minWidth: '165px',
}}
onClick={() => {
if (isShown) {
this.setState({ isShown: false });
} else {
this.setState({ isShown: true });
}
}}
>
Menu Shown: {isShown.toString()}
</Button>
<div
ref={this.button}
className="btn btn-secondary disabled"
style={{ marginRight: '1rem' }}
>
Shown using isShown
<DropdownMenu
isShown={isShown}
onMenuClosed={() => {
this.setState({ isShown: false });
}}
actions={actions}
/>
</div>
</SampleSection>
);
}
}
export default DropdownMenus;