# Status toggle

A status toggle allows a user to quickly set a status by tapping (primary action) on the desired status. Tap and drag to change the status (secondary-action) is also supported.

## Usage

A status toggle is a good way to directly set a status on a screen, e.g. the result of a datapoint-test, home/away state, etc.

![Status toggle](<../images/status-toggle.png>)

![Status toggle examples](<../images/status-toggle-examples.png>)

### Best practices

- In order to access it quickly, a status toggle should remain visible on the screen and not be part of the scrolling area.
- A status toggle can only hold 2 or 3 states.

## Design

### Elements

![Status toggle specification](<../images/status-toggle-usage-construction.png>)

> 1. Icon, 2. Label, 3. Selected state, 4. Unselected state

### Label

- The label describes the state.
- Labels are concise and use no more than two words.
- The label will be truncated with 3 dots, if there is not enough space.
- The width of a label depends on the number of states.

## Code

#### Example

##### All examples

Component:

```typescript
/**
 * Copyright (c) Siemens 2016 - 2026
 * SPDX-License-Identifier: MIT
 */
import { Component, inject } from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { FormControl, ReactiveFormsModule } from '@angular/forms';
import { SiStatusToggleComponent, StatusToggleItem } from '@siemens/element-ng/status-toggle';
import { LOG_EVENT } from '@siemens/live-preview';

@Component({
  selector: 'app-sample',
  imports: [ReactiveFormsModule, SiStatusToggleComponent],
  templateUrl: './si-status-toggle.html'
})
export class SampleComponent {
  protected readonly logEvent = inject(LOG_EVENT);

  itemsPlain: StatusToggleItem[] = [
    { text: 'Not checked', value: 'A', icon: 'element-not-checked' },
    {
      text: 'Failed (error status)',
      value: 'B',
      icon: 'element-issue',
      activeIcon: 'element-circle-filled',
      activeIconStacked: 'element-state-exclamation-mark',
      activeIconClass: 'status-danger',
      activeIconStackedClass: 'status-danger-contrast',
      activeTextClass: 'text-danger'
    },
    {
      text: 'Passed',
      value: 'C',
      icon: 'element-checked',
      activeIcon: 'element-circle-filled',
      activeIconStacked: 'element-state-tick',
      activeIconClass: 'status-success',
      activeIconStackedClass: 'status-success-contrast',
      activeTextClass: 'text-success'
    }
  ];

  valuePlain: string | number = 'B';

  itemsTwoItems: StatusToggleItem[] = [
    { text: 'Not checked', value: 'A', icon: 'element-not-checked' },
    {
      text: 'Passed',
      value: 'C',
      icon: 'element-checked',
      activeIcon: 'element-circle-filled',
      activeIconStacked: 'element-state-tick',
      activeIconClass: 'status-success',
      activeIconStackedClass: 'status-success-contrast',
      activeTextClass: 'text-success'
    }
  ];

  valueTwoItems: string | number = 'C';

  itemsSingleDisabled: StatusToggleItem[] = [
    { text: 'Not checked', value: 'A', icon: 'element-not-checked' },
    {
      text: 'Failed',
      value: 'B',
      icon: 'element-issue',
      activeIcon: 'element-circle-filled',
      activeIconStacked: 'element-state-exclamation-mark',
      activeIconClass: 'status-danger',
      activeIconStackedClass: 'status-danger-contrast',
      activeTextClass: 'text-danger'
    },
    {
      text: 'Passed',
      value: 'C',
      icon: 'element-checked',
      activeIconClass: 'status-success',
      activeTextClass: 'text-success',
      disabled: true
    }
  ];

  valueSingleDisabled: string | number = 'A';

  itemsAllDisabled: StatusToggleItem[] = [
    { text: 'Not checked', value: 'A', icon: 'element-not-checked' },
    {
      text: 'Failed',
      value: 'B',
      icon: 'element-issue',
      activeIconClass: 'status-danger',
      activeTextClass: 'text-danger'
    },
    {
      text: 'Passed',
      value: 'C',
      icon: 'element-checked',
      activeIconClass: 'status-success',
      activeTextClass: 'text-success'
    }
  ];

  valueAllDisabled: string | number = 'A';

  itemsForm: StatusToggleItem[] = [
    { text: 'Not checked', value: 'A', icon: 'element-not-checked' },
    {
      text: 'Failed',
      value: 'B',
      icon: 'element-issue',
      activeIcon: 'element-circle-filled',
      activeIconStacked: 'element-state-exclamation-mark',
      activeIconClass: 'status-danger',
      activeIconStackedClass: 'status-danger-contrast',
      activeTextClass: 'text-danger'
    },
    {
      text: 'Passed',
      value: 'C',
      icon: 'element-checked',
      activeIcon: 'element-circle-filled',
      activeIconStacked: 'element-state-tick',
      activeIconClass: 'status-success',
      activeIconStackedClass: 'status-success-contrast',
      activeTextClass: 'text-success'
    }
  ];

  formControl = new FormControl('B');

  constructor() {
    this.formControl.valueChanges
      .pipe(takeUntilDestroyed())
      .subscribe(event => this.logEvent('Form toggle value changed', event));
  }

  changePlainValue(): void {
    if (this.valuePlain === 'A') {
      this.valuePlain = 'B';
    } else if (this.valuePlain === 'B') {
      this.valuePlain = 'C';
    } else if (this.valuePlain === 'C') {
      this.valuePlain = 'A';
    }
  }
}
```

Template:

```html
<div class="p-5" style="max-inline-size: 500px">
  <h6>Plain</h6>
  <si-status-toggle
    [items]="itemsPlain"
    [(value)]="valuePlain"
    (valueChange)="logEvent('Plain toggle value changed', $event)"
    (itemClick)="logEvent('item click', $event)"
  />

  <button type="button" class="btn btn-secondary mt-6" (click)="changePlainValue()">
    Switch by code
  </button>

  <h6 class="mt-6">Two items</h6>
  <si-status-toggle
    [items]="itemsTwoItems"
    [(value)]="valueTwoItems"
    (valueChange)="logEvent('Two items toggle value changed', $event)"
  />

  <h6 class="mt-6">Single disabled</h6>
  <si-status-toggle
    [items]="itemsSingleDisabled"
    [(value)]="valueSingleDisabled"
    (valueChange)="logEvent('Single disabled toggle value changed', $event)"
  />

  <h6 class="mt-6">All disabled</h6>
  <si-status-toggle
    [items]="itemsAllDisabled"
    [disabled]="true"
    [(value)]="valueAllDisabled"
    (valueChange)="logEvent('All disabled toggle value changed', $event)"
  />

  <h6 class="mt-6">Form Element</h6>
  <form>
    <si-status-toggle [items]="itemsForm" [formControl]="formControl" />
  </form>
</div>
```

### [SiStatusToggleComponent](<https://github.com/siemens/element/blob/main/projects/element-ng/status-toggle/si-status-toggle.component.ts#L41-L241>)

**Kind:** component

**Selector:** `si-status-toggle`

```
import { SiStatusToggleComponent } from '@siemens/element-ng/status-toggle';
```

```
component SiStatusToggleComponent implements ControlValueAccessor, OnInit, OnDestroy, OnChanges
```

#### Input Properties

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| [disabled](<https://github.com/siemens/element/blob/main/projects/element-ng/status-toggle/si-status-toggle.component.ts#L50-L50>) | `boolean` | `false` | Disabled state for the whole component. |
| [items](<https://github.com/siemens/element/blob/main/projects/element-ng/status-toggle/si-status-toggle.component.ts#L45-L45>) (required) | `StatusToggleItem[]` |  | List of status items. |
| [value](<https://github.com/siemens/element/blob/main/projects/element-ng/status-toggle/si-status-toggle.component.ts#L52-L52>) | `string \| number \| undefined` |  | Value of currently selected status item. |

#### Output Properties

| Name | Type | Description |
| --- | --- | --- |
| [itemClick](<https://github.com/siemens/element/blob/main/projects/element-ng/status-toggle/si-status-toggle.component.ts#L55-L55>) | `string \| number` | Emitted when an item is clicked. |
| [valueChange](<https://github.com/siemens/element/blob/main/projects/element-ng/status-toggle/si-status-toggle.component.ts#L52-L52>) | `string \| number \| undefined` | Value of currently selected status item. |

### Types Documentation

### [StatusToggleItem](<https://github.com/siemens/element/blob/main/projects/element-ng/status-toggle/status-toggle.model.ts#L8-L27>)

**Kind:** interface

```
import type { StatusToggleItem } from '@siemens/element-ng/status-toggle';
```

An item for si-status-toggle.

```
interface StatusToggleItem
```

#### Properties

| Name | Type | Description |
| --- | --- | --- |
| [activeIcon](<https://github.com/siemens/element/blob/main/projects/element-ng/status-toggle/status-toggle.model.ts#L18-L18>) (optional) | `string` | Icon shown when the item is active. |
| [activeIconClass](<https://github.com/siemens/element/blob/main/projects/element-ng/status-toggle/status-toggle.model.ts#L22-L22>) (optional) | `string` | Class applied to the icon when the item is selected. |
| [activeIconStacked](<https://github.com/siemens/element/blob/main/projects/element-ng/status-toggle/status-toggle.model.ts#L20-L20>) (optional) | `string` | Stacked icon shown when the item is active. |
| [activeIconStackedClass](<https://github.com/siemens/element/blob/main/projects/element-ng/status-toggle/status-toggle.model.ts#L24-L24>) (optional) | `string` | Class applied to the stacked icon when the item is selected. |
| [activeTextClass](<https://github.com/siemens/element/blob/main/projects/element-ng/status-toggle/status-toggle.model.ts#L26-L26>) (optional) | `string` | Class applied to the text when the item is selected. |
| [disabled](<https://github.com/siemens/element/blob/main/projects/element-ng/status-toggle/status-toggle.model.ts#L16-L16>) (optional) | `boolean` | Whether the item is disabled. |
| [icon](<https://github.com/siemens/element/blob/main/projects/element-ng/status-toggle/status-toggle.model.ts#L12-L12>) | `string` | Icon displayed for the item. |
| [text](<https://github.com/siemens/element/blob/main/projects/element-ng/status-toggle/status-toggle.model.ts#L10-L10>) | `TranslatableString` | Text displayed for the item. |
| [value](<https://github.com/siemens/element/blob/main/projects/element-ng/status-toggle/status-toggle.model.ts#L14-L14>) | `string \| number` | Value of the item. |

### [TranslatableString](<https://github.com/siemens/element/blob/main/projects/element-translate-ng/translate-types/global.types.ts#L18-L18>)

**Kind:** type alias

```
import type { TranslatableString } from '@siemens/element-translate-ng/translate-types';
```

Represents a translatable string. This can either be a translation key, e.g. `ACTIONS.EDIT` that will be automatically translated when displayed on the UI or a pre-translated string, e.g. `Edit`. Equivalent to a normal string in usage and functionality.

```
type TranslatableString = string & Translatable
```
