File

src/app/core/common-components/icon-input/icon-input.component.ts

Description

A MatFormField to let the user define a FontAwesome icon (showing some additional explanation in the UI).

Implements

OnInit OnChanges

Metadata

Index

Properties
Inputs
Outputs

Inputs

icon
Type : string

Outputs

iconChange
Type : EventEmitter

Properties

iconControl
Type : FormControl
import {
  Component,
  EventEmitter,
  Input,
  OnChanges,
  OnInit,
  Output,
  SimpleChanges,
} from "@angular/core";
import { FormControl, ReactiveFormsModule } from "@angular/forms";
import { MatFormFieldModule } from "@angular/material/form-field";
import { MatInputModule } from "@angular/material/input";
import { MatTooltipModule } from "@angular/material/tooltip";
import { FaIconComponent } from "@fortawesome/angular-fontawesome";

/**
 * A MatFormField to let the user define a FontAwesome icon
 * (showing some additional explanation in the UI).
 */
@Component({
  selector: "app-icon-input",
  standalone: true,
  imports: [
    ReactiveFormsModule,
    MatFormFieldModule,
    MatInputModule,
    MatTooltipModule,
    FaIconComponent,
  ],
  templateUrl: "./icon-input.component.html",
  styleUrl: "./icon-input.component.scss",
})
export class IconComponent implements OnInit, OnChanges {
  @Input() icon: string;
  @Output() iconChange = new EventEmitter<string>();

  iconControl: FormControl;

  ngOnInit(): void {
    this.iconControl = new FormControl(this.icon || "");
    this.iconControl.valueChanges.subscribe((value) =>
      this.iconChange.emit(value),
    );
  }

  ngOnChanges(changes: SimpleChanges): void {
    if (changes["icon"] && this.iconControl) {
      this.iconControl.setValue(this.icon || "", { emitEvent: false });
    }
  }
}
<mat-form-field class="full-width" floatLabel="always">
  <mat-label>
    <span i18n>Icon</span>
    &nbsp;
    <fa-icon
      icon="question-circle"
      matTooltip="Enter the ID of an icon here, which will be displayed as a visual icon then."
      i18n-matTooltip
    ></fa-icon>
  </mat-label>
  <input matInput [formControl]="iconControl" placeholder="Enter icon name" />
  <mat-hint align="start" i18n>
    Find available icon names at
    <a
      href="https://fontawesome.com/v6/search?o=r&m=free"
      target="_blank"
      rel="noopener"
    >
      fontawesome.com
    </a>
  </mat-hint>
</mat-form-field>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""