The Node.js® Website
1import type { FC, PropsWithChildren } from 'react';
2
3import CodeBox from '@/components/Common/CodeBox';
4import { getLanguageDisplayName } from '@/util/getLanguageDisplayName';
5
6type CodeBoxProps = { className?: string; showCopyButton?: string };
7
8const MDXCodeBox: FC<PropsWithChildren<CodeBoxProps>> = ({
9 children: code,
10 className,
11 showCopyButton,
12}) => {
13 const matches = className?.match(/language-(?<language>.*)/);
14 const language = matches?.groups?.language ?? '';
15
16 return (
17 <CodeBox
18 language={getLanguageDisplayName(language)}
19 showCopyButton={showCopyButton ? showCopyButton === 'true' : undefined}
20 >
21 {code}
22 </CodeBox>
23 );
24};
25
26export default MDXCodeBox;