Skip to content

Instantly share code, notes, and snippets.

@mhamzas
Created July 8, 2020 14:13
Show Gist options
  • Select an option

  • Save mhamzas/454978473c593d8397c43fa0442d5dbf to your computer and use it in GitHub Desktop.

Select an option

Save mhamzas/454978473c593d8397c43fa0442d5dbf to your computer and use it in GitHub Desktop.
Toggle Class (Simple Approach)
<template>
<button class={cssClass} onclick={handleToggleClick}>
<lightning-icon icon-name={iconName}></lightning-icon>
Non Profit
</button>
</template>
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