Skip to content

Commit a975edb

Browse files
committed
feat: define interface for annotation rendering components
1 parent f913590 commit a975edb

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

projects/ngx-annotate-text/src/lib/components/annotation/annotation-renderer.components.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { Component, Input } from '@angular/core';
22
import { Annotation } from '../../models/annotation.model';
3+
import { NgxAnnotationRendererComponentInterface } from '../../models/annotation-renderer-component.model';
34

45
@Component({
56
// eslint-disable-next-line @angular-eslint/component-selector
67
selector: 'ngx-annotation-renderer',
78
templateUrl: './annotation-renderer.component.html',
89
styleUrls: ['./annotation-renderer.component.css'],
910
})
10-
export class NgxAnnotationRendererComponent {
11+
export class NgxAnnotationRendererComponent implements NgxAnnotationRendererComponentInterface {
1112
@Input({ required: true }) annotation!: Annotation;
1213
@Input() removable = true;
1314
@Input() clickAnnotation!: (annotation: Annotation) => void;

projects/ngx-annotate-text/src/lib/components/ngx-annotate-text/ngx-annotate-text.component.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { Annotation } from '../../models/annotation.model';
1313
import { ISelection } from '../../models/selection.model';
1414
import { TokenizerService } from '../../services/tokenizer.service';
1515
import { NgxAnnotationRendererComponent } from '../annotation/annotation-renderer.components';
16+
import { NgxAnnotationRendererComponentInterface } from '../../models/annotation-renderer-component.model';
1617

1718
@Component({
1819
// eslint-disable-next-line @angular-eslint/component-selector
@@ -27,7 +28,8 @@ export class NgxAnnotateTextComponent implements OnInit, OnChanges {
2728
/** An optional CSS class applied to all elements which wrap the annotated parts of the given text. */
2829
@Input() annotationClass?: string;
2930

30-
@Input() annotationRenderComponent: Type<any> = NgxAnnotationRendererComponent;
31+
/** An optional Angular component that shall be used for rendering the annotation. Must implement the interface NgxAnnotationRendererComponentInterface. */
32+
@Input() annotationRenderComponent: Type<NgxAnnotationRendererComponentInterface> = NgxAnnotationRendererComponent;
3133

3234
/**
3335
* Determines whether annotations shall have a small button in the top right corner so that the user can
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { Annotation } from './annotation.model';
2+
3+
export interface NgxAnnotationRendererComponentInterface {
4+
annotation: Annotation;
5+
removable: boolean;
6+
clickAnnotation: (annotation: Annotation) => void;
7+
removeAnnotation: (annotation: Annotation) => void;
8+
}

src/app/app.component.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import { Component, Type, ViewChild } from '@angular/core';
2-
import { RouterOutlet } from '@angular/router';
32
import { NgxAnnotateTextModule } from '../../projects/ngx-annotate-text/src/lib/ngx-annotate-text.module';
43
import { Annotation, NgxAnnotateTextComponent } from '../../projects/ngx-annotate-text/src/public-api';
54
import { MyAnnotationRendererComponent } from './my-annotation-renderer/my-annotation-renderer.component';
65
import { NgxAnnotationRendererComponent } from '../../projects/ngx-annotate-text/src/lib/components/annotation/annotation-renderer.components';
76
import { FormsModule } from '@angular/forms';
7+
import { NgxAnnotationRendererComponentInterface } from '../../projects/ngx-annotate-text/src/lib/models/annotation-renderer-component.model';
88

99
@Component({
1010
// eslint-disable-next-line @angular-eslint/component-selector
1111
selector: 'app-root',
1212
standalone: true,
13-
imports: [RouterOutlet, NgxAnnotateTextModule, FormsModule],
13+
imports: [NgxAnnotateTextModule, FormsModule],
1414
templateUrl: './app.component.html',
1515
styleUrl: './app.component.css',
1616
})
@@ -28,9 +28,12 @@ export class AppComponent {
2828

2929
events: string[] = [];
3030

31-
rendererComponents: Type<any>[] = [NgxAnnotationRendererComponent, MyAnnotationRendererComponent];
31+
rendererComponents: Type<NgxAnnotationRendererComponentInterface>[] = [
32+
NgxAnnotationRendererComponent,
33+
MyAnnotationRendererComponent,
34+
];
3235

33-
selectedRendererComponent: Type<any> = NgxAnnotationRendererComponent;
36+
selectedRendererComponent: Type<NgxAnnotationRendererComponentInterface> = NgxAnnotationRendererComponent;
3437

3538
text = 'On August 1, we went on vacation to Barcelona, Spain. Our flight took off at 11:00 am.';
3639

0 commit comments

Comments
 (0)