-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use parameters for info addon #3697
Changes from 11 commits
a1b4296
8b174bc
848cf43
6217be8
29aaa62
0ccf131
1a81105
f1d318b
44ffa26
837cfbe
f1ae4ea
bb3c5bf
5738a8e
cd6cdd3
3cc1566
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import React from 'react'; | ||
import nestedObjectAssign from 'nested-object-assign'; | ||
import deprecate from 'util-deprecate'; | ||
import { makeDecorator } from '@storybook/addons'; | ||
import { logger } from '@storybook/client-logger'; | ||
import Story from './components/Story'; | ||
import PropTable from './components/PropTable'; | ||
|
@@ -82,13 +84,23 @@ function addInfo(storyFn, context, infoOptions) { | |
return <Story {...props}>{storyFn(context)}</Story>; | ||
} | ||
|
||
export const withInfo = textOrOptions => { | ||
const options = typeof textOrOptions === 'string' ? { text: textOrOptions } : textOrOptions; | ||
return storyFn => context => addInfo(storyFn, context, options); | ||
}; | ||
export const withInfo = makeDecorator({ | ||
name: 'withInfo', | ||
parameterName: 'info', | ||
wrapper: (getStory, context, { options, parameters }) => { | ||
const storyOptions = parameters || options; | ||
const infoOptions = typeof storyOptions === 'string' ? { text: storyOptions } : storyOptions; | ||
const mergedOptions = | ||
typeof infoOptions === 'string' ? infoOptions : { ...options, ...infoOptions }; | ||
return addInfo(getStory, context, mergedOptions); | ||
}, | ||
}); | ||
|
||
export { Story }; | ||
|
||
export function setDefaults(newDefaults) { | ||
return Object.assign(defaultOptions, newDefaults); | ||
return deprecate( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't feel like this is how I should've implemented the depreciation, but only this worked for me for some reason. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Keraito you tried I mean what you have is fine anyway ;) |
||
() => Object.assign(defaultOptions, newDefaults), | ||
'setDefaults is deprecated. Instead, you can pass options into withInfo(options) directly, or use the info parameter.' | ||
)(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to skip the addon if they don't set options or parameters? Either by passing
skipIfNoOptionsOrParameters: true
or manually doing it here..There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise (or maybe anyway) we should document setting
{ info: { disable: true } }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Def agree with the
disable: true
part, will do. I'm not so sure about theskipIfNoOptionsOrParameters
part though. I assume the both of them do the same thing, namely disable the addon entirely. Butinfo
is slightly different from the others addons imo that it does something even without configuration: display Proptypes, the component, etc.Example: https://github.com/storybooks/storybook/pull/3697/files#diff-c915ecbefba3a2734ebd93eb258431dbR353 This is basically an parameters- and options-less story, besides some minor options (header styling) and parameters (inline and manual text). The configuration don't add a lot, but the addon itself adds a lot of information stand-alone already.
So I would say just only documenting the disable flag should be the only way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, makes sense. Thanks for thinking about that.