Skip to content

Commit 7bed115

Browse files
committed
Place copy page button in docs sidebar
1 parent bba5788 commit 7bed115

7 files changed

Lines changed: 72 additions & 6 deletions

File tree

docusaurus.config.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,12 @@ module.exports = {
371371
versions: VERSIONS_JSON,
372372
},
373373
],
374-
'docusaurus-plugin-copy-page-button',
374+
[
375+
'docusaurus-plugin-copy-page-button',
376+
{
377+
injectButton: false,
378+
},
379+
],
375380
],
376381
customFields: {},
377382
themes: [],

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"clsx": "^1.1.1",
5151
"concurrently": "^6.2.0",
5252
"crowdin": "^3.5.0",
53-
"docusaurus-plugin-copy-page-button": "^0.4.2",
53+
"docusaurus-plugin-copy-page-button": "^0.6.1",
5454
"docusaurus-plugin-module-alias": "^0.0.2",
5555
"docusaurus-plugin-sass": "^0.2.6",
5656
"fs-extra": "^9.1.0",

src/theme/DocItem/Layout/index.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import React from 'react';
1313
import clsx from 'clsx';
1414
import {useWindowSize} from '@docusaurus/theme-common';
1515
import {useDoc} from '@docusaurus/plugin-content-docs/client';
16+
import CopyPageButton from 'docusaurus-plugin-copy-page-button/react';
1617
import DocItemPaginator from '@theme/DocItem/Paginator';
1718
import DocVersionBanner from '@theme/DocVersionBanner';
1819
import DocVersionBadge from '@theme/DocVersionBadge';
@@ -23,6 +24,7 @@ import DocItemContent from '@theme/DocItem/Content';
2324
import ContentVisibility from '@theme/ContentVisibility';
2425
import type {Props} from '@theme/DocItem/Layout';
2526
import styles from '@docusaurus/theme-classic/lib/theme/DocItem/Layout/styles.module.css';
27+
import copyPageStyles from './styles.module.css';
2628

2729
// CUSTOM CODE
2830
import DocDemo from '@components/global/DocDemo';
@@ -86,6 +88,15 @@ export default function DocItemLayout({children, ...props}: Props): JSX.Element
8688
<article>
8789
<DocVersionBadge />
8890
{docTOC.mobile}
91+
<div className={copyPageStyles.copyPageArticleAction}>
92+
<CopyPageButton
93+
customStyles={{
94+
container: {className: copyPageStyles.copyPageContainer},
95+
button: {className: copyPageStyles.copyPageButton},
96+
dropdown: {className: copyPageStyles.copyPageDropdown},
97+
}}
98+
/>
99+
</div>
89100
<DocItemContent>{children}</DocItemContent>
90101
<DocItemFooter />
91102
</article>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.copyPageArticleAction {
2+
display: flex;
3+
justify-content: flex-end;
4+
min-height: 37px;
5+
margin-bottom: 1rem;
6+
}
7+
8+
.copyPageContainer {
9+
display: inline-block;
10+
}
11+
12+
.copyPageButton,
13+
.copyPageDropdown {
14+
font-family: var(--ifm-font-family-base);
15+
}
16+
17+
@media (min-width: 997px) {
18+
.copyPageArticleAction {
19+
display: none;
20+
}
21+
}

src/theme/DocSidebar/index.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88

99
import React, { useEffect } from 'react';
1010
import { useLocation } from '@docusaurus/router';
11+
import CopyPageButton from 'docusaurus-plugin-copy-page-button/react';
1112
import DocSidebar from '@theme-original/DocSidebar';
1213
import type { Props } from '@theme/DocSidebar';
1314

1415
import Logo from '@theme-original/Logo';
16+
import styles from './styles.module.css';
1517

1618
export default function DocSidebarWrapper(props: Props): JSX.Element {
1719
const location = useLocation();
@@ -28,6 +30,15 @@ export default function DocSidebarWrapper(props: Props): JSX.Element {
2830
return (
2931
<>
3032
<Logo />
33+
<div className={styles.copyPageAction}>
34+
<CopyPageButton
35+
customStyles={{
36+
container: { className: styles.copyPageContainer },
37+
button: { className: styles.copyPageButton },
38+
dropdown: { className: styles.copyPageDropdown },
39+
}}
40+
/>
41+
</div>
3142
<DocSidebar {...props} />
3243
</>
3344
);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
.copyPageAction {
2+
padding: 0 var(--sidebar-spacing-horizontal) 1rem;
3+
}
4+
5+
.copyPageContainer {
6+
display: block;
7+
width: 100%;
8+
}
9+
10+
.copyPageButton {
11+
width: 100%;
12+
justify-content: space-between;
13+
font-family: var(--ifm-font-family-base);
14+
}
15+
16+
.copyPageDropdown {
17+
font-family: var(--ifm-font-family-base);
18+
}

0 commit comments

Comments
 (0)