BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/shadcn-collections/command-block

Command Block

shadcn-collections/command-block
FreeComponent

Command block component for displaying commands

Install it

npx shadcn@latest add https://chatcn.me/r/command-block.json

Source

components/chatcn/ai/command-block.tsxchatcn.me/r/command-block.json · first 6 KB
1"use client";
2import React, { createContext, useContext, useState, useEffect } from "react";
3import {
4 Copy01Icon,
5 ComputerTerminal01Icon,
6 Tick01Icon,
7} from "@hugeicons/core-free-icons";
8import { HugeiconsIcon } from "@hugeicons/react";
9import { Separator } from "@/components/ui/separator";
10import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
11import {
12 Tooltip,
13 TooltipContent,
14 TooltipTrigger,
15} from "@/components/ui/tooltip";
16import { Button } from "@/components/ui/button";
17import { cn } from "@/lib/utils";
18
19type CommandBlockContextType = {
20 activeCommand: string;
21 setActiveCommand: (cmd: string) => void;
22 copied: boolean;
23 setCopied: (copied: boolean) => void;
24};
25
26const CommandBlockContext = createContext<CommandBlockContextType | null>(null);
27
28export function useCommandBlockContext() {
29 const context = useContext(CommandBlockContext);
30 if (!context) {
31 throw new Error(
32 "useCommandBlockContext must be used within a CommandBlockContext.Provider"
33 );
34 }
35 return context;
36}
37
38type CommandBlockProps = {
39 className?: string;
40 children: React.ReactNode;
41};
42
43export function CommandBlock({ className, children }: CommandBlockProps) {
44 const [activeCommand, setActiveCommand] = useState("");
45 const [copied, setCopied] = useState(false);
46
47 return (
48 <CommandBlockContext.Provider
49 value={{ activeCommand, setActiveCommand, copied, setCopied }}
50 >
51 <div className={cn("w-full mx-auto", className)}>
52 <div className="bg-card rounded-md border">{children}</div>
53 </div>
54 </CommandBlockContext.Provider>
55 );
56}
57
58type CommandBlockHeaderProps = {
59 children?: React.ReactNode;
60};
61
62export function CommandBlockHeader({ children }: CommandBlockHeaderProps) {
63 const { activeCommand, copied, setCopied } = useCommandBlockContext();
64
65 const copyToClipboard = async (text: string) => {
66 try {
67 await navigator.clipboard.writeText(text);
68 setCopied(true);
69 setTimeout(() => setCopied(false), 2000);
70 } catch (err) {
71 console.error("Failed to copy text: ", err);
72 }
73 };
74
75 return (
76 <>
77 <div className="flex items-center justify-between px-3 sm:px-4 py-1.5 sm:py-2">
78 <div className="flex items-center space-x-2">{children}</div>
79 <Tooltip>
80 <TooltipTrigger asChild>
81 <Button
82 variant="ghost"
83 size="sm"
84 className="h-7 w-7 sm:h-8 sm:w-8 p-0"
85// … truncated

What it pulls in

Other registry items

  • tooltip

Files it writes

  • components/chatcn/ai/command-block.tsx

Facts

Registry
shadcn-collections
Type
registry:component
Access
Free
Files written
1
Licence
the repository states none
First indexed
2026-08-03
Last confirmed
yesterday

Go to the source

chatcn.me sankalpaacharya/chatcn on GitHub Raw registry item This item as JSON

More from shadcn-collections

All 24 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
Audio Visualizeraudio-visualizershadcn-collectionsComponentsFree4 deps
Calendarcalendarshadcn-collectionsComponentsFreeno deps
Chat Containerchat-containershadcn-collectionsComponentsFreeno deps
Code Editorcode-editorshadcn-collectionsComponentsFreeno deps
Code Blockcodeblockshadcn-collectionsComponentsFree1 dep
Command Tabscommand-tabsshadcn-collectionsComponentsFreeno deps
Emailemailshadcn-collectionsComponentsFreeno deps
Filefileshadcn-collectionsComponentsFreeno deps
BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex