Back to Storybook

Code Panel In Meta And Story

docs/_snippets/code-panel-in-meta-and-story.md

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

import { Button } from './button.component';

const meta: Meta<Button> = {
  component: Button,
  parameters: {
    docs: {
      // ๐Ÿ‘‡ Enable Code panel for all stories in this file
      codePanel: true,
    },
  },
};
export default meta;

type Story = StoryObj<typeof Button>;

// ๐Ÿ‘‡ This story will display the Code panel
export const Primary: Story = {
  args: {
    children: 'Button',
  },
};

export const Secondary: Story = {
  args: {
    children: 'Button',
    variant: 'secondary',
  },
  parameters: {
    docs: {
      // ๐Ÿ‘‡ Disable Code panel for this specific story
      codePanel: false,
    },
  },
};
ts
import preview from '../.storybook/preview';

import { Button } from './button.component';

const meta = preview.meta({
  component: Button,
  parameters: {
    docs: {
      // ๐Ÿ‘‡ Enable Code panel for all stories in this file
      codePanel: true,
    },
  },
});

// ๐Ÿ‘‡ This story will display the Code panel
export const Primary = meta.story({
  args: {
    children: 'Button',
  },
});

export const Secondary = meta.story({
  args: {
    children: 'Button',
    variant: 'secondary',
  },
  parameters: {
    docs: {
      // ๐Ÿ‘‡ Disable Code panel for this specific story
      codePanel: false,
    },
  },
});
ts
import type { Meta, StoryObj } from '@storybook/react-vite';

import { Button } from './Button';

const meta = {
  component: Button,
  parameters: {
    docs: {
      // ๐Ÿ‘‡ Enable Code panel for all stories in this file
      codePanel: true,
    },
  },
} satisfies Meta<typeof Button>;
export default meta;

type Story = StoryObj<typeof meta>;

// ๐Ÿ‘‡ This story will display the Code panel
export const Primary: Story = {
  args: {
    children: 'Button',
  },
};

export const Secondary: Story = {
  args: {
    children: 'Button',
    variant: 'secondary',
  },
  parameters: {
    docs: {
      // ๐Ÿ‘‡ Disable Code panel for this specific story
      codePanel: false,
    },
  },
};
js
import { Button } from './Button';

export default {
  component: Button,
  parameters: {
    docs: {
      // ๐Ÿ‘‡ Enable Code panel for all stories in this file
      codePanel: true,
    },
  },
};

// ๐Ÿ‘‡ This story will display the Code panel
export const Primary = {
  args: {
    children: 'Button',
  },
};

export const Secondary = {
  args: {
    children: 'Button',
    variant: 'secondary',
  },
  parameters: {
    docs: {
      // ๐Ÿ‘‡ Disable Code panel for this specific story
      codePanel: false,
    },
  },
};
svelte
<script module>
  import { defineMeta } from '@storybook/addon-svelte-csf';

  import Button from './Button.svelte';

  const { Story } = defineMeta({
    component: Button,
    parameters: {
      docs: {
        // ๐Ÿ‘‡ Enable Code panel for all stories in this file
        codePanel: true,
      },
    },
  });
</script>

<Story
  name="Primary"
  args={{
    children: 'Button',
  }}
/>

<Story
  name="Secondary"
  args={{
    children: 'Button',
    variant: 'secondary',
  }}
  parameters={{
    docs: {
      // ๐Ÿ‘‡ Disable Code panel for this specific story
      codePanel: false,
    },
  }}
/>
ts
// Replace your-framework with svelte-vite or sveltekit
import type { Meta, StoryObj } from '@storybook/your-framework';

import Button from './Button.svelte';

const meta = {
  component: Button,
  parameters: {
    docs: {
      // ๐Ÿ‘‡ Enable Code panel for all stories in this file
      codePanel: true,
    },
  },
} satisfies Meta<typeof Button>;
export default meta;

type Story = StoryObj<typeof meta>;

// ๐Ÿ‘‡ This story will display the Code panel
export const Primary: Story = {
  args: {
    children: 'Button',
  },
};

export const Secondary: Story = {
  args: {
    children: 'Button',
    variant: 'secondary',
  },
  parameters: {
    docs: {
      // ๐Ÿ‘‡ Disable Code panel for this specific story
      codePanel: false,
    },
  },
};
svelte
<script module>
  import { defineMeta } from '@storybook/addon-svelte-csf';

  import Button from './Button.svelte';

  const { Story } = defineMeta({
    component: Button,
    parameters: {
      docs: {
        // ๐Ÿ‘‡ Enable Code panel for all stories in this file
        codePanel: true,
      },
    },
  });
</script>

<Story
  name="Primary"
  args={{
    children: 'Button',
  }}
/>

<Story
  name="Secondary"
  args={{
    children: 'Button',
    variant: 'secondary',
  }}
  parameters={{
    docs: {
      // ๐Ÿ‘‡ Disable Code panel for this specific story
      codePanel: false,
    },
  }}
/>
js
import Button from './Button.svelte';

export default {
  component: Button,
  parameters: {
    docs: {
      // ๐Ÿ‘‡ Enable Code panel for all stories in this file
      codePanel: true,
    },
  },
};

// ๐Ÿ‘‡ This story will display the Code panel
export const Primary = {
  args: {
    children: 'Button',
  },
};

export const Secondary = {
  args: {
    children: 'Button',
    variant: 'secondary',
  },
  parameters: {
    docs: {
      // ๐Ÿ‘‡ Disable Code panel for this specific story
      codePanel: false,
    },
  },
};
ts
import type { Meta, StoryObj } from '@storybook/vue3-vite';

import Button from './Button.vue';

const meta = {
  component: Button,
  parameters: {
    docs: {
      // ๐Ÿ‘‡ Enable Code panel for all stories in this file
      codePanel: true,
    },
  },
} satisfies Meta<typeof Button>;
export default meta;

type Story = StoryObj<typeof meta>;

// ๐Ÿ‘‡ This story will display the Code panel
export const Primary: Story = {
  args: {
    children: 'Button',
  },
};

export const Secondary: Story = {
  args: {
    children: 'Button',
    variant: 'secondary',
  },
  parameters: {
    docs: {
      // ๐Ÿ‘‡ Disable Code panel for this specific story
      codePanel: false,
    },
  },
};
js
import Button from './Button.vue';

export default {
  component: Button,
  parameters: {
    docs: {
      // ๐Ÿ‘‡ Enable Code panel for all stories in this file
      codePanel: true,
    },
  },
};

// ๐Ÿ‘‡ This story will display the Code panel
export const Primary = {
  args: {
    children: 'Button',
  },
};

export const Secondary = {
  args: {
    children: 'Button',
    variant: 'secondary',
  },
  parameters: {
    docs: {
      // ๐Ÿ‘‡ Disable Code panel for this specific story
      codePanel: false,
    },
  },
};
ts
import preview from '../.storybook/preview';

import Button from './Button.vue';

const meta = preview.meta({
  component: Button,
  parameters: {
    docs: {
      // ๐Ÿ‘‡ Enable Code panel for all stories in this file
      codePanel: true,
    },
  },
});

// ๐Ÿ‘‡ This story will display the Code panel
export const Primary = meta.story({
  args: {
    children: 'Button',
  },
});

export const Secondary = meta.story({
  args: {
    children: 'Button',
    variant: 'secondary',
  },
  parameters: {
    docs: {
      // ๐Ÿ‘‡ Disable Code panel for this specific story
      codePanel: false,
    },
  },
});
<!-- JS snippets still needed while providing both CSF 3 & Next -->
js
import preview from '../.storybook/preview';

import Button from './Button.vue';

const meta = preview.meta({
  component: Button,
  parameters: {
    docs: {
      // ๐Ÿ‘‡ Enable Code panel for all stories in this file
      codePanel: true,
    },
  },
});

// ๐Ÿ‘‡ This story will display the Code panel
export const Primary = meta.story({
  args: {
    children: 'Button',
  },
});

export const Secondary = meta.story({
  args: {
    children: 'Button',
    variant: 'secondary',
  },
  parameters: {
    docs: {
      // ๐Ÿ‘‡ Disable Code panel for this specific story
      codePanel: false,
    },
  },
});
ts
import type { Meta, StoryObj } from '@storybook/web-components-vite';

const meta: Meta = {
  component: 'demo-button',
  parameters: {
    docs: {
      // ๐Ÿ‘‡ Enable Code panel for all stories in this file
      codePanel: true,
    },
  },
};
export default meta;

type Story = StoryObj;

// ๐Ÿ‘‡ This story will display the Code panel
export const Primary: Story = {
  args: {
    children: 'Button',
  },
};

export const Secondary: Story = {
  args: {
    children: 'Button',
    variant: 'secondary',
  },
  parameters: {
    docs: {
      // ๐Ÿ‘‡ Disable Code panel for this specific story
      codePanel: false,
    },
  },
};
js
export default {
  component: 'demo-button',
  parameters: {
    docs: {
      // ๐Ÿ‘‡ Enable Code panel for all stories in this file
      codePanel: true,
    },
  },
};

// ๐Ÿ‘‡ This story will display the Code panel
export const Primary = {
  args: {
    children: 'Button',
  },
};

export const Secondary = {
  args: {
    children: 'Button',
    variant: 'secondary',
  },
  parameters: {
    docs: {
      // ๐Ÿ‘‡ Disable Code panel for this specific story
      codePanel: false,
    },
  },
};
js
import preview from '../.storybook/preview';

const meta = preview.meta({
  component: 'demo-button',
  parameters: {
    docs: {
      // ๐Ÿ‘‡ Enable Code panel for all stories in this file
      codePanel: true,
    },
  },
});

// ๐Ÿ‘‡ This story will display the Code panel
export const Primary = meta.story({
  args: {
    children: 'Button',
  },
});

export const Secondary = meta.story({
  args: {
    children: 'Button',
    variant: 'secondary',
  },
  parameters: {
    docs: {
      // ๐Ÿ‘‡ Disable Code panel for this specific story
      codePanel: false,
    },
  },
});
ts
import preview from '../.storybook/preview';

const meta = preview.meta({
  component: 'demo-button',
  parameters: {
    docs: {
      // ๐Ÿ‘‡ Enable Code panel for all stories in this file
      codePanel: true,
    },
  },
});

// ๐Ÿ‘‡ This story will display the Code panel
export const Primary = meta.story({
  args: {
    children: 'Button',
  },
});

export const Secondary = meta.story({
  args: {
    children: 'Button',
    variant: 'secondary',
  },
  parameters: {
    docs: {
      // ๐Ÿ‘‡ Disable Code panel for this specific story
      codePanel: false,
    },
  },
});
ts
import preview from '../.storybook/preview';

import { Button } from './Button';

const meta = preview.meta({
  component: Button,
  parameters: {
    docs: {
      // ๐Ÿ‘‡ Enable Code panel for all stories in this file
      codePanel: true,
    },
  },
});

// ๐Ÿ‘‡ This story will display the Code panel
export const Primary = meta.story({
  args: {
    children: 'Button',
  },
});

export const Secondary = meta.story({
  args: {
    children: 'Button',
    variant: 'secondary',
  },
  parameters: {
    docs: {
      // ๐Ÿ‘‡ Disable Code panel for this specific story
      codePanel: false,
    },
  },
});
<!-- JS snippets still needed while providing both CSF 3 & Next -->
js
import preview from '../.storybook/preview';

import { Button } from './Button';

const meta = preview.meta({
  component: Button,
  parameters: {
    docs: {
      // ๐Ÿ‘‡ Enable Code panel for all stories in this file
      codePanel: true,
    },
  },
});

// ๐Ÿ‘‡ This story will display the Code panel
export const Primary = meta.story({
  args: {
    children: 'Button',
  },
});

export const Secondary = meta.story({
  args: {
    children: 'Button',
    variant: 'secondary',
  },
  parameters: {
    docs: {
      // ๐Ÿ‘‡ Disable Code panel for this specific story
      codePanel: false,
    },
  },
});