Wrapper.tsx 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import { useTranslation } from 'react-i18next';
  2. import Box from '@mui/material/Box';
  3. import React from 'react';
  4. import type { SxProps, Theme } from '@mui/material';
  5. interface WrapperProps {
  6. hasPermission?: boolean;
  7. children?: React.ReactNode;
  8. className?: string;
  9. style?: React.CSSProperties;
  10. sx?: SxProps<Theme>;
  11. }
  12. const Wrapper = ({
  13. hasPermission = true,
  14. children,
  15. className,
  16. style,
  17. sx,
  18. }: WrapperProps) => {
  19. const { t } = useTranslation();
  20. return (
  21. <Box
  22. className={className}
  23. style={style}
  24. sx={{
  25. width: '100%',
  26. height: '100%',
  27. position: 'relative',
  28. ...((Array.isArray(sx) ? Object.assign({}, ...sx) : sx) || {}),
  29. }}
  30. >
  31. {children}
  32. {!hasPermission && (
  33. <Box
  34. sx={{
  35. position: 'absolute',
  36. top: 0,
  37. left: 0,
  38. right: 0,
  39. bottom: 0,
  40. display: 'flex',
  41. alignItems: 'center',
  42. justifyContent: 'center',
  43. bgcolor: 'background.default',
  44. zIndex: 1000,
  45. }}
  46. >
  47. <Box
  48. sx={{
  49. fontSize: 14,
  50. color: 'text.primary',
  51. textAlign: 'center',
  52. fontStyle: 'italic',
  53. }}
  54. >
  55. {t('noPermissionTip')}
  56. </Box>
  57. </Box>
  58. )}
  59. </Box>
  60. );
  61. };
  62. export default Wrapper;