Skip to content

Commit

Permalink
Update docs to mention argsToTemplate
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinpalkovic committed Oct 11, 2023
1 parent a42f7b9 commit 79c2381
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
9 changes: 8 additions & 1 deletion docs/snippets/angular/button-story-click-handler-args.ts.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Button.stories.ts

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

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

Expand All @@ -17,7 +18,13 @@ type Story = StoryObj<Button>;
export const Text: Story = {
render: (args) => ({
props: args,
template: `<storybook-button [label]="label" (onClick)="onClick()"></storybook-button>`,
// The argsToTemplate helper function converts the args to property and event bindings.
// You could also write the template in plain HTML and bind to the component's inputs and outputs yourself:
// <storybook-button ["label"]="label" (onClick)="onClick($event)">
// We don't recommend the latter since it can conflict with how Storybook applies arguments via its controls addon.
// Binding to the component's inputs and outputs yourself will conflict with default values set inside the component's class.
// In edge-case scenarios, you may need to define the template yourself, though.
template: `<storybook-button ${argsToTemplate(args)}></storybook-button>`,
}),
args: {
label: 'Hello',
Expand Down
1 change: 1 addition & 0 deletions docs/snippets/angular/button-story-click-handler.ts.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const Text: Story = {
label: 'Button',
onClick: action('clicked'),
},
template: `<storybook-button [label]="label" (onClick)="onClick($event)"></storybook-button>`,
}),
};
```
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

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

import { moduleMetadata } from '@storybook/angular';
import { moduleMetadata, argsToTemplate } from '@storybook/angular';

import { CommonModule } from '@angular/common';

Expand All @@ -26,14 +26,15 @@ type Story = StoryObj<MyComponent>;

// This story uses a render function to fully control how the component renders.
export const Example: Story = {
render: () => ({
render: (args) => ({
props: args,
template: `
<app-layout>
<header>
<h1>Example</h1>
</header>
<article>
<app-my-component></app-my-component>
<app-my-component ${argsToTemplate(args)}></app-my-component>
</article>
</app-layout>
`,
Expand Down
3 changes: 2 additions & 1 deletion docs/snippets/angular/page-story-slots.ts.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Page.stories.ts

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

import { Page } from './page.component';

Expand All @@ -12,7 +13,7 @@ const meta: Meta<PagePropsAndCustomArgs> = {
render: ({ footer, ...args }) => ({
props: args,
template: `
<storybook-page>
<storybook-page ${argsToTemplate(args)}>
<ng-container footer>${footer}</ng-container>
</storybook-page>`,
}),
Expand Down

0 comments on commit 79c2381

Please sign in to comment.