Add deprecation warning

This commit is contained in:
Oleg Proskurin 2017-07-11 20:06:39 +03:00
parent 973e8ea173
commit ec8ee5cb2d
2 changed files with 26 additions and 11 deletions

View File

@ -30,7 +30,7 @@ const defaultMarksyConf = {
};
export function withInfo(info, _options) {
return (storyFn) => {
return storyFn => {
if (typeof storyFn !== 'function') {
if (typeof info === 'function') {
_options = storyFn; // eslint-disable-line
@ -79,12 +79,34 @@ export function withInfo(info, _options) {
{storyFn(context)}
</Story>
);
};}
};
};
}
function deprecate() {
const logger = console;
let warned = false;
const deprecated = msg => {
if (!warned) {
logger.warn(msg);
warned = true;
}
};
return deprecated;
}
const showWaring = deprecate();
const warning = storyFn => context => {
showWaring(
`Warning: Applying addWithInfo is deprecated and will be removed in the next major release. Use withInfo from the same package instead. Please check the "${context.kind}/${context.story}" story. See https://github.com/storybooks/storybook/tree/master/addons/info`
);
return storyFn(context);
};
export default {
addWithInfo(storyName, info, storyFn, _options) {
return this.add(storyName, withInfo(info, _options)(storyFn));
return this.add(storyName, warning(withInfo(info, _options)(storyFn)));
},
};

View File

@ -47,20 +47,13 @@ const InfoButton = () =>
background: 'rgb(34, 136, 204)',
color: 'rgb(255, 255, 255)',
padding: '5px 15px',
margin: 4,
marginTop: 16,
cursor: 'pointer',
margin: 10,
borderRadius: '0px 0px 0px 5px',
}}
>
{' '}Show Info{' '}
</span>;
const withNotes = (note, storyFn) => context =>
<WithNotes notes={note}>
{storyFn(context)}
</WithNotes>;
storiesOf('Button', module)
.addDecorator(withKnobs)
.add('with text', () => <Button onClick={action('clicked')}>Hello Button</Button>)