Skip to content

Commit

Permalink
Addon-docs: Convert repo stories to new module format (#7175)
Browse files Browse the repository at this point in the history
Addon-docs: Convert repo stories to new module format
  • Loading branch information
shilman authored Jun 28, 2019
2 parents b693b38 + eece7bc commit e937c58
Show file tree
Hide file tree
Showing 198 changed files with 6,269 additions and 3,989 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ function integrityTest(integrityOptions, stories2snapsConverter) {
const possibleStoriesFiles = stories2snapsConverter.getPossibleStoriesFiles(fileName);
return !possibleStoriesFiles.some(fs.existsSync);
});
expect(abandonedStoryshots.length).toBe(0);

expect(abandonedStoryshots).toEqual([]);
});
});
}
Expand Down
1 change: 1 addition & 0 deletions app/rax/src/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ export {
getStorybook,
forceReRender,
raw,
load,
} from './preview';
7 changes: 5 additions & 2 deletions app/rax/src/client/preview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import { start } from '@storybook/core/client';
import './globals';
import render from './render';

const { clientApi, configApi, forceReRender } = start(render);
const { load: coreLoad, clientApi, configApi, forceReRender } = start(render);

export const {
storiesOf,
setAddon,
addDecorator,
addParameters,
Expand All @@ -15,5 +14,9 @@ export const {
raw,
} = clientApi;

const framework = 'rax';
export const storiesOf = (...args) => clientApi.storiesOf(...args).addParameters({ framework });
export const load = (...args) => coreLoad(...args, framework);

export const { configure } = configApi;
export { forceReRender };
13 changes: 2 additions & 11 deletions examples/cra-kitchen-sink/.storybook/config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { configure, addParameters, addDecorator } from '@storybook/react';
import { load, addParameters, addDecorator } from '@storybook/react';
import { create } from '@storybook/theming';
import { withA11y } from '@storybook/addon-a11y';

Expand All @@ -22,13 +22,4 @@ addParameters({
},
});

function loadStories() {
// order of imports will determine the order of the stories unless a storySort is passed to the options object
require('../src/stories/welcome');

// automatically import all story js files that end with *.stories.js
const req = require.context('../src/stories', true, /\.stories\.js$/);
req.keys().forEach(filename => req(filename));
}

configure(loadStories, module);
load(require.context('../src/stories', true, /\.stories\.js$/), module);
11 changes: 9 additions & 2 deletions examples/cra-kitchen-sink/src/stories/App.stories.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
// FIXME: svgr issue @igor-dv

import React from 'react';
import { storiesOf } from '@storybook/react';

import App from '../App';

storiesOf('App', module).add('full app', () => <App />);
export default {
title: 'App',
};

export const fullApp = () => <App />;

fullApp.story = {
name: 'full app',
};
7 changes: 5 additions & 2 deletions examples/cra-kitchen-sink/src/stories/Lifecycle.stories.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import React from 'react';
import { storiesOf } from '@storybook/react';
import LifecycleLogger from '../components/LifecycleLogger';

storiesOf('Lifecycle', module).add('logging', () => <LifecycleLogger />);
export default {
title: 'Lifecycle',
};

export const logging = () => <LifecycleLogger />;
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import React from 'react';
import { storiesOf, forceReRender } from '@storybook/react';
import { forceReRender } from '@storybook/react';

let Component;

storiesOf('CRA', module).add('Dynamic import', () => {
export default {
title: 'CRA',
};

export const story1 = () => {
if (!Component) {
import('@storybook/react/demo').then(({ Button }) => {
Component = Button;
Expand All @@ -14,4 +18,6 @@ storiesOf('CRA', module).add('Dynamic import', () => {
}

return <Component>Hello Button</Component>;
});
};

story1.story = { name: 'Dynamic import' };
10 changes: 7 additions & 3 deletions examples/cra-kitchen-sink/src/stories/force-rerender.stories.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import React from 'react';
import { storiesOf, forceReRender } from '@storybook/react';
import { forceReRender } from '@storybook/react';

let count = 0;
const increment = () => {
count += 1;
forceReRender();
};

storiesOf('Force ReRender', module).add('button', () => (
export default {
title: 'Force ReRender',
};

export const button = () => (
<button type="button" onClick={increment}>
Click me to increment: {count}
</button>
));
);
95 changes: 55 additions & 40 deletions examples/cra-kitchen-sink/src/stories/index.stories.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable react/destructuring-assignment */
import React from 'react';
import { storiesOf } from '@storybook/react';
import { action } from '@storybook/addon-actions';
import { withInfo } from '@storybook/addon-info';
import { Button } from '@storybook/react/demo';
Expand All @@ -23,46 +23,61 @@ const InfoButton = () => (
</span>
);

storiesOf('Button', module)
.addParameters({
export default {
title: 'Button',

parameters: {
component: Button,
})
.add('with text', () => <Button onClick={action('clicked', { depth: 1 })}>Hello Button</Button>, {
},
};

export const story1 = () => <Button onClick={action('clicked', { depth: 1 })}>Hello Button</Button>;
story1.story = {
name: 'with text',
parameters: {
options: { selectedPanel: 'storybook/actions/panel' },
},
};

export const story2 = () => (
<Button onClick={action('clicked')}>
<span role="img" aria-label="yolo">
😀 😎 👍 💯
</span>
</Button>
);
story2.story = {
name: 'with some emoji',
parameters: {
options: { selectedPanel: 'storybook/actions/panel' },
})
.add(
'with some emoji',
() => (
<Button onClick={action('clicked')}>
<span role="img" aria-label="yolo">
😀 😎 👍 💯
</span>
</Button>
),
{
options: { selectedPanel: 'storybook/actions/panel' },
}
)
.add('with notes', () => <Button>Check my notes in the notes panel</Button>, {
},
};

export const story3 = () => <Button>Check my notes in the notes panel</Button>;
story3.story = {
name: 'with notes',
parameters: {
notes: 'A very simple button',
options: { selectedPanel: 'storybook/notes/panel' },
})
.add(
'with new info',
context => (
<Container>
<span>
click the <InfoButton /> label in top right for info about "{context.name}"
</span>
</Container>
),
{
notes: 'Composition: Info(Notes())',
options: { selectedPanel: 'storybook/info/panel' },
decorators: [
withInfo(
'Use the [info addon](https://github.com/storybookjs/storybook/tree/master/addons/info) with its new painless API.'
),
],
}
);
},
};

export const story4 = context => (
<Container>
<span>
click the <InfoButton /> label in top right for info about "{context.name}"
</span>
</Container>
);
story4.story = {
name: 'with new info',
parameters: {
notes: 'Composition: Info(Notes())',
options: { selectedPanel: 'storybook/info/panel' },
decorators: [
withInfo(
'Use the [info addon](https://github.com/storybookjs/storybook/tree/master/addons/info) with its new painless API.'
),
],
},
};
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import React from 'react';
import { storiesOf } from '@storybook/react';
import { action } from '@storybook/addon-actions';
import centered from '@storybook/addon-centered/react';
import { Button } from '@storybook/react/demo';

storiesOf('Some really long story kind description', module)
.addDecorator(centered)
.add('with text', () => <Button onClick={action('clicked')}>Hello Button</Button>);
export default {
title: 'Some really long story kind description',
decorators: [centered],
};

export const story1 = () => <Button onClick={action('clicked')}>Hello Button</Button>;
story1.story = { name: 'with text' };
14 changes: 9 additions & 5 deletions examples/cra-kitchen-sink/src/stories/welcome.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import React from 'react';
import { Welcome } from '@storybook/react/demo';
import { storiesOf } from '@storybook/react';
import { linkTo } from '@storybook/addon-links';

storiesOf('Welcome', module)
.addParameters({
export default {
title: 'Welcome',

parameters: {
component: Welcome,
})
.add('to Storybook', () => <Welcome showApp={linkTo('Button')} />);
},
};

export const story1 = () => <Welcome showApp={linkTo('Button')} />;
story1.title = 'to Storybook';
8 changes: 2 additions & 6 deletions examples/cra-react15/.storybook/config.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { configure, addParameters } from '@storybook/react';
import { load, addParameters } from '@storybook/react';
import { create } from '@storybook/theming/create';

function loadStories() {
require('../src/stories');
}

addParameters({
options: {
theme: create({ colorPrimary: 'hotpink', colorSecondary: 'orangered' }),
},
});

configure(loadStories, module);
load(require.context('../src/stories', true, /\.stories\.js$/), module);
22 changes: 22 additions & 0 deletions examples/cra-react15/src/stories/button.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react';
import { action } from '@storybook/addon-actions';
import { Button } from '@storybook/react/demo';

export default {
title: 'Button',
parameters: {
component: Button,
},
};

export const story1 = () => <Button onClick={action('clicked')}>Hello Button</Button>;
story1.story = { name: 'with text' };

export const story2 = () => (
<Button onClick={action('clicked')}>
<span role="img" aria-label="so cool">
😀 😎 👍 💯
</span>
</Button>
);
story2.story = { name: 'with some emoji' };
26 changes: 0 additions & 26 deletions examples/cra-react15/src/stories/index.js

This file was deleted.

13 changes: 13 additions & 0 deletions examples/cra-react15/src/stories/welcome.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from 'react';
import { linkTo } from '@storybook/addon-links';
import { Welcome } from '@storybook/react/demo';

export default {
title: 'Welcome',
parameters: {
component: Welcome,
},
};

export const story1 = () => <Welcome showApp={linkTo('Button')} />;
story1.story = { name: 'to Storybook' };
11 changes: 2 additions & 9 deletions examples/ember-cli/.storybook/config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { configure, addParameters, addDecorator } from '@storybook/ember';
import { load, addParameters, addDecorator } from '@storybook/ember';
import { withA11y } from '@storybook/addon-a11y';

addDecorator(withA11y);
Expand All @@ -9,11 +9,4 @@ addParameters({
},
});

function loadStories() {
require('../stories/index.stories');

const req = require.context('../stories', true, /\.stories\.js$/);
req.keys().forEach(filename => req(filename));
}

configure(loadStories, module);
load(require.context('../stories', true, /\.stories\.js$/), module);
Loading

1 comment on commit e937c58

@vercel
Copy link

@vercel vercel bot commented on e937c58 Jun 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.