Skip to content

Commit 5c51def

Browse files
committed
Fix copy page button rendering
1 parent 7b5dfd1 commit 5c51def

4 files changed

Lines changed: 186 additions & 1 deletion

File tree

website/docusaurus.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,6 @@ const config: Config = {
221221
],
222222
plugins: [
223223
'docusaurus-plugin-sass',
224-
'docusaurus-plugin-copy-page-button',
225224
function disableExpensiveBundlerOptimizationPlugin() {
226225
return {
227226
name: 'disable-expensive-bundler-optimizations',
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
import React, {type ReactNode} from 'react';
9+
import clsx from 'clsx';
10+
import {useWindowSize} from '@docusaurus/theme-common';
11+
import {useDoc} from '@docusaurus/plugin-content-docs/client';
12+
import CopyPageButton from 'docusaurus-plugin-copy-page-button/src/CopyPageButton';
13+
import DocItemPaginator from '@theme/DocItem/Paginator';
14+
import DocVersionBanner from '@theme/DocVersionBanner';
15+
import DocVersionBadge from '@theme/DocVersionBadge';
16+
import DocItemFooter from '@theme/DocItem/Footer';
17+
import DocItemTOCMobile from '@theme/DocItem/TOC/Mobile';
18+
import DocItemTOCDesktop from '@theme/DocItem/TOC/Desktop';
19+
import DocItemContent from '@theme/DocItem/Content';
20+
import DocBreadcrumbs from '@theme/DocBreadcrumbs';
21+
import ContentVisibility from '@theme/ContentVisibility';
22+
import type {Props} from '@theme/DocItem/Layout';
23+
24+
import styles from './styles.module.css';
25+
26+
function DocItemCopyPageButton({className}: {className?: string}) {
27+
return (
28+
<div className={clsx(styles.copyPageAction, className)}>
29+
<CopyPageButton
30+
customStyles={{
31+
container: {className: styles.copyPageButtonContainer},
32+
button: {
33+
className: styles.copyPageButton,
34+
style: {marginBottom: 0},
35+
},
36+
dropdown: {className: styles.copyPageDropdown},
37+
}}
38+
/>
39+
</div>
40+
);
41+
}
42+
43+
/**
44+
* Decide if the toc should be rendered, on mobile or desktop viewports
45+
*/
46+
function useDocTOC() {
47+
const {frontMatter, toc} = useDoc();
48+
const windowSize = useWindowSize();
49+
50+
const hidden = frontMatter.hide_table_of_contents;
51+
const canRender = !hidden && toc.length > 0;
52+
53+
const mobile = canRender ? <DocItemTOCMobile /> : undefined;
54+
55+
const desktop =
56+
canRender && (windowSize === 'desktop' || windowSize === 'ssr') ? (
57+
<DocItemTOCDesktop />
58+
) : undefined;
59+
60+
return {
61+
canRender,
62+
hidden,
63+
mobile,
64+
desktop,
65+
};
66+
}
67+
68+
export default function DocItemLayout({children}: Props): ReactNode {
69+
const docTOC = useDocTOC();
70+
const {metadata} = useDoc();
71+
return (
72+
<div className="row">
73+
<div className={clsx('col', !docTOC.hidden && styles.docItemCol)}>
74+
<ContentVisibility metadata={metadata} />
75+
<DocVersionBanner />
76+
<div className={styles.docItemContainer}>
77+
<article>
78+
<DocBreadcrumbs />
79+
<DocVersionBadge />
80+
{docTOC.mobile}
81+
<DocItemCopyPageButton
82+
className={clsx(
83+
styles.copyPageArticleAction,
84+
docTOC.canRender && styles.copyPageArticleActionWithToc
85+
)}
86+
/>
87+
<DocItemContent>{children}</DocItemContent>
88+
<DocItemFooter />
89+
</article>
90+
<DocItemPaginator />
91+
</div>
92+
</div>
93+
{docTOC.desktop && (
94+
<div className="col col--3">
95+
<DocItemCopyPageButton className={styles.copyPageAsideAction} />
96+
{docTOC.desktop}
97+
</div>
98+
)}
99+
</div>
100+
);
101+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
.docItemContainer header + *,
9+
.docItemContainer article > *:first-child {
10+
margin-top: 0;
11+
}
12+
13+
.copyPageAction {
14+
display: flex;
15+
}
16+
17+
.copyPageArticleAction {
18+
justify-content: flex-end;
19+
min-height: 37px;
20+
margin-bottom: 1rem;
21+
}
22+
23+
.copyPageAsideAction {
24+
display: none;
25+
margin-bottom: 1rem;
26+
}
27+
28+
.copyPageButtonContainer {
29+
display: inline-block;
30+
}
31+
32+
.copyPageButton {
33+
font-family: var(--ifm-font-family-base);
34+
}
35+
36+
.copyPageDropdown {
37+
font-family: var(--ifm-font-family-base);
38+
}
39+
40+
@media (min-width: 997px) {
41+
.docItemCol {
42+
max-width: 75% !important;
43+
}
44+
45+
.copyPageArticleActionWithToc {
46+
display: none;
47+
}
48+
49+
.copyPageAsideAction {
50+
display: flex;
51+
justify-content: flex-start;
52+
min-height: 37px;
53+
}
54+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
declare module 'docusaurus-plugin-copy-page-button/src/CopyPageButton' {
9+
import type {ComponentType, CSSProperties} from 'react';
10+
11+
type StyleConfig = {
12+
className?: string;
13+
style?: CSSProperties;
14+
};
15+
16+
type CustomStyles = {
17+
container?: StyleConfig;
18+
button?: StyleConfig;
19+
dropdown?: StyleConfig;
20+
dropdownItem?: StyleConfig;
21+
};
22+
23+
type CopyPageButtonProps = {
24+
customStyles?: CustomStyles;
25+
enabledActions?: Array<'copy' | 'view' | 'chatgpt' | 'claude' | 'gemini'>;
26+
generateMarkdownRoutes?: boolean;
27+
};
28+
29+
const CopyPageButton: ComponentType<CopyPageButtonProps>;
30+
export default CopyPageButton;
31+
}

0 commit comments

Comments
 (0)