Skip to content

Commit

Permalink
Fix CodeBlock
Browse files Browse the repository at this point in the history
  • Loading branch information
lachlancollins committed Jan 18, 2024
1 parent 77b71bb commit 37e4fcd
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions app/components/CodeBlock.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import {
useState,
type FC,
type HTMLAttributes,
type ReactElement,
} from 'react'
import { useState, type ReactNode } from 'react'
import invariant from 'tiny-invariant'
import type { Language } from 'prism-react-renderer'
import { Highlight, Prism } from 'prism-react-renderer'
Expand All @@ -29,16 +24,20 @@ function isLanguageSupported(lang: string): lang is Language {
return lang in Prism.languages
}

export const CodeBlock: FC<HTMLAttributes<HTMLPreElement>> = ({ children }) => {
console.log(children)
type Props = {
children: ReactNode
}

export const CodeBlock = ({ children }: Props) => {
invariant(!!children, 'children is required')
const [copied, setCopied] = useState(false)
const child = children as ReactElement
const className = child.props?.className || ''
const child = Array.isArray(children) ? children[0] : children
const className = child.props.className || ''
const userLang = getLanguageFromClassName(className)
const lang = isLanguageSupported(userLang) ? userLang : 'bash'
// TODO Problem here?
const code = child.props.children || ''
const code = Array.isArray(child.props.children)
? child.props.children[0]
: child.props.children
return (
<div className="w-full max-w-full relative">
<button
Expand Down

0 comments on commit 37e4fcd

Please sign in to comment.