<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Simeon Simeonoff on Medium]]></title>
        <description><![CDATA[Stories by Simeon Simeonoff on Medium]]></description>
        <link>https://medium.com/@simeonoff?source=rss-96b72f1c3d09------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*bqDw3cAoy00yufAmqE-xUQ.jpeg</url>
            <title>Stories by Simeon Simeonoff on Medium</title>
            <link>https://medium.com/@simeonoff?source=rss-96b72f1c3d09------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 00:50:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@simeonoff/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Architect a Theming System — Component Themes with Sass — Part 3]]></title>
            <link>https://medium.com/@simeonoff/architect-a-theming-system-component-themes-with-sass-part-3-142e79ab590e?source=rss-96b72f1c3d09------2</link>
            <guid isPermaLink="false">https://medium.com/p/142e79ab590e</guid>
            <category><![CDATA[sass]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[theming]]></category>
            <dc:creator><![CDATA[Simeon Simeonoff]]></dc:creator>
            <pubDate>Wed, 18 Sep 2019 08:46:09 GMT</pubDate>
            <atom:updated>2019-09-18T08:47:17.871Z</atom:updated>
            <content:encoded><![CDATA[<h3>Architect a Theming System — Component Themes with Sass — Part 3</h3><figure><img alt="Photo by RhondaK Native Florida Folk Artist on Unsplash" src="https://cdn-images-1.medium.com/max/1024/1*Ivou1p0qSO9zxbA9jawabQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@rhondak?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">RhondaK Native Florida Folk Artist</a> on <a href="https://unsplash.com/search/photos/colors?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>In my previous two articles I talked about coming up with strategies for building reusable component themes by structurally splitting our components into several parts, one of which was colors and palettes.</p><p>If you haven’t read them yet, here are the links:</p><ul><li><a href="https://medium.com/@simeonoff/architect-a-theming-system-for-reusable-web-components-part-1-51787154a667">Architect a Theming System for Reusable Web Components — Part 1</a></li><li><a href="https://medium.com/@simeonoff/architect-a-theming-system-colors-palettes-part-2-ac72661df423">Architect a Theming System — Colors &amp; Palettes — Part 2</a></li></ul><p>In this article I will expand on those ideas by providing a more practical approach to solving the problem of component themes in <a href="https://sass-lang.com/">Sass</a>. We will be using the palette and color functions we’ve created in <a href="https://medium.com/@simeonoff/architect-a-theming-system-colors-palettes-part-2-ac72661df423">Part 2</a>, as well as some additional utility functions and mixins.</p><p>Here are the requirements that our component themes should fulfil:</p><ul><li>Component themes modify the visual properties of a component, such as colors, roundness, and elevation, etc;</li><li>Component themes should be based on a blueprint, which we will call <em>schema.</em> Each component theme should have its own schema;</li><li>A component schema should not carry any hard-coded values, such as colors or sizes. It’s only a prescription for an eventual component theme;</li><li>Component themes should accept palette as an input;</li><li>Component themes should be extensible;</li><li>Component themes should be reusable;</li><li>The output of a component theme is only compiled into CSS if the theme is included using the @include directive;</li><li>Component themes should support custom CSS properties (variables) so they can be modified after compilation, i.e. outside of Sass; <strong>**</strong></li></ul><p>In case you are curious about the end result before reading the article, you can explore the full implementation in this <a href="https://codesandbox.io/s/jovial-chatelet-94cwf"><strong>CodeSandbox Sample</strong></a>.</p><h3>API Overview</h3><p>Instead of jumping straight down to the implementation details of each of the requirements, let’s take a look at how we want the finalized API to look and feel like for the end user.</p><pre>// 1. Create a color palette<br>$my-palette: palette(royalblue, seagreen);</pre><pre>// 2. Include the predefined component styles by passing the<br>// palette and schema for the given component<br>.component {<br>  @include component($palette, $schema);<br>}</pre><p>In step 1 of our sample API we call a function unimaginatively named palette that returns a map of colors that will be used by the mixin component we call in step 2.</p><p>The mixin component should resolve the component $schema by going through each of its properties, applying the values of $palette.</p><h3>Component Schemas</h3><p>Component schemas are simple recipes that inform the component theme about its properties — what color variants from the palette a specific part of the component should use, what its roundness factor(s) should be, i.e. the value of the border radius between a minimum and a maximum value, and what elevation (shadow) the component should throw in its different states (resting, hover, active, etc.). We will cover roundness and elevation in another article for the sake of brevity.</p><p>To illustrate the concepts in this article, let’s assume we want to create a functional component theme a with proper schema for a button component.</p><p>Here’s the design of our button component:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/716/1*bht-ylW2oqGG-HEiKLCW3Q.jpeg" /></figure><p>We can immediately notice that the button has 4 states, two of which have the same style, but we shouldn’t assume that the user of our theming system shouldn’t be allowed to choose a different background/text color when the component is in its focus state.</p><p>Here’s some additional information about the component design, that isn’t immediately obvious from the picture above:</p><p>— the<strong> </strong>default<strong> border-radius</strong> on all sides is <strong>4px</strong></p><p>— the default <strong>background-color </strong>in each of the 4 states:</p><ul><li>Resting State — Primary 500</li><li>Hover State — Primary 700</li><li>Focus State — Primary 700</li><li>Disabled State — Gray 100</li></ul><p>— the default <strong>text color </strong>in each of the 4 states<strong>:</strong></p><ul><li>Resting State — #fff</li><li>Hover State — #fff</li><li>Focus State — #fff</li><li>Disabled State — Gray 300</li></ul><blockquote><em>A note about the text colors — </em><a href="http://www.w3.org/TR/WCAG20/"><em>WCAG2</em></a><em> level AAA calls for a 7:1 contrast ratio of normal text against the background it sits on top of for better accessibility. It could be useful to use/write a function that returns the contrast color for a given color according to the WCAG2 standards, which is exactly what we do in our actual implementation.</em></blockquote><p>It becomes apparent from the list of properties above that we need at least 9 properties — 4 for the background colors, 4 for the corresponding text colors and 1 for the border-radius; This is where schemas come into play. The button schema is simply a map of key value pairs that describe the aforementioned properties. Here’s how the schema for the button will look like:</p><pre>$button-schema: (<br>  border-radius: 4px,</pre><pre>  resting-background: (<br>    color: (&#39;primary&#39;, 500)<br>  ),</pre><pre>  resting-text-color: (<br>    contrast-color: (&#39;primary&#39;, 500)<br>  ),</pre><pre>  hover-background: (<br>    color: (&#39;primary&#39;, 700)<br>  ),</pre><pre>  hover-text-color: (<br>    contrast-color: (&#39;primary&#39;, 700)<br>  ),<br>  <br>  focus-background: (<br>    color: (&#39;primary&#39;, 700)<br>  ),</pre><pre>  focus-text-color: (<br>    contrast-color: (&#39;primary&#39;, 700)<br>  ),</pre><pre>  disabled-background: (<br>   color: (&#39;gray&#39;, 100)<br>  ),</pre><pre>  disabled-text-color: (<br>   color: (&#39;gray&#39;, 500),<br>   transparentize: .12<br>  )<br>);</pre><p>This way of describing the default properties of a theme can look a little weird at first. The idea is to escape from having hard values assigned. The schema above doesn’t know anything about the values behind the primary color palette.</p><blockquote>A side note — Unfortunately, Sass isn’t a typed language, and this makes things a bit more unstable. If we ensure, however, that all color variants are part of the palette we resolve the values from, then this approach should be a-okay.</blockquote><p>Now, the other thing above is how colors are described in their own map, for instance:</p><pre>disabled-text-color: (<br> color: (&#39;gray&#39;, 500),<br> transparentize: .12<br>)</pre><p>When properties are described using a map, such as the one above, then we consider that to be a set of instructions, where the key color is a function name and the value (gray, 500) is the arguments the function will receive. The output of the color function call is then fed to the next function in the map, i.e. transparentize as its first argument and the value .12 as a second argument. In the next section we take a look at how we resolve those maps. <strong><em>The important takeaway here is that we don’t really know anything about the palette yet.</em></strong> This is why we expect the user to pass both a <em>palette</em> and a component <em>schema</em>. We take both and mix them to produce the final values.</p><h3>Resolving Schema Values</h3><p>Let’s create a function that is capable of resolving the values in a schema. The function will accept an instruction map and call each function with its arguments, then pass the result to the next function and so on until completion:</p><pre><a href="http://twitter.com/function">@function</a> resolve-value($map, $extra: null) {<br>  $result: null;<br>  <br>  // Iterate over the &lt;key&gt;:&lt;value&gt; pairs in the instruction map<br>  <a href="http://twitter.com/each">@each</a> $fn, $args in $map {<br>    <br>    // Check if the function exists before trying to execute it<br>    <a href="http://twitter.com/if">@if</a> function-exists($fn) {<br>      <br>      // get a handle to the function<br>      $fn: get-function($fn);<br>      <br>      <a href="http://twitter.com/if">@if</a> $result == null {</pre><pre>        <a href="http://twitter.com/if">@if</a>($extra) {<br>          $result: call($fn, $extra, $args...);<br>        } <a href="http://twitter.com/else">@else</a> {<br>          $result: call($fn, $args...);<br>        }<br>      } <a href="http://twitter.com/else">@else</a> {<br>        $result: call($fn, $result, $args...)<br>      } <br>    }<br>  }<br>  <br>  <a href="http://twitter.com/return">@return</a> $result;<br>}</pre><p>We first iterate over the key-value pairs inside the instructions map and extract each key as a function name and the value as the arguments to be passed to the function. We then check whether the function exists before proceeding to calling it. Then we check whether there’s anything stored in the $results reference. If there’s nothing we check if there’s any $extra arguments we want to pass to the function and call it. The produced value is then stored in the $results reference. After the first function has been executed, every consecutive function (if any) in the map will be called with the value of $result as its first argument. Any supplied arguments will then be passed to the function call. If there are no more functions, we return the final $result.</p><p>If we run an instruction set through the resolve-value function, we will get a color from the palette we passed as an extra argument; Here’s an example:</p><pre>// Create a palette<br>$palette: palette(royalblue, seagreen);</pre><pre>// Create an instruction map<br>$value: (<br> contrast-color: (&#39;secondary&#39;, 400),<br> transparentize: .12<br>);</pre><pre>// Resolves to rgba(58, 148, 98, 0.88);<br>$resolved-value: resolve-value($value, $palette);</pre><p>Now that we have a function that can resolve values given an instruction set and a palette, we need a function that can go through an entire schema and resolve all values from any instruction set. Let’s create that function next:</p><pre>@function resolve-schema($schema, $palette) {<br>  $result: ();<br>  <br>  <a href="http://twitter.com/each">@each</a> $key, $value in $schema {<br>    <a href="http://twitter.com/if">@if</a> type-of($value) == &#39;map&#39; {<br>      $result: map-merge(<br>        $result, <br>        (<br>          #{$key}: resolve-value($value, $palette)<br>        )<br>      );<br>    } <a href="http://twitter.com/else">@else</a> {<br>      $result: map-merge(<br>        $result, (<br>          #{$key}: #{$value}<br>        )<br>      );<br>    }<br>  }</pre><pre>  <a href="http://twitter.com/return">@return</a> $result;<br>}</pre><p>The function resolve-schema takes two input arguments — a $schema and a $palette; We iterate over the schema to get each key-value pair in the map; If the value is of type map, we assume it’s an instruction set that needs to be resolved to a value, so we call the resolve-value function on it with the value, and since we are going to be resolving colors, we pass the $palette as an <em>extra</em> argument. We then merge the resolved value in a $result map with the $key from the schema; In case the $value is not a map, we merge it as it is in our $result map; Finally, we return the $result map to the user with all schema values now resolved.</p><h3>Theme Mixins</h3><p>Now that we have a strategy fоr describing themes in terms of colors, we can proceed to coming up with a pattern for how those themes can produce CSS. We will use a mixin to build our button theme.</p><p>The ides is that our button theme will accept a schema and a palette, resolve the schema with the given palette, then use the resolved values inside the CSS rules. Let’s get started:</p><pre>@mixin button($palette, $schema) {<br>  $theme: resolve-schema($schema, $palette);</pre><pre>  display: inline-flex;<br>  align-items: center;<br>  justify-content: center;<br>  border: none;<br>  outline-style: none;<br>  background-color: map-get($theme, &#39;resting-background&#39;);<br>  color: map-get($theme, &#39;resting-text-color&#39;);<br>  border-radius: map-get($theme, &#39;border-radius&#39;);<br>  padding: 12px 16px;<br>  font-size: 14px;<br>  cursor: pointer;<br>  transition: background-color .25s ease-out;<br>    <br>  &amp;:hover {<br>    background-color: map-get($theme, &#39;hover-background&#39;);<br>    color: map-get($theme, &#39;hover-text-color&#39;);<br>  }<br>    <br>  &amp;:focus {<br>    background-color: map-get($theme, &#39;focus-background&#39;);<br>    color: map-get($theme, &#39;focus-text-color&#39;);<br>  }</pre><pre>  &amp;[disabled] {<br>    background-color: map-get($theme, &#39;disabled-background&#39;);<br>    color: map-get($theme, &#39;disabled-text-color&#39;);<br>    pointer-events: none;<br>  }</pre><pre>  @content;<br>};</pre><p>As you can see from the sample above, all of our colors are consumed from the resolved theme. We can now customize the button by just altering the palette/schema passed to the button mixin. We can have unlimited palettes and schemas that we can pass around to button mixins.</p><pre>$royal-palette: palette(royalblue, seagreen);<br>$firebrick-palette: palette(firebrick, orange);</pre><pre>.royal-button {<br>  @include button($royal-palette, $button-schema);<br>}</pre><pre>.firebrick-button {<br>  @include button($firebrick-palette, $button-schema);<br>}</pre><p>Now we can apply the produced button styles to some markup:</p><pre>&lt;button class=&quot;royal-button&quot;&gt;Royal&lt;/button&gt;<br>&lt;button class=&quot;firebrick-button&quot;&gt;Firebrick&lt;/button&gt;</pre><p>We can even change the recipe for each button by extending the original $button-schema:</p><pre>// Create a new button schema from the original<br>$custom-button-schema: extend(<br>  $button-schema,<br>  (<br>    resting-text-color: (secondary, 500)<br>  )<br>);</pre><pre>// Pass the new schema to our firebrick button<br>.firebrick-button {<br>  @include button($firebrick-palette, $custom-button-schema);<br>}</pre><p>This approach allows us to separate the structural styles of a component, in this case the button, within its own mixin, leaving all other aspects of it stored in a schema and a palette, exposing just the parts we want. This allows us to modify the underlying styles, without affecting the end-user experience in case future versions of the theme are introduced. We can add more properties to the schemas and still preserve backward compatibility.</p><p>In the next part, we will incorporate custom CSS properties without changing the much about the current approach. This will allow the users of our themes to be able to alter the colors of the theme by changing the value of the corresponding CSS variable.</p><p><strong>**</strong> Some of the functions used to achieve the end result were not explained in this article. If you want to explore a working implementation of the approach described here, please take a look at the full <a href="https://codesandbox.io/s/jovial-chatelet-94cwf"><strong>CodeSandbox Sample</strong></a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=142e79ab590e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Architect a Theming System — Colors & Palettes — Part 2]]></title>
            <link>https://medium.com/hackernoon/architect-a-theming-system-colors-palettes-part-2-ac72661df423?source=rss-96b72f1c3d09------2</link>
            <guid isPermaLink="false">https://medium.com/p/ac72661df423</guid>
            <category><![CDATA[design-systems]]></category>
            <category><![CDATA[colors]]></category>
            <category><![CDATA[sass]]></category>
            <category><![CDATA[material-design]]></category>
            <dc:creator><![CDATA[Simeon Simeonoff]]></dc:creator>
            <pubDate>Tue, 19 Feb 2019 15:41:52 GMT</pubDate>
            <atom:updated>2019-02-19T15:59:55.453Z</atom:updated>
            <content:encoded><![CDATA[<h3>Architect a Theming System — Part 2 — Colors &amp; Palettes</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7ftkP9YZT3U13NbAcmmTZg.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/photos/1fj5teDyPUY?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Steve Johnson</a> on <a href="https://unsplash.com/search/photos/color-palette?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>In my <a href="https://blog.usejournal.com/architect-a-theming-system-for-reusable-web-components-part-1-51787154a667">previous article</a> I talked about the theoretical concepts and possible strategies to building a theming system for reusable web components when it comes to colors and shadows.<br>In this article we will implement the proposed strategy for colors by making a palette-producing function in Sass.</p><h3>About Colors</h3><p>Colors are unquestionably one of the defining characteristics of any UI. In fact, colors are paramount to how we perceive the world, and as such, one of the main communication channels between the designer and the user of an application. Having a well defined and structured set of colors is crucial to building a theming system. It ensures visual consistency between one color scheme and another. Thankfully, we have had the concept of digitally organizing colors since the dawn of the monochrome computer monitor — using palettes.</p><h3>Color Palettes</h3><p>Essentially, a color palette is a set of two or more colors. It can consist of just monochromatic colors, or colors across the entire visible spectrum. So how do we pick colors to put in our color palette?</p><p>For a design to look interesting and engaging, we need to create contrast between the different visual elements. Having at least two colors on the opposite ends of the color spectrum is a good place to start. In fact, if you search the internet about how color palettes in design systems are built, they usually consist of at least two colors, usually — primary and secondary. Most design guides will have detailed instructions as to how those colors should be used. By keeping the amount of colors to just 2 or 3, we reduce the visual clutter without depriving the design of flavor.</p><h3>Colors In Code</h3><p>Instead of trying to reinvent the wheel, we can start from an existing color system and try to implement it using some language.</p><p>Since I am most familiar with <a href="https://material.io/design/color/the-color-system.html">Google’s Material Color System</a>, I will use that and the <a href="http://sass-lang.com/">Sass</a> language to transform the spec into usable color functions for generating palettes and getting the colors from those palettes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*saVagOlzqtwnd7CI7Om-GA.png" /><figcaption>Base Material Color Palette</figcaption></figure><p>Taking a look at the base palette in the Material Color System, we immediately see that it consists of 2 colors — primary and secondary. Each of those colors is made up of 10 color shades, enumerated as variants, using numbers from 50 through 900.</p><p>The naive approach to represent those palette colors in code would be do declare each of the color variants as variables, like so:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2ff46d35dbf8038bc6f4b8ce8173035f/href">https://medium.com/media/2ff46d35dbf8038bc6f4b8ce8173035f/href</a></iframe><p>The above approach would work if this was a one-off task. We, however, want to build a theming framework. You can imagine that setting 20 colors by hand for each theme we want to create can become a demanding process. You would have to determine each shade in the palette manually.</p><p>So what would the specification for automating the making of color palettes look like? Here’s a 2-point spec:</p><p><em>1. As a user I want to be able to provide a base color from which all other shades of that color in the palette get generated automatically for me.</em></p><p><em>2. As a user I want to be able to easily retrieve any color of any palette by providing the palette name, color name, and variant.</em></p><p>Now that we know the requirements, we can start by thinking of the data structure for our color palette. Maps in Sass are a pretty good candidate for what we’re trying to achieve. You can easily retrieve any value from a <em>map</em> in Sass by its key. Let’s transform the above palette into a map:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/623dfe0555a2d9f0e5a006bf97be1cc8/href">https://medium.com/media/623dfe0555a2d9f0e5a006bf97be1cc8/href</a></iframe><p>Using the built-in map-get function in Sass, we can retrieve any value from our palette. You will notice that our $palette map contains 2 properties — primary and secondary. Each of those is a color in our palette and a Sass map consisting of 10 color shades.</p><p>To retrieve a color from our palette we would first have to get the color map:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a649b3e24c566d5005cb20928809f5ee/href">https://medium.com/media/a649b3e24c566d5005cb20928809f5ee/href</a></iframe><p>Then we can retrieve any of the color variants(shades) of the primary color by using map-get again. Let’s get the 500 variant of the primary color:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/166a24f9e9d0f7ac49b6adc731111316/href">https://medium.com/media/166a24f9e9d0f7ac49b6adc731111316/href</a></iframe><p>Or we can shorten this whole process by doing:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f0fc1d315d08a41b4fd24017a1cbaf34/href">https://medium.com/media/f0fc1d315d08a41b4fd24017a1cbaf34/href</a></iframe><p>The above approach for retrieving colors from our palette works, but it’s not very elegant. We can write a simple function that accepts a palette, color, and variant as its parameters and returns a color shade from any palette. Let’s declare a function called color that does just that:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/802276ce50224e00fd3511b678d8b423/href">https://medium.com/media/802276ce50224e00fd3511b678d8b423/href</a></iframe><p>Now we can get any of the color variants from our palette by calling the color function.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2af09da6c39eff03c2590a1f8e51ac65/href">https://medium.com/media/2af09da6c39eff03c2590a1f8e51ac65/href</a></iframe><p>Cool, now we have a function that, given the data structure of the palette we defined above, can retrieve any of the color variants it contains. With this, we have satisfied point 2 of our spec.</p><p>Creating a solution for generating a color palette from a single color shade is a bit more involved. It would require us to come up with an algorithm for generating color shades.</p><h3>Generating Palettes</h3><p>We know that a single color has 10 shades. If we pick the 500 variant as the base color that would mean that there are 4 darker and 5 lighter shades. The Material Color System doesn’t prescribe an algorithm for generating the shades of a single color in the palette, so we have to come up with a system on our own. Fortunately, Sass gives us enough built-in functions for working with colors, so this should make our lives a bit easier.</p><p>Here’s a function that generates 10 color shades for us:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f31f707d8d50f7c44654d2cd85132f17/href">https://medium.com/media/f31f707d8d50f7c44654d2cd85132f17/href</a></iframe><p>Let’s explain what’s going on here. Our color-shade function accepts a color and a variant. The color parameter is the base color shade from which we generate the other 9 shades. The variant is the shade variant we want to get a value for. The value produced for each shade is the result of lightening/darkening and saturating/desaturating the base color. The amount by which we lighten/darken or saturate/desaturate the base color is very opinionated. You can change any of those values and come up with a different color palette yourself. I picked those values as I thought they produced a good set of shades for a wide range of colors — from hot colors, such as red, through cold ones, like blue.</p><p>We will use the color-shades function inside another function that will be generating our palettes.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/45cd9b05d31f7d565fd65dbbc76abba4/href">https://medium.com/media/45cd9b05d31f7d565fd65dbbc76abba4/href</a></iframe><p>The function above produces all the color variants for both the primary and the secondary colors by utilizing the color-shade function; The palette function iterates over a list of predefined variants and produces a color shade for each variant using the primary and secondary input parameters.</p><p>Let’s use the palette function to generate a color palette:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eba39373866db820f1f4db5490b66ed7/href">https://medium.com/media/eba39373866db820f1f4db5490b66ed7/href</a></iframe><p>Because the generated palette has the same shape as the one we came up with in the beginning of this article, we can now use the color function to retrieve any of the color variants from the palette.</p><p>We have now satisfied both requirement in our specification. We can easily build as many color palettes as we want using our palette function and retrieve any of the colors from the palette using the color function.</p><h3>Conclusion</h3><p>By coming up with a data structure for organizing colors, the way we did for our palette map, we gain the power to automate the process of generating and retrieving colors. With that in place we can now just start plugging in colors into the palette function we’ve created.</p><p>In the next article we are going to be implementing the foundations for our component themes in Sass, having a go at a few strategies for better scaling and maintainability of our themes.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ac72661df423" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/architect-a-theming-system-colors-palettes-part-2-ac72661df423">Architect a Theming System — Colors &amp; Palettes — Part 2</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Architect a Theming System for Reusable Web Components — Part 1]]></title>
            <link>https://medium.com/hackernoon/architect-a-theming-system-for-reusable-web-components-part-1-51787154a667?source=rss-96b72f1c3d09------2</link>
            <guid isPermaLink="false">https://medium.com/p/51787154a667</guid>
            <category><![CDATA[sass]]></category>
            <category><![CDATA[design]]></category>
            <category><![CDATA[design-systems]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Simeon Simeonoff]]></dc:creator>
            <pubDate>Tue, 22 Jan 2019 11:53:07 GMT</pubDate>
            <atom:updated>2019-01-24T18:23:55.755Z</atom:updated>
            <cc:license>http://creativecommons.org/licenses/by/4.0/</cc:license>
            <content:encoded><![CDATA[<h3>Architect a Theming System for Reusable Web Components — Part 1</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T5H3JvS9KAJqApNBVniHTQ.jpeg" /><figcaption>Photo by Pierre Bamin</figcaption></figure><p>Building reusable components for the web or otherwise is hard. It’s hard because you have to think of the hundred situations your component might be used in. Apart from being functional, the components you are building have to be <em>extensible</em>, <em>accessible</em>, and what concerns me the most — <strong><em>themeable</em></strong>.</p><p>Every time we start laying out the spec for a new component, we have to immediately start thinking about all aspects of how a component can morph. Could it lose its shadows, borders, change text or background colors? Do we allow the user to change its typography? What if it’s used in a right-to-left context? These are just some of the questions you have to ask yourself when building reusable, themeable components.</p><p>Then comes environment and tooling. What platform are you building for? Do you know your audience? Your audience’s audience? Can you really come up with a single design language that works for everyone? The answer to most of those questions is — I don’t know. I’d like to know, and when I am not completely sure I know, I want to make it so that the things I build can be adaptable and composable.</p><p>Enough beating around the bush, let’s talk about how we approached some of those problems and what solutions we came up with to make our components themeable.</p><p>This is just the first of a series of articles I am planning to write to share what my colleagues and I have learned in the process of trying to come up with a themeing system that allows users to change colors, shadows, and typography in the components we build.</p><p><em>A few disclaimers (order doesn’t matter):</em></p><ul><li><em>This series is by no means a tutorial, though, feel free to use it for whatever purposes you wish. It’s simply a case-study on what we do.</em></li><li><em>The platform we target is the Web.</em></li><li><em>The design system we use to base our component designs on is Material.</em></li><li><em>The language we use to build our theming system is Sass, so the code samples I will be showing throughout the series are gonna be written in Sass. Some of the code may be simplified for brevity.</em></li></ul><p>This article is a gentle introduction to the basic concepts and techniques we used when building our theming system as far as colors and shadows are concerned. In the next article we will take a look at a possible implementation of the concepts described below.</p><p>Before we dig into colors and shadows, let’s first talk about what a component themes is.</p><h3><strong>The Anatomy of a Component Theme</strong></h3><p>What defines a component theme? Is it just colors, or are there any other properties to the visual aesthetic of a component that define its theme?</p><p>Let’s take a simple button and dissect it to get some insight into what the user might want to change.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/746/1*NkhSWyPqDCku6NvwGfE-aA.jpeg" /></figure><p>From the image above it becomes apparent that there are at least 4 properties for customization:</p><ul><li>Background Color</li><li>Text Color</li><li>Border Radius</li><li>Shadow</li></ul><blockquote><strong>I have intentionally left typography out of the component theme for now. We will treat typography as a separate module.</strong></blockquote><p>Because the button is a stateful component, i.e. can be in different states based on user interaction or configuration, like when it’s pressed, hovered, focused, or disabled, we have to multiply the amount of properties that can mutate in the different states by the number of states. So the list of modifiable properties can quickly grow to something like:</p><ul><li>Resting Background Color</li><li>Hover Background Color</li><li>Pressed Background Color</li><li>Focused Background Color</li><li>Disabled Background Color</li><li>Resting Text Color</li><li>Hover Text Color</li><li>Pressed Text Color</li><li>Focused Text Color</li><li>Disabled Text Color</li><li>Resting Shadow</li><li>Hover Shadow</li><li>Pressed Shadow</li><li>Focused Shadow</li><li>Disabled Shadow</li><li>Border Radius</li></ul><p>It quickly becomes apparent that if our component theme were to accept all those properties as inputs, the user of our component theme can get tired of having to manage the themes for all button instances very fast.</p><p>So how do we approach component themes in a simple manner without sacrificing the amount of customization that can be achieved?</p><p>We can begin with colors.</p><h3><strong>Colors</strong></h3><p>Let’s take a step back from component themes for a second and think about colors and color palettes. We can come up with a range of colors (palettes) that can be consumed by all component themes. This will make colors consistent across components. Moreover, we can pick specific colors from a palette for the different states a component can be in.</p><p>So let’s come up with a color palette, and feed it to our button theme:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/746/1*d-rKGD4IXxQc4SR5j-sYog.jpeg" /></figure><p>We establish 2 monochromatic palettes. One of them defines a set of primary colors, the other one a set of grayscale colors. Let’s imagine that we invented some sort of a mechanism through which we can feed the palettes directly to the component themes. Essentially, the palettes become an input to a component theme function.</p><p>In such scenario, the component theme doesn’t care about specific hard-coded colors, rather, only about a data type that represents a color palette. The only condition is that we feed the component theme a primary and grayscale color palettes. We give each palette and color in it unique name identifiers so that we can refer to them from within the component theme. Using this approach gives us the flexibility to modify any of the colors in the palettes, hence changing how the button component, or any other component that uses this palette, will look. If we decided to change the color 300 in the <strong><em>primary colors</em></strong><em> </em>palette to <strong><em>green</em></strong> we would modify the background color of the button in its normal state.</p><p>We can go a bit further and create an algorithm that can generate color palettes for us from a single color. Our primary palette is made up of 5 colors. If we use the middle color — 300 as the base color, we can create an algorithm that generates 2 lighter and 2 darker shades so that we always have a palette that consists of 5 shades of the same color.</p><p>What I’ve described above is exactly what we do in our theming system.</p><h3><strong>Shadows</strong></h3><p>We can take a very similar approach when handling shadows to what we did with colors. Instead of hard-coded values, we can make the shadows an input of the theme function.</p><p>Like colors, shadows can be part of a shadow set where each shadow variant has its own name. We can create a system in which shadows are predefined based on a set of rules.</p><p>Objects, in nature, throw shadows when they are illuminated by a light source. Or put otherwise, the obstructed light that gets reflected off an opaque object onto some surface forms a shadow. The shadow that forms is dimensional and can be broken down in 3 major parts — penumbra, umbra, and antumbra.</p><ul><li><strong>The penumbra</strong> shadow is the part of the shadow that appears when only some of the light is obscured by the object. This will be the shadow that appears across the sides of our objects. It won’t be the darkest or thickest, but will still be a substantial part of the shadow.</li><li><strong>The umbra</strong> shadow is a subset of the penumbra shadow and describes the shadow that gets thrown when the object blocks all of the light from the light source. This part of the shadow will be the thickest and darkest one.</li><li><strong>The antumbra</strong> shadow is the shadow that gets created when the object is entirely within the disc of the light source. This will be the faintest and lightest part of the shadow set.</li></ul><p>In our case we assume the objects, i.e. components, are always being fully illuminated by the light source at a specific angle for simplicity. We won’t be using math to get precise values for our shadow levels, although if that’s your thing here’s how <a href="https://ntrs.nasa.gov/archive/nasa/casi.ntrs.nasa.gov/19950023025.pdf">NASA calculates umbra and penumbra</a>. Instead, we can just eyeball some shadows, just like artists do when they draw. The description above just makes us a bit more informed shadow creators.</p><p>We will create some different levels of shadows based on how far the component is from the surface of our app, a.k.a the background. Thus creating layers/levels on which each component sits. This approach is the same as the one Google defines for their Material Design system.</p><p>For now we can create just three shadow levels that our sample button component can use in each of its states.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/731/1*va6_RupwxTF9ZZdFECXrwA.jpeg" /></figure><p>Let’s imagine the button is a life-like element that is magnetically charged, and to interact with it you will have to attract it, essentially pulling it up closer to the source that’s trying to interact with it. This guides our decision in choosing the shadow levels when designing the button theme. Because the button theme doesn’t know anything about the actual shape of the shadows, apart from the shadow names it should use in the different states, we can just change the shadow input to achieve a different look and feel.</p><h3><strong>Conclusion</strong></h3><p>By coming up with more abstract and cohesive data constructs for colors and shadows, we can separate the details of a component theme from the theme itself. This allows for multiple color palettes and shadow sets that can be consumed by a component theme, enabling us to produce very different looking and feeling components from the same theme base.</p><p>In the next article we will attempt to implement the concepts introduced here using Sass.</p><figure><a href="https://usejournal.com/?utm_source=medium.com&amp;utm_medium=noteworthy_blog&amp;utm_campaign=guest_post_image"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f2IVAl0TbsfES9cFGYr40g.png" /></a></figure><p><strong>This story is published in Noteworthy, where 10,000+ readers come every day to learn about the people &amp; ideas shaping the products we love.</strong></p><p><strong>Follow our publication to see more product &amp; design stories featured by the </strong><a href="https://usejournal.com/?utm_source=medium.com&amp;utm_medium=noteworthy_blog&amp;utm_campaign=guest_post_text"><strong>Journal</strong></a><strong> team.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=51787154a667" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/architect-a-theming-system-for-reusable-web-components-part-1-51787154a667">Architect a Theming System for Reusable Web Components — Part 1</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>