Created
July 8, 2020 14:13
-
-
Save mhamzas/454978473c593d8397c43fa0442d5dbf to your computer and use it in GitHub Desktop.
Toggle Class (Simple Approach)
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> | |
| <button class={cssClass} onclick={handleToggleClick}> | |
| <lightning-icon icon-name={iconName}></lightning-icon> | |
| Non Profit | |
| </button> | |
| </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, track} from 'lwc'; | |
| export default class PcSelectButtonFramework extends LightningElement { | |
| buttonClicked; //defaulted to false | |
| @track cssClass = 'slds-button slds-button_neutral'; | |
| @track iconName = ''; | |
| // Handles click on the 'Show/hide content' button | |
| handleToggleClick() { | |
| this.buttonClicked = !this.buttonClicked; //set to true if false, false if true. | |
| this.cssClass = this.buttonClicked ? 'slds-button slds-button_outline-brand' : 'slds-button slds-button_neutral'; | |
| this.iconName = this.buttonClicked ? 'utility:check' : ''; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment