docs/_snippets/component-story-custom-args-complex.md
import type { Meta, StoryObj } from '@storybook/angular';
import { YourComponent } from './your-component.component';
const meta: Meta<YourComponent> = {
component: YourComponent,
//๐ Creates specific argTypes with options
argTypes: {
propertyA: {
options: ['Item One', 'Item Two', 'Item Three'],
control: { type: 'select' }, // automatically inferred when 'options' is defined
},
propertyB: {
options: ['Another Item One', 'Another Item Two', 'Another Item Three'],
},
},
};
export default meta;
type Story = StoryObj<YourComponent>;
const someFunction = (valuePropertyA: String, valuePropertyB: String) => {
// Do some logic here
};
export const ExampleStory: Story = {
render: (args) => {
const { propertyA, propertyB } = args;
//๐ Assigns the function result to a variable
const someFunctionResult = someFunction(propertyA, propertyB);
return {
props: {
...args,
someProperty: someFunctionResult,
},
};
},
args: { propertyA: 'Item One', propertyB: 'Another Item One' },
};
import preview from '../.storybook/preview';
import { YourComponent } from './your-component.component';
const someFunction = (valuePropertyA: String, valuePropertyB: String) => {
// Do some logic here
};
const meta = preview.meta({
component: YourComponent,
//๐ Creates specific argTypes with options
argTypes: {
propertyA: {
options: ['Item One', 'Item Two', 'Item Three'],
control: { type: 'select' }, // automatically inferred when 'options' is defined
},
propertyB: {
options: ['Another Item One', 'Another Item Two', 'Another Item Three'],
},
},
});
export const ExampleStory = meta.story({
render: (args) => {
const { propertyA, propertyB } = args;
//๐ Assigns the function result to a variable
const someFunctionResult = someFunction(propertyA, propertyB);
return {
props: {
...args,
someProperty: someFunctionResult,
},
};
},
args: { propertyA: 'Item One', propertyB: 'Another Item One' },
});
import { YourComponent } from './your-component';
export default {
component: YourComponent,
//๐ Creates specific argTypes with options
argTypes: {
propertyA: {
options: ['Item One', 'Item Two', 'Item Three'],
control: { type: 'select' }, // Automatically inferred when 'options' is defined
},
propertyB: {
options: ['Another Item One', 'Another Item Two', 'Another Item Three'],
},
},
};
const someFunction = (valuePropertyA, valuePropertyB) => {
// Do some logic here
};
export const ExampleStory = {
render: (args) => {
const { propertyA, propertyB } = args;
//๐ Assigns the function result to a variable
const someFunctionResult = someFunction(propertyA, propertyB);
return <YourComponent {...args} someProperty={someFunctionResult} />;
},
args: {
propertyA: 'Item One',
propertyB: 'Another Item One',
},
};
// Replace your-framework with the framework you are using, e.g. react-vite, nextjs, nextjs-vite, etc.
import type { Meta, StoryObj } from '@storybook/your-framework';
import { YourComponent } from './your-component';
const meta = {
component: YourComponent,
//๐ Creates specific argTypes with options
argTypes: {
propertyA: {
options: ['Item One', 'Item Two', 'Item Three'],
control: { type: 'select' }, // Automatically inferred when 'options' is defined
},
propertyB: {
options: ['Another Item One', 'Another Item Two', 'Another Item Three'],
},
},
} satisfies Meta<typeof YourComponent>;
export default meta;
type Story = StoryObj<typeof meta>;
const someFunction = (valuePropertyA, valuePropertyB) => {
// Do some logic here
};
export const ExampleStory: Story = {
render: (args) => {
const { propertyA, propertyB } = args;
//๐ Assigns the function result to a variable
const someFunctionResult = someFunction(propertyA, propertyB);
return <YourComponent {...args} someProperty={someFunctionResult} />;
},
args: {
propertyA: 'Item One',
propertyB: 'Another Item One',
},
};
import { createSignal, createEffect } from 'solid-js';
import { YourComponent } from './your-component';
export default {
component: YourComponent,
//๐ Creates specific argTypes with options
argTypes: {
propertyA: {
options: ['Item One', 'Item Two', 'Item Three'],
control: { type: 'select' }, // Automatically inferred when 'options' is defined
},
propertyB: {
options: ['Another Item One', 'Another Item Two', 'Another Item Three'],
},
},
};
const someFunction = (valuePropertyA, valuePropertyB) => {
// Do some logic here
};
export const ExampleStory = {
render: (args) => {
const [someFunctionResult, setSomeFunctionResult] = createSignal();
//๐ Assigns the function result to a signal
createEffect(() => {
setSomeFunctionResult(someFunction(args.propertyA, args.propertyB));
});
return <YourComponent {...args} someProperty={someFunctionResult()} />;
},
args: {
propertyA: 'Item One',
propertyB: 'Another Item One',
},
};
import type { Meta, StoryObj } from 'storybook-solidjs-vite';
import { createSignal, createEffect } from 'solid-js';
import { YourComponent } from './your-component';
const meta = {
component: YourComponent,
//๐ Creates specific argTypes with options
argTypes: {
propertyA: {
options: ['Item One', 'Item Two', 'Item Three'],
control: { type: 'select' }, // Automatically inferred when 'options' is defined
},
propertyB: {
options: ['Another Item One', 'Another Item Two', 'Another Item Three'],
},
},
} satisfies Meta<typeof YourComponent>;
export default meta;
type Story = StoryObj<typeof meta>;
const someFunction = (valuePropertyA, valuePropertyB) => {
// Do some logic here
};
export const ExampleStory: Story = {
render: (args) => {
const [someFunctionResult, setSomeFunctionResult] = createSignal();
//๐ Assigns the function result to a signal
createEffect(() => {
setSomeFunctionResult(someFunction(args.propertyA, args.propertyB));
});
return <YourComponent {...args} someProperty={someFunctionResult()} />;
},
args: {
propertyA: 'Item One',
propertyB: 'Another Item One',
},
};
<script module>
import { defineMeta } from '@storybook/addon-svelte-csf';
import YourComponent from './YourComponent.svelte';
const { Story } = defineMeta({
component: YourComponent,
//๐ Creates specific argTypes
argTypes: {
propertyA: {
options: ['Item One', 'Item Two', 'Item Three'],
control: { type: 'select' }, // Automatically inferred when 'options' is defined
},
propertyB: {
options: ['Another Item One', 'Another Item Two', 'Another Item Three'],
},
},
});
const someFunction = (valuePropertyA, valuePropertyB) => {
// Do some logic here
};
</script>
<Story
name="ExampleStory"
args={{
propertyA: 'Item One',
propertyB: 'Another Item One',
}}
>
{#snippet template(args)}
<YourComponent
{...args}
someProperty={someFunction(args.propertyA, args.propertyB)}
/>
{/snippet}
</Story>
import YourComponent from './YourComponent.svelte';
export default {
component: YourComponent,
//๐ Creates specific argTypes
argTypes: {
propertyA: {
options: ['Item One', 'Item Two', 'Item Three'],
control: { type: 'select' }, // Automatically inferred when 'options' is defined
},
propertyB: {
options: ['Another Item One', 'Another Item Two', 'Another Item Three'],
},
},
};
const someFunction = (valuePropertyA, valuePropertyB) => {
// Do some logic here
};
export const ExampleStory = {
render: (args) => {
//๐ Assigns the function result to a variable
const someFunctionResult = someFunction(args.propertyA, args.propertyB);
return {
Component: YourComponent,
props: {
...args,
someProperty: someFunctionResult,
},
};
},
args: {
propertyA: 'Item One',
propertyB: 'Another Item One',
},
};
<script module>
import { defineMeta } from '@storybook/addon-svelte-csf';
import YourComponent from './YourComponent.svelte';
const { Story } = defineMeta({
component: YourComponent,
//๐ Creates specific argTypes
argTypes: {
propertyA: {
options: ['Item One', 'Item Two', 'Item Three'],
control: { type: 'select' }, // Automatically inferred when 'options' is defined
},
propertyB: {
options: ['Another Item One', 'Another Item Two', 'Another Item Three'],
},
},
});
const someFunction = (valuePropertyA, valuePropertyB) => {
// Do some logic here
};
</script>
<Story
name="ExampleStory"
args={{
propertyA: 'Item One',
propertyB: 'Another Item One',
}}
>
{#snippet template(args)}
<YourComponent
{...args}
someProperty={someFunction(args.propertyA, args.propertyB)}
/>
{/snippet}
</Story>
// Replace your-framework with svelte-vite or sveltekit
import type { Meta, StoryObj } from '@storybook/your-framework';
import YourComponent from './YourComponent.svelte';
const meta = {
component: YourComponent,
//๐ Creates specific argTypes
argTypes: {
propertyA: {
options: ['Item One', 'Item Two', 'Item Three'],
control: { type: 'select' }, // Automatically inferred when 'options' is defined
},
propertyB: {
options: ['Another Item One', 'Another Item Two', 'Another Item Three'],
},
},
} satisfies Meta<typeof YourComponent>;
export default meta;
type Story = StoryObj<typeof meta>;
const someFunction = (valuePropertyA, valuePropertyB) => {
// Do some logic here
};
export const ExampleStory: Story = {
render: (args) => {
//๐ Assigns the function result to a variable
const someFunctionResult = someFunction(args.propertyA, args.propertyB);
return {
Component: YourComponent,
props: {
...args,
someProperty: someFunctionResult,
},
};
},
args: {
propertyA: 'Item One',
propertyB: 'Another Item One',
},
};
import YourComponent from './YourComponent.vue';
export default {
component: YourComponent,
//๐ Creates specific argTypes with options
argTypes: {
propertyA: {
options: ['Item One', 'Item Two', 'Item Three'],
control: { type: 'select' }, // automatically inferred when 'options' is defined
},
propertyB: {
options: ['Another Item One', 'Another Item Two', 'Another Item Three'],
},
},
};
const someFunction = (valuePropertyA, valuePropertyB) => {
// Do some logic here
};
export const ExampleStory = {
render: ({ args }) => {
const { propertyA, propertyB } = args;
//๐ Assigns the function result to a variable
const functionResult = someFunction(propertyA, propertyB);
return {
components: { YourComponent },
setup() {
return {
...args,
//๐ Replaces arg variable with the override (without the need of mutation)
someProperty: functionResult,
};
},
template:
'<YourComponent :propertyA="propertyA" :propertyB="propertyB" :someProperty="someProperty"/>',
};
},
args: {
propertyA: 'Item One',
propertyB: 'Another Item One',
},
};
import type { Meta, StoryObj } from '@storybook/vue3-vite';
import YourComponent from './YourComponent.vue';
const meta = {
component: YourComponent,
//๐ Creates specific argTypes with options
argTypes: {
propertyA: {
options: ['Item One', 'Item Two', 'Item Three'],
control: { type: 'select' }, // automatically inferred when 'options' is defined
},
propertyB: {
options: ['Another Item One', 'Another Item Two', 'Another Item Three'],
},
},
} satisfies Meta<typeof YourComponent>;
const someFunction = (valuePropertyA, valuePropertyB) => {
// Do some logic here
};
export default meta;
type Story = StoryObj<typeof meta>;
export const ExampleStory: Story = {
render: ({ args }) => {
const { propertyA, propertyB } = args;
//๐ Assigns the function result to a variable
const functionResult = someFunction(propertyA, propertyB);
return {
components: { YourComponent },
setup() {
return {
...args,
//๐ Replaces arg variable with the override (without the need of mutation)
someProperty: functionResult,
};
},
template:
'<YourComponent :propertyA="propertyA" :propertyB="propertyB" :someProperty="someProperty"/>',
};
},
args: {
propertyA: 'Item One',
propertyB: 'Another Item One',
},
};
import { html } from 'lit';
export default {
component: 'custom-component',
//๐ Creates specific argTypes
argTypes: {
propertyA: {
options: ['Item One', 'Item Two', 'Item Three'],
control: { type: 'select' }, // Automatically inferred when 'options' is defined
},
propertyB: {
options: ['Another Item One', 'Another Item Two', 'Another Item Three'],
},
},
};
const someFunction = (valuePropertyA, valuePropertyB) => {
// Do some logic here
};
export const ExampleStory = {
render: ({ propertyA, propertyB }) => {
//๐ Assigns the function result to a variable
const someFunctionResult = someFunction(propertyA, propertyB);
return html`
<custom-component
.propertyA=${propertyA}
.propertyB=${propertyB}
.someProperty=${someFunctionResult}
></custom-component>
`;
},
args: {
propertyA: 'Item One',
propertyB: 'Another Item One',
},
};
import type { Meta, StoryObj } from '@storybook/web-components-vite';
import { html } from 'lit';
const meta: Meta = {
component: 'custom-component',
//๐ Creates specific argTypes with options
argTypes: {
propertyA: {
options: ['Item One', 'Item Two', 'Item Three'],
control: { type: 'select' }, // Automatically inferred when 'options' is defined
},
propertyB: {
options: ['Another Item One', 'Another Item Two', 'Another Item Three'],
},
},
};
export default meta;
type Story = StoryObj;
const someFunction = (valuePropertyA: any, valuePropertyB: any) => {
// Do some logic here
};
export const ExampleStory: Story = {
render: ({ propertyA, propertyB }) => {
//๐ Assigns the function result to a variable
const someFunctionResult = someFunction(propertyA, propertyB);
return html`
<custom-component
.propertyA=${propertyA}
.propertyB=${propertyB}
.someProperty=${someFunctionResult}
></custom-component>
`;
},
args: {
propertyA: 'Item One',
propertyB: 'Another Item One',
},
};
import { html } from 'lit';
import preview from '../.storybook/preview';
const meta = preview.meta({
component: 'custom-component',
//๐ Creates specific argTypes
argTypes: {
propertyA: {
options: ['Item One', 'Item Two', 'Item Three'],
control: { type: 'select' }, // Automatically inferred when 'options' is defined
},
propertyB: {
options: ['Another Item One', 'Another Item Two', 'Another Item Three'],
},
},
});
const someFunction = (valuePropertyA, valuePropertyB) => {
// Do some logic here
};
export const ExampleStory = meta.story({
render: ({ propertyA, propertyB }) => {
//๐ Assigns the function result to a variable
const someFunctionResult = someFunction(propertyA, propertyB);
return html`
<custom-component
.propertyA=${propertyA}
.propertyB=${propertyB}
.someProperty=${someFunctionResult}
></custom-component>
`;
},
args: {
propertyA: 'Item One',
propertyB: 'Another Item One',
},
});
import { html } from 'lit';
import preview from '../.storybook/preview';
const meta = preview.meta({
component: 'custom-component',
//๐ Creates specific argTypes with options
argTypes: {
propertyA: {
options: ['Item One', 'Item Two', 'Item Three'],
control: { type: 'select' }, // Automatically inferred when 'options' is defined
},
propertyB: {
options: ['Another Item One', 'Another Item Two', 'Another Item Three'],
},
},
});
const someFunction = (valuePropertyA: any, valuePropertyB: any) => {
// Do some logic here
};
export const ExampleStory = meta.story({
render: ({ propertyA, propertyB }) => {
//๐ Assigns the function result to a variable
const someFunctionResult = someFunction(propertyA, propertyB);
return html`
<custom-component
.propertyA=${propertyA}
.propertyB=${propertyB}
.someProperty=${someFunctionResult}
></custom-component>
`;
},
args: {
propertyA: 'Item One',
propertyB: 'Another Item One',
},
});
import preview from '../.storybook/preview';
import YourComponent from './YourComponent.vue';
const meta = preview.meta({
component: YourComponent,
//๐ Creates specific argTypes with options
argTypes: {
propertyA: {
options: ['Item One', 'Item Two', 'Item Three'],
control: { type: 'select' }, // automatically inferred when 'options' is defined
},
propertyB: {
options: ['Another Item One', 'Another Item Two', 'Another Item Three'],
},
},
});
const someFunction = (valuePropertyA, valuePropertyB) => {
// Do some logic here
};
export const ExampleStory = meta.story({
render: ({ args }) => {
const { propertyA, propertyB } = args;
//๐ Assigns the function result to a variable
const functionResult = someFunction(propertyA, propertyB);
return {
components: { YourComponent },
setup() {
return {
...args,
//๐ Replaces arg variable with the override (without the need of mutation)
someProperty: functionResult,
};
},
template:
'<YourComponent :propertyA="propertyA" :propertyB="propertyB" :someProperty="someProperty"/>',
};
},
args: {
propertyA: 'Item One',
propertyB: 'Another Item One',
},
});
import preview from '../.storybook/preview';
import YourComponent from './YourComponent.vue';
const meta = preview.meta({
component: YourComponent,
//๐ Creates specific argTypes with options
argTypes: {
propertyA: {
options: ['Item One', 'Item Two', 'Item Three'],
control: { type: 'select' }, // automatically inferred when 'options' is defined
},
propertyB: {
options: ['Another Item One', 'Another Item Two', 'Another Item Three'],
},
},
});
const someFunction = (valuePropertyA, valuePropertyB) => {
// Do some logic here
};
export const ExampleStory = meta.story({
render: ({ args }) => {
const { propertyA, propertyB } = args;
//๐ Assigns the function result to a variable
const functionResult = someFunction(propertyA, propertyB);
return {
components: { YourComponent },
setup() {
return {
...args,
//๐ Replaces arg variable with the override (without the need of mutation)
someProperty: functionResult,
};
},
template:
'<YourComponent :propertyA="propertyA" :propertyB="propertyB" :someProperty="someProperty"/>',
};
},
args: {
propertyA: 'Item One',
propertyB: 'Another Item One',
},
});
import preview from '../.storybook/preview';
import { YourComponent } from './your-component';
const meta = preview.meta({
component: YourComponent,
//๐ Creates specific argTypes with options
argTypes: {
propertyA: {
options: ['Item One', 'Item Two', 'Item Three'],
control: { type: 'select' }, // Automatically inferred when 'options' is defined
},
propertyB: {
options: ['Another Item One', 'Another Item Two', 'Another Item Three'],
},
},
});
const someFunction = (valuePropertyA, valuePropertyB) => {
// Do some logic here
};
export const ExampleStory = meta.story({
render: (args) => {
const { propertyA, propertyB } = args;
//๐ Assigns the function result to a variable
const someFunctionResult = someFunction(propertyA, propertyB);
return <YourComponent {...args} someProperty={someFunctionResult} />;
},
args: {
propertyA: 'Item One',
propertyB: 'Another Item One',
},
});
import preview from '../.storybook/preview';
import { YourComponent } from './your-component';
const meta = preview.meta({
component: YourComponent,
//๐ Creates specific argTypes with options
argTypes: {
propertyA: {
options: ['Item One', 'Item Two', 'Item Three'],
control: { type: 'select' }, // Automatically inferred when 'options' is defined
},
propertyB: {
options: ['Another Item One', 'Another Item Two', 'Another Item Three'],
},
},
});
const someFunction = (valuePropertyA, valuePropertyB) => {
// Do some logic here
};
export const ExampleStory = meta.story({
render: (args) => {
const { propertyA, propertyB } = args;
//๐ Assigns the function result to a variable
const someFunctionResult = someFunction(propertyA, propertyB);
return <YourComponent {...args} someProperty={someFunctionResult} />;
},
args: {
propertyA: 'Item One',
propertyB: 'Another Item One',
},
});