src/app/core/basic-datatypes/configurable-enum/display-configurable-enum/display-configurable-enum.component.ts

Description

This component displays a ConfigurableEnumValue as text. If the value has a color property, it is used as the background color.

Extends

ViewDirective< ConfigurableEnumValue | ConfigurableEnumValue[] >

Example

Metadata

Relationships

Index

Properties
Inputs
Accessors

Inputs

config
Type : C
Default value : undefined
Inherited from ViewDirective
entity
Type : Entity
Inherited from ViewDirective
formFieldConfig
Type : FormFieldConfig
Inherited from ViewDirective
id
Type : string
Inherited from ViewDirective
tooltip
Type : string
Inherited from ViewDirective
value
Type : T
Inherited from ViewDirective

Properties

Readonly iterableValue
Type : unknown
Default value : computed<ConfigurableEnumValue[]>(() => { const value = this.value(); if (!value) return []; return Array.isArray(value) ? value : [value]; })
Readonly config
Type : unknown
Default value : computed<C>(() => { const ffc = this.formFieldConfig(); return ffc !== undefined ? (ffc.additional as C) : this._directConfig(); })
Inherited from ViewDirective
Readonly isPartiallyAnonymized
Type : unknown
Default value : computed<boolean>(() => { const entity = this.entity(); const id = this.id(); return ( (entity?.anonymized && entity?.getSchema()?.get(id)?.anonymize === "retain-anonymized") ?? false ); })
Inherited from ViewDirective

Accessors

extraLabels
getextraLabels()
import { Component, computed, ChangeDetectionStrategy } from "@angular/core";
import { MatTooltipModule } from "@angular/material/tooltip";
import { ViewDirective } from "#src/app/core/entity/default-datatype/view.directive";
import { DynamicComponent } from "../../../config/dynamic-components/dynamic-component.decorator";

import { ConfigurableEnumValue } from "../configurable-enum.types";

/**
 * This component displays a {@link ConfigurableEnumValue} as text.
 * If the value has a `color` property, it is used as the background color.
 */
@DynamicComponent("DisplayConfigurableEnum")
@Component({
  changeDetection: ChangeDetectionStrategy.OnPush,
  selector: "app-display-configurable-enum",
  templateUrl: "./display-configurable-enum.component.html",
  styleUrls: ["./display-configurable-enum.component.scss"],
  imports: [MatTooltipModule],
})
export class DisplayConfigurableEnumComponent extends ViewDirective<
  ConfigurableEnumValue | ConfigurableEnumValue[]
> {
  readonly iterableValue = computed<ConfigurableEnumValue[]>(() => {
    const value = this.value();
    if (!value) return [];
    return Array.isArray(value) ? value : [value];
  });

  get extraLabels(): string {
    return this.iterableValue()
      .slice(3)
      .map((v) => v.label)
      .join(", ");
  }
}
<span class="bubble-list">
  @for (val of iterableValue().slice(0, 3); track val.id) {
    <span
      class="colored-bubble"
      [style.background-color]="val.color"
      [title]="val.label"
    >
      {{ val.label }}
    </span>
  }
  @if (iterableValue().length > 3) {
    <span
      class="colored-bubble"
      style="background: #eee; color: #333"
      [matTooltip]="extraLabels"
      i18n
    >
      +{{ iterableValue().length - 3 }} more
    </span>
  }
</span>

./display-configurable-enum.component.scss

@use "variables/colors";

.colored-bubble {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 6px;
  margin-right: 6px;
  margin-bottom: 2px;
  background: colors.$grey-transparent;
  white-space: nowrap;
  vertical-align: middle;
  font-size: inherit;
  font-family: inherit;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  max-width: 230px;
}

.bubble-list {
  display: flex;
  align-items: center;
}
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""