mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-07 21:51:48 +08:00
Added allowDeprecatedUsage
option to makeDecorator
(and enable it for all existing addons)
This commit is contained in:
parent
759d741f03
commit
aa8a421907
@ -15,6 +15,7 @@ export const withBackgrounds = makeDecorator({
|
|||||||
name: 'backgrounds',
|
name: 'backgrounds',
|
||||||
parameterName: 'backgrounds',
|
parameterName: 'backgrounds',
|
||||||
skipIfNoParametersOrOptions: true,
|
skipIfNoParametersOrOptions: true,
|
||||||
|
allowDeprecatedUsage: true,
|
||||||
wrapper: (getStory, context, { options, parameters }) => {
|
wrapper: (getStory, context, { options, parameters }) => {
|
||||||
const backgrounds = parameters || options;
|
const backgrounds = parameters || options;
|
||||||
|
|
||||||
|
@ -87,6 +87,7 @@ function addInfo(storyFn, context, infoOptions) {
|
|||||||
export const withInfo = makeDecorator({
|
export const withInfo = makeDecorator({
|
||||||
name: 'withInfo',
|
name: 'withInfo',
|
||||||
parameterName: 'info',
|
parameterName: 'info',
|
||||||
|
allowDeprecatedUsage: true,
|
||||||
wrapper: (getStory, context, { options, parameters }) => {
|
wrapper: (getStory, context, { options, parameters }) => {
|
||||||
const storyOptions = parameters || options;
|
const storyOptions = parameters || options;
|
||||||
const infoOptions = typeof storyOptions === 'string' ? { text: storyOptions } : storyOptions;
|
const infoOptions = typeof storyOptions === 'string' ? { text: storyOptions } : storyOptions;
|
||||||
|
@ -77,6 +77,7 @@ export const withKnobs = makeDecorator({
|
|||||||
name: 'withKnobs',
|
name: 'withKnobs',
|
||||||
parameterName: 'knobs',
|
parameterName: 'knobs',
|
||||||
skipIfNoParametersOrOptions: false,
|
skipIfNoParametersOrOptions: false,
|
||||||
|
allowDeprecatedUsage: true,
|
||||||
wrapper: (getStory, context, { options, parameters }) => {
|
wrapper: (getStory, context, { options, parameters }) => {
|
||||||
const storyOptions = parameters || options;
|
const storyOptions = parameters || options;
|
||||||
const allOptions = { ...defaultOptions, ...storyOptions };
|
const allOptions = { ...defaultOptions, ...storyOptions };
|
||||||
|
@ -10,6 +10,7 @@ export const withNotes = makeDecorator({
|
|||||||
name: 'withNotes',
|
name: 'withNotes',
|
||||||
parameterName: 'notes',
|
parameterName: 'notes',
|
||||||
skipIfNoParametersOrOptions: true,
|
skipIfNoParametersOrOptions: true,
|
||||||
|
allowDeprecatedUsage: true,
|
||||||
wrapper: (getStory, context, { options, parameters }) => {
|
wrapper: (getStory, context, { options, parameters }) => {
|
||||||
const channel = addons.getChannel();
|
const channel = addons.getChannel();
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ export const makeDecorator = ({
|
|||||||
parameterName,
|
parameterName,
|
||||||
wrapper,
|
wrapper,
|
||||||
skipIfNoParametersOrOptions = false,
|
skipIfNoParametersOrOptions = false,
|
||||||
|
allowDeprecatedUsage = false,
|
||||||
}) => {
|
}) => {
|
||||||
const decorator = options => (getStory, context) => {
|
const decorator = options => (getStory, context) => {
|
||||||
const parameters = context.parameters && context.parameters[parameterName];
|
const parameters = context.parameters && context.parameters[parameterName];
|
||||||
@ -44,11 +45,17 @@ export const makeDecorator = ({
|
|||||||
return decorator(...args)(...innerArgs);
|
return decorator(...args)(...innerArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Used to wrap a story directly .add('story', decorator(options)(() => <Story />))
|
if (allowDeprecatedUsage) {
|
||||||
// This is now deprecated:
|
// Used to wrap a story directly .add('story', decorator(options)(() => <Story />))
|
||||||
return deprecate(
|
// This is now deprecated:
|
||||||
context => decorator(...args)(innerArgs[0], context),
|
return deprecate(
|
||||||
`Passing stories directly into ${name}() is deprecated, instead use addDecorator(${name}) and pass options with the '${parameterName}' parameter`
|
context => decorator(...args)(innerArgs[0], context),
|
||||||
|
`Passing stories directly into ${name}() is deprecated, instead use addDecorator(${name}) and pass options with the '${parameterName}' parameter`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error(
|
||||||
|
`Passing stories directly into ${name}() is not allowed, instead use addDecorator(${name}) and pass options with the '${parameterName}' parameter`
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -103,10 +103,15 @@ describe('makeDecorator', () => {
|
|||||||
expect(story).toHaveBeenCalled();
|
expect(story).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('passes options added at story time, but with a deprecation warning', () => {
|
it('passes options added at story time, but with a deprecation warning, if allowed', () => {
|
||||||
deprecatedFns = [];
|
deprecatedFns = [];
|
||||||
const wrapper = jest.fn();
|
const wrapper = jest.fn();
|
||||||
const decorator = makeDecorator({ wrapper, name: 'test', parameterName: 'test' });
|
const decorator = makeDecorator({
|
||||||
|
wrapper,
|
||||||
|
name: 'test',
|
||||||
|
parameterName: 'test',
|
||||||
|
allowDeprecatedUsage: true,
|
||||||
|
});
|
||||||
const options = 'test-val';
|
const options = 'test-val';
|
||||||
const story = jest.fn();
|
const story = jest.fn();
|
||||||
const decoratedStory = decorator(options)(story);
|
const decoratedStory = decorator(options)(story);
|
||||||
@ -121,4 +126,17 @@ describe('makeDecorator', () => {
|
|||||||
});
|
});
|
||||||
expect(deprecatedFns[0].deprecatedFn).toHaveBeenCalled();
|
expect(deprecatedFns[0].deprecatedFn).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('throws if options are added at storytime, if not allowed', () => {
|
||||||
|
const wrapper = jest.fn();
|
||||||
|
const decorator = makeDecorator({
|
||||||
|
wrapper,
|
||||||
|
name: 'test',
|
||||||
|
parameterName: 'test',
|
||||||
|
allowDeprecatedUsage: false,
|
||||||
|
});
|
||||||
|
const options = 'test-val';
|
||||||
|
const story = jest.fn();
|
||||||
|
expect(() => decorator(options)(story)).toThrow(/not allowed/);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user