Skip to content

Commit

Permalink
fix(theme): apply docs sidebar_class_name in DocCard + better dogfo…
Browse files Browse the repository at this point in the history
…oding (#10909)
  • Loading branch information
slorber authored Feb 6, 2025
1 parent 0162f6a commit b76f0fe
Show file tree
Hide file tree
Showing 11 changed files with 97 additions and 33 deletions.
1 change: 0 additions & 1 deletion argos/tests/screenshot.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ function isBlacklisted(pathname: string) {
'/tests/pages/react-18',
// Flaky because of hydration error
'/tests/blog/archive',
'/tests/docs/tests/custom-props',
'/tests/pages/code-block-tests',
'/tests/pages/embeds',
// Flaky because of hydration error with docusaurus serve + .html
Expand Down
10 changes: 8 additions & 2 deletions packages/docusaurus-theme-classic/src/theme/DocCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,34 +43,38 @@ function useCategoryItemsPlural() {
}

function CardContainer({
className,
href,
children,
}: {
className?: string;
href: string;
children: ReactNode;
}): ReactNode {
return (
<Link
href={href}
className={clsx('card padding--lg', styles.cardContainer)}>
className={clsx('card padding--lg', styles.cardContainer, className)}>
{children}
</Link>
);
}

function CardLayout({
className,
href,
icon,
title,
description,
}: {
className?: string;
href: string;
icon: ReactNode;
title: string;
description?: string;
}): ReactNode {
return (
<CardContainer href={href}>
<CardContainer href={href} className={className}>
<Heading
as="h2"
className={clsx('text--truncate', styles.cardTitle)}
Expand Down Expand Up @@ -99,6 +103,7 @@ function CardCategory({item}: {item: PropSidebarItemCategory}): ReactNode {

return (
<CardLayout
className={item.className}
href={href}
icon="🗃️"
title={item.label}
Expand All @@ -112,6 +117,7 @@ function CardLink({item}: {item: PropSidebarItemLink}): ReactNode {
const doc = useDocById(item.docId ?? undefined);
return (
<CardLayout
className={item.className}
href={item.href}
icon={icon}
title={item.label}
Expand Down

This file was deleted.

This file was deleted.

22 changes: 0 additions & 22 deletions website/_dogfooding/_docs tests/tests/custom-props/index.mdx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
sidebar_class_name: 'dogfood_sidebar_class_name_test'
---

# Doc With Sidebar Class Name

This doc has `sidebar_label` front matter
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ sidebar_custom_props:
boolean: true
---

# Doc with Custom Props
# Doc With Custom Props

This doc has custom props.
This doc has `sidebar_custom_props` front matter.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
sidebar_label: Doc With Sidebar Label
---

# Doc with `sidebar_label`

This doc has `sidebar_label` front matter
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Doc Without

This doc doesn't have any `sidebar_` front matter
Original file line number Diff line number Diff line change
@@ -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()} />
```
14 changes: 14 additions & 0 deletions website/_dogfooding/dogfooding.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ html {
.navbar {
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 {
Expand Down

0 comments on commit b76f0fe

Please sign in to comment.