# Configuring Cell Flashing

Canonical page: https://www.adaptabletools.com/docs/handbook-flashing-cell-configuring

- Developers are able to set default properties for Flashing Cells
- These override the AdapTable defaults and are used when turning on Flashing from the Column Menu
- These defaults can themselves, in turn, be overridden, when creating a Flashing Cell Definition

Flashing, like everything in AdapTable, is highly configurable.

## Setting Flashing Defaults

By default when Flashing is turned on for a column these values are used by AdapTable:

- <div style={{background: '#008000', padding: '0.5rem', width:'200px', borderRadius: 5}}>Up Change Style</div>

- <div style={{background: '#FF0000', padding: '0.5rem', width:'200px', borderRadius: 5}}>Down Change Style</div>

- <div style={{background: '#808080', padding: '0.5rem', width:'200px', borderRadius: 5}}>Neutral Change Style</div>

- Duration - 500ms

- Flash Target - cell

Like with any AdapTable object, different properties can be set for a particular Flashing Cell Definition - either at runtime in the Flashing Wizard or at design time in [Flashing Cell Initial State](https://www.adaptabletools.com/docs/technical-reference-flashing-cell/index.md).

Those provided properties will then be used, in preference to the default values.

However, it is additionally possible for developers to set their own default values for each of these properties.

This is useful as it allows for Flashing to be turned on for a Column via the [Column Menu](https://www.adaptabletools.com/docs/ui-column-menu/index.md)

These "new" defaults are supplied in the [Flashing Cell Options](https://www.adaptabletools.com/docs/technical-reference-flashing-cell/index.md) section of Adaptable Options.

They will **only** be used if the equivalent property is not included in the Flashing Cell Definition (which takes priority)

### Rules of Precedence when using Flashing Cells

 
This is the order of precedence AdapTable uses when deciding which property to use when Flashing a Cell:

1. Any property **explicitly set** in the Flashing Cell Definition - either provided at design-time or set in the UI
2. Any Default Value configured in [Flashing Cell Options](https://www.adaptabletools.com/docs/technical-reference-flashing-cell/index.md)
3. The AdapTable default value for that property

### Default Change Styles

As noted, AdapTable provides 3 properties in [Flashing Cell Options](https://www.adaptabletools.com/docs/technical-reference-flashing-cell/index.md) which enable developers to set the Styles for flashing changes.

All 3 properties are [Adaptable Styles](https://www.adaptabletools.com/docs/ui-tutorial-providing-adaptable-style/index.md) which is used in multiple Modules in AdapTable, and contains fore, back and border colours and a selection of font-related properties.

- Unlike with other AdapTable Style use cases, you **cannot** provide [CSS ClassNames](https://www.adaptabletools.com/docs/ui-tutorial-providing-adaptable-style/index.md#css-class-option) for Flashing Cells
- Instead only the provided properties of the Adaptable Style object can be used

The default for these properties as set by AdapTable is to set just one property, `BackColor`, as follows:

- `defaultUpChangeStyle` - Green
- `defaultDownChangeStyle` - Red
- `defaultNeutralChangeStyle` - Gray

As the `Style` object can be used in Initial State (e.g. for [Format Columns](https://www.adaptabletools.com/docs/handbook-column-formatting/index.md)) the properties use pascal, not camel, casing

### `defaultUpChangeStyle`

The default Style to Flash a Cell when it changes in an upward direction

  [`AdaptableStyle`](https://www.adaptabletools.com/docs/reference/adaptablestyle.md)

Sets the default Style to use for Flashing Cells when the data change is 'up', where the current default (of `BackColor` of Green) is not desired.

This only applies to Numeric or Date cells

The property is an [Adaptable Style](https://www.adaptabletools.com/docs/ui-tutorial-providing-adaptable-style/index.md) - which is used in multiple places in AdapTable.

```ts {4}
// Change the default Up Style
const adaptableOptions: AdaptableOptions = {
  flashingCellOptions: {
    defaultUpChangeStyle: {
      BackColor: 'var(--ab-color-palette-17)',
      ForeColor: 'var(--ab-color-palette-14)',
      FontWeight: 'Bold',
    },
  },
};
```

### `defaultDownChangeStyle`

The default Style to Flash a Cell when it changes in a downward direction

  [`AdaptableStyle`](https://www.adaptabletools.com/docs/reference/adaptablestyle.md)

Sets the default Style to use for Flashing Cells when the data change is 'down', where the current default (of `BackColor` of Red) is not desired.

This only applies to Numeric or Date cells

The property is an [Adaptable Style](https://www.adaptabletools.com/docs/ui-tutorial-providing-adaptable-style/index.md) - which is used in multiple places in AdapTable.

```ts {4}
// Change the default Down Style
const adaptableOptions: AdaptableOptions = {
  flashingCellOptions: {
    defaultDownChangeStyle: {
      BackColor: 'var(--ab-color-palette-17)',
      ForeColor: 'var(--ab-color-palette-14)',
      FontWeight: 'Bold',
    },
  },
};
```

### `defaultNeutralChangeStyle`

The default Style to Flash a Cell when it changes in a neutral direction

  [`AdaptableStyle`](https://www.adaptabletools.com/docs/reference/adaptablestyle.md)

Sets the default Style to use for Flashing Cells when the data change is 'neutral', where the current default (of `BackColor` of Gray) is not desired.

This generally applies to string cells where there is no obvious 'up' or 'down' direction

The property is an [Adaptable Style](https://www.adaptabletools.com/docs/ui-tutorial-providing-adaptable-style/index.md) - which is used in multiple places in AdapTable.

```ts {4}
// Change the default Neutral Style
const adaptableOptions: AdaptableOptions = {
  flashingCellOptions: {
    defaultNeutralChangeStyle: {
      BackColor: 'var(--ab-color-palette-17)',
      ForeColor: 'var(--ab-color-palette-14)',
      FontWeight: 'Bold',
    },
  },
};
```

### Default Flash Duration

By default Cells (and Rows) will flash for half a second.

This can be changed by using the `defaultFlashDuration` property in [Flashing Cell Options](https://www.adaptabletools.com/docs/technical-reference-flashing-cell/index.md).

Either an alternative duration can be provided, or set to 'always' so the Style renders indefinitely.

### `defaultFlashDuration`

Duration of Flashing Cell

How long, by default, a Cell or Row will flash for.

Possible values are:

- any number (in milliseconds) - the default is 500

```ts {4}
// By default set Cells and Rows to flash for 1 second
const adaptableOptions: AdaptableOptions = {
  flashingCellOptions: {
    defaultFlashDuration: 1000,
  },
};
```

- `always` - the flash is never removed

```ts {4}
// By default set Cells and Rows to flash indefinitely (or until removed by user)
const adaptableOptions: AdaptableOptions = {
  flashingCellOptions: {
    defaultFlashDuration: 'always',
  },
};
```

### Default Flash Target

By default the Target for all Flashes is the Cell that contains the changed value.

The `defaultFlashTarget` property in [Flashing Cell Options](https://www.adaptabletools.com/docs/technical-reference-flashing-cell/index.md) allows the whole Row to flash by default.

### `defaultFlashTarget`

Whether default behaviour is for a Cell or the whole Row to flash

Sets the default target for Flashing Cells.

This property is used if not overridden in a [Flashing Cell Definition](https://www.adaptabletools.com/docs/technical-reference-flashing-cell/index.md).

Possible values are:

- `cell` (the default)
- `row`

```ts {4}
// By default always Flash a Row (unless overridden in a Flashing Cell Definition)
const adaptableOptions: AdaptableOptions = {
  flashingCellOptions: {
    defaultFlashTarget: 'row',
  },
};
```

**Example: Changing Flashing Cell Defaults**

Changing Flashing Colours and Duration

- In this example we override some default Flashing Cell properties:
  - New (more pastel-based) default `up`, `down` and `neutral` change styles are provided
  - `duration` is increased to 1 second
- These defaults are used by the `Github Stars` and `Github Watchers` Columns
- However the `Open Issues` and `Closed Issues` Columns override these defaults - they provide:
  - bespoke styles of Blue (up change) and Brown (down change)
  - a Duration of 350ms
### See the Flashing Cell Definitions

The Flashing Cell defaults are set in Flashing Cell Options:
```ts
flashingCellOptions: {
  defaultDownChangeStyle: {
    BackColor: '#e18989',
  },
  defaultUpChangeStyle: {
    BackColor: '#86d586',
  },
  defaultNeutralChangeStyle: {
    BackColor: '#c67676',
  },
  defaultFlashDuration: 1000
},
```
These are overridden by the Flashing Cell Styles provided in Initial Adaptable State:
```
initialState: {
   FlashingCell: {
    FlashingCellDefinitions: [
      {
        Name: 'Flashing_Cell_Github',
        Scope: {
          ColumnIds: ['github_stars', 'github_watchers'],
        },
        Rule: 'ANY_CHANGE()',
      },
      {
        Name: 'FlashingCell-2',
        Scope: {
          ColumnIds: ['open_issues_count', 'closed_issues_count'],
        },
        Rule: 'ANY_CHANGE()',
        UpChangeStyle: {
          BackColor: 'var(--ab-color-palette-24)',
          ForeColor: 'var(--ab-color-palette-14)',
        },
        DownChangeStyle: {
          BackColor: 'var(--ab-color-palette-17)',
          ForeColor: 'var(--ab-color-palette-14)',
        },
        FlashDuration: 350
      },
    ],
  },
},
```

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
  rowData.ts            [template]
  styles.css            [template]
  tickingDataHelper.ts  [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: 'Flashing Options',
  flashingCellOptions: {
    defaultDownChangeStyle: {
      BackColor: '#e18989',
    },
    defaultUpChangeStyle: {
      BackColor: '#86d586',
    },
    defaultNeutralChangeStyle: {
      BackColor: '#c67676',
    },
    defaultFlashDuration: 1000,
  },
  initialState: {
    Dashboard: {
      ModuleButtons: ['FlashingCell'],
    },
    Theme: {CurrentTheme: 'dark'},
    FlashingCell: {
      FlashingCellDefinitions: [
        {
          Name: 'flashingCell-github-anyChange',
          Scope: {
            ColumnIds: ['github_stars', 'github_watchers'],
          },
          Rule: 'ANY_CHANGE()',
        },
        {
          Name: 'flashingCell-Issues-anyChange',
          Scope: {
            ColumnIds: ['open_issues_count', 'closed_issues_count'],
          },
          Rule: 'ANY_CHANGE()',
          UpChangeStyle: {
            BackColor: 'var(--ab-color-palette-24)',
            ForeColor: 'var(--ab-color-palette-14)',
          },
          DownChangeStyle: {
            BackColor: 'var(--ab-color-palette-17)',
            ForeColor: 'var(--ab-color-palette-14)',
          },
          FlashDuration: 350,
        },
      ],
    },
    Layout: {
      CurrentLayout: 'Standard Layout',
      Layouts: [
        {
          TableColumns: [
            'name',
            'github_stars',
            'license',
            'github_watchers',
            'language',
            'open_issues_count',
            'closed_issues_count',
            'created_at',
            'has_wiki',
            'updated_at',
            'pushed_at',
            'description',
            'open_pr_count',
            'closed_pr_count',
            'has_projects',
            'has_pages',
            'week_issue_change',
          ],
          Name: 'Standard Layout',
          AutoSizeColumns: true,
        },
      ],
    },
  },
};
```

**`src/onAdaptableReady.ts`**

```ts
import {AdaptableReadyInfo} from '@adaptabletools/adaptable';
import {tickNumericData} from './tickingDataHelper';

export const onAdaptableReady = ({adaptableApi}: AdaptableReadyInfo) => {
  tickNumericData(adaptableApi, 2000, [
    'github_stars',
    'github_watchers',
    'open_issues_count',
    'closed_issues_count',
  ]);
};
```

## Defining Flashing Cell Rules

Cell Flashing rules can be defined at design-time via the [Flashing Cell](https://www.adaptabletools.com/docs/technical-reference-flashing-cell/index.md) section of Initial Adaptable State.

This will ensure they are applied when the Application first loads and will be stored with Adaptable State.

In addition default values can be set for the Styles used in Flashing.

### FAQ

**Can we change the default colours at run-time?**
No, default colours can only be set at design time in [Flashing Cell Options](https://www.adaptabletools.com/docs/technical-reference-flashing-cell/index.md)
