Is it possible to create a custom DocCardList that displays items from different sidebars? #10752
-
Custom DocCardList Component for Cross-Sidebar Category DisplayDescriptionI'm trying to create a custom version of the Current BehaviorThe
<DocCardList items={[
{
type: 'link',
href: '/api/getting-started',
label: 'Getting Started',
description: '...'
}
]} /> Desired BehaviorGiven a file structure like:
I want to be able to reference items from a different sidebar category using a simple prop, like: <CustomDocCardList
docId="api-docs/endpoints/index"
/> This would allow me to display the endpoints category items while viewing a page in the main documentation, without manually maintaining the list of items. Questions
Additional Context
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You can use If you need to access other sidebars of a given version (not just categories), the only way I can think of is using Once you get the sidebar, it's your responsibility to traverse it and find the Remember all these are undocumented APIs on which we may make breaking changes. The API may break however I don't think the feature will disappear so it's relatively safe to use. |
Beta Was this translation helpful? Give feedback.
You can use
useDocsSidebar()
to get access to the sidedar in which the current doc is.If you need to access other sidebars of a given version (not just categories), the only way I can think of is using
useDocsVersion().docsSidebars["apiSidebar"]
Once you get the sidebar, it's your responsibility to traverse it and find the
category.items
to pass as props toDocCardList
.Remember all these are undocumented APIs on which we may make breaking changes. The API may break however I don't think the feature will disappear so it's relatively safe to use.