import React from 'react'; import styles from './silke-code-snippet.scss'; import { SilkeButton, SilkeButtonSet } from '../silke-button'; import { copyToClipboard } from '../../helpers/copy-to-clipboard'; import { Highlight, Language, PrismTheme, themes } from 'prism-react-renderer'; import { SilkeBox } from '../silke-box'; interface Props { buttons?: React.ReactNode; code?: string; language?: Language; lineNumbers?: boolean; onCopy?: () => void; inlineStyle?: React.CSSProperties; noWrap?: boolean; } /** * Default theme with background removed */ export const useTheme: PrismTheme = { ...themes.nightOwl, plain: { ...themes.nightOwl.plain, backgroundColor: 'transparent', backgroundImage: 'none', }, }; export const SilkeCodeSnippet = ({ buttons, code = '', language = 'javascript', lineNumbers, onCopy, inlineStyle = {}, noWrap, }: Props) => ( {({ className, style, tokens, getLineProps, getTokenProps }) => (
          {tokens.map((line, i) => (
            
{lineNumbers && {i + 1}} {line.map((token, key) => ( ))}
))}
)}
); const Buttons = ({ buttons, code, onCopy, }: { buttons?: React.ReactNode; code: string; onCopy?: () => void; }) => ( {buttons} {onCopy && } ); const CopyButton = ({ code, onCopy }: { code: string; onCopy?: () => void }) => code ? ( { copyToClipboard(code); if (onCopy) onCopy(); }} /> ) : null;