|
1 | | -import { componentConfig } from "@/config"; |
2 | 1 | import { Tab, TabGroup, TabList, TabPanel, TabPanels } from "@headlessui/react"; |
3 | | -import { Code } from "lucide-react"; |
| 2 | +import React from "react"; |
4 | 3 | import { HTMLAttributes } from "react"; |
| 4 | +import { Check, Copy } from "lucide-react"; |
| 5 | +import { useState } from "react"; |
| 6 | +import { Button } from "./retroui"; |
5 | 7 |
|
6 | 8 | interface IComponentShowcase extends HTMLAttributes<HTMLDivElement> {} |
7 | 9 |
|
8 | | -function ComponentInstallCli({ children }: { children: React.ReactNode }) { |
9 | | - return <TabPanel>{children}</TabPanel>; |
| 10 | +const CopyableCommand = ({ command }: { command: string }) => { |
| 11 | + const [copied, setCopied] = useState(false); |
| 12 | + |
| 13 | + const copyToClipboard = async () => { |
| 14 | + await navigator.clipboard.writeText(command); |
| 15 | + setCopied(true); |
| 16 | + setTimeout(() => setCopied(false), 2000); |
| 17 | + }; |
| 18 | + |
| 19 | + return ( |
| 20 | + <div className="flex items-center justify-between gap-2 group"> |
| 21 | + <code className="flex-1">{command}</code> |
| 22 | + <Button size="sm" onClick={copyToClipboard} title="Copy to clipboard"> |
| 23 | + {copied ? "Copied" : "Copy"} |
| 24 | + </Button> |
| 25 | + </div> |
| 26 | + ); |
| 27 | +}; |
| 28 | + |
| 29 | +export function CliCommand({ |
| 30 | + npmCommand, |
| 31 | + yarnCommand, |
| 32 | + pnpmCommand, |
| 33 | + bunCommand, |
| 34 | +}: { |
| 35 | + npmCommand: string; |
| 36 | + yarnCommand?: string; |
| 37 | + pnpmCommand?: string; |
| 38 | + bunCommand?: string; |
| 39 | +}) { |
| 40 | + const isNpx = npmCommand.includes("npx"); |
| 41 | + if (isNpx) { |
| 42 | + pnpmCommand = pnpmCommand ?? npmCommand.replace("npx", "pnpm dlx"); |
| 43 | + yarnCommand = yarnCommand ?? npmCommand.replace("npx", "yarn dlx"); |
| 44 | + bunCommand = bunCommand ?? npmCommand.replace("npx", "bunx"); |
| 45 | + } else { |
| 46 | + pnpmCommand = pnpmCommand ?? npmCommand.replace("npm", "pnpm"); |
| 47 | + yarnCommand = yarnCommand ?? npmCommand.replace("npm install", "yarn add"); |
| 48 | + bunCommand = bunCommand ?? npmCommand.replace("npm", "bun"); |
| 49 | + } |
| 50 | + |
| 51 | + return ( |
| 52 | + <TabGroup className="p-4 my-2 bg-gray-800 rounded-md text-background/90"> |
| 53 | + <TabList className="flex space-x-4 mb-6 text-sm"> |
| 54 | + <Tab className="cursor-pointer text-gray-400 relative px-2 py-1 bg-transparent data-selected:border-b-2 border-accent data-selected:text-white focus:outline-hidden"> |
| 55 | + pnpm |
| 56 | + </Tab> |
| 57 | + <Tab className="cursor-pointer text-gray-400 relative px-2 py-1 bg-transparent data-selected:border-b-2 border-accent data-selected:text-white focus:outline-hidden"> |
| 58 | + npm |
| 59 | + </Tab> |
| 60 | + <Tab className="cursor-pointer text-gray-400 relative px-2 py-1 bg-transparent data-selected:border-b-2 border-accent data-selected:text-white focus:outline-hidden"> |
| 61 | + yarn |
| 62 | + </Tab> |
| 63 | + <Tab className="cursor-pointer text-gray-400 relative px-2 py-1 bg-transparent data-selected:border-b-2 border-accent data-selected:text-white focus:outline-hidden"> |
| 64 | + bun |
| 65 | + </Tab> |
| 66 | + </TabList> |
| 67 | + <TabPanels className="text-sm text-accent"> |
| 68 | + <TabPanel> |
| 69 | + <CopyableCommand command={pnpmCommand} /> |
| 70 | + </TabPanel> |
| 71 | + <TabPanel> |
| 72 | + <CopyableCommand command={npmCommand} /> |
| 73 | + </TabPanel> |
| 74 | + <TabPanel> |
| 75 | + <CopyableCommand command={yarnCommand} /> |
| 76 | + </TabPanel> |
| 77 | + <TabPanel> |
| 78 | + <CopyableCommand command={bunCommand} /> |
| 79 | + </TabPanel> |
| 80 | + </TabPanels> |
| 81 | + </TabGroup> |
| 82 | + ); |
| 83 | +} |
| 84 | + |
| 85 | +function ComponentInstallCli({ |
| 86 | + npmCommand, |
| 87 | + yarnCommand, |
| 88 | + pnpmCommand, |
| 89 | + bunCommand, |
| 90 | +}: { |
| 91 | + npmCommand: string; |
| 92 | + yarnCommand?: string; |
| 93 | + pnpmCommand?: string; |
| 94 | + bunCommand?: string; |
| 95 | +}) { |
| 96 | + return ( |
| 97 | + <TabPanel> |
| 98 | + <CliCommand |
| 99 | + npmCommand={npmCommand} |
| 100 | + yarnCommand={yarnCommand} |
| 101 | + pnpmCommand={pnpmCommand} |
| 102 | + bunCommand={bunCommand} |
| 103 | + /> |
| 104 | + </TabPanel> |
| 105 | + ); |
10 | 106 | } |
11 | 107 |
|
12 | 108 | function ComponentInstallManual({ children }: { children: React.ReactNode }) { |
|
0 commit comments