Skip to content

CodeCoupler Components Costara Header & Sidebar

This component is ideal for use as a root application component. It creates a Flexbox-based layout with a sidebar and header. The layout is suitable for both PWA applications and applications that require authentication.

The following stages (id's and classnames) are provided:

Costara Header & Sidebar Overview

Get Started

Here is an example of how this component could be loaded into the root stage and which properties of the Start Definition Object should be set:

import { CostaraHeaderSidebar } from "@codecoupler/costara-header-sidebar"
import { ComponentInitError, Stage } from "@codecoupler/costa-core";

// Import your background banner image and your logo
import logoIcon from "./images/logo-icon.png";
import logoBackground from "./images/logo-banner.png";

// Define your applications as a component registry configuration that will be used in the sidebar:
import Example from "./example-app";
let apps = {
  "example-app": {
    id: "example-app",
    component: Example
  }
};

// If you want to load a service worker you should use a ServiceWorkerLoader instance and handle 
// some specific cases:
import { ServiceWorkerLoader } from "@codecoupler-pro/app-service-worker";
import { Interceptors } from "@codecoupler/costa-core";
let swLoader = new ServiceWorkerLoader({
  serviceWorkerUrl: "/sw.js"
});
// Handle after update
let url = new URL(window.location);
if (url.hash === "#sw-update") {
  window.history.replaceState({}, document.title, "/");
}
// Handle after forced update
if (url.hash === "#sw-update-forced") {
  Interceptors.register("sw-update-forced", () => new Promise(() => true));
  if (auth) auth.loginReload();
}

// If you want to use PWA features use a PWA instance:
import { PWA } from "@codecoupler-pro/app-pwa";
let pwa = new PWA();

// If you want to use authentication define your authentication module:
import { AuthMockup } from "@codecoupler/auth-bundle";
auth = new AuthMockup();

let startRoot = () => {
  new Stage()
    .load({
      component: CostaraHeaderSidebar,
      options: {
        apps: apps,
        auth: auth,
        authStatusVue: {},
        pwa: pwa,
        pwaVue: {},
        swLoader: swLoader,
        swLoaderVue: {}
        logoIcon,
        logoBackground,
        styles: {
          statusDropdwown:
          statusPopup:
          statusAuthDropdwown:
          statusAuthPopup:
          statusPwaDropdwown:
          statusSwDropdwown:
          launcherTooltip:
          launcherPopup:
        }
      }
    })
    .then((rootComponent) => {
      console.info("Root Component Ready", rootComponent.id);
    })
    .catch((e) => {
      if (e instanceof ComponentInitError) {
        console.info("Error was thrown from component", e.component.id);
      }
      console.error(e);
    });
};

// Smart replacement for `window.addEventListener("load", callback)`
// See: https://stackoverflow.com/q/13364613 and https://stackoverflow.com/a/53525488
if (performance.getEntriesByType("navigation").every((e) => e.loadEventEnd))
  startRoot();
else window.addEventListener("load", startRoot);

Options

apps: Object

Applications registry of the root component and used by the sidebar. The @codecoupler/launcher component is loaded into the stage sidebar which will display n application start menu-

swLoader: ServiceWorkerLoader and swLoaderVue: Object

To configure the loading of a service worker, use the swLoader option and assign a @codecoupler-pro/app-service-worker instance.

If a service worker is used, the @codecoupler-pro/app-service-worker-vue component is loaded into the stage status-sw and is used to display a button for updating the service worker if needed and display status information. You can find all the configuration options (Vue props) for this component here: Service Worker Loader Vue

All the configuration options described there can be set using the swLoaderVue option, except for the swLoader property, which is set automatically.

Hint: You can also control the debugging property showIcons via the URL. To display all icons regardless of the current service worker status, add the hash #debug-all-icons to your URL.

Hint: You can also control the debugging property swDebugUpdateAvailable via the URL. To simulate an available service worker update, add the hash #debug-sw-update to your URL.

pwa: PWA and pwaVue: Object

To configure the use of PWA features, use the pwa option and assign a @codecoupler-pro/pwa instance.

If PWA features have been enabled, the @codecoupler-pro/app-pwa-vue component is loaded into the stage pwa-status and is used to display a button for installing a PWA. You can find all the configuration options (Vue props) for this component here: PWA Vue

Hint: Handling the installation prompt works only in chromium based browsers!

All the configuration options described there can be set using the pwaVue property, except for the pwa property, which is set automatically.

of the current PWA status and in other than chromium-based browsers add the hash #debug-all-icons to your url.

AuthenticationModule and authStatusVue: Object

Define an authentication module in the option auth that applies to components loaded in the custom header and main stage.

If an authentication module is configured, the @codecoupler/auth-status-vue component is used to display a login/logout button and status information. You can find all the configuration options (Vue props) for this component here: Auth Status Vue

All the configuration options described there can be set using the authStatusVue property, except for the auth property, which is set automatically.

Hint: You can also control the debugging property showIcons via the URL. To display all icons regardless of the current authentication status, add the hash #debug-all-icons to your URL.

Styling

  • All stages also use their id as class name.
  • Stages with status buttons also have the general class status-button
  • The background layer of the main stage has the class background.
  • In all stages where a component is loaded, the component has the class component.

Stages

Stage wco-header

This stage is hidden by default and is displayed only if PWA features are enabled and the site runs as standalone PWA application in windows control overlay mode; it represents the title bar of the PWA application.

It is a simple line of text containing the image from the passed via logoIcon option and the current title from document.title in the form <img ...><span>...</span>.

More details about the classes that will be used to handle this stage: CodeCoupler Application Basics PWA Handling.

Hint: You can display the wco-header regardless of the current PWA mode, add the hash #debug-wco-header to your URL. Note, however, that the height of the header does not correspond to the final result. This is not possible unless the PWA is running in windows control overlay mode, in which case the variable env(titlebar-area-height) cannot be resolved.

Just an img element which loads the image passed via the logoIcon option.

Stage sidebar

The @codecoupler/launcher component is loaded into this stage.

Stage main

We load components into the stage main that do require authentication. If the user is not authenticated or has logged out, these components should be destroyed. However, we make an exception for the background layer.

We load a centered image into the background layer that was passed via logoBackground option.

We will assign a background class to the background layer element to enable more specific styling.

Therefore, we set the following options for the main stage:

{
  start: {
    settings: {
      $auth: {
        module: this.#options.auth,
        restrictions: { required: true },
        controller: AuthControllerDestroy
      }
    }
  },
  levels: {
    background: {
      class: "background",
      start: { settings: { $auth: { restrictions: { required: false } } } }
    }
  }
}

Stage custom-header

We do not load any additional components into the custom-header stage. This stage is intended for custom components. However, components are not destroyed but merely hidden when authentication is not present. For this purpose, we use a special controller that does not block the initialization phase. This means the components can be loaded as early as possible. Therefore, we set the following options:

{
  start: {
    settings: {
      $auth: {
        module: this.#options.auth,
        restrictions: { disabled: true },
        controller: AuthControllerHide
      }
    }
  }
}

Stages status-pwa, status-sw and status-auth

This is where the components described above are loaded. Read more about this in the descriptions of the pwa, swLoader, and auth options.