@@ -3,7 +3,9 @@ import { action } from '@storybook/addon-actions'
33import { logger } from '@storybook/client-logger'
44import { text , boolean , number , object , select } from '@storybook/addon-knobs'
55
6- const cleanupString = str => str . replace ( / ^ [ ' " ] ( .* ) [ ' " ] $ / , '$1' )
6+ const QUOTED_STRING_REGEXP = / ^ [ ' " ] ( .* ) [ ' " ] $ /
7+
8+ const cleanupValue = ( value ) => typeof value === 'string' ? value . replace ( QUOTED_STRING_REGEXP , '$1' ) : value
79
810const knobResolvers = { }
911export const addKnobResolver = ( { name, resolver, weight = 0 } ) => ( knobResolvers [ name ] = { name, resolver, weight } )
@@ -51,7 +53,7 @@ const createSelect = (propName, elements, defaultValue, isRequired) => {
5153 try {
5254 const options = elements
5355 // Cleanup string quotes, if any.
54- . map ( value => cleanupString ( value . value ) )
56+ . map ( value => cleanupValue ( value . value ) )
5557 . reduce ( optionsReducer , { } )
5658 const value = defaultValue || ( isRequired && Object . values ( options ) [ 0 ] ) || undefined
5759 return select ( propName , isRequired ? options : withDefaultOption ( options ) , value )
@@ -143,7 +145,7 @@ const resolvePropValues = (propTypes, defaultProps) => {
143145 . map ( propName => resolvers . reduce (
144146 ( value , resolver ) => {
145147 const propType = propTypes [ propName ] || { }
146- const defaultValue = defaultProps [ propName ] || ( propType . defaultValue && cleanupString ( propType . defaultValue . value || '' ) ) || undefined
148+ const defaultValue = defaultProps [ propName ] || ( propType . defaultValue && cleanupValue ( propType . defaultValue . value || '' ) ) || undefined
147149
148150 return value !== undefined ? value
149151 : resolver ( propName , propType , defaultValue )
0 commit comments