Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(theme-classic): DocPage theme refactors polish #7268

Merged
merged 4 commits into from
Apr 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions packages/docusaurus-theme-classic/src/theme-classic.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ declare module '@theme/DocPage/Layout' {
export default function DocPageLayout(props: Props): JSX.Element;
}

declare module '@theme/DocPage/Layout/Aside' {
declare module '@theme/DocPage/Layout/Sidebar' {
import type {Dispatch, SetStateAction} from 'react';
import type {PropSidebar} from '@docusaurus/plugin-content-docs';

Expand All @@ -278,7 +278,17 @@ declare module '@theme/DocPage/Layout/Aside' {
readonly setHiddenSidebarContainer: Dispatch<SetStateAction<boolean>>;
}

export default function DocPageLayoutAside(props: Props): JSX.Element;
export default function DocPageLayoutSidebar(props: Props): JSX.Element;
}

declare module '@theme/DocPage/Layout/Sidebar/ExpandButton' {
export interface Props {
toggleSidebar: () => void;
}

export default function DocPageLayoutSidebarExpandButton(
props: Props,
): JSX.Element;
}

declare module '@theme/DocPage/Layout/Main' {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

.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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import React from 'react';
import {useDocsSidebar} from '@docusaurus/theme-common';

import clsx from 'clsx';
import styles from './styles.module.css';
import styles from './Main.module.css';
import type {Props} from '@theme/DocPage/Layout/Main';

export default function DocPageLayoutMain({
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

@media (min-width: 997px) {
.expandButton {
position: sticky;
top: 0;
height: 100%;
max-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
transition: background-color var(--ifm-transition-fast) ease;
}

.expandButton:hover,
.expandButton:focus {
background-color: var(--ifm-color-emphasis-200);
}

.expandButtonIcon {
transform: rotate(0);
}

[dir='rtl'] .expandButtonIcon {
transform: rotate(180deg);
}

[data-theme='dark'] .expandButton:hover,
[data-theme='dark'] .expandButton:focus {
background-color: var(--collapse-button-bg-color-dark);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import React from 'react';
import IconArrow from '@theme/IconArrow';
import {translate} from '@docusaurus/Translate';
import type {Props} from '@theme/DocPage/Layout/Sidebar/ExpandButton';

import styles from './ExpandButton.module.css';

export default function DocPageLayoutSidebarExpandButton({
toggleSidebar,
}: Props): JSX.Element {
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,32 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

: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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,15 @@

import React, {type ReactNode, useState, useCallback} from 'react';
import DocSidebar from '@theme/DocSidebar';
import IconArrow from '@theme/IconArrow';
import {translate} from '@docusaurus/Translate';
import {useLocation} from '@docusaurus/router';
import type {Props} from '@theme/DocPage/Layout/Aside';
import type {Props} from '@theme/DocPage/Layout/Sidebar';
import ExpandButton from '@theme/DocPage/Layout/Sidebar/ExpandButton';

import clsx from 'clsx';
import styles from './styles.module.css';
import styles from './index.module.css';

import {ThemeClassNames, useDocsSidebar} from '@docusaurus/theme-common';

function SidebarExpandButton({toggleSidebar}: {toggleSidebar: () => void}) {
return (
<div
className={styles.collapsedDocSidebar}
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.expandSidebarButtonIcon} />
</div>
);
}

// Reset sidebar state when sidebar changes
// Use React key to unmount/remount the children
// See https://github.com/facebook/docusaurus/issues/3414
Expand All @@ -54,7 +28,7 @@ function ResetOnSidebarChange({children}: {children: ReactNode}) {
);
}

export default function DocPageLayoutAside({
export default function DocPageLayoutSidebar({
sidebar,
hiddenSidebarContainer,
setHiddenSidebarContainer,
Expand Down Expand Up @@ -94,7 +68,7 @@ export default function DocPageLayoutAside({
/>
</ResetOnSidebarChange>

{hiddenSidebar && <SidebarExpandButton toggleSidebar={toggleSidebar} />}
{hiddenSidebar && <ExpandButton toggleSidebar={toggleSidebar} />}
</aside>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

.docPage {
display: flex;
width: 100%;
}

.docsWrapper {
display: flex;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import React, {useState} from 'react';
import Layout from '@theme/Layout';
import BackToTopButton from '@theme/BackToTopButton';
import type {Props} from '@theme/DocPage/Layout';
import DocPageLayoutAside from '@theme/DocPage/Layout/Aside';
import DocPageLayoutSidebar from '@theme/DocPage/Layout/Sidebar';
import DocPageLayoutMain from '@theme/DocPage/Layout/Main';

import styles from './styles.module.css';
import styles from './index.module.css';

import {useDocsSidebar} from '@docusaurus/theme-common';

Expand All @@ -24,7 +24,7 @@ export default function DocPageLayout({children}: Props): JSX.Element {
<BackToTopButton />
<div className={styles.docPage}>
{sidebar && (
<DocPageLayoutAside
<DocPageLayoutSidebar
sidebar={sidebar.items}
hiddenSidebarContainer={hiddenSidebarContainer}
setHiddenSidebarContainer={setHiddenSidebarContainer}
Expand Down

This file was deleted.

Loading