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 ( +
+
+ + {label} + + {showCopy && ( + + )} +
+
+        {code}
+      
+
+ ) +} diff --git a/apps/web/components/command-block/index.ts b/apps/web/components/command-block/index.ts new file mode 100644 index 0000000..7bcfe17 --- /dev/null +++ b/apps/web/components/command-block/index.ts @@ -0,0 +1 @@ +export { CommandBlock } from "./command-block" diff --git a/apps/web/components/install-command/install-command.tsx b/apps/web/components/install-command/install-command.tsx index 3d288c0..784829d 100644 --- a/apps/web/components/install-command/install-command.tsx +++ b/apps/web/components/install-command/install-command.tsx @@ -1,4 +1,4 @@ -import { CodeBlock } from "@/components/code-block" +import { CommandBlock } from "@/components/command-block" interface InstallCommandProps { itemId: string @@ -20,7 +20,7 @@ export function InstallCommand({ itemId }: InstallCommandProps) { Add this component to your project with the shadcn CLI. Pick the mode that matches how you installed the registry.

- +
Other install modes @@ -30,14 +30,14 @@ export function InstallCommand({ itemId }: InstallCommandProps) {

URL mode — works against the deployed showcase site:

- +

Namespace mode — register once, then any item by short name:

- - + +