Back to Storybook

Page Story Slots

docs/_snippets/page-story-slots.md

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

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

type PagePropsAndCustomArgs = Page & { footer?: string };

const meta: Meta<PagePropsAndCustomArgs> = {
  component: Page,
  render: ({ footer, ...args }) => ({
    props: args,
    template: `
      <storybook-page ${argsToTemplate(args)}>
        <ng-container footer>${footer}</ng-container>
      </storybook-page>`,
  }),
};
export default meta;

type Story = StoryObj<PagePropsAndCustomArgs>;

export const CustomFooter: Story = {
  args: {
    footer: 'Built with Storybook',
  },
};
ts
import { argsToTemplate } from '@storybook/angular';

import preview from '../.storybook/preview';

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

type PagePropsAndCustomArgs = Page & { footer?: string };

const meta = preview.type<{ args: PagePropsAndCustomArgs }>().meta({
  component: Page,
  render: ({ footer, ...args }) => ({
    props: args,
    template: `
      <storybook-page ${argsToTemplate(args)}>
        <ng-container footer>${footer}</ng-container>
      </storybook-page>`,
  }),
});

export const CustomFooter = meta.story({
  args: {
    footer: 'Built with Storybook',
  },
});
jsx
import { Page } from './Page';

export default {
  component: Page,
  render: ({ footer, ...args }) => (
    <Page {...args}>
      <footer>{footer}</footer>
    </Page>
  ),
};

export const CustomFooter = {
  args: {
    footer: 'Built with Storybook',
  },
};
tsx
// 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 { Page } from './Page';

type PagePropsAndCustomArgs = React.ComponentProps<typeof Page> & { footer?: string };

const meta = {
  component: Page,
  render: ({ footer, ...args }) => (
    <Page {...args}>
      <footer>{footer}</footer>
    </Page>
  ),
} satisfies Meta<PagePropsAndCustomArgs>;
export default meta;

type Story = StoryObj<typeof meta>;

export const CustomFooter = {
  args: {
    footer: 'Built with Storybook',
  },
} satisfies Story;
jsx
import { Page } from './Page';

export default {
  component: Page,
  render: ({ footer, ...args }) => (
    <Page {...args}>
      <footer>{footer}</footer>
    </Page>
  ),
};

export const CustomFooter = {
  args: {
    footer: 'Built with Storybook',
  },
};
tsx
import type { ComponentProps } from 'solid-js';

import type { Meta, StoryObj } from 'storybook-solidjs-vite';

import { Page } from './Page';

type PagePropsAndCustomArgs = ComponentProps<typeof Page> & { footer?: string };

const meta = {
  component: Page,
  render: ({ footer, ...args }) => (
    <Page {...args}>
      <footer>{footer}</footer>
    </Page>
  ),
} satisfies Meta<PagePropsAndCustomArgs>;
export default meta;

type Story = StoryObj<typeof meta>;

export const CustomFooter = {
  args: {
    footer: 'Built with Storybook',
  },
} satisfies Story;
svelte
<script module>
  import { defineMeta } from '@storybook/addon-svelte-csf';

  import Page from './Page.svelte';

  const { Story } = defineMeta({
    component: Page
  });
</script>

<Story name="CustomFooter" args={{ footer: 'Built with Storybook' }}>
  {#snippet template(args)}
    <Page {...args} >
      <footer>{args.footer}</footer>
    </Page>
  {/snippet}
</Story>
svelte
<script module>
  import { defineMeta } from '@storybook/addon-svelte-csf';

  import Page from './Page.svelte';

  const { Story } = defineMeta({
    component: Page
  });
</script>

<Story name="CustomFooter" args={{ footer: 'Built with Storybook' }}>
  {#snippet template(args)}
    <Page {...args} >
      <footer>{args.footer}</footer>
    </Page>
  {/snippet}
</Story>
js
import Page from './Page.vue';

export default {
  component: Page,
  render: (args) => ({
    components: { Page },
    setup() {
      return { args };
    },
    template: `
      <page v-bind="args">
        <template v-slot:footer>
          <footer v-if="args.footer" v-html="args.footer" />
        </template>
      </page>
    `,
  }),
};

export const CustomFooter = {
  args: {
    footer: 'Built with Storybook',
  },
};
ts
import type { ComponentPropsAndSlots, Meta, StoryObj } from '@storybook/vue3-vite';

import Page from './Page.vue';

type PagePropsAndCustomArgs = ComponentPropsAndSlots<typeof Page> & { footer?: string };

const meta = {
  component: Page,
  render: (args) => ({
    components: { Page },
    setup() {
      return { args };
    },
    template: `
      <page v-bind="args">
        <template v-slot:footer>
          <footer v-if="args.footer" v-html="args.footer" />
        </template>
      </page>
    `,
  }),
} satisfies Meta<PagePropsAndCustomArgs>;
export default meta;

type Story = StoryObj<typeof meta>;

export const Primary = {
  args: {
    footer: 'Built with Storybook',
  },
} satisfies Story;
ts
import type { ComponentPropsAndSlots } from '@storybook/vue3-vite';

import preview from '../.storybook/preview';

import Page from './Page.vue';

type PagePropsAndCustomArgs = ComponentPropsAndSlots<typeof Page> & { footer?: string };

const meta = preview.type<{ args: PagePropsAndCustomArgs }>().meta({
  component: Page,
  render: (args) => ({
    components: { Page },
    setup() {
      return { args };
    },
    template: `
      <page v-bind="args">
        <template v-slot:footer>
          <footer v-if="args.footer" v-html="args.footer" />
        </template>
      </page>
    `,
  }),
});

export const Primary = meta.story({
  args: {
    footer: 'Built with Storybook',
  },
});
js
import preview from '../.storybook/preview';

import Page from './Page.vue';

const meta = preview.meta({
  component: Page,
  render: (args) => ({
    components: { Page },
    setup() {
      return { args };
    },
    template: `
      <page v-bind="args">
        <template v-slot:footer>
          <footer v-if="args.footer" v-html="args.footer" />
        </template>
      </page>
    `,
  }),
});

export const CustomFooter = meta.story({
  args: {
    footer: 'Built with Storybook',
  },
});
js
import { html } from 'lit';

export default {
  title: 'Page',
  component: 'demo-page',
  render: ({ footer }) => html`
    <demo-page>
      <footer>${footer}</footer>
    </demo-page>
  `,
};

export const CustomFooter = {
  args: {
    footer: 'Built with Storybook',
  },
};
ts
import { html } from 'lit';

import type { Meta, StoryObj } from '@storybook/web-components-vite';

const meta: Meta = {
  title: 'Page',
  component: 'demo-page',
  render: ({ footer }) => html`
    <demo-page>
      <footer>${footer}</footer>
    </demo-page>
  `,
};

export default meta;
type Story = StoryObj;

export const CustomFooter: Story = {
  args: {
    footer: 'Built with Storybook',
  },
};
js
import { html } from 'lit';

import preview from '../.storybook/preview';

const meta = preview.meta({
  title: 'Page',
  component: 'demo-page',
  render: ({ footer }) => html`
    <demo-page>
      <footer>${footer}</footer>
    </demo-page>
  `,
});

export const CustomFooter = meta.story({
  args: {
    footer: 'Built with Storybook',
  },
});
ts
import { html } from 'lit';

import preview from '../.storybook/preview';

type CustomArgs = { footer?: string };

const meta = preview.type<{ args: CustomArgs }>()meta({
  title: 'Page',
  component: 'demo-page',
  render: ({ footer }) => html`
    <demo-page>
      <footer>${footer}</footer>
    </demo-page>
  `,
});

export const CustomFooter = meta.story({
  args: {
    footer: 'Built with Storybook',
  },
});
tsx
import preview from '../.storybook/preview';

import { Page } from './Page';

type PagePropsAndCustomArgs = React.ComponentProps<typeof Page> & {
  footer?: string;
};

const meta = preview.type<{ args: PagePropsAndCustomArgs }>().meta({
  component: Page,
  render: ({ footer, ...args }) => (
    <Page {...args}>
      <footer>{footer}</footer>
    </Page>
  ),
});

export const CustomFooter = meta.story({
  args: {
    footer: 'Built with Storybook',
  },
});
jsx
import preview from '../.storybook/preview';

import { Page } from './Page';

const meta = preview.meta({
  component: Page,
  render: ({ footer, ...args }) => (
    <Page {...args}>
      <footer>{footer}</footer>
    </Page>
  ),
});

export const CustomFooter = meta.story({
  args: {
    footer: 'Built with Storybook',
  },
});