forked from patternfly/react-console
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpiceActions.tsx
More file actions
46 lines (42 loc) · 1.43 KB
/
Copy pathSpiceActions.tsx
File metadata and controls
46 lines (42 loc) · 1.43 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
import React from 'react';
import { Dropdown, DropdownItem, DropdownList, MenuToggle, MenuToggleElement } from '@patternfly/react-core';
export interface SpiceActionsProps extends React.HTMLProps<HTMLDivElement> {
/** Callback for when Ctrl+Alt+Delete item is selected */
onCtrlAltDel?: () => void;
/** Text for the Dropdown Ctrl+Alt+Delety item */
textCtrlAltDel?: string;
/** Text for the Dropdown toggle button */
textSendShortcut?: string;
}
export const SpiceActions: React.FunctionComponent<SpiceActionsProps> = ({
textSendShortcut = 'Send Key',
textCtrlAltDel = 'Ctrl+Alt+Del',
onCtrlAltDel
}: SpiceActionsProps) => {
const [isOpen, setIsOpen] = React.useState(false);
const onToggleClick = () => {
setIsOpen(!isOpen);
};
const onSelect = (_event: React.MouseEvent<Element, MouseEvent>, _value: string | number) => {
setIsOpen(false);
onCtrlAltDel();
};
return (
<Dropdown
id="console-send-shortcut"
onSelect={onSelect}
isOpen={isOpen}
onOpenChange={(isOpen: boolean) => setIsOpen(isOpen)}
toggle={(toggleRef: React.Ref<MenuToggleElement>) => (
<MenuToggle ref={toggleRef} onClick={onToggleClick} isExpanded={isOpen}>
{textSendShortcut}
</MenuToggle>
)}
>
<DropdownList>
<DropdownItem key="ctrl-alt-delete">{textCtrlAltDel}</DropdownItem>
</DropdownList>
</Dropdown>
);
};
SpiceActions.displayName = 'SpiceActions';