Skip to content

Commit de1099e

Browse files
authored
Merge pull request #937 from PaloAltoNetworks/layout-paginator
Conditionally set col width for api doc layout
2 parents db293ef + 3aa8916 commit de1099e

File tree

6 files changed

+106
-3
lines changed

6 files changed

+106
-3
lines changed

packages/docusaurus-theme-openapi-docs/src/plugin-content-docs.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@ declare module "@docusaurus/plugin-content-docs/client" {
1515
children: ReactNode;
1616
content: PropDocContent;
1717
});
18+
19+
export function useDoc();
1820
}

packages/docusaurus-theme-openapi-docs/src/theme-classic.d.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ declare module "@docusaurus/theme-common/internal" {
2727
export interface LineProps extends ILineProps {}
2828
export interface CodeBlockProps extends ICodeBlockProps {}
2929

30-
export function useDoc();
31-
3230
export function usePrismTheme(): PrismTheme;
3331

3432
export function sanitizeTabsChildren(children: TabProps["children"]);

packages/docusaurus-theme-openapi-docs/src/theme-openapi.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ declare module "@theme/ApiItem/hooks" {
5454
}
5555

5656
declare module "@theme/ApiItem/Layout" {
57+
export interface Props {
58+
readonly children: JSX.Element;
59+
}
60+
5761
export default function Layout(props: any): JSX.Element;
5862
}
5963

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/* ============================================================================
2+
* Copyright (c) Palo Alto Networks
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
* ========================================================================== */
7+
8+
import React from "react";
9+
10+
import { useDoc } from "@docusaurus/plugin-content-docs/client";
11+
import { useWindowSize } from "@docusaurus/theme-common";
12+
import type { Props } from "@theme/ApiItem/Layout";
13+
import ContentVisibility from "@theme/ContentVisibility";
14+
import DocBreadcrumbs from "@theme/DocBreadcrumbs";
15+
import DocItemContent from "@theme/DocItem/Content";
16+
import DocItemFooter from "@theme/DocItem/Footer";
17+
import DocItemPaginator from "@theme/DocItem/Paginator";
18+
import DocItemTOCDesktop from "@theme/DocItem/TOC/Desktop";
19+
import DocItemTOCMobile from "@theme/DocItem/TOC/Mobile";
20+
import DocVersionBadge from "@theme/DocVersionBadge";
21+
import DocVersionBanner from "@theme/DocVersionBanner";
22+
import clsx from "clsx";
23+
24+
import styles from "./styles.module.css";
25+
26+
/**
27+
* Decide if the toc should be rendered, on mobile or desktop viewports
28+
*/
29+
function useDocTOC() {
30+
const { frontMatter, toc } = useDoc();
31+
const windowSize = useWindowSize();
32+
33+
const hidden = frontMatter.hide_table_of_contents;
34+
const canRender = !hidden && toc.length > 0;
35+
36+
const mobile = canRender ? <DocItemTOCMobile /> : undefined;
37+
38+
const desktop =
39+
canRender && (windowSize === "desktop" || windowSize === "ssr") ? (
40+
<DocItemTOCDesktop />
41+
) : undefined;
42+
43+
return {
44+
hidden,
45+
mobile,
46+
desktop,
47+
};
48+
}
49+
50+
export default function DocItemLayout({ children }: Props): JSX.Element {
51+
const docTOC = useDocTOC();
52+
const { metadata } = useDoc();
53+
const { frontMatter } = useDoc();
54+
const api = frontMatter.api;
55+
return (
56+
<div className="row">
57+
<div className={clsx("col", !docTOC.hidden && styles.docItemCol)}>
58+
<ContentVisibility metadata={metadata} />
59+
<DocVersionBanner />
60+
<div className={styles.docItemContainer}>
61+
<article>
62+
<DocBreadcrumbs />
63+
<DocVersionBadge />
64+
{docTOC.mobile}
65+
<DocItemContent>{children}</DocItemContent>
66+
<div className="row">
67+
<div className={clsx("col", api ? "col--7" : "col--12")}>
68+
<DocItemFooter />
69+
</div>
70+
</div>
71+
</article>
72+
<div className="row">
73+
<div className={clsx("col", api ? "col--7" : "col--12")}>
74+
<DocItemPaginator />
75+
</div>
76+
</div>
77+
</div>
78+
</div>
79+
{docTOC.desktop && <div className="col col--3">{docTOC.desktop}</div>}
80+
</div>
81+
);
82+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/* ============================================================================
2+
* Copyright (c) Palo Alto Networks
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
* ========================================================================== */
7+
8+
.docItemContainer header + *,
9+
.docItemContainer article > *:first-child {
10+
margin-top: 0;
11+
}
12+
13+
@media (min-width: 997px) {
14+
.docItemCol {
15+
max-width: 75% !important;
16+
}
17+
}

packages/docusaurus-theme-openapi-docs/src/theme/ApiItem/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ import useDocusaurusContext from "@docusaurus/useDocusaurusContext";
1717
import useIsBrowser from "@docusaurus/useIsBrowser";
1818
import { createAuth } from "@theme/ApiExplorer/Authorization/slice";
1919
import { createPersistanceMiddleware } from "@theme/ApiExplorer/persistanceMiddleware";
20+
import DocItemLayout from "@theme/ApiItem/Layout";
2021
import type { Props } from "@theme/DocItem";
21-
import DocItemLayout from "@theme/DocItem/Layout";
2222
import DocItemMetadata from "@theme/DocItem/Metadata";
2323
import clsx from "clsx";
2424
import { ServerObject } from "docusaurus-plugin-openapi-docs/src/openapi/types";

0 commit comments

Comments
 (0)