storybook-addon-deep-controls
Version:
A Storybook addon that extends @storybook/addon-controls and provides an alternative to interacting with object arguments
57 lines (56 loc) • 2.11 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const story_1 = require("./utils/story");
// todo test it does not do anything custom if deepControls is not enabled
const preview = {
argsEnhancers: [
/**
* If enabled, adds initial args to fit the flattened controls
*
* @note This only gets called when the story is rendered (ie not when controls change etc)
*
* @note Might be called multiple times during render for the same story
*/
(context) => {
if (!context.parameters.deepControls?.enabled) {
return context.initialArgs;
}
return (0, story_1.createFlattenedArgs)(context);
},
],
argTypesEnhancers: [
/**
* If enabled, replaces controls with flattened controls based on the initial args
* and these will be what the user interacts with, ie the flat args become the source of truth
*
* @note Storybook still adds in the un-flattened args but these should be ignored
*
* @note This only gets called when the story is rendered (ie not when controls change etc)
*
* @note Might be called multiple times during render for the same story
*/
(context) => {
if (!context.parameters.deepControls?.enabled) {
return context.argTypes;
}
return (0, story_1.createFlattenedArgTypes)(context);
},
],
decorators: [
/**
* If enabled, un-flattens the args from controls to the original format
* before passing them to the story component
*/
(storyFn, context) => {
if (!context.parameters.deepControls?.enabled) {
return storyFn(context);
}
return storyFn({
...context,
args: (0, story_1.expandObject)(context.args),
initialArgs: (0, story_1.expandObject)(context.initialArgs),
});
},
],
};
exports.default = preview;