File size: 1,085 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
38
39
40
41
42
43
44
45
46
47
48
49
import { Box, HStack, Text } from "@chakra-ui/react"
import type { CodeLang } from "./code-lang-icon"
import { CodeLangIcon } from "./code-lang-icon"

interface CodeBlockProps {
  title?: string
  lang?: CodeLang
  children: React.ReactNode
  [key: string]: any
}

export const CodeBlock = (props: CodeBlockProps) => {
  const { title, lang, children, ...rest } = props
  return (
    <Box
      {...rest}
      data-lang={lang}
      spaceY="0!"
      marginY="1.6em"
      borderWidth="1px"
      rounded="10px"
      borderColor="gray.800"
      css={{
        "& pre.shiki": {
          roundedTop: "0!",
          roundedBottom: "lg!",
          shadow: "none!",
        },
      }}
    >
      <HStack
        bg="#1E1E1E"
        px="4"
        py="3"
        color="gray.300"
        roundedTop="lg"
        borderBottomWidth="1px"
        borderBottomColor="gray.800"
      >
        {lang && <CodeLangIcon type={lang} />}
        <Text fontSize="xs" fontFamily="mono" fontWeight="semibold">
          {title}
        </Text>
      </HStack>
      {children}
    </Box>
  )
}