WebChat Theming

By default, the webchat has a light and a dark theme. The colors used in these themes can be altered and new themes can be added as needed.

 

Customizing themes

In the Configuration.templates.colors object a new color theme can be set. This should be a JavaScript array of Theme objects. A theme object looks as follows:

Copy
Script
interface Theme {
    themeName: string;
    textColor?: string;
    textColorLight?: string;
    iconColor?: string;
    backgroundColor?: string;
    borderColor?: string;
    primaryColor?: string;
    hoverColor?: string;
}

Each of these themes should have a themeName, which is unique. When light or dark is used as a name, the theme will take the default light or dark theme and replace the colors in it with those provided in the theme. When a new name is used, the colors from the light theme are used combined with the new theme. These themes can be used to switch to using the toggleStyle command (see the next chapter: “Switching themes”).

 

Switching themes

The currently used theme can we changed as follows:

Copy
Script
WebChat.toggleStyle(themeName);

Where themeName is a string and either 'light' or 'dark' when using the default webchat theming, or one of the theme classes added in a custom colors configuration. When only the dark and light theme are used, a theme button will be shown giving the user the ability to switch themes on the fly. In this case the webchat will also automatically switch between the light and dark theme according to the user’s device settings.

 

Browser restrictions

Theming is only supported on browsers that support css variables. For older browsers, like internet explorer, only the first theme in the themes configuration is used. By default this will be the light theme. The theme button will not be visible in these browsers and no automatic theme switching will occur.