File size: 853 Bytes
e7abd9e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import React from 'react';
import { Box, IconButton } from '@mui/material';
import ContentCopyIcon from '@mui/icons-material/ContentCopy';

const CodeBlock = ({ code }) => (
  <Box sx={{ position: 'relative' }}>
    <IconButton
      onClick={() => navigator.clipboard.writeText(code)}
      sx={{
        position: 'absolute',
        top: 8,
        right: 8,
        color: 'grey.500',
        '&:hover': { color: 'grey.300' },
      }}
    >
      <ContentCopyIcon fontSize="small" />
    </IconButton>
    <Box
      sx={{
        backgroundColor: 'grey.900',
        color: 'grey.100',
        p: 2,
        borderRadius: 1,
        fontFamily: 'monospace',
        fontSize: '0.875rem',
        overflowX: 'auto',
        textAlign: 'left',
        whiteSpace: 'pre',
      }}
    >
      {code}
    </Box>
  </Box>
);

export default CodeBlock;