Skip to content

CodeCoupler Costa Components 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:

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 { HeaderSidebar } from "@codecoupler/costa-header-sidebar"
import { ComponentInitError, Stage } from "@codecoupler/costa-core";

// Import your stylesheet including special styles for popovers, dropdowns and tooltips
import RootStyles from "./root.module.css";

// 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: HeaderSidebar,
      options: {
        apps: apps,
        auth: auth,
        authStatusVue: {},
        pwa: pwa,
        pwaVue: {},
        swLoader: swLoader,
        swLoaderVue: {}
        launcher: {},
        logoIcon,
        logoBackground,
        classes: {
          statusAuthDropdown: RootStyles.style1,
          statusSwDropdown: RootStyles.style2,
          statusSwPopover: RootStyles.style3,
          launcherTooltip: RootStyles.style4,
          launcherPopover: RootStyles.style5
        }
      }
    })
    .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-

auth: 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.

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.

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.

launcher: Object

Configuration options for the launcher component loaded into the sidebar stage. You can find all the configuration options for this component here: Launcher

You should not set the following options as they will be set automatically: registry, identity, popoverClasses, tooltipClasses.

Hint: You can also control the debugging property debug via the URL. To keep all tooltips and popovers open, add the hash #debug-launcher to your URL.

logoIcon and logoBackground

These images will be used as background and in the header section.

classes

With the option classes you have the possibility to set classnames for elements that will be rendered into the body:

  • statusAuthDropdown: Dropdown of the authentication status component (See Auth Status Vue).
  • statusSwDropdown: Dropdown of the service worker status component (See Service Worker Loader Vue).
  • statusSwPopover: Popover of the service worker status component (See Service Worker Loader Vue).
  • launcherTooltip: Tooltips of the launcher component (See Launcher).
  • launcherPopover: Popvers of the launcher component (See Launcher).

Styling

Every stage where a component is loaded (all except header), the component has the class component:

& .component {}

All stages also use their id as class name.

Stage "wco-header":

1
2
3
4
5
6
& .wco-header {
  & .component {
    & img {}
    & span {}
  }
}

Stage "logo":

1
2
3
4
5
& .logo {
  & .component {
    & img {}
  }
}

Stage "sidebar"

& .sidebar {
  & .component {
    &.collapsed ul li a .name {}
    &.expanded ul li a .name {}
    &.empty .toggler-collapse,
    &.empty .toggler-expand {}
    &.filled .toggler-collapse,
    &.filled .toggler-expand {}
    & ul {
      & li.restricted {}
      & li {
        & a {
          & .name {}
          & .icon {
            & svg {}
          }
        }
      }
    }
    & .toggler-collapse,
    & .toggler-expand {
      & svg {}
    }
  }
}

The background layer of the main stage has the class background:

1
2
3
4
5
6
7
8
& .main {
  & .background {
    & .component {
      & img {
      }
    }
  }
}

Stages with status buttons also have the general class status-button:

1
2
3
4
5
6
7
& .status-button {
  & .component {
    & span.icon {
      & svg {}
    }
  }
}

You can select a specific status button stage by adding the identifier: "& .status-button.identifier {}". Possible identifiers:

  • status-sw
  • status-pwa
  • status-auth

You can select a specific icon inside a status button stage by adding the identifier: "& span.icon.identifier {}". Possible identifiers:

  • login
  • loading
  • user
  • error
  • desktop
  • mobile
  • ok
  • update

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. You can configure the component with the option launcher. Read more about this in the description of the launcher option.

The stage will be configured as scrollable:

1
2
3
4
5
6
7
{
  levels: {
    base: {
      scrollable: true
    }
  }
}

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.