@brightlayer-ui/storybook-rtl-addon

中文文档
1.1.0发布于 2021/10/26BSD-3-ClauseTypeScriptCommonJS零依赖近 30 天下载 1715

RTL Toggle for Storybook

此软件包已被标记为弃用

This package has been deprecated.

原始使用文档
文档目录8 节
  1. Installation
  2. Usage
  3. getDirection
  4. Angular Usage
  5. React Usage
  6. useDirection
  7. Tested Frameworks
  8. Local Testing

npm

@brightlayer-ui/storybook-rtl-addon

This storybook addon provides a Right-to-Left toggle used to test your component's bidirectionality support.
When this addon is active, it sets the current story body's dir attribute to rtl.

This addon assumes the default text orientation of the parent storybook app is Left-to-Right.

Installation

To install the @brightlayer-ui/storybook-rtl-addon run:

yarn add @brightlayer-ui/storybook-rtl-addon

In your main.js file, register this addon:

addons: ['@brightlayer-ui/storybook-rtl-addon/register']

Usage

This package exports two functions getDirection & useDirection that returns the current Direction ('rtl' or 'ltr').

getDirection

getDirection is used within Stories to access the current Direction. In React, this is value is only set during the initial component mount.

Brightlayer UI uses this addon extensively in our storybook documentation to guarantee bidirectional support of our components and examples.

To see live-example usage of this addon, click on the "Story" tab of each linked example.

Angular Usage

import { getDirection } from '@brightlayer-ui/storybook-rtl-addon';

export const angularExampleStory = () => ({
    template: `
        <div>{{direction}}</div>
    `,
    props: {
        direction: getDirection
    }
});

Angular Components: If your component uses the Direction service, use the exported function getDirection() to supply the [dir] directive with the appropriate direction.

Live Example

React Usage

import { getDirection } from '@brightlayer-ui/storybook-rtl-addon';

export const reactExampleStory = () => {
    const direction = getDirection();
    return <div>{direction}</div>;
}

Live Example

useDirection

useDirection is a React hook that returns the current Direction and re-emits on every Direction change (when toggling the RTL sidebar button). It can be used to set values for Providers in a Decorators or Stories.

import useDirection from "@brightlayer-ui/storybook-rtl-addon/useDirection";

export const decorators = [
    (Story) => {
        const direction = useDirection();
        return (
            <>
                {direction}
                <Story />
            </>
        );
    },
];

Tested Frameworks

  • Angular (^8.0.0)
  • React (^17.0.0)

Local Testing

This addon can be tested locally by using npm link or yarn link commands.

From the addon's root folder, run the following to rebuild the addon when changes occur:

yarn watch

From another terminal, run:

yarn link

From your storybook app's root folder, run:

yarn link @brightlayer-ui/storybook-rtl-addon

When finished testing the local version of this addon, run:

yarn unlink @brightlayer-ui/storybook-rtl-addon

版本与发布记录

@brightlayer-ui/storybook-rtl-addon 共发布 2 个版本,首次发布于 2021/10/22;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.1.0latest2021/10/265 年前
1.1.0-beta.0beta2021/10/225 年前

关于 @brightlayer-ui/storybook-rtl-addon 的常见问题

@brightlayer-ui/storybook-rtl-addon 是什么?

RTL Toggle for Storybook注意:该包已被作者标记为弃用——This package has been deprecated.

如何安装 @brightlayer-ui/storybook-rtl-addon?

在项目目录运行 npm install @brightlayer-ui/storybook-rtl-addon,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@storybook/addons(>= 5.x)、@storybook/api(>= 5.x)、@storybook/components(>= 5.x)、@storybook/core-events(>= 5.x)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@brightlayer-ui/storybook-rtl-addon 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@brightlayer-ui/storybook-rtl-addon 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@brightlayer-ui/storybook-rtl-addon 可以商用吗?

@brightlayer-ui/storybook-rtl-addon 使用 BSD-3-Clause 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。另外不得用原作者名义为衍生产品背书。以上为概括,不构成法律意见,请以许可原文为准。

@brightlayer-ui/storybook-rtl-addon 的下载量有多少?

根据 npm 官方下载统计,@brightlayer-ui/storybook-rtl-addon 在 2026/10/09 – 2026/11/07 这 30 天内被下载 1,715 次,日均约 57 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@brightlayer-ui/storybook-rtl-addon 还在维护吗?

最新版本 1.1.0 发布于 2021/10/26(5 年前);至今共发布 2 个版本,其中过去 12 个月发布了 0 个;首次发布于 2021/10/22。作者已将其标记为弃用,新项目建议寻找替代方案。