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

Commit

Permalink
Merge pull request #80 from petermikitsh/disable-addon
Browse files Browse the repository at this point in the history
feat: disable addon
  • Loading branch information
ndelangen authored Jun 22, 2020
2 parents 523c59d + a9f2753 commit bfa6c65
Show file tree
Hide file tree
Showing 3 changed files with 2,657 additions and 3,033 deletions.
28 changes: 15 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,20 @@
"test": "jest"
},
"devDependencies": {
"@babel/cli": "^7.4.3",
"@babel/core": "^7.4.3",
"@babel/plugin-proposal-class-properties": "^7.4.0",
"@babel/plugin-proposal-export-default-from": "^7.2.0",
"@babel/preset-env": "^7.4.3",
"@babel/preset-flow": "^7.0.0",
"@babel/preset-react": "^7.0.0",
"@storybook/addon-actions": "^5.0.0",
"@storybook/addon-info": "^5.0.0",
"@storybook/addon-knobs": "^5.0.0",
"@storybook/addon-options": "^5.0.0",
"@storybook/client-logger": "^5.0.0",
"@storybook/react": "^5.0.0",
"@babel/cli": "^7.9.0",
"@babel/core": "^7.9.0",
"@babel/plugin-proposal-class-properties": "^7.9.0",
"@babel/plugin-proposal-export-default-from": "^7.9.0",
"@babel/preset-env": "^7.9.5",
"@babel/preset-flow": "^7.9.0",
"@babel/preset-react": "7.9.0",
"@storybook/addon-actions": "^5.3.19",
"@storybook/addon-info": "^5.3.19",
"@storybook/addon-knobs": "^5.3.19",
"@storybook/addon-options": "^5.3.19",
"@storybook/addons": "^5.3.19",
"@storybook/client-logger": "^5.3.19",
"@storybook/react": "^5.3.19",
"@types/react": "^16.9.1",
"babel-loader": "^8.0.4",
"core-js": "^3.0.1",
Expand All @@ -46,6 +47,7 @@
"peerDependencies": {
"@storybook/addon-knobs": "^5.0.0",
"@storybook/addon-options": "^5.0.0",
"@storybook/addons": "^5.0.0",
"@storybook/react": "^5.0.0",
"babel-plugin-react-docgen": "^2.0.0",
"react": ">=15.0.0 || ^16.0.0"
Expand Down
22 changes: 14 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { cloneElement, Children } from 'react'
import { action } from '@storybook/addon-actions'
import { logger } from '@storybook/client-logger'
import { text, boolean, number, object, select } from '@storybook/addon-knobs'
import { makeDecorator } from '@storybook/addons'

const QUOTED_STRING_REGEXP = /^['"](.*)['"]$/

Expand Down Expand Up @@ -123,17 +124,22 @@ const mutateChildren = (component, context, opts) => {
}) })
}

export const withSmartKnobs = (opts = {}) => (story, context) => {
const component = story(context)
export const withSmartKnobs = (opts = {}) => makeDecorator({
name: 'withSmartKnobs',
parameterName: 'smartKnobs',
skipIfNoParametersOrOptions: false,
wrapper: (story, context) => {
const component = story(context)

if (!component.type.__docgenInfo && component.props.children) {
return mutateChildren(component, context, opts)
}
if (!component.type.__docgenInfo && component.props.children) {
return mutateChildren(component, context, opts)
}

const newProps = getNewProps(component, context, opts)
const newProps = getNewProps(component, context, opts)

return cloneElement(component, newProps)
}
return cloneElement(component, newProps)
},
})

const getDefaultValue = (defaultProp, propType) => {
// If the defaultProp is not undefined, return it. This avoids relying on the
Expand Down
Loading

0 comments on commit bfa6c65

Please sign in to comment.