Skip to content

Commit e5e3a4e

Browse files
committed
feat: Integrate CodeBlock component for improved code display and copy functionality in GetStarted page
1 parent 6c6ff1d commit e5e3a4e

File tree

1 file changed

+32
-55
lines changed

1 file changed

+32
-55
lines changed

demo/src/pages/GetStarted.tsx

Lines changed: 32 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Link } from 'react-router-dom';
33
import { Button } from '@/components/ui/button';
44
import { Copy, Check } from 'lucide-react';
55
import { useState } from 'react';
6+
import CodeBlock from '@/components/ui/codeBlock';
67

78
export default function GetStarted() {
89
const [copied, setCopied] = useState<string | null>(null);
@@ -13,7 +14,12 @@ export default function GetStarted() {
1314
setTimeout(() => setCopied(null), 2000);
1415
};
1516

16-
const installCommand = 'npm install react-hook-form-ai';
17+
const installCommands = [
18+
{ id: 'npm', label: 'npm', code: 'npm install react-hook-form-ai' },
19+
{ id: 'pnpm', label: 'pnpm', code: 'pnpm add react-hook-form-ai' },
20+
{ id: 'yarn', label: 'yarn', code: 'yarn add react-hook-form-ai' },
21+
];
22+
1723
const basicExample = `import { useForm } from 'react-hook-form-ai';
1824
1925
interface FormData {
@@ -83,34 +89,19 @@ function Root() {
8389
Install the package using your preferred package manager
8490
</CardDescription>
8591
</CardHeader>
86-
<CardContent>
87-
<div className="relative">
88-
<pre className="bg-slate-950 text-slate-50 p-4 rounded-md overflow-x-auto">
89-
<code>{installCommand}</code>
90-
</pre>
91-
<Button
92-
size="icon"
93-
variant="ghost"
94-
className="absolute top-2 right-2 text-slate-50 hover:bg-slate-800"
95-
onClick={() => copyToClipboard(installCommand, 'install')}
96-
>
97-
{copied === 'install' ? (
98-
<Check className="h-4 w-4" />
99-
) : (
100-
<Copy className="h-4 w-4" />
101-
)}
102-
</Button>
103-
</div>
104-
<div className="mt-4 space-y-2">
105-
<p className="text-sm text-muted-foreground">Or with pnpm:</p>
106-
<pre className="bg-slate-950 text-slate-50 p-4 rounded-md overflow-x-auto text-sm">
107-
<code>pnpm add react-hook-form-ai</code>
108-
</pre>
109-
<p className="text-sm text-muted-foreground">Or with yarn:</p>
110-
<pre className="bg-slate-950 text-slate-50 p-4 rounded-md overflow-x-auto text-sm">
111-
<code>yarn add react-hook-form-ai</code>
112-
</pre>
113-
</div>
92+
<CardContent className="space-y-4">
93+
{installCommands.map(cmd => (
94+
<div key={cmd.id} className="relative group">
95+
<CodeBlock code={cmd.code} />
96+
<Button
97+
size="sm"
98+
className="absolute top-2 right-2 flex items-center gap-1 bg-transparent hover:bg-muted/10 border border-gray-300"
99+
onClick={() => copyToClipboard(cmd.code, cmd.id)}
100+
>
101+
{copied === cmd.id ? <Check className="w-4 h-4" /> : <Copy className="w-4 h-4" />}
102+
</Button>
103+
</div>
104+
))}
114105
</CardContent>
115106
</Card>
116107

@@ -122,22 +113,15 @@ function Root() {
122113
Replace your React Hook Form import and start using AI features
123114
</CardDescription>
124115
</CardHeader>
125-
<CardContent>
126-
<div className="relative">
127-
<pre className="bg-slate-950 text-slate-50 p-4 rounded-md overflow-x-auto text-sm">
128-
<code>{basicExample}</code>
129-
</pre>
116+
<CardContent className="relative">
117+
<div className='relative'>
118+
<CodeBlock code={basicExample} />
130119
<Button
131-
size="icon"
132-
variant="ghost"
133-
className="absolute top-2 right-2 text-slate-50 hover:bg-slate-800"
120+
size="sm"
121+
className="absolute top-2 right-2 flex items-center gap-1 bg-transparent hover:bg-muted/10 border border-gray-300"
134122
onClick={() => copyToClipboard(basicExample, 'basic')}
135123
>
136-
{copied === 'basic' ? (
137-
<Check className="h-4 w-4" />
138-
) : (
139-
<Copy className="h-4 w-4" />
140-
)}
124+
{copied === 'basic' ? <Check className="w-4 h-4" /> : <Copy className="w-4 h-4" />}
141125
</Button>
142126
</div>
143127
</CardContent>
@@ -151,22 +135,15 @@ function Root() {
151135
Set up multiple AI providers with automatic fallback
152136
</CardDescription>
153137
</CardHeader>
154-
<CardContent>
138+
<CardContent className="relative">
155139
<div className="relative">
156-
<pre className="bg-slate-950 text-slate-50 p-4 rounded-md overflow-x-auto text-sm">
157-
<code>{providerExample}</code>
158-
</pre>
140+
<CodeBlock code={providerExample} />
159141
<Button
160-
size="icon"
161-
variant="ghost"
162-
className="absolute top-2 right-2 text-slate-50 hover:bg-slate-800"
142+
size="sm"
143+
className="absolute top-2 right-2 flex items-center gap-1 bg-transparent hover:bg-muted/10 border border-gray-300"
163144
onClick={() => copyToClipboard(providerExample, 'provider')}
164145
>
165-
{copied === 'provider' ? (
166-
<Check className="h-4 w-4" />
167-
) : (
168-
<Copy className="h-4 w-4" />
169-
)}
146+
{copied === 'provider' ? <Check className="w-4 h-4" /> : <Copy className="w-4 h-4" />}
170147
</Button>
171148
</div>
172149
</CardContent>
@@ -262,4 +239,4 @@ function Root() {
262239
</div>
263240
</div>
264241
);
265-
}
242+
}

0 commit comments

Comments
 (0)