原始碼

顯示目前 Story 的原始碼範例

在 Github 上檢視

@mihkeleidast/storybook-addon-source

安裝

首先,安裝套件。

npm install --save-dev @mihkeleidast/storybook-addon-source

然後,在 .storybook/main.js 中將其註冊為擴充功能。

// .storybook/main.ts

// Replace your-framework with the framework you are using (e.g., react-webpack5, vue3-vite)
import type { StorybookConfig } from '@storybook/your-framework';

const config: StorybookConfig = {
  // ...rest of config
  addons: [
    '@storybook/addon-essentials'
    '@mihkeleidast/storybook-addon-source', // 👈 register the addon here
  ],
};

export default config;

然後,在 .storybook/preview.js 中新增裝飾器。

// .storybook/preview.ts
import { Preview } from "@storybook/react";

import { withJsx } from '../dist/index.js'

const preview: Preview = {
  decorators: [
    withJsx, // 👈 add the decorator as the first one
    // ... rest of decorators
  ],
};

export default preview;
由以下人員製作
  • mihkeleidast
    mihkeleidast
適用於
    React
標籤