Skip to content

Instantly share code, notes, and snippets.

@karkranikhil
Created September 21, 2020 12:53
Show Gist options
  • Select an option

  • Save karkranikhil/d75adbba684943d21b15ab6f47e4fd4d to your computer and use it in GitHub Desktop.

Select an option

Save karkranikhil/d75adbba684943d21b15ab6f47e4fd4d to your computer and use it in GitHub Desktop.
button {
border: none; /* Remove borders */
color: white; /* Add a text color */
padding: 14px 28px; /* Add some padding */
cursor: pointer; /* Add a pointer cursor on mouse-over */
background-color: #e7e7e7;
color: black;
border:1px solid black;
}
.green{
background:green;
}
.red{
background:red;
}
.box{
height:100px;
width:100px;
border:1px solid black;
}
<template>
<div class="slds-m-bottom_large">
<lightning-card title="Getter Demo" icon-name="custom:custom20">
<div class="slds-m-around_medium">
<h1 class="slds-text-heading_large">{getTitle}</h1>
</div>
<div class="slds-m-around_medium">
<button onclick={clickHandler}>ON</button>
<button onclick={clickHandler}>OFF</button>
</div>
<div class="slds-m-around_medium">
<div class={boxStatus}></div>
</div>
</lightning-card>
</div>
</template>
import { LightningElement } from "lwc";
export default class GetterDemo extends LightningElement {
title = "This is a Getter power";
selectedBtn = "OFF";
get getTitle() {
return this.title.toUpperCase();
}
get boxStatus() {
return `box ${this.selectedBtn === 'ON' ? 'green':'red'}`
// return this.selectedBtn === "ON" ? "box green" : "box red";
}
clickHandler(event) {
console.log(event.currentTarget.innerText);
this.selectedBtn = event.currentTarget.innerText;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment