Salesforce Lightning Design System (SLDS)

SLDS for Flask and Angular


At this moment our UI looks ugly without any styles. To make it looks better we can to use any of existing CSS frameworks. I tried Bootstrap (https://getbootstrap.com/), Foundation (https://get.foundation/), UIkit (https://getuikit.com/). But as a Salesforce developer I found SLDS (https://www.lightningdesignsystem.com/) is closer to my heart. Let's add it to our project.

Download last SLDS (current version is 2.11.6) from
https://www.lightningdesignsystem.com/downloads/

Extract it to the ./backend/static/slds folder. There are few other ways to add SLDS to the project:
- from NPM in the Angular subproject. But in this case it can be accessible by Angular only and is compiled as part of the result bundle. But we have Flask project as global playground and few pages (like /auth/login) should work out of the angular context but have the same look.
- external CDN (like https://cdnjs.com/). I like this approach and use it often during development time, but in case of SLDS it doesn't work. SLDS contains great SVG icons collection and SVG flow doesn't work due to security limitations in browsers.
So the right place to use SLDS is ./backend/static folder

Also I create global.css in ./backend/static where I will hold custom styles for global context.

Here is updated base template

./backend/templates/_base.html
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Salesforce Backup Service</title>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

    <link rel="stylesheet" href="/static/slds/styles/salesforce-lightning-design-system.min.css" />

    <link rel="stylesheet" href="/static/global.css">

    {% block header %}{% endblock %}

</head>
<body>

    <div class="main-wrapper">
        <div class="c-header">
            <span class="slds-icon_container slds-icon-custom-custom5" title="Description of icon when needed">
                <svg style="width: 50px; height:50px;" class="slds-icon" aria-hidden="true">
                    <use xlink:href="/static/slds/icons/custom-sprite/svg/symbols.svg#custom5"></use>
                </svg>
            </span>
            <h1 class="c-header-title">Salesforce Backup Service</h1>
        </div>

        <hr />

        <div class="c-body">
            {% block content %}{% endblock %}
        </div>

        <hr />

    </div>

    <footer style="text-align: center;">
        <p>&copy; 2020 - Salesforce Backup Service</p>
    </footer>

</body>
</html>

You should notice two new link tags with css
<link rel="stylesheet" href="...">
and global.css goes after SLDS that allow us to override some standard behavior.

Also as an example of working SLDS I put Logo SVG Icon to header.

SLDS in Flask and Angular project


Comments

Popular posts from this blog

HTTPS in local environment for Angular + Flask project.

Salesforce Authentication 2 (Token Validation and Refresh)

User authentification with Flask-Login