31 lines
709 B
TypeScript
Raw Normal View History

import { cn, copyToClipboard } from "@/lib/utils";
2024-08-14 15:36:25 +07:00
import React from "react";
import Button from "./button";
import { Copy } from "lucide-react";
2024-08-14 15:36:25 +07:00
type Props = Omit<React.ComponentPropsWithoutRef<"code">, "children"> & {
children?: string;
};
2024-08-14 15:36:25 +07:00
const Code = ({ className, children, ...props }: Props) => {
2024-08-14 15:36:25 +07:00
return (
<code
className={cn(
"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}
>
{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;