@docusaurus/theme-classic 0.0.0-4778 → 0.0.0-4783

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -235,6 +235,40 @@ declare module '@theme/DocSidebarItem' {
235
235
  export default function DocSidebarItem(props: Props): JSX.Element;
236
236
  }
237
237
 
238
+ declare module '@theme/DocSidebarItem/Link' {
239
+ import type {Props as DocSidebarItemProps} from '@theme/DocSidebarItem';
240
+
241
+ import type {PropSidebarItemLink} from '@docusaurus/plugin-content-docs';
242
+
243
+ export interface Props extends DocSidebarItemProps {
244
+ item: PropSidebarItemLink;
245
+ }
246
+
247
+ export default function DocSidebarItemLink(props: Props): JSX.Element;
248
+ }
249
+
250
+ declare module '@theme/DocSidebarItem/Html' {
251
+ import type {Props as DocSidebarItemProps} from '@theme/DocSidebarItem';
252
+ import type {PropSidebarItemHtml} from '@docusaurus/plugin-content-docs';
253
+
254
+ export interface Props extends DocSidebarItemProps {
255
+ item: PropSidebarItemHtml;
256
+ }
257
+
258
+ export default function DocSidebarItemHtml(props: Props): JSX.Element;
259
+ }
260
+
261
+ declare module '@theme/DocSidebarItem/Category' {
262
+ import type {Props as DocSidebarItemProps} from '@theme/DocSidebarItem';
263
+ import type {PropSidebarItemCategory} from '@docusaurus/plugin-content-docs';
264
+
265
+ export interface Props extends DocSidebarItemProps {
266
+ item: PropSidebarItemCategory;
267
+ }
268
+
269
+ export default function DocSidebarItemCategory(props: Props): JSX.Element;
270
+ }
271
+
238
272
  declare module '@theme/DocSidebarItems' {
239
273
  import type {Props as DocSidebarItemProps} from '@theme/DocSidebarItem';
240
274
  import type {PropSidebarItem} from '@docusaurus/plugin-content-docs';
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
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
+ import React, {useState, useCallback} from 'react';
8
+ import DocSidebar from '@theme/DocSidebar';
9
+ import IconArrow from '@theme/IconArrow';
10
+ import {translate} from '@docusaurus/Translate';
11
+ import {useLocation} from '@docusaurus/router';
12
+ import clsx from 'clsx';
13
+ import styles from './styles.module.css';
14
+ import {ThemeClassNames, useDocsSidebar} from '@docusaurus/theme-common';
15
+
16
+ function SidebarExpandButton({toggleSidebar}) {
17
+ return (
18
+ <div
19
+ className={styles.collapsedDocSidebar}
20
+ title={translate({
21
+ id: 'theme.docs.sidebar.expandButtonTitle',
22
+ message: 'Expand sidebar',
23
+ description:
24
+ 'The ARIA label and title attribute for expand button of doc sidebar',
25
+ })}
26
+ aria-label={translate({
27
+ id: 'theme.docs.sidebar.expandButtonAriaLabel',
28
+ message: 'Expand sidebar',
29
+ description:
30
+ 'The ARIA label and title attribute for expand button of doc sidebar',
31
+ })}
32
+ tabIndex={0}
33
+ role="button"
34
+ onKeyDown={toggleSidebar}
35
+ onClick={toggleSidebar}>
36
+ <IconArrow className={styles.expandSidebarButtonIcon} />
37
+ </div>
38
+ );
39
+ } // Reset sidebar state when sidebar changes
40
+ // Use React key to unmount/remount the children
41
+ // See https://github.com/facebook/docusaurus/issues/3414
42
+
43
+ function ResetOnSidebarChange({children}) {
44
+ const sidebar = useDocsSidebar();
45
+ return (
46
+ <React.Fragment key={sidebar?.name ?? 'noSidebar'}>
47
+ {children}
48
+ </React.Fragment>
49
+ );
50
+ }
51
+
52
+ export default function DocPageLayoutAside({
53
+ sidebar,
54
+ hiddenSidebarContainer,
55
+ setHiddenSidebarContainer,
56
+ }) {
57
+ const {pathname} = useLocation();
58
+ const [hiddenSidebar, setHiddenSidebar] = useState(false);
59
+ const toggleSidebar = useCallback(() => {
60
+ if (hiddenSidebar) {
61
+ setHiddenSidebar(false);
62
+ }
63
+
64
+ setHiddenSidebarContainer((value) => !value);
65
+ }, [setHiddenSidebarContainer, hiddenSidebar]);
66
+ return (
67
+ <aside
68
+ className={clsx(
69
+ ThemeClassNames.docs.docSidebarContainer,
70
+ styles.docSidebarContainer,
71
+ hiddenSidebarContainer && styles.docSidebarContainerHidden,
72
+ )}
73
+ onTransitionEnd={(e) => {
74
+ if (!e.currentTarget.classList.contains(styles.docSidebarContainer)) {
75
+ return;
76
+ }
77
+
78
+ if (hiddenSidebarContainer) {
79
+ setHiddenSidebar(true);
80
+ }
81
+ }}>
82
+ <ResetOnSidebarChange>
83
+ <DocSidebar
84
+ sidebar={sidebar}
85
+ path={pathname}
86
+ onCollapse={toggleSidebar}
87
+ isHidden={hiddenSidebar}
88
+ />
89
+ </ResetOnSidebarChange>
90
+
91
+ {hiddenSidebar && <SidebarExpandButton toggleSidebar={toggleSidebar} />}
92
+ </aside>
93
+ );
94
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
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
+ import React from 'react';
8
+ import {useDocsSidebar} from '@docusaurus/theme-common';
9
+ import clsx from 'clsx';
10
+ import styles from './styles.module.css';
11
+ export default function DocPageLayoutMain({hiddenSidebarContainer, children}) {
12
+ const sidebar = useDocsSidebar();
13
+ return (
14
+ <main
15
+ className={clsx(
16
+ styles.docMainContainer,
17
+ (hiddenSidebarContainer || !sidebar) && styles.docMainContainerEnhanced,
18
+ )}>
19
+ <div
20
+ className={clsx(
21
+ 'container padding-top--md padding-bottom--lg',
22
+ styles.docItemWrapper,
23
+ hiddenSidebarContainer && styles.docItemWrapperEnhanced,
24
+ )}>
25
+ {children}
26
+ </div>
27
+ </main>
28
+ );
29
+ }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
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
+ import React, {useState} from 'react';
8
+ import Layout from '@theme/Layout';
9
+ import BackToTopButton from '@theme/BackToTopButton';
10
+ import DocPageLayoutAside from '@theme/DocPage/Layout/Aside';
11
+ import DocPageLayoutMain from '@theme/DocPage/Layout/Main';
12
+ import styles from './styles.module.css';
13
+ import {useDocsSidebar} from '@docusaurus/theme-common';
14
+ export default function DocPageLayout({children}) {
15
+ const sidebar = useDocsSidebar();
16
+ const [hiddenSidebarContainer, setHiddenSidebarContainer] = useState(false);
17
+ return (
18
+ <Layout>
19
+ <BackToTopButton />
20
+ <div className={styles.docPage}>
21
+ {sidebar && (
22
+ <DocPageLayoutAside
23
+ sidebar={sidebar.items}
24
+ hiddenSidebarContainer={hiddenSidebarContainer}
25
+ setHiddenSidebarContainer={setHiddenSidebarContainer}
26
+ />
27
+ )}
28
+ <DocPageLayoutMain hiddenSidebarContainer={hiddenSidebarContainer}>
29
+ {children}
30
+ </DocPageLayoutMain>
31
+ </div>
32
+ </Layout>
33
+ );
34
+ }
@@ -4,132 +4,22 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import React, {useState, useCallback} from 'react';
7
+ import React from 'react';
8
8
  import renderRoutes from '@docusaurus/renderRoutes';
9
- import Layout from '@theme/Layout';
10
- import DocSidebar from '@theme/DocSidebar';
11
9
  import NotFound from '@theme/NotFound';
12
- import IconArrow from '@theme/IconArrow';
13
- import BackToTopButton from '@theme/BackToTopButton';
10
+ import DocPageLayout from '@theme/DocPage/Layout';
14
11
  import {matchPath} from '@docusaurus/router';
15
- import {translate} from '@docusaurus/Translate';
16
12
  import clsx from 'clsx';
17
- import styles from './styles.module.css';
18
13
  import {
19
14
  HtmlClassNameProvider,
20
15
  ThemeClassNames,
21
16
  docVersionSearchTag,
22
17
  DocsSidebarProvider,
23
- useDocsSidebar,
24
18
  DocsVersionProvider,
25
19
  } from '@docusaurus/theme-common';
26
20
  import SearchMetadata from '@theme/SearchMetadata';
27
21
 
28
- function DocPageContent({
29
- currentDocRoute,
30
- versionMetadata,
31
- children,
32
- sidebarName,
33
- }) {
34
- const sidebar = useDocsSidebar();
35
- const {pluginId, version} = versionMetadata;
36
- const [hiddenSidebarContainer, setHiddenSidebarContainer] = useState(false);
37
- const [hiddenSidebar, setHiddenSidebar] = useState(false);
38
- const toggleSidebar = useCallback(() => {
39
- if (hiddenSidebar) {
40
- setHiddenSidebar(false);
41
- }
42
-
43
- setHiddenSidebarContainer((value) => !value);
44
- }, [hiddenSidebar]);
45
- return (
46
- <>
47
- <SearchMetadata
48
- version={version}
49
- tag={docVersionSearchTag(pluginId, version)}
50
- />
51
- <Layout>
52
- <div className={styles.docPage}>
53
- <BackToTopButton />
54
-
55
- {sidebar && (
56
- <aside
57
- className={clsx(
58
- ThemeClassNames.docs.docSidebarContainer,
59
- styles.docSidebarContainer,
60
- hiddenSidebarContainer && styles.docSidebarContainerHidden,
61
- )}
62
- onTransitionEnd={(e) => {
63
- if (
64
- !e.currentTarget.classList.contains(
65
- styles.docSidebarContainer,
66
- )
67
- ) {
68
- return;
69
- }
70
-
71
- if (hiddenSidebarContainer) {
72
- setHiddenSidebar(true);
73
- }
74
- }}>
75
- <DocSidebar
76
- key={
77
- // Reset sidebar state on sidebar changes
78
- // See https://github.com/facebook/docusaurus/issues/3414
79
- sidebarName
80
- }
81
- sidebar={sidebar}
82
- path={currentDocRoute.path}
83
- onCollapse={toggleSidebar}
84
- isHidden={hiddenSidebar}
85
- />
86
-
87
- {hiddenSidebar && (
88
- <div
89
- className={styles.collapsedDocSidebar}
90
- title={translate({
91
- id: 'theme.docs.sidebar.expandButtonTitle',
92
- message: 'Expand sidebar',
93
- description:
94
- 'The ARIA label and title attribute for expand button of doc sidebar',
95
- })}
96
- aria-label={translate({
97
- id: 'theme.docs.sidebar.expandButtonAriaLabel',
98
- message: 'Expand sidebar',
99
- description:
100
- 'The ARIA label and title attribute for expand button of doc sidebar',
101
- })}
102
- tabIndex={0}
103
- role="button"
104
- onKeyDown={toggleSidebar}
105
- onClick={toggleSidebar}>
106
- <IconArrow className={styles.expandSidebarButtonIcon} />
107
- </div>
108
- )}
109
- </aside>
110
- )}
111
- <main
112
- className={clsx(
113
- styles.docMainContainer,
114
- (hiddenSidebarContainer || !sidebar) &&
115
- styles.docMainContainerEnhanced,
116
- )}>
117
- <div
118
- className={clsx(
119
- 'container padding-top--md padding-bottom--lg',
120
- styles.docItemWrapper,
121
- hiddenSidebarContainer && styles.docItemWrapperEnhanced,
122
- )}>
123
- {children}
124
- </div>
125
- </main>
126
- </div>
127
- </Layout>
128
- </>
129
- );
130
- }
131
-
132
- export default function DocPage(props) {
22
+ function extractDocRouteMetadata(props) {
133
23
  const {
134
24
  route: {routes: docRoutes},
135
25
  versionMetadata,
@@ -140,32 +30,53 @@ export default function DocPage(props) {
140
30
  );
141
31
 
142
32
  if (!currentDocRoute) {
143
- return <NotFound />;
33
+ return null;
144
34
  } // For now, the sidebarName is added as route config: not ideal!
145
35
 
146
36
  const sidebarName = currentDocRoute.sidebar;
147
- const sidebar = sidebarName
37
+ const sidebarItems = sidebarName
148
38
  ? versionMetadata.docsSidebars[sidebarName]
149
- : null;
39
+ : undefined;
40
+ const docElement = renderRoutes(props.route.routes, {
41
+ versionMetadata,
42
+ });
43
+ return {
44
+ docElement,
45
+ sidebarName,
46
+ sidebarItems,
47
+ };
48
+ }
49
+
50
+ export default function DocPage(props) {
51
+ const {versionMetadata} = props;
52
+ const currentDocRouteMetadata = extractDocRouteMetadata(props);
53
+
54
+ if (!currentDocRouteMetadata) {
55
+ return <NotFound />;
56
+ }
57
+
58
+ const {docElement, sidebarName, sidebarItems} = currentDocRouteMetadata;
150
59
  return (
151
- <HtmlClassNameProvider
152
- className={clsx(
153
- ThemeClassNames.wrapper.docsPages,
154
- ThemeClassNames.page.docsDocPage,
155
- versionMetadata.className,
156
- )}>
157
- <DocsVersionProvider version={versionMetadata}>
158
- <DocsSidebarProvider sidebar={sidebar ?? null}>
159
- <DocPageContent
160
- currentDocRoute={currentDocRoute}
161
- versionMetadata={versionMetadata}
162
- sidebarName={sidebarName}>
163
- {renderRoutes(docRoutes, {
164
- versionMetadata,
165
- })}
166
- </DocPageContent>
167
- </DocsSidebarProvider>
168
- </DocsVersionProvider>
169
- </HtmlClassNameProvider>
60
+ <>
61
+ <SearchMetadata
62
+ version={versionMetadata.version}
63
+ tag={docVersionSearchTag(
64
+ versionMetadata.pluginId,
65
+ versionMetadata.version,
66
+ )}
67
+ />
68
+ <HtmlClassNameProvider
69
+ className={clsx(
70
+ ThemeClassNames.wrapper.docsPages,
71
+ ThemeClassNames.page.docsDocPage,
72
+ props.versionMetadata.className,
73
+ )}>
74
+ <DocsVersionProvider version={versionMetadata}>
75
+ <DocsSidebarProvider name={sidebarName} items={sidebarItems}>
76
+ <DocPageLayout>{docElement}</DocPageLayout>
77
+ </DocsSidebarProvider>
78
+ </DocsVersionProvider>
79
+ </HtmlClassNameProvider>
80
+ </>
170
81
  );
171
82
  }
@@ -0,0 +1,199 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
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
+ import React, {useEffect, useMemo} from 'react';
8
+ import clsx from 'clsx';
9
+ import {
10
+ isActiveSidebarItem,
11
+ usePrevious,
12
+ Collapsible,
13
+ useCollapsible,
14
+ findFirstCategoryLink,
15
+ ThemeClassNames,
16
+ useThemeConfig,
17
+ useDocSidebarItemsExpandedState,
18
+ isSamePath,
19
+ } from '@docusaurus/theme-common';
20
+ import Link from '@docusaurus/Link';
21
+ import {translate} from '@docusaurus/Translate';
22
+ import DocSidebarItems from '@theme/DocSidebarItems';
23
+ import useIsBrowser from '@docusaurus/useIsBrowser'; // If we navigate to a category and it becomes active, it should automatically
24
+ // expand itself
25
+
26
+ function useAutoExpandActiveCategory({isActive, collapsed, setCollapsed}) {
27
+ const wasActive = usePrevious(isActive);
28
+ useEffect(() => {
29
+ const justBecameActive = isActive && !wasActive;
30
+
31
+ if (justBecameActive && collapsed) {
32
+ setCollapsed(false);
33
+ }
34
+ }, [isActive, wasActive, collapsed, setCollapsed]);
35
+ }
36
+ /**
37
+ * When a collapsible category has no link, we still link it to its first child
38
+ * during SSR as a temporary fallback. This allows to be able to navigate inside
39
+ * the category even when JS fails to load, is delayed or simply disabled
40
+ * React hydration becomes an optional progressive enhancement
41
+ * see https://github.com/facebookincubator/infima/issues/36#issuecomment-772543188
42
+ * see https://github.com/facebook/docusaurus/issues/3030
43
+ */
44
+
45
+ function useCategoryHrefWithSSRFallback(item) {
46
+ const isBrowser = useIsBrowser();
47
+ return useMemo(() => {
48
+ if (item.href) {
49
+ return item.href;
50
+ } // In these cases, it's not necessary to render a fallback
51
+ // We skip the "findFirstCategoryLink" computation
52
+
53
+ if (isBrowser || !item.collapsible) {
54
+ return undefined;
55
+ }
56
+
57
+ return findFirstCategoryLink(item);
58
+ }, [item, isBrowser]);
59
+ }
60
+
61
+ function CollapseButton({categoryLabel, onClick}) {
62
+ return (
63
+ <button
64
+ aria-label={translate(
65
+ {
66
+ id: 'theme.DocSidebarItem.toggleCollapsedCategoryAriaLabel',
67
+ message: "Toggle the collapsible sidebar category '{label}'",
68
+ description:
69
+ 'The ARIA label to toggle the collapsible sidebar category',
70
+ },
71
+ {
72
+ label: categoryLabel,
73
+ },
74
+ )}
75
+ type="button"
76
+ className="clean-btn menu__caret"
77
+ onClick={onClick}
78
+ />
79
+ );
80
+ }
81
+
82
+ export default function DocSidebarItemCategory({
83
+ item,
84
+ onItemClick,
85
+ activePath,
86
+ level,
87
+ index,
88
+ ...props
89
+ }) {
90
+ const {items, label, collapsible, className, href} = item;
91
+ const hrefWithSSRFallback = useCategoryHrefWithSSRFallback(item);
92
+ const isActive = isActiveSidebarItem(item, activePath);
93
+ const isCurrentPage = isSamePath(href, activePath);
94
+ const {collapsed, setCollapsed} = useCollapsible({
95
+ // active categories are always initialized as expanded
96
+ // the default (item.collapsed) is only used for non-active categories
97
+ initialState: () => {
98
+ if (!collapsible) {
99
+ return false;
100
+ }
101
+
102
+ return isActive ? false : item.collapsed;
103
+ },
104
+ });
105
+ useAutoExpandActiveCategory({
106
+ isActive,
107
+ collapsed,
108
+ setCollapsed,
109
+ });
110
+ const {expandedItem, setExpandedItem} = useDocSidebarItemsExpandedState();
111
+
112
+ function updateCollapsed(toCollapsed = !collapsed) {
113
+ setExpandedItem(toCollapsed ? null : index);
114
+ setCollapsed(toCollapsed);
115
+ }
116
+
117
+ const {autoCollapseSidebarCategories} = useThemeConfig();
118
+ useEffect(() => {
119
+ if (
120
+ collapsible &&
121
+ expandedItem &&
122
+ expandedItem !== index &&
123
+ autoCollapseSidebarCategories
124
+ ) {
125
+ setCollapsed(true);
126
+ }
127
+ }, [
128
+ collapsible,
129
+ expandedItem,
130
+ index,
131
+ setCollapsed,
132
+ autoCollapseSidebarCategories,
133
+ ]);
134
+ return (
135
+ <li
136
+ className={clsx(
137
+ ThemeClassNames.docs.docSidebarItemCategory,
138
+ ThemeClassNames.docs.docSidebarItemCategoryLevel(level),
139
+ 'menu__list-item',
140
+ {
141
+ 'menu__list-item--collapsed': collapsed,
142
+ },
143
+ className,
144
+ )}>
145
+ <div
146
+ className={clsx('menu__list-item-collapsible', {
147
+ 'menu__list-item-collapsible--active': isCurrentPage,
148
+ })}>
149
+ <Link
150
+ className={clsx('menu__link', {
151
+ 'menu__link--sublist': collapsible,
152
+ 'menu__link--sublist-caret': !href,
153
+ 'menu__link--active': isActive,
154
+ })}
155
+ onClick={
156
+ collapsible
157
+ ? (e) => {
158
+ onItemClick?.(item);
159
+
160
+ if (href) {
161
+ updateCollapsed(false);
162
+ } else {
163
+ e.preventDefault();
164
+ updateCollapsed();
165
+ }
166
+ }
167
+ : () => {
168
+ onItemClick?.(item);
169
+ }
170
+ }
171
+ aria-current={isCurrentPage ? 'page' : undefined}
172
+ aria-expanded={collapsible ? !collapsed : undefined}
173
+ href={collapsible ? hrefWithSSRFallback ?? '#' : hrefWithSSRFallback}
174
+ {...props}>
175
+ {label}
176
+ </Link>
177
+ {href && collapsible && (
178
+ <CollapseButton
179
+ categoryLabel={label}
180
+ onClick={(e) => {
181
+ e.preventDefault();
182
+ updateCollapsed();
183
+ }}
184
+ />
185
+ )}
186
+ </div>
187
+
188
+ <Collapsible lazy as="ul" className="menu__list" collapsed={collapsed}>
189
+ <DocSidebarItems
190
+ items={items}
191
+ tabIndex={collapsed ? -1 : 0}
192
+ onItemClick={onItemClick}
193
+ activePath={activePath}
194
+ level={level + 1}
195
+ />
196
+ </Collapsible>
197
+ </li>
198
+ );
199
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
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
+ import React from 'react';
8
+ import clsx from 'clsx';
9
+ import {ThemeClassNames} from '@docusaurus/theme-common';
10
+ import styles from './Html.module.css';
11
+ export default function DocSidebarItemHtml({item, level, index}) {
12
+ const {value, defaultStyle, className} = item;
13
+ return (
14
+ <li
15
+ className={clsx(
16
+ ThemeClassNames.docs.docSidebarItemLink,
17
+ ThemeClassNames.docs.docSidebarItemLinkLevel(level),
18
+ defaultStyle && `${styles.menuHtmlItem} menu__list-item`,
19
+ className,
20
+ )}
21
+ key={index} // eslint-disable-next-line react/no-danger
22
+ dangerouslySetInnerHTML={{
23
+ __html: value,
24
+ }}
25
+ />
26
+ );
27
+ }
@@ -11,7 +11,3 @@
11
11
  var(--ifm-menu-link-padding-horizontal);
12
12
  }
13
13
  }
14
-
15
- .menuExternalLink {
16
- align-items: center;
17
- }