Source: Dialog/index.tsx

  1. import React, { ReactNode } from 'react';
  2. import styles from './dialog.module.css';
  3. import { clx } from '@/helpers';
  4. type Props = {
  5. dialogRef?: React.RefObject<HTMLDivElement>;
  6. className?: string;
  7. open?: boolean;
  8. withPadding?: boolean;
  9. modalMode?: boolean;
  10. header?: ReactNode;
  11. body?: ReactNode;
  12. footer?: ReactNode;
  13. large?: boolean;
  14. };
  15. /**
  16. * @example
  17. * <Dialog
  18. * dialogRef={dialogRef}
  19. * open={open}
  20. * withPadding={withPadding}
  21. * modalMode={modalMode}
  22. * header={<h1>Header</h1>}
  23. * body={<p>Body</p>}
  24. * footer={<button>Footer</button>}
  25. * large={large}
  26. * />;
  27. *
  28. * @param {React.RefObject<HTMLDivElement>} dialogRef - Ref to the dialog element
  29. * @param {boolean} open - If true, the dialog will be open
  30. * @param {boolean} withPadding - If true, the dialog will have padding
  31. * @param {boolean} modalMode - If true, the dialog will be not complete screen
  32. * @param {ReactNode} header - The header of the dialog
  33. * @param {ReactNode} body - The body of the dialog
  34. * @param {ReactNode} footer - The footer of the dialog
  35. * @param {boolean} large - If true, the dialog will be large
  36. * @returns {JSX.Element}
  37. */
  38. const Dialog = (props: Props) => {
  39. const {
  40. dialogRef,
  41. className,
  42. open,
  43. large,
  44. withPadding,
  45. modalMode,
  46. header = <></>,
  47. body = <></>,
  48. footer = <></>,
  49. } = props;
  50. return (
  51. <div
  52. ref={dialogRef}
  53. data-testid="dialog"
  54. className={clx(
  55. className,
  56. styles.dialog,
  57. open ? styles.open : '',
  58. withPadding ? styles.padding : '',
  59. modalMode ? styles.modalMode : '',
  60. large ? styles.large : ''
  61. )}
  62. >
  63. <header data-testid="dialog-header">{header}</header>
  64. <main className={styles.body} data-testid="dialog-body">
  65. {body}
  66. </main>
  67. <footer data-testid="dialog-footer">{footer}</footer>
  68. </div>
  69. );
  70. };
  71. export default Dialog;