mayognaise / storybook-addon-rtl-direction

Toggle between LTR and RTL mode in Storybook

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

storybook-addon-rtl-direction

A Storybook tool add-on to toggle html dir attribute between LTR and RTL.

  • dir="ltr" or dir="rtl" style will be added to html tag with LTR/RTL icon in tool section.

Example

Installation

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

Add it to .storybook/main.js

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

With Locale

You can sync with locale to set default 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,
  },
};
with-locale.mov

About

Toggle between LTR and RTL mode in Storybook

License:MIT License


Languages

Language:JavaScript 67.1%Language:TypeScript 29.1%Language:CSS 3.8%