import { Check, Copy } from "lucide-react"; import React, { DetailedHTMLProps, HTMLAttributes, PropsWithChildren, } from "react"; import { twMerge } from "tailwind-merge"; import Stack from "../layout/Stack"; import Row from "../layout/Row"; import Button from "../layout/Button"; import Divider from "../layout/Divider"; export const TWUIPrismLanguages = ["shell", "javascript"] as const; type Props = PropsWithChildren & DetailedHTMLProps, HTMLPreElement> & { wrapperProps?: DetailedHTMLProps< HTMLAttributes, HTMLDivElement >; "data-title"?: string; backgroundColor?: string; singleBlock?: boolean; language?: (typeof TWUIPrismLanguages)[number]; }; /** * # CodeBlock * * @className `twui-code-block-wrapper` * @className `twui-code-pre-wrapper` * @className `twui-code-block-pre` * @className `twui-code-block-header` */ export default function CodeBlock({ children, wrapperProps, backgroundColor, singleBlock, language, ...props }: Props) { const codeRef = React.useRef(); const [copied, setCopied] = React.useState(false); const title = props?.["data-title"]; const finalBackgroundColor = backgroundColor || "#28272b"; return (
{title && {title}}
{copied ? ( Copied!
) : (
{!singleBlock && ( )}
                        {children}
                    
); }