Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow passing ReactNode to Code #1620

Merged
merged 1 commit into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core/primitives/code/code.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const Code = forwardRef(function Code(
return (
<StyledCode data-ui="Code" {...restProps} $size={useArrayProp(size)} $weight={weight} ref={ref}>
<Suspense fallback={<code>{children}</code>}>
<LazyRefractor language={language} value={String(children)} />
<LazyRefractor language={language} value={children} />
</Suspense>
</StyledCode>
)
Expand Down
7 changes: 4 additions & 3 deletions src/core/primitives/code/refractor.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import Refractor from 'react-refractor'

export default function LazyRefractor(
props: Partial<Pick<React.ComponentProps<typeof Refractor>, 'language'>> &
Pick<React.ComponentProps<typeof Refractor>, 'value'>,
props: Partial<Pick<React.ComponentProps<typeof Refractor>, 'language'>> & {
value: React.ReactNode
},
) {
const {language: languageProp, value} = props
const language = typeof languageProp === 'string' ? languageProp : undefined
Expand All @@ -11,7 +12,7 @@ export default function LazyRefractor(
return (
<>
{!(language && registered) && <code>{value}</code>}
{language && registered && <Refractor inline language={language} value={value} />}
{language && registered && <Refractor inline language={language} value={String(value)} />}
</>
)
}
Expand Down
Loading