Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 

116 řádky
3.3 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, Grid } 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. <Grid container direction="column"
  37. // alignItems="center"
  38. // justify="center"
  39. >
  40. <Card
  41. elevation={elevation || 0}
  42. ref={ref}
  43. {...others}
  44. sx={{
  45. alignItems: "center",
  46. border: border ? '1px solid' : 'none',
  47. borderRadius: 2,
  48. borderColor: theme.palette.mode === 'dark' ? theme.palette.divider : theme.palette.grey.A800,
  49. boxShadow: boxShadow && (!border || theme.palette.mode === 'dark') ? shadow || theme.customShadows.z1 : 'inherit',
  50. ':hover': {
  51. boxShadow: boxShadow ? shadow || theme.customShadows.z1 : 'inherit'
  52. },
  53. '& pre': {
  54. m: 0,
  55. p: '16px !important',
  56. fontFamily: theme.typography.fontFamily,
  57. fontSize: '0.75rem'
  58. },
  59. // maxWidth: { xs: 700, sm: 900, md: 1000, lg: 1300, xl: 1850 },
  60. // minWidth: { xs: 600, sm: 800, md: 900, lg: 1000, xl: 1000 },
  61. margin: { xs: 2, md: 2 },
  62. // '& > *': {
  63. // flexGrow: 1,
  64. // flexBasis: '50%'
  65. // },
  66. ...sx
  67. }}
  68. >
  69. {/* card header and action */}
  70. {!darkTitle && title && (
  71. <CardHeader sx={headerSX} titleTypographyProps={{ variant: 'subtitle1' }} title={title} action={secondary} />
  72. )}
  73. {darkTitle && title && <CardHeader sx={headerSX} title={<Typography variant="h3">{title}</Typography>} action={secondary} />}
  74. {/* card content */}
  75. {content && <CardContent sx={contentSX}>{children}</CardContent>}
  76. {!content && children}
  77. {/* card footer - clipboard & highlighter */}
  78. {codeHighlight && (
  79. <>
  80. <Divider sx={{ borderStyle: 'dashed' }} />
  81. <Highlighter codeHighlight={codeHighlight} main>
  82. {children}
  83. </Highlighter>
  84. </>
  85. )}
  86. </Card></Grid>
  87. );
  88. }
  89. );
  90. MainCard.propTypes = {
  91. border: PropTypes.bool,
  92. boxShadow: PropTypes.bool,
  93. contentSX: PropTypes.object,
  94. darkTitle: PropTypes.bool,
  95. divider: PropTypes.bool,
  96. elevation: PropTypes.number,
  97. secondary: PropTypes.node,
  98. shadow: PropTypes.string,
  99. sx: PropTypes.object,
  100. title: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
  101. codeHighlight: PropTypes.bool,
  102. content: PropTypes.bool,
  103. children: PropTypes.node
  104. };
  105. export default MainCard;