-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
/
BadgeVisibility.tsx
72 lines (68 loc) · 1.97 KB
/
BadgeVisibility.tsx
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
import React from 'react';
import { Theme, createStyles, makeStyles } from '@material-ui/core/styles';
import Badge from '@material-ui/core/Badge';
import ButtonGroup from '@material-ui/core/ButtonGroup';
import Button from '@material-ui/core/Button';
import AddIcon from '@material-ui/icons/Add';
import RemoveIcon from '@material-ui/icons/Remove';
import MailIcon from '@material-ui/icons/Mail';
import Switch from '@material-ui/core/Switch';
import FormControlLabel from '@material-ui/core/FormControlLabel';
const useStyles = makeStyles((theme: Theme) =>
createStyles({
root: {
display: 'flex',
flexDirection: 'column',
'& > *': {
marginBottom: theme.spacing(2),
},
'& .MuiBadge-root': {
marginRight: theme.spacing(4),
},
},
}),
);
export default function BadgeVisibility() {
const classes = useStyles();
const [count, setCount] = React.useState(1);
const [invisible, setInvisible] = React.useState(false);
const handleBadgeVisibility = () => {
setInvisible(!invisible);
};
return (
<div className={classes.root}>
<div>
<Badge color="secondary" badgeContent={count}>
<MailIcon />
</Badge>
<ButtonGroup>
<Button
aria-label="reduce"
onClick={() => {
setCount(Math.max(count - 1, 0));
}}
>
<RemoveIcon fontSize="small" />
</Button>
<Button
aria-label="increase"
onClick={() => {
setCount(count + 1);
}}
>
<AddIcon fontSize="small" />
</Button>
</ButtonGroup>
</div>
<div>
<Badge color="secondary" variant="dot" invisible={invisible}>
<MailIcon />
</Badge>
<FormControlLabel
control={<Switch color="primary" checked={!invisible} onChange={handleBadgeVisibility} />}
label="Show Badge"
/>
</div>
</div>
);
}