Last active
November 8, 2019 08:05
-
-
Save armanozak/249f2f8951d1c4f98d7a9c382ca4833b to your computer and use it in GitHub Desktop.
Adaptive Components - Not-So-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, | |
Optional, | |
} from '@angular/core'; | |
import { CardVerticalComponent } from './card-vertical.component'; | |
@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() src = 'https://picsum.photos/200'; | |
ready = false; | |
classes = `card-img-${this.vertical ? "top" : "side"}`; | |
constructor(@Optional() public vertical: CardVerticalComponent) {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment