Created
May 4, 2020 23:11
-
-
Save JitendraZaa/7f1253ef9ab2b0234fb2cba14118e194 to your computer and use it in GitHub Desktop.
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
.roundImg{ | |
border-radius: 50%; | |
} |
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
<template> | |
<div> | |
<img src={imgSrc} class={cssClass} /> | |
</div> | |
</template> |
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 { LightningElement, api, track, wire } from 'lwc'; | |
import getMD5Hash from '@salesforce/apex/GravatarController.getMD5Hash'; | |
export default class Gravatar extends LightningElement { | |
@api size; | |
@api email; | |
@track emailHash = '66f795f030fcc5290902fd41eb7386fe'; | |
@api isRoundCorner; | |
//Advantage of getter - if any of property changes like size, it would cause rebinding on UI | |
get imgSrc(){ | |
if(!this.size){ | |
this.size = 150; | |
} | |
return "https://www.gravatar.com/avatar/"+this.emailHash+"?s="+this.size; | |
} | |
//Advantage of getter - if any of property changes like isroundedcorner, it would cause rebinding on UI | |
get cssClass(){ | |
if(this.isRoundCorner){ | |
return 'roundImg'; | |
} | |
} | |
@wire( getMD5Hash , {email : '$email'}) | |
wireMethodCallback({error,data}){ | |
if(data){ | |
this.emailHash = data; | |
} | |
} | |
connectedCallback() { | |
// initialize component - equivalent to init method of Aura | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment