forked from taskcluster/taskcluster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.jsx
69 lines (60 loc) · 1.66 KB
/
index.jsx
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
import React, { useState } from 'react';
import classNames from 'classnames';
import { arrayOf, node, oneOfType } from 'prop-types';
import { withStyles } from '@material-ui/core/styles';
import MuiSpeedDial from '@material-ui/lab/SpeedDial';
import SpeedDialIcon from '@material-ui/lab/SpeedDialIcon';
import CloseIcon from 'mdi-react/CloseIcon';
import DotsVerticalIcon from 'mdi-react/DotsVerticalIcon';
const styles = withStyles(theme => ({
speedDial: {
...theme.mixins.fab,
},
}));
/**
* Render a dynamically expanding set of floating action buttons.
*/
function SpeedDial(props) {
const { classes, children, className, ...rest } = props;
const [open, setOpen] = useState(false);
let timeout;
function handleClose(evt) {
if (evt.type === 'click') {
setOpen(false);
} else {
if (timeout) {
clearTimeout(timeout);
}
timeout = setTimeout(() => setOpen(false), 2000);
}
}
function handleOpen() {
if (timeout) {
clearTimeout(timeout);
}
setOpen(true);
}
return (
<MuiSpeedDial
ariaLabel="speed-dial"
icon={
<SpeedDialIcon icon={<DotsVerticalIcon />} openIcon={<CloseIcon />} />
}
FabProps={{ color: 'secondary' }}
className={classNames(classes.speedDial, className)}
onOpen={handleOpen}
onClose={handleClose}
open={open}
{...rest}>
{children}
</MuiSpeedDial>
);
}
SpeedDial.propTypes = {
/**
* A set of `SpeedDialAction`s which will be rendered upon interaction
* with the base `SpeedDial` floating action button.
*/
children: oneOfType([arrayOf(node), node]).isRequired,
};
export default styles(SpeedDial);