mirror of
https://github.com/storybookjs/storybook.git
synced 2025-03-18 05:02:24 +08:00
Make withKnobs accept story parameters
- use makeDectorator to upgrade withKnobs - deprecate withKnobsOptions
This commit is contained in:
parent
c28a02a943
commit
3a4dc2a17d
@ -1,4 +1,6 @@
|
||||
import addons from '@storybook/addons';
|
||||
import deprecate from 'util-deprecate';
|
||||
|
||||
import addons, { makeDecorator } from '@storybook/addons';
|
||||
|
||||
import { manager, registerKnobs } from './registerKnobs';
|
||||
|
||||
@ -71,16 +73,22 @@ const defaultOptions = {
|
||||
escapeHTML: true,
|
||||
};
|
||||
|
||||
export const withKnobsOptions = (options = {}) => storyFn => {
|
||||
const allOptions = { ...defaultOptions, ...options };
|
||||
export const withKnobs = makeDecorator({
|
||||
name: 'withKnobs',
|
||||
parameterName: 'knobs',
|
||||
skipIfNoParametersOrOptions: false,
|
||||
wrapper: (getStory, context, { options, parameters }) => {
|
||||
const storyOptions = parameters || options;
|
||||
const allOptions = { ...defaultOptions, ...storyOptions };
|
||||
|
||||
manager.setOptions(allOptions);
|
||||
const channel = addons.getChannel();
|
||||
manager.setChannel(channel);
|
||||
channel.emit('addon:knobs:setOptions', allOptions);
|
||||
manager.setOptions(allOptions);
|
||||
const channel = addons.getChannel();
|
||||
manager.setChannel(channel);
|
||||
channel.emit('addon:knobs:setOptions', allOptions);
|
||||
|
||||
registerKnobs();
|
||||
return storyFn();
|
||||
};
|
||||
registerKnobs();
|
||||
return getStory(context);
|
||||
},
|
||||
});
|
||||
|
||||
export const withKnobs = withKnobsOptions();
|
||||
export const withKnobsOptions = deprecate(withKnobs, 'Use withKnobs directly');
|
||||
|
@ -181,7 +181,10 @@ storiesOf('Addons|Knobs.withKnobs', module)
|
||||
__html: text('Rendered string', '<img src="x" onerror="alert(\'XSS Attack\')" >'),
|
||||
}}
|
||||
/>
|
||||
));
|
||||
))
|
||||
.add('accepts story parameters', () => <div>{text('Rendered string', '<h1>Hello</h1>')}</div>, {
|
||||
knobs: { escapeHTML: false },
|
||||
});
|
||||
|
||||
storiesOf('Addons|Knobs.withKnobsOptions', module)
|
||||
.addDecorator(
|
||||
|
Loading…
x
Reference in New Issue
Block a user