import { H1 } from '@teambit/documenter.ui.heading'; import classNames from 'classnames'; import React, { HTMLAttributes, useMemo } from 'react'; import { CodeSnippet } from '@teambit/documenter.ui.code-snippet'; import { useFileContent } from '@teambit/ui.queries.get-file-content'; import SyntaxHighlighter from 'react-syntax-highlighter/dist/esm/prism-light'; import markDownSyntax from 'react-syntax-highlighter/dist/esm/languages/prism/markdown'; import { staticStorageUrl } from '@teambit/base-ui.constants.storage'; import { ComponentID } from '@teambit/component'; import styles from './code-view.module.scss'; export type CodeViewProps = { componentId: ComponentID; currentFile?: string; icon?: string; } & HTMLAttributes; SyntaxHighlighter.registerLanguage('md', markDownSyntax); export function CodeView({ className, componentId, currentFile, icon }: CodeViewProps) { const { fileContent, loading } = useFileContent(componentId, currentFile); const title = useMemo(() => currentFile?.split('/').pop(), [currentFile]); const lang = useMemo(() => { const langFromFileEnding = currentFile?.split('.').pop(); // for some reason, SyntaxHighlighter doesnt support scss or sass highlighting, only css. I need to check how to fix this properly if (langFromFileEnding === 'scss' || langFromFileEnding === 'sass') return 'css'; if (langFromFileEnding === 'mdx') return 'md'; return langFromFileEnding; }, [fileContent]); if (!fileContent && !loading && currentFile) return ; return (

{currentFile && } {title}

{fileContent || ''}
); } function EmptyCodeView() { return (
Nothing to show
); }