# Empty state

Use the `si-empty-state` component in places where you would normally display data, but there is none available. For example, in lists with filters/search when no data is left after filtering. You can customize the icon and text to your needs.

## Design

![Empty state specification](<../images/empty-state-usage-construction.png>)

An empty state component consists of the following elements:

1. **Icon**: The object icon associated with the current view.
2. **Title**: A short and concise title to describe the state. A simple wording should be used (e.g. `No devices`) and full sentences shall be avoided.
3. **Text**: A more detailed explanation of the state, outlining the reasoning for it and how a user can resolve it (*optional*).
4. **Actions**: Allows the user to take actions to resolve the issue (*optional*).

## Code

### Usage

```
import { SiEmptyStateComponent } from '@siemens/element-ng/empty-state';

@Component({
  imports: [SiEmptyStateComponent, ...]
})
```

#### Example

Component:

```typescript
/**
 * Copyright (c) Siemens 2016 - 2026
 * SPDX-License-Identifier: MIT
 */
import { Component, inject } from '@angular/core';
import { SiEmptyStateComponent } from '@siemens/element-ng/empty-state';
import { LOG_EVENT } from '@siemens/live-preview';

@Component({
  selector: 'app-sample',
  imports: [SiEmptyStateComponent],
  templateUrl: './si-empty-state.html'
})
export class SampleComponent {
  logEvent = inject(LOG_EVENT);
}
```

Template:

```html
<si-empty-state
  icon="element-users"
  heading="No users"
  content="There are no users within this group. Add users to get started."
>
  <button
    type="button"
    class="btn btn-secondary me-6"
    (click)="logEvent('Learn more button clicked')"
  >
    Learn more
  </button>
  <button type="button" class="btn btn-primary" (click)="logEvent('Add user button clicked')">
    Add user
  </button>
</si-empty-state>
```

### Responsive behavior

The responsive behavior can be adjusted to adapt the empty state to the available container height. Use the playground settings to explore this behavior, toggle actions, and resize the container.

Enable `responsiveMode` in a container with a defined height to progressively hide the icon and then the description at fixed height breakpoints. These breakpoints provide approximate layout tiers rather than measuring whether all supplied content fits.

When `responsiveMode` is enabled, the heading and description are each limited to one line and truncated with an ellipsis. Without responsive mode, text keeps its normal wrapping behavior.

#### Example

Component:

```typescript
/**
 * Copyright (c) Siemens 2016 - 2026
 * SPDX-License-Identifier: MIT
 */
import { Component, inject, signal } from '@angular/core';
import { form, FormField, max, min } from '@angular/forms/signals';
import { SiEmptyStateComponent } from '@siemens/element-ng/empty-state';
import { LOG_EVENT } from '@siemens/live-preview';

@Component({
  selector: 'app-sample',
  imports: [SiEmptyStateComponent, FormField],
  templateUrl: './si-empty-state-playground.html'
})
export class SampleComponent {
  protected readonly logEvent = inject(LOG_EVENT);
  protected readonly settings = signal<{
    responsiveMode: boolean;
    showActions: boolean;
    containerHeight: number;
  }>({
    responsiveMode: true,
    showActions: true,
    containerHeight: 220
  });
  protected readonly settingsForm = form(this.settings, path => {
    min(path.containerHeight, 60);
    max(path.containerHeight, 400);
  });
}
```

Template:

```html
<div class="d-flex flex-column h-100">
  <div
    class="card flex-shrink-0 mt-8 mx-6"
    style="min-block-size: min-content"
    [style.block-size.px]="settings().containerHeight"
  >
    <si-empty-state
      class="d-block h-100"
      style="min-block-size: min-content"
      icon="element-users"
      heading="No users"
      content="There are no users within this group. Add users to get started."
      [responsiveMode]="settings().responsiveMode"
    >
      @if (settings().showActions) {
        <button
          type="button"
          class="btn btn-secondary me-6"
          (click)="logEvent('Learn more button clicked')"
        >
          Learn more
        </button>
        <button type="button" class="btn btn-primary" (click)="logEvent('Add user button clicked')">
          Add user
        </button>
      }
    </si-empty-state>
  </div>
  <div class="flex-grow-1 e2e-ignore" aria-hidden="true"></div>
  <div class="card flex-shrink-0 e2e-ignore mx-6 my-8">
    <div class="card-header">Control Panel</div>
    <div class="card-body">
      <div class="form-check mb-6">
        <input
          id="responsive-mode"
          type="checkbox"
          class="form-check-input"
          [formField]="settingsForm.responsiveMode"
        />
        <label class="form-check-label" for="responsive-mode">Responsive mode</label>
      </div>
      <div class="mb-6">
        <label class="form-label" for="container-height">
          Container height: {{ settings().containerHeight }} px
        </label>
        <input
          id="container-height"
          type="range"
          class="form-range"
          step="1"
          [formField]="settingsForm.containerHeight"
        />
      </div>
      <div class="form-check">
        <input
          id="show-actions"
          type="checkbox"
          class="form-check-input"
          [formField]="settingsForm.showActions"
        />
        <label class="form-check-label" for="show-actions">Show actions</label>
      </div>
    </div>
  </div>
</div>
```

### [SiEmptyStateComponent](<https://github.com/siemens/element/blob/main/projects/element-ng/empty-state/si-empty-state.component.ts#L15-L38>)

**Kind:** component

**Selector:** `si-empty-state`

```
import { SiEmptyStateComponent } from '@siemens/element-ng/empty-state';
```

```
component SiEmptyStateComponent
```

#### Input Properties

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| [content](<https://github.com/siemens/element/blob/main/projects/element-ng/empty-state/si-empty-state.component.ts#L29-L29>) | `TranslatableString \| undefined` |  | Description of empty state content. |
| [heading](<https://github.com/siemens/element/blob/main/projects/element-ng/empty-state/si-empty-state.component.ts#L24-L24>) (required) | `TranslatableString` |  | Heading of empty state content. |
| [icon](<https://github.com/siemens/element/blob/main/projects/element-ng/empty-state/si-empty-state.component.ts#L19-L19>) | `string \| undefined` |  | CSS class name of the desired icon. |
| [responsiveMode](<https://github.com/siemens/element/blob/main/projects/element-ng/empty-state/si-empty-state.component.ts#L37-L37>) | `boolean` | `false` | Enables automatic adaptation to the available height. Heading and description are truncated to one line. When disabled, all supplied elements remain visible. |

### Types Documentation

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