mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-01 05:05:25 +08:00
fix optional description
This commit is contained in:
parent
03c3d6dae4
commit
c753d744e3
@ -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)}
|
||||
/>
|
||||
|
||||
));
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user