Skip to content

Commit b76f0fe

Browse files
authored
fix(theme): apply docs sidebar_class_name in DocCard + better dogfooding (#10909)
1 parent 0162f6a commit b76f0fe

File tree

11 files changed

+97
-33
lines changed

11 files changed

+97
-33
lines changed

argos/tests/screenshot.spec.ts

-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ function isBlacklisted(pathname: string) {
5555
'/tests/pages/react-18',
5656
// Flaky because of hydration error
5757
'/tests/blog/archive',
58-
'/tests/docs/tests/custom-props',
5958
'/tests/pages/code-block-tests',
6059
'/tests/pages/embeds',
6160
// Flaky because of hydration error with docusaurus serve + .html

packages/docusaurus-theme-classic/src/theme/DocCard/index.tsx

+8-2
Original file line numberDiff line numberDiff line change
@@ -43,34 +43,38 @@ function useCategoryItemsPlural() {
4343
}
4444

4545
function CardContainer({
46+
className,
4647
href,
4748
children,
4849
}: {
50+
className?: string;
4951
href: string;
5052
children: ReactNode;
5153
}): ReactNode {
5254
return (
5355
<Link
5456
href={href}
55-
className={clsx('card padding--lg', styles.cardContainer)}>
57+
className={clsx('card padding--lg', styles.cardContainer, className)}>
5658
{children}
5759
</Link>
5860
);
5961
}
6062

6163
function CardLayout({
64+
className,
6265
href,
6366
icon,
6467
title,
6568
description,
6669
}: {
70+
className?: string;
6771
href: string;
6872
icon: ReactNode;
6973
title: string;
7074
description?: string;
7175
}): ReactNode {
7276
return (
73-
<CardContainer href={href}>
77+
<CardContainer href={href} className={className}>
7478
<Heading
7579
as="h2"
7680
className={clsx('text--truncate', styles.cardTitle)}
@@ -99,6 +103,7 @@ function CardCategory({item}: {item: PropSidebarItemCategory}): ReactNode {
99103

100104
return (
101105
<CardLayout
106+
className={item.className}
102107
href={href}
103108
icon="🗃️"
104109
title={item.label}
@@ -112,6 +117,7 @@ function CardLink({item}: {item: PropSidebarItemLink}): ReactNode {
112117
const doc = useDocById(item.docId ?? undefined);
113118
return (
114119
<CardLayout
120+
className={item.className}
115121
href={item.href}
116122
icon={icon}
117123
title={item.label}

website/_dogfooding/_docs tests/tests/custom-props/_category_.json

-3
This file was deleted.

website/_dogfooding/_docs tests/tests/custom-props/doc-without-custom-props.mdx

-3
This file was deleted.

website/_dogfooding/_docs tests/tests/custom-props/index.mdx

-22
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
sidebar_class_name: 'dogfood_sidebar_class_name_test'
3+
---
4+
5+
# Doc With Sidebar Class Name
6+
7+
This doc has `sidebar_label` front matter

website/_dogfooding/_docs tests/tests/custom-props/doc-with-custom-props.mdx website/_dogfooding/_docs tests/tests/sidebar-frontmatter/doc-with-sidebar-custom-props.mdx

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ sidebar_custom_props:
55
boolean: true
66
---
77

8-
# Doc with Custom Props
8+
# Doc With Custom Props
99

10-
This doc has custom props.
10+
This doc has `sidebar_custom_props` front matter.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
sidebar_label: Doc With Sidebar Label
3+
---
4+
5+
# Doc with `sidebar_label`
6+
7+
This doc has `sidebar_label` front matter
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Doc Without
2+
3+
This doc doesn't have any `sidebar_` front matter
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
sidebar_label: 'Sidebar Front Matter Tests'
3+
sidebar_class_name: 'dogfood_sidebar_class_name_test'
4+
---
5+
6+
# Sidebar front matter
7+
8+
```mdx-code-block
9+
import Link from '@docusaurus/Link';
10+
import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
11+
import DocCardList from '@theme/DocCardList';
12+
13+
<DocCardList />
14+
15+
---
16+
17+
## Items table
18+
19+
export const DocPropsList = ({category}) => {
20+
const items = [category, ...category.items];
21+
return (
22+
<table>
23+
<thead>
24+
<tr>
25+
<th>
26+
<code>type</code>
27+
</th>
28+
<th>
29+
<code>label</code>
30+
</th>
31+
<th>
32+
<code>customProps</code>
33+
</th>
34+
<th>
35+
<code>className</code>
36+
</th>
37+
</tr>
38+
</thead>
39+
<tbody>
40+
{items.map((item, index) => (
41+
<tr key={index}>
42+
<td>{item.type}</td>
43+
<td>
44+
<Link to={item.href}>{item.label}</Link>
45+
</td>
46+
<td>{JSON.stringify(item.customProps)}</td>
47+
<td>{JSON.stringify(item.className)}</td>
48+
</tr>
49+
))}
50+
</tbody>
51+
</table>
52+
);
53+
};
54+
55+
<DocPropsList category={useCurrentSidebarCategory()} />
56+
```

website/_dogfooding/dogfooding.css

+14
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,20 @@ html {
2424
.navbar {
2525
border-bottom: solid thin cyan;
2626
}
27+
28+
.dogfood_sidebar_class_name_test {
29+
&.theme-doc-sidebar-item-link > a {
30+
color: cyan;
31+
}
32+
33+
&.theme-doc-sidebar-item-category > div > a {
34+
color: cyan;
35+
}
36+
37+
&.card {
38+
border: solid thin cyan;
39+
}
40+
}
2741
}
2842

2943
&.plugin-blog.plugin-id-blog-tests {

0 commit comments

Comments
 (0)