2018-04-30 00:16:36 -07:00

44 lines
1013 B
JavaScript

import addons from '@storybook/addons';
import WrapStory from './WrapStory.marko';
import {
knob,
text,
boolean,
number,
color,
object,
array,
date,
select,
selectV2,
button,
manager,
} from '../base';
export { knob, text, boolean, number, color, object, array, date, select, selectV2, button };
export const markoHandler = (channel, knobStore) => getStory => context => {
const initialContent = getStory(context);
const props = { context, storyFn: getStory, channel, knobStore, initialContent };
return WrapStory.renderSync({ props });
};
function wrapperKnobs(options) {
const channel = addons.getChannel();
manager.setChannel(channel);
if (options) channel.emit('addon:knobs:setOptions', options);
return markoHandler(channel, manager.knobStore);
}
export function withKnobs(storyFn, context) {
return wrapperKnobs()(storyFn)(context);
}
export function withKnobsOptions(options = {}) {
return (storyFn, context) => wrapperKnobs(options)(storyFn)(context);
}