Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Commit 705199c

Browse files
committed
adds handling of stories wrapped with info addon
1 parent 1e09baf commit 705199c

File tree

4 files changed

+196
-12
lines changed

4 files changed

+196
-12
lines changed

example/stories/index.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,25 @@ import React from 'react'
22
import { storiesOf } from '@storybook/react'
33
import { withSmartKnobs } from '../../src'
44
import { withKnobs, select } from '@storybook/addon-knobs'
5+
import { withInfo } from '@storybook/addon-info'
56

67
import SmartKnobedComponent from './SmartKnobedComponent'
78
import SmartKnobedComponentMissingProps from './SmartKnobedComponentMissingProps'
89

910
const stub = fn => fn()
1011

12+
13+
storiesOf("Example of smart Knobs", module)
14+
.addDecorator(withSmartKnobs)
15+
.addDecorator(withKnobs)
16+
.add("full example", () => <SmartKnobedComponent />);
17+
1118
storiesOf('Example of smart Knobs', module)
1219
.addDecorator(withSmartKnobs)
1320
.addDecorator(withKnobs)
14-
.add('full example', () => (
21+
.add('full example with info', withInfo('test')(() => (
1522
<SmartKnobedComponent />
16-
))
23+
)))
1724

1825
storiesOf('Smart Knobs missing props', module)
1926
.addDecorator(withSmartKnobs)

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"react": "^0.14.7 || ^15.5.4"
2020
},
2121
"devDependencies": {
22+
"@storybook/addon-info": "^3.2.10",
2223
"@storybook/addon-knobs": "^3.0.0",
2324
"@storybook/addon-options": "^3.0.0",
2425
"@storybook/react": "^3.0.0",

src/index.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,15 @@ addKnobResolver({
5656

5757
export const withSmartKnobs = (story, context) => {
5858
const component = story(context)
59-
const { __docgenInfo: { props } = { props: { } } } = component.type
59+
60+
let target = component.props.marksyConf && component.props.propTables && component.props.propTablesExclude
61+
? component.props.children
62+
: component
63+
64+
const { __docgenInfo: { props } = { props: {} } } = target.type
6065
const defaultProps = {
61-
...(component.type.defaultProps || {}),
62-
...component.props
66+
...(target.type.defaultProps || {}),
67+
...target.props
6368
}
6469

6570
const finalProps = props ? Object.keys(props).reduce((acc, n) => {
@@ -76,7 +81,13 @@ export const withSmartKnobs = (story, context) => {
7681
}
7782
}, {}) : {}
7883

79-
return cloneElement(component, resolvePropValues(finalProps, defaultProps))
84+
const newProps = resolvePropValues(finalProps, defaultProps)
85+
86+
if (component.props.marksyConf) {
87+
return cloneElement(component, { ...component.props, children: cloneElement(component.props.children, newProps) })
88+
}
89+
90+
return cloneElement(component, newProps)
8091
}
8192

8293
const resolvePropValues = (propTypes, defaultProps) => {

0 commit comments

Comments
 (0)