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

How to write this in new format #14817

Closed
angelod1as opened this issue May 5, 2021 · 2 comments
Closed

How to write this in new format #14817

angelod1as opened this issue May 5, 2021 · 2 comments

Comments

@angelod1as
Copy link

angelod1as commented May 5, 2021

What's the problem?
I have this code in my codebase and need to upgrade to Storybook's new format:

import React from 'react';
import withMock from 'storybook-addon-mock';

storiesOf('Storybook Addon Mock', module)
  .addDecorator(withMock)
  .add('Getting Mock API Response', () => <ComponentWithAPICall />, {
    mockData: [{
      url: '/api/get-users',
      method: 'GET',
      status: 200,
      response: {
        data: [{ id: 1}],
      },
    }],
  });

My code, right now is:

import React from 'react'
import withMock from 'storybook-addon-mock'
import CycleCard from './CycleCard'

export default {
  title: 'Settings/CycleCard',
  component: CycleCard,
  argTypes: {},
  decorators: [
    Story => (
      <withMock> // I don't know exactly where to put the code in `.add` function
        <Story />
      </withMock>
    ),
  ],
}

const Template = args => <CycleCard {...args} />

export const Default = Template.bind({})
Default.args = {}

Is there documentation on this?
This code comes from this addon but I think you can help me better how to translate this code, as it's more a syntax difference than addon functionality

@shilman
Copy link
Member

shilman commented May 6, 2021

import React from 'react'
import withMock from 'storybook-addon-mock'
import CycleCard from './CycleCard'

export default {
  title: 'Settings/CycleCard',
  component: CycleCard,
  decorators: [withMock],
}

const Template = args => <CycleCard {...args} />

export const Default = Template.bind({})
Default.parameters = {
    mockData: [{
      url: '/api/get-users',
      method: 'GET',
      status: 200,
      response: {
        data: [{ id: 1}],
      },
    }],
}

You can also use the storiesof-to-csf codemod to do this automatically for you: https://github.com/storybookjs/storybook/blob/next/lib/codemod/README.md#storiesof-to-csf

@shilman shilman added PN and removed needs triage labels May 6, 2021
@angelod1as
Copy link
Author

Thanks @shilman , always mega helpful.

I opened a PR on the addon repo to reflect this new structure.

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

2 participants