@coveo/atomic

中文文档
3.65.0发布于 2026/11/03Apache-2.0TypeScriptESM + CJS构建来源已验证近 30 天下载 4.1万

A web-component library for building modern UIs interfacing with the Coveo platform

原始使用文档
文档目录10 节
  1. Entry points
  2. Getting Started
  3. Running package scripts
  4. Available scripts
  5. Storybook MCP (Model Context Protocol)
  6. Utilities
  7. Stencil decorators
  8. InitializeBindings & BindStateToController decorators
  9. ResultContext decorator
  10. Generate Component Command

npm version Built With Stencil

Atomic

A web-component library for building modern UIs interfacing with the Coveo platform. Atomic web-components are built with Stencil. They are self-encapsulated, composable, and light-weight.

Using the library: Coveo Atomic Library Official Documentation.

Contributing: See CONTRIBUTING.md for guidelines on developing Atomic components, running tests, and using development tools.

Entry points

The @coveo/atomic package exposes the following entry points:

  • @coveo/atomic: exports various types and utilities used by Coveo Atomic.
  • @coveo/atomic/loader: exports the Coveo Atomic components types, as well as the defineCustomElements and setNonce utilities.
  • @coveo/atomic/themes: exports the sample Coveo Atomic themes.
  • @coveo/atomic/assets: exports the SVG icons used by Coveo Atomic.
  • @coveo/atomic/lang: exports the localization files used by Coveo Atomic.

Getting Started

Once you have cloned the repo, follow the instructions in the top-level README.md to install dependencies and link packages.

Running package scripts

While there are package specific scripts for this package, its best to rely on running command with turbo from the root of the monorepo.

For example, to run the package in the development you would run

# ✅ Preferred method
pnpm turbo run dev --filter=@coveo/atomic

from the root of the monorepo, as opposed to

# ❌ Deprecated method
cd package/atomic
pnpm run dev

While running scripts from the package folder does work, using the turbo scripts is generally a smoother experience.

All the subsequent examples assume you are operating from the monorepo root.

Available scripts

Atomic uses Storybook for component development, documentation, and testing. To start Storybook in development mode:

pnpm turbo run dev --filter=@coveo/atomic

Storybook will be available at http://localhost:4400.

[!NOTE] It is important you build @coveo/atomic at least once before running the Storybook server. This ensures all components can be properly rendered by Storybook, otherwise you not see components rendered.

To build the library for production, run:

pnpm turbo run build --filter=@coveo/atomic

To run the unit tests for the components, run:

pnpm turbo run test --filter=@coveo/atomic

Storybook MCP (Model Context Protocol)

This Storybook instance is configured with the MCP addon, which enables AI agents to programmatically interact with component stories. When Storybook is running, the MCP server is accessible at http://localhost:4400/mcp.

Utilities

Stencil decorators

When building Atomic components, a series of decorators are used to make development faster.

InitializeBindings & BindStateToController decorators

InitializeBindings is a utility that automatically fetches the bindings from the parent atomic-search-interface or atomic-external component. This decorator has to be applied to a property named bindings.

Important In order for a component using this decorator to render properly, it should have an internal state bound to one of the properties from bindings. This is possible by using the BindStateToController decorator along with a State decorator.

Here is a complete example:

import {
  InitializeBindings,
  InitializableComponent,
  BindStateToController,
  Bindings,
} from '@coveo/atomic';
import {ControllerState, Controller, buildController} from '@coveo/headless';
import {Component, State} from '@stencil/core';

@Component({
  tag: 'atomic-component',
})
export class AtomicComponent implements InitializableComponent {
  @InitializeBindings() public bindings!: Bindings;
  private controller!: Controller;

  // Automatically subscribes the `controllerState` to the state of the `controller`
  @BindStateToController('controller')
  @State()
  private controllerState!: ControllerState;

  // Method called after bindings are defined, where controllers should be initialized
  public initialize() {
    this.controller = buildController(this.bindings.engine);
  }

  render() {
    return [this.strings.value(), this.controllerState.value];
  }
}

ResultContext decorator

ResultContext is a utility that automatically fetches the result from the parent component's rendered atomic-result. This utility is used inside of custom result template components.

import {ResultContext} from '@coveo/atomic';
import {Component, State} from '@stencil/core';

@Component({
  tag: 'atomic-result-component',
})
export class AtomicResultComponent {
  @ResultContext() private result!: Result;

  @State() public error!: Error;

  public render() {
    return this.result.title;
  }
}

Generate Component Command

To generate a new component, use the following command:

pnpm turbo generate-component --filter=@coveo/atomic -- --name=<component-name> --output=<path-to-output-directory>

The output argument is optional. If not provided, it will default to src/components/commerce.

For example, to generate a component named atomic-ball, run:

pnpm turbo generate-component --filter=@coveo/atomic -- --name=ball

This will create the necessary component files under the default path src/components/commerce/atomic-ball.

If you'd like to specify a different path, you can use the --output flag. For example, to generate the component under src/components/search, run:

pnpm turbo generate-component --filter=@coveo/atomic -- --name=ball --output=src/components/search

You can also use --name=atomic-ball if you'd like, but the script will automatically add the "atomic" prefix if necessary.

This will create the component in the specified directory (src/components/search/atomic-ball in this case), or use the default src/components/commerce/atomic-ball if no output is provided.

版本与发布记录

@coveo/atomic 共发布 4,981 个版本,首次发布于 2020/07/23;过去 12 个月发布了 65 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
3.65.0latest2026/11/038 天前
3.64.12026/10/2714 天前
3.64.02026/10/2022 天前
3.63.02026/10/1428 天前
3.62.02026/10/061 个月前
3.61.52026/09/301 个月前

其他发布通道:v2-latest → 2.79.3。

关于 @coveo/atomic 的常见问题

@coveo/atomic 是什么?

A web-component library for building modern UIs interfacing with the Coveo platform

如何安装 @coveo/atomic?

在项目目录运行 npm install @coveo/atomic,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@coveo/bueno(^1.1.9)、@coveo/headless(^3.58.1)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@coveo/atomic 支持 TypeScript 吗?

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

@coveo/atomic 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@coveo/atomic 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js ^20.9.0 || ^22.11.0 || ^24.11.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@coveo/atomic 可以商用吗?

@coveo/atomic 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@coveo/atomic 的下载量有多少?

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

@coveo/atomic 还在维护吗?

最新版本 3.65.0 发布于 2026/11/03(8 天前);至今共发布 4981 个版本,其中过去 12 个月发布了 65 个;首次发布于 2020/07/23。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。