Lightning Stateful Button Component

The lightning:buttonStateful represents a toggleable button state similar to those found on social media. It enables dynamic display of different labels and icons. Specific examples and further information can be found on the Lightning Design System and Salesforce Developer websites.

The lightning:buttonStateful can be used to represent a button state that toggles between states just like you experience on social media. The stateful button can show different labels and icons dynamically.

Below are some examples:

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
<aura:attribute name="buttonstate" type="Boolean" default="false"/>
<lightning:buttonStateful
labelWhenOff="Follow"
labelWhenOn="Following"
labelWhenHover="Unfollow"
iconNameWhenOff="utility:add"
iconNameWhenOn="utility:check"
iconNameWhenHover="utility:close"
state="{! v.buttonstate }"
onclick="{! c.handleClick }"
/>
</aura:component>

({
handleClick : function (cmp, event, helper) {
var buttonstate = cmp.get('v.buttonstate');
cmp.set('v.buttonstate', !buttonstate);
}
})

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
<aura:attribute name="buttonstate" type="Boolean" default="false"/>
<lightning:buttonStateful
state="{! v.buttonstate }"
variant="text"
labelWhenOff="Like"
labelWhenOn="Liked"
iconNameWhenOff="utility:like"
iconNameWhenOn="utility:like"
onclick="{! c.handleClick }"
/>
</aura:component>
view raw LikeButtonCmp hosted with ❤ by GitHub

({
handleClick : function (cmp, event, helper) {
var buttonstate = cmp.get('v.buttonstate');
cmp.set('v.buttonstate', !buttonstate);
}
})

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
<aura:attribute name="buttonstate" type="Boolean" default="false"/>
<aura:attribute name="button1state" type="Boolean" default="false"/>
<lightning:buttonStateful
labelWhenOff="Mute"
labelWhenOn="Muted"
labelWhenHover="UnMute"
iconNameWhenOff="utility:unmuted"
iconNameWhenOn="utility:muted"
iconNameWhenHover="utility:unmuted"
state="{! v.buttonstate }"
onclick="{! c.handleClick }"
/>
</aura:component>
view raw MuteButtonCmp hosted with ❤ by GitHub

({
handleClick : function (cmp, event, helper) {
var buttonstate = cmp.get('v.buttonstate');
cmp.set('v.buttonstate', !buttonstate);
}
})

References:

https://www.lightningdesignsystem.com/components/buttons/#flavor-stateful

https://lightningdesignsystem.com/icons/#utility

https://developer.salesforce.com/docs/component-library/bundle/lightning:buttonStateful/example#lightningcomponentdemo:exampleButtonStateful

Arun Kumar
Arun Kumar

Arun Kumar is a Salesforce Certified Platform Developer I with over 7+ years of experience working on the Salesforce platform. He specializes in developing custom applications, integrations, and reports to help customers streamline their business processes. Arun is passionate about helping businesses leverage the power of Salesforce to achieve their goals.

Articles: 162

Leave a Reply

Discover more from SFDC Lessons

Subscribe now to keep reading and get access to the full archive.

Continue reading

Discover more from SFDC Lessons

Subscribe now to keep reading and get access to the full archive.

Continue reading