Skip to content

Commit a8683a9

Browse files
committed
chore(): Conditionally render TOC and Demo based on screen size
1 parent 2ed1f90 commit a8683a9

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

docusaurus-theme/src/theme/DocItem/index.tsx

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { MainHeading } from '@theme/Heading';
1616
import clsx from 'clsx';
1717
import styles from './styles.module.scss';
1818
import { useActivePlugin, useVersions } from '@theme/hooks/useDocs';
19+
import useWindowSize, { windowSizes } from '@theme/hooks/useWindowSize';
1920

2021
function DocItem(props) {
2122
const { content: DocContent, versionMetadata } = props;
@@ -39,6 +40,8 @@ function DocItem(props) {
3940
lastUpdatedBy,
4041
} = metadata;
4142

43+
const windowSize = useWindowSize();
44+
4245
const { pluginId } = useActivePlugin({
4346
failfast: true,
4447
});
@@ -124,14 +127,8 @@ function DocItem(props) {
124127
</div>
125128
</div>
126129

127-
{!hideTableOfContents && DocContent.toc ? (
128-
<TOC
129-
toc={DocContent.toc}
130-
editUrl={editUrl}
131-
className={clsx(styles.tableOfContents)}
132-
/>
133-
) : (
134-
demoUrl && (
130+
{windowSize !== windowSizes.mobile &&
131+
(demoUrl ? (
135132
<div
136133
className={clsx(
137134
'docDemoWrapper',
@@ -141,8 +138,16 @@ function DocItem(props) {
141138
>
142139
<DocDemo url={demoUrl} source={demoSourceUrl} />
143140
</div>
144-
)
145-
)}
141+
) : (
142+
!hideTableOfContents &&
143+
DocContent.toc && (
144+
<TOC
145+
toc={DocContent.toc}
146+
editUrl={editUrl}
147+
className={clsx(styles.tableOfContents)}
148+
/>
149+
)
150+
))}
146151
</div>
147152
</>
148153
);

0 commit comments

Comments
 (0)