LTR / RTL

一个 Storybook 工具插件,用于在 LTR 和 RTL 之间切换 html dir 属性。

在 Github 上查看

storybook-addon-rtl-direction

一个 Storybook 工具插件,用于在 LTR 和 RTL 之间切换 html dir 属性。

  • dir="ltr"dir="rtl" 样式将与工具部分中的 LTR/RTL 图标一起添加到 html 标签中。

Example

安装

npm i --save-dev storybook-addon-rtl-direction

将其添加到 .storybook/main.js

module.exports = {
  addons: ["storybook-addon-rtl-direction"],
};

使用语言环境

您可以与语言环境同步以设置默认方向。

// preview.js

export const globalTypes = {
  locale: {
    name: "Locale",
    description: "Internationalization locale",
    defaultValue: "en",
    toolbar: {
      icon: "globe",
      items: [
        { value: "en-US", right: "LTR", title: "English (United States)" },
        { value: "es", right: "LTR", title: "Spanish" },
        { value: "ar", right: "RTL", title: "Arabic" },
        { value: "ar-OM", right: "RTL", title: "Arabic (Oman)" },
        { value: "pa-IN", right: "LTR", title: "Punjabi (India)" },
        { value: "pa-PK", right: "RTL", title: "Punjabi (Pakistan)" },
      ],
    },
  },
};

export const parameters = {
  rtlDirection: {
    // Collection to set as RTL (You can add language or with add country code specifically)
    autoLocales: ["ar", "pa-PK"],
    // Condition to reload the page each time locale is updated
    reload: true,
  },
};

https://user-images.githubusercontent.com/588874/194731628-07124805-cc11-4acb-bb45-0aa24d53c625.mov

由以下人员制作
  • mayognaise
    mayognaise
适用于
    Angular
    Ember
    HTML
    Preact
    React
    Svelte
    Vue
    Web Components
标签