Skip to content

Commit

Permalink
Add ArgTypes API reference
Browse files Browse the repository at this point in the history
- Remove previous ArgTypes guide
- Add/update relevant snippets
  • Loading branch information
kylegach committed Jun 7, 2023
1 parent adf5051 commit 7c40967
Show file tree
Hide file tree
Showing 76 changed files with 1,754 additions and 447 deletions.
511 changes: 511 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: 'string',
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 7c40967

Please sign in to comment.