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: Add ArgTypes API reference #22970

Merged
merged 6 commits into from
Jun 13, 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
500 changes: 500 additions & 0 deletions docs/api/arg-types.md

Large diffs are not rendered by default.

216 changes: 0 additions & 216 deletions docs/api/argtypes.md

This file was deleted.

23 changes: 23 additions & 0 deletions docs/snippets/angular/arg-types-control.ts.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
```ts
// Example.stories.ts

import type { Meta } from '@storybook/angular';

import { Example } from './Example';

const meta: Meta<Example> = {
component: Example,
argTypes: {
value: {
control: {
type: 'number',
min: 0,
max: 100,
step: 10,
},
},
},
};

export default meta;
```
23 changes: 23 additions & 0 deletions docs/snippets/angular/arg-types-default-value.ts.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
```ts
// Example.stories.ts

import type { Meta } from '@storybook/angular';

import { Example } from './Example';

const meta: Meta<Example> = {
component: Example,
argTypes: {
value: {
// ❌ Deprecated
defaultValue: 0,
},
},
// ✅ Do this instead
args: {
value: 0,
},
};

export default meta;
```
18 changes: 18 additions & 0 deletions docs/snippets/angular/arg-types-description.ts.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
```ts
// Example.stories.ts

import type { Meta } from '@storybook/angular';

import { Example } from './Example';

const meta: Meta<Example> = {
component: Example,
argTypes: {
value: {
description: 'The value of the slider',
},
},
};

export default meta;
```
40 changes: 40 additions & 0 deletions docs/snippets/angular/arg-types-if.ts.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
```ts
// Example.stories.ts

import type { Meta } from '@storybook/angular';

import { Example } from './Example';

const meta: Meta<Example> = {
component: Example,
argTypes: {
parent: { control: 'select', options: ['one', 'two', 'three'] },

// 👇 Only shown when `parent` arg exists
parentExists: { if: { arg: 'parent', exists: true } },

// 👇 Only shown when `parent` arg does not exist
parentDoesNotExist: { if: { arg: 'parent', exists: false } },

// 👇 Only shown when `parent` arg value is truthy
parentIsTruthy: { if: { arg: 'parent' } },
parentIsTruthyVerbose: { if: { arg: 'parent', truthy: true } },

// 👇 Only shown when `parent` arg value is not truthy
parentIsNotTruthy: { if: { arg: 'parent', truthy: false } },

// 👇 Only shown when `parent` arg value is 'three'
parentIsEqToValue: { if: { arg: 'parent', eq: 'three' } },

// 👇 Only shown when `parent` arg value is not 'three'
parentIsNotEqToValue: { if: { arg: 'parent', neq: 'three' } },

// Each of the above can also be conditional on the value of a globalType, e.g.:

// 👇 Only shown when `theme` global exists
parentExists: { if: { global: 'theme', exists: true } },
},
};

export default meta;
```
20 changes: 20 additions & 0 deletions docs/snippets/angular/arg-types-in-meta.ts.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
```ts
// Button.stories.ts

import type { Meta } from '@storybook/angular';

import { Button } from './button.component';

const meta: Meta<Button> = {
component: Button,
argTypes: {
// 👇 All Button stories expect a label arg
label: {
control: 'string',
description: 'Overwritten description',
},
},
};

export default meta;
```
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,19 @@ import { Button } from './button.component';

const meta: Meta<Button> = {
component: Button,
};

export default meta;

type Story = StoryObj<typeof Button>;

export const Basic: Story = {
argTypes: {
// 👇 This story expects a label arg
label: {
description: 'overwritten description',
table: {
type: {
summary: 'something short',
detail: 'something really really long',
},
},
control: {
type: null,
},
control: 'text',
description: 'Overwritten description',
},
},
};

export default meta;
```
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
```ts
// MyComponent.stories.ts
// Example.stories.ts

import type { Meta } from '@storybook/angular';

import { MyComponent } from './MyComponent';
import { Example } from './Example';

const meta: Meta<MyComponent> = {
component: MyComponent,
const meta: Meta<Example> = {
component: Example,
argTypes: {
label: {
options: ['Normal', 'Bold', 'Italic'],
Expand Down
Loading