feat: add copy button to code component

This commit is contained in:
Khairul Hidayat 2024-08-17 01:00:17 +07:00
parent fb02d273c2
commit 61a07068d5
2 changed files with 18 additions and 6 deletions

View File

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

View File

@ -59,7 +59,7 @@ const ConnectNodeDialog = () => {
>
<Modal.Header>Connect Node</Modal.Header>
<Modal.Body>
<p>Run this command to get node id:</p>
<p>Run this command in your target node to get node id:</p>
<Code className="mt-2">docker exec garage /garage node id</Code>
<p className="mt-8">Enter node id:</p>