You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

104 regels
2.8 KiB

  1. import PropTypes from 'prop-types';
  2. import { forwardRef } from 'react';
  3. // material-ui
  4. import { useTheme } from '@mui/material/styles';
  5. import { Card, CardContent, CardHeader, Divider, Typography } from '@mui/material';
  6. // project import
  7. import Highlighter from './third-party/Highlighter';
  8. // header style
  9. const headerSX = {
  10. p: 2.5,
  11. '& .MuiCardHeader-action': { m: '0px auto', alignSelf: 'center' }
  12. };
  13. // ==============================|| CUSTOM - MAIN CARD ||============================== //
  14. const MainCard = forwardRef(
  15. (
  16. {
  17. border = true,
  18. boxShadow,
  19. children,
  20. content = true,
  21. contentSX = {},
  22. darkTitle,
  23. elevation,
  24. secondary,
  25. shadow,
  26. sx = {},
  27. title,
  28. codeHighlight,
  29. ...others
  30. },
  31. ref
  32. ) => {
  33. const theme = useTheme();
  34. boxShadow = theme.palette.mode === 'dark' ? boxShadow || true : boxShadow;
  35. return (
  36. <Card
  37. elevation={elevation || 0}
  38. ref={ref}
  39. {...others}
  40. sx={{
  41. border: border ? '1px solid' : 'none',
  42. borderRadius: 2,
  43. borderColor: theme.palette.mode === 'dark' ? theme.palette.divider : theme.palette.grey.A800,
  44. boxShadow: boxShadow && (!border || theme.palette.mode === 'dark') ? shadow || theme.customShadows.z1 : 'inherit',
  45. ':hover': {
  46. boxShadow: boxShadow ? shadow || theme.customShadows.z1 : 'inherit'
  47. },
  48. '& pre': {
  49. m: 0,
  50. p: '16px !important',
  51. fontFamily: theme.typography.fontFamily,
  52. fontSize: '0.75rem'
  53. },
  54. ...sx
  55. }}
  56. >
  57. {/* card header and action */}
  58. {!darkTitle && title && (
  59. <CardHeader sx={headerSX} titleTypographyProps={{ variant: 'subtitle1' }} title={title} action={secondary} />
  60. )}
  61. {darkTitle && title && <CardHeader sx={headerSX} title={<Typography variant="h3">{title}</Typography>} action={secondary} />}
  62. {/* card content */}
  63. {content && <CardContent sx={contentSX}>{children}</CardContent>}
  64. {!content && children}
  65. {/* card footer - clipboard & highlighter */}
  66. {codeHighlight && (
  67. <>
  68. <Divider sx={{ borderStyle: 'dashed' }} />
  69. <Highlighter codeHighlight={codeHighlight} main>
  70. {children}
  71. </Highlighter>
  72. </>
  73. )}
  74. </Card>
  75. );
  76. }
  77. );
  78. MainCard.propTypes = {
  79. border: PropTypes.bool,
  80. boxShadow: PropTypes.bool,
  81. contentSX: PropTypes.object,
  82. darkTitle: PropTypes.bool,
  83. divider: PropTypes.bool,
  84. elevation: PropTypes.number,
  85. secondary: PropTypes.node,
  86. shadow: PropTypes.string,
  87. sx: PropTypes.object,
  88. title: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
  89. codeHighlight: PropTypes.bool,
  90. content: PropTypes.bool,
  91. children: PropTypes.node
  92. };
  93. export default MainCard;