2
0

CustomDialogTitle.tsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { DialogTitleProps, Typography } from '@mui/material';
  2. import MuiDialogTitle from '@mui/material/DialogTitle';
  3. import icons from '../icons/Icons';
  4. import { theme } from '../../styles/theme';
  5. import { makeStyles } from '@mui/styles';
  6. const getStyles = makeStyles(() => ({
  7. root: {
  8. display: 'flex',
  9. justifyContent: 'space-between',
  10. alignItems: 'center',
  11. marginBottom: 8,
  12. paddingTop: 32,
  13. },
  14. title: {
  15. fontWeight: 500,
  16. wordBreak: 'break-all',
  17. fontSize: '20px',
  18. },
  19. icon: {
  20. fontSize: '18px',
  21. color: theme.palette.attuDark.main,
  22. cursor: 'pointer',
  23. },
  24. }));
  25. interface IProps extends DialogTitleProps {
  26. onClose?: () => void;
  27. showCloseIcon?: boolean;
  28. }
  29. const CustomDialogTitle = (props: IProps) => {
  30. const {
  31. children,
  32. classes = { root: '' },
  33. onClose,
  34. showCloseIcon = true,
  35. ...other
  36. } = props;
  37. const innerClass = getStyles();
  38. const ClearIcon = icons.clear;
  39. return (
  40. <MuiDialogTitle className={`${innerClass.root} ${classes.root}`} {...other}>
  41. <Typography variant="body2" className={innerClass.title}>
  42. {children}
  43. </Typography>
  44. {showCloseIcon && onClose ? (
  45. <ClearIcon
  46. data-testid="clear-icon"
  47. classes={{ root: innerClass.icon }}
  48. onClick={onClose}
  49. />
  50. ) : null}
  51. </MuiDialogTitle>
  52. );
  53. };
  54. export default CustomDialogTitle;