Skip to content
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

Core: Top-level components in MDX/Module formats #7524

Merged
merged 5 commits into from
Jul 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions addons/docs/__snapshots__/mdx-compiler-plugin.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@ function MDXContent({ components, ...props }) {
<MDXLayout {...layoutProps} {...props} components={components} mdxType=\\"MDXLayout\\">
<Meta
title=\\"Button\\"
component={Button}
parameters={{
component: Button,
notes: 'component notes',
}}
mdxType=\\"Meta\\"
Expand Down Expand Up @@ -323,7 +323,6 @@ storyNotes.story.parameters = {
const componentMeta = {
title: 'Button',
parameters: {
component: Button,
notes: 'component notes',
},
includeStories: ['componentNotes', 'storyNotes'],
Expand Down Expand Up @@ -364,8 +363,8 @@ function MDXContent({ components, ...props }) {
<MDXLayout {...layoutProps} {...props} components={components} mdxType=\\"MDXLayout\\">
<Meta
title=\\"Button\\"
component={Button}
parameters={{
component: Button,
notes: 'component notes',
}}
mdxType=\\"Meta\\"
Expand Down Expand Up @@ -400,7 +399,6 @@ two.story.parameters = { mdxSource: '<Button>Two</Button>' };
const componentMeta = {
title: 'Button',
parameters: {
component: Button,
notes: 'component notes',
},
includeStories: ['helloButton', 'two'],
Expand Down
2 changes: 1 addition & 1 deletion addons/docs/fixtures/parameters.mdx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Button } from '@storybook/react/demo';
import { Story, Meta } from '@storybook/addon-docs/blocks';

<Meta title="Button" parameters={{ component: Button, notes: 'component notes' }} />
<Meta title="Button" component={Button} parameters={{ notes: 'component notes' }} />

<Story name="component notes">
<Button>Component notes</Button>
Expand Down
2 changes: 1 addition & 1 deletion addons/docs/fixtures/previews.mdx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Button } from '@storybook/react/demo';
import { Preview, Story, Meta } from '@storybook/addon-docs/blocks';

<Meta title="Button" parameters={{ component: Button, notes: 'component notes' }} />
<Meta title="Button" component={Button} parameters={{ notes: 'component notes' }} />

# Preview

Expand Down
1 change: 1 addition & 0 deletions addons/docs/src/blocks/Meta.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ type Decorator = (...args: any) => any;

interface MetaProps {
title: string;
component?: any;
decorators?: [Decorator];
parameters?: any;
}
Expand Down
7 changes: 5 additions & 2 deletions docs/src/pages/basics/writing-stories/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ import React from 'react';
import { action } from '@storybook/addon-actions';
import Button from './Button';

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

export const withText = () => <Button onClick={action('clicked')}>Hello Button</Button>;

Expand All @@ -33,7 +36,7 @@ This is what you'll see in Storybook:

![Basic stories](../static/basic-stories.png)

The named exports define the Button's stories, and the `default` export defines metadata that applies to the group. In this case, the title determines the title of the group in Storybook's left-hand navigation panel.
The named exports define the Button's stories, and the `default` export defines metadata that applies to the group. In this case, the `component` is `Button`. The title determines the title of the group in Storybook's left-hand navigation panel. In this case it's located at the top level, but typically it's [positioned within the story hierarchy](#story-hierarchy).

This example is written in Storybook's [Module format](../../formats/module-story-format/). Storybook also supports:

Expand Down
14 changes: 7 additions & 7 deletions docs/src/pages/formats/module-story-format/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ The module format is supported in all frameworks except React Native, where you

## Default export

The default export defines metadata about your component, including its `title` (where it will show up in the Storybook navigation UI), [decorators](../../basics/writing-stories/#decorators) and [parameters](../../writing-stories/#parameters).
The default export defines metadata about your component, including the `component` itself, its `title` (where it will show up in the [navigation UI story hierarchy](../../basics/writing-stories/#story-hierarchy)), [decorators](../../basics/writing-stories/#decorators), and [parameters](../../basics/writing-stories/#parameters).

```js
import MyComponent from './MyComponent';

export default {
title: 'Path|To/Some/Component',
title: 'Path|To/MyComponent',
component: MyComponent,
decorators: [ ... ],
parameters: { ... }
}
Expand All @@ -27,7 +30,7 @@ For more examples, see [writing stories](../../basics/writing-stories/)

By default every named export in the file represents a story function.

Story functions can be annotated with a `story` object to define story-level [decorators](../../basics/writing-stories/#decorators) and [parameters](../../writing-stories/#parameters), and also to define the `name` of the story.
Story functions can be annotated with a `story` object to define story-level [decorators](../../basics/writing-stories/#decorators) and [parameters](../../basics/writing-stories/#parameters), and also to define the `name` of the story.

The `name` is useful if you want to use names with spaces, names that correspond to restricted keywords in Javascript, or names that collide with other variables in the file. If it's not specified, the export name will be used instead.

Expand Down Expand Up @@ -55,6 +58,7 @@ import someData from './data.json';

export default {
title: 'MyComponent',
component: MyComponent,
includeStories: ['simpleStory', 'complexStory']
}
export const simpleData = { foo: 1, bar: 'baz' };
Expand All @@ -71,7 +75,3 @@ For this specific example the equivalent result can be achieved in a few ways de
- `includeStories: /.*Story$/`
- `excludeStories: ['simpleData', 'complexData']`
- `excludeStories: /.*Data$/`

```

```
4 changes: 1 addition & 3 deletions examples/mithril-kitchen-sink/src/stories/welcome.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import Welcome from '../Welcome';

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

export const story1 = () => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const text = 'Testing the a11y addon';

export default {
title: 'Addons|A11y/BaseButton',
component: BaseButton,
parameters: {
component: BaseButton,
options: { selectedPanel: 'storybook/a11y/panel' },
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const text = 'Testing the a11y addon';

export default {
title: 'Addons|A11y/Button',
component: Button,
parameters: {
component: Button,
options: { selectedPanel: 'storybook/a11y/panel' },
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const text = 'Testing the a11y addon';

export default {
title: 'Addons|A11y/Form',
component: Form,
parameters: {
component: Form,
options: { selectedPanel: 'storybook/a11y/panel' },
},
};
Expand Down
4 changes: 1 addition & 3 deletions examples/official-storybook/stories/addon-docs.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import DocgenButton from '../components/DocgenButton';

export default {
title: 'Addons|Docs/stories',
parameters: {
component: DocgenButton,
},
component: DocgenButton,
};

export const basic = () => <div>Click docs tab to see basic docs</div>;
Expand Down
3 changes: 2 additions & 1 deletion examples/official-storybook/stories/addon-docs.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ import DocgenButton from '../components/DocgenButton';

<Meta
title="Addons|Docs/mdx"
component={Button}
decorators={[storyFn => <div style={{ backgroundColor: 'yellow' }}>{storyFn()}</div>]}
parameters={{ component: Button, notes: 'component notes' }}
parameters={{ notes: 'component notes' }}
/>

# Selected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ fullControlOverStylesUsingAFunction.story = {
export const useACustomComponentForTheTable = () => <BaseButton label="Button" />;
useACustomComponentForTheTable.story = {
name: 'Use a custom component for the table',
component: TableComponent,
parameters: {
component: TableComponent,
info: {
TableComponent,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ let injectedIsLoading = false;
export default {
title: 'Addons|Knobs.withKnobs',
decorators: [withKnobs],

parameters: {
component: withKnobs,
},
};

export const tweaksStaticValues = () => {
Expand Down
4 changes: 1 addition & 3 deletions examples/official-storybook/stories/demo/button.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import { Button } from '@storybook/react/demo';

export default {
title: 'Other|Demo/Button',
parameters: {
component: Button,
},
component: Button,
};

export const withText = () => <Button onClick={action('clicked')}>Hello Button</Button>;
Expand Down
7 changes: 1 addition & 6 deletions examples/official-storybook/stories/demo/button.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@ import { action } from '@storybook/addon-actions';
import { Button } from '@storybook/react/demo';
import { Meta, Story, Preview } from '@storybook/addon-docs/blocks';

<Meta
title="Other|Demo/ButtonMdx"
parameters={{
component: Button,
}}
/>
<Meta title="Other|Demo/ButtonMdx" component={Button} />

# Simple Button

Expand Down
4 changes: 1 addition & 3 deletions examples/official-storybook/stories/demo/welcome.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import { Welcome } from '@storybook/react/demo';

export default {
title: 'Other|Demo/Welcome',
parameters: {
component: Welcome,
},
component: Welcome,
};

export const toStorybook = () => <Welcome showApp={linkTo('Button')} />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ import Button from '../Button';

export default {
title: 'Addons|Centered',
component: Button,
decorators: [Centered],

parameters: {
component: Centered,
},
};

export const button = () => <Button>A button</Button>;
Expand Down
5 changes: 1 addition & 4 deletions examples/preact-kitchen-sink/src/stories/button.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ import Button from '../Button';

export default {
title: 'Button',

parameters: {
component: Button,
},
component: Button,
};

export const withText = () => <Button onclick={action('clicked')}>Hello Button</Button>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ import Button from '../components/Button.svelte';

export default {
title: 'Addon|Centered',
component: Button,
decorators: [Centered],
parameters: {
component: Centered,
},
};

export const rounded = () => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ import MyButton from './Button.vue';

export default {
title: 'Addon|Centered',
component: MyButton,
decorators: [Centered],
parameters: {
component: Centered,
},
};

export const rounded = () => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ import App from '../../App.vue';

export default {
title: 'App',

parameters: {
component: App,
},
component: App,
};

export const app = () => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import Button from '../Button.vue';

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

export const rounded = () => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { Meta, Story } from '@storybook/addon-docs/blocks';

<Meta
title='Button'
component={Button}
parameters={{
component: Button,
foo: 1,
bar: 2,
}} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { storiesOf } from '@storybook/react';

export default {
title: 'Button',
component: Button,

parameters: {
component: Button,
foo: 1,
bar: 2,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import { Button } from '@storybook/react/demo';

<Meta
title="Addons|Docs/mdx"
component={Button}
decorators={[storyFn => <div style={{ backgroundColor: 'yellow' }}>{storyFn()}</div>]}
parameters={{ component: Button, notes: 'component notes' }}
parameters={{ notes: 'component notes' }}
/>

## Getting into details
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Button } from '@storybook/react/demo';

export default {
title: 'Addons|Docs/mdx',
component: Button,

decorators: [
storyFn => (
Expand All @@ -18,7 +19,6 @@ export default {
],

parameters: {
component: Button,
notes: 'component notes',
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import { storiesOf } from '@storybook/react';

export default {
title: 'Button',

component: Button,
parameters: {
component: Button,
foo: 1,
bar: 2,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { Meta, Story } from '@storybook/addon-docs/blocks';

<Meta
title='Button'
component={Button}
parameters={{
component: Button,
foo: 1,
bar: 2,
}} />
Expand Down
Loading