Skip to content

IColorPalette

A colour palette is a named set of colours that editors pick from in the admin's colour editor, so they use the brand's colours instead of typing codes. Charts also use a palette to colour their data. Implement IColorPalette in a theme or module to offer your own set.

Interface declaration

	namespace Veva.Core.Domain.Pages;

	public interface IColorPalette
	{
		string Description { get; }

		int OrderIndex { get; }

		IEnumerable<string> Colors(Guid websiteId);
	}

Example

This palette offers a theme's brand colours. It sorts before Veva's default chart colours, so the colour editor opens on it.

	using Veva.Core.Domain.Pages;

	public class BrandColorPalette : IColorPalette
	{
		public string Description => "The brand colours of this theme";

		// Lower comes first in the colour editor.
		public int OrderIndex => 0;

		public IEnumerable<string> Colors(Guid websiteId)
		{
			// Hex codes: the colour editor stores them with an alpha channel added.
			return ["#0B3D91", "#1A73E8", "#34A853", "#FBBC04", "#EA4335", "#202124"];
		}
	}

Registration

This is how the implementation is registered into the DI container in Veva, this should be done in your module config file (The class which implements IModule).

	using Veva.Core.Application.DependencyInjection;
	using Veva.Core.Domain.Pages;

	public void ConfigureServices(IServiceCollection services, IConfiguration configuration)
	{
		// The key is the class name; the colour editor shows it as the palette's title.
		services.AddNamed<IColorPalette, BrandColorPalette>();
	}

Where it shows. The admin's colour editor, used for colour properties of components, modifiers and settings, lists every registered palette. Each palette is a panel with its registration name as the title, its Description under it, and a swatch for each colour. Clicking a swatch sets the colour. Palettes are sorted by OrderIndex, lowest first, and the first one is open. The editor can still pick a custom colour, unless the property does not allow it. With no palettes registered, the colour editor goes straight to the colour picker.

No Name member. The interface has no Name: the title is the name passed to AddNamed, or the class name when you pass none. Older palettes, such as Default chart colors in the Veva.Modules.ChartJS package, still declare a Name property, but Veva does not read it.

Colours. Return colours as hex codes, #RRGGBB or #RRGGBBAA. The colour editor adds an FF alpha channel to a code of seven characters or fewer, so a CSS colour name or an rgb() value would be stored broken. websiteId is the website the editor works on, so a palette can return different colours per website, for example from the website's settings.

Charts. The pie, bar and line charts in the Veva.Modules.ChartJS package have a Color palette setting that picks one palette by name. The chart passes it to its data source in ChartDataSourceContext.ColorPalette, and the data source gives each value the next colour. That package registers Default chart colors, with an OrderIndex of 100.

Turning it on. Register the palette with AddNamed; there is no website setting. A theme usually registers its own, so editors have its colours at hand. Colors is called each time a colour editor opens and for every chart render, so return a fixed list or one you keep, not the result of a slow call.

Type to search the docs, components and API.

↑↓ to move ↵ to open Esc to close Search by Veva