mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-16 01:32:37 +02:00
fix(theme): apply docs sidebar_class_name
in DocCard + better dogfooding (#10909)
This commit is contained in:
parent
0162f6abc6
commit
b76f0feadc
11 changed files with 97 additions and 33 deletions
|
@ -55,7 +55,6 @@ function isBlacklisted(pathname: string) {
|
||||||
'/tests/pages/react-18',
|
'/tests/pages/react-18',
|
||||||
// Flaky because of hydration error
|
// Flaky because of hydration error
|
||||||
'/tests/blog/archive',
|
'/tests/blog/archive',
|
||||||
'/tests/docs/tests/custom-props',
|
|
||||||
'/tests/pages/code-block-tests',
|
'/tests/pages/code-block-tests',
|
||||||
'/tests/pages/embeds',
|
'/tests/pages/embeds',
|
||||||
// Flaky because of hydration error with docusaurus serve + .html
|
// Flaky because of hydration error with docusaurus serve + .html
|
||||||
|
|
|
@ -43,34 +43,38 @@ function useCategoryItemsPlural() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function CardContainer({
|
function CardContainer({
|
||||||
|
className,
|
||||||
href,
|
href,
|
||||||
children,
|
children,
|
||||||
}: {
|
}: {
|
||||||
|
className?: string;
|
||||||
href: string;
|
href: string;
|
||||||
children: ReactNode;
|
children: ReactNode;
|
||||||
}): ReactNode {
|
}): ReactNode {
|
||||||
return (
|
return (
|
||||||
<Link
|
<Link
|
||||||
href={href}
|
href={href}
|
||||||
className={clsx('card padding--lg', styles.cardContainer)}>
|
className={clsx('card padding--lg', styles.cardContainer, className)}>
|
||||||
{children}
|
{children}
|
||||||
</Link>
|
</Link>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function CardLayout({
|
function CardLayout({
|
||||||
|
className,
|
||||||
href,
|
href,
|
||||||
icon,
|
icon,
|
||||||
title,
|
title,
|
||||||
description,
|
description,
|
||||||
}: {
|
}: {
|
||||||
|
className?: string;
|
||||||
href: string;
|
href: string;
|
||||||
icon: ReactNode;
|
icon: ReactNode;
|
||||||
title: string;
|
title: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
}): ReactNode {
|
}): ReactNode {
|
||||||
return (
|
return (
|
||||||
<CardContainer href={href}>
|
<CardContainer href={href} className={className}>
|
||||||
<Heading
|
<Heading
|
||||||
as="h2"
|
as="h2"
|
||||||
className={clsx('text--truncate', styles.cardTitle)}
|
className={clsx('text--truncate', styles.cardTitle)}
|
||||||
|
@ -99,6 +103,7 @@ function CardCategory({item}: {item: PropSidebarItemCategory}): ReactNode {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<CardLayout
|
<CardLayout
|
||||||
|
className={item.className}
|
||||||
href={href}
|
href={href}
|
||||||
icon="🗃️"
|
icon="🗃️"
|
||||||
title={item.label}
|
title={item.label}
|
||||||
|
@ -112,6 +117,7 @@ function CardLink({item}: {item: PropSidebarItemLink}): ReactNode {
|
||||||
const doc = useDocById(item.docId ?? undefined);
|
const doc = useDocById(item.docId ?? undefined);
|
||||||
return (
|
return (
|
||||||
<CardLayout
|
<CardLayout
|
||||||
|
className={item.className}
|
||||||
href={item.href}
|
href={item.href}
|
||||||
icon={icon}
|
icon={icon}
|
||||||
title={item.label}
|
title={item.label}
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
{
|
|
||||||
"label": "Custom Props"
|
|
||||||
}
|
|
|
@ -1,3 +0,0 @@
|
||||||
# Doc Without Custom Props
|
|
||||||
|
|
||||||
This doc doesn't have custom props.
|
|
|
@ -1,22 +0,0 @@
|
||||||
# Custom Props
|
|
||||||
|
|
||||||
```mdx-code-block
|
|
||||||
import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
|
|
||||||
|
|
||||||
export const DocPropsList = ({items}) => (
|
|
||||||
<table>
|
|
||||||
<tr>
|
|
||||||
<th>Doc Page</th>
|
|
||||||
<th>Custom Props</th>
|
|
||||||
</tr>
|
|
||||||
{items.map((item, index) => (
|
|
||||||
<tr key={index}>
|
|
||||||
<td>{item.label}</td>
|
|
||||||
<td>{JSON.stringify(item.customProps)}</td>
|
|
||||||
</tr>
|
|
||||||
))}
|
|
||||||
</table>
|
|
||||||
);
|
|
||||||
|
|
||||||
<DocPropsList items={useCurrentSidebarCategory().items}/>
|
|
||||||
```
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
---
|
||||||
|
sidebar_class_name: 'dogfood_sidebar_class_name_test'
|
||||||
|
---
|
||||||
|
|
||||||
|
# Doc With Sidebar Class Name
|
||||||
|
|
||||||
|
This doc has `sidebar_label` front matter
|
|
@ -5,6 +5,6 @@ sidebar_custom_props:
|
||||||
boolean: true
|
boolean: true
|
||||||
---
|
---
|
||||||
|
|
||||||
# Doc with Custom Props
|
# Doc With Custom Props
|
||||||
|
|
||||||
This doc has custom props.
|
This doc has `sidebar_custom_props` front matter.
|
|
@ -0,0 +1,7 @@
|
||||||
|
---
|
||||||
|
sidebar_label: Doc With Sidebar Label
|
||||||
|
---
|
||||||
|
|
||||||
|
# Doc with `sidebar_label`
|
||||||
|
|
||||||
|
This doc has `sidebar_label` front matter
|
|
@ -0,0 +1,3 @@
|
||||||
|
# Doc Without
|
||||||
|
|
||||||
|
This doc doesn't have any `sidebar_` front matter
|
|
@ -0,0 +1,56 @@
|
||||||
|
---
|
||||||
|
sidebar_label: 'Sidebar Front Matter Tests'
|
||||||
|
sidebar_class_name: 'dogfood_sidebar_class_name_test'
|
||||||
|
---
|
||||||
|
|
||||||
|
# Sidebar front matter
|
||||||
|
|
||||||
|
```mdx-code-block
|
||||||
|
import Link from '@docusaurus/Link';
|
||||||
|
import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
|
||||||
|
import DocCardList from '@theme/DocCardList';
|
||||||
|
|
||||||
|
<DocCardList />
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Items table
|
||||||
|
|
||||||
|
export const DocPropsList = ({category}) => {
|
||||||
|
const items = [category, ...category.items];
|
||||||
|
return (
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>
|
||||||
|
<code>type</code>
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
<code>label</code>
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
<code>customProps</code>
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
<code>className</code>
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{items.map((item, index) => (
|
||||||
|
<tr key={index}>
|
||||||
|
<td>{item.type}</td>
|
||||||
|
<td>
|
||||||
|
<Link to={item.href}>{item.label}</Link>
|
||||||
|
</td>
|
||||||
|
<td>{JSON.stringify(item.customProps)}</td>
|
||||||
|
<td>{JSON.stringify(item.className)}</td>
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
<DocPropsList category={useCurrentSidebarCategory()} />
|
||||||
|
```
|
|
@ -24,6 +24,20 @@ html {
|
||||||
.navbar {
|
.navbar {
|
||||||
border-bottom: solid thin cyan;
|
border-bottom: solid thin cyan;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.dogfood_sidebar_class_name_test {
|
||||||
|
&.theme-doc-sidebar-item-link > a {
|
||||||
|
color: cyan;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.theme-doc-sidebar-item-category > div > a {
|
||||||
|
color: cyan;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.card {
|
||||||
|
border: solid thin cyan;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&.plugin-blog.plugin-id-blog-tests {
|
&.plugin-blog.plugin-id-blog-tests {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue