-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #937 from PaloAltoNetworks/layout-paginator
Conditionally set col width for api doc layout
- Loading branch information
Showing
6 changed files
with
106 additions
and
3 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
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
82 changes: 82 additions & 0 deletions
82
packages/docusaurus-theme-openapi-docs/src/theme/ApiItem/Layout/index.tsx
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,82 @@ | ||
/* ============================================================================ | ||
* Copyright (c) Palo Alto Networks | ||
* | ||
* 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 { useDoc } from "@docusaurus/plugin-content-docs/client"; | ||
import { useWindowSize } from "@docusaurus/theme-common"; | ||
import type { Props } from "@theme/ApiItem/Layout"; | ||
import ContentVisibility from "@theme/ContentVisibility"; | ||
import DocBreadcrumbs from "@theme/DocBreadcrumbs"; | ||
import DocItemContent from "@theme/DocItem/Content"; | ||
import DocItemFooter from "@theme/DocItem/Footer"; | ||
import DocItemPaginator from "@theme/DocItem/Paginator"; | ||
import DocItemTOCDesktop from "@theme/DocItem/TOC/Desktop"; | ||
import DocItemTOCMobile from "@theme/DocItem/TOC/Mobile"; | ||
import DocVersionBadge from "@theme/DocVersionBadge"; | ||
import DocVersionBanner from "@theme/DocVersionBanner"; | ||
import clsx from "clsx"; | ||
|
||
import styles from "./styles.module.css"; | ||
|
||
/** | ||
* Decide if the toc should be rendered, on mobile or desktop viewports | ||
*/ | ||
function useDocTOC() { | ||
const { frontMatter, toc } = useDoc(); | ||
const windowSize = useWindowSize(); | ||
|
||
const hidden = frontMatter.hide_table_of_contents; | ||
const canRender = !hidden && toc.length > 0; | ||
|
||
const mobile = canRender ? <DocItemTOCMobile /> : undefined; | ||
|
||
const desktop = | ||
canRender && (windowSize === "desktop" || windowSize === "ssr") ? ( | ||
<DocItemTOCDesktop /> | ||
) : undefined; | ||
|
||
return { | ||
hidden, | ||
mobile, | ||
desktop, | ||
}; | ||
} | ||
|
||
export default function DocItemLayout({ children }: Props): JSX.Element { | ||
const docTOC = useDocTOC(); | ||
const { metadata } = useDoc(); | ||
const { frontMatter } = useDoc(); | ||
const api = frontMatter.api; | ||
return ( | ||
<div className="row"> | ||
<div className={clsx("col", !docTOC.hidden && styles.docItemCol)}> | ||
<ContentVisibility metadata={metadata} /> | ||
<DocVersionBanner /> | ||
<div className={styles.docItemContainer}> | ||
<article> | ||
<DocBreadcrumbs /> | ||
<DocVersionBadge /> | ||
{docTOC.mobile} | ||
<DocItemContent>{children}</DocItemContent> | ||
<div className="row"> | ||
<div className={clsx("col", api ? "col--7" : "col--12")}> | ||
<DocItemFooter /> | ||
</div> | ||
</div> | ||
</article> | ||
<div className="row"> | ||
<div className={clsx("col", api ? "col--7" : "col--12")}> | ||
<DocItemPaginator /> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
{docTOC.desktop && <div className="col col--3">{docTOC.desktop}</div>} | ||
</div> | ||
); | ||
} |
17 changes: 17 additions & 0 deletions
17
packages/docusaurus-theme-openapi-docs/src/theme/ApiItem/Layout/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,17 @@ | ||
/* ============================================================================ | ||
* Copyright (c) Palo Alto Networks | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* ========================================================================== */ | ||
|
||
.docItemContainer header + *, | ||
.docItemContainer article > *:first-child { | ||
margin-top: 0; | ||
} | ||
|
||
@media (min-width: 997px) { | ||
.docItemCol { | ||
max-width: 75% !important; | ||
} | ||
} |
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