On March 2nd, version 1.0.0 of the Lightning Design System was released. Seemed to us like a great time to take a quick tour of the system and a few of the core features available.
Let’s start with a brief introduction.
Introducing the Lightning Design System
The Lightning Design System is a CSS framework that gives you all of the power of the Salesforce user interface without having to do any re-engineering. The design system consists of the following pieces:
- Design Guidelines: The design principles that Salesforce adheres to when building their products. There are a variety of topics covered such as aesthetic guidelines (color palette, typography), suggested layouts, and recommendations for dealing with complex input.
- Resources: The assets (fonts, icons, images and styles) that make up the Salesforce user interface, specifically Lightning Experience.
- Web Components: Dozens of HTML components that are built with design system resources. Many of them are ready to use and can be pasted directly into your application code.
- Native Components: An iOS library that brings the design system assets to your native iOS applications.
Best of all, the Lighting Design System is open source! Repositories are available on GitHub. You can even contribute by creating an issue, forking a repository and submitting a pull request.
Now let’s take a peek under the hood and check out some of the design system components…
The Salesforce Sans fonts (TrueType and web fonts) are packaged with the design system and are ready to use in your application. Here is a snippet of CSS that imports a few of the web fonts as a user-defined font family called SalesforceSans:
And here’s what these fonts look like in action:
The SalesforceSans-Bold font.
The SalesforceSans-Italic font.
The design system is packaged with many of the icons that you see in the Salesforce user interface. They are available as individual PNG files at 33x33 and 65x65 resolutions, individual SVGs, or via a single SVG sprite map that contains all of the icons in a single file. It is a best practice to use the sprite map and reference the exact icon inside of an HTML SVG element.
Icons are categorized by type. There are five icon groups:
- Actions – Things a user can do, like download a file, follow a record, edit a record, etc.
- Document Types – These are visual representations of common file types such as Word, Excel and PDF.
- Standard icons – The icons that are used to represent standard Salesforce objects, like Account and Case.
- Custom icons – Icons for user created objects.
- Utility – Miscellaneous icons that share a common color scheme. There is some overlap here between the action icons and utility icons.
Using the svg tag, you can link to an icon in the sprite map by supplying the corresponding style and icon name. You can also use size modifiers to upscale or downscale the icon image. An example:
There are dozens of icons available for use, check the documentation for the full list.
A key feature of the Lightning Design System is a mobile-first grid for designing layouts that look good on any device. Design system grids follow the principles established in Flexible Layouts and can take care of the work that would have formerly required another mobile-first framework such as Twitter Bootstrap.
Let’s start with a simple example of a two-column grid:
This snippet illustrates the two basic components of any grid: a container div (slds-grid) and the columns (slds-col). Now let’s spice it up a bit by using sizing helpers and breakpoints to make it responsive.
Sizing helper classes tell the browser how much of the available container space should be occupied by a given column. This is done using an “X-of-Y” syntax, which reads as “takes up X amount of a total available space of Y”. For example, if the first column in a two-column grid has a size “1-of-3”, the column will occupy 33% (1 divided by 3) of the available space in the container (typically the grid div).
Breakpoints can be added to sizing helpers to specify behavior for small, medium and large sized displays. A default helper with no breakpoint is required, and should be the first one specified in the class attribute. Additional breakpoints should be added to the class attribute in order of size ranging from smallest to largest. Breakpoints are optional and you do not need to override every breakpoint. For example, if you choose to override medium, you do not need to override small; you do, however, need to provide a default breakpoint.
Here is the code for a two-column grid that stacks until the container reaches the medium breakpoint size, at which point the columns appear side-by-side:
Here’s what it looks like in action. Go ahead and resize the window, you should see the stacking behavior (assuming you have at least a medium-sized display):
We’ve only scratched the surface of what’s available in the Lightning Design System. Aside from the documentation, Trailhead is an excellent resource for getting up to speed in a variety of contexts, including Lightning Components and Visualforce. With so much available for developers to take advantage of, it’s never been easier to build beautiful applications.