-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs table horizontal scroll fix (#11845)
- Loading branch information
1 parent
d6f2ce3
commit 6d7a6ad
Showing
12 changed files
with
281 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import React from 'react'; | ||
import clsx from 'clsx'; | ||
import {useDocsSidebar} from '@docusaurus/plugin-content-docs/client'; | ||
import styles from './styles.module.css'; | ||
export default function DocRootLayoutMain({hiddenSidebarContainer, children}) { | ||
const sidebar = useDocsSidebar(); | ||
return ( | ||
<main | ||
className={clsx( | ||
styles.docMainContainer, | ||
(hiddenSidebarContainer || !sidebar) && styles.docMainContainerEnhanced, | ||
)}> | ||
<div | ||
className={clsx( | ||
'container padding-top--md padding-bottom--lg', | ||
styles.docItemWrapper, | ||
hiddenSidebarContainer && styles.docItemWrapperEnhanced, | ||
)}> | ||
{children} | ||
</div> | ||
</main> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
.docMainContainer { | ||
display: flex; | ||
width: 100%; | ||
} | ||
|
||
@media (min-width: 997px) { | ||
.docMainContainer { | ||
flex-grow: 1; | ||
max-width: calc(100% - var(--doc-sidebar-width)); | ||
} | ||
|
||
.docMainContainerEnhanced { | ||
max-width: calc(100% - var(--doc-sidebar-hidden-width)); | ||
} | ||
|
||
.docItemWrapperEnhanced { | ||
max-width: calc( | ||
var(--ifm-container-width) + var(--doc-sidebar-width) | ||
) !important; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
website/src/theme/DocRoot/Layout/Sidebar/ExpandButton/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React from 'react'; | ||
import {translate} from '@docusaurus/Translate'; | ||
import IconArrow from '@theme/Icon/Arrow'; | ||
import styles from './styles.module.css'; | ||
export default function DocRootLayoutSidebarExpandButton({toggleSidebar}) { | ||
return ( | ||
<div | ||
className={styles.expandButton} | ||
title={translate({ | ||
id: 'theme.docs.sidebar.expandButtonTitle', | ||
message: 'Expand sidebar', | ||
description: | ||
'The ARIA label and title attribute for expand button of doc sidebar', | ||
})} | ||
aria-label={translate({ | ||
id: 'theme.docs.sidebar.expandButtonAriaLabel', | ||
message: 'Expand sidebar', | ||
description: | ||
'The ARIA label and title attribute for expand button of doc sidebar', | ||
})} | ||
tabIndex={0} | ||
role="button" | ||
onKeyDown={toggleSidebar} | ||
onClick={toggleSidebar}> | ||
<IconArrow className={styles.expandButtonIcon} /> | ||
</div> | ||
); | ||
} |
27 changes: 27 additions & 0 deletions
27
website/src/theme/DocRoot/Layout/Sidebar/ExpandButton/styles.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
@media (min-width: 997px) { | ||
.expandButton { | ||
position: absolute; | ||
top: 0; | ||
right: 0; | ||
width: 100%; | ||
height: 100%; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
transition: background-color var(--ifm-transition-fast) ease; | ||
background-color: var(--docusaurus-collapse-button-bg); | ||
} | ||
|
||
.expandButton:hover, | ||
.expandButton:focus { | ||
background-color: var(--docusaurus-collapse-button-bg-hover); | ||
} | ||
|
||
.expandButtonIcon { | ||
transform: rotate(0); | ||
} | ||
|
||
[dir='rtl'] .expandButtonIcon { | ||
transform: rotate(180deg); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import React, {useState, useCallback} from 'react'; | ||
import clsx from 'clsx'; | ||
import {prefersReducedMotion, ThemeClassNames} from '@docusaurus/theme-common'; | ||
import {useDocsSidebar} from '@docusaurus/plugin-content-docs/client'; | ||
import {useLocation} from '@docusaurus/router'; | ||
import DocSidebar from '@theme/DocSidebar'; | ||
import ExpandButton from '@theme/DocRoot/Layout/Sidebar/ExpandButton'; | ||
import styles from './styles.module.css'; | ||
// Reset sidebar state when sidebar changes | ||
// Use React key to unmount/remount the children | ||
// See https://github.com/facebook/docusaurus/issues/3414 | ||
function ResetOnSidebarChange({children}) { | ||
const sidebar = useDocsSidebar(); | ||
return ( | ||
<React.Fragment key={sidebar?.name ?? 'noSidebar'}> | ||
{children} | ||
</React.Fragment> | ||
); | ||
} | ||
export default function DocRootLayoutSidebar({ | ||
sidebar, | ||
hiddenSidebarContainer, | ||
setHiddenSidebarContainer, | ||
}) { | ||
const {pathname} = useLocation(); | ||
const [hiddenSidebar, setHiddenSidebar] = useState(false); | ||
const toggleSidebar = useCallback(() => { | ||
if (hiddenSidebar) { | ||
setHiddenSidebar(false); | ||
} | ||
// onTransitionEnd won't fire when sidebar animation is disabled | ||
// fixes https://github.com/facebook/docusaurus/issues/8918 | ||
if (!hiddenSidebar && prefersReducedMotion()) { | ||
setHiddenSidebar(true); | ||
} | ||
setHiddenSidebarContainer((value) => !value); | ||
}, [setHiddenSidebarContainer, hiddenSidebar]); | ||
return ( | ||
<aside | ||
className={clsx( | ||
ThemeClassNames.docs.docSidebarContainer, | ||
styles.docSidebarContainer, | ||
hiddenSidebarContainer && styles.docSidebarContainerHidden, | ||
)} | ||
onTransitionEnd={(e) => { | ||
if (!e.currentTarget.classList.contains(styles.docSidebarContainer)) { | ||
return; | ||
} | ||
if (hiddenSidebarContainer) { | ||
setHiddenSidebar(true); | ||
} | ||
}}> | ||
<ResetOnSidebarChange> | ||
<div | ||
className={clsx( | ||
styles.sidebarViewport, | ||
hiddenSidebar && styles.sidebarViewportHidden, | ||
)}> | ||
<DocSidebar | ||
sidebar={sidebar} | ||
path={pathname} | ||
onCollapse={toggleSidebar} | ||
isHidden={hiddenSidebar} | ||
/> | ||
{hiddenSidebar && <ExpandButton toggleSidebar={toggleSidebar} />} | ||
</div> | ||
</ResetOnSidebarChange> | ||
</aside> | ||
); | ||
} |
32 changes: 32 additions & 0 deletions
32
website/src/theme/DocRoot/Layout/Sidebar/styles.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
:root { | ||
--doc-sidebar-width: 300px; | ||
--doc-sidebar-hidden-width: 30px; | ||
} | ||
|
||
.docSidebarContainer { | ||
display: none; | ||
} | ||
|
||
@media (min-width: 997px) { | ||
.docSidebarContainer { | ||
display: block; | ||
width: var(--doc-sidebar-width); | ||
margin-top: calc(-1 * var(--ifm-navbar-height)); | ||
border-right: 1px solid var(--ifm-toc-border-color); | ||
will-change: width; | ||
transition: width var(--ifm-transition-fast) ease; | ||
clip-path: inset(0); | ||
} | ||
|
||
.docSidebarContainerHidden { | ||
width: var(--doc-sidebar-hidden-width); | ||
cursor: pointer; | ||
} | ||
|
||
.sidebarViewport { | ||
top: 0; | ||
position: sticky; | ||
height: 100%; | ||
max-height: 100vh; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React, {useState} from 'react'; | ||
import {useDocsSidebar} from '@docusaurus/plugin-content-docs/client'; | ||
import BackToTopButton from '@theme/BackToTopButton'; | ||
import DocRootLayoutSidebar from '@theme/DocRoot/Layout/Sidebar'; | ||
import DocRootLayoutMain from '@theme/DocRoot/Layout/Main'; | ||
import styles from './styles.module.css'; | ||
export default function DocRootLayout({children}) { | ||
const sidebar = useDocsSidebar(); | ||
const [hiddenSidebarContainer, setHiddenSidebarContainer] = useState(false); | ||
return ( | ||
<div className={styles.docsWrapper}> | ||
<BackToTopButton /> | ||
<div className={styles.docRoot}> | ||
{sidebar && ( | ||
<DocRootLayoutSidebar | ||
sidebar={sidebar.items} | ||
hiddenSidebarContainer={hiddenSidebarContainer} | ||
setHiddenSidebarContainer={setHiddenSidebarContainer} | ||
/> | ||
)} | ||
<DocRootLayoutMain hiddenSidebarContainer={hiddenSidebarContainer}> | ||
{children} | ||
</DocRootLayoutMain> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.docRoot { | ||
display: flex; | ||
width: 100%; | ||
} | ||
|
||
.docsWrapper { | ||
display: flex; | ||
flex: 1 0 auto; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React from 'react'; | ||
import clsx from 'clsx'; | ||
import {HtmlClassNameProvider, ThemeClassNames} from '@docusaurus/theme-common'; | ||
import { | ||
DocsSidebarProvider, | ||
useDocRootMetadata, | ||
} from '@docusaurus/plugin-content-docs/client'; | ||
import DocRootLayout from '@theme/DocRoot/Layout'; | ||
import NotFoundContent from '@theme/NotFound/Content'; | ||
|
||
const arrayOfPages = (matchPath) => [`${matchPath}/configurations`, `${matchPath}/basic_configurations`, `${matchPath}/timeline`, `${matchPath}/table_types`, `${matchPath}/migration_guide`, `${matchPath}/compaction`, `${matchPath}/clustering`, `${matchPath}/indexing`, `${matchPath}/metadata`, `${matchPath}/metadata_indexing`, `${matchPath}/record_payload`, `${matchPath}/file_sizing`, `${matchPath}/hoodie_cleaner`, `${matchPath}/concurrency_control`, , `${matchPath}/write_operations`, `${matchPath}/key_generation`]; | ||
const showCustomStylesForDocs = (matchPath, pathname) => arrayOfPages(matchPath).includes(pathname); | ||
|
||
export default function DocRoot(props) { | ||
const currentDocRouteMetadata = useDocRootMetadata(props); | ||
if (!currentDocRouteMetadata) { | ||
// We only render the not found content to avoid a double layout | ||
// see https://github.com/facebook/docusaurus/pull/7966#pullrequestreview-1077276692 | ||
return <NotFoundContent />; | ||
} | ||
const {docElement, sidebarName, sidebarItems} = currentDocRouteMetadata; | ||
const addCustomClass = showCustomStylesForDocs(props.match.path, props.location.pathname) | ||
return ( | ||
<HtmlClassNameProvider className={clsx(ThemeClassNames.page.docsDocPage, {'docs-custom-styles': addCustomClass })}> | ||
<DocsSidebarProvider name={sidebarName} items={sidebarItems}> | ||
<DocRootLayout>{docElement}</DocRootLayout> | ||
</DocsSidebarProvider> | ||
</HtmlClassNameProvider> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters