Back to Website
Show / Hide Table of Contents

Creating toggle sets

  • Last updated on June 25, 2025
  • •
  • 5 minutes to read

This article describes how you can define toggle sets to enable switching the style of design elements or changing text strings. Toggle sets are defined in the JSON format, and you can create and edit them in the Customer's Canvas JSON editor or in any other editor that supports JSON validation and subsequent import.

Toggle set format

The JSON representation of a toggle set contains the following fields:

{
    "id": "some-unique-string",
    "name": "Human readable toggle set name",
    "toggles": [
        {
            "id": "unique-string-for-toggle",
            "name": "Human readable toggle name",
            "selector": ".classname",
            "colorParams | fontParams | textParams": { ... }
        }
    ]
}

The id property is used within the editor to reference the toggle programmatically. The toggle name will be displayed in the user interface and can be, for example, Primary Color or Add plaid mark. A selector describes which design elements the toggle will affect.

The toggles array contains descriptions of different types of toggles. Each toggle has a unified structure, but depending on its type, they have different parameters specified by:

  • colorParams for color toggles
  • fontParams for font style toggles
  • textParams for text toggles

Selectors

The selector syntax can resemble a very simplified version of CSS. It allows referencing elements in three ways:

  • By specifying the name of a specific element.
  • By specifying a unique ID preceded by the # sign.
  • By specifying the class name prefixed with a period (.).

Let's consider the following design.

Design Example

If we want to refer to the element Event, we can use the selectors:

  1. Event
  2. #d9564396-4800-4d0e-a116-0685c881d10e
  3. .main-text-color

Multiple selectors can be combined by separating them with a space. In this case, the selection will include all elements that match at least one selector. For example, to select the Title and Event fields in the image above, you can use "#d9564396-4800-4d0e-a116-0685c881d10e Title" or "Event Title", etc.

Warning

To specify design element names in the selectors, avoid using names with spaces.

In practice, it is preferable to use classes, reusing the same classes across all your design. This allows using the same toggle set with different designs.

Types of toggles

Now let's look at the different types of toggles and their parameters.

Color toggle

This toggle allows selecting the color of elements from a list. It supports the following arguments:

  • items: An array of color samples.

Color samples are described by the following structure:

{
    "label": "Dodger Blue",
    "previewColor": "rgb(0, 144, 255)",
    "value": {
        "fillColor": "cmyk(100%, 44%, 0%, 0%)",
        "strokeColor": "cmyk(100%, 44%, 0%, 0%)",
        "color": "cmyk(100%, 44%, 0%, 0%)"
    }
}

The label specifies a human-readable name for the color, which may be displayed in the user interface. The previewColor property sets the color visible in the interface. Use the format rgb(0, 144, 255) for this property. The value object contains several color values applied to different types of elements: fillColor and strokeColor for shapes, and color for text color. If you do not want to change a property, just omit it. Values are also specified in string representation, according to the format described in the editor API documentation: Defining colors.

Example:

Color toggle

{
    "id": "some-unique-string",
    "name": "Human readable toggle set name",
    "toggles": [
        {
            "id": "main-text-color",
            "name": "Primary color",
            "selector": ".main-text-color Title Event",            
            "colorParams": {
                "items": [
                    {
                        "label": "Green",
                        "previewColor": "rgb(0,100,0)",
                        "value": {
                            "color": "cmyk(100%,0%,100%,50%, 1.0)",
                            "fillColor": "cmyk(100%,0%,100%,50%, 1.0)"
                        }
                    },
                    {
                        "label": "Brown",
                        "previewColor": "rgb(60,40,20)",
                        "value": {
                            "color": "cmyk(0%,33%,67%,76%, 1.0)",
                            "fillColor": "cmyk(0%,33%,67%,76%, 1.0)"
                        }
                    }
                ]
            }
        }
    ]
}

When you don't specify all color properties, make sure each color sample has the same properties defined. If you don't, you might run into issues where only some properties update when switching toggle values. For example, the following definition would be incorrect:

[
    {
        "label": "Green",
        "previewColor": "rgb(0,100,0)",
        "value": {
            "color": "cmyk(100%,0%,100%,50%, 1.0)"
        }
    },
    {
        "label": "Brown",
        "previewColor": "rgb(60,40,20)",
        "value": {
            "color": "cmyk(0%,33%,67%,76%, 1.0)",
            "fillColor": "cmyk(0%,33%,67%,76%, 1.0)"
        }
    }
]

Font toggle

The font style toggle works like the color toggle but modifies only the font and other style properties. It accepts these arguments:

  • items: An array of style descriptions.

Each style description looks like this:

{
    "label": "Classic Style",
    "value": {
        "postscriptName": "ArialMT",
        "size": 16,
        "underline": false,
        "fauxBold": true,
        "letterSpacing": 100,
        "fontCaseRule": "uppercase"
    }
}

The "fontCaseRule" supports the "uppercase", "lowercase", and "original" values.

You can omit any style properties to keep them unchanged. However, it's recommended to use the same set of properties for all values within the same toggle.

Example:

Font toggle

{
    "id": "some-unique-string",
    "name": "Human readable Toggle Set name",
    "toggles": [
        {
            "id": "main-font-style",
            "name": "Main font",
            "selector": ".main-style",
            "fontParams": {
                "items": [
                    {
                        "label": "Comic",
                        "value": {
                            "postscriptName": "ComicSansMS"
                        }
                    },
                    {
                        "label": "Monserrat",
                        "value": {
                            "postscriptName": "Montserrat-Bold"
                        }
                    }
                ]
            }
        }
    ]
}

Text toggle

This toggle allows changing the content of a text element either from a list or by entering custom text. It supports the following parameters:

  • allowCustom: If true, allows entering custom text. If false, restricts input to the list, which is the default behavior.
  • items: A list of text strings.

Each text value description looks like this:

{
    "label": "Roman greeting",
    "value": {
        "value": "Ave, Caesar!"
    }
}

The text can use markup in Graphics Mill format, as described in the Advanced Formatted Text article.

{
    "label": "Roman greeting",
    "value": {
        "value": "<p><span>Ave, </span><span style='bold:true'>Caesar!</span></p>"
    }
}
Note

For special characters, you can use their escaped versions:

  • < - \u003c
  • > - \u003e
  • & - \u0026
  • " - \u0022

Example:

Text toggle

{
   "id": "some-unique-string",
   "name": "Human readable toggle set name",
   "toggles": [
       {
            "id": "event-text",
            "name": "Event name",
            "selector": "Event",
            "textParams": {
                "allowCustom": false,
                "items": [
                    {
                        "label": "Friday",
                        "value": {
                            "value": "Friday:\n Live Music"
                        }
                    },
                    {
                        "label": "Wednesday",
                        "value": {
                            "value": "Wednesday:\n Board Game Night"
                        }
                    },
                    {
                        "label": "Sunday",
                        "value": {
                            "value": "Sunday:\n Outdoor Cinema"
                        }
                    }
                ]
            }
       }
   ]
}
Was this page helpful?
Thanks for your feedback!
Back to top Copyright © 2001–2025 Aurigma, Inc. All rights reserved.
Loading...
    Thank for your vote
    Your opinion is important to us. To provide details, send feedback.
    Send feedback