Configuring the Colour Picker

View as Markdown

Summary

  • AdapTable provides its own Colour Picker component used when choosing colours for AdapTable Styles
  • The Colour Picker contains 2 tabs:
    • Custom - allows users to choose any colour via a picker
    • Palette - offers active theme's palette (--ab-color-palette-*) and its key theme colours
  • Colour Picker is very configurable, including setting which colours are displayed in Palette tab
  • Theme colours come from Customising Themes — tune palette slots in DevTools — Theme Builder or CSS

Topics on this Page

TopicSummary
Palette tabTheme vs palette swatches
colourPickerOptionsTabs, filter, ordering
DemosFilter and restrict colours

AdapTable provides its own Colour Picker component.

It's used when users need to select colours when creating an Adaptable Style (e.g. styling a Format Column).

Colour Picker Contents

The Colour Picker has 2 tabs:

TabContents
PaletteThe colours of the active theme
CustomFree colour picker (with opacity), hex field and (where supported by browser) an eyedropper

Hint

  • The tab last used is shared by every Colour Picker on the page, until the page reloads
  • So a user who works from the palette does not have to switch to it in every picker

Palette Tab

The Palette tab displays a series of colours as swatches.

These colours come from 2 sources (both of which are CSS variables):

Colour SetExamples
Themevar(--ab-color-accent), var(--ab-color-success)
Palette--ab-color-palette-1 upwards, 32 by default

Note

  • By default the Palette colours are merged, and then ordered using the colour wheel, and duplicates are filtered out
  • However all of this is configurable - see below

A colour picked from the Palette tab is stored as its CSS variable (e.g. var(--ab-color-palette-3)).

This means that it follows the light / dark theme and any override of that variable.

Theme Colours

By default the Colour Picker will show these 15 theme colours in the Palette tab:

ColourLabelLight ThemeDark Theme
--ab-color-accentAccent(#07c)(#07c)
--ab-color-successSuccess(#419641)(#419641)
--ab-color-infoInfo(#17a2b8)(#17a2b8)
--ab-color-warnWarning(#eb9316)(#eb9316)
--ab-color-destructiveDestructive(#dc3545)(#dc3545)
--ab-color-destructive-foregroundDestructive text(#ffffff)(#ffffff)
--ab-color-action-editEdit action(#17a2b8)(#17a2b8)
--ab-color-action-shareShare action(#eb9316)(#eb9316)
--ab-color-action-deleteDelete action(#dc3545)(#dc3545)
--ab-color-action-cloneClone action(#419641)(#419641)
--ab-color-primaryPrimary(#e9e9e9)(#262d2f)
--ab-color-primary-foregroundPrimary text(#656565)(#e2e2e2)
--ab-color-backgroundBackground(#ffffff)(#474c52)
--ab-color-mutedMuted(#f5f5f5)(#3d3e3f)
--ab-color-muted-foregroundMuted text(#656565)(#e2e2e2)

Note

  • Surface colours change between the light and dark themes; the others keep the same default in both
  • Muted follows --ab-color-primarylight, and Muted text follows --ab-color-primary-foreground

Colour Palette Colours

The Colour Palette contains 32 colours - all defined in CSS Variables.

The first 12 palette colours are theme-aware slots for muted cell highlights:

ColourTypical UseLight ThemeDark Theme
--ab-color-palette-1Error / breach highlight(#fde8e8)(#5c1a1a)
--ab-color-palette-2Error / breach highlight(#9b2c2c)(#ffb4b4)
--ab-color-palette-3Warning / pending highlight(#fff8e1)(#4a3b00)
--ab-color-palette-4Warning / pending highlight(#975a16)(#ffd966)
--ab-color-palette-5Success / booked highlight(#e6f4ea)(#1b4332)
--ab-color-palette-6Success / booked highlight(#276749)(#95d5b2)
--ab-color-palette-7Informational highlight(#e6f2ff)(#1a365d)
--ab-color-palette-8Informational highlight(#2b6cb0)(#90cdf4)
--ab-color-palette-9Neutral / inactive highlight(#edf2f7)(#2d3748)
--ab-color-palette-10Neutral / inactive highlight(#4a5568)(#e2e8f0)
--ab-color-palette-11Accent / stage highlight(#f3e8ff)(#44337a)
--ab-color-palette-12Accent / stage highlight(#553c9a)(#d6bcfa)

Note

  • These can be categorised into 6 pairs with background and matching foreground
  • They are used for error, warn, success, info, neutral, and accent respectively

The next 20 Colour Palette colours are plain, the same in light and dark themes:

VariableDefaultVariableDefault
--ab-color-palette-13(#000000)--ab-color-palette-23(#00008B)
--ab-color-palette-14(#FFFFFF)--ab-color-palette-24(#0000FF)
--ab-color-palette-15(#D3D3D3)--ab-color-palette-25(#87CEFA)
--ab-color-palette-16(#808080)--ab-color-palette-26(#00FFFF)
--ab-color-palette-17(#A52A2A)--ab-color-palette-27(#FF00FF)
--ab-color-palette-18(#006400)--ab-color-palette-28(#800080)
--ab-color-palette-19(#008000)--ab-color-palette-29(#8B0000)
--ab-color-palette-20(#32CD32)--ab-color-palette-30(#FF0000)
--ab-color-palette-21(#FFFF00)--ab-color-palette-31(#DC143C)
--ab-color-palette-22(#FFFFE0)--ab-color-palette-32(#FFA500)

Note

  • Palette variables only feed the Colour Picker
  • The colours AdapTable applies on its own (e.g. Flashing Cells, Quick Search) have their own Module Colours

Find Out More

Customising Colour Picker

The Colour Picker is very configurable - options include:

  • Setting Palette Colors — replace the palette colours, or add colours after --ab-color-palette-32
  • Configuring Tabs — choose the Custom and Palette tabs, and the order they appear
  • Filtering Colours — choose which theme colours and palette colours the Palette tab shows
  • Configuring Colour Palette Tab — order the colours, remove duplicates, display labels

Caution

  • Most configuration is done using properties in the colourPickerOptions object in User Interface Options
  • However setting the intitial colours is done in the Theme itself using CSS variables

Setting Palette Colors

You can customise the Palette by overriding CSS variables on the shipped light and/or dark themes.

For example, to replace the first seven palette colours in dark mode:

html.ab--theme-dark {
  --ab-color-palette-1: #660033;
  --ab-color-palette-2: #ccffff;
  --ab-color-palette-3: #ffccff;
  --ab-color-palette-4: #b2ff66;
  --ab-color-palette-5: #ff3333;
  --ab-color-palette-6: #ffffff;
  --ab-color-palette-7: #0000ff;
}

Hint

  • The Colour Picker offers every palette colour from --ab-color-palette-1 upwards until one is not defined
  • So a theme can also add colours after --ab-color-palette-32if required

You can also override the theme colours the same way — see Customising Themes and Referencing Themes.

Setting Palette Colours in CSS
Fork
  • styles.css replaces the first 7 palette colours on the dark theme
  • It also defines --ab-color-palette-33 and --ab-color-palette-34, so the Colour Picker offers two colours after the default 32
  • The grid uses the dark theme, and the Colour Picker shows the Palette tab
Try It Out
  • Create a new Format Column; in the Style section click a colour to open the Colour Picker
  • The replaced colours and the two added colours (deep pink and gold) are in the palette
Loading demo…

Managing Tabs

AdapTable allows you to set which tabs the Colour Picker shows, and in which order.

This is done using the tabs property in colourPickerOptions section of User Interface Options.

tabs

Default: ['Custom', 'Palette']

ColourPickerTab[]

Which tabs the Colour Picker shows, and in which order

Configuring Palette Tab

There are 3 properties available that allow you configure the look and feel of the Palette Tab

  • orderPaletteColours - orders the colours using a colour-wheel order
  • removeDuplicates - ensures that each colour only appears once
  • showGroupLabels - show Theme and Palette headings

Hint

There is also an option to set which colours are displayed - see below for details

orderPaletteColours

Default: true
boolean
Orders the colours using a colour-wheel order

removeDuplicates

Default: true
boolean
Ensures that each colour only appears once

showGroupLabels

Default: false
boolean
Shows Theme and Palette headings
Palette Tab Order, Duplicates and Labels
Fork
  • orderPaletteColours is false, so swatches stay in the order the theme lists them
  • removeDuplicates is false, so colours that paint the same hex both appear (for example Info and Edit action)
  • showGroupLabels is true, so the Palette tab shows Theme and Palette headings
Try It Out
  • Create a new Format Column; in the Style section click a colour to open the Colour Picker
  • Compare the Theme group with the default colour-wheel order, and note the repeated swatches
Loading demo…

Filtering Colours

By default the 15 theme colours and all 32 colour palette variables are displayed in the Colour Palette tab.

However sometimes a developer might want to restrict which colours are displayed, or change the order.

This can be done using the filterColours property.

filterColours

(context: ColourPickerFilterContext) => ColourPickerFilterResult | void

Chooses which colours the Palette tab shows
Filtering the Palette Tab
Fork
  • filterColours returns no theme colours and only the first 7 palette colours
  • Anything else in the lists passed to the function is left out
  • The Colour Picker shows the Palette tab
Try It Out
  • Create a new Format Column; in the Style section click a colour to open the Colour Picker
  • Only palette colours 1 to 7 are offered
Loading demo…

FAQ

Palette vs Custom tab?

  • Palette stores var(--ab-color-…) so colours follow the active theme
  • Custom picks any colour (often stored as hex/rgba)

Picker vs theme CSS?

  • colourPickerOptions controls the picker UI
  • changing swatches users see still means overriding --ab-color-palette-* in theme CSS