Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[addon-docs] Previous/Next links in docs.#23059

folz started this conversation inIdeas
Discussion options

Is your feature request related to a problem? Please describe.

I would like docs stories to link to their Previous and Next stories at either the top or bottom of the page.

I tried searching for variations of "storybook" "addon-docs" "previous next" "link", but wasn't able to find documentation that this feature already exists.

Describe the solution you'd like

Here is a screenshot from Docusaurus showing the ideal behavior:

Screen Shot 2020-01-29 at 1 36 06 PM

For Storybook, given a sidebar of

  • Guide
    • Getting Started
    • Installation
  • Components
    • Button
    • Card

I would like the Guide|Installation docs to include

[ Previous                ]   [                Next ][ Guide - Getting Started ]   [ Components - Button ]

at either/both of the top and bottom of the docs.

Describe alternatives you've considered

Storybook supports linking to stories, so I could manually include the previous and next buttons for each docs story. However, this is manual and prone to becoming outdated. Ideally we would look at the storybook stories context, but I don't know enough about storybook's internals to know how to do this.

Are you able to assist bring the feature to reality?

Yes, if you can point me to the relevant code.

You must be logged in to vote

Replies: 7 comments

Comment options

Hi@folz this would be an awesome example of a fairly simple docblock to write. I'm on the hook for documentingaddon-docs as part of the 6.0 milestone, so once there's a dev guide it would be amazing if you could kick the tires on that and see how hard it is to implement this. I'd expect it shouldn't be too hard to extract this information automatically and create the links.

You must be logged in to vote
0 replies
Comment options

For sure, that sounds good to me! Is there a place I can follow for updates to 6.0, or would you be able to tag me in this issue once that's released?

You must be logged in to vote
0 replies
Comment options

@folz absolutely. i'll tag you here when it's ready.

in terms of 6.0 here's a general issue (still basically empty):#9311

and for doc blocks documentation there isn't an issue yet. here's the closest thing to track#8379

You must be logged in to vote
0 replies
Comment options

Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks!

You must be logged in to vote
0 replies
Comment options

Converting this to a discussion. We’re reserving feature issues for things that are on ourshort-term roadmap. We’ll check back periodically to see whether this is a good candidate to be added. If this feature would be useful to you, please upvote!

You must be logged in to vote
0 replies
Comment options

This would be an excellent feature to add. We have implemented it in our codebase in a hacky way but a proper official DocBlock for it would be great.

You must be logged in to vote
0 replies
Comment options

Until we get a proper block for this basic feature, here's a block you can place in your MDX files. Might have to tweak it some for your setup or Storybook version (I'm on version 8). Tried usingitems.json initially and figuring out using API but it was a bit overwhelming... sometimes it's just easier to work off rendered content in the sidebar.

exportconstFooter=({  nextLink,  prevLink,  nextLinkText,  prevLinkText}:{nextLink:string;prevLink:string;nextLinkText:string;prevLinkText:string;})=>{varfindAdjacentSibling=function(elem,selector,direction:'prev'|'next'){// Get the next sibling elementvarsibling=elem[direction==='prev' ?'previousElementSibling' :'nextElementSibling'];if(!selector)returnsibling;while(sibling){if(sibling.matches(selector))returnsibling;sibling=sibling[direction==='prev' ?'previousElementSibling' :'nextElementSibling'];}};constgetAdjacentPageInSidebar=(direction:'prev'|'next')=>{// From parent iframeconstsidebar=window.parent.document.querySelector('#storybook-explorer-tree');if(!sidebar)returnnull;constsidebarActiveItem=sidebar.querySelector('[data-selected="true"]');if(!sidebarActiveItem)returnnull;constsidebarAdjacentToActiveItem=findAdjacentSibling(sidebarActiveItem,'.sidebar-item',direction);if(!sidebarAdjacentToActiveItem)returnnull;constsidebarAdjacentToActiveItemLink=sidebarAdjacentToActiveItem.querySelector('a');if(!sidebarAdjacentToActiveItemLink)returnnull;console.log(sidebarAdjacentToActiveItemLink.getAttribute('href'));returnsidebarAdjacentToActiveItemLink;};constprevDocLink=getAdjacentPageInSidebar('prev');constnextDocLink=getAdjacentPageInSidebar('next');constprevDocLinkText=prevDocLink?.textContent;constnextDocLinkText=nextDocLink?.textContent;constprevDocLinkHref=prevDocLink?.getAttribute('href');constnextDocLinkHref=nextDocLink?.getAttribute('href');return(<>{(prevLink||prevDocLinkHref)&&(<ahref={prevLink??prevDocLinkHref}>{prevLinkText||prevDocLinkText}</a>)}{(nextLink||nextDocLinkHref)&&(<ahref={nextLink??nextDocLinkHref}>{nextLinkText||nextDocLinkText}</a>)}</>);};

Then at the bottom of your MDX you would do<Footer />

You must be logged in to vote
0 replies
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Ideas
4 participants
@folz@shilman@kerryj89@AngusMacrae
Converted from issue

This discussion was converted from issue #9676 on June 14, 2023 02:53.


[8]ページ先頭

©2009-2025 Movatter.jp