Developer guide
Developer guide

Build a WE component

Custom UI modules live under working/environment_modules/custom/<module>/. A browser component has a WebComponent/ directory with a JavaScript class and matching HTML template. The class extends WEngineElement; a modal extends WEngineModal. The JavaScript class name must match its filename. Package metadata declares wEngine.hasWebComponent: true, component_name, isActive, and apiVersion.

The compiler reads the source and creates a registered browser wrapper. Do not call customElements.define in the source. npm run build:components is the documented component build command in the application; it writes generated files under working/compiled/components, so run it only when you intend to change the application checkout. The /component route serves those generated files.

Minimal layout

environment_modules/custom/greeting_panel/
  package.json
  index.js
  WebComponent/
    GreetingPanel.js
    GreetingPanel.html
    GreetingPanel.css       # optional

The package's wEngine section can look like this:

{
  "hasWebComponent": true,
  "hasServerPage": false,
  "component_name": "greeting_panel",
  "isActive": true,
  "label": "Greeting Panel",
  "apiVersion": "v1.0"
}

WebComponent/GreetingPanel.js:

import { WEngineElement, apiAttribute } from 'WEngineElement';

class GreetingPanel extends WEngineElement {
  @apiAttribute heading = 'Welcome';

  componentReady() {
    // The host is connected and component logic can start.
  }
}

WebComponent/GreetingPanel.html uses WE's source template naming convention:

<c:greeting_panel>
  <h2>{heading}</h2>
</c:greeting_panel>

The logical custom module name and browser custom element tag both use c:. The browser tag generated from GreetingPanel is <c:greeting-panel>. Existing custom components such as opportunity_path use this form. Other installed packages can provide their own namespace, such as we-crm:. The namespace maps to an environment_modules folder through its module-config.json.

Lifecycle and composition

Use componentReady() for initial component work. Component fields supply template state. Use bindings such as {heading} in the HTML template. Child components can receive values as attributes; for example, <we-input label="Name" field-value="{name}">. Listen to a child's custom events with the template's on<event> form, as existing components do with onstagechange.

For a modal, extend WEngineModal and open it through the class's static open({ props: { ... } }) call. See approval comments modal and the standard component reference. The component authoring contract is implemented by working/core_engines/componentCompiler.js and described in working/docs/component-wrapper.md.

Next: public properties, methods, and template values.