CustomDialogTitle.tsx 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import {
  2. DialogTitleProps,
  3. makeStyles,
  4. Theme,
  5. Typography,
  6. } from '@material-ui/core';
  7. import MuiDialogTitle from '@material-ui/core/DialogTitle';
  8. import icons from '../icons/Icons';
  9. const getStyles = makeStyles((theme: Theme) => ({
  10. root: {
  11. margin: 0,
  12. display: 'flex',
  13. justifyContent: 'space-between',
  14. alignItems: 'center',
  15. },
  16. title: {
  17. fontWeight: 500,
  18. },
  19. icon: {
  20. fontSize: '24px',
  21. color: theme.palette.milvusDark.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
  41. disableTypography
  42. className={`${innerClass.root} ${classes.root}`}
  43. {...other}
  44. >
  45. <Typography variant="h4" className={innerClass.title}>
  46. {children}
  47. </Typography>
  48. {showCloseIcon && onClose ? (
  49. <ClearIcon
  50. data-testid="clear-icon"
  51. classes={{ root: innerClass.icon }}
  52. onClick={onClose}
  53. />
  54. ) : null}
  55. </MuiDialogTitle>
  56. );
  57. };
  58. export default CustomDialogTitle;