nocobase/.dumi/theme/builtins/SourceCode.tsx
chenos d5d0e1036b
docs: add docs (#75)
* docs: add docs

* ignore dumi theme test

* fix: error TS2717: Subsequent property declarations must have the same type.

* update docs

* deploy gh-pages

* plugins docs

* hash & cname

* exportStatic

* ssr

* vercel

* vercel

* fix: deploy vercel

* Delete vercel.json

* docs

* fix APP_DIST

* on master branch
2021-04-17 21:33:21 +08:00

42 lines
1.3 KiB
TypeScript
Executable File

import React from 'react';
import type { Language } from 'prism-react-renderer';
import Highlight, { defaultProps } from 'prism-react-renderer';
import { useCopy } from 'dumi/theme';
import 'prismjs/themes/prism.css';
import './SourceCode.less';
export interface ICodeBlockProps {
code: string;
lang: Language;
showCopy?: boolean;
}
export default ({ code, lang, showCopy = true }: ICodeBlockProps) => {
const [copyCode, copyStatus] = useCopy();
return (
<div className="__dumi-default-code-block">
<Highlight {...defaultProps} code={code} language={lang} theme={undefined}>
{({ className, style, tokens, getLineProps, getTokenProps }) => (
<pre className={className} style={style}>
{showCopy && (
<button
className="__dumi-default-icon __dumi-default-code-block-copy-btn"
data-status={copyStatus}
onClick={() => copyCode(code)}
/>
)}
{tokens.map((line, i) => (
<div {...getLineProps({ line, key: i })}>
{line.map((token, key) => (
<span {...getTokenProps({ token, key })} />
))}
</div>
))}
</pre>
)}
</Highlight>
</div>
);
};