fix(v2): make code blocks scrollable (#2241)

* wip

* fix(v2): make code blocks scrollable

Co-authored-by: Yangshun Tay <tay.yang.shun@gmail.com>
This commit is contained in:
Alexey Pyltsyn 2020-02-08 14:44:45 +03:00 committed by GitHub
parent 0fa080c39c
commit bb82d0e073
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 86 additions and 63 deletions

View file

@ -90,11 +90,17 @@ export default ({children, className: languageClassName, metastring}) => {
code={children.trim()}
language={language}>
{({className, style, tokens, getLineProps, getTokenProps}) => (
<div className={styles.codeBlockWrapper}>
<pre
ref={target}
className={classnames(className, styles.codeBlock)}
style={style}>
<pre className={classnames(className, styles.codeBlock)}>
<button
ref={button}
type="button"
aria-label="Copy code to clipboard"
className={styles.copyButton}
onClick={handleCopyCode}>
{showCopied ? 'Copied' : 'Copy'}
</button>
<code ref={target} className={styles.codeBlockLines} style={style}>
{tokens.map((line, i) => {
const lineProps = getLineProps({line, key: i});
@ -110,16 +116,8 @@ export default ({children, className: languageClassName, metastring}) => {
</div>
);
})}
</pre>
<button
ref={button}
type="button"
aria-label="Copy code to clipboard"
className={styles.copyButton}
onClick={handleCopyCode}>
{showCopied ? 'Copied' : 'Copy'}
</button>
</div>
</code>
</pre>
)}
</Highlight>
);