Skip to content

CodeCoupler Professional UI Boilerplate 🔒

This boilerplate uses the component provided by the @codecoupler/header-sidebar package as its root component. Further details on the structure of this component can be found at Header & Sidebar.

The boilerplate does not load the component directly. Instead, it loads the component src/root.js as the root component. This component is derived from the aforementioned package. This allows you to override and customise all properties and methods in src/root.js to meet your own requirements.

Configuration

The boilerplate provides configuration options in the files src/config.js and static/env.js. Each file exports an object. Within this object, you can define the rootComponent property, which is used for the options of the @codecoupler/header-sidebar component.

1
2
3
4
5
{
  rootComponent: {
    // Put here your root component options
  }
}

Attention! Please read below for more details about the individual options and how to use them in this boilerplate. Some of these can take on other values or are handled differently. In addition, there are other options available to simplify tasks.

Both files are merged and used as the overall configuration. The env.js file has higher priority and can override values from config.js.

Differences between env.js and config.js

The env.js file is loaded at runtime and its contents may vary depending on the environment. It is not included in the final package and will not be pushed into the Git repository. It must be created individually in each deployment environment.

The config.js file, however, is statically compiled into the build output. Unlike the env.js file, the config.js file can use dynamic content, for example by importing and using other modules. The env.js file cannot do this.

This means that all configuration options can be present in both files. However, it is recommended to define the entire configuration in config.js and to use env.js only in deployment environments.

Since the env.js file is not part of either the repository or the deployment package, it is recommended that you save a configuration template in the env.default.js file, if this is important for the deployment. This can then be used as a template to create an env.js file during the initial deployment.

Languages

The boilerplate defines a default token loader that loads the language files at runtime. Language files for each component can be placed in the directory locales according to the following schema:

<namespace (including @char at beginning)>.<language code>.js

The default language code will be set according to the user's browser settings. Only the primary subtag (e.g. "en", "de") will be used.

Also note that the default language code for the Costa Framework is "en". This code is used if no matching language file is found. Therefore, it is advisable to provide at least one language file with the language code "en".

The files must export the object with the tokens that you will use:

1
2
3
export default {
  "any-message-token": "This is the translated string"
};

In your component you can use language tokens instead of fixed strings:

import { Component } from "@codecoupler/costa-core";

let namespace = "@demo.component";

export default class extends Component {
  // Define here the supported languages:
  static defaults = {
    $i18n: {
      [namespace]: {
        languages: ["en", "de"]
      }
    }
  };

  // Use this helper to make your code shorter:
  #i18n(token, language = undefined) {
    return this.i18n(token, namespace, language);
  }

  // Use this pattern whenever you need a translated string:
  async start() {
    console.info(this.#i18n("any-message-token"));
  }
}

Configuration Reference

swLoader (Service Worker)

The boilerplate includes a service worker that handles OIDC authentication, among other things.

Instead of specifying a ServiceWorkerLoader instance using the swLoader option, you can simply set the option to true. The boilerplate then takes care of all aspects of the service worker.

Warning! If you use your own ServiceWorkerLoader instance, the boilerplate code does not handle any special actions following a service worker update, and the oidc authentication module template cannot be used.

You can also specify a path to the boilerplate's Service Worker in swLoader if it differs from the default path (/sw.js).

pwa (PWA Features)

To enable all PWA features, simply set the pwa option to true instead of a PWA instance.

auth and authTemplate (Authentication Modules)

Instead of defining an authentication module for the auth option yourself, you can use the additional authTemplate option in your component configuration to take advantage of predefined templates. These templates not only create an authentication module but also perform all the necessary steps required for that module.

Attention! If both options are defined, the authTemplate option takes precedence!

The boilerplate contains the following authentication module templates from which you can choose:

OIDC:

{
  authTemplate: {
    // You must set this to "oidc"
    type: "oidc",
    // Set here the URL to the authority server
    authority: "https://demo.duendesoftware.com",
    // Set client ID and scope you request
    client_id: "interactive.public",
    scope: "openid offline_access profile email"
  }
};

You can use any other properties here that the @codecoupler-pro/auth-oidc module accepts.

Read more about the OIDC Module here: OIDC

Here an example for Keycloak including the roles in the ID token:

1
2
3
4
5
6
7
8
{
  authTemplate: {
    type: "oidc",
    authority: "https://keycloak-server/realms/your-realm-name",
    client_id: "your-client-id",
    scope: "openid offline_access profile email roles"
  }
};

Mockup:

{
  authTemplate: {
    // You must set this to "mockup"
    type: "mockup",
    // Set here all or some properties of your dummy user (optional)
    // Here an example:
    identity: { username: "admin", roles: ["example"] },
    // Set this to true if you want to be initially logedin
    authenticated: false
    // Set this to true or to a string (representing the error message) to throw an error on initializing
    // errorInit: true
    // Set here the delay before init in milliseconds
    // delayInit: 5000
  }
};

You can use any other properties here that the @codecoupler/auth-mockup module accepts.

Read more about the Mockup Module here: Mockup

apps (Applications)

You cannot define components to be used by the sidebar launcher using the apps option. Instead, you can define them as follows:

  1. Put the components into the local subfolder src/apps. Create a subdirectory with the component id and put there an index.js file which will be loaded as an component. Because the directory name will be used as id, the component will not be started multiple times.
  2. Override defaults or define additional components in src/apps/static.config.js.

classes (Styling)

The option classes will be automatically set. The boilerplate includes a pre-built CSS file styles/root.module.css that covers all aspects and options for styling.