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

Chore: (Docs) Updates the api/CSFsection #17153

Merged
merged 1 commit into from
Jan 7, 2022
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
16 changes: 3 additions & 13 deletions docs/api/csf.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,24 +109,12 @@ Now consider the same example, re-written with args:
'vue/button-story-click-handler-args.2.js.mdx',
'vue/button-story-click-handler-args.3.js.mdx',
'angular/button-story-click-handler-args.ts.mdx',
'svelte/button-story-click-handler-args.js.mdx',
]}
/>

<!-- prettier-ignore-end -->

At first blush, this might seem no better than the original example. However, if we add the [Docs addon](https://github.com/storybookjs/storybook/tree/master/addons/docs) and configure the [Actions addon](https://github.com/storybookjs/storybook/tree/master/addons/actions) appropriately, we can write:

<!-- prettier-ignore-start -->

<CodeSnippets
paths={[
'react/button-story-click-handler-simple-docs.js.mdx',
'vue/button-story-click-handler-simple-docs.2.js.mdx',
'vue/button-story-click-handler-simple-docs.3.js.mdx',
]}
/>

<!-- prettier-ignore-end -->

Or even more simply:

Expand All @@ -136,6 +124,8 @@ Or even more simply:
paths={[
'react/button-story-click-handler-simplificated.js.mdx',
'angular/button-story-click-handler-simplificated.ts.mdx',
'vue/button-story-click-handler-simplificated.js.mdx',
'svelte/button-story-click-handler-simplificated.native-format.mdx',
]}
/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ export default {
component: Button,
} as Meta;

export const Text: Story = (args) => ({
props: args,
template: `<storybook-button [label]="label" (onClick)="onClick()"></storybook-button>`,
export const Text: Story = ({ label, onClick }) => ({
props: {
label,
onClick,
},
});

Text.args = {
Expand Down
5 changes: 5 additions & 0 deletions docs/snippets/react/button-story-click-handler-args.js.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@ export default {
};

export const Text = ({ label, onClick }) => <Button label={label} onClick={onClick} />;

Text.args = {
label: 'Hello',
onClick: action('clicked'),
};
```

This file was deleted.

31 changes: 31 additions & 0 deletions docs/snippets/svelte/button-story-click-handler-args.js.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
```js
// Button.stories.js

import Button from './Button.svelte';

import { action } from '@storybook/addon-actions';

export default {
/* 👇 The title prop is optional.
* See https://storybook.js.org/docs/svelte/configure/overview#configure-story-loading
* to learn how to generate automatic titles
*/
title: 'Button',
component: Button,
};

export const Text = ({ label, click }) => ({
Component: Button,
props: {
label,
},
on: {
click,
},
});

Text.args = {
label: 'Hello',
click: action('clicked'),
};
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
```html
<!-- Button.stories.svelte -->

<script>
import { Meta, Template, Story } from "@storybook/addon-svelte-csf";
import Button from './Button.svelte';
</script>

<!--
See https://storybook.js.org/docs/svelte/essentials/actions#action-argtype-annotation
to learn how to set up argTypes for actions
-->

<Meta
title="Button"
component={Button}
argTypes={{
onClick: { action: "onClick" },
}}
/>

<Template let:args>
<Button {...args} on:click={args.onClick} />
</Template>

<Story name="Text" args={{ label: 'Hello' }}/>
```
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
```html
<-- Button.stories.svelte -->
<!-- Button.stories.svelte -->

<script>
import { Meta, Story } from '@storybook/addon-svelte-csf';
Expand All @@ -12,6 +12,6 @@
<Meta title="Button" component={Button}/>

<Story name="Text">
<Button text="Custom text" on:click={action('clicked')}/>
<Button text="Hello" on:click={action('clicked')}/>
</Story>
```
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const Text = (args, { argTypes }) => ({
components: { Button },
template: '<Button @onClick="onClick" :label="label" />'
});

Text.args = {
label: 'Hello',
onClick: action('clicked'),
Expand Down
8 changes: 5 additions & 3 deletions docs/snippets/vue/button-story-click-handler-args.3.js.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,19 @@ export default {
component: Button,
};

export const Text = (args) => ({
export const Text = ({ label, onClick }) => ({
components: { Button },
setup() {
return {
label: args.label,
onClick: action('clicked'),
label,
onClick,
};
},
template: '<Button @onClick="onClick" :label="label" />',
});

Text.args = {
label: 'Hello',
onClick: action('clicked'),
};
```

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
```js
// Button.stories.js

import Button from './Button.vue';

export default {
/* 👇 The title prop is optional.
* See https://storybook.js.org/docs/vue/configure/overview#configure-story-loading
* to learn how to generate automatic titles
*/
title: 'Button',
component: Button,
/*
* See https://storybook.js.org/docs/vue/essentials/actions#action-argtype-annotation
* to learn how to set up argTypes for actions
*/
argTypes: {
onClick: {},
},
};

export const Text = (args) => ({
components: { Button },
setup() {
return { args };
},
template: '<Button v-bind="args" />',
});
```