-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathActionButton.js
More file actions
36 lines (31 loc) · 877 Bytes
/
Copy pathActionButton.js
File metadata and controls
36 lines (31 loc) · 877 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
import Button from '@mui/material/Button';
import Tooltip from '@mui/material/Tooltip';
import { bind } from 'mousetrap';
import React, { useEffect } from 'react';
// for adding tooltip to disabled buttons
// from https://stackoverflow.com/questions/61115913
const ActionButton = ({ tooltipText, disabled, onClick, hotkey, ...other }) => {
const adjustedButtonProps = {
disabled: disabled,
component: disabled ? 'div' : undefined,
onClick: disabled ? undefined : onClick,
};
useEffect(() => {
bind(hotkey, onClick);
}, [hotkey, onClick]);
return (
<Tooltip title={tooltipText} placement='right'>
<Button
{...other}
{...adjustedButtonProps}
sx={{
p: 0,
'&.Mui-disabled': {
pointerEvents: 'auto',
},
}}
/>
</Tooltip>
);
};
export default ActionButton;