Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[addon-docs] Link to another story #8618

Open
thany opened this issue Oct 29, 2019 · 13 comments
Open

[addon-docs] Link to another story #8618

thany opened this issue Oct 29, 2019 · 13 comments

Comments

@thany
Copy link

thany commented Oct 29, 2019

Is your feature request related to a problem? Please describe.
Well of course. I need to link to another story to sort of build a "See also" or "For more information, see..." section.

Describe the solution you'd like
I would like to be able to just link to another story by writing a MD link, something like:

See [this cool component](Components|General/CoolComponent) for more information

Storybook would recognize that this is not a regular url, but a link to a story, and transform the link in such a way that it will navigate to that story, instead of trying to open the url as-is.

Describe alternatives you've considered
The best workaround at the moment would be to go to that story using the existing navigation, recording what the url is, and pasting that into the MD link. It doesn't feel like that's the most stable way to go, because I don't think those url's a completely chained to the components that are on them.

Are you able to assist bring the feature to reality?
Not sure I can, sorry.

Additional context
It might be worth noting that the documentation of MDX stories is a bit "all over the place". I feel there isn't a single source of truth when it comes to MDX. All I can find is a couple of use-cases (although very common ones) and their solutions, but not an exhaustive reference. Perhaps working on that may reveal that the feature being requested here, is already possible in some other way, that I have no way of being aware of.

@shilman
Copy link
Member

shilman commented Oct 30, 2019

This sounds reasonable. I'll try to take a pass at it while addressing these related issues #7799 #8184

@shilman shilman added the todo label Oct 30, 2019
@robbeman
Copy link

robbeman commented Nov 7, 2019

You could use addon-links for this. I just checked and it is possible to use the <LinkTo> component in mdx.

Update: This apparently doesn't work for page anchors, so you might want to look at the other thread if you want to do in page links.

@grgur
Copy link

grgur commented Jan 16, 2020

I just used @robbeman's suggestion (thanks!) to navigate to another page with the <LinkTo> component. The router maintains scroll position (doesn't scroll back to the top) but using anchor links actually worked. Here's what I did:

import LinkTo from '@storybook/addon-links/react';

Please read the section on <LinkTo kind="writing-docs--page#writing-documentation-stories">Writing Documentation Stories</LinkTo>

Notes:

  • writing-docs - the ID of the other page
  • Appending --page was needed to navigate to another Docs page, although I don't like that it's hacky
  • #writing-documentation-stories is the anchor to the h1 tag at the top of another page

I hope that helps.

@Bamblehorse
Copy link

Bamblehorse commented May 22, 2020

LinkTo works nicely 🙂 did some more digging and found a new PR

Seems like since this issue was created you can potentially more reliably use a normal md link like this: [link to another story](/?path=/docs/addons-docs-docs-only--page#bottom)

https://github.com/storybookjs/storybook/pull/9051/files#diff-809d0afec1adb3c90fb654474a0bf015

@AndrewOttavianoAbb
Copy link

Don't know if this is the right place for this, but can you link to the "Docs" .mdx page for a give story. For example, if the user is reading a document for one story and it needs to refer to the document for another story, can you create a link for that?

I tried using the LinkTo component but no go. Here's what I've tried so far:

// This is what works for me right now to link to the story but it just goes to the story
<LinkTo kind="core-theme" story="color-palette">blah blah</LinkTo>
// I tried these to link to the docs page but no go
<LinkTo kind="docs/core-theme" story="color-palette">blah blah</LinkTo>
<LinkTo kind="/docs/core-theme" story="color-palette">blah blah</LinkTo>
<LinkTo kind="docs/core-theme">blah blah</LinkTo> // This just goes to /docs/story/core-theme first story :(

@ghost
Copy link

ghost commented Oct 17, 2022

description: {
  component:
    'Description with a [link](/?path=/docs/another-page--page) to another page.'
}

This suggestion from @Bamblehorse will lead to http://localhost:6006/iframe.html?path=/?path=/docs/another-page--page, eg. a broken page.

@dreyks
Copy link

dreyks commented Nov 3, 2022

@mystrdat this might be a bug, but the immediate workaround is [link](/docs/another-page--page)

@ghost
Copy link

ghost commented Nov 3, 2022

@mystrdat this might be a bug, but the immediate workaround is [link](/docs/another-page--page)

This seems to result in the same behavior, somehow Storybook actually modifies the url as such
[link](/docs/another-page--default) becomes href="?path=/docs/another-page--default"
and it leads to http://localhost:6006/iframe.html?path=/docs/another-page--default

@joakimbeng
Copy link

@mystrdat this might be a bug, but the immediate workaround is [link](/docs/another-page--page)

This seems to result in the same behavior, somehow Storybook actually modifies the url as such [link](/docs/another-page--default) becomes href="?path=/docs/another-page--default" and it leads to http://localhost:6006/iframe.html?path=/docs/another-page--default

Noticed the same issue myself. I tried writing <a href="/docs/another-page--default">Link</a> manually but it's the same thing there, Storybook prepends /iframe.html?path= to the href in that case as well.

@redjov
Copy link

redjov commented Nov 14, 2022

@joakimbeng Add target='_self' to the anchor element and storybook will not prepend iframe.html

@mseyfayi
Copy link

For preventing iframe.html be added to the start of the URL, this trick can be used:

<a href="../?path=/docs/button--primary">Button</a>

Adding ../ at the start of the URL can fix this issue for now.

@dimitrieh
Copy link

dimitrieh commented Feb 15, 2023

I have created a test for internal linking for storybook 7.0 using beta 48 as this issue seems to persist there.

Other related issues:

cc: @yannbf

@mel-miller
Copy link

Adding ../ at the start of the URL can fix this issue for now.

Thanks! And FYI, this also works with Markdown linking syntax like so:

[Icon component](../?path=/docs/components-icon--icon)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests