Skip to content

Commit

Permalink
refactor(ShikiHighlighter): Rename PreTag prop to as, remove Reac…
Browse files Browse the repository at this point in the history
…t.FC, improve readability
  • Loading branch information
AVGVSTVS96 committed Jul 11, 2024
1 parent 33bda0e commit c79c534
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions src/components/ChatUI/ShikiHihlighter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,25 @@ interface ShikiHighlighterProps {
language: BundledLanguage;
children: string;
theme: BundledTheme;
PreTag?: keyof JSX.IntrinsicElements;
as?: React.ElementType;
}

export const ShikiHighlighter: React.FC<ShikiHighlighterProps> = ({
export const ShikiHighlighter = ({
language,
children,
theme,
PreTag = 'pre',
}) => {
const highlightedCode = useShikiHighlighter(
children,
language,
theme,
);

children: code,
as: Element = 'pre',
}: ShikiHighlighterProps) => {
const highlightedCode = useShikiHighlighter(code, language, theme);

return (
<PreTag className="shiki not-prose relative [&_pre]:overflow-auto [&_pre]:rounded-lg [&_pre]:px-6 [&_pre]:py-5">
<Element className="shiki not-prose relative [&_pre]:overflow-auto [&_pre]:rounded-lg [&_pre]:px-6 [&_pre]:py-5">
{language ? (
<span className="absolute right-3 top-2 text-xs tracking-tighter text-muted-foreground/85">
{language}
</span>
) : null}
{highlightedCode}
</PreTag>
</Element>
);
};

0 comments on commit c79c534

Please sign in to comment.