mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-08 02:21:48 +08:00
Make the wrapStory decorator simple to use.
This commit is contained in:
parent
dc1d9df0fe
commit
cf38bf7d43
@ -12,7 +12,7 @@ import {
|
|||||||
import Button from './Button';
|
import Button from './Button';
|
||||||
|
|
||||||
storiesOf('Button', module)
|
storiesOf('Button', module)
|
||||||
.addDecorator((story, context) => (withKnobs(story)(context)))
|
.addDecorator(withKnobs)
|
||||||
.add('default view', () => (
|
.add('default view', () => (
|
||||||
<Button
|
<Button
|
||||||
onClick={ action('button clicked') }
|
onClick={ action('button clicked') }
|
||||||
|
@ -30,8 +30,7 @@ export default class KnobManager {
|
|||||||
return knobStore.get(name).value;
|
return knobStore.get(name).value;
|
||||||
}
|
}
|
||||||
|
|
||||||
wrapStory(storyFn, channel) {
|
wrapStory(channel, storyFn, context) {
|
||||||
return context => {
|
|
||||||
const key = `${context.kind}:::${context.story}`;
|
const key = `${context.kind}:::${context.story}`;
|
||||||
let knobStore = this.knobStoreMap[key];
|
let knobStore = this.knobStoreMap[key];
|
||||||
|
|
||||||
@ -42,6 +41,5 @@ export default class KnobManager {
|
|||||||
|
|
||||||
const props = { context, storyFn, channel, knobStore };
|
const props = { context, storyFn, channel, knobStore };
|
||||||
return (<WrapStory {...props} />);
|
return (<WrapStory {...props} />);
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ export function object(name, value) {
|
|||||||
return manager.knob(name, { type: 'object', value });
|
return manager.knob(name, { type: 'object', value });
|
||||||
}
|
}
|
||||||
|
|
||||||
export function withKnobs(storyFn) {
|
export function withKnobs(storyFn, context) {
|
||||||
const channel = addons.getChannel();
|
const channel = addons.getChannel();
|
||||||
return manager.wrapStory(storyFn, channel);
|
return manager.wrapStory(channel, storyFn, context);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user