Last active
November 4, 2019 12:22
-
-
Save armanozak/0c7f0d5ad4dd3a825a96c26090a6f028 to your computer and use it in GitHub Desktop.
Adaptive Components - Dumb Card Image Component #blog
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ChangeDetectionStrategy, Component, Input } from '@angular/core'; | |
@Component({ | |
selector: 'app-card-image', | |
changeDetection: ChangeDetectionStrategy.OnPush, | |
template: ` | |
<img [alt]="alt" [src]="src" [ngClass]="classes" (load)="ready = true" /> | |
<span *ngIf="ready && attribution"> | |
Image by <a [href]="attribution.href">{{ attribution.text }}</a> | |
</span> | |
`, | |
}) | |
export class CardImageComponent { | |
@Input() alt = ''; | |
@Input() attribution = { | |
href: 'https://unsplash.com', | |
text: 'Unsplash', | |
}; | |
@Input() placement: 'top' | 'side' = 'side'; | |
@Input() src = 'https://picsum.photos/200'; | |
ready = false; | |
get classes(): string { | |
return 'card-img-' + this.placement; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment