11'use client'
22import Image from 'next/image'
3+ import Link from 'next/link'
34import { Check , Clipboard } from 'phosphor-react'
45import { ReactNode , useState } from 'react'
56import { PrismLight as SyntaxHighlighter } from 'react-syntax-highlighter'
@@ -13,15 +14,17 @@ interface CodePreviewProps {
1314 github ?: string
1415 className ?: string
1516 activeTab ?: number
17+ hasData ?: boolean
18+ data ?: any
1619}
1720
18- const CodePreview = ( { children, code, github, className, activeTab } : CodePreviewProps ) => {
19- const [ active , setActive ] = useState ( activeTab ? activeTab : 0 )
21+ const CodePreview = ( { children, code, github, className, activeTab, hasData , data } : CodePreviewProps ) => {
22+ const [ active , setActive ] = useState ( activeTab ?? 0 )
2023 const { copy, copyToClipboard } = useCopy ( )
2124 const githubUrl = `https://github.com/StaticMania/keep-react/tree/main/app/src/components/${ github } `
2225
2326 return (
24- < div className = "my-10 w-full overflow-hidden rounded-xl border border-metal-200 shadow-small" >
27+ < div className = "my-10 w-full overflow-hidden rounded-xl border border-metal-200 shadow-small dark:border-metal-800 " >
2528 < div className = "-mb-px flex flex-wrap border-b border-metal-200 bg-metal-900 px-5 text-center" >
2629 < button
2730 type = "button"
@@ -40,19 +43,30 @@ const CodePreview = ({ children, code, github, className, activeTab }: CodePrevi
4043 } `} >
4144 Code
4245 </ button >
46+
47+ { hasData ? (
48+ < button
49+ id = "code-btn"
50+ onClick = { ( ) => setActive ( 2 ) }
51+ className = { ` flex items-center justify-center border-b border-b-transparent px-5 py-3 text-body-4 font-medium text-metal-400 first:ml-0 ${
52+ active === 2 ? '!border-b-metal-100 text-white' : ''
53+ } `} >
54+ Data
55+ </ button >
56+ ) : null }
4357 </ div >
4458
4559 < div >
46- { active ? (
60+ { active === 1 && (
4761 < div className = "relative" >
4862 < div className = "absolute -top-10 right-3 flex items-center justify-between gap-3 md:top-5 lg:right-10" >
49- < a
63+ < Link
5064 id = "github-page-link"
5165 target = "_blank"
5266 href = { githubUrl }
5367 className = " flex h-8 w-8 items-center justify-center rounded-md bg-metal-800 transition-all duration-300 hover:bg-metal-700 md:h-9 md:w-9" >
5468 < Image src = "/images/icon/github-white.svg" height = { 20 } width = { 20 } alt = "github" />
55- </ a >
69+ </ Link >
5670 < button
5771 className = "flex h-8 w-8 items-center justify-center rounded-md border-2 border-metal-800 bg-metal-900 transition-all duration-300 hover:border-transparent hover:bg-metal-700 md:h-9 md:w-9"
5872 onClick = { ( ) => copyToClipboard ( code ) } >
@@ -83,11 +97,40 @@ const CodePreview = ({ children, code, github, className, activeTab }: CodePrevi
8397 { code . trim ( ) }
8498 </ SyntaxHighlighter >
8599 </ div >
86- ) : (
87- < div className = { cn ( 'flex w-full items-center justify-center bg-white px-2 py-3 md:p-6' , className ) } >
100+ ) }
101+
102+ { active === 0 && (
103+ < div
104+ className = { cn (
105+ 'flex w-full items-center justify-center bg-white px-2 py-3 dark:bg-black md:p-6' ,
106+ className ,
107+ ) } >
88108 < div className = "h-full w-full overflow-auto" > { children } </ div >
89109 </ div >
90110 ) }
111+
112+ { active === 2 && (
113+ < div >
114+ < SyntaxHighlighter
115+ language = "javascript"
116+ style = { coldarkDark }
117+ showLineNumbers
118+ customStyle = { {
119+ maxHeight : '420px' ,
120+ borderRadius : '0px' ,
121+ paddingLeft : '40px' ,
122+ paddingBottom : '20px' ,
123+ marginTop : '0px' ,
124+ marginBottom : '0px' ,
125+ background : '#1C222B' ,
126+ fontSize : '14px' ,
127+ lineHeight : '22px' ,
128+ letterSpacing : '-0.2px' ,
129+ } } >
130+ { data . trim ( ) }
131+ </ SyntaxHighlighter >
132+ </ div >
133+ ) }
91134 </ div >
92135 </ div >
93136 )
0 commit comments