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

Docs: Adds missing snippets args page #23665

Merged
merged 2 commits into from
Aug 1, 2023
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
8 changes: 8 additions & 0 deletions docs/snippets/common/args-in-preview.js.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
```js
// .storybook/preview.js

export default {
// The default value of the theme arg for all stories
args: { theme: 'light' },
};
```
13 changes: 13 additions & 0 deletions docs/snippets/common/args-in-preview.ts-4-9.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
```ts
// .storybook/preview.ts

// Replace your-renderer with the renderer you are using (e.g., react, vue3, angular, etc.)
import { Preview } from '@storybook/your-renderer';

const preview = {
// The default value of the theme arg for all stories
args: { theme: 'light' },
} satisfies Preview;

export default preview;
```
13 changes: 13 additions & 0 deletions docs/snippets/common/args-in-preview.ts.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
```ts
// .storybook/preview.ts

// Replace your-renderer with the renderer you are using (e.g., react, vue3, angular, etc.)
import { Preview } from '@storybook/your-renderer';

const preview: Preview = {
// The default value of the theme arg for all stories
args: { theme: 'light' },
};

export default preview;
```
12 changes: 9 additions & 3 deletions docs/writing-stories/args.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,25 @@ You can also define args at the component level; they will apply to all the comp

## Global args

You can also define args at the global level; they will apply to every component's stories unless you overwrite them. To do so, export the `args` key in your `preview.js`:
You can also define args at the global level; they will apply to every component's stories unless you overwrite them. To do so, define the `args` property in the default export of `preview.js`:

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

<CodeSnippets
paths={[
'common/button-story-project-args-theme.js.mdx',
'common/button-story-project-args-theme.ts.mdx',
'common/args-in-preview.js.mdx',
'common/args-in-preview.ts.mdx',
]}
/>

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

<div class="aside">

💡 For most uses of global args, [globals](../essentials/toolbars-and-globals.md) are a better tool for defining globally-applied settings, such as a theme. Using globals enables users to change the value with the toolbar menu.

</div>

## Args composition

You can separate the arguments to a story to compose in other stories. Here's how you can combine args for multiple stories of the same component.
Expand Down