@coveo/atomic
TypeScript icon, indicating that this package has built-in type declarations

2.58.1 • Public • Published

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.

Getting Started

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

To start the project in development mode, run:

npm run dev

To build the library for production, run:

npm run build

To run the unit tests for the components, run:

npm test

Run Cypress for Atomic components

Ref: https://docs.cypress.io/

  • All the tests will need to be under folder cypress\integration

Open

To open cypress, run:

npm run e2e:watch

To run all the test, run:

npm run e2e

To run all the test in Firefox:

npm run e2e:firefox

Separate test for Hosted Search Page

To test the current Atomic build against the hosted search pages for Trials, use the following commands:

npm run e2e:hsp:watch
npm run e2e:hsp
npm run e2e:hsp:firefox

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;
  }
}

Readme

Keywords

none

Package Sidebar

Install

npm i @coveo/atomic

Weekly Downloads

27,982

Version

2.58.1

License

Apache-2.0

Unpacked Size

50.8 MB

Total Files

3972

Last publish

Collaborators

  • ndescoteaux-coveo
  • sallain
  • aboissinot
  • mmitiche
  • jkatofsky
  • agong-coveo
  • pixhel
  • ndlr
  • npmcoveo
  • camarois
  • lcoolen
  • coveo-organization
  • coveoit
  • olamothe
  • sssayegh
  • ylakhdar