diff --git a/apps/web/components/command-block/command-block.tsx b/apps/web/components/command-block/command-block.tsx new file mode 100644 index 0000000..69796d5 --- /dev/null +++ b/apps/web/components/command-block/command-block.tsx @@ -0,0 +1,60 @@ +"use client" + +import { useState } from "react" + +interface CommandBlockProps { + code: string + label?: string + showCopy?: boolean + /** + * Override the default "Copy" / "Copied" label pair (e.g. for localized + * UI). The function receives the current state and returns the label. + */ + copyLabel?: (state: "idle" | "copied") => string +} + +export function CommandBlock({ + code, + label = "bash", + showCopy = true, + copyLabel, +}: CommandBlockProps) { + const [copied, setCopied] = useState(false) + + const onCopy = async () => { + try { + await navigator.clipboard.writeText(code) + setCopied(true) + window.setTimeout(() => setCopied(false), 1500) + } catch { + // Clipboard API can fail in non-secure contexts; silently ignore — + // the user can still select-and-copy manually. + } + } + + return ( +
+ {code}
+
+ URL mode — works against the deployed showcase site:
-Namespace mode — register once, then any item by short name:
-