Skip to content

Commit

Permalink
add CodeField className #152
Browse files Browse the repository at this point in the history
  • Loading branch information
ukorvl committed Oct 30, 2023
1 parent 62852a9 commit 9507e0e
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/components/codefield/CodeField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,33 @@ export type CodeFieldProps = {
onCopy?: (code: string, isCopied: boolean) => void;
transformOnCopy?: (code: string) => string;
showLineNumbers?: boolean;
className?: string;
};

const CodeFieldRenderFunction: ForwardRefRenderFunction<HTMLDivElement, CodeFieldProps> = (
{ code, extensions = [], themeOverrides, displayCopy = true, onCopy, transformOnCopy, showLineNumbers = false },
{
code,
extensions = [],
themeOverrides,
displayCopy = true,
onCopy,
transformOnCopy,
showLineNumbers = false,
className,
},
ref
) => {
const [css] = useStyletron();
const copyHandler = useCopyToClipboard(code, onCopy, transformOnCopy);
const mergedExtensions = [...extensions];
const computedCn = className ? `${css(s.containerStyles)} ${className}` : css(s.containerStyles);

if (showLineNumbers) {
mergedExtensions.push(prefixLineNumberExtension);
}

return (
<div ref={ref} className={css(s.containerStyles)}>
<div ref={ref} className={computedCn}>
<CodeMirror
value={code}
readOnly
Expand Down

0 comments on commit 9507e0e

Please sign in to comment.