Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Learning Salesforce Lightning Application Development

You're reading from   Learning Salesforce Lightning Application Development Build and test Lightning Components for Salesforce Lightning Experience using Salesforce DX

Arrow left icon
Product type Paperback
Published in Jul 2018
Publisher Packt
ISBN-13 9781787124677
Length 458 pages
Edition 1st Edition
Arrow right icon
Author (1):
Arrow left icon
Mohit Shrivatsava Mohit Shrivatsava
Author Profile Icon Mohit Shrivatsava
Mohit Shrivatsava
Arrow right icon
View More author details
Toc

Table of Contents (17) Chapters Close

Preface 1. Introduction to the Lightning Component Framework FREE CHAPTER 2. Exploring Salesforce DX 3. Lightning Component Building Blocks 4. The Lightning JavaScript API 5. Events in the Lightning Component Framework 6. Lightning Data Service and Base Components 7. Using External JavaScript Libraries in Lightning Components 8. Debugging Lightning Components 9. Performance Tuning Your Lightning Component 10. Taking Lightning Components out of Salesforce Using Lightning Out 11. Lightning Flows 12. Making Components Available for Salesforce Mobile and Communities 13. Lightning Navigation and Lightning Console APIs 14. Unit Testing Lightning Components 15. Publishing Lightning Components on AppExchange 16. Other Books You May Enjoy

The Lightning Design system

A real-world application involves UI widgets such as lists, tables, cards, modal, and many more. For its Lightning Experience UI, Salesforce uses a common design pattern, which is an open source project known as the Lightning Design System. You can read more about the Lightning Design System, and the patterns and components provided from the official documentation located at https://www.Lightningdesignsystem.com.

Lightning Components can use the styles provided by the Lightning Design System. Let's modify our HelloWorld component to display HelloWorld in a card format, using the card components provided by the Salesforce Lightning Design System (SLDS).

Creating a simple card component using SLDS 

Let's open the Helloworld application we have built so far again and modify it to include the SLDS:

  1. To open the existing Lightning Component, in Developer Console, use File | Open Lightning Resource, search for the HelloWorld component, and select Open Selected.
  2. Copy the code that is in the SLDS card component from SLDS (https://www.Lightningdesignsystem.com/components/cards/).
  3. Paste the markup as it is on the HelloWorld component file. You will get an error, as shown in the following screenshot:
Error when you try using SVG tags in component markup
  1. The error is because of the SVG tag (we will see how to use SVG tags in later chapters). Let's remove the highlighted portion for now to allow the save operation. The complete code for the component is as follows:
<aura:component >
<article class="slds-card">
<div class="slds-card__header slds-grid">
<header class="slds-media slds-media_center slds-has-flexi-truncate">
<div class="slds-media__figure">
</div>
<div class="slds-media__body">
<h2>
<a href="JavaScript:void(0);" class="slds-card__header-link slds-truncate" title="[object Object]">
<span class="slds-text-heading_small">Card Header</span>
</a>
</h2>
</div>
</header>
<div class="slds-no-flex">
<button class="slds-button slds-button_neutral">New</button>
</div>
</div>
<div class="slds-card__body slds-card__body_inner">Card Body (custom goes in here)</div>
<footer class="slds-card__footer">Card Footer</footer>
</article>
</aura:component>
  1. Also, to make sure SLDS is imported into the shell application for testing, we will need to extend the application to use the force:slds base component. Let's modify our HelloworldApp as follows:
<aura:application extends="force:slds">
<c:HelloWorld />
</aura:application>

  1. Let's preview the application and see the SLDS card in the browser. The following screenshot shows the results rendered on the browser:
If you drag these components into the Lightning App Builder, the SLDS will be automatically imported by Salesforce, but for the application created using <aura:application> use extends="force:slds".

The preceding is a simple demonstration of how to use the Salesforce SLDS in Lightning Component Framework. The Lightning Component framework is pretty powerful and provides many components and patterns. As a designer, you can build a complete application using the component set provided. Through this book, as we move ahead, we will use the SLDS extensively to build the UI for our components.

You have been reading a chapter from
Learning Salesforce Lightning Application Development
Published in: Jul 2018
Publisher: Packt
ISBN-13: 9781787124677
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime