Skip to content

Commit

Permalink
Merge pull request #22970 from storybookjs/api-reference-arg-types
Browse files Browse the repository at this point in the history
Docs: Add ArgTypes API reference
  • Loading branch information
kylegach authored Jun 13, 2023
2 parents 55b1627 + 0bbf15a commit e39cc9f
Show file tree
Hide file tree
Showing 82 changed files with 1,834 additions and 459 deletions.
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

0 comments on commit e39cc9f

Please sign in to comment.