22
33import { FC , useState } from "react"
44import { Select , SelectContent , SelectItem , SelectTrigger , SelectValue } from "@/components/ui/select"
5- import { Card , CardContent } from "@/components/ui/card"
5+ import { Card , CardContent , CardDescription , CardTitle } from "@/components/ui/card"
66import { Button } from "@/components/ui/button"
7- import { Copy , CopyCheck } from "lucide-react"
7+ import { Copy , CopyCheck , Download } from "lucide-react"
88import { getCodeExample , Language , Method } from "@/utils/getCodeExample" ;
99
1010interface ApiExampleProps {
1111url :string
1212method :Method
1313}
1414
15-
1615export const ApiExample :FC < ApiExampleProps > = ( { url, method} ) => {
1716const [ language , setLanguage ] = useState < Language > ( "js" )
1817const [ isCopied , setIsCopied ] = useState ( false )
18+ const [ isSdkCopied , setIsSdkCopied ] = useState ( false )
1919
2020const handleCopy = async ( ) => {
2121try {
@@ -27,38 +27,88 @@ export const ApiExample: FC<ApiExampleProps> = ({ url, method }) => {
2727}
2828}
2929
30+ const handleCopyInstallCommand = async ( ) => {
31+ try {
32+ await navigator . clipboard . writeText ( "npx api200-generate-sdk -t your_token_here" )
33+ setIsSdkCopied ( true )
34+ setTimeout ( ( ) => setIsSdkCopied ( false ) , 2000 )
35+ } catch ( err ) {
36+ console . error ( 'Failed to copy install command:' , err )
37+ }
38+ }
39+
3040return (
31- < Card className = { `w-full bg-gray-100 shadow-none` } >
32- < CardContent className = "p-4" >
33- < div className = "flex justify-between items-center mb-4" >
34- < Select value = { language } onValueChange = { ( value ) => setLanguage ( value as Language ) } >
35- < SelectTrigger className = "w-[120px] bg-white h-8 text-xs" >
36- < SelectValue placeholder = "Select language" />
37- </ SelectTrigger >
38- < SelectContent >
39- < SelectItem value = "js" > JavaScript</ SelectItem >
40- < SelectItem value = "python" > Python</ SelectItem >
41- < SelectItem value = "php" > PHP</ SelectItem >
42- < SelectItem value = "go" > Go</ SelectItem >
43- < SelectItem value = "rust" > Rust</ SelectItem >
44- < SelectItem value = "java" > Java</ SelectItem >
45- < SelectItem value = "csharp" > C#</ SelectItem >
46- < SelectItem value = "curl" > cURL</ SelectItem >
47- </ SelectContent >
48- </ Select >
49- < Button variant = "outline" size = "sm" onClick = { handleCopy } className = "h-8 w-8 p-0" >
50- { isCopied ?(
51- < CopyCheck className = "h-4 w-4 text-green-500" />
52- ) :(
53- < Copy className = "h-4 w-4" />
54- ) }
55- </ Button >
56- </ div >
57- < pre className = "text-sm overflow-x-auto" >
58- < code > { getCodeExample ( language , url , method ) } </ code >
59- </ pre >
60- </ CardContent >
61- </ Card >
41+ < div className = "w-full space-y-4" >
42+ { /* SDK Installation Instructions for JavaScript */ }
43+ { language === "js" && (
44+ < Card className = "w-full bg-blue-50 border-blue-200 shadow-none" >
45+ < CardContent className = "p-4" >
46+ < div className = "flex justify-between items-start mb-3" >
47+ < div >
48+ < CardTitle className = "text-sm text-blue-900" >
49+ 📦 SDK Installation
50+ </ CardTitle >
51+ < CardDescription className = "text-xs text-blue-700" >
52+ Generate your personalized SDK with your API token
53+ </ CardDescription >
54+ </ div >
55+ < Button
56+ variant = "outline"
57+ size = "sm"
58+ onClick = { handleCopyInstallCommand }
59+ className = "h-8 w-8 p-0 border-blue-300 hover:bg-blue-100"
60+ >
61+ { isSdkCopied ?< CopyCheck className = "h-3 w-3 text-blue-600" /> :< Copy className = "h-3 w-3 text-blue-600" /> }
62+
63+ </ Button >
64+ </ div >
65+ < div className = "bg-white rounded border border-blue-200 p-3" >
66+ < code className = "text-sm text-blue-800 font-mono" >
67+ npx api200-generate-sdk -t your_token_here
68+ </ code >
69+ </ div >
70+ </ CardContent >
71+ </ Card >
72+ ) }
73+
74+ { /* Main Code Example */ }
75+ < Card className = "w-full bg-gray-100 shadow-none" >
76+ < CardContent className = "p-4" >
77+ < div className = "flex justify-between items-center mb-4" >
78+ < Select value = { language } onValueChange = { ( value ) => setLanguage ( value as Language ) } >
79+ < SelectTrigger className = "w-[160px] bg-white h-8 text-xs" >
80+ < SelectValue placeholder = "Select language" />
81+ </ SelectTrigger >
82+ < SelectContent >
83+ < SelectItem value = "js" >
84+ < div className = "flex items-center gap-2" >
85+ < span > JavaScript</ span >
86+ < span className = "text-xs bg-blue-100 text-blue-800 px-1.5 py-0.5 rounded" > SDK</ span >
87+ </ div >
88+ </ SelectItem >
89+ < SelectItem value = "python" > Python</ SelectItem >
90+ < SelectItem value = "php" > PHP</ SelectItem >
91+ < SelectItem value = "go" > Go</ SelectItem >
92+ < SelectItem value = "rust" > Rust</ SelectItem >
93+ < SelectItem value = "java" > Java</ SelectItem >
94+ < SelectItem value = "csharp" > C#</ SelectItem >
95+ < SelectItem value = "curl" > cURL</ SelectItem >
96+ </ SelectContent >
97+ </ Select >
98+ < Button variant = "outline" size = "sm" onClick = { handleCopy } className = "h-8 w-8 p-0" >
99+ { isCopied ?(
100+ < CopyCheck className = "h-4 w-4 text-green-500" />
101+ ) :(
102+ < Copy className = "h-4 w-4" />
103+ ) }
104+ </ Button >
105+ </ div >
106+ < pre className = "text-sm overflow-x-auto" >
107+ < code > { getCodeExample ( language , url , method ) } </ code >
108+ </ pre >
109+ </ CardContent >
110+ </ Card >
111+ </ div >
62112)
63113}
64114