Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions components/CodeBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export function CodeBlock({ className, children, ...props }: ICodeBlock) {
}, 3000);
}
};

return (
<div className="relative">
<pre
Expand Down
104 changes: 100 additions & 4 deletions components/ComponentInstall.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,108 @@
import { componentConfig } from "@/config";
import { Tab, TabGroup, TabList, TabPanel, TabPanels } from "@headlessui/react";
import { Code } from "lucide-react";
import React from "react";
import { HTMLAttributes } from "react";
import { Check, Copy } from "lucide-react";
import { useState } from "react";
import { Button } from "./retroui";

interface IComponentShowcase extends HTMLAttributes<HTMLDivElement> {}

function ComponentInstallCli({ children }: { children: React.ReactNode }) {
return <TabPanel>{children}</TabPanel>;
const CopyableCommand = ({ command }: { command: string }) => {
const [copied, setCopied] = useState(false);

const copyToClipboard = async () => {
await navigator.clipboard.writeText(command);
setCopied(true);
setTimeout(() => setCopied(false), 2000);
};

return (
<div className="flex items-center justify-between gap-2 group">
<code className="flex-1">{command}</code>
<Button size="sm" onClick={copyToClipboard} title="Copy to clipboard">
{copied ? "Copied" : "Copy"}
</Button>
</div>
);
};
Comment on lines +10 to +27
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add error handling for clipboard operations.

The CopyableCommand component uses the clipboard API without error handling. The clipboard API may not be available in all browsers or non-HTTPS contexts.

  const copyToClipboard = async () => {
-    await navigator.clipboard.writeText(command);
-    setCopied(true);
-    setTimeout(() => setCopied(false), 2000);
+    try {
+      await navigator.clipboard.writeText(command);
+      setCopied(true);
+      setTimeout(() => setCopied(false), 2000);
+    } catch (error) {
+      // Fallback for environments where clipboard API is not available
+      console.warn('Failed to copy to clipboard:', error);
+      // Could implement a fallback method here
+    }
  };
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const CopyableCommand = ({ command }: { command: string }) => {
const [copied, setCopied] = useState(false);
const copyToClipboard = async () => {
await navigator.clipboard.writeText(command);
setCopied(true);
setTimeout(() => setCopied(false), 2000);
};
return (
<div className="flex items-center justify-between gap-2 group">
<code className="flex-1">{command}</code>
<Button size="sm" onClick={copyToClipboard} title="Copy to clipboard">
{copied ? "Copied" : "Copy"}
</Button>
</div>
);
};
const CopyableCommand = ({ command }: { command: string }) => {
const [copied, setCopied] = useState(false);
const copyToClipboard = async () => {
try {
await navigator.clipboard.writeText(command);
setCopied(true);
setTimeout(() => setCopied(false), 2000);
} catch (error) {
// Fallback for environments where clipboard API is not available
console.warn('Failed to copy to clipboard:', error);
// Could implement a fallback method here
}
};
return (
<div className="flex items-center justify-between gap-2 group">
<code className="flex-1">{command}</code>
<Button size="sm" onClick={copyToClipboard} title="Copy to clipboard">
{copied ? "Copied" : "Copy"}
</Button>
</div>
);
};
🤖 Prompt for AI Agents
In components/ComponentInstall.tsx around lines 10 to 27, the clipboard API
usage in the copyToClipboard function lacks error handling, which can cause
issues if the API is unavailable or fails. Wrap the clipboard writeText call in
a try-catch block to catch any errors, and handle failures gracefully, such as
by logging the error or showing a fallback message. This ensures the component
behaves reliably across different browsers and contexts.


export function CliCommand({
npmCommand,
yarnCommand,
pnpmCommand,
bunCommand,
}: {
npmCommand: string;
yarnCommand?: string;
pnpmCommand?: string;
bunCommand?: string;
}) {
const isNpx = npmCommand.includes("npx");
if (isNpx) {
pnpmCommand = pnpmCommand ?? npmCommand.replace("npx", "pnpm dlx");
yarnCommand = yarnCommand ?? npmCommand.replace("npx", "yarn dlx");
bunCommand = bunCommand ?? npmCommand.replace("npx", "bunx");
} else {
pnpmCommand = pnpmCommand ?? npmCommand.replace("npm", "pnpm");
yarnCommand = yarnCommand ?? npmCommand.replace("npm install", "yarn add");
bunCommand = bunCommand ?? npmCommand.replace("npm", "bun");
}

return (
<TabGroup className="p-4 my-2 bg-gray-800 rounded-md text-background/90">
<TabList className="flex space-x-4 mb-6 text-sm">
<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">
pnpm
</Tab>
<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">
npm
</Tab>
<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">
yarn
</Tab>
<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">
bun
</Tab>
</TabList>
<TabPanels className="text-sm text-accent">
<TabPanel>
<CopyableCommand command={pnpmCommand} />
</TabPanel>
<TabPanel>
<CopyableCommand command={npmCommand} />
</TabPanel>
<TabPanel>
<CopyableCommand command={yarnCommand} />
</TabPanel>
<TabPanel>
<CopyableCommand command={bunCommand} />
</TabPanel>
</TabPanels>
</TabGroup>
);
}

function ComponentInstallCli({
npmCommand,
yarnCommand,
pnpmCommand,
bunCommand,
}: {
npmCommand: string;
yarnCommand?: string;
pnpmCommand?: string;
bunCommand?: string;
}) {
return (
<TabPanel>
<CliCommand
npmCommand={npmCommand}
yarnCommand={yarnCommand}
pnpmCommand={pnpmCommand}
bunCommand={bunCommand}
/>
</TabPanel>
);
}

function ComponentInstallManual({ children }: { children: React.ReactNode }) {
Expand Down
3 changes: 2 additions & 1 deletion components/MDX.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { cn } from "@/lib/utils";
import { ComponentSource } from "./ComponentSource";
import { CodeBlock } from "./CodeBlock";
import Link from "next/link";
import { ComponentInstall } from "./ComponentInstall";
import { ComponentInstall, CliCommand } from "./ComponentInstall";
import Image from "next/image";
import { Tab, TabGroup, TabList, TabPanel, TabPanels } from "@headlessui/react";

Expand Down Expand Up @@ -103,6 +103,7 @@ const components = (type: "doc" | "blog") => ({
ComponentShowcase,
ComponentSource,
ComponentInstall,
CliCommand,
});

export default function MDX({
Expand Down
6 changes: 1 addition & 5 deletions content/docs/components/accordion.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ links:
## Installation

<ComponentInstall>
<ComponentInstall.Cli>
```sh
npx shadcn@latest add "https://retroui.dev/r/accordion.json"
```
</ComponentInstall.Cli>
<ComponentInstall.Cli npmCommand="npx shadcn@latest add 'https://retroui.dev/r/accordion.json'" />
<ComponentInstall.Manual>
#### 1. Install dependencies:

Expand Down
6 changes: 1 addition & 5 deletions content/docs/components/alert.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ lastUpdated: 24 Oct, 2024
<br />

<ComponentInstall>
<ComponentInstall.Cli>
```sh
npx shadcn@latest add "https://retroui.dev/r/alert.json"
```
</ComponentInstall.Cli>
<ComponentInstall.Cli npmCommand="npx shadcn@latest add 'https://retroui.dev/r/alert.json'" />
<ComponentInstall.Manual>
#### 1. Install dependencies:

Expand Down
6 changes: 1 addition & 5 deletions content/docs/components/avatar.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ lastUpdated: 12 Oct, 2024
<br />

<ComponentInstall>
<ComponentInstall.Cli>
```sh
npx shadcn@latest add "https://retroui.dev/r/avatar.json"
```
</ComponentInstall.Cli>
<ComponentInstall.Cli npmCommand="npx shadcn@latest add 'https://retroui.dev/r/avatar.json'" />
<ComponentInstall.Manual>
#### 1. Install dependencies:

Expand Down
6 changes: 1 addition & 5 deletions content/docs/components/badge.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ lastUpdated: 30 Oct, 2024
<br />

<ComponentInstall>
<ComponentInstall.Cli>
```sh
npx shadcn@latest add "https://retroui.dev/r/badge.json"
```
</ComponentInstall.Cli>
<ComponentInstall.Cli npmCommand="npx shadcn@latest add 'https://retroui.dev/r/badge.json'" />
<ComponentInstall.Manual>
#### 1. Install dependencies:

Expand Down
6 changes: 1 addition & 5 deletions content/docs/components/breadcrumb.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ lastUpdated: 12 May, 2025
<br />

<ComponentInstall>
<ComponentInstall.Cli>
```sh
npx shadcn@latest add "https://retroui.dev/r/breadcrumb.json"
```
</ComponentInstall.Cli>
<ComponentInstall.Cli npmCommand="npx shadcn@latest add 'https://retroui.dev/r/breadcrumb.json'" />
<ComponentInstall.Manual>
#### 1. Install dependencies:

Expand Down
6 changes: 1 addition & 5 deletions content/docs/components/button.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ links:
<br />

<ComponentInstall>
<ComponentInstall.Cli>
```sh
npx shadcn@latest add "https://retroui.dev/r/button.json"
```
</ComponentInstall.Cli>
<ComponentInstall.Cli npmCommand="npx shadcn@latest add 'https://retroui.dev/r/button.json'" />
<ComponentInstall.Manual>
#### 1. Install dependencies:

Expand Down
6 changes: 1 addition & 5 deletions content/docs/components/card.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ lastUpdated: 20 Oct, 2024
## Installation

<ComponentInstall>
<ComponentInstall.Cli>
```sh
npx shadcn@latest add "https://retroui.dev/r/card.json"
```
</ComponentInstall.Cli>
<ComponentInstall.Cli npmCommand="npx shadcn@latest add 'https://retroui.dev/r/card.json'" />
<ComponentInstall.Manual>

#### Copy the code 👇 into your project:
Expand Down
6 changes: 1 addition & 5 deletions content/docs/components/checkbox.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ links:
## Installation

<ComponentInstall>
<ComponentInstall.Cli>
```sh
npx shadcn@latest add "https://retroui.dev/r/checkbox.json"
```
</ComponentInstall.Cli>
<ComponentInstall.Cli npmCommand="npx shadcn@latest add 'https://retroui.dev/r/checkbox.json'" />
<ComponentInstall.Manual>

#### 1. Install dependencies:
Expand Down
6 changes: 1 addition & 5 deletions content/docs/components/dialog.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ links:
## Instalation

<ComponentInstall>
<ComponentInstall.Cli>
```sh
npx shadcn@latest add "https://retroui.dev/r/dialog.json"
```
</ComponentInstall.Cli>
<ComponentInstall.Cli npmCommand="npx shadcn@latest add 'https://retroui.dev/r/dialog.json'" />
<ComponentInstall.Manual>

#### 1. Install dependencies:
Expand Down
6 changes: 1 addition & 5 deletions content/docs/components/input.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ lastUpdated: 04 Mar, 2024
## Installation

<ComponentInstall>
<ComponentInstall.Cli>
```sh
npx shadcn@latest add "https://retroui.dev/r/input.json"
```
</ComponentInstall.Cli>
<ComponentInstall.Cli npmCommand="npx shadcn@latest add 'https://retroui.dev/r/input.json'" />
<ComponentInstall.Manual>

#### 1. Copy the code 👇 into your project:
Expand Down
6 changes: 1 addition & 5 deletions content/docs/components/label.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ lastUpdated: 04 Apr, 2025
<br />

<ComponentInstall>
<ComponentInstall.Cli>
```sh
npx shadcn@latest add "https://retroui.dev/r/label.json"
```
</ComponentInstall.Cli>
<ComponentInstall.Cli npmCommand="npx shadcn@latest add 'https://retroui.dev/r/label.json'" />
<ComponentInstall.Manual>
#### 1. Install dependencies:

Expand Down
6 changes: 1 addition & 5 deletions content/docs/components/menu.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ links:
## Installation

<ComponentInstall>
<ComponentInstall.Cli>
```sh
npx shadcn@latest add "https://retroui.dev/r/menu.json"
```
</ComponentInstall.Cli>
<ComponentInstall.Cli npmCommand="npx shadcn@latest add 'https://retroui.dev/r/menu.json'" />
<ComponentInstall.Manual>

#### 1. Install dependencies:
Expand Down
8 changes: 2 additions & 6 deletions content/docs/components/popover.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,8 @@ lastUpdated: 08 Apr, 2025
<br />

<ComponentInstall>
<ComponentInstall.Cli>
```sh
npx shadcn@latest add "https://retroui.dev/r/popover.json"
```
</ComponentInstall.Cli>
<ComponentInstall.Manual>
<ComponentInstall.Cli npmCommand="npx shadcn@latest add 'https://retroui.dev/r/popover.json'" />
<ComponentInstall.Manual>
#### 1. Install dependencies:

```sh
Expand Down
6 changes: 1 addition & 5 deletions content/docs/components/progress.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ links:
## Installation

<ComponentInstall>
<ComponentInstall.Cli>
```sh
npx shadcn@latest add "https://retroui.dev/r/progress.json"
```
</ComponentInstall.Cli>
<ComponentInstall.Cli npmCommand="npx shadcn@latest add 'https://retroui.dev/r/progress.json'" />
<ComponentInstall.Manual>
#### 1. Install dependencies:

Expand Down
6 changes: 1 addition & 5 deletions content/docs/components/radio.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ links:
## Installation

<ComponentInstall>
<ComponentInstall.Cli>
```sh
npx shadcn@latest add "https://retroui.dev/r/radio.json"
```
</ComponentInstall.Cli>
<ComponentInstall.Cli npmCommand="npx shadcn@latest add 'https://retroui.dev/r/radio.json'" />
<ComponentInstall.Manual>

#### 1. Install dependencies:
Expand Down
6 changes: 1 addition & 5 deletions content/docs/components/select.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ links:
## Installation

<ComponentInstall>
<ComponentInstall.Cli>
```sh
npx shadcn@latest add "https://retroui.dev/r/select.json"
```
</ComponentInstall.Cli>
<ComponentInstall.Cli npmCommand="npx shadcn@latest add 'https://retroui.dev/r/select.json'" />
<ComponentInstall.Manual>

#### 1. Install dependencies:
Expand Down
6 changes: 1 addition & 5 deletions content/docs/components/slider.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ links:
## Installation

<ComponentInstall>
<ComponentInstall.Cli>
```sh
npx shadcn@latest add "https://retroui.dev/r/slider.json"
```
</ComponentInstall.Cli>
<ComponentInstall.Cli npmCommand="npx shadcn@latest add 'https://retroui.dev/r/slider.json'" />
<ComponentInstall.Manual>

#### 1. Install dependencies:
Expand Down
8 changes: 2 additions & 6 deletions content/docs/components/sonner.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,8 @@ links:
## Installation

<ComponentInstall>
<ComponentInstall.Cli>
```sh
npx shadcn@latest add "https://retroui.dev/r/sonner.json"
```
</ComponentInstall.Cli>
<ComponentInstall.Manual>
<ComponentInstall.Cli npmCommand="npx shadcn@latest add 'https://retroui.dev/r/sonner.json'" />
<ComponentInstall.Manual>
#### 1. Install dependencies:

```sh
Expand Down
6 changes: 1 addition & 5 deletions content/docs/components/switch.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ links:
## Installation

<ComponentInstall>
<ComponentInstall.Cli>
```sh
npx shadcn@latest add "https://retroui.dev/r/switch.json"
```
</ComponentInstall.Cli>
<ComponentInstall.Cli npmCommand="npx shadcn@latest add 'https://retroui.dev/r/switch.json'" />
<ComponentInstall.Manual>

#### 1. Install dependencies:
Expand Down
Loading