No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

MainCard.js 3.8 KiB

hace 3 años
hace 3 meses
hace 3 años
hace 2 años
hace 3 años
hace 3 meses
hace 3 años
hace 3 meses
hace 3 años
hace 2 años
hace 3 años
hace 2 años
hace 3 meses
hace 2 años
hace 2 años
hace 2 años
hace 2 años
hace 3 años
hace 2 años
hace 3 años
hace 2 años
hace 3 años
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. import PropTypes from 'prop-types';
  2. import { forwardRef } from 'react';
  3. import omit from 'lodash/omit';
  4. // material-ui
  5. import { useTheme } from '@mui/material/styles';
  6. import { Card, CardContent, CardHeader, Divider, Typography, Grid } from '@mui/material';
  7. // project import
  8. import Highlighter from './third-party/Highlighter';
  9. /** Props often mistaken for Card / Grid / sx — must not reach the underlying DOM node via `{...others}`. */
  10. const PROPS_OMIT_FROM_CARD = [
  11. 'backgroundColor',
  12. 'bgcolor',
  13. 'xs',
  14. 'sm',
  15. 'md',
  16. 'lg',
  17. 'xl',
  18. 'item',
  19. 'container',
  20. 'spacing',
  21. 'direction',
  22. 'justify',
  23. 'alignItems',
  24. 'alignContent',
  25. 'flexWrap',
  26. 'wrap',
  27. 'zeroMinWidth',
  28. 'rowSpacing',
  29. 'columnSpacing'
  30. ];
  31. // header style
  32. const headerSX = {
  33. p: 2.5,
  34. '& .MuiCardHeader-action': { m: '0px auto', alignSelf: 'center' }
  35. };
  36. // ==============================|| CUSTOM - MAIN CARD ||============================== //
  37. const MainCard = forwardRef(
  38. (
  39. {
  40. border = true,
  41. boxShadow,
  42. children,
  43. content = true,
  44. contentSX = {},
  45. darkTitle,
  46. elevation,
  47. secondary,
  48. shadow,
  49. sx = {},
  50. title,
  51. codeHighlight,
  52. ...others
  53. },
  54. ref
  55. ) => {
  56. const theme = useTheme();
  57. boxShadow = theme.palette.mode === 'dark' ? boxShadow || true : boxShadow;
  58. const cardProps = omit(others, PROPS_OMIT_FROM_CARD);
  59. return (
  60. <Grid container direction="column"
  61. // alignItems="center"
  62. // justify="center"
  63. >
  64. <Card
  65. elevation={elevation || 0}
  66. ref={ref}
  67. {...cardProps}
  68. sx={{
  69. alignItems: "center",
  70. border: border ? '1px solid' : 'none',
  71. borderRadius: 2,
  72. borderColor: theme.palette.mode === 'dark' ? theme.palette.divider : theme.palette.grey.A800,
  73. boxShadow: boxShadow && (!border || theme.palette.mode === 'dark') ? shadow || theme.customShadows.z1 : 'inherit',
  74. ':hover': {
  75. boxShadow: boxShadow ? shadow || theme.customShadows.z1 : 'inherit'
  76. },
  77. '& pre': {
  78. m: 0,
  79. p: '16px !important',
  80. fontFamily: theme.typography.fontFamily,
  81. fontSize: '0.75rem'
  82. },
  83. // maxWidth: { xs: 700, sm: 900, md: 1000, lg: 1300, xl: 1850 },
  84. // minWidth: { xs: 600, sm: 800, md: 900, lg: 1000, xl: 1000 },
  85. margin: { xs: 2, md: 2 },
  86. // '& > *': {
  87. // flexGrow: 1,
  88. // flexBasis: '50%'
  89. // },
  90. ...sx
  91. }}
  92. >
  93. {/* card header and action */}
  94. {!darkTitle && title && (
  95. <CardHeader sx={headerSX} titleTypographyProps={{ variant: 'subtitle1' }} title={title} action={secondary} />
  96. )}
  97. {darkTitle && title && <CardHeader sx={headerSX} title={<Typography variant="h3">{title}</Typography>} action={secondary} />}
  98. {/* card content */}
  99. {content && <CardContent sx={contentSX}>{children}</CardContent>}
  100. {!content && children}
  101. {/* card footer - clipboard & highlighter */}
  102. {codeHighlight && (
  103. <>
  104. <Divider sx={{ borderStyle: 'dashed' }} />
  105. <Highlighter codeHighlight={codeHighlight} main>
  106. {children}
  107. </Highlighter>
  108. </>
  109. )}
  110. </Card></Grid>
  111. );
  112. }
  113. );
  114. MainCard.propTypes = {
  115. border: PropTypes.bool,
  116. boxShadow: PropTypes.bool,
  117. contentSX: PropTypes.object,
  118. darkTitle: PropTypes.bool,
  119. divider: PropTypes.bool,
  120. elevation: PropTypes.number,
  121. secondary: PropTypes.node,
  122. shadow: PropTypes.string,
  123. sx: PropTypes.object,
  124. title: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
  125. codeHighlight: PropTypes.bool,
  126. content: PropTypes.bool,
  127. children: PropTypes.node
  128. };
  129. export default MainCard;