Revisiting design systems
Design systems are interesting because of how they scale design to multiple teams and multiple sites/products while still providing a consistent and recognizable brand. For a full introduction to design systems, see [Introducing Design Systems](https://www.designbetter.co/design-systems-handbook/introducing-design-systems) The work I do is not always conducive to creating a design system but it's always good to know about them so we can jump in without having to start completely from scratch. That said we'll look at three areas: - Building a basic component using just HTML, and CSS - Building the same component using existing design systems - Material Design from Google - Atomic Design from Brad Frost - Building the component using Web Components - Plain Web Components - Polymer ## No Design Systems I want to design a card component where we can control the direction (vertical or horizontal), the dimensions (height and width) and the border. The component should also provide ways to layout its children using Flex. The CSS looks something like this: ```css :root { --card-border-color: #000; --card-border-width: 1px; --card-border-style: solid; --card-display: flex; --card-direction: column; --card-width: 400px; --card-height: 300px; --card-padding: 1em; } .card { display: var(--card-display); flex-flow: var(--card-direction); border: var(--card-border-width) var(--card-border-style) var(--card-border-color); height: var(--card-height); width: var(--card-width); } .card-title { color: #fff; background-color: #000; } .card-content { padding: var(--card-padding); } ``` The idea is that by changing the value of the variable declared in the `:root` element we change the way that all card elements will look on the page. I choose the `: root` element rather than `HTML` because `:root` has higher specificity and it would override any declarations in HTML rather than having to depend on the way properties were declared every time. Let's say that we want to create a horizontal card. All we have to do is redefine the variables for the elements we need to change, something like the following example: In this example, we make the card layout its children in a row, rather than a column, we also change the dimensions of the card but we keep all other values the same as our `:root` declaration. ```css :root { --card-border-color: #000; --card-border-width: 1px; --card-border-style: solid; --card-display: flex; --card-direction: column; --card-width: 400px; --card-height: 300px; --card-padding: 1em; } .card2 { --card-border-color: #000; --card-direction: row; --card-height: 300px; --card-width: 800px; border: var(--card-border-width) var(--card-border-style) var(--card-border-color); display: var(--card-display); flex-flow: var(--card-direction); height: var(--card-height); width: var(--card-width); .card-title { width: 10em; } } ``` This is just an initial step, we could further refine the card component by providing defaults in case we want to add an image instead of text on the title, but it'll do as the basic example of what we want to accomplish. One other thing that needs to happen for this card to become an element is to document the ways in which you can customize the component... ideally with full examples that can be copy and pasted to be used. ## Design System Now that we have a basic idea of what we want to do, let's look at different ways in which design systems can make the process easier, less painful or both. ### Material Design The new iteration of material design has its good and bad aspects. The good is that the new version is much easier to customize and make look "less like a Google product" than the original The bad is that Material Design now requires SCSS and ES6 for development. You can't just drop the Material Design components into an existing project if the project doesn't use a build system or SASS to process the CSS. Since I already use both ES6 and SCSS for my projects, I think the drawbacks, if you can call them that, are worth the investment. As you can see the code depends heavily on classes starting with `mdc-`. The reason why will become clearer when we look at the SCSS code that styles the element. ```html
Title
Content goes here
Card Title
I want to design a card component
Title
Content
Card Demo #2
Some content that is different from our default
Title
Content
Card Demo #2
Some content that is different from our default so we can be sure that the slots are working as intended and we are not pulling the default content