Skip to content

Commit

Permalink
feat(theme): ability to use <DocCardList> without items prop, on any …
Browse files Browse the repository at this point in the history
…doc page (#8008)
  • Loading branch information
slorber committed Sep 1, 2022
1 parent 091656f commit a6b8e72
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
3 changes: 1 addition & 2 deletions website/versioned_docs/version-2.1.0/advanced/index.md
Expand Up @@ -4,9 +4,8 @@ This section is not going to be very structured, but we will cover the following

```mdx-code-block
import DocCardList from '@theme/DocCardList';
import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
<DocCardList items={useCurrentSidebarCategory().items}/>
<DocCardList />
```

We will assume that you have finished the guides, and know the basics like how to configure plugins, how to write React components, etc. These sections will have plugin authors and code contributors in mind, so we may occasionally refer to [plugin APIs](../api/plugin-methods/README.md) or other architecture details. Don't panic if you don't understand everything😉
Expand Up @@ -35,9 +35,8 @@ This section serves as an overview of miscellaneous features of the doc sidebar.

```mdx-code-block
import DocCardList from '@theme/DocCardList';
import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
<DocCardList items={useCurrentSidebarCategory().items}/>
<DocCardList />
```

## Default sidebar {#default-sidebar}
Expand Down
20 changes: 13 additions & 7 deletions website/versioned_docs/version-2.1.0/guides/docs/sidebar/items.md
Expand Up @@ -8,6 +8,7 @@ slug: /sidebar/items
```mdx-code-block
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
import BrowserWindow from '@site/src/components/BrowserWindow';
```

We have introduced three types of item types in the example in the previous section: `doc`, `category`, and `link`, whose usages are fairly intuitive. We will formally introduce their APIs. There's also a fourth type: `autogenerated`, which we will explain in detail later.
Expand Down Expand Up @@ -291,18 +292,23 @@ See it in action on the [i18n introduction page](../../../i18n/i18n-introduction

#### Embedding generated index in doc page {#embedding-generated-index-in-doc-page}

You can embed the generated cards list in a normal doc page as well, as long as the doc is used as a category index page. To do so, you need to use the `DocCardList` component, paired with the `useCurrentSidebarCategory` hook.
You can embed the generated cards list in a normal doc page as well with the `DocCardList` component. It will display all the sidebar items of the parent category of the current document.

```jsx title="a-category-index-page.md"
```md title="docs/sidebar/index.md"
import DocCardList from '@theme/DocCardList';
import {useCurrentSidebarCategory} from '@docusaurus/theme-common';

In this section, we will introduce the following concepts:

<DocCardList items={useCurrentSidebarCategory().items}/>
<DocCardList />
```

See this in action on the [sidebar guides page](index.md).
```mdx-code-block
<BrowserWindow>
import DocCardList from '@theme/DocCardList';
<DocCardList />
</BrowserWindow>
```

### Collapsible categories {#collapsible-categories}

Expand Down

0 comments on commit a6b8e72

Please sign in to comment.