Back to Storybook

Your Component

docs/_snippets/your-component.md

10.3.612.8 KB
Original Source
ts
import type { Meta, StoryObj } from '@storybook/angular';

import { YourComponent } from './your.component';

//๐Ÿ‘‡ This default export determines where your story goes in the story list
const meta: Meta<YourComponent> = {
  component: YourComponent,
};

export default meta;
type Story = StoryObj<YourComponent>;

export const Basic: Story = {
  args: {
    //๐Ÿ‘‡ The args you need here will depend on your component
  },
};
ts
import preview from '../.storybook/preview';

import { YourComponent } from './your.component';

//๐Ÿ‘‡ This default export determines where your story goes in the story list
const meta = preview.meta({
  component: YourComponent,
});

export const Basic = meta.story({
  args: {
    //๐Ÿ‘‡ The args you need here will depend on your component
  },
});
js
import { createYourComponent } from './YourComponent';

// ๐Ÿ‘‡ This default export determines where your story goes in the story list
export default {
  /* ๐Ÿ‘‡ The title prop is optional.
   * See https://storybook.js.org/docs/configure/#configure-story-loading
   * to learn how to generate automatic titles
   */
  title: 'YourComponent',
};

/*
 *๐Ÿ‘‡ Render functions are a framework specific feature to allow you control on how the component renders.
 * See https://storybook.js.org/docs/api/csf
 * to learn how to use render functions.
 */
export const Basic = {
  render: (args) => createYourComponent(args),
  args: {
    // ๐Ÿ‘‡ The args you need here will depend on your component
  },
};
ts
import type { Meta, StoryObj } from '@storybook/html';

import { createYourComponent, ComponentProps } from './YourComponent';

//๐Ÿ‘‡ This default export determines where your story goes in the story list
const meta: Meta<ComponentProps> = {
  /* ๐Ÿ‘‡ The title prop is optional.
   * See https://storybook.js.org/docs/configure/#configure-story-loading
   * to learn how to generate automatic titles
   */
  title: 'YourComponent',
};

export default meta;
type Story = StoryObj<ComponentProps>;

/*
 *๐Ÿ‘‡ Render functions are a framework specific feature to allow you control on how the component renders.
 * See https://storybook.js.org/docs/api/csf
 * to learn how to use render functions.
 */
export const Basic: Story = {
  render: (args) => createYourComponent(args),
  args: {
    // ๐Ÿ‘‡ The args you need here will depend on your component
  },
};
js
/** @jsx h */
import { h } from 'preact';

import { YourComponent } from './YourComponent';

//๐Ÿ‘‡ This default export determines where your story goes in the story list
export default {
  component: YourComponent,
};

/*
 *๐Ÿ‘‡ Render functions are a framework specific feature to allow you control on how the component renders.
 * See https://storybook.js.org/docs/api/csf
 * to learn how to use render functions.
 */
export const Basic = {
  render: (args) => <YourComponent {...args} />,
  args: {
    //๐Ÿ‘‡ The args you need here will depend on your component
  },
};
js
import { YourComponent } from './YourComponent';

//๐Ÿ‘‡ This default export determines where your story goes in the story list
export default {
  component: YourComponent,
};

export const Basic = {
  args: {
    //๐Ÿ‘‡ The args you need here will depend on your component
  },
};
ts
// 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 './YourComponent';

//๐Ÿ‘‡ This default export determines where your story goes in the story list
const meta = {
  component: YourComponent,
} satisfies Meta<typeof YourComponent>;

export default meta;
type Story = StoryObj<typeof meta>;

export const Basic: Story = {
  args: {
    //๐Ÿ‘‡ The args you need here will depend on your component
  },
};
js
import { YourComponent } from './YourComponent';

//๐Ÿ‘‡ This default export determines where your story goes in the story list
export default {
  component: YourComponent,
};

export const Basic = {
  args: {
    //๐Ÿ‘‡ The args you need here will depend on your component
  },
};
tsx
import type { Meta, StoryObj } from 'storybook-solidjs-vite';

import { YourComponent } from './YourComponent';

//๐Ÿ‘‡ This default export determines where your story goes in the story list
const meta = {
  component: YourComponent,
} satisfies Meta<typeof YourComponent>;

export default meta;
type Story = StoryObj<typeof meta>;

export const Basic: Story = {
  args: {
    //๐Ÿ‘‡ The args you need here will depend on your component
  },
};
svelte
<script module>
  import { defineMeta } from '@storybook/addon-svelte-csf';

  import YourComponent from './YourComponent.svelte';

  //๐Ÿ‘‡ This export determines where your story goes in the story list
  const { Story } = defineMeta({
    component: YourComponent,
  });
</script>

<Story
  name="Basic"
  args={{
    /*๐Ÿ‘‡ The args you need here will depend on your component */
  }}
/>
js
import YourComponent from './YourComponent.svelte';

//๐Ÿ‘‡ This default export determines where your story goes in the story list
export default {
  component: YourComponent,
};

export const Basic = {
  args: {
    //๐Ÿ‘‡ The args you need here will depend on your component
  },
};
svelte
<script module>
  import { defineMeta } from '@storybook/addon-svelte-csf';

  import YourComponent from './YourComponent.svelte';

  //๐Ÿ‘‡ This export determines where your story goes in the story list
  const { Story } = defineMeta({
    component: YourComponent,
  });
</script>

<Story
  name="Basic"
  args={{
    /*๐Ÿ‘‡ The args you need here will depend on your component */
  }}
/>
ts
// Replace your-framework with svelte-vite or sveltekit
import type { Meta, StoryObj } from '@storybook/your-framework';

import YourComponent from './YourComponent.svelte';

//๐Ÿ‘‡ This default export determines where your story goes in the story list
const meta = {
  component: YourComponent,
} satisfies Meta<typeof YourComponent>;

export default meta;
type Story = StoryObj<typeof meta>;

export const Basic: Story = {
  args: {
    //๐Ÿ‘‡ The args you need here will depend on your component
  },
};
js
import YourComponent from './YourComponent.vue';

//๐Ÿ‘‡ This default export determines where your story goes in the story list
export default {
  component: YourComponent,
};

/*
 *๐Ÿ‘‡ Render functions are a framework specific feature to allow you control on how the component renders.
 * See https://storybook.js.org/docs/api/csf
 * to learn how to use render functions.
 */
export const Basic = {
  render: (args) => ({
    components: { YourComponent },
    setup() {
      return { args };
    },
    template: '<YourComponent v-bind="args" />',
  }),
  args: {
    //๐Ÿ‘‡ The args you need here will depend on your component
  },
};
ts
import type { Meta, StoryObj } from '@storybook/vue3-vite';

import YourComponent from './YourComponent.vue';

const meta = {
  component: YourComponent,
} satisfies Meta<typeof YourComponent>;

//๐Ÿ‘‡ This default export determines where your story goes in the story list
export default meta;
type Story = StoryObj<typeof meta>;

/*
 *๐Ÿ‘‡ Render functions are a framework specific feature to allow you control on how the component renders.
 * See https://storybook.js.org/docs/api/csf
 * to learn how to use render functions.
 */
export const Basic: Story = {
  render: (args) => ({
    components: { YourComponent },
    setup() {
      return { args };
    },
    template: '<YourComponent v-bind="args" />',
  }),
  args: {
    //๐Ÿ‘‡ The args you need here will depend on your component
  },
};
ts
import preview from '../.storybook/preview';

import YourComponent from './YourComponent.vue';

//๐Ÿ‘‡ This default export determines where your story goes in the story list
const meta = preview.meta({
  component: YourComponent,
});

/*
 *๐Ÿ‘‡ Render functions are a framework specific feature to allow you control on how the component renders.
 * See https://storybook.js.org/docs/api/csf
 * to learn how to use render functions.
 */
export const Basic = meta.story({
  render: (args) => ({
    components: { YourComponent },
    setup() {
      return { args };
    },
    template: '<YourComponent v-bind="args" />',
  }),
  args: {
    //๐Ÿ‘‡ The args you need here will depend on your component
  },
});
<!-- JS snippets still needed while providing both CSF 3 & Next -->
js
import preview from '../.storybook/preview';

import YourComponent from './YourComponent.vue';

//๐Ÿ‘‡ This default export determines where your story goes in the story list
const meta = preview.meta({
  component: YourComponent,
});

/*
 *๐Ÿ‘‡ Render functions are a framework specific feature to allow you control on how the component renders.
 * See https://storybook.js.org/docs/api/csf
 * to learn how to use render functions.
 */
export const Basic = meta.story({
  render: (args) => ({
    components: { YourComponent },
    setup() {
      return { args };
    },
    template: '<YourComponent v-bind="args" />',
  }),
  args: {
    //๐Ÿ‘‡ The args you need here will depend on your component
  },
});
js
// This default export determines where your story goes in the story list
export default {
  component: 'demo-your-component',
};

export const Basic = {
  args: {
    // ๐Ÿ‘‡ The args you need here will depend on your component
  },
};
ts
import type { Meta, StoryObj } from '@storybook/web-components-vite';

// This default export determines where your story goes in the story list
const meta: Meta = {
  component: 'demo-your-component',
};

export default meta;
type Story = StoryObj;

export const Basic: Story = {
  args: {
    // ๐Ÿ‘‡ The args you need here will depend on your component
  },
};
js
import preview from '../.storybook/preview';

// ๐Ÿ‘‡ This default export determines where your story goes in the story list
const meta = preview.meta({
  component: 'demo-your-component',
});

export const Basic = meta.story({
  args: {
    // ๐Ÿ‘‡ The args you need here will depend on your component
  },
});
ts
import preview from '../.storybook/preview';

// ๐Ÿ‘‡ This default export determines where your story goes in the story list
const meta = preview.meta({
  component: 'demo-your-component',
});

export const Basic = meta.story({
  args: {
    // ๐Ÿ‘‡ The args you need here will depend on your component
  },
});
ts
import preview from '../.storybook/preview';

import { YourComponent } from './YourComponent';

//๐Ÿ‘‡ This default export determines where your story goes in the story list
const meta = preview.meta({
  component: YourComponent,
});

export const Basic = meta.story({
  args: {
    //๐Ÿ‘‡ The args you need here will depend on your component
  },
});
<!-- JS snippets still needed while providing both CSF 3 & Next -->
js
import preview from '../.storybook/preview';

import { YourComponent } from './YourComponent';

const meta = preview.meta({
  component: YourComponent,
});

export const Basic = meta.story({
  args: {
    //๐Ÿ‘‡ The args you need here will depend on your component
  },
});