fix optional description

This commit is contained in:
Daniel Duan 2017-10-26 16:47:03 -04:00
parent 03c3d6dae4
commit c753d744e3
2 changed files with 20 additions and 1 deletions

View File

@ -188,3 +188,12 @@ storiesOf('Button').addWithInfo(
}
}
)
storiesOf('shared/ProgressBar', module)
.addDecorator(withKnobs)
.addWithInfo('default style', () => (
<ProgressBar progress={number('progress', 25)}
delay={number('delay', 500)}
/>
));

View File

@ -36,6 +36,10 @@ export default function transformer(file, api) {
*/
const getOptions = args => {
if (args[3] === undefined) {
if (args[2] === undefined) {
// when the optional description string is not supplied for addWithInfo, just use story name
return [args[0]];
}
return [args[1]];
}
return [
@ -56,10 +60,16 @@ export default function transformer(file, api) {
const node = addWithInfoExpression.node;
const args = node.arguments;
// if optional description string is not supplied, the story component becomes second arg
const storyComponent = args[2] ? args[2] : args[1];
node.callee.property.name = 'add';
node.arguments = [
args[0],
j.callExpression(j.callExpression(j.identifier('withInfo'), getOptions(args)), [args[2]]),
j.callExpression(
j.callExpression(j.identifier('withInfo'), getOptions(args)),
storyComponent
),
];
return node;