ABSYZ ABSYZ

  • Home

    Welcome to ABSYZ

  • About us

    Who We Are

  • Our Expertise

    What We Do

  • Our Approach

    How We Do It

  • Products

    What We Made

  • Industries

    Who We Do It For

  • Clients

    Whom We Did It For.

  • Article & Blogs

    What Experts Think

  • Careers

    Join The Team

  • Get In Touch

    Let’s Get Started

ABSYZ

Lightning Reusable Carousel component

Home / Article & Blogs / Salesforce / Lightning / Lightning Reusable Carousel component

Lightning Reusable Carousel component

By Gulafsha Mohammed inLightning, Salesforce, Web Design

Carousels are often thought of as an easy solution to provide better navigation to all the important content/offers on the site. It is used to highlight important information and engage the customers on the go. It is often a hurdle for developers to include a carousel in the code. Here I have written a reusable lightning carousel which can be used anywhere, any number of times.

Reusable Carousel:

A single container with a series of images is all about a lightning:carousel component. This component displays one image at a time, and you can select other images by clicking the carousel indicators.This reusable component uses Lightning:carousel component and lightning:carouselImage component.

Lightning:carousel component is an inbuilt functionality available for salesforce developers. It is one of the simplest way to write a carousel. The main attributes that are used in Lightning:carousel are:

  1. title: Displays tooltip text when the mouse moves over the element.
  2. scrollDuration: The auto scroll duration. The default is 5 seconds, after that the next image is displayed.
  3. disableAutoScroll: Specifies whether auto scroll is disabled. The default value is false.
  4. disableAutoRefresh: Specifies whether the carousel should stop looping from the beginning after the last item is displayed. The default value is false.

Lightning:carouselImage component is used to display images for the carousel. It is used to define all the attributes that are related to the images that are to be included in the carousel. These attributes includes:

1. src : The path of the image is specified here.

2. header : The heading of the image element is specified in this attribute.

3. description : Image description is provided here.

4. alternativeText : When image is not loaded, this text will be displayed.

Steps to write the reusable carousel:

  1. Upload the required images to static resources.
    • Search for static resources in the Quick Find and select Static Resources.Static Resource1
    • Click on the new button and enter the details of the static resource as mentioned in the below image.Also include the image of your choice for the carousel.Static Resource2
    • Repeat step 2 for two more times(As there are three images for this carousel ) include two more static resources named Carousel2 and Carousel3 (You can give any names or choose any number of images but you should make changes in the code accordingly).
  2. Copy the carousel component and js.

Make_Carousel_Comp.cmp:

[sourcecode language=”java”]
<aura:component implements=”force:appHostable, flexipage:availableForAllPageTypes, flexipage:availableForRecordHome, force:hasRecordId, forceCommunity:availableForAllPageTypes, force:lightningQuickAction” access=”global” >
<aura:attribute name=”lstimg” type=”Object[]”/>
<aura:handler name=”init” action=”{!c.listAction}” value=”{!this}”/>
<div class=”slds-align_absolute-center” style=”height: 5rem;”>
<div class=”slds-size_1-of-2″>
<div class=”slds-box slds-align_absolute-center” style=”height: 5rem; position: absolute; width: 300px; height: 200px; z-index: 15; top: 50%; left: 50%; margin: -100px 0 0 -150px; border-color: rgb(255, 255, 255);” >
<!–Set disableAutoScroll=”true” for disabling auto scrolling–>
<lightning:carousel disableAutoScroll=”false”>
<aura:iteration items=”{!v.lstimg}” var=”img”>
<lightning:carouselImage width=”10px” height=”10px” src = “{!img.image}” header = “{!img.Header}” description = “{!img.Description}” alternativeText = “{!img.AlterText}” href = “{!img.imgUrl}”>
</lightning:carouselImage>
</aura:iteration>
</lightning:carousel>
</div>
</div>
</div>
</aura:component>
[/sourcecode]
Make_Carousel_Comp.js:

[sourcecode language=”java”]
({
listAction : function(component, event, helper) {
//change the image names,header,description etc as required
var name=[‘Carousel1′,’Carousel2′,’Carousel3’];
var header=[‘Card1′,’Card2′,’Card3’];
var description=[‘Description1′,’Description2′,’Description3’];
var AlternativeText=[‘Text1′,’Text2′,’Text3’];
var ImageUrl=[‘https://www.salesforce.com’,’https://www.salesforce.com’,’https://www.salesforce.com’];
var b=[‘1′,’2′,’3′,’4′,’5’];
var list1=[];
var a=name.length;

for(var i=0;i<a;i++){
list1.push({image:$A.get(‘$Resource.’+name[i]), Header:header[i], Description:description[i], AlterText:AlternativeText[i], imgUrl:ImageUrl[i]}) ;

}
component.set(“v.lstimg”,list1);
}
})
[/sourcecode]

3. Make the required changes to the component including image names, description, header etc(In js) and styling(In component).

4. Include the carousel component into a record detail page or in an App page.

Make_Carousel_App:

[sourcecode language=”java”]
<aura:application extends=”force:slds”>

<c:Make_Carousel_Comp/>

</aura:application>
[/sourcecode]

5. Test your carousel.

OUTPUT:

This is how our carousel will look like :

 

Note: The images required for carousel are uploaded as static resources. The static resource name is given in the js for carousel images(Carousel1, Carousel2, Carousel3). Other features like header, description etc can also be changed depending on the requirement. A wrapper object ‘lstimg’ is used to wrap the carousel components together. The component iterates over the list to show the carousel. This component uses styling from lightning design system.Do not forget to include force:slds in your code for the application if you are including this component in a stand alone application.

carouselJavascriptlightning carouselLightning componentuser interface
39
Like this post
1 Post
Gulafsha Mohammed

Search Posts

Archives

Categories

Recent posts

SUMMER’21 HIGHLIGHTS: TABLEAU CRM

Is Kanban really helpful in Project Management?

Is Kanban really helpful in Project Management?

Smarter and efficient way of selecting a candidate with Compare Applicant

Smarter and efficient way of selecting a candidate with Compare Applicant

Tableau CRM: Add action buttons on Table without XMD

Tableau CRM: Add action buttons on Table without XMD

jQuery DataTable in Salesforce Lightning Component

jQuery DataTable in Salesforce Lightning Component

  • Previous PostManaging Duplicate Records in Salesforce
  • Next PostDREAMFORCE 2018: TOP 5 Sessions You Cannot Afford to Miss if you are in Sales/ops

Related Posts

Is Kanban really helpful in Project Management?
AppExchange ConnectEazy HRMS Salesforce

Is Kanban really helpful in Project Management?

Smarter and efficient way of selecting a candidate with Compare Applicant
AppExchange ConnectEazy Salesforce

Smarter and efficient way of selecting a candidate with Compare Applicant

Tableau CRM: Add action buttons on Table without XMD
Salesforce Salesforce Einstein Tableau

Tableau CRM: Add action buttons on Table without XMD

jQuery DataTable in Salesforce Lightning Component
Jquery Lightning Salesforce

jQuery DataTable in Salesforce Lightning Component

Leave a Reply (Cancel reply)

Your email address will not be published. Required fields are marked *

*
*

ABSYZ Logo
  • Home
  • About us
  • Article & Blogs
  • Careers
  • Get In Touch
  • Our Expertise
  • Our Approach
  • Products
  • Industries
  • Clients
  • White Papers

ABSYZ Software Consulting Pvt. Ltd.
USA: 49197 Wixom Tech Dr, Wixom, MI 48393, USA
M: +1.415.364.8055

India: 6th Floor, SS Techpark, PSR Prime, DLF Cyber City, Gachibowli, Hyderabad, Telangana – 500032
M: +91 79979 66174

Copyright ©2020 Absyz Inc. All Rights Reserved.

youngsoft
Copy