文字方向

切換由左至右(LTR)和由右至左(RTL)的文字方向

在 Github 上檢視

Storybook 文字方向擴充功能

安裝

首先,安裝套件。

npm install --save-dev storybook-addon-text-direction

然後,在 .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'
    'storybook-addon-text-direction', // 👈 register the addon here
  ],
};

export default config;

用法

使用此擴充功能的主要方式是定義 textDirection 參數。您可以在元件層級執行此操作(如下所示)以影響檔案中的所有 Story,或者您可以針對單個 Story 執行此操作。

// Button.stories.ts

// Replace your-framework with the name of your framework
import type { Meta } from 'storybook-addon-text-direction';

import { Button } from './Button';

const meta: Meta<typeof Button> = {
  component: Button,
  parameters: {
    textDirection: 'rtl',
  }
};

export default meta;