Back to Storybook

Component Story Static Asset With Import

docs/_snippets/component-story-static-asset-with-import.md

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

import { MyComponent } from './my-component.component';

import imageFile from './static/image.png';

const meta: Meta<MyComponent> = {
  component: MyComponent,
};

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

const image = {
  src: imageFile,
  alt: 'my image',
};

export const WithAnImage: Story = {
  render: () => ({
    props: {
      src: image.src,
      alt: image.alt,
    },
    template: ``,
  }),
};
ts
import preview from '../.storybook/preview';

import { MyComponent } from './my-component.component';

import imageFile from './static/image.png';

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

const image = {
  src: imageFile,
  alt: 'my image',
};

export const WithAnImage = meta.story({
  render: () => ({
    props: {
      src: image.src,
      alt: image.alt,
    },
    template: ``,
  }),
});
js
import { MyComponent } from './MyComponent';

import imageFile from './static/image.png';

export default {
  component: MyComponent,
};

const image = {
  src: imageFile,
  alt: 'my image',
};

export const WithAnImage = {
  render: () => ,
};
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 imageFile from './static/image.png';

import { MyComponent } from './MyComponent';

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

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

const image = {
  src: imageFile,
  alt: 'my image',
};

export const WithAnImage: Story = {
  render: () => ,
};
js
import imageFile from './static/image.png';

import { MyComponent } from './MyComponent';

export default {
  component: MyComponent,
};

const image = {
  src: imageFile,
  alt: 'my image',
};

export const WithAnImage = {
  render: () => ,
};
tsx
import type { Meta, StoryObj } from 'storybook-solidjs-vite';

import imageFile from './static/image.png';

import { MyComponent } from './MyComponent';

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

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

const image = {
  src: imageFile,
  alt: 'my image',
};

export const WithAnImage: Story = {
  render: () => ,
};
svelte
<script module>
  import { defineMeta } from '@storybook/addon-svelte-csf';

  import MyComponent from './MyComponent.svelte';

  import imageFile from './static/image.png';

  let image = {
    src: imageFile,
    alt: 'my image',
  };

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

<Story name="WithAnImage">
  <MyComponent {image} />
</Story>
js
import MyComponent from './MyComponent.svelte';

import imageFile from './static/image.png';

export default {
  component: MyComponent,
};

const image = {
  src: imageFile,
  alt: 'my image',
};

export const WithAnImage = {
  render: () => ({
    Component: MyComponent,
    props: image,
  }),
};
svelte
<script module>
  import { defineMeta } from '@storybook/addon-svelte-csf';

  import MyComponent from './MyComponent.svelte';

  import imageFile from './static/image.png';

  let image = {
    src: imageFile,
    alt: 'my image',
  };

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

<Story name="WithAnImage">
	<MyComponent {image} />
</Story>
ts
// Replace your-framework with svelte-vite or sveltekit
import type { Meta, StoryObj } from '@storybook/your-framework';

import MyComponent from './MyComponent.svelte';

import imageFile from './static/image.png';

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

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

const image = {
  src: imageFile,
  alt: 'my image',
};

export const WithAnImage: Story = {
  render: () => ({
    Component: MyComponent,
    props: image,
  }),
};
js
import MyComponent from './MyComponent.vue';

import imageFile from './static/image.png';

export default {
  component: MyComponent,
};

const image = {
  src: imageFile,
  alt: 'my image',
};

export const WithAnImage = {
  render: () => ({
    setup() {
      //๐Ÿ‘‡ Returns the content of the image object created above.
      return { image };
    },
    template: ``,
  }),
};
ts
import type { Meta, StoryObj } from '@storybook/vue3-vite';

import MyComponent from './MyComponent.vue';

import imageFile from './static/image.png';

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

const image = {
  src: imageFile,
  alt: 'my image',
};

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

export const WithAnImage: Story = {
  render: () => ({
    setup() {
      //๐Ÿ‘‡ Returns the content of the image object created above.
      return { image };
    },
    template: ``,
  }),
};
ts
import preview from '../.storybook/preview';

import MyComponent from './MyComponent.vue';

import imageFile from './static/image.png';

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

const image = {
  src: imageFile,
  alt: 'my image',
};

export const WithAnImage = meta.story({
  render: () => ({
    setup() {
      //๐Ÿ‘‡ Returns the content of the image object created above.
      return { image };
    },
    template: ``,
  }),
});
<!-- JS snippets still needed while providing both CSF 3 & Next -->
js
import preview from '../.storybook/preview';

import MyComponent from './MyComponent.vue';

import imageFile from './static/image.png';

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

const image = {
  src: imageFile,
  alt: 'my image',
};

export const WithAnImage = meta.story({
  render: () => ({
    setup() {
      //๐Ÿ‘‡ Returns the content of the image object created above.
      return { image };
    },
    template: ``,
  }),
});
js
import { html } from 'lit';

import imageFile from './static/image.png';

export default {
  component: 'my-component',
};

const image = {
  src: imageFile,
  alt: 'my image',
};

export const WithAnImage = {
  render: () => html` `,
};
ts
import type { Meta, StoryObj } from '@storybook/web-components-vite';

import { html } from 'lit';

import imageFile from './static/image.png';

const meta: Meta = {
  component: 'my-component',
};

const image = {
  src: imageFile,
  alt: 'my image',
};

export default meta;
type Story = StoryObj;

export const WithAnImage: Story = {
  render: () => html``,
};
js
import { html } from 'lit';

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

import imageFile from './static/image.png';

const meta = preview.meta({
  component: 'my-component',
});

const image = {
  src: imageFile,
  alt: 'my image',
};

export const WithAnImage = meta.story({
  render: () => html` `,
});
ts
import { html } from 'lit';

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

import imageFile from './static/image.png';

const meta = preview.meta({
  component: 'my-component',
});

const image = {
  src: imageFile,
  alt: 'my image',
};

export const WithAnImage = meta.story({
  render: () => html``,
});
tsx
import preview from '../.storybook/preview';

import imageFile from './static/image.png';

import { MyComponent } from './MyComponent';

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

const image = {
  src: imageFile,
  alt: 'my image',
};

export const WithAnImage = meta.story({
  render: () => ,
});
<!-- JS snippets still needed while providing both CSF 3 & Next -->
js
import preview from '../.storybook/preview';

import { MyComponent } from './MyComponent';

import imageFile from './static/image.png';

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

const image = {
  src: imageFile,
  alt: 'my image',
};

export const WithAnImage = meta.story({
  render: () => ,
});