mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-02 05:03:44 +08:00
Add deprecation warning
This commit is contained in:
parent
973e8ea173
commit
ec8ee5cb2d
@ -30,7 +30,7 @@ const defaultMarksyConf = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export function withInfo(info, _options) {
|
export function withInfo(info, _options) {
|
||||||
return (storyFn) => {
|
return storyFn => {
|
||||||
if (typeof storyFn !== 'function') {
|
if (typeof storyFn !== 'function') {
|
||||||
if (typeof info === 'function') {
|
if (typeof info === 'function') {
|
||||||
_options = storyFn; // eslint-disable-line
|
_options = storyFn; // eslint-disable-line
|
||||||
@ -79,12 +79,34 @@ export function withInfo(info, _options) {
|
|||||||
{storyFn(context)}
|
{storyFn(context)}
|
||||||
</Story>
|
</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 {
|
export default {
|
||||||
addWithInfo(storyName, info, storyFn, _options) {
|
addWithInfo(storyName, info, storyFn, _options) {
|
||||||
return this.add(storyName, withInfo(info, _options)(storyFn));
|
return this.add(storyName, warning(withInfo(info, _options)(storyFn)));
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -47,20 +47,13 @@ const InfoButton = () =>
|
|||||||
background: 'rgb(34, 136, 204)',
|
background: 'rgb(34, 136, 204)',
|
||||||
color: 'rgb(255, 255, 255)',
|
color: 'rgb(255, 255, 255)',
|
||||||
padding: '5px 15px',
|
padding: '5px 15px',
|
||||||
margin: 4,
|
margin: 10,
|
||||||
marginTop: 16,
|
|
||||||
cursor: 'pointer',
|
|
||||||
borderRadius: '0px 0px 0px 5px',
|
borderRadius: '0px 0px 0px 5px',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{' '}Show Info{' '}
|
{' '}Show Info{' '}
|
||||||
</span>;
|
</span>;
|
||||||
|
|
||||||
const withNotes = (note, storyFn) => context =>
|
|
||||||
<WithNotes notes={note}>
|
|
||||||
{storyFn(context)}
|
|
||||||
</WithNotes>;
|
|
||||||
|
|
||||||
storiesOf('Button', module)
|
storiesOf('Button', module)
|
||||||
.addDecorator(withKnobs)
|
.addDecorator(withKnobs)
|
||||||
.add('with text', () => <Button onClick={action('clicked')}>Hello Button</Button>)
|
.add('with text', () => <Button onClick={action('clicked')}>Hello Button</Button>)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user