Skip to content

Commit

Permalink
docs table horizontal scroll fix (#11845)
Browse files Browse the repository at this point in the history
  • Loading branch information
pintusoliya authored Aug 29, 2024
1 parent d6f2ce3 commit 6d7a6ad
Show file tree
Hide file tree
Showing 12 changed files with 281 additions and 14 deletions.
13 changes: 13 additions & 0 deletions website/src/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,19 @@ h1.blogPostTitle_src-theme-BlogPostItem-styles-module{
margin-left: 8px;
}

.locale-dropdown-wrapper {
display: flex;
align-items: center;
&:hover {
path {
stroke: var(--ifm-navbar-link-hover-color);
}
}
&:after {
display: none !important;
}
}

@media(max-width:1524px) {
.navbar__item {
padding: var(--ifm-navbar-item-padding-vertical) 7px;
Expand Down
23 changes: 23 additions & 0 deletions website/src/theme/DocRoot/Layout/Main/index.js
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>
);
}
21 changes: 21 additions & 0 deletions website/src/theme/DocRoot/Layout/Main/styles.module.css
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 website/src/theme/DocRoot/Layout/Sidebar/ExpandButton/index.js
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>
);
}
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);
}
}
70 changes: 70 additions & 0 deletions website/src/theme/DocRoot/Layout/Sidebar/index.js
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 website/src/theme/DocRoot/Layout/Sidebar/styles.module.css
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;
}
}
27 changes: 27 additions & 0 deletions website/src/theme/DocRoot/Layout/index.js
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>
);
}
9 changes: 9 additions & 0 deletions website/src/theme/DocRoot/Layout/styles.module.css
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;
}
30 changes: 30 additions & 0 deletions website/src/theme/DocRoot/index.js
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>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default function LocaleDropdownNavbarItem({
<DropdownNavbarItem
{...props}
mobile={mobile}
className={styles.wrapper}
className='locale-dropdown-wrapper'
label={
<>
<IconLanguage className={styles.iconLaynguage} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,3 @@
.globeIcon {
margin-left: 5.5px;
}

.wrapper {
display: flex;
align-items: center;
&:hover {
path {
stroke: var(--ifm-navbar-link-hover-color);
}
}
&:after {
display: none !important;
}
}

0 comments on commit 6d7a6ad

Please sign in to comment.