import React, { forwardRef, ElementRef } from 'react' import Highlight, { defaultProps } from 'prism-react-renderer' import { styled } from '~/theme' import { useClipboard } from '~/hooks' import { useTheme } from '~/providers' import { Tooltip } from '../../Feedback/Tooltip' import { Conditional } from '../../Utilities/Conditional' import { CodeLanguage } from './types' import { CopyButton } from './CopyButton' import { getPrismTheme } from './theme' const StyledPrism = styled('div', { position: 'relative', }) const TooltipContainer = styled('div', { display: 'inline-block', position: 'absolute', top: '0px', right: '0px', padding: '16px', zIndex: '2', }) const Pre = styled('pre', { lineHeight: '1.55', borderRadius: '4px', fontSize: '15px', padding: '10px', margin: '0px', overflowX: 'auto', }) const Line = styled('div', { display: 'table-row', }) const LineNo = styled('div', { display: 'table-cell', textAlign: 'right', paddingRight: '1em', opacity: '0.5', userSelect: 'none', }) const LineContent = styled('div', { display: 'table-cell', }) export interface PrismProps { language: CodeLanguage withLineNumbers?: boolean copyLabel?: string copiedLabel?: string children: string } export const Prism = forwardRef, PrismProps>( (properties, forwardedRef) => { const { language, withLineNumbers = false, copyLabel = 'Copy code', copiedLabel = 'Copied', children = '', ...remainingProps } = properties const { activeTheme } = useTheme() const trimmedCode = children.trim() const clipboard = useClipboard() return ( clipboard.copy(trimmedCode)} /> {({ className, style, tokens, getLineProps, getTokenProps }) => (
              {tokens.map((line, index) => (
                
                  
                    {index + 1}
                  

                  
                    {line.map((token, key) => (
                      
                    ))}
                  
                
              ))}
            
)}
) } ) Prism.displayName = 'Prism' const CodeSnippet = Prism CodeSnippet.displayName = 'CodeSnippet' export { CodeSnippet }