CodeView.tsx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import { Theme, Typography } from '@mui/material';
  2. import { FC } from 'react';
  3. import { useTranslation } from 'react-i18next';
  4. import CustomTabList from '../customTabList/CustomTabList';
  5. import { ITab } from '../customTabList/Types';
  6. import CodeBlock from './CodeBlock';
  7. import { CodeViewProps } from './Types';
  8. import { makeStyles } from '@mui/styles';
  9. const getStyles = makeStyles((theme: Theme) => ({
  10. wrapper: {
  11. boxSizing: 'border-box',
  12. width: '100%',
  13. padding: theme.spacing(4),
  14. backgroundColor: theme.palette.attuDark.main,
  15. display: 'flex',
  16. flexDirection: 'column',
  17. color: '#fff',
  18. },
  19. title: {
  20. marginBottom: theme.spacing(2),
  21. },
  22. // override tab list style
  23. tabs: {
  24. minHeight: 0,
  25. '& .MuiTab-wrapper': {
  26. fontWeight: 'bold',
  27. color: '#fff',
  28. },
  29. '& .MuiTab-root': {
  30. minHeight: 18,
  31. marginRight: 0,
  32. },
  33. // disable Ripple Effect
  34. '& .MuiTouchRipple-root': {
  35. display: 'none',
  36. },
  37. '& .Mui-selected': {
  38. '& .MuiTab-wrapper': {
  39. color: theme.palette.primary.main,
  40. },
  41. },
  42. '& .MuiTabs-indicator': {
  43. display: 'flex',
  44. justifyContent: 'center',
  45. top: 32,
  46. backgroundColor: 'transparent',
  47. '& .tab-indicator': {
  48. height: 1,
  49. width: '100%',
  50. maxWidth: 26,
  51. backgroundColor: theme.palette.primary.main,
  52. },
  53. },
  54. '& .MuiTabs-flexContainer': {
  55. borderBottom: 'none',
  56. },
  57. },
  58. block: {
  59. height: `calc(100% - ${theme.spacing(4.5)})`,
  60. overflowY: 'auto',
  61. },
  62. }));
  63. const CodeView: FC<CodeViewProps> = ({ wrapperClass = '', data }) => {
  64. const classes = getStyles();
  65. const { t: commonTrans } = useTranslation();
  66. const tabs: ITab[] = data.map(item => ({
  67. label: item.label,
  68. component: (
  69. <CodeBlock
  70. wrapperClass={classes.block}
  71. language={item.language}
  72. code={item.code}
  73. />
  74. ),
  75. }));
  76. return (
  77. <section className={`${classes.wrapper} ${wrapperClass}`}>
  78. <Typography variant="h5" className={classes.title}>
  79. {commonTrans('code')}
  80. </Typography>
  81. <CustomTabList tabs={tabs} wrapperClass={classes.tabs} />
  82. </section>
  83. );
  84. };
  85. export default CodeView;