-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathindex.js
More file actions
74 lines (70 loc) · 1.91 KB
/
index.js
File metadata and controls
74 lines (70 loc) · 1.91 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
// @flow
import * as React from 'react';
import Tooltip from '@material-ui/core/Tooltip';
import classNames from 'classnames';
import classes from './CompactToggleButtons.module.css';
import { tooltipEnterDelay } from '../Tooltip';
export type CompactToggleButton = {|
id: string,
renderIcon: (className?: string) => React.Node,
tooltip: React.Node,
onClick: () => void,
isActive: boolean,
label?: string,
|};
export type CompactToggleButtonsProps = {|
id: string,
noSeparator?: boolean,
buttons: CompactToggleButton[],
expand?: boolean,
|};
const CompactToggleButtons = ({
id,
noSeparator,
buttons,
expand,
}: CompactToggleButtonsProps): React.MixedElement => {
return (
<div
id={id}
className={classNames({
[classes.container]: true,
[classes.containerExpand]: expand,
})}
>
{buttons.map((button, index) => (
<React.Fragment key={button.id}>
<Tooltip
title={button.tooltip}
enterDelay={tooltipEnterDelay}
placement="top"
>
<button
className={classNames({
[classes.compactToggleButton]: true,
[classes.first]: index === 0,
[classes.last]: index === buttons.length - 1,
[classes.active]: button.isActive,
})}
onClick={button.onClick}
>
{button.renderIcon(classes.icon)}
{button.label && (
<span className={classes.label}>{button.label}</span>
)}
</button>
</Tooltip>
{index < buttons.length - 1 && !noSeparator && (
<div
key={`spacer-${index}`}
className={classNames({
[classes.separator]: true,
})}
/>
)}
</React.Fragment>
))}
</div>
);
};
export default CompactToggleButtons;