MCPcopy Create free account
hub / github.com/cosscom/coss / CodeBlockCommand

Function CodeBlockCommand

apps/ui/components/code-block-command.tsx:21–127  ·  view source on GitHub ↗
({
  __npm__,
  __yarn__,
  __pnpm__,
  __bun__,
}: React.ComponentProps<"pre"> & {
  __npm__?: string;
  __yarn__?: string;
  __pnpm__?: string;
  __bun__?: string;
})

Source from the content-addressed store, hash-verified

19import { useConfig } from "@/hooks/use-config";
20
21export function CodeBlockCommand({
22 __npm__,
23 __yarn__,
24 __pnpm__,
25 __bun__,
26}: React.ComponentProps<"pre"> & {
27 __npm__?: string;
28 __yarn__?: string;
29 __pnpm__?: string;
30 __bun__?: string;
31}) {
32 const [config, setConfig] = useConfig();
33 const { isCopied, copyToClipboard } = useCopyToClipboard();
34
35 const packageManager = config.packageManager || "pnpm";
36 const tabs = React.useMemo(() => {
37 return {
38 bun: __bun__,
39 npm: __npm__,
40 pnpm: __pnpm__,
41 yarn: __yarn__,
42 };
43 }, [__npm__, __pnpm__, __yarn__, __bun__]);
44
45 const copyCommand = React.useCallback(() => {
46 const command = tabs[packageManager];
47
48 if (!command) {
49 return;
50 }
51
52 copyToClipboard(command);
53 }, [packageManager, tabs, copyToClipboard]);
54
55 return (
56 <div>
57 <Tabs
58 className="gap-0"
59 onValueChange={(value) => {
60 setConfig({
61 ...config,
62 packageManager: value as "pnpm" | "npm" | "yarn" | "bun",
63 });
64 }}
65 value={packageManager}
66 >
67 <div className="flex items-center gap-2 border-border/64 border-b px-4 py-1 font-mono">
68 <HugeiconsIcon
69 className="size-5 text-code-foreground sm:size-4"
70 icon={ComputerTerminal02Icon}
71 strokeWidth={2}
72 />
73 <TabsList className="bg-transparent p-0 *:data-[slot=tab-indicator]:rounded-lg *:data-[slot=tab-indicator]:bg-accent *:data-[slot=tab-indicator]:shadow-none">
74 {Object.entries(tabs).map(([key]) => {
75 return (
76 <TabsTab className="rounded-lg" key={key} value={key}>
77 {key}
78 </TabsTab>

Callers

nothing calls this directly

Calls 3

useConfigFunction · 0.90
useCopyToClipboardFunction · 0.90
copyToClipboardFunction · 0.50

Tested by

no test coverage detected