mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-14 00:32:47 +02:00
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:
parent
0fa080c39c
commit
bb82d0e073
8 changed files with 86 additions and 63 deletions
|
@ -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>
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue