Skip to content

Commit 0b106c2

Browse files
committed
Add copy button to config
1 parent 78042f2 commit 0b106c2

File tree

5 files changed

+24
-18
lines changed

5 files changed

+24
-18
lines changed

packages/mdx/dev/files.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@ export async function getCode(file: string, config = {}) {
3434
remarkPlugins: [
3535
[
3636
remarkCodeHike,
37-
{ autoImport: false, theme, ...config },
37+
{
38+
autoImport: false,
39+
showCopyButton: true,
40+
theme,
41+
...config,
42+
},
3843
],
3944
],
4045
})

packages/mdx/pages/themes.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export async function getStaticProps() {
3838
const { code } = await getCode(mdx, {
3939
theme,
4040
lineNumbers: true,
41+
showCopyButton: true,
4142
})
4243
return { themeName, code }
4344
})

packages/mdx/src/mdx-client/code.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,7 @@ export function InnerCode({
3232
<div className="ch-codeblock not-prose">
3333
<CodeSpring
3434
className="ch-code"
35-
config={{
36-
...props.codeConfig,
37-
showCopyButton: true,
38-
}}
35+
config={props.codeConfig}
3936
step={props.files[0]}
4037
/>
4138
</div>

packages/mdx/src/mdx-plugin/plugin.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type CodeHikeConfig = {
1515
theme: any
1616
lineNumbers?: boolean
1717
autoImport?: boolean
18+
showCopyButton?: boolean
1819
}
1920

2021
export function remarkCodeHike(

packages/mdx/src/mini-editor/editor-tween.tsx

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ function EditorTween({
5454
...divProps
5555
}: EditorTweenProps) {
5656
const ref = React.createRef<HTMLDivElement>()
57+
58+
const { showCopyButton, ...config } = codeConfig
5759
const {
5860
northPanel,
5961
southPanel,
@@ -65,7 +67,7 @@ function EditorTween({
6567
next || prev,
6668
t,
6769
backward,
68-
codeConfig
70+
config
6971
)
7072

7173
const [frozenHeight, freezeHeight] = React.useState<
@@ -109,20 +111,20 @@ function EditorTween({
109111
terminalPanel={terminalPanel}
110112
theme={codeConfig.theme}
111113
northButton={
112-
<CopyButton
113-
content={northContent}
114-
style={{
115-
margin: "0 0.8em",
116-
}}
117-
/>
114+
showCopyButton ? (
115+
<CopyButton
116+
content={northContent}
117+
style={{ margin: "0 0.8em" }}
118+
/>
119+
) : undefined
118120
}
119121
southButton={
120-
<CopyButton
121-
content={southContent}
122-
style={{
123-
margin: "0 0.8em",
124-
}}
125-
/>
122+
showCopyButton ? (
123+
<CopyButton
124+
content={southContent}
125+
style={{ margin: "0 0.8em" }}
126+
/>
127+
) : undefined
126128
}
127129
/>
128130
)

0 commit comments

Comments
 (0)