index.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import React, { useState, useRef } from "react";
  2. import Popover from "@material-ui/core/Popover";
  3. import IconButton from "@material-ui/core/IconButton";
  4. import List from "@material-ui/core/List";
  5. import { makeStyles } from "@material-ui/core/styles";
  6. import VolumeUpIcon from "@material-ui/icons/VolumeUp";
  7. import VolumeDownIcon from "@material-ui/icons/VolumeDown";
  8. import { Grid, Slider } from "@material-ui/core";
  9. const useStyles = makeStyles((theme) => ({
  10. tabContainer: {
  11. padding: theme.spacing(2),
  12. },
  13. popoverPaper: {
  14. width: "100%",
  15. maxWidth: 350,
  16. marginLeft: theme.spacing(2),
  17. marginRight: theme.spacing(1),
  18. [theme.breakpoints.down("sm")]: {
  19. maxWidth: 270,
  20. },
  21. },
  22. noShadow: {
  23. boxShadow: "none !important",
  24. },
  25. icons: {
  26. color: "#fff",
  27. },
  28. customBadge: {
  29. backgroundColor: "#f44336",
  30. color: "#fff",
  31. },
  32. }));
  33. const NotificationsVolume = ({ volume, setVolume }) => {
  34. const classes = useStyles();
  35. const anchorEl = useRef();
  36. const [isOpen, setIsOpen] = useState(false);
  37. const handleClick = () => {
  38. setIsOpen((prevState) => !prevState);
  39. };
  40. const handleClickAway = () => {
  41. setIsOpen(false);
  42. };
  43. const handleVolumeChange = (value) => {
  44. setVolume(value);
  45. localStorage.setItem("volume", value);
  46. };
  47. return (
  48. <>
  49. <IconButton
  50. className={classes.icons}
  51. onClick={handleClick}
  52. ref={anchorEl}
  53. aria-label="Open Notifications"
  54. // color="inherit"
  55. // color="secondary"
  56. >
  57. <VolumeUpIcon color="inherit" />
  58. </IconButton>
  59. <Popover
  60. disableScrollLock
  61. open={isOpen}
  62. anchorEl={anchorEl.current}
  63. anchorOrigin={{
  64. vertical: "bottom",
  65. horizontal: "right",
  66. }}
  67. transformOrigin={{
  68. vertical: "top",
  69. horizontal: "right",
  70. }}
  71. classes={{ paper: classes.popoverPaper }}
  72. onClose={handleClickAway}
  73. >
  74. <List dense className={classes.tabContainer}>
  75. <Grid container spacing={2}>
  76. <Grid item>
  77. <VolumeDownIcon />
  78. </Grid>
  79. <Grid item xs>
  80. <Slider
  81. value={volume}
  82. aria-labelledby="continuous-slider"
  83. step={0.1}
  84. min={0}
  85. max={1}
  86. onChange={(e, value) =>
  87. handleVolumeChange(value)
  88. }
  89. />
  90. </Grid>
  91. <Grid item>
  92. <VolumeUpIcon />
  93. </Grid>
  94. </Grid>
  95. </List>
  96. </Popover>
  97. </>
  98. );
  99. };
  100. export default NotificationsVolume;