Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

Drawer.tsx 2.0KB

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