UNPKG

react-carousel-query

Version:

A infinite carousel component made with react that handles the pagination for you.

45 lines (38 loc) 1.21 kB
export const makeDecorator = ({ name, parameterName, wrapper, skipIfNoParametersOrOptions = false }) => { const decorator = options => (storyFn, context) => { const parameters = context.parameters && context.parameters[parameterName]; if (parameters && parameters.disable) { return storyFn(context); } if (skipIfNoParametersOrOptions && !options && !parameters) { return storyFn(context); } return wrapper(storyFn, context, { options, parameters }); }; return (...args) => { // Used without options as .addDecorator(decorator) if (typeof args[0] === 'function') { return decorator()(...args); } return (...innerArgs) => { // Used as [.]addDecorator(decorator(options)) if (innerArgs.length > 1) { // Used as [.]addDecorator(decorator(option1, option2)) if (args.length > 1) { return decorator(args)(...innerArgs); } return decorator(...args)(...innerArgs); } throw new Error(`Passing stories directly into ${name}() is not allowed, instead use addDecorator(${name}) and pass options with the '${parameterName}' parameter`); }; }; };