2024-08-17 01:00:17 +07:00
|
|
|
import { cn, copyToClipboard } from "@/lib/utils";
|
2024-08-14 15:36:25 +07:00
|
|
|
import React from "react";
|
2024-08-17 01:00:17 +07:00
|
|
|
import Button from "./button";
|
|
|
|
import { Copy } from "lucide-react";
|
2024-08-14 15:36:25 +07:00
|
|
|
|
2024-08-17 01:00:17 +07:00
|
|
|
type Props = Omit<React.ComponentPropsWithoutRef<"code">, "children"> & {
|
|
|
|
children?: string;
|
|
|
|
};
|
2024-08-14 15:36:25 +07:00
|
|
|
|
2024-08-17 01:00:17 +07:00
|
|
|
const Code = ({ className, children, ...props }: Props) => {
|
2024-08-14 15:36:25 +07:00
|
|
|
return (
|
|
|
|
<code
|
|
|
|
className={cn(
|
2024-08-17 01:00:17 +07:00
|
|
|
"border border-base-content/20 px-4 py-3 rounded-lg font-mono block relative",
|
2024-08-14 15:36:25 +07:00
|
|
|
className
|
|
|
|
)}
|
|
|
|
{...props}
|
2024-08-17 01:00:17 +07:00
|
|
|
>
|
|
|
|
{children}
|
|
|
|
<Button
|
|
|
|
icon={Copy}
|
|
|
|
className="absolute right-0 top-0"
|
|
|
|
color="ghost"
|
|
|
|
onClick={() => copyToClipboard(children || "")}
|
|
|
|
/>
|
|
|
|
</code>
|
2024-08-14 15:36:25 +07:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Code;
|