# Toast Notifications

Canonical page: https://www.adaptabletools.com/docs/ui-tutorial-using-toast-notifications

- Toast Notifications are a configurable way to display messages
- They can include Forms if required
- Toast Notifications are configured via **`notificationsOptions`** on Adaptable Options
- Used for [Alerts](https://www.adaptabletools.com/docs/handbook-alerting/index.md) and [System Status Messages](https://www.adaptabletools.com/docs/handbook-system-status-message/index.md)

## Topics on this Page

| Topic                                           | Summary                                                                                           |
| ----------------------------------------------- | ------------------------------------------------------------------------------------------------- |
| [Demo & behaviour](#configuring-notifications)  | Sandpack — alerts and system status                                                               |
| [Notifications options](#notifications-options) | `notificationsOptions` on Adaptable Options                                                       |
| Technical reference                             | [Notifications Technical Reference](https://www.adaptabletools.com/docs/technical-reference-notifications/index.md) |

[UI Guides](https://www.adaptabletools.com/docs/ui-tutorial-overview/index.md).

Toast Notifications are rich, highly configurable popup messages.

They are designed to inform users of important messages or updates.

Toast Notifications are available - as options - in 2 modules in AdapTable:

- [Alerts](https://www.adaptabletools.com/docs/handbook-alerting/index.md)
- [System Status Messages](https://www.adaptabletools.com/docs/handbook-system-status-message/index.md)

- Alert Notifications can be configured to show an **Alert Form** (i.e. buttons and other Form fields)
- System Status toasts are typically message text plus a default OK button unless you customise the underlying alert

**Example: Notifications in AdapTable**

Keeping end users notified and updated

- This example demonstrates some of the Notification functionality available in AdapTable, including:
  - **System Status Messages** — four toolbar buttons call `systemStatusApi` (toolbar, tool panel, and — because `showSystemStatusMessageNotifications` is _true_ — a toast)
  - **Scheduled Alert** — **Schedule alert (15s)** adds a one-off [Scheduled Alert](https://www.adaptabletools.com/docs/handbook-alerting-schedule/index.md) that fires 15 seconds later with both a toast and a System Status entry
  - **Toast Notifications** — positioned top-centre with a bounce transition and 8 second duration (`notificationsOptions` on this demo)

- Click the status-type buttons in _Setting Message Buttons_ to change System Status (and see the toast)
- Click **Schedule alert (15s)** and wait for the scheduled toast and System Status update

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 {
  AdaptableButton,
  AdaptableOptions,
  CustomToolbarButtonContext,
} from '@adaptabletools/adaptable';
import {WebFramework} from './rowData';

export const adaptableOptions: AdaptableOptions<WebFramework> = {
  primaryKey: 'id',
  adaptableId: 'Notifications',
  dashboardOptions: {
    customToolbars: [
      {
        name: 'SettingMessageButtons',
        title: 'Setting Message Buttons',
        toolbarButtons: [
          {
            label: 'Set Info',
            buttonStyle: {
              variant: 'text',
              tone: 'info',
            },
            onClick: (
              button: AdaptableButton<CustomToolbarButtonContext>,
              context: CustomToolbarButtonContext
            ) => {
              context.adaptableApi.systemStatusApi.setInfoSystemStatus(
                'No issues'
              );
            },
          },
          {
            label: 'Set Success',
            buttonStyle: {
              variant: 'text',
              tone: 'success',
            },
            onClick: (
              button: AdaptableButton<CustomToolbarButtonContext>,
              context: CustomToolbarButtonContext
            ) => {
              context.adaptableApi.systemStatusApi.setSuccessSystemStatus(
                'All working fine'
              );
            },
          },
          {
            label: 'Set Warning',
            buttonStyle: {
              variant: 'text',
              tone: 'warning',
            },
            onClick: (
              button: AdaptableButton<CustomToolbarButtonContext>,
              context: CustomToolbarButtonContext
            ) => {
              context.adaptableApi.systemStatusApi.setWarningSystemStatus(
                'Problems with server',
                'Avoid any unnecessary edits'
              );
            },
          },
          {
            label: 'Set Error',
            buttonStyle: {
              variant: 'text',
              tone: 'error',
            },
            onClick: (
              button: AdaptableButton<CustomToolbarButtonContext>,
              context: CustomToolbarButtonContext
            ) => {
              context.adaptableApi.systemStatusApi.setErrorSystemStatus(
                'The server is down!',
                'Please do not make any edits until the server comes back up'
              );
            },
          },
          {
            label: 'Schedule alert (15s)',
            buttonStyle: {
              variant: 'raised',
              tone: 'accent',
            },
            onClick: (
              _button: AdaptableButton<CustomToolbarButtonContext>,
              context: CustomToolbarButtonContext
            ) => {
              const runAt = new Date(Date.now() + 15_000).toISOString();
              context.adaptableApi.alertApi.addAlertDefinition({
                Name: `Toolbar scheduled ${runAt}`,
                MessageHeader: 'Scheduled alert',
                MessageText:
                  'This one-off alert was scheduled 15 seconds after you clicked the button.',
                MessageType: 'Info',
                AlertProperties: {
                  DisplayNotification: true,
                  DisplaySystemStatusMessage: true,
                },
                Schedule: {
                  IsOneOff: true,
                  RunAt: runAt,
                },
              });
              context.adaptableApi.systemStatusApi.setInfoSystemStatus(
                'Alert scheduled',
                `Fires at ${new Date(runAt).toLocaleTimeString()}`
              );
            },
          },
        ],
      },
    ],
  },
  notificationsOptions: {
    showSystemStatusMessageNotifications: true,
    position: 'TopCenter',
    transition: 'Bounce',
    duration: 8000,
  },
  initialState: {
    Dashboard: {
      ModuleButtons: ['SystemStatus', 'Alert'],
      Tabs: [
        {
          Name: 'Messages',
          Toolbars: ['SystemStatus', 'SettingMessageButtons', 'Alert'],
        },
      ],
    },
    StatusBar: {
      StatusBars: [
        {
          Key: 'Center Panel',
          StatusBarPanels: ['SystemStatus'],
        },
      ],
    },
    Theme: {CurrentTheme: 'dark'},
    Layout: {
      CurrentLayout: 'Standard Layout',
      Layouts: [
        {
          TableColumns: [
            'name',
            'language',
            'github_stars',
            'license',
            'has_projects',
            'has_pages',
            'created_at',
            'has_wiki',
            'updated_at',
            'pushed_at',
            'github_watchers',
            'week_issue_change',
          ],
          Name: 'Standard Layout',
          AutoSizeColumns: true,
        },
      ],
    },
  },
};
```

## Configuring Notifications

By default a Toast Notification will:

- appear with a sliding action
- be positioned in the BottomRight of the screen
- remain on the screen for 3 seconds
- display without a progress bar
- not be draggable
- not close when it is clicked

However all these settings are configurable in [Notifications Options](https://www.adaptabletools.com/docs/technical-reference-notifications/index.md).

- These Options are global in AdapTable
- Changes affect **all** Toast Notifications (i.e. in both [Alerts](https://www.adaptabletools.com/docs/handbook-alerting/index.md) and [System Status Messages](https://www.adaptabletools.com/docs/handbook-system-status-message/index.md))

**Example: Toast Notifications**

Configuring Toast Notifications

- This demo **sends** System Status messages in the same way as the demo above.
- However we have overridden some of the default Toast Notification properties as follows:
  - `position`: 'TopCenter'
  - `duration`: 5000
  - `transition`: 'Bounce'
  - `showProgressBar`: true
  - `closeWhenClicked`: true
  - `pauseWhenHovering`: true

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 {
  AdaptableButton,
  AdaptableOptions,
  ContextMenuContext,
  CustomContextMenuContext,
  CustomToolbarButtonContext,
  UserContextMenuItem,
} from '@adaptabletools/adaptable';
import {WebFramework} from './rowData';

export const adaptableOptions: AdaptableOptions<WebFramework> = {
  primaryKey: 'id',
  adaptableId: 'Toast Notifications Configuration',
  dashboardOptions: {
    customToolbars: [
      {
        name: 'SettingMessageButtons',
        title: 'Setting Message Buttons',
        toolbarButtons: [
          {
            label: 'Set Info',
            buttonStyle: {
              variant: 'text',
              tone: 'info',
            },
            onClick: (
              button: AdaptableButton<CustomToolbarButtonContext>,
              context: CustomToolbarButtonContext
            ) => {
              context.adaptableApi.systemStatusApi.setInfoSystemStatus(
                'No issues'
              );
            },
          },
          {
            label: 'Set Success',
            buttonStyle: {
              variant: 'text',
              tone: 'success',
            },
            onClick: (
              button: AdaptableButton<CustomToolbarButtonContext>,
              context: CustomToolbarButtonContext
            ) => {
              context.adaptableApi.systemStatusApi.setSuccessSystemStatus(
                'All working fine'
              );
            },
          },
          {
            label: 'Set Warning',
            buttonStyle: {
              variant: 'text',
              tone: 'warning',
            },
            onClick: (
              button: AdaptableButton<CustomToolbarButtonContext>,
              context: CustomToolbarButtonContext
            ) => {
              context.adaptableApi.systemStatusApi.setWarningSystemStatus(
                'Problems with server',
                'Avoid any unnecesary edits'
              );
            },
          },
          {
            label: 'Set Error',
            buttonStyle: {
              variant: 'text',
              tone: 'error',
            },
            onClick: (
              button: AdaptableButton<CustomToolbarButtonContext>,
              context: CustomToolbarButtonContext
            ) => {
              context.adaptableApi.systemStatusApi.setErrorSystemStatus(
                'The server is down!',
                'Please do not make any edits until the server comes back up'
              );
            },
          },
        ],
      },
    ],
  },
  notificationsOptions: {
    showSystemStatusMessageNotifications: true,
    position: 'TopCenter',
    duration: 5000,
    transition: 'Bounce',
    showProgressBar: true,
    closeWhenClicked: true,
    pauseWhenHovering: true,
  },
  contextMenuOptions: {
    customContextMenu: (context: CustomContextMenuContext) => {
      const {defaultAgGridMenuStructure, defaultAdaptableMenuStructure} =
        context;

      const setSystemStatusMenuItem: UserContextMenuItem = {
        menuType: 'User',
        label: 'Set System Status',
        subMenuItems: [
          {
            menuType: 'User',
            label: 'Set Error',
            icon: {
              name: 'error',
            },
            onClick: (menuContext: ContextMenuContext) => {
              menuContext.adaptableApi.systemStatusApi.setErrorSystemStatus(
                'System Down'
              );
            },
          },
          {
            menuType: 'User',
            label: 'Set Warning',
            icon: {
              name: 'warning',
            },
            onClick: (menuContext: ContextMenuContext) => {
              menuContext.adaptableApi.systemStatusApi.setWarningSystemStatus(
                'System Slow'
              );
            },
          },
          {
            menuType: 'User',
            label: 'Set Success',
            icon: {
              name: 'check',
            },
            onClick: (menuContext: ContextMenuContext) => {
              menuContext.adaptableApi.systemStatusApi.setSuccessSystemStatus(
                'System Fine'
              );
            },
          },
          {
            menuType: 'User',
            label: 'Set Info',
            icon: {
              name: 'info',
            },
            onClick: (menuContext: ContextMenuContext) => {
              menuContext.adaptableApi.systemStatusApi.setInfoSystemStatus(
                'Demos working fine'
              );
            },
          },
        ],
      };

      return [
        setSystemStatusMenuItem,
        '-',
        ...defaultAgGridMenuStructure,
        '-',
        ...defaultAdaptableMenuStructure,
      ];
    },
  },
  initialState: {
    Dashboard: {
      ModuleButtons: ['SystemStatus'],
      Tabs: [
        {
          Name: 'Messages',
          Toolbars: ['SystemStatus', 'SettingMessageButtons'],
        },
      ],
    },
    Theme: {CurrentTheme: 'dark'},
    Layout: {
      CurrentLayout: 'Standard Layout',
      Layouts: [
        {
          TableColumns: [
            'name',
            'language',
            'github_stars',
            'license',
            'has_projects',
            'has_pages',
            'created_at',
            'has_wiki',
            'updated_at',
            'pushed_at',
            'github_watchers',
            'week_issue_change',
          ],
          Name: 'Standard Layout',
          AutoSizeColumns: true,
        },
      ],
    },
  },
};
```

## Notifications Options

Toast Notifications are configured in [`NotificationsOptions`](https://www.adaptabletools.com/docs/reference/notificationsoptions.md) on Adaptable Options (`notificationsOptions`).

### `closeWhenClicked`

Closes Notification automatically when its clicked

Closes a Toast Notification as soon as the user clicks it

```ts {3}
const adaptableOptions: AdaptableOptions = {
  notificationsOptions: {
    closeWhenClicked: true,
  },
};
```

### `duration`

Determines how long a Toast Notification will be displayed

Sets the duration of the appearance of a Toast Notification.

```ts {4}
const adaptableOptions: AdaptableOptions = {
  notificationsOptions: {
    // this can be a number (duration in millis) or the string 'always'
    duration: 'always',
  },
};
```

### `isDraggable`

Whether a Toast Notification can be dragged to a new location

Allows a Toast Notification to be moved by clicking and dragging.

```ts {3}
const adaptableOptions: AdaptableOptions = {
  notificationsOptions: {
    isDraggable: true,
  },
};
```

### `maxNotifications`

How many Notifications can be displayed at one time

Sets how many Notifications can be displayed at one time

```ts {3}
const adaptableOptions: AdaptableOptions = {
  notificationsOptions: {
    maxNotifications: 5,
  },
};
```

### `pauseWhenHovering`

Pauses the Notification when mouse hovers over it

Use this property to suspend the duration of a Toast Notification while the mouse is hovering over it

```ts {3}
const adaptableOptions: AdaptableOptions = {
  notificationsOptions: {
    pauseWhenHovering: true,
  },
};
```

### `position`

Where the Notification will appear

  [`TOAST_POSITIONS`](https://www.adaptabletools.com/docs/reference/toastpositions.md)

Use this property to set where a Toast Notification will appear (if anywhere). Options are:

- `TopRight`
- `TopCenter`
- `TopLeft`
- `BottomRight` (the default)
- `BottomCenter`
- `BottomLeft`

```ts {3}
const adaptableOptions: AdaptableOptions = {
  notificationsOptions: {
    position: 'TopCenter',
  },
};
```

### `showApplicationIcon`

Displays the application icon in Notifications

Displays the Application Icon in Toast Notifications.

This requires an icon to be provided in the applicationIcon property of [User Interface Options](https://www.adaptabletools.com/docs/technical-reference-ui/index.md)

```ts {3}
const adaptableOptions: AdaptableOptions = {
  notificationsOptions: {
    showApplicationIcon: true,
  },
};
```

### `showProgressBar`

Displays a Progress Bar in a Toast Notification

Displays a Progress Bar inside a Toast Notification which shows how long left in the Notification Duration

```ts {3}
const adaptableOptions: AdaptableOptions = {
  notificationsOptions: {
    showProgressBar: true,
  },
};
```

### `transition`

How a Toast Notification will first appear

Sets the transition appearance of a Toast Notification.

Defaults to 'slide' but can also bounce, zoom or flip.

```ts {4}
const adaptableOptions: AdaptableOptions = {
  notificationsOptions: {
    // Make Toast Notifications Flip into view
    transition: 'Flip',
  },
};
```

The full property list is in the [Notifications Technical Reference](https://www.adaptabletools.com/docs/technical-reference-notifications/index.md)

### FAQ

**Alerts vs System Status vs toasts?**
**Alerts** can show a toast when rules fire (optional form buttons). **System Status** updates the status bar and can mirror the same message as a toast when enabled — see the demo toolbar buttons.

**Where do I configure defaults?**
`adaptableOptions.notificationsOptions`. Per-alert overrides use presentation properties on the alert definition — see [Alerting](https://www.adaptabletools.com/docs/handbook-alerting/index.md).
