Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

Drawer.js 1.8KB

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