Skip to content

Commit 22e64ea

Browse files
Updated copy button
1 parent 1d41c25 commit 22e64ea

4 files changed

Lines changed: 47 additions & 44 deletions

File tree

src/app/extensions/[slug]/page.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { notFound } from 'next/navigation';
66
import { useEffect, useState } from 'react';
77

88
import { AnimatedGradient } from '@/components/animated-gradient';
9+
import { CopyButton } from '@/components/copy-button';
910
import { ParticlesBackground } from '@/components/particles-background';
1011
import { TemplateCard } from '@/components/template-card';
1112
import { Badge } from '@/components/ui/badge';
@@ -270,16 +271,13 @@ export default function ExtensionPage({ params }: ExtensionPageProps) {
270271
</div>
271272
</CardContent>
272273
<CardFooter className="flex flex-col items-start gap-4">
273-
<Button
274+
<CopyButton
274275
className="w-full bg-gradient-to-r from-indigo-500 to-purple-500 hover:from-indigo-500/90 hover:to-purple-500/90 glow transition-all duration-300"
275276
onClick={() => {
276277
const command = `npx create-awesome-node-app --template [template-name] --addons ${extension.slug}`;
277278
navigator.clipboard?.writeText?.(command);
278279
}}
279-
>
280-
<Copy className="mr-2 h-4 w-4" />
281-
Copy Command
282-
</Button>
280+
/>
283281
<Link href={extension.url} className="w-full" target="_blank">
284282
<Button
285283
variant="outline"

src/app/templates/[slug]/extensions/[extensionSlug]/page.tsx

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
'use client';
22

3-
import { ArrowLeft, Check, Copy, Loader2, Package, Puzzle } from 'lucide-react';
3+
import { ArrowLeft, Check, Loader2, Package, Puzzle } from 'lucide-react';
44
import Link from 'next/link';
55
import { notFound } from 'next/navigation';
66
import React, { useEffect, useState } from 'react';
77

88
import { AnimatedGradient } from '@/components/animated-gradient';
9+
import { CopyButton } from '@/components/copy-button';
910
import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert';
1011
import { Badge } from '@/components/ui/badge';
1112
import { Button } from '@/components/ui/button';
@@ -419,38 +420,3 @@ export default function TemplateExtensionPage({
419420
</div>
420421
);
421422
}
422-
423-
// Copy button component with copy feedback
424-
function CopyButton({
425-
command,
426-
className,
427-
size = 'default',
428-
}: {
429-
command: string;
430-
className?: string;
431-
size?: 'default' | 'sm' | 'lg';
432-
}) {
433-
const [copied, setCopied] = useState(false);
434-
435-
const handleCopy = () => {
436-
navigator.clipboard?.writeText(command);
437-
setCopied(true);
438-
setTimeout(() => setCopied(false), 2000);
439-
};
440-
441-
return (
442-
<Button onClick={handleCopy} className={className} size={size}>
443-
{copied ? (
444-
<>
445-
<Check className="mr-2 h-4 w-4" />
446-
Copied!
447-
</>
448-
) : (
449-
<>
450-
<Copy className="mr-2 h-4 w-4" />
451-
Copy Command
452-
</>
453-
)}
454-
</Button>
455-
);
456-
}

src/app/templates/[slug]/page.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { notFound } from 'next/navigation';
66
import React, { useEffect, useState } from 'react';
77

88
import { AnimatedGradient } from '@/components/animated-gradient';
9+
import { CopyButton } from '@/components/copy-button';
910
import { ExtensionCard } from '@/components/extension-card';
1011
import { ParticlesBackground } from '@/components/particles-background';
1112
import { TemplateExtensionCombo } from '@/components/template-extension-combo';
@@ -286,9 +287,13 @@ export default function TemplatePage({ params }: { params: Promise<{ slug: strin
286287
</div>
287288
</CardContent>
288289
<CardFooter className="flex flex-col items-start gap-4">
289-
<Button className="w-full bg-gradient-to-r from-primary to-indigo-500 hover:from-primary/90 hover:to-indigo-500/90 glow transition-all duration-300">
290-
Copy Command
291-
</Button>
290+
<CopyButton
291+
className="w-full bg-gradient-to-r from-primary to-indigo-500 hover:from-primary/90 hover:to-indigo-500/90 glow transition-all duration-300"
292+
onClick={() => {
293+
const command = `npx create-awesome-node-app --template [template-name]`;
294+
navigator.clipboard?.writeText?.(command);
295+
}}
296+
/>
292297
<Link href={template.url} className="w-full" target="_blank">
293298
<Button
294299
variant="outline"

src/components/copy-button.tsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { Check, Copy } from 'lucide-react';
2+
import { useState } from 'react';
3+
import { Button, ButtonProps } from 'react-day-picker';
4+
5+
export function CopyButton({
6+
command,
7+
...props
8+
}: ButtonProps & {
9+
command: string;
10+
}) {
11+
const [copied, setCopied] = useState(false);
12+
13+
const handleCopy = () => {
14+
navigator.clipboard?.writeText(command);
15+
setCopied(true);
16+
setTimeout(() => setCopied(false), 2000);
17+
};
18+
19+
return (
20+
<Button onClick={handleCopy} {...props}>
21+
{copied ? (
22+
<>
23+
<Check className="mr-2 h-4 w-4" />
24+
Copied!
25+
</>
26+
) : (
27+
<>
28+
<Copy className="mr-2 h-4 w-4" />
29+
Copy Command
30+
</>
31+
)}
32+
</Button>
33+
);
34+
}

0 commit comments

Comments
 (0)