Use Salesforce Lightning Design System to Build a Prototype
Learning Objectives
After completing this module, you’ll be able to:
- Break down a project into digestible pieces.
- Utilize the Lightning Design System to rapidly prototype.
- Create a prototyping environment inside Salesforce.
Where to Start?
Starting with a blank page can be daunting. Luckily we have the screens our designers created to help get us started. We use them to break the content into a set of columns to give our layout a grid system.
Ask yourself, is it one large column, or a 1/3–2/3 setup? Is there a header across the top that takes up the full width?
- 1/3 width column
- 2/3 width column
Once that’s done, let’s break down the design further into components, like tab sets, data tables, or cards. This is best done using the Lightning Design System.
Use the Lightning Design System to Your Advantage
By using the Salesforce Lightning Design System (SLDS), we can translate the different sections of the designers’ screens to specific Lightning components that will make development easier.
The design system offers code blocks for many common user interface components, such as data tables, tab sets, and cards. In addition, there are also base lightning components available through Salesforce that we can use without needing to worry about the underlying code. By using both the Lightning Design System and the base lightning components, we can map each portion of the design to components and plan for the pieces that have to be custom made. This lets us put more of our energy toward the implementation.
- Vertical Navigation Component
- SLDS Grid
- Card component
Setting Up a Prototype Inside the Platform
Now let’s create an application inside our Trailhead Playground where we'll implement our prototype. Create a new Trailhead Playground for this module. Using an existing org might create problems when you check the challenge.
By using the Lightning Design System and base lightning components, we can quickly produce a prototype to share with stakeholders.
Create an Application to Host Our Prototype
We create our prototype over 5 steps. Follow along in your Trailhead Playground.
Step 1: Create a Search Proto app in your org
- From Setup, enter App Manager in the Quick Find and select App Manager.
- Click New Lightning App.
- Name the app Search Proto. Clicking on the Developer Name input will auto fill the Developer name to Search_Proto, leave as is.
- Click Next.
- Leave Standard navigation selected, then click Next.
- Click Next again (we don’t need a utility bar).
- We’re not going to add any items to our app yet, so leave Selected Items blank and click Next.
- Highlight all Available Profiles and click the Add icon to move them to Selected Profiles.
- Click Save & Finish.
Step 2: Create a Search Results page using the Lightning App Builder
- From Setup, enter Lightning App Builder in the Quick Find and select Lightning App Builder.
- Click New to add a new lightning app.
- Select App Page and click Next.
- Name the page: Search Results.
- Select the Header and Left Sidebar layout and click Finish.
Step 3: Edit the Search Results page
- In the page editor, use the view selector dropdown at the top of the page and choose Desktop.
- Click Save and then Activate.
- (Optional) Change the app icon.
- Under the Lightning Experience tab, click our Search Proto app, and then click Add page to app.
- Click Save.
- Click Back in the top right corner of the page.
- Click the
App Launcher and select Search Proto.
You should now see a blank Search Results page in your Search Proto app as one of the app’s tabs.
Step 4: Use Developer Console and Lightning Design System to make a custom component
- Click the
setup gear icon and choose Developer Console.
- In Developer Console, select File › New › Lightning Component.
- Enter VerticalNavigation as the name.
- Select all the configuration option checkboxes.
- Click Submit.
- Replace the placeholder code with the following code for the vertical navigation:
<aura:component implements="force:appHostable, flexipage:availableForAllPageTypes,flexipage:availableForRecordHome, force:hasRecordId,forceCommunity:availableForAllPageTypes, force:lightningQuickAction" access="global" > <div class="slds-card"> <div class="slds-grid slds-grid__vertical slds-navigation-list__vertical"> <h2 class="slds-text-title__caps slds-p-around__medium" id="entity-header">Results for 'CO'</h2> <ul> <li class="slds-is-active"> <a href="javascript:void(0);" class="slds-navigation-list__vertical__action slds-text-link__reset" aria-describedby="entity-header"> All </a> </li> <li> <a href="javascript:void(0);" class="slds-navigation-list__vertical__action slds-text-link__reset" aria-describedby="entity-header"> Accounts </a> </li> <li> <a href="javascript:void(0);" class="slds-navigation-list__vertical__action slds-text-link__reset" aria-describedby="entity-header"> Contacts </a> </li> <li> <a href="javascript:void(0);" class="slds-navigation-list__vertical__action slds-text-link__reset" aria-describedby="entity-header"> Leads </a> </li> </ul> </div> </div> </aura:component>
Click File > Save.
Step 5: Use Base Lightning Components to create another custom component
- Still within the Developer Console, select File › New › Lightning Component.
- Enter ResultsSection as the name.
- Select all the configuration option checkboxes.
- Click Submit.
- Replace the placeholder code with the following code for section headings:
<aura:component implements="force:appHostable, flexipage:availableForAllPageTypes,flexipage:availableForRecordHome, force:hasRecordId,forceCommunity:availableForAllPageTypes, force:lightningQuickAction" access="global" > <div class="slds-card"> <h2 class="slds-text-heading__medium slds-p-left_small slds-p-vertical__medium"> Accounts </h2> <div class="slds-grid"> <!-- REPLACE THIS WITH THE CODE FOR ACCOUNT CARDS --> </div> <h2 class="slds-text-heading__medium slds-p-left_small slds-p-vertical__medium"> Contacts </h2> <div class="slds-grid"> <!-- FOR CHALLENGE: REPLACE THIS WITH THE CODE FOR CONTACT CARDS --> </div> <h2 class="slds-text-heading__medium slds-p-left_small slds-p-vertical__medium"> Leads </h2> <div class="slds-grid"> <!-- FOR CHALLENGE: REPLACE THIS WITH THE CODE FOR LEAD CARDS --> </div> </div> </aura:component>
For each section’s content, we add a set of lightning:card components inside the empty <div> tags. Let’s focus on the Account cards for now. After the comment saying <!-- REPLACE THIS WITH THE CODE FOR ACCOUNT CARDS -->, add the following code:
<ul class="slds-col slds-size__1-of-1"> <li class="slds-size__1-of-3 slds-show__inline-block"> <lightning:card variant="narrow" class="slds-m-around__small slds-card_boundary"> <aura:set attribute="title"> Compass Construction Inc. </aura:set> <div class="slds-tile slds-p-horizontal__large"> <div class="slds-tile__detail slds-text-body__small"> <dl class="slds-list__horizontal slds-wrap"> <dt class="slds-item__label slds-text-color__weak slds-truncate" title="First Label">Phone:</dt> <dd class="slds-item__detail slds-truncate">(123) 456-7890</dd> <dt class="slds-item__label slds-text-color__weak slds-truncate" title="Second Label">Website:</dt> <dd class="slds-item__detail slds-truncate">compassinc@construction.com</dd> <dt class="slds-item__label slds-text-color--weak slds-truncate" title="Third Label">Account Owner:</dt> <dd class="slds-item__detail slds-truncate">Amelia Abbott</dd> </dl> </div> </div> </lightning:card> </li> <li class="slds-size--1-of-3 slds-show__inline-block"> <lightning:card variant="narrow" class="slds-m-around__small slds-card_boundary"> <aura:set attribute="title"> Northern Trail Coalition </aura:set> <div class="slds-tile slds-p-horizontal--large"> <div class="slds-tile__detail slds-text-body__small"> <dl class="slds-list__horizontal slds-wrap"> <dt class="slds-item__label slds-text-color__weak slds-truncate" title="First Label">Phone:</dt> <dd class="slds-item__detail slds-truncate">(555) 456-7890</dd> <dt class="slds-item__label slds-text-color__weak slds-truncate" title="Second Label">Website:</dt> <dd class="slds-item__detail slds-truncate">trail@coalition.com</dd> <dt class="slds-item__label slds-text-color__weak slds-truncate" title="Third Label">Account Owner:</dt> <dd class="slds-item__detail slds-truncate">Hadi Samara</dd> </dl> </div> </div> </lightning:card> </li> <li class="slds-size__1-of-3 slds-show__inline-block"> <lightning:card variant="narrow" class="slds-m-around__small slds-card_boundary"> <aura:set attribute="title"> Coffee Corp </aura:set> <div class="slds-tile slds-p-horizontal__large"> <div class="slds-tile__detail slds-text-body__small"> <dl class="slds-list__horizontal slds-wrap"> <dt class="slds-item__label slds-text-color__weak slds-truncate" title="First Label">Phone:</dt> <dd class="slds-item__detail slds-truncate">(123) 555-7890</dd> <dt class="slds-item__label slds-text-color__weak slds-truncate" title="Second Label">Website:</dt> <dd class="slds-item__detail slds-truncate">coffee@corp.com</dd> <dt class="slds-item__label slds-text-color__weak slds-truncate" title="Third Label">Account Owner:</dt> <dd class="slds-item__detail slds-truncate">Franz Jenkins</dd> </dl> </div> </div> </lightning:card> </li> <li class="slds-size__1-of-3 slds-show__inline-block"> <lightning:card variant="narrow" class="slds-m-around__small slds-card_boundary"> <aura:set attribute="title"> Looper Coding Camp </aura:set> <div class="slds-tile slds-p-horizontal__large"> <div class="slds-tile__detail slds-text-body__small"> <dl class="slds-list__horizontal slds-wrap"> <dt class="slds-item__label slds-text-color__weak slds-truncate" title="First Label">Phone:</dt> <dd class="slds-item__detail slds-truncate">(123) 456-0000</dd> <dt class="slds-item__label slds-text-color__weak slds-truncate" title="Second Label">Website:</dt> <dd class="slds-item__detail slds-truncate">looper@codingcamp.com</dd> <dt class="slds-item__label slds-text-color__weak slds-truncate" title="Third Label">Account Owner:</dt> <dd class="slds-item__detail slds-truncate">Carmen Morales</dd> </dl> </div> </div> </lightning:card> </li> </ul>
Click File > Save.
Step 6: Add our components to the page in the page editor
- Back in your org on the Search Results page, click the
setup gear icon and choose Edit Page.
- In the Page Editor, look for VerticalNavigation and ResultsSection components under Custom components.
- Drag the VerticalNavigation component into the left sidebar (the narrow column) of our page.
- Drag the ResultsSection component into the main body (the wide column) of our page.
- Click Save, then click Back.
- Now you should see your Search Results page look like this: