ProxmoxVE/frontend/src/components/TextCopyBlock.tsx
2024-11-04 23:55:08 +01:00

29 lines
735 B
TypeScript

import { ClipboardIcon } from "lucide-react";
import handleCopy from "./handleCopy";
export default function TextCopyBlock(description: string) {
const pattern = /`([^`]*)`/g;
const parts = description.split(pattern);
const formattedDescription = parts.map((part: string, index: number) => {
if (index % 2 === 1) {
return (
<span
key={index}
className="bg-secondary py-1 px-2 rounded-lg inline-flex items-center gap-2"
>
{part}
<ClipboardIcon
className="size-3 cursor-pointer"
onClick={() => handleCopy("command", part)}
/>
</span>
);
} else {
return part;
}
});
return formattedDescription;
}