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

React: Add DecoratorFn type to exports #8121

Merged
merged 3 commits into from Sep 28, 2019
Merged

React: Add DecoratorFn type to exports #8121

merged 3 commits into from Sep 28, 2019

Conversation

hipstersmoothie
Copy link
Contributor

@hipstersmoothie hipstersmoothie commented Sep 18, 2019

What I did

With the old @types/storybook__react, users could use StoryDecorator to make a decorator outside of the addDecorator function. With the new types I had to do a little type math to get it to work

import { storiesOf, addDecorator } from '@storybook/react';

type StoryDecorator = Parameters<typeof addDecorator>[0]

const container: StoryDecorator = storyFn => (
  <div style={{ maxWidth: 800, margin: 'auto', padding: '20px 0' }}>
    {storyFn()}
  </div>
);

storiesOf('Components|Deck/Carrousel', module)
  .addDecorator(container)

This PR add Decorator to the @storybook/react types.

import { storiesOf, StoryDecorator } from '@storybook/react';

const container: StoryDecorator = storyFn => (
  <div style={{ maxWidth: 800, margin: 'auto', padding: '20px 0' }}>
    {storyFn()}
  </div>
);

storiesOf('Components|Deck/Carrousel', module)
  .addDecorator(container)

How to test

  • Is this testable with Jest or Chromatic screenshots? no
  • Does this need a new example in the kitchen sink apps? no
  • Does this need an update to the documentation? no

If your answer is yes to any of these, please make sure to include it in your PR.

@hipstersmoothie hipstersmoothie added bug patch:yes Bugfix & documentation PR that need to be picked to main branch labels Sep 18, 2019
@vercel
Copy link

vercel bot commented Sep 18, 2019

This pull request is automatically deployed with Now.
To access deployments, click Details below or on the icon next to each push.

Latest deployment for this branch: https://monorepo-git-react-decorator.storybook.now.sh

@shilman
Copy link
Member

shilman commented Sep 19, 2019

@hipstersmoothie @kroeder Do we need to add this to every other framework as well?

@hipstersmoothie
Copy link
Contributor Author

I am unfamiliar with the other frameworks but it would probably make sense. Would you like me to add it to the other apps?

@ndelangen
Copy link
Member

@hipstersmoothie if you could add it to the other frameworks too, that'd be great, but I think we can do that in a separate PR tbh, no reason to block this one for that.

@ndelangen ndelangen added this to the 5.2.x milestone Sep 25, 2019
@@ -27,6 +27,7 @@ export const storiesOf: ClientApi['storiesOf'] = (kind, m) => {

export const configure: ClientApi['configure'] = (...args) => api.configure(...args, framework);
export const addDecorator: ClientApi['addDecorator'] = api.clientApi.addDecorator;
export type StoryDecorator = Parameters<typeof addDecorator>[0];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally think the name StoryDecorator is a bit verbose, either DecoratorFn or DecoratorFunction would be a bit better IMHO.

This IS what it's called in the addons package btw.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am open to change the name. I was just copying what the definitely typed package named it to cause the least friction. But will change it to anything you want as it's pretty easy to replace it in my stories.

@github-actions
Copy link
Contributor

Automention: Hey @emilio-martinez @gaetanmaisse @kroeder, you've been tagged! Can you give a hand here?

@ndelangen
Copy link
Member

@hipstersmoothie what do you think of the proposed namechange?

@hipstersmoothie
Copy link
Contributor Author

I am open to change the name. I was just copying what the DefinitelyTyped package named it to cause the least friction. But will change it to anything you want as it's pretty easy to replace it in my stories.

@ndelangen
Copy link
Member

Yeah I'd rather change the name to something that makes sense to us.

@hipstersmoothie
Copy link
Contributor Author

@ndelangen changed it to DecoratorFn

@shilman shilman changed the title add react decorator type to exports React: Add DecoratorFn type to exports Sep 28, 2019
@ndelangen ndelangen merged commit 78f4d86 into next Sep 28, 2019
@ndelangen ndelangen deleted the react-decorator branch September 28, 2019 08:24
@shilman shilman added the patch:done Patch/release PRs already cherry-picked to main/release branch label Oct 7, 2019
shilman pushed a commit that referenced this pull request Oct 7, 2019
React: Add DecoratorFn type to exports
@mvasin
Copy link
Contributor

mvasin commented Oct 26, 2019

Renaming StoryDecorator to DecoratorFn is a breaking change, and you just bump a patch version. Not quite semver-friendly.

@shilman
Copy link
Member

shilman commented Oct 26, 2019

@mvasin is there something we can do to make it back-compat? want to create a PR for that?

@MichaelDeBoey
Copy link
Contributor

@mvasin Technically it's not a breaking change, since the types were not in this repo yet and were maintained externally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug patch:done Patch/release PRs already cherry-picked to main/release branch patch:yes Bugfix & documentation PR that need to be picked to main branch typescript
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants