@docusaurus/theme-classic 3.8.1-canary-6384 → 3.8.1-canary-6386

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.
@@ -6,4 +6,4 @@
6
6
  */
7
7
  import { type ReactNode } from 'react';
8
8
  import type { Props } from '@theme/DocSidebarItem/Category';
9
- export default function DocSidebarItemCategory({ item, onItemClick, activePath, level, index, ...props }: Props): ReactNode;
9
+ export default function DocSidebarItemCategory(props: Props): ReactNode;
@@ -18,11 +18,13 @@ import {
18
18
  isActiveSidebarItem,
19
19
  findFirstSidebarItemLink,
20
20
  useDocSidebarItemsExpandedState,
21
+ useVisibleSidebarItems,
21
22
  } from '@docusaurus/plugin-content-docs/client';
22
23
  import Link from '@docusaurus/Link';
23
24
  import {translate} from '@docusaurus/Translate';
24
25
  import useIsBrowser from '@docusaurus/useIsBrowser';
25
26
  import DocSidebarItems from '@theme/DocSidebarItems';
27
+ import DocSidebarItemLink from '@theme/DocSidebarItem/Link';
26
28
  import styles from './styles.module.css';
27
29
  // If we navigate to a category and it becomes active, it should automatically
28
30
  // expand itself
@@ -108,7 +110,43 @@ function CategoryLinkLabel({label}) {
108
110
  </span>
109
111
  );
110
112
  }
111
- export default function DocSidebarItemCategory({
113
+ export default function DocSidebarItemCategory(props) {
114
+ const visibleChildren = useVisibleSidebarItems(
115
+ props.item.items,
116
+ props.activePath,
117
+ );
118
+ if (visibleChildren.length === 0) {
119
+ return <DocSidebarItemCategoryEmpty {...props} />;
120
+ } else {
121
+ return <DocSidebarItemCategoryCollapsible {...props} />;
122
+ }
123
+ }
124
+ function isCategoryWithHref(category) {
125
+ return typeof category.href === 'string';
126
+ }
127
+ // If a category doesn't have any visible children, we render it as a link
128
+ function DocSidebarItemCategoryEmpty({item, ...props}) {
129
+ // If the category has no link, we don't render anything
130
+ // It's not super useful to render a category you can't open nor click
131
+ if (!isCategoryWithHref(item)) {
132
+ return null;
133
+ }
134
+ // We remove props that don't make sense for a link and forward the rest
135
+ const {
136
+ type,
137
+ collapsed,
138
+ collapsible,
139
+ items,
140
+ linkUnlisted,
141
+ ...forwardableProps
142
+ } = item;
143
+ const linkItem = {
144
+ type: 'link',
145
+ ...forwardableProps,
146
+ };
147
+ return <DocSidebarItemLink item={linkItem} {...props} />;
148
+ }
149
+ function DocSidebarItemCategoryCollapsible({
112
150
  item,
113
151
  onItemClick,
114
152
  activePath,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/theme-classic",
3
- "version": "3.8.1-canary-6384",
3
+ "version": "3.8.1-canary-6386",
4
4
  "description": "Classic theme for Docusaurus",
5
5
  "main": "lib/index.js",
6
6
  "types": "src/theme-classic.d.ts",
@@ -20,19 +20,19 @@
20
20
  "copy:watch": "node ../../admin/scripts/copyUntypedFiles.js --watch"
21
21
  },
22
22
  "dependencies": {
23
- "@docusaurus/core": "3.8.1-canary-6384",
24
- "@docusaurus/logger": "3.8.1-canary-6384",
25
- "@docusaurus/mdx-loader": "3.8.1-canary-6384",
26
- "@docusaurus/module-type-aliases": "3.8.1-canary-6384",
27
- "@docusaurus/plugin-content-blog": "3.8.1-canary-6384",
28
- "@docusaurus/plugin-content-docs": "3.8.1-canary-6384",
29
- "@docusaurus/plugin-content-pages": "3.8.1-canary-6384",
30
- "@docusaurus/theme-common": "3.8.1-canary-6384",
31
- "@docusaurus/theme-translations": "3.8.1-canary-6384",
32
- "@docusaurus/types": "3.8.1-canary-6384",
33
- "@docusaurus/utils": "3.8.1-canary-6384",
34
- "@docusaurus/utils-common": "3.8.1-canary-6384",
35
- "@docusaurus/utils-validation": "3.8.1-canary-6384",
23
+ "@docusaurus/core": "3.8.1-canary-6386",
24
+ "@docusaurus/logger": "3.8.1-canary-6386",
25
+ "@docusaurus/mdx-loader": "3.8.1-canary-6386",
26
+ "@docusaurus/module-type-aliases": "3.8.1-canary-6386",
27
+ "@docusaurus/plugin-content-blog": "3.8.1-canary-6386",
28
+ "@docusaurus/plugin-content-docs": "3.8.1-canary-6386",
29
+ "@docusaurus/plugin-content-pages": "3.8.1-canary-6386",
30
+ "@docusaurus/theme-common": "3.8.1-canary-6386",
31
+ "@docusaurus/theme-translations": "3.8.1-canary-6386",
32
+ "@docusaurus/types": "3.8.1-canary-6386",
33
+ "@docusaurus/utils": "3.8.1-canary-6386",
34
+ "@docusaurus/utils-common": "3.8.1-canary-6386",
35
+ "@docusaurus/utils-validation": "3.8.1-canary-6386",
36
36
  "@mdx-js/react": "^3.0.0",
37
37
  "clsx": "^2.0.0",
38
38
  "copy-text-to-clipboard": "^3.2.0",
@@ -62,5 +62,5 @@
62
62
  "engines": {
63
63
  "node": ">=18.0"
64
64
  },
65
- "gitHead": "1f293331ed8aeb0d81fd0856b88b4329cc263dda"
65
+ "gitHead": "588d7e70cceaaaaf7218b0834ee3623e5aa1fe0b"
66
66
  }
@@ -24,13 +24,19 @@ import {
24
24
  isActiveSidebarItem,
25
25
  findFirstSidebarItemLink,
26
26
  useDocSidebarItemsExpandedState,
27
+ useVisibleSidebarItems,
27
28
  } from '@docusaurus/plugin-content-docs/client';
28
29
  import Link from '@docusaurus/Link';
29
30
  import {translate} from '@docusaurus/Translate';
30
31
  import useIsBrowser from '@docusaurus/useIsBrowser';
31
32
  import DocSidebarItems from '@theme/DocSidebarItems';
33
+ import DocSidebarItemLink from '@theme/DocSidebarItem/Link';
32
34
  import type {Props} from '@theme/DocSidebarItem/Category';
33
35
 
36
+ import type {
37
+ PropSidebarItemCategory,
38
+ PropSidebarItemLink,
39
+ } from '@docusaurus/plugin-content-docs';
34
40
  import styles from './styles.module.css';
35
41
 
36
42
  // If we navigate to a category and it becomes active, it should automatically
@@ -136,7 +142,48 @@ function CategoryLinkLabel({label}: {label: string}) {
136
142
  );
137
143
  }
138
144
 
139
- export default function DocSidebarItemCategory({
145
+ export default function DocSidebarItemCategory(props: Props): ReactNode {
146
+ const visibleChildren = useVisibleSidebarItems(
147
+ props.item.items,
148
+ props.activePath,
149
+ );
150
+ if (visibleChildren.length === 0) {
151
+ return <DocSidebarItemCategoryEmpty {...props} />;
152
+ } else {
153
+ return <DocSidebarItemCategoryCollapsible {...props} />;
154
+ }
155
+ }
156
+
157
+ function isCategoryWithHref(
158
+ category: PropSidebarItemCategory,
159
+ ): category is PropSidebarItemCategory & {href: string} {
160
+ return typeof category.href === 'string';
161
+ }
162
+
163
+ // If a category doesn't have any visible children, we render it as a link
164
+ function DocSidebarItemCategoryEmpty({item, ...props}: Props): ReactNode {
165
+ // If the category has no link, we don't render anything
166
+ // It's not super useful to render a category you can't open nor click
167
+ if (!isCategoryWithHref(item)) {
168
+ return null;
169
+ }
170
+ // We remove props that don't make sense for a link and forward the rest
171
+ const {
172
+ type,
173
+ collapsed,
174
+ collapsible,
175
+ items,
176
+ linkUnlisted,
177
+ ...forwardableProps
178
+ } = item;
179
+ const linkItem: PropSidebarItemLink = {
180
+ type: 'link',
181
+ ...forwardableProps,
182
+ };
183
+ return <DocSidebarItemLink item={linkItem} {...props} />;
184
+ }
185
+
186
+ function DocSidebarItemCategoryCollapsible({
140
187
  item,
141
188
  onItemClick,
142
189
  activePath,