# Configuring the Colour Picker

Canonical page: https://www.adaptabletools.com/docs/ui-tutorial-custom-colour-palette

- 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](https://www.adaptabletools.com/docs/handbook-theming-custom/index.md) — tune palette slots in [DevTools — Theme Builder](https://www.adaptabletools.com/docs/dev-guide-support-devtools-theme-builder/index.md) or CSS

## Topics on this Page

| Topic                                             | Summary                     |
| ------------------------------------------------- | --------------------------- |
| [Palette tab](#palette-tab)                       | Theme vs palette swatches   |
| [colourPickerOptions](#customising-colour-picker) | Tabs, filter, ordering      |
| [Demos](#customising-colour-picker)               | Filter and restrict colours |

[UI Guides](https://www.adaptabletools.com/docs/ui-tutorial-overview/index.md) · [Adaptable Style Object](https://www.adaptabletools.com/docs/ui-tutorial-providing-adaptable-style/index.md).

AdapTable provides its own Colour Picker component.

It's used when users need to select colours when creating an [Adaptable Style](https://www.adaptabletools.com/docs/ui-tutorial-providing-adaptable-style/index.md) (e.g. styling a [Format Column](https://www.adaptabletools.com/docs/handbook-column-formatting/index.md)).

## Colour Picker Contents

The Colour Picker has 2 tabs:

| Tab         | Contents                                                                                    |
| ----------- | ------------------------------------------------------------------------------------------- |
| **Palette** | The colours of the active theme                                                             |
| **Custom**  | Free colour picker (with opacity), hex field and (where supported by browser) an eyedropper |

- 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 Set  | Examples                                            |
| ----------- | --------------------------------------------------- |
| **Theme**   | `var(--ab-color-accent)`, `var(--ab-color-success)` |
| **Palette** | `--ab-color-palette-1` upwards, 32 by default       |

- 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:

| Colour                              | Label            |           Light Theme           |           Dark Theme            |
| ----------------------------------- | ---------------- | :-----------------------------: | :-----------------------------: |
| `--ab-color-accent`                 | Accent           |     |     |
| `--ab-color-success`                | Success          |  |  |
| `--ab-color-info`                   | Info             |  |  |
| `--ab-color-warn`                   | Warning          |  |  |
| `--ab-color-destructive`            | Destructive      |  |  |
| `--ab-color-destructive-foreground` | Destructive text |  |  |
| `--ab-color-action-edit`            | Edit action      |  |  |
| `--ab-color-action-share`           | Share action     |  |  |
| `--ab-color-action-delete`          | Delete action    |  |  |
| `--ab-color-action-clone`           | Clone action     |  |  |
| `--ab-color-primary`                | Primary          |  |  |
| `--ab-color-primary-foreground`     | Primary text     |  |  |
| `--ab-color-background`             | Background       |  |  |
| `--ab-color-muted`                  | Muted            |  |  |
| `--ab-color-muted-foreground`       | Muted text       |  |  |

- 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:

|         Colour          | Typical Use                  |           Light Theme           |           Dark Theme            |
| :---------------------: | ---------------------------- | :-----------------------------: | :-----------------------------: |
| `--ab-color-palette-1`  | Error / breach highlight     |  |  |
| `--ab-color-palette-2`  | Error / breach highlight     |  |  |
| `--ab-color-palette-3`  | Warning / pending highlight  |  |  |
| `--ab-color-palette-4`  | Warning / pending highlight  |  |  |
| `--ab-color-palette-5`  | Success / booked highlight   |  |  |
| `--ab-color-palette-6`  | Success / booked highlight   |  |  |
| `--ab-color-palette-7`  | Informational highlight      |  |  |
| `--ab-color-palette-8`  | Informational highlight      |  |  |
| `--ab-color-palette-9`  | Neutral / inactive highlight |  |  |
| `--ab-color-palette-10` | Neutral / inactive highlight |  |  |
| `--ab-color-palette-11` | Accent / stage highlight     |  |  |
| `--ab-color-palette-12` | Accent / stage highlight     |  |  |

- 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:

|        Variable         |             Default             |        Variable         |             Default             |
| :---------------------: | :-----------------------------: | :---------------------: | :-----------------------------: |
| `--ab-color-palette-13` |  | `--ab-color-palette-23` |  |
| `--ab-color-palette-14` |  | `--ab-color-palette-24` |  |
| `--ab-color-palette-15` |  | `--ab-color-palette-25` |  |
| `--ab-color-palette-16` |  | `--ab-color-palette-26` |  |
| `--ab-color-palette-17` |  | `--ab-color-palette-27` |  |
| `--ab-color-palette-18` |  | `--ab-color-palette-28` |  |
| `--ab-color-palette-19` |  | `--ab-color-palette-29` |  |
| `--ab-color-palette-20` |  | `--ab-color-palette-30` |  |
| `--ab-color-palette-21` |  | `--ab-color-palette-31` |  |
| `--ab-color-palette-22` |  | `--ab-color-palette-32` |  |

- 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](https://www.adaptabletools.com/docs/handbook-theming-custom/index.md#module-colours)

- [Customising Themes](https://www.adaptabletools.com/docs/handbook-theming-custom/index.md) shows how to override theme variables in CSS
- [Referencing Themes](https://www.adaptabletools.com/docs/handbook-theming-referencing/index.md) shows how to use those variables in Format Columns and other Adaptable Styles

## 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

- Most configuration is done using properties in the `colourPickerOptions` object in [User Interface Options](https://www.adaptabletools.com/docs/technical-reference-ui/index.md)
- 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:

```css
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;
}
```

- 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-32`if required

You can also override the theme colours the same way — see [Customising Themes](https://www.adaptabletools.com/docs/handbook-theming-custom/index.md) and [Referencing Themes](https://www.adaptabletools.com/docs/handbook-theming-referencing/index.md).

**Example: Setting Palette Colours in CSS**

Replace palette colours on the dark theme, and add two more

- `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

- 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

Demo project (Vanilla); the files without a marker are shown below:

```text
src/
  adaptableOptions.ts
  agGridModules.ts     [template]
  columnDefs.ts        [template]
  gridOptions.ts       [template]
  index.ts             [template]
  onAdaptableReady.ts  [template]
  rowData.ts           [template]
  styles.css           [template + shown below]
index.html             [template]
package.json           [template]
tsconfig.json          [template]
```

Files marked `[template]` are the same in every demo; see the [demo template](https://www.adaptabletools.com/llms/demo-template.md#vanilla).

**`src/adaptableOptions.ts`**

```ts
import {AdaptableOptions} from '@adaptabletools/adaptable';
import {WebFramework} from './rowData';

export const adaptableOptions: AdaptableOptions<WebFramework> = {
  primaryKey: 'id',
  adaptableId: 'Colour Picker CSS Colours',
  userInterfaceOptions: {
    colourPickerOptions: {
      tabs: ['Palette'],
    },
  },
  initialState: {
    Dashboard: {
      ModuleButtons: ['FormatColumn'],
    },
    StatusBar: {
      StatusBars: [
        {
          Key: 'Center Panel',
          StatusBarPanels: ['FormatColumn'],
        },
      ],
    },
    Theme: {CurrentTheme: 'dark'},
    Layout: {
      CurrentLayout: 'Standard Layout',
      Layouts: [
        {
          Name: 'Standard Layout',
          TableColumns: [
            'name',
            'language',
            'github_stars',
            'license',
            'created_at',
            'has_wiki',
            'updated_at',
            'pushed_at',
            'github_watchers',
            'description',
            'open_issues_count',
          ],
          AutoSizeColumns: true,
        },
      ],
    },
  },
};
```

**`src/styles.css`**

```css
/* Replace the first 7 palette colours, and add two after the default 32 */
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;
  --ab-color-palette-33: #ff1493;
  --ab-color-palette-34: #ffd700;
}
```

### 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](https://www.adaptabletools.com/docs/technical-reference-ui/index.md).

### `tabs`

Which tabs the Colour Picker shows, and in which order

  `ColourPickerTab[]`

Each entry is `Custom` or `Palette`:

| Value     | Tab                                                         |
| --------- | ----------------------------------------------------------- |
| `Custom`  | Free colour picker (with opacity), hex field and eyedropper |
| `Palette` | Theme colours and palette colours                           |

- The first tab listed is the one the picker opens on, until the user picks another tab
- When only one tab is listed, the tab bar is hidden

```ts {4}
userInterfaceOptions: {
  colourPickerOptions: {
    // Show the Palette tab first
    tabs: ['Palette', 'Custom'],
  },
},
```

### 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

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

### `orderPaletteColours`

Orders the colours using a colour-wheel order

Reds stay together, then oranges, yellows, greens, blues and purples, with greys, white and black after them.

Set it to `false` to keep the order the theme lists.

```ts {4}
userInterfaceOptions: {
  colourPickerOptions: {
    // Keep the order the theme lists
    orderPaletteColours: false,
  },
},
```

### `removeDuplicates`

Ensures that each colour only appears once

A swatch that paints the same hex as one already listed is left out.

The first one stays, and theme colours are listed before palette colours.

Set it to `false` to show every swatch, even duplicates.

```ts {4}
userInterfaceOptions: {
  colourPickerOptions: {
    // Show every swatch, including ones that paint the same hex
    removeDuplicates: false,
  },
},
```

### `showGroupLabels`

Shows Theme and Palette headings

Shows **Theme** and **Palette** headings on the Palette tab when both groups have colours.

A group the filter emptied is left out, and a single remaining group has no heading.

```ts {4}
userInterfaceOptions: {
  colourPickerOptions: {
    // Show Theme and Palette headings
    showGroupLabels: true,
  },
},
```

**Example: Palette Tab Order, Duplicates and Labels**

Theme order, duplicate swatches, and Theme and Palette headings

- `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

- 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

Demo project (Vanilla); the files without a marker are shown below:

```text
src/
  adaptableOptions.ts
  agGridModules.ts     [template]
  columnDefs.ts        [template]
  gridOptions.ts       [template]
  index.ts             [template]
  onAdaptableReady.ts  [template]
  rowData.ts           [template]
  styles.css           [template]
index.html             [template]
package.json           [template]
tsconfig.json          [template]
```

Files marked `[template]` are the same in every demo; see the [demo template](https://www.adaptabletools.com/llms/demo-template.md#vanilla).

**`src/adaptableOptions.ts`**

```ts
import {AdaptableOptions} from '@adaptabletools/adaptable';
import {WebFramework} from './rowData';

export const adaptableOptions: AdaptableOptions<WebFramework> = {
  primaryKey: 'id',
  adaptableId: 'Colour Picker Palette Tab',
  userInterfaceOptions: {
    colourPickerOptions: {
      tabs: ['Palette'],
      orderPaletteColours: false,
      removeDuplicates: false,
      showGroupLabels: true,
    },
  },
  initialState: {
    Dashboard: {
      ModuleButtons: ['FormatColumn'],
    },
    StatusBar: {
      StatusBars: [
        {
          Key: 'Center Panel',
          StatusBarPanels: ['FormatColumn'],
        },
      ],
    },
    Layout: {
      CurrentLayout: 'Standard Layout',
      Layouts: [
        {
          Name: 'Standard Layout',
          TableColumns: [
            'name',
            'language',
            'github_stars',
            'license',
            'created_at',
            'has_wiki',
            'updated_at',
            'pushed_at',
            'github_watchers',
            'description',
            'open_issues_count',
          ],
          AutoSizeColumns: true,
        },
      ],
    },
  },
};
```

### 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`

Chooses which colours the Palette tab shows

  `(context: ColourPickerFilterContext) => ColourPickerFilterResult | void`

Receives the theme colours, the palette colours, and the module being edited, and returns the ones to show.

The [`ColourPickerFilterContext`](https://www.adaptabletools.com/docs/reference/colourpickerfiltercontext.md) object received by the function is defined as follows:

| Property | Type | Description |
| --- | --- | --- |
| [module](https://www.adaptabletools.com/docs/reference/colourpickerfiltercontext.md#module) | [`AdaptableModule`](https://www.adaptabletools.com/docs/reference/adaptablemodule.md) | Module being edited |
| [paletteColours](https://www.adaptabletools.com/docs/reference/colourpickerfiltercontext.md#palettecolours) | [`ColourPickerColour`](https://www.adaptabletools.com/docs/reference/colourpickercolour.md)`[]` | Available Palette colours |
| [themeColours](https://www.adaptabletools.com/docs/reference/colourpickerfiltercontext.md#themecolours) | [`ColourPickerColour`](https://www.adaptabletools.com/docs/reference/colourpickercolour.md)`[]` | Available Theme colours |

The [`ColourPickerColour`](https://www.adaptabletools.com/docs/reference/colourpickercolour.md) property in the context is defined as follows:

| Property | Type | Description |
| --- | --- | --- |
| [hex](https://www.adaptabletools.com/docs/reference/colourpickercolour.md#hex) | `string` | The colour as the active theme paints it |
| [label](https://www.adaptabletools.com/docs/reference/colourpickercolour.md#label) | `string` | The name shown for the colour, e.g. &quot;Success&quot; or &quot;Palette 3&quot;. |
| [value](https://www.adaptabletools.com/docs/reference/colourpickercolour.md#value) | `string` | The CSS value that gets stored, e.g. `var(--ab-color-success)`. |

A returned colour is shown only when its `value` is one of the values passed in for that list.

This means that the function is able to filter the lists but it cannot add colours not already defined.

Omit the function, or return nothing, to show every colour.

- `module` is the Adaptable Module open when the Colour Picker was opened
- This allows developers to supply different colours for different modules

```ts {4}
userInterfaceOptions: {
  colourPickerOptions: {
    // Palette colours only, and only the first 7
    filterColours: ({ paletteColours }) => ({
      themeColours: [],
      paletteColours: paletteColours.slice(0, 7),
    }),
  },
},
```

**Example: Filtering the Palette Tab**

The Palette tab offers only the first 7 palette colours

- `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

- 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

Demo project (Vanilla); the files without a marker are shown below:

```text
src/
  adaptableOptions.ts
  agGridModules.ts     [template]
  columnDefs.ts        [template]
  gridOptions.ts       [template]
  index.ts             [template]
  onAdaptableReady.ts  [template]
  rowData.ts           [template]
  styles.css           [template]
index.html             [template]
package.json           [template]
tsconfig.json          [template]
```

Files marked `[template]` are the same in every demo; see the [demo template](https://www.adaptabletools.com/llms/demo-template.md#vanilla).

**`src/adaptableOptions.ts`**

```ts
import {AdaptableOptions} from '@adaptabletools/adaptable';
import {WebFramework} from './rowData';

export const adaptableOptions: AdaptableOptions<WebFramework> = {
  primaryKey: 'id',
  adaptableId: 'Colour Picker Filter Colours',
  userInterfaceOptions: {
    colourPickerOptions: {
      tabs: ['Palette'],
      filterColours: ({paletteColours}) => ({
        themeColours: [],
        paletteColours: paletteColours.slice(0, 7),
      }),
    },
  },
  initialState: {
    Dashboard: {
      ModuleButtons: ['FormatColumn'],
    },
    StatusBar: {
      StatusBars: [
        {
          Key: 'Center Panel',
          StatusBarPanels: ['FormatColumn'],
        },
      ],
    },
    Layout: {
      CurrentLayout: 'Standard Layout',
      Layouts: [
        {
          Name: 'Standard Layout',
          TableColumns: [
            'name',
            'language',
            'github_stars',
            'license',
            'created_at',
            'has_wiki',
            'updated_at',
            'pushed_at',
            'github_watchers',
            'description',
            'open_issues_count',
          ],
          AutoSizeColumns: true,
        },
      ],
    },
  },
};
```

### 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
