File

src/app/shared/components/tag-list/tag-list.component.ts

Description

A list of removable tags

Metadata

Index

Properties
Methods
Inputs
Outputs
HostBindings

Constructor

constructor(ga: GoogleAnalyticsService)

Creates an instance of tag list component.

Parameters :
Name Type Optional Description
ga GoogleAnalyticsService No

Analytics service

Inputs

tags
Type : Tag[]

The tags

Outputs

tagRemoved
Type : EventEmitter

Emits when a tag is removed

tagsChange
Type : EventEmitter

Emits the new array of tags when a tag has been removed

HostBindings

class
Type : "ccf-tag-list"
Default value : 'ccf-tag-list'

HTML class name

Methods

removeTag
removeTag(tag: Tag)

Removes a tag from the list

Parameters :
Name Type Optional Description
tag Tag No

Tag to remove

Returns : void
tagClasses
tagClasses(tag: Tag)
Parameters :
Name Type Optional
tag Tag No
Returns : string[]
tagId
tagId(_index: number, tag: Tag)

Gets the unique identifier for a tag

Parameters :
Name Type Optional Description
_index number No

Unused

tag Tag No

A tag

Properties

Readonly clsName
Type : string
Default value : 'ccf-tag-list'
Decorators :
@HostBinding('class')

HTML class name

import { ChangeDetectionStrategy, Component, EventEmitter, HostBinding, Input, Output } from '@angular/core';
import { GoogleAnalyticsService } from 'ngx-google-analytics';

import { Tag } from '../../../core/models/anatomical-structure-tag';

/**
 * A list of removable tags
 */
@Component({
  selector: 'ccf-tag-list',
  templateUrl: './tag-list.component.html',
  styleUrls: ['./tag-list.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class TagListComponent {
  /** HTML class name */
  @HostBinding('class') readonly clsName = 'ccf-tag-list';

  /**
   * The tags
   */
  @Input() tags!: Tag[];

  /**
   * Emits when a tag is removed
   */
  @Output() readonly tagRemoved = new EventEmitter<Tag>();

  /**
   * Emits the new array of tags when a tag has been removed
   */
  @Output() readonly tagsChange = new EventEmitter<Tag[]>();

  /**
   * Creates an instance of tag list component.
   *
   * @param ga Analytics service
   */
  constructor(private readonly ga: GoogleAnalyticsService) {}

  /**
   * Gets the unique identifier for a tag
   *
   * @param _index Unused
   * @param tag A tag
   * @returns An identifier
   */
  tagId(_index: number, tag: Tag): unknown {
    return tag.id;
  }

  tagClasses(tag: Tag): string[] {
    return tag.type === 'added' ? ['added'] : ['assigned'];
  }

  /**
   * Removes a tag from the list
   *
   * @param tag Tag to remove
   */
  removeTag(tag: Tag): void {
    this.tags = this.tags.filter((obj) => obj !== tag);
    this.ga.event('tag_removed', 'tag_list', tag.label);
    this.tagRemoved.emit(tag);
    this.tagsChange.emit(this.tags);
  }
}
<mat-chip-listbox selectable="false">
  <mat-chip
    *ngFor="let tag of tags; trackBy: tagId"
    removable
    disableRipple
    [class]="tagClasses(tag)"
    (removed)="removeTag(tag)"
  >
    {{ tag.label }}
    <mat-icon matChipRemove class="icon remove">cancel</mat-icon>
  </mat-chip>
</mat-chip-listbox>

./tag-list.component.scss

:host {
  display: block;
  overflow-x: hidden;
  overflow-y: auto;

  ::ng-deep .mdc-evolution-chip-set__chips {
    margin: 0 !important;

    .mdc-evolution-chip__text-label {
      font-size: 14px;
    }
  }
}
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""