import { useParams } from 'common' import { PropsWithChildren } from 'react' import { SimpleCodeBlock } from 'ui-patterns/SimpleCodeBlock' import { Markdown } from '../Markdown' import { useTrack } from '@/lib/telemetry/track' interface ContentSnippetProps { apikey?: string endpoint?: string selectedLanguage: 'js' | 'bash' snippet: { key: string category: string title: string description?: string js?: (apikey?: string, endpoint?: string) => string bash?: (apikey?: string, endpoint?: string) => string } } const ContentSnippet = ({ apikey, endpoint, selectedLanguage, snippet, children, }: PropsWithChildren) => { const { ref: projectRef } = useParams() const track = useTrack() const codeSnippet = snippet[selectedLanguage]?.(apikey, endpoint).replaceAll( '[ref]', projectRef ?? '' ) const handleCopy = () => { track('api_docs_code_copy_button_clicked', { title: snippet.title, selectedLanguage }) } return (

{snippet.title}

{snippet.description !== undefined && (
)}
{children} {codeSnippet !== undefined && (
{codeSnippet}
)}
) } export default ContentSnippet