Dynamic Appearance Customization

Edit in →

Survey Creator allows users to dynamically customize the colors and sizes of its UI elements. These customizations can be saved as a theme and reapplied on subsequent visits. Survey Creator comes with four predefined themes to kick-start the customization process: Light, Dark, Contrast, and Survey Creator 2020. By default, this demo uses the Contrast theme. You can choose a different theme, adjust colors and sizes, and click "Persist the UI theme" to save your customizations. The theme will be stored in the browser's localStorage and automatically restored when you reload the page.

Add Predefined Themes to Survey Creator

By default, users can customize only the Light theme. To make other predefined themes available for customization, import an object with predefined theme configurations or reference a script with it and pass the object to the static registerCreatorTheme() method:

Modular applications

import SurveyCreatorTheme from "survey-creator-core/themes";
import { registerCreatorTheme } from "survey-creator-core";

registerCreatorTheme(SurveyCreatorTheme);

Classic script applications

<head>
    <!-- ... -->
    <script src="https://unpkg.com/survey-creator-core/themes/index.min.js"></script>
    <!-- ... -->
</head>
<body>
    <script>
        SurveyCreatorCore.registerCreatorTheme(SurveyCreatorTheme);
    </script>
</body>

If you want to add only specific predefined themes, use the following code:

Modular applications

import {
    SC2020,
    DefaultDark,
    DefaultContrast
} from "survey-creator-core/themes";
import { registerCreatorTheme } from "survey-creator-core";

registerCreatorTheme(SC2020, DefaultDark, DefaultContrast);

Classic script applications

<head>
    <!-- ... -->
    <script src="https://unpkg.com/survey-creator-core/themes/sc2020.min.js"></script>
    <script src="https://unpkg.com/survey-creator-core/themes/default-dark.min.js"></script>
    <script src="https://unpkg.com/survey-creator-core/themes/default-contrast.min.js"></script>
    <!-- ... -->
</head>
<body>
    <script>
        SurveyCreatorCore.registerCreatorTheme(
            SurveyCreatorTheme.SC2020,
            SurveyCreatorTheme.DefaultDark,
            SurveyCreatorTheme.DefaultContrast
        );
    </script>
</body>

Apply a Predefined Theme in Code

The Light theme is applied with the survey-creator-core.css style sheet. All other themes are defined as JSON objects that contain a unique theme identifier and a nested object with CSS variables that override the corresponding variables in the Light theme. To apply the Dark, Contrast, or Survey Creator 2020 theme, import or reference it and pass the theme JSON object to the applyCreatorTheme(theme) method on a SurveyCreatorModel instance:

Modular applications

// Option 1: Import an individual theme
import { SC2020 } from "survey-creator-core/themes";
// import { DefaultDark } from "survey-creator-core/themes";
// import { DefaultContrast } from "survey-creator-core/themes";

const creatorOptions = { /* ... */ };
const creator = new SurveyCreatorModel(creatorOptions);
creator.applyCreatorTheme(SC2020);
// Option 2: Import all themes
import SurveyCreatorTheme from "survey-creator-core/themes";

const creatorOptions = { /* ... */ };
const creator = new SurveyCreatorModel(creatorOptions);
creator.applyCreatorTheme(SurveyCreatorTheme.SC2020);
// creator.applyCreatorTheme(SurveyCreatorTheme.DefaultDark);
// creator.applyCreatorTheme(SurveyCreatorTheme.DefaultContrast);

Classic script applications

<head>
    <!-- ... -->
    <!-- Option 1: Reference an individual theme -->
    <script src="https://unpkg.com/survey-creator-core/themes/sc2020.min.js"></script>
    <!-- <script src="https://unpkg.com/survey-creator-core/themes/default-dark.min.js"></script> -->
    <!-- <script src="https://unpkg.com/survey-creator-core/themes/default-contrast.min.js"></script> -->

    <!-- Option 2: Reference all themes -->
    <script src="https://unpkg.com/survey-creator-core/themes/index.min.js"></script>
    <!-- ... -->
</head>
<body>
    <script>
        const creatorOptions = { /* ... */ };
        const creator = new SurveyCreatorModel(creatorOptions);
        creator.applyCreatorTheme(SurveyCreatorTheme.SC2020);
        // creator.applyCreatorTheme(SurveyCreatorTheme.DefaultDark);
        // creator.applyCreatorTheme(SurveyCreatorTheme.DefaultContrast);
    </script>
</body>

Save and Restore User-Made Customizations

You can save theme customizations made by a user in the browser's localStorage and restore them next time the user opens Survey Creator. To access the theme JSON object, use the SurveyCreatorModel's creatorTheme property. Convert this object to string and save the result to the localStorage.

In this demo, a custom theme is saved when users click the "Persist the UI theme" toolbar button. To configure it, define an IAction object and pass it to the Action constructor. Refer to the Code tab for a code listing.

As an alternative, a custom theme can be saved automatically when a user changes it. To implement this functionality, handle the onCreatorThemePropertyChanged event as follows:

creator.onCreatorThemePropertyChanged.add(() => {
    const themeStr = JSON.stringify(creator.creatorTheme);
    localStorage.setItem(localStorageKey, themeStr);
});

Disable Theme Customization

If you want to disable the ability for users to customize the Survey Creator UI, set the showCreatorThemeSettings property to false:

// Option 1: Disable theme customization before instantiating Survey Creator
const creatorOptions = {
    // ...
    showCreatorThemeSettings: false
}
const creator = new SurveyCreatorModel(creatorOptions);

// Option 2: Disable theme customization at runtime
creator.showCreatorThemeSettings = false;

Your cookie settings

We use cookies on our site to make your browsing experience more convenient and personal. In some cases, they are essential to making the site work properly. By clicking "Accept All", you consent to the use of all cookies in accordance with our Terms of Use & Privacy Statement. However, you may visit "Cookie settings" to provide a controlled consent.

Your renewal subscription expires soon.

Since the license is perpetual, you will still have permanent access to the product versions released within the first 12 month of the original purchase date.

If you wish to continue receiving technical support from our Help Desk specialists and maintain access to the latest product updates, make sure to renew your subscription by clicking the "Renew" button below.

Your renewal subscription has expired.

Since the license is perpetual, you will still have permanent access to the product versions released within the first 12 month of the original purchase date.

If you wish to continue receiving technical support from our Help Desk specialists and maintain access to the latest product updates, make sure to renew your subscription by clicking the "Renew" button below.