Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

Drawer.tsx 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import { makeStyles } from '@material-ui/core';
  2. import React, { ReactElement, useCallback } from 'react';
  3. import { DRAWER_MAX_HEIGHT } from '../../constants';
  4. type Props = {
  5. /**
  6. * The component(s) to be displayed within the drawer menu.
  7. */
  8. children: ReactElement,
  9. /**
  10. * Class name for custom styles.
  11. */
  12. className?: string,
  13. /**
  14. * Whether the drawer should be shown or not.
  15. */
  16. isOpen: boolean,
  17. /**
  18. * Function that hides the drawer.
  19. */
  20. onClose: Function
  21. };
  22. const useStyles = makeStyles((theme: any) => {
  23. return {
  24. drawer: {
  25. backgroundColor: theme.palette.ui02,
  26. maxHeight: `calc(${DRAWER_MAX_HEIGHT})`
  27. }
  28. };
  29. });
  30. /**
  31. * Component that displays the mobile friendly drawer on web.
  32. *
  33. * @returns {ReactElement}
  34. */
  35. function Drawer({
  36. children,
  37. className = '',
  38. isOpen,
  39. onClose
  40. }: Props) {
  41. const styles = useStyles();
  42. /**
  43. * Handles clicks within the menu, preventing the propagation of the click event.
  44. *
  45. * @param {Object} event - The click event.
  46. * @returns {void}
  47. */
  48. const handleInsideClick = useCallback(event => {
  49. event.stopPropagation();
  50. }, []);
  51. /**
  52. * Handles clicks outside of the menu, closing it, and also stopping further propagation.
  53. *
  54. * @param {Object} event - The click event.
  55. * @returns {void}
  56. */
  57. const handleOutsideClick = useCallback(event => {
  58. event.stopPropagation();
  59. onClose();
  60. }, [ onClose ]);
  61. return (
  62. isOpen ? (
  63. <div
  64. className = 'drawer-menu-container'
  65. onClick = { handleOutsideClick }>
  66. <div
  67. className = { `drawer-menu ${styles.drawer} ${className}` }
  68. onClick = { handleInsideClick }>
  69. {children}
  70. </div>
  71. </div>
  72. ) : null
  73. );
  74. }
  75. export default Drawer;