@equinor/echo-components

中文文档
7.0.0发布于 2026/10/27TypeScriptCommonJS近 30 天下载 2715

This publishable library was generated with Nx.

原始使用文档
文档目录18 节
  1. ⚠️ Dependency Rules
  2. Guidelines for storybook
  3. Online storybook
  4. Why Use Storybook?
  5. Before you write your storybook
  6. Building Blocks of Captivating Stories
  7. Writing Effective Descriptions:
  8. Beyond the Basics:
  9. Text Example: Let's Build a Button Story!
  10. Recipe for Writing a Good Story in Your Storybook (Using th…
  11. Picture Example: SecondaryMarker
  12. How to develop and release EchoComponents
  13. Available NPM scripts
  14. Old repository of echoComponents
  15. Guidelines for developing
  16. Example: Card Component
  17. Example: Bootstrapping Card Components
  18. Developer Checklist

EchoComponents

This publishable library was generated with Nx.

Building blocks for Echo, built on top of EDS (Equinor Design System).

⚠️ Dependency Rules

Source of truth: /eslint.config.js - The @nx/enforce-module-boundaries rule defines all allowed dependencies.

echo-components can only import from:

  • echo-utils ✅

echo-components CANNOT import from:

  • echo-framework ❌
  • echo-search ❌
  • echo-core ❌
  • echo-base ❌
  • echopedia-web (app) ❌

See libs/README.md for the full dependency flow diagram.


Guidelines for storybook

Think of Storybook as a virtual showroom for your app's building blocks - the UI components. It lets developers experiment with components in isolation, like tinkering with Legos before building something bigger. Storybook isn't just about documenting components, it's about creating an interactive playground for developers to explore their full potential.

Online storybook

Publishing static storybook page

  • a github action builds and deploys the static storybook page to the following branch: echo-components-storybook - we shouldn't delete this one!
  • another github action will pick it up from here, and publish it to a github page.

Online storybook can be found here

Why Use Storybook?

  • Faster Development: Experiment with components quickly, without needing the whole app running.
  • Improved Consistency: Ensures all components look and behave the same way throughout the app.
  • Better Collaboration: Designers and developers can easily share component design and functionality.
  • Easier Maintenance: New developers can understand existing components through clear documentation.

Before you write your storybook

  • Understand Your Components: Take some time to thoroughly understand the components you'll document. What purpose do they serve? What props do they accept? What states can they be in? This knowledge will guide the scenarios you showcase in your storybook.
  • Know Your Audience: Consider who will be using your storybook. Are they primarily developers new to the codebase, or seasoned veterans? This will influence the level of detail you provide and the complexity of the stories you create.

Building Blocks of Captivating Stories

  • Isolate and Conquer: Storybook lets components shine by themselves. This allows developers to experiment with props and states without worrying about interactions with other parts of the code.
  • Variety is the Spice of Life: Don't just show the basics! Showcase the versatility of your component with different prop combinations (sizes, styles), visual themes (light/dark mode), and functional states (loading, error, success).
  • Interactive Playground: Utilize Storybook's interactivity features. Allow developers to change props and states directly within the storybook interface. This fosters exploration and experimentation.

Writing Effective Descriptions:

  • Clear and Concise: Write clear and concise descriptions that explain the component's purpose and usage. Avoid technical jargon that new developers might not understand.
  • Focus on Benefits: Highlight the benefits of using the component. How does it make development easier or more efficient?
  • Code Examples: Provide relevant code examples that demonstrate how to use the component in practice. Include both basic usage and more advanced scenarios.

Beyond the Basics:

  • Accessibility for All: Consider accessibility in your stories. Showcase how the component can be used to create interfaces that everyone can use.
  • BeBest Practices for Best Results: Include examples of how to use the component effectively. This helps developers avoid common pitfalls and write cleaner, more maintainable code.
  • Visual Appeal Matters: Use clear and organized layouts for your stories. Consider using visual aids like screenshots or mockups to enhance understanding.

Text Example: Let's Build a Button Story!

Imagine a button component - the workhorse of applications. Here's how to craft a compelling story around it:

  • Title: Button - A Versatile Action Trigger
  • Description: A versatile button component for triggering actions in your application. Supports various styles (primary, secondary), sizes (large, small), and states (enabled, disabled) for a consistent user experience.
  • Basic Usage: Show a simple button with its default label and style.
  • Prop Variations: Include stories that demonstrate different props like size, variant, and disabled state.
  • Visual Themes: Showcase the button in different themes (light mode, dark mode) if applicable.
  • Interactive Playground: Allow developers to change the button text, choose a variant, and toggle the disabled state directly within the storybook.
  • Code Example: Provide a code snippet demonstrating how to import and use the button component with different props.

Recipe for Writing a Good Story in Your Storybook (Using the Button Component Example)

Ingredients:

  • Fresh Code: The code for the component you want to showcase (like the provided Button.stories.tsx file).
  • Storybook Utilities: StoryFn and Meta functions from @storybook/react.
  • Clarity and Conciseness: Aim for clear and easy-to-understand stories.
  • Variety: Showcase different configurations and usage scenarios.
  • Visual Appeal (Optional): Make the stories visually appealing for better engagement.

Step 1. Set the Stage: Configuration and Title (Meta): Define the Meta object with:

  • title: A descriptive title indicating the component hierarchy (e.g., "Components/Button/Button").
  • component: The component you're showcasing (e.g., Button).
  • args: Default values for component props (e.g., as: 'button').
  • argTypes: Define control types for interactive prop selection.
  • parameters.docs.page: Link to your component's documentation (optional).
import { Meta, StoryFn } from '@storybook/react';
import { Button } from './Button'; // Replace with your Button component import path

const meta: Meta<typeof Button> = {
  title: 'Components/Button/Button', // Descriptive title for Storybook navigation
  component: Button,
  args: {
    as: 'button', // Default element type (can be overridden as 'span' or 'a')
  },
  argTypes: {
    as: {
      options: ['span', 'a', 'button'], // Available options for the 'as' prop
      control: {
        type: 'select', // Control type for selecting the 'as' prop in Storybook UI
      },
    },
  },
  parameters: {
    docs: {
      page: './Button.docs.mdx', // Path to your button documentation file (replace if needed)
    },
  },
};

export default meta;

Step 2. Create the Template: Write a reusable Template function that renders the component within a container element (e.g., div). This template will be used in most stories.

const Template: StoryFn<Button.Props> = (args) => (
  <div className="button-container"> {/* Add a container class for styling (optional) */}
    <Button {...args} />
  </div>
);

Step 3. Tell the Main Story: Introduction:

  • Define a story named Introduction (or similar) that uses the Template function.
  • Render a basic button with its default props to showcase its fundamental form.
export const Introduction: StoryFn<Button.Props> = () => (
  <Template>You can control me</Template>
);

Step 4. Spice it Up: Variations and States: Create additional stories to demonstrate different button variations and states. These could be:

  • Different styles (primary, secondary, outlined)
  • Sizes (large, small)
  • Disabled state
  • Loading state (if applicable)
  • Icon variations (with or without icons)
  • Interactive elements (toggling loading state) For each story, provide a descriptive title that reflects the variation (e.g., "Primary Button - Large").
export const PrimaryButtonLarge: StoryFn<Button.Props> = () => (
  <Template>
    <Button variant="primary" size="large">
      Large Primary Button
    </Button>
  </Template>
);

export const DisabledButton: StoryFn<Button.Props> = () => (
  <Template>
    <Button disabled>Click Me (Disabled)</Button>
  </Template>
);

export const LoadingButton: StoryFn<Button.Props> = () => (
  <Template>
    <Button isLoading>Loading...</Button>
  </Template>
);

export const IconButton: StoryFn<Button.Props> = () => (
  <Template>
    <Button variant="icon">
      <Icon name="search" /> {/* Assuming you have an Icon component */}
    </Button>
  </Template>
);

Step 5. Visual Presentation (Optional): Consider using background colors or layouts to enhance the visual appeal of your stories. Example: You can customize the button-container class in the Template to add background colors or styles for a more visually appealing presentation.

Step 6. Serve it Up! (Export): Export the meta object (containing configuration) at the end of your file..

export default meta;

Picture Example: SecondaryMarker

image

How to develop and release EchoComponents

Check the readme in the NX libraries folder.

Available NPM scripts

  • lint-components
  • build-components
  • test-components

Old repository of echoComponents

Keeping it for historical reasons. https://github.com/equinor/EchoComponents

Guidelines for developing

Composition

When deciding how to write your new component consider the composition. Using smaller interchangeable components that each represent a specific function or feature in the context of a larger component. Using wrapper components in conjunction with the children property, allows for a greater separation of concerns, smaller blocks of code and a greater level of customization in the final product.

Example: Card Component

<Card.Container> {/* REQUIRED */}
    <Card.Image src="hello_world.jpg"> {/* INTERCHANGEABLE */}
        <Card.Caption>Descriptive text</Card.Caption> {/* INTERCHANGEABLE */}
        <Card.Heading>Heading</Card.Heading> {/* INTERCHANGEABLE */}
        <Card.Ingress>Subtitle/Ingress</Card.Ingress> {/* INTERCHANGEABLE */}
        <Card.Article>Main content</Card.Article> {/* INTERCHANGEABLE */}
    </Card.Image>
</Card.Container>

The makeup of each component may vary depending on the feature and the problem being solved. Some components may not be interchangeable, and some components may need additional props.

Abstracting the individual composition should be possible, by creating a new component in the project that can act as a bootstrapping mechanism for the EchoComponent composition.

Example: Bootstrapping Card Components

import React from 'react';

type Props = {
    heading: string;
    mainContent: string;
    imageSrc?: string;
    imageCaption?: string;
    ingress?: string;
};

export const ExampleCard: React.FC<Props> = ({ heading, mainContent, imageSrc, imageCaption, ingress }) => {
    return (
        <Card.Container>
            <Card.Image src={imageSrc}>
                {imageCaption && <Card.Caption>{imageCaption}</Card.Caption>}
                <Card.Heading>{heading}</Card.Heading>
                {ingress && <Card.Ingress>{ingress}</Card.Ingress>}
                <Card.Article>{mainContent}</Card.Article>
            </Card.Image>
        </Card.Container>
    );
};

export default ExampleCard;

Developer Checklist

  1. Keep components small, focused with a single responsibility where possible.
  2. When possible, use wrapper components with properties for children and className.
  3. className should always be included, to allow for custom styling when needed. (see point 6. for more information on custom styling)
  4. Styling of components should always be done with CSS Modules.
  5. Make sure the component(s) accurately reflect the provided UX sketches, but do not be afraid to challenge the UX sketches if they have not accounted for specific uses case, and/or present a unusually difficult challenge.
  6. Allowing custom styling of individual components does not mean developers have free rein to do as they please. Custom styling should always be approved by UX and only when it makes sense for the user experience.
  7. When naming components always check if the UX sketches already have a name, if not make the name as intuitive and descriptive as possible.
  8. Add each component to Storybook with default props, examples, and explanations (when needed).

版本与发布记录

@equinor/echo-components 共发布 226 个版本,首次发布于 2021/02/05;过去 12 个月发布了 37 个版本。

版本发布日期距今
7.0.0latest2026/10/2717 天前
7.0.0-beta-2beta2026/10/2717 天前
7.0.0-beta-12026/10/2222 天前
6.3.12026/08/073 个月前
6.3.02026/07/233 个月前
6.2.42026/07/094 个月前

其他发布通道:next → 0.5.19-rc1,beta → 7.0.0-beta-2。

关于 @equinor/echo-components 的常见问题

@equinor/echo-components 是什么?

This publishable library was generated with Nx.

如何安装 @equinor/echo-components?

在项目目录运行 npm install @equinor/echo-components,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(>= 19.2.4)、lodash(>= 4.17.21 < 5)、zustand(>= 4.4.7 < 5)、react-dom(>= 19.2.4)、classnames(2.5.1)、sortablejs(>= 1.15.1 < 2)、react-sortablejs(6.1.4)、@equinor/eds-icons(0.22.0)、@equinor/echo-utils(>= 7.0.0 < 8.0.0)、@equinor/eds-tokens(2.1.0)、@equinor/eds-core-react(0.49.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@equinor/echo-components 支持 TypeScript 吗?

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

@equinor/echo-components 支持 ESM 还是 CommonJS?

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

@equinor/echo-components 可以商用吗?

@equinor/echo-components 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@equinor/echo-components 的下载量有多少?

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

@equinor/echo-components 还在维护吗?

最新版本 7.0.0 发布于 2026/10/27(17 天前);至今共发布 226 个版本,其中过去 12 个月发布了 37 个;首次发布于 2021/02/05。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。