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

Allow local decorators via params #5806

Merged
merged 2 commits into from
Mar 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions examples/official-storybook/stories/core/decorators.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import React from 'react';

// We would need to add this in config.js idomatically however that would make this file a bit confusing
import { addDecorator } from '@storybook/react';

addDecorator((s, { kind }) =>
kind === 'Core|Decorators' ? (
<>
<p>Global Decorator</p>
{s()}
</>
) : (
s()
)
);

export default {
title: 'Core|Decorators',
decorators: [
s => (
<>
<p>Kind Decorator</p>
{s()}
</>
),
],
};

export const all = () => <p>Story</p>;
all.parameters = {
decorators: [
s => (
<>
<p>Local Decorator</p>
{s()}
</>
),
],
};
Original file line number Diff line number Diff line change
Expand Up @@ -5077,6 +5077,23 @@ exports[`Storyshots Basics|ScrollArea vertical 1`] = `
</div>
`;

exports[`Storyshots Core|Decorators all 1`] = `
Array [
<p>
Global Decorator
</p>,
<p>
Kind Decorator
</p>,
<p>
Local Decorator
</p>,
<p>
Story
</p>,
]
`;

exports[`Storyshots Core|Events Force re-render 1`] = `
.emotion-0 {
border: 0;
Expand Down
7 changes: 6 additions & 1 deletion lib/client-api/src/client_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,12 @@ export default class ClientApi {
},
{
applyDecorators: this._decorateStory,
getDecorators: () => [...localDecorators, ..._globalDecorators, withSubscriptionTracking],
getDecorators: () => [
...(allParam.decorators || []),
Copy link
Member

Choose a reason for hiding this comment

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

@tmeasday not part of the change per se, but why is this called allParam?

Copy link
Member Author

Choose a reason for hiding this comment

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

@shilman I guess it's a combination of all parameters (local global etc) in a similar way?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is why I meant that addDecorator could just be redefined to addDecorator(d) => addParameters({ decorators: [d] })

...localDecorators,
..._globalDecorators,
withSubscriptionTracking,
],
}
);
return api;
Expand Down