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

Implement linkTo functionality #86

Merged
merged 2 commits into from
Apr 9, 2016
Merged

Conversation

jeef3
Copy link
Contributor

@jeef3 jeef3 commented Apr 8, 2016

As mentioned in #50 this implements linkTo.

It uses the API suggested in the issue, with a couple of additions. The API is:

linkTo(kind: string|func, [story: string|func])


The initial suggestion was:

import { linkTo } from @kadira/storybook

storiesOf('Toggle', module)
  .add('on', () => {
    return <Toggle value={true} onChange={linkTo('Toggle', 'off')} />
  })
  .add('off', () => {
    return <Toggle value={false} onChange={linkTo('Toggle', 'on')} />
  });

In addition to this, made the kind optional, so you can linkTo('Toggle') and it will link to the first story in that kind.

Also, while building this functionality I found that there was a use case where the function being passed to the component should accept one or more arguments. That function should then decide where to go based on those arguments. For example, in the Todo Example:

  .add('show completed', () => (
    <div className="todoapp">
      <Footer
        completedCount={10}
        activeCount={4}
        filter={SHOW_COMPLETED}
        onClearCompleted={action('onClearCompleted')}
        onShow={action('onShow')} />
    </div>
  ))

In onShow={action('onShow')}, the action() is passed a constant describing the filter. There is no way to know what the filter will be, so we can't use a string. This is where you can use a function.

onShow={linkTo('Footer', (filter) => {
  switch (filter) {
  case SHOW_ALL: return 'default view';
  case SHOW_COMPLETED: return 'show completed';
  case SHOW_ACTIVE: return 'show active';
  }
})}

@arunoda
Copy link
Member

arunoda commented Apr 9, 2016

Great work. 💯

I can see the point of passing an function. That's clever.

@arunoda arunoda merged commit 5a84fb0 into storybookjs:master Apr 9, 2016
@jeef3 jeef3 deleted the link-to branch April 13, 2016 10:00
@montogeek
Copy link

It is possible to link storybook components by URL?
Something like http://localhost:8081/?component=MyComponent.

I am asking because I have an idea of link them from a Styleguide, something like:
"Try it in our Storybook"

@arunoda
Copy link
Member

arunoda commented Apr 26, 2016

@montogeek It'll be available by end of this week.

@montogeek
Copy link

@arunoda Marvelous! :D

ndelangen pushed a commit that referenced this pull request Apr 5, 2017
Update react-native to version 0.34.1 🚀
ndelangen pushed a commit that referenced this pull request Apr 5, 2017
@shilman shilman added the misc label May 27, 2017
ndelangen pushed a commit that referenced this pull request Feb 23, 2024
Add esbuild options for handling PNG files
Copy link

nx-cloud bot commented Sep 9, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 1b07acc. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


🟥 Failed Commands
nx run-many -t build --parallel=3

Sent with 💌 from NxCloud.

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

Successfully merging this pull request may close these issues.

4 participants