Created
September 14, 2018 17:01
-
-
Save Sunil02kumar/a48809c62468dd54eabc43c4e6431411 to your computer and use it in GitHub Desktop.
Lightning Component for Stopwatch
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
<aura:component > | |
<aura:handler name="init" value="{! this }" action="{!c.doInit}"/> | |
<aura:attribute name="ltngCurrTime" type="String" default="00:00:00"/> | |
<aura:attribute name="ltngIsDisplayed" type="boolean" default="false"/> | |
<div class="slds-card slds-align_absolute-center" style="width:250px;padding:8px;" > | |
<div class="slds-grid slds-wrap" > | |
<div class="slds-col slds-size_1-of-1 slds-align_absolute-center" > | |
<b>Stopwatch</b> | |
</div> | |
<div class="slds-col slds-size_1-of-1 slds-align_absolute-center" > | |
{!v.ltngCurrTime} | |
</div> | |
<div class="slds-col slds-size_1-of-1 slds-align_absolute-center"> | |
<lightning:button variant="brand" label="Start" onclick="{! c.handleStartClick }" disabled="{!v.ltngIsDisplayed}"/> | |
<lightning:button variant="brand" label="Stop" onclick="{! c.handleStopClick }" disabled="{! !v.ltngIsDisplayed}"/> | |
<lightning:button variant="brand" label="Reset" onclick="{! c.handleResetClick }" /> | |
</div> | |
</div> | |
</div> | |
</aura:component> |
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
<aura:application extends="force:slds"> | |
<c:SK_StopWatch /> | |
</aura:application> |
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
({ | |
doInit : function(component, event, helper) { | |
console.log("diinit get called!!"); | |
}, | |
handleStartClick : function(component, event, helper) { | |
console.log("start button clicked!!"); | |
helper.setStartTimeOnUI(component); | |
}, | |
handleStopClick : function(component, event, helper) { | |
console.log("stop button clicked!!"); | |
helper.setStopTimeOnUI(component); | |
}, | |
handleResetClick : function(component, event, helper) { | |
console.log("Reset button clicked!!"); | |
helper.setResetTimeOnUI(component); | |
} | |
}) |
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
({ | |
waitingTimeId: null, | |
setStartTimeOnUI : function(component) { | |
component.set("v.ltngIsDisplayed",true); | |
var currTime =component.get("v.ltngCurrTime"); | |
var ss = currTime.split(":"); | |
var dt = new Date(); | |
dt.setHours(ss[0]); | |
dt.setMinutes(ss[1]); | |
dt.setSeconds(ss[2]); | |
var dt2 = new Date(dt.valueOf() + 1000); | |
var temp = dt2.toTimeString().split(" "); | |
var ts = temp[0].split(":"); | |
component.set("v.ltngCurrTime",ts[0] + ":" + ts[1] + ":" + ts[2]); | |
this.waitingTimeId =setTimeout($A.getCallback(() => this.setStartTimeOnUI(component)), 1000); | |
}, | |
setStopTimeOnUI : function(component) { | |
component.set("v.ltngIsDisplayed",false); | |
window.clearTimeout(this.waitingTimeId); | |
}, | |
setResetTimeOnUI : function(component) { | |
component.set("v.ltngIsDisplayed",false); | |
component.set("v.ltngCurrTime","00:00:00"); | |
window.clearTimeout(this.waitingTimeId); | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment