import { CheckIcon, CopyIcon } from 'lucide-react'; import { useState } from 'react'; import { Button } from '#/components/atoms/button.jsx'; import { cn } from '#/lib/utils.js'; /** * A shell command with a copy button beside it. The command is what a reader * came for, so it reads in full where there is room and truncates where there * is not. `lines` draws several commands as one block, each on its own * line, and copies them joined by newlines the way a shell takes them. * @param {{command?: string, lines?: string[], label?: string, className?: string}} props */ export function CopyCommand({ command, lines, label, className }) { const [copied, setCopied] = useState(false); const text = lines ? lines.join('\n') : (command ?? ''); const copy = async () => { await navigator.clipboard.writeText(text); setCopied(true); setTimeout(() => setCopied(false), 1600); }; if (lines) { return (
{text}
{text}