<?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 Mandy Michael on Medium]]></title>
        <description><![CDATA[Stories by Mandy Michael on Medium]]></description>
        <link>https://medium.com/@mandy.michael?source=rss-eb5fea6e7083------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*FdLk6nsKzfmjq3zn.png</url>
            <title>Stories by Mandy Michael on Medium</title>
            <link>https://medium.com/@mandy.michael?source=rss-eb5fea6e7083------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 04:15:46 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mandy.michael/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[People deserved a better web. Will AI be the one who gets it?]]></title>
            <link>https://medium.com/@mandy.michael/people-deserved-a-better-web-will-ai-be-the-one-who-gets-it-9b7192af3f0e?source=rss-eb5fea6e7083------2</link>
            <guid isPermaLink="false">https://medium.com/p/9b7192af3f0e</guid>
            <category><![CDATA[accessibility]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[performance]]></category>
            <dc:creator><![CDATA[Mandy Michael]]></dc:creator>
            <pubDate>Mon, 01 Dec 2025 06:10:46 GMT</pubDate>
            <atom:updated>2025-12-01T06:17:49.126Z</atom:updated>
            <content:encoded><![CDATA[<p>Like many people in the web industry I’ve been keeping an eye on the “state of AI” and what it means for my job, and my day to day life. To be honest I still don’t really know? Most of the talks, articles and panels seem to fall into a few predictable categories:</p><ol><li>How AI will replace <em>your</em> job, but <em>my</em> job is still extremely important</li><li>Sales pitch for new AI tool/startup/company etc</li><li>Some useful predictions</li></ol><p>I don’t have much to say about category one, this seems pretty par for the course. In some ways I think this article falls into that category so who am I to judge.</p><p>Category two, is <em>fine</em>, it kinda reminds me of the JavaScript Frameworks era, every week a new one is popping up promising to change everything. It’s pretty exhausting but business as usual for the web really?</p><p>Then we have category three, which I think has been the most interesting because it dives into how people are imagining or seeing right now how AI might shape the future of the web. And one area that keeps cropping up that is especially interesting to me is the idea that AI will become the customer.</p><p>I think the reason I’m so drawn to this particular idea is probably tied to my own bias (hello from category one). If AI is our customer will this elevate two parts of web development that are often undervalued, pushed to the very end of a project or just completely ignored all together, I’m looking at you performance and accessibility.</p><p>If AI becomes the customer, then does the way we structure our documents suddenly become very important? Will semantic HTML and proper consideration of how things are composed become the backbone of how AI consumes our content? How will this impact visual design, will design thinking shift to simpler layouts and structures because AI does not care about your fancy layouts, images and gradients? If an image is meaningful to your product or brand and you didn’t bother adding an alt attribute, what happens when AI tries to understand your site? What does that mean for your company when an emerging customer base has no clue what half your content even is or how it ties together? Is it smart enough to understand without proper consideration for semantics and structure?</p><p>And what about performance? Will AI start to expect near instant load times? If your website is slow and takes a long time to load will AI just move on because you’re too slow. There has already been much talk about the impact of JavaScript frameworks on performance, could AI be the shift that moves us away from massive JavaScript frameworks and back toward native web features and lighter pages?</p><p>I’m not an expert, I don’t spend my days pondering what AI will do to the industry, but this line of thought absolutely fascinates me. And I’ll admit… I’d be <em>delighted</em> to see accessibility and performance engineers suddenly become the heroes of the industry, the people everyone suddenly needs on their team, because the new “user” they’re optimizing for is now an AI that only cares about your data, structure, and content.</p><p>While I would be happy to see this shift, I think i’d find it a little depressing? It would feel pretty awful to know we spent years dragging our feet on accessibility and performance for actual human beings who struggle to use the web we have built. But as soon as an AI becomes a key user, suddenly we’re ready to jump through hoops to make things cleaner, faster, and more semantic?</p><p>It’s kind of sad that it might take a machine to force us into doing the work we should’ve been doing for humans all along.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9b7192af3f0e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Font Variant Numeric]]></title>
            <link>https://medium.com/@mandy.michael/using-font-variant-numeric-04e96609da2c?source=rss-eb5fea6e7083------2</link>
            <guid isPermaLink="false">https://medium.com/p/04e96609da2c</guid>
            <category><![CDATA[css]]></category>
            <category><![CDATA[fonts]]></category>
            <category><![CDATA[web-typography]]></category>
            <category><![CDATA[web]]></category>
            <category><![CDATA[front-end-development]]></category>
            <dc:creator><![CDATA[Mandy Michael]]></dc:creator>
            <pubDate>Sun, 18 Feb 2024 23:01:41 GMT</pubDate>
            <atom:updated>2024-02-18T23:01:41.592Z</atom:updated>
            <content:encoded><![CDATA[<p>The font-variant-numeric CSS property allows us to control alternate glyphs for numbers, fractions, and ordinal markers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Xsyv5SDSjnv3bBfEk-hZuA.png" /></figure><p>It’s important to note with all font properties, that if the font does not support the variant it will not do anything and will instead fall back to the default. So if you want to use these you have to make sure to choose a font that supports them. I like to use the tool <a href="https://wakamaifondue.com/">Wakamaifondue</a> as it analyses the font and shows you all the available features.</p><p>font-variant-numeric deals specifically with numeric characters like digits - it allows us to control the usage of alternate glyphs for numbers, fractions, and ordinal markers. The related property, font-variant is the shorthand name for five separate variant properties, but in this post I&#39;ll focus only on font-variant-numeric.</p><p>Fonts will sometimes come with a number of different glyphs that can be used to represent different number formats, fractions etc. But on the web it’s not something you see utilised very often simply because it’s either forgotten about or not widely known. The font-variant-numeric property allows us to access these features and is particularly useful for product interfaces, admin systems and data where you deal with a lot of numbers.</p><p>There are a number of different values for font-variant-numeric you can check out the <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/font-variant-numeric">font-variant-numeric MDN page</a> for a full list, in this article i&#39;ll demonstrate some of the options which I find most useful.</p><pre>font-variant-numeric: slashed-zero;<br>font-variant-numeric: lining-nums;<br>font-variant-numeric: tabular-nums;<br>font-variant-numeric: old-style-nums;<br>font-variant-numeric: diagonal-fractions;<br>font-variant-numeric: stacked-fractions;<br>font-variant-numeric: ordinal;</pre><p>Some of these values might seem obvious, something like slashed zero and diagonal or stacked fractions for example, but if you aren’t familiar with the terminology something like lining-nums might be confusing. The image below demonstrates some examples.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KoCrze4QURDnX005uTMQyw.png" /><figcaption>Example different font-variant-numeric features</figcaption></figure><p>Some of these might look very different or very similar and when and when not to use them can be confusing so lets take a closer look.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8T4zFbzc5GU03N0YNWKcAw.png" /><figcaption>Example image demonstrating the differences between lining numerals tabular numerals and oldstyle numerals using Roslindale font it shows the horizontal spacing difference between lining and tabular numerals and now the old style numerals run below the baseline</figcaption></figure><p>An option like tabular-nums is useful where you want each number to sit on the <a href="https://fonts.google.com/knowledge/glossary/baseline">baseline</a> and take up the same amount space per number - think charts or tables of data where you want everything to align. Whereas lining-nums are better suited to places where the numbers align on the baseline but the individual numbers do not necessarily take up the same space, typically more common in body copy. Finally oldstyle-nums have varying heights and alignments, as opposed to the other two examples which are uniform in height and alignment. They are similar in height to lowercase characters, so you often see this used in body copy as well (though it appears to be less common in more modern fonts).</p><p>If we take a look at the image below it has a table with tabular-numson the left and oldstyle-nums on the right. It demonstrates how using tabular nums in this context makes the numbers and data significantly easier to read than the old style nums on the right. Now, the type of font you choose will also play a part in this but primarily the tabular-nums style is easier to read because all the numbers take up the same space and align on the baseline making the reading vertically and horizontally easier to follow.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MRrQt1e-yBDGpM3Sien4ZQ.png" /><figcaption>Example image demonstrating the differences in a table between old style numerals and tabular numerals using Playfair Display it demonstrates that old style numerals in a table make it difficult to read the data</figcaption></figure><p>Most modern professional fonts will contain both lining numerals and old style numerals (though not always) additionally they will not always include tabular-nums so if you are dealing with a lot of data in your applications you should absolutely check the availability of this in your fonts before committing at the design phase.</p><p>If the font supports it you can also utilise different styles for ordinals (numbers that express position in a series e.g. 1st, 2nd, 3rd) and fractions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gIcnkha5tKsheS_zK6aJjA.png" /><figcaption>Image demonstrating the difference between the normal state for ordinals, or utilising the ordinals style represented like a superscript</figcaption></figure><p>When it comes to ordinals, if you want them to display as an ordinal (kind of like superscript) you can specify the value of ordinal otherwise it will display as regular text as per the image above.</p><pre>font-variant-numeric: ordinal;</pre><p>There are two options for fractions, diagonal and stackedthe most common style is the diagonal fraction, however they are typically only available for a common set of fractions, e.g. 1/2, 1/3 etc. Unless specifically requested it&#39;s rare for a font to have a variety of combinations. However, the regular set is useful for things like recipe sites. A &quot;Horizontal fraction&quot; is generally considered what you would get by using the forward slash e.g. 1/2. They are harder to read than diagonal fractions, they take up more space, and also, they don&#39;t look as good as the pre-prepared diagonal fractions so if you think you&#39;ll be needing fractions it&#39;s good to investigate what fonts will support your needs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*euTXZenYPlPr1l2iR_noog.png" /><figcaption>Image demonstrating the difference between the difference between stacked, diagonal or regular fractions</figcaption></figure><p>Stacked fractions are even less common and are mainly reserved for mathematical equations, they aren’t commonly supported in fonts so you’d really have to look around for them. (As an aside stacked fractions are also referred to as nut fractions which I thought was interesting). These ones if you’re wondering are part of the <a href="https://www.typography.com/fonts/surveyor/overview">Surveyor Font</a>.</p><p>These are only a handful of the options available, so do make sure you check out the <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/font-variant-numeric">font-variant-numeric MDN page</a> for a full list. Most importantly though, you can combine the options by specifying multiple values at once. For example, you could set tabular-nums AND diagonal-fractions with a space separated list.</p><pre>    font-variant-numeric: tabular-nums diagonal-fractions;</pre><p>While this is supported in new releases of the browsers, depending on how far back you need to support you may need to include the font-feature-settings property. Each option is mapped to an Open Type feature, in this case, frac === diagonal-fractions. You can find these values on the font-variant-numeric mdn page. Please remember though that while font-feature-settings will accomplish the same thing, you should use the font-variant property wherever possible as it will lead to more effective, predictable and understandable results. The same applies to using any of the font-variant properties.</p><p>What’s unfortunate though is that even though many devs may be familiar with the CSS property I think they assume it will just work with whatever font they are using, and when it doesn’t they ignore the feature. However it’s definitely worth checking if alternate versions of your chosen font support the feature or if you are in the design phase considering how you want numbers represented and choosing fonts which support these methods. font-variant-numeric is a great property to keep in mind if you&#39;re dealing with a lot of data, especially if you&#39;re finding people are struggling to understand your content. Sometimes changing the font, or the way it&#39;s displayed can make a significant difference to the users understanding of what we are trying to convey.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=04e96609da2c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Animating Font Palette]]></title>
            <link>https://medium.com/@mandy.michael/animating-font-palette-062b44781dae?source=rss-eb5fea6e7083------2</link>
            <guid isPermaLink="false">https://medium.com/p/062b44781dae</guid>
            <category><![CDATA[web]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[animation]]></category>
            <category><![CDATA[fonts]]></category>
            <dc:creator><![CDATA[Mandy Michael]]></dc:creator>
            <pubDate>Fri, 16 Feb 2024 03:27:20 GMT</pubDate>
            <atom:updated>2024-02-16T03:27:20.796Z</atom:updated>
            <content:encoded><![CDATA[<h3>With the release of Chrome 121 we can now animate a smooth transition between font-palettes in Color Fonts using only CSS.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5tylMX6lMQE6bJjYcK-ing.png" /><figcaption><a href="https://fonts.google.com/specimen/Bungee+Spice">BUNGEE SPICE</a> BY DAVID JONATHON ROSS</figcaption></figure><p><em>Previously published on </em><a href="https://textlab.dev/"><em>textlab.dev</em></a><em> as “</em><a href="https://textlab.dev/posts/animating-font-palette"><em>Animating font-pallette</em></a><em>”.</em></p><p>If you aren’t familiar with color fonts I recommend you check out my previous post <a href="https://textlab.dev/posts/using-color-fonts">Using Color Fonts</a> to get a bit of a background on how to use them. If you are familiar with color fonts lets dive into the latest update in Chrome 121 allowing for animating the font palettes. <em>Note: please make sure you have updated to the latest Chrome (Chrome 121) to see the transition. It is not currently supported in the other browsers.</em></p><p>As a brief introduction to save you reading the whole post about Color Fonts, they allow font designers to merge multiple color layers into one font file and assign a color to each layer. They come with one or more colour palettes predetermined but developers can access and change these values through CSS using the font-palette property. In the latest release of Chrome (121) we can now animate the change between font-palette values. Below is the Codepen if you want to skip all the explanation, otherwise feel free to read on!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fmandymichael%2Fembed%2Fpreview%2FpoYWayY%3Fdefault-tabs%3Dcss%252Cresult%26height%3D600%26host%3Dhttps%253A%252F%252Fcodepen.io%26slug-hash%3DpoYWayY&amp;display_name=CodePen&amp;url=https%3A%2F%2Fcodepen.io%2Fmandymichael%2Fpen%2FpoYWayY&amp;image=https%3A%2F%2Fshots.codepen.io%2Fusername%2Fpen%2FpoYWayY-512.jpg%3Fversion%3D1706164194&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/217644e5419796a6be917ce6daf94e4e/href">https://medium.com/media/217644e5419796a6be917ce6daf94e4e/href</a></iframe><p><em>Reminder: please make sure you have updated to the latest Chrome (Chrome 121) to see the transition. It is not currently supported in the other browsers.</em></p><p>First thing we are going to need is a color font that supports color palettes, I’ve chosen <a href="https://fonts.google.com/specimen/Bungee+Spice">Bungee Spice</a> by David Jonathon Ross, it’s available on <a href="https://fonts.google.com/specimen/Bungee+Spice">Google Fonts</a>. If you aren’t sure if the font you want to use supports font palettes you can load it up into <a href="https://wakamaifondue.com/">Wakamai Fondue</a> and it well let you know what palettes are available and how many colors in each one.</p><p>Assuming you’ve loaded in the google font we’ll set up our html next with just a simple h1.</p><pre>&lt;h1&gt;Jello&lt;/h1&gt;</pre><p>Next up we need to set up the font-palette-values function in the CSS. As Bungee Spice only comes with one palette I&#39;m going to create two new ones to use for the transition. The first one I&#39;ll name --base and the transition colors I&#39;ll call --transition. Because I want to use a custom palette I&#39;ll add in the override-colors property alongside the font-family property. This particular font only has two colours in the palette so starting from 0, I&#39;ve added the two colours I want in. Next I create another palette the same way with the name --transition but change the colours to the secondary set. I&#39;ve used the hex code from position 1 in the --base palette as the start position (0) in my --transition palette, but you can use whatever colours you want.</p><pre>@font-palette-values --base {<br> font-family: &quot;Bungee Spice&quot;;<br> override-colors: 0 #1894b0, 1 #fc00fc;<br>}<br><br>@font-palette-values --transition {<br> font-family: &quot;Bungee Spice&quot;;<br> override-colors: 0 #fc00fc, 1 #4200d9;<br>}</pre><p>Once we have our font-palette-values functions set up we can continue with the rest of the CSS. You may think that because we&#39;ve defined the font-family in the function we don&#39;t need to add it to the h1, but that is not the case, so we add the font-family onto the h1 as well, followed by the font-palette property with the value of our first palette i.e. --base.</p><p>Next up we can add a transition in with the transition property, this can be whatever you want as long as you are transitioning the font-palette property. Finally to trigger the transition I&#39;ll use the hover state for simplicity. At this point we need to change the value of the font-palette property to the --transition font-palette values function on the hover selector.</p><pre>h1 {<br> font-family: &quot;Bungee Spice&quot;, sans-serif;<br> font-palette: --base;<br> transition: ease 250ms font-palette;<br>}<br><br>h1:hover {<br> font-palette: --transition;<br>}</pre><p>This will result in a smooth transition between the two colour sets when you hover over the text. You can then proceed to add any other features you want, in my case I included a text-shadow for oomph. The full demo is available on my <a href="https://codepen.io/mandymichael/pen/poYWayY">Animating Font-Palette Codepen</a>.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fmandymichael%2Fembed%2Fpreview%2FpoYWayY%3Fdefault-tabs%3Dcss%252Cresult%26height%3D600%26host%3Dhttps%253A%252F%252Fcodepen.io%26slug-hash%3DpoYWayY&amp;display_name=CodePen&amp;url=https%3A%2F%2Fcodepen.io%2Fmandymichael%2Fpen%2FpoYWayY&amp;image=https%3A%2F%2Fshots.codepen.io%2Fusername%2Fpen%2FpoYWayY-512.jpg%3Fversion%3D1706164194&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/217644e5419796a6be917ce6daf94e4e/href">https://medium.com/media/217644e5419796a6be917ce6daf94e4e/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=062b44781dae" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a Server Side Zendesk App with NextJs, JWTs & Iron Session]]></title>
            <link>https://medium.com/@mandy.michael/building-a-server-side-zendesk-app-with-nextjs-jwts-iron-session-e2a831788732?source=rss-eb5fea6e7083------2</link>
            <guid isPermaLink="false">https://medium.com/p/e2a831788732</guid>
            <category><![CDATA[zendesk]]></category>
            <dc:creator><![CDATA[Mandy Michael]]></dc:creator>
            <pubDate>Thu, 17 Nov 2022 00:10:41 GMT</pubDate>
            <atom:updated>2022-11-17T00:10:41.406Z</atom:updated>
            <content:encoded><![CDATA[<p>This post will run you through setting up a Zendesk app which makes a client side request using the Zendesk App SDK and also makes a request to an external API on the server-side. It includes authentication on the server-side, JWT verification and signed cookies with iron-session.</p><p>I was tasked with making a simple Zendesk app to load in some user information, but I hit some hurdles along the way which weren’t obvious to us while developing, so I decided to document the approach in case anyone needs to do something similar. I have added some useful links at the end which I recommend reading.</p><p>First up you should consider whether your app needs to be client side or server-side. <a href="https://developer.zendesk.com/documentation/apps/getting-started/choose-your-own-app-adventure/">Zendesk has some documentation on this</a> but one thing to keep in mind is that for any Zendesk API calls that don’t use the standard Zendesk library/SDK, Zendesk will regard it as an “external API”, and you’ll need to implement a server-side app.</p><h4>Getting started</h4><p>First up you need to setup your NextJs app, you can follow theNextJS instructions, or you can <a href="https://github.com/ericagirges/sample-zaf-next">use this sample app</a> that Zendesk ran through in a webinar. I’ll assume you used the sample app so if you set one up from scratch just have a quick look at make sure you have a similar setup. <em>Note: make sure you have version 12 of NextJs.</em></p><p>I wont run through the specifics for <a href="https://developer.zendesk.com/documentation/apps/build-an-app/build-your-first-sell-app/building-your-first-sell-app-part-1-laying-the-groundwork/#installing-zcli">setup</a>, <a href="https://developer.zendesk.com/documentation/apps/build-an-app/build-your-first-sell-app/building-your-first-sell-app-part-2-designing-the-user-interface/#testing-the-app">testing</a> or <a href="https://developer.zendesk.com/documentation/apps/getting-started/uploading-and-installing-a-private-app/">uploading and installing an app</a>, you can read through the Zendesk setup docs for that. However, some things to keep in mind, I could not get the app to load consistently in Chrome using zcli despite following the instructions, so I ended up doing all my testing in Firefox.</p><p>In addition to that I had some ongoing caching issues (in all browsers). So just a reminder to make sure when you are making updates to your app you have some way to check it is not being cached (this was more problematic as I started on the server-side aspect and started implementing the authentication), so make sure to clear cookies, site data etc if you are facing trouble, just to be sure.</p><p>If your app is client side only you can use the zcli pretty easily, but when you get to the server-side parts you’ll need to deploy the app somewhere to host it. You can do some of the dev locally by just running the app and checking it in the browser at localhost:3000. I did this mainly to check I didn’t mess up any imports, JS, that the builds worked etc. To properly check things like the JWT, authentication etc you’ll eventually need to deploy it.</p><h4>Setting up the manifest file.</h4><p>If you set up from scratch you’ll need to add a few things in. Create a new folder for the Zendesk App, I called it app_local. Check out the <a href="https://github.com/ericagirges/sample-zaf-next/tree/main/app_local">sample app</a> for what you need, but the main part is the manifest.json file, just copy their file to get started.</p><p>Inside the manifest file you need to set the <a href="https://developer.zendesk.com/documentation/apps/app-developer-guide/getting_started/#how-does-it-work">location of your app</a>. The first level under the location node is reserved for the product that you want to host your app within. Then nested down further is the specific location within that product where you want to host the app. In my case, I wanted to host the app within Zendesk Sell, under the Deal card.</p><pre>&quot;location&quot;: { <br>    &quot;sell&quot;: {<br>       &quot;deal_card&quot;: &quot;localhost:3000&quot;<br>     }<br>},</pre><p>Where I have localhost will be the url of the hosted app but you can leave it as localhost for now for local development. Zendesk have a reference for different locations you can check <a href="https://developer.zendesk.com/api-reference/apps/apps-support-api/introduction/">out on their website</a>.</p><p><strong>IMPORTANT</strong>: <em>The Zendesk documentation will say the url needs to include the location in the pathname e.g. </em><em>localhost:3000/sidebar, however I found this was not the case for my setup with NextJS.</em></p><h4>The ZAF client</h4><p>The next step is setting up the ZAF Client. Create a folder somewhere in your app like utils or whatever you want to call it, and then create a new file, I called mine zafClient.js but whatever works for you is fine.</p><p>Inside that file paste the following. This will initialise the ZAF client so you can access it. It also sets the height and width of your app, so you can change these values to whatever works for you.</p><pre>import { useEffect, useState } from &quot;react&quot;<br>let zafClient = null;<br>export function useZafClient() {<br>  const [client, setClient] = useState(zafClient)<br>useEffect(() =&gt; {<br>    if (!client &amp;&amp; typeof window.ZAFClient !== &#39;undefined&#39;) {<br>      zafClient = window.ZAFClient.init();<br>      setClient(zafClient);<br>      if(zafClient) {<br>        zafClient.invoke(&quot;resize&quot;, {width: &quot;100%&quot;, height: &quot;200px&quot;});<br>      }<br>    }<br>  }, [client])<br>return client<br>}</pre><p>Once we have that we can start setting up our pages and accessing the data we need.</p><h4>Accessing data client side</h4><p>In order to access the data you can jump over to your index.js under pages and initialise the ZAF Client. A simple example is below, you can check out the <a href="https://developer.zendesk.com/api-reference/apps/apps-core-api/client_api/#clientgetpaths">Zendesk docs</a> to find out what data you can access with client.get</p><pre>export default function Home() {<br>  const client = useZafClient();<br>  const [data, setData] = useState(&#39;&#39;)<br>  useEffect(() =&gt; {<br>      const getSomeData = async () =&gt; {<br>        if(client !== null) {<br>         const data = await client.get(&quot;nameOfThingYouWant&quot;)<br>            .then(data =&gt; {<br>              return data<br>            });<br>         setData(data)<br>        }<br>      }<br>      getSomeData()<br>   }, [client]);<br>}</pre><p>In my case (not shown here) I take the data and pass it to a query string so I can use it on the next route in a server side request, but you can use it however you want.</p><h4>Server side requests / External APIs</h4><p>In order to make requests to external APIs the requests need to be server side. In our case we assumed because our endpoint was from Zendesk it would be fine client side, but because of the Zendesk endpoint we are using its considered external. This is unconfirmed but I think making the call from Zendesk Sell is related given it’s technically a separate product.</p><p><strong><em>Note</em></strong><em>: the docs talk about setting up secure settings in the manifest, but this only works as part of request() as per our client side example. You cannot use the API token setup defined in the manifest file to request the endpoint server side instead it has to be defined as an environment variable.</em></p><p>With NextJS you can use getServerSideProps to fetch data server-side and store it in a prop to use on page render.</p><p>As mentioned earlier we took the data we got from the Zendesk client request on the first page and passed this through on the route as a query string. If you want to do something similar you can access this via the context. It would look something like the below example (this is a lot easier than trying to get it from the url).</p><pre>export function getServerSideProps(context) {<br> const queryStringInfo = context.query;<br> ....<br>}</pre><p>For the Authorisation you’ll need to set some environment variables to store the user authentication information. You can find <a href="https://support.zendesk.com/hc/en-us/articles/4408889192858-Generating-a-new-API-token">information on generating the token</a> on the Zendesk website, in my case however the team responsible for Zendesk had already set it up so I just asked them for it.</p><p>Here is an example snippet of code for the Authorisation headers, you’ll note I have some environment variables for the user specific information, and that I am encoding it to Base64.</p><pre>const headers = {<br>      &quot;Authorization&quot;: <br>        `Basic ${Buffer.from(process.env.USER + &#39;/token:&#39; +  <br>          process.env.API_TOKEN, &#39;binary&#39;).toString(&#39;base64&#39;)}`,<br> };</pre><p>Essentially it would be something like the following but the output of the username/password combination of what follows Basic is Base64 encoded.</p><pre>Basic name@email.com/token:theToken</pre><p>You can also have OAUTH2 applications set up in Zendesk, but for non-attended scenarios, you’ll likely need to or want to use Basic (just make sure you’re using the https endpoints).</p><p>If you have some difficulties with the token I’d recommend setting up in Postman or similar to test the endpoint and authentication is working correctly first, that way you’ll know if it’s a problem with the details or with something in your code.</p><p>Next you can make the GET request. I put it all together in a try catch in case it failed, and then return the data from the endpoint to props. This will then be accessible on the client side render and you can render the data in the page.</p><pre>export function getServerSideProps(context) {<br>   try {<br>     const headers = {<br>      &quot;Authorization&quot;: <br>        `Basic ${Buffer.from(process.env.USER + &#39;/token:&#39; +  <br>          process.env.API_TOKEN, &#39;binary&#39;).toString(&#39;base64&#39;)}`,<br>      };<br>          <br>      const response = await fetch(&#39;https://url/goes/here&#39;, {<br>         method: &quot;GET&quot;,<br>         headers: headers,<br>         secure: true,<br>      });<br>            <br>      const data = await response.json();<br>                <br>      return { props: { data } }<br>   } catch (err) {<br>      throw new Error(`Error has occurred - ${err}`);<br>   }<br>});</pre><p>If you’re wondering where the query string comes into it, it was used as part of the url, I just haven’t shown that here.</p><h4>JWT and Sessions</h4><p>At this point we added some extra levels of security with a JWT from Zendesk and a signed cookie with iron-session. The reason we did this was due to the specific endpoint we were using.</p><p><strong><em>Note</em></strong>: I hit an issue with iron-session after installation where one of its dependancies was importing a module in a way that was considered incompatible. Most of the documentation says “add modules:true to your package.json ”, but this just causes a bunch of other problems so instead I downgraded my NextJS to 12.0.1 where this issue is not a problem. It turns out there was/is a bug with later versions of NextJS, hopefully that will get resolved.</p><h4>Accessing the JWT</h4><p>In order to access the JWT you need to modify your manifest.json file and re-upload it to Zendesk.</p><p>You’ll see an example manifest below, the key part you need to add in is the signedUrls . You can read more about it in this Medium post <a href="https://developerblog.zendesk.com/securing-your-zendesk-app-framework-zaf-app-7f8fef2b5c45">Securing your ZAF App</a>.</p><pre>{<br>  &quot;name&quot;: &quot;My Cool App&quot;,<br>  &quot;defaultLocale&quot;: &quot;en&quot;,<br>  &quot;private&quot;: true,<br> <strong> &quot;signedUrls&quot;: true,</strong><br>  &quot;location&quot;: {<br>    &quot;sell&quot;: {<br>      &quot;deal_card&quot;: &quot;http://<a href="https://cool-babka-000173.netlify.app/">l</a>ocalhost:3000&quot;<br>    }<br>  },<br>  &quot;version&quot;: &quot;1.0&quot;,<br>  &quot;frameworkVersion&quot;: &quot;2.0&quot;,<br>  &quot;domainWhitelist&quot;: [&quot;yoursubdomain.zendesk.com&quot;]<br>}</pre><p>Essentially by adding signedUrls to your manifest file you are given access to a key which you can verify to make sure its a trusted source. The docs say you can just add signed: true to the specific location if you have more than one app location but I found this didn’t work. I think you actually need both if you want to do that e.g. signedUrls set to true at the top level and signed either set as true or false in each location block. In my case we only have one so I just set signedUrls.</p><p>At this point you’ll need zip up the files inside your app_local folder and re-upload to Zendesk otherwise you wont get the token. You don’t want to upload the whole next application here because it will be hosted separately. So just include the files inside app_local.</p><p><em>Note: Regarding hosting the app itself, I chucked mine up on Netlify for testing purposes, it was quick has a build setup for NextJs already and support environment variables. But you can host it wherever works for you, in the end ours will be hosted on AWS but it was much quicker for me to test via Netlify while I was developing.</em></p><p>Once you have re-uploaded the app into Zendesk it will make a POST request and from there you’ll have access to the token. What is important here is that this request is only made <strong>once on the initial page. </strong>This means it you will only have access to it on that initial page. If you need access on every route, (like in my case) you’ll need to chuck it in a cookie or something like that, otherwise you’ll only be able to verify your initial page.</p><p>To do this we used <a href="https://github.com/vvo/iron-session">iron-session</a>, so go ahead and install that, there are some great usage examples <a href="https://github.com/vvo/iron-session">in the docs</a>.</p><pre>npm install iron-session;</pre><p>We’ll use this to created a signed cookie we can use to store the JWT so we can access it on our first route and verify the token.</p><p>Because we want to do this inside getServerSideProps we’ll use withIronSessionSSR . It’ll look something like the example below.</p><pre>import { withIronSessionSsr } from &quot;iron-session/next&quot;;<br>import { parseBody } from &quot;next/dist/server/api-utils&quot;;<br>export default function Home() {<br>...<br>}<br>export const getServerSideProps = withIronSessionSsr(<br>  async function getServerSideProps(context) {<br>    const contextReq = await parseBody(context.req, &quot;1mb&quot;);<br>    if (!contextReq.token) {      <br>       return { notFound: true }     <br>    }<br>    // token verification goes here<br>       <br>    return { props: { } }      <br>},{<br>  cookieName: &quot;MyCookie&quot;,<br>  password: process.env.APPLICATION_SECRET,<br>  cookieOptions: {<br>    maxAge: undefined,<br>    secure: true,<br>    sameSite: &quot;none&quot;,<br>  },<br>});</pre><p><strong><em>Note</em></strong><em>: the import path for </em><em>parseBody might be different depending on your version of Next, sometimes it has a /node on the end.</em></p><p>The main takeaways here are that we access the session in the req and save the token to the user property on the session. You can name it whatever you want, I called it token.</p><p>There are a few important parts to the cookie options, I recommend reading the <a href="https://github.com/vvo/iron-session#installation">iron-session installation notes</a> it will help you through this, including generating the password. The most important parts for the Zendesk side of things however is the sameSite: none property. The iron-session setup defaults this to lax I found that while it worked fine locally once deployed to production it failed the only solution I came up with was setting sameSite to none.</p><p><strong><em>Note</em></strong><em>: if you set </em><em>sameSite: none you must set </em><em>secure: true. Secure should be set as true on production anyway though, the docs have an example of how you can set this up with an environment variable.</em></p><p>Once you have this setup you can make sure that the JWT is verified and set it in the session.</p><p>You’ll need an appPublicKey and the appId for this, the<a href="https://developer.zendesk.com/documentation/apps/app-developer-guide/using-the-apps-framework/#handling-the-jwt-token-in-your-server-side-app"> Zendesk docs explain</a> how you can get the public key and the app id. The audience is whatever your Zendesk url is and the app id.</p><p><em>NOTE: when you get the app id you’ll notice there is an </em><em>id and an </em><em>appId For the installations url you want the </em><em>id but when you are generating the public key you want the </em><em>appId .</em></p><pre>verify(token, appPublicKey, {<br>  algorithms: [&#39;RS256&#39;],<br>  audience: `x.zendesk.com/api/v2/apps/installations/${id}.json`<br> });</pre><p>If the JWT is authorised it will carry on and fetch our data, if not, it will throw and error and bail out. Don’t forget to set up the cookie options like we did on the first page. See example below.</p><pre>import { withIronSessionSsr } from &quot;iron-session/next&quot;;<br>import { parseBody } from &quot;next/dist/server/api-utils&quot;;<br>export default function Home() {<br>...<br>}<br>export const getServerSideProps = withIronSessionSsr(<br>  async function getServerSideProps(context) {<br>    const contextReq = await parseBody(context.req, &quot;1mb&quot;);<br><br>    const zendeskUrl = process.env.ZENDESK_URL;<br>    const appId = process.env.ZENDESK_PLUGIN_APP_ID;<br>    const appPublicKey = Buffer.from(process.env.ZENDESK_PLUGIN_PUBLIC_KEY, &#39;base64&#39;).toString(&#39;utf8&#39;);<br><br>    const appId = <br>    if (!contextReq.token) {      <br>       return { notFound: true }     <br>    }<br>    if(appId &amp;&amp; appPublicKey) {      <br>      try {        <br>        verify(contextReq.token, appPublicKey, {               <br>           algorithms: [&#39;RS256&#39;],<br>           audience:<br>            `${zendeskUrl}/api/v2/apps/installations/${appId}.json`       <br>        });         <br>        context.req.session.user = {          <br>           token: contextReq.token        <br>        };            <br>        await context.req.session.save();                <br>          return { props: { } }      <br>     } catch (err) {        <br>         throw new Error(`Invalid Zendesk JWT - ${err}`);      <br>     }    <br>   } else {      <br>      return { notFound: true }    <br>   }<br>},{<br>  cookieName: &quot;MyCookie&quot;,<br>  password: process.env.APPLICATION_SECRET,<br>  cookieOptions: {<br>    maxAge: undefined,<br>    secure: true,<br>    sameSite: &quot;none&quot;,<br>  },<br>});</pre><p>Once this is setup we can move to our second page check the session information before we try to access the data. Like the first page we need to add in withIronSessionSsr and then all we have to do is check the session data for the user before we make our request for the data. If there is no session info we return notFound: true and bail out.</p><pre>if (!context.req.session.user) {<br>      return { notFound: true }<br>}</pre><p>Putting it all together for the second route it looks something like this:</p><pre>import { withIronSessionSsr } from &quot;iron-session/next&quot;;<br>import { verify } from &#39;jsonwebtoken&#39;;<br>export default function NewPage() {<br>...<br>}<br>export const getServerSideProps = withIronSessionSsr(<br>  async function getServerSideProps(context) {<br>    if (!context.req.session.user) {<br>      return { notFound: true }<br>    }<br><br>    const headers = {<br>      &quot;Authorization&quot;: <br>        `Basic ${Buffer.from(process.env.USER + &#39;/token:&#39; +  <br>          process.env.API_TOKEN, &#39;binary&#39;).toString(&#39;base64&#39;)}`,<br>    };<br>          <br>    const response = await fetch(&#39;https://url/goes/here&#39;, {<br>       method: &quot;GET&quot;,<br>       headers: headers,<br>       secure: true,<br>    });<br>            <br>    const data = await response.json();<br>                <br>    return { props: { data } }<br>},{<br>  cookieName: &quot;MyCookie&quot;,<br>  password: process.env.APPLICATION_SECRET,<br>  cookieOptions: {<br>    maxAge: undefined,<br>    secure: true,<br>    sameSite: &quot;none&quot;,<br>  },<br>});</pre><p>And that’s it. Be sure to set up all your environment variables before deploying and running your site. From here everything should <strong>hopefully</strong> work as you intended.</p><p>Best of luck.</p><h4>Resources:</h4><ul><li><a href="https://developerblog.zendesk.com/getting-started-zaf-next-js-4d1f83dae815">Getting started with ZAF and NextJs</a></li><li><a href="https://developerblog.zendesk.com/securing-your-zendesk-app-framework-zaf-app-7f8fef2b5c45">Securing your Zendesk App Framework (ZAF) App</a></li><li><a href="https://developer.zendesk.com/documentation/apps/app-developer-guide/getting_started/">Getting started with ZAF</a></li><li><a href="https://developer.zendesk.com/documentation/apps/app-developer-guide/using-the-apps-framework/#handling-the-jwt-token-in-your-server-side-app">Handling JWT in your server side app</a></li><li><a href="https://github.com/vvo/iron-session">Iron session on Github</a></li><li><a href="https://developer.zendesk.com/api-reference/apps/apps-core-api/client_api/#clientgetpaths">client.get paths in the Zendesk A</a>PI</li><li><a href="https://support.zendesk.com/hc/en-us/articles/4408889192858-Generating-a-new-API-token">Generating a new API token for Zendesk</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e2a831788732" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why you shouldn’t write your content in Uppercase, instead use CSS.]]></title>
            <link>https://medium.com/@mandy.michael/why-you-shouldnt-write-your-content-in-uppercase-instead-use-css-b03ac2c65b99?source=rss-eb5fea6e7083------2</link>
            <guid isPermaLink="false">https://medium.com/p/b03ac2c65b99</guid>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[web-design]]></category>
            <dc:creator><![CDATA[Mandy Michael]]></dc:creator>
            <pubDate>Thu, 23 Jul 2020 00:09:46 GMT</pubDate>
            <atom:updated>2020-07-23T00:39:40.912Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k-YyLkF7D3UJ7si8KQZk7Q.png" /></figure><p>Uppercasing is common in designs on the web you’ll often see it in navigation, on buttons and in headings or subheadings. I was recently changing the text in a navbar from uppercase to lowercase and I came across the situation where, instead of relying on the CSS, the last editor of this nav wrote the text in uppercase. This prompted a tweet whinge because this really bothers me. As a result of my tweet, it came to my attention that a lot of people don’t know why this is a problem (it’s easy to forget people, sorry about that). I figured it was a good opportunity to run through the reasons you shouldn’t write your content in uppercase and instead you should rely on CSS.</p><h3></h3><p>Does anyone else get irrationally annoyed when people write webpage content in uppercase when you already have CSS in place that styles it accordingly. 😒 Just me?</p><p><em>There are some great tweets from </em><a href="https://twitter.com/jensimmons"><em>Jen Simmons</em></a><em> in the thread of this tweet you should totally read, also follow her, she is a great source of knowledge!</em></p><p>First, a caveat, if something is meant to be uppercase, like an acronym, that is okay to write as uppercase, e.g CSS. If your text makes sense semantically in uppercase then it’s not a problem. <em>(Note: HTML has an </em><a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/abbr"><em>abbreviation element</em></a><em> you should totally use)</em></p><p>With that in mind, if your content is uppercased, only for design or styling purposes, then it should always be done with CSS. The way that you accomplish this is with the <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/text-transform">text-transform CSS property</a>.</p><p>Text transform will allow you to specify how you want to capitalise your element’s text. It has a number of options, e.g. all uppercase, all lowercase or you can choose to capitalise each word. There are also some options for working with other languages.</p><p>In our case it would be:</p><pre>text-transform: uppercase;</pre><h4>Why is this important?</h4><ol><li>Like my original example, it’s a lot harder to change the design later if you have written everything in uppercase. In my case, it was a small fix because it was only one instance. However, imagine this across a large website. You couldn’t easily switch the casing without having to edit all of the site’s content. CSS was literally made to make this stuff easy, lean into it!</li><li>When you copy and paste text written in uppercase, it will copy in uppercase. Unlike text styled with CSS, which will copy however you wrote it. (This is a constant source of frustration for me, especially when it’s a word I have trouble spelling, I copied it for a reason, and now you going to make me re-type, or use some tool to convert it anyway, come on friends, make my life easy not hard 😭!). <br><em>Note: It was pointed out that Chrome still copies and pastes in uppercase if you style with CSS. Can confirm Firefox doesn’t.</em></li><li>It’s not great for screen readers — uppercased text will be read out as individual letters (like abbreviations). So CSS is read as C.S.S. Just as JELLO would be read as J.E.L.L.O, not as the word Jello.<br><em>Note: some screenreaders, like Macs Voiceover, will still do this with text styled as uppercase using CSS — you can resolve this with an </em><a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-label_attribute"><em>aria-label</em></a><em>.</em></li><li>Reading modes don’t work as well. I have a particular interest in reading modes (Check out my blog post on <a href="https://medium.com/@mandy.michael/building-websites-for-safari-reader-mode-and-other-reading-apps-1562913c86c9">Building websites for Safari Reading Mode</a>). Reading modes, and other reading apps typically work by taking the content from your page and applying new styles. It relies on the proper use of semantic HTML, among other things, but also it assumes that you have written the content up as it is meant to be. If you uppercase your text in the content, it will come across as uppercase, therefore any styles reading mode attempts to apply to improve the reading experience will not work. The same applies to instances like Google Search results, or if you want to re-use the content in a different area of your site with different treatment. (Think back to CSS Zen Garden!)</li></ol><p>The main takeaway to remember is this:</p><blockquote>If your text does not make sense in uppercase, semantically, whether it be in your page, in search results, in reading modes, when you copy paste. If it is simply a design treatment for a specific instance, then use text-transform.</blockquote><p>Thanks for reading, and thanks to everyone for supporting my tweet frustrations 💜</p><p>Mandy</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b03ac2c65b99" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating 3D Layout with CSS using Grid & Perspective]]></title>
            <link>https://javascript.plainenglish.io/creating-3d-layout-with-css-using-grid-perspective-65cd03dfc56c?source=rss-eb5fea6e7083------2</link>
            <guid isPermaLink="false">https://medium.com/p/65cd03dfc56c</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[css-animation]]></category>
            <category><![CDATA[css-grid]]></category>
            <dc:creator><![CDATA[Mandy Michael]]></dc:creator>
            <pubDate>Thu, 16 Jul 2020 04:17:41 GMT</pubDate>
            <atom:updated>2020-07-31T00:28:59.619Z</atom:updated>
            <content:encoded><![CDATA[<h3>Creating 3D Layout with CSS using Grid &amp; Transforms</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/604/1*wy0PDiPysqceWnKwC6tJsA.gif" /></figure><p>CSS Grid isn’t just for creating flat, 2D layouts — we can make the most of the CSS grid and combine it with other CSS properties to do a lot of amazing things, like 3D layouts (and also some great shapes too).</p><p>If you just want to play with the Codepen, feel free, otherwise read on for some explanations/ step by step process.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fmandymichael%2Fembed%2Fpreview%2FExPebjY%3Fheight%3D600%26slug-hash%3DExPebjY%26default-tabs%3Dcss%2Cresult%26host%3Dhttps%3A%2F%2Fcodepen.io&amp;display_name=CodePen&amp;url=https%3A%2F%2Fcodepen.io%2Fmandymichael%2Fpen%2FExPebjY&amp;image=https%3A%2F%2Fassets.codepen.io%2F209981%2Finternal%2Fscreenshots%2Fpens%2FExPebjY.default.png%3Fformat%3Dauto%26amp%3Bha%3Dtrue%26amp%3Bheight%3D360%26amp%3Bquality%3D75%26amp%3Bv%3D1%26amp%3Bversion%3D1594872267%26amp%3Bwidth%3D640&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/7f5f01afbe82aaaa219d1a18594c13f9/href">https://medium.com/media/7f5f01afbe82aaaa219d1a18594c13f9/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cnuqXixxZNOno1I6cNTm7g.png" /><figcaption>Figure 1: CSS Grid layout. Top row has an image spanning two columns, bottom row has two images each taking up half the space.</figcaption></figure><p>There are a couple of things we’ll need to create this effect — CSS Grid and some transforms.</p><p>We’ll start off with a base layout (See figure 1) and we’ll add a 3D rotation to it. You can apply this to any kind of layout, we’ll just keep it simple for the purposes of the demo.</p><p>We’ll talk about the different shapes as seen in the header image at the end.</p><p>The HTML for the layout will look something like the following example. A grid container element, and three containers to hold our images, or text or whatever you want it to be.</p><pre><br>  &lt;div class=&quot;grid&quot;&gt;<br>    &lt;div class=&quot;grid-item&quot;&gt;&lt;img src=&quot;../image.jpg&quot;&gt;&lt;/div&gt;<br>    &lt;div class=&quot;grid-item&quot;&gt;&lt;img src=&quot;../image.jpg&quot;&gt;&lt;/div&gt;<br>    &lt;div class=&quot;grid-item&quot;&gt;&lt;img src=&quot;../image.jpg&quot;&gt;&lt;/div&gt;<br>  &lt;/div&gt;<br></pre><h4>Setting up the Grid</h4><p>We want to set up the grid first, CSS is Grid is so awesome that we don’t really need much code for our example, but depending on what layout you want to create you may need to get a bit fancier.</p><pre>.grid {<br>  display: grid;<br>  grid-gap: 10px;<br>  grid-template-columns: 1fr 1fr;<br>}</pre><pre>.grid-item {<br>  height: 200px;<br>  <br>  &amp;:nth-child(1) {<br>   grid-column: 1 / span 2;<br>  }<br>  <br>  &amp;:nth-child(2) {<br>   grid-row: 2 / span 1;<br>   grid-column: 1 / span 1;<br>  }<br>  <br>  &amp;:nth-child(3) {<br>   grid-row: 2 / span 1;<br>   grid-column: 2 / span 1;<br>  } <br>}</pre><p>For the purposes of the demo, we’ll be super verbose, I set up my grid with a gap between each item of 10px. I want 2 columns for the bottom row so we set a grid-template-columns to 1 fraction for each column.</p><p>Then I can place my items within the grid using nth-child and the grid-row and grid-column properties. Grid row and grid column allow me to define where within the grid I want each item to be placed and what the start and end columns are. (Remember that the grid lines start from 1 not 0).</p><p>I have images inside my grid items so I’m also going to add the following code so that they cover the entire available space.</p><pre>img {<br>   object-fit: cover;<br>   width: 100%;<br>   height: 100%;<br> }</pre><h4>Making the Grid rotate in 3D Space</h4><p>There are a couple of ways you can do 3D effects in CSS, for this example we’ll use 3D transforms.</p><pre>.grid {<br>   ...<br>   transform: rotate3d(3, 29, 0, 80deg);<br>   transform-style: preserve-3d;<br>   transform-origin: center;<br>}</pre><p>For me figuring out the 3D rotation (<a href="https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/rotate3d">rotate3D</a>) was just some trial and error, I basically opened up dev tools and edited the numbers in the style panel until it looked the way I wanted.</p><p><em>Note: If you want to animate this from flat to rotating like my example Codepen you would start with </em><em>transform:rotate3d(0, 0, 0, 0); and then in your animation you would put the end state. (More on this later)</em></p><p>We use transform-style to ensure the children of our element are positioned in the 3D space, so don’t forget this part.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/308/1*KSpSnneubg5E3vIMiL51gA.gif" /><figcaption>Figure 2: transform-origin: top left</figcaption></figure><p>Thetransform-origin property is really important. The rotate3D function rotates the element around a fixed axis — transform-origin defines the coordinate where the transformation is applied.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/308/1*dMas6apxnp5or5gDt2Ozyw.gif" /><figcaption>Figure 3: transform-origin: bottom center</figcaption></figure><p>Using the <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/transform-origin">demos on MDN</a> Figure 2, demonstrates a transform origin of top left, meaning that the rotation is applied from the top left of the element.</p><p>In Figure 3, the transform origin is set to centre. This is what we will use for our example, but you can play around with the options to find what best suits you.</p><h4>Staggering the items within the 3d Space</h4><p>In my example you’ll see that each grid-item is sitting at a different point within the 3D space, creating a “layer” effect.</p><p>To accomplish this we can add the <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/translate3d">translate3D</a> function to each of our grid items with the transform property. For example:</p><pre>&amp;:nth-child(1) {<br>   grid-column: 1 / span 2;<br>   transform: translate3d(0, 0, 40px);<br>}</pre><p>The translate3D function works very similarly to the standard translate, except you have an additional vector. Where translate has the x and y axis, translate3d has in addition to those a z axis. Because we want to translate our items in the 3D space we will leave the x and y values at 0 and set the z axis. You can play around with this to suit your needs, again I just opened the dev tools and positioned it manually in the style panel until it looked the way I wanted.</p><h4>Animating the rotation</h4><p>If you want to animate the rotation I used a CSS animation — starting “flat” at 0 and rotating to 80deg, with some slight offsets for positioning.</p><pre><a href="http://twitter.com/keyframes">@keyframes</a> rotatediv {<br> 10% {<br>  transform:rotate3d(0, 0, 0, 0);<br> }<br> 50% {<br>  transform: rotate3d(3, 29, 0, 80deg);<br> }<br> 80% {<br>  transform:rotate3d(0, 0, 0, 0);<br> }<br>}</pre><p>On the parent grid element, I added the animation property</p><pre>.grid {<br>  ...<br>  animation: 10s rotatediv infinite;<br>}</pre><h4>Creating non-rectangular shapes</h4><p>You might have noticed in the hero image of this article my images were not rectangular, instead, they were different shapes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/354/1*o2Hgh10Ulw00yilUMVkaNg.png" /><figcaption>Figure 4: Overlapping images in 3D space</figcaption></figure><p>The way you create something like this is by having the grid items overlap, then using clip-path to create the shapes.</p><p>Using the two bottom images, we set them both to start at grid line 1 and span for 2 columns.(See Figure 4 for an example)</p><pre>&amp;:nth-child(2) {<br>   grid-column: 1 / span 2;<br>}</pre><pre>&amp;:nth-child(3){<br>   grid-column: 1 / span 2;<br>}</pre><p>By having the images overlap, we can then clip out the parts we no longer need. You can create any shapes that you want, a useful tool is <a href="https://bennettfeely.com/clippy/">Clippy</a>, that gives you an interface and some base shapes. Firefox dev tools also has a fantastic path editor which is extremely useful for more complex shapes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/446/1*sA4L0LjxThUFkQQCHcEeTg.png" /></figure><pre>&amp;:nth-child(2) {<br>   grid-column: 1 / span 2;<br>   clip-path: polygon(0 0, calc(100% - 10px) 0, calc(50% - 10px) 100%, 0% 100%);</pre><pre>}</pre><pre>&amp;:nth-child(3){<br>   grid-column: 1 / span 2;<br>   clip-path: polygon(100% 0, 50% 100%, 100% 100%);<br>}</pre><p>With clip-path you need to define the position of each co-ordinate. I have used the calc function to match the borders with the grid-gap I set earlier (you can use a variable for this to make sure it’s consistent).</p><p>With this technique, you can create all sorts of shapes and layouts, and you can combine it with the 3D perspective to create some really interesting effects. Checkout some examples in my <a href="https://codepen.io/collection/XzePLw">Layout Experiments Collection</a> on Codepen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/556/1*i1QmYJITY2ChELnTgqclKQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/447/1*UlvawrC76A8t13doxPpVvg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/485/1*FusG7rtk5YXJwONt96Kw-Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/452/1*3hEb2DiOe5Vykm5nR8BJPQ.png" /></figure><p>This leaves us with our final effect, which you can <a href="https://codepen.io/mandymichael/pen/ExPebjY">find on Codepen</a>. There really are a lot of options here, go and experiment and have fun.</p><figure><img alt="Rotating CSS Grid with 3D perspective" src="https://cdn-images-1.medium.com/max/604/1*wy0PDiPysqceWnKwC6tJsA.gif" /></figure><p>Thanks, and have fun.<br>Mandy 💜</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=65cd03dfc56c" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/creating-3d-layout-with-css-using-grid-perspective-65cd03dfc56c">Creating 3D Layout with CSS using Grid &amp; Perspective</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setting up Playroom in a custom Component Library]]></title>
            <link>https://medium.com/pixel-and-ink/setting-up-playroom-in-a-custom-component-library-8f83e113be41?source=rss-eb5fea6e7083------2</link>
            <guid isPermaLink="false">https://medium.com/p/8f83e113be41</guid>
            <category><![CDATA[javacript]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[component-libraries]]></category>
            <category><![CDATA[tooling]]></category>
            <category><![CDATA[design-systems]]></category>
            <dc:creator><![CDATA[Mandy Michael]]></dc:creator>
            <pubDate>Mon, 13 Jul 2020 06:51:57 GMT</pubDate>
            <atom:updated>2020-07-13T08:19:20.146Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6TBagjTkJrO7VkBhrBaJGA.png" /><figcaption>#Spoilers — Playroom setup working for our Component Library</figcaption></figure><p>This is a story of setting up <a href="https://github.com/seek-oss/playroom">Playroom</a> in my component library may it help you through some of the bumps (specifically the ones I hit) along the way. Spoiler alert, I did get it running. 😄</p><p>First things first, the basic setup was pretty much as the <a href="https://github.com/seek-oss/playroom#getting-started">Getting Started</a> section of the readme explains — install playroom, setup the config. I set up a index.ts file inside my component library that manually listed the components I wanted playroom to have access too, I started with just one super basic component to keep things simple— a heading (we will talk more complex ones further on in the post).</p><p>It was literally just:</p><pre>export { Headline } <em>from</em> &#39;./publication/Headline/Headline&#39;</pre><p>Once I got the initial stuff set up I started hitting problems.</p><h4>Issue #1 — totally awesome Type Error. 🤨 Issue #2 — Can’t find my files 😒</h4><p>These two issues were related.</p><pre>TypeError: Cannot read property &#39;0&#39; of undefined <br>at Parser.getComponentInfo (/node_modules/playroom/node_modules/react-docgen-typescript/lib/parser.js)<br>    at /node_modules/playroom/node_modules/react-docgen-typescript/lib/parser.js</pre><pre>(node:63647) UnhandledPromiseRejectionWarning: Error: Cannot find module &#39;./src/component-library&#39;</pre><p>Both of these errors I was able to resolve with the help of the Fenders community, specifically <a href="https://twitter.com/luke__john">Luke</a> (It’s totally in the readme on Github as well — folks you gotta learn to read stuff, don’t be impatient like me 🙈). You have to make sure you are including the typeScriptFiles property in your playroom.config.js file (I just whacked it at the end).</p><p><em>For example:</em></p><pre>typeScriptFiles: <br>  [&#39;./component-library/**/*.tsx&#39;, &#39;!**/node_modules&#39;],</pre><p><em>💬 Narrator: Mandy was in fact very happy at this point.</em></p><p>Mission #1&amp;2 Complete ✅ 🎉</p><p><strong>Issue #3 — Can’t find the playroom files for Snippets and </strong><strong>frameComponent.</strong> <br>No probs, I’ll just comment that out for now, you don’t need it to get started. Let’s get back to this later.</p><p><em>💬 Narrator: Mandy would later regret this decision.</em></p><p>Mission #2 Complete 🙈</p><h4>Issue #4 —Loader Issues 😒</h4><pre>Module parse failed: Unexpected token <br>You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file.</pre><p>Need some loaders, cool cool. Thankfully Playroom had an<a href="https://github.com/seek-oss/playroom/blob/master/examples/typescript/playroom.config.js"> example in the Github Repo</a> so copy-paste that example and you <em>should</em> be good to go.</p><pre>webpackConfig: () =&gt; ({<br>  module: {<br>   rules: [{<br>     test: /\.tsx?$/,<br>     include: __dirname,<br>     exclude: /node_modules/,<br>     use: {<br>       loader: &#39;babel-loader&#39;,<br>       options: {<br>         presets: [<br>           &#39;@babel/preset-env&#39;,<br>           &#39;@babel/preset-typescript&#39;,<br>           &#39;@babel/preset-react&#39;,<br>         ],<br>       },<br>     },<br>  }],<br> },</pre><pre> resolve: {<br>   extensions: [&#39;.js&#39;, &#39;.ts&#39;, &#39;.tsx&#39;],<br> },<br>}),</pre><p>Stuff is compiling now success. 👍 Except now I’m getting new errors…</p><p>Mission #4 Complete ✅</p><p><strong>Issue #5 — Dependency Issues 😩</strong></p><pre>This dependency was not found:<br>component-library/typography/Heading/Heading.styled in ./src/component-library/src/typography/Heading/Heading.tsx</pre><p>Now that I’ve got stuff running I get a delightful blank screen. But that’s okay because I also got the above error.</p><p>This happens because inside each of our components we reference other dependencies, whether it’s helper functions, styling etc. Our codebase uses aliases to simplify the paths in our projects, so I need to set this up in the Playroom custom webpage config as well. I had a slight issue here because I’d copied it from our tsconfig which has wildcards in, which I totally didn’t need.</p><p>With that in mind let’s add that in:</p><pre>resolve: {<br>   extensions: [&#39;.js&#39;, &#39;.ts&#39;, &#39;.tsx&#39;],<br>   alias: {<br>      &#39;component-library&#39;:<br>          path.resolve(__dirname, &#39;src/component-library/&#39;),<br>   },<br>},</pre><p>👍 Yeah. Mission #5 Complete ✅ (I’m on a roll)</p><p><em>💬 Narrator: Mandy was getting very enthusiastic at this point</em></p><h4>Issue #6 — Syntax Errors 😒</h4><pre>Syntax Error: SyntaxError: //src/component-library/__product/index.ts: &#39;const&#39; enums are not supported.</pre><p>This one wasn’t so bad, we already have all our plugins defined for our component library configuration so I just had to copy-paste the ones we already had set up into the playroom.config.js file (I just put if after my presets inside the webpackConfig).</p><p>You can see an example of what we needed below:</p><pre>&quot;plugins&quot;: [<br>  [&quot;const-enum&quot;,<br>    { <br>       &quot;transform&quot;: &quot;constObject&quot;<br>    }<br>  ],</pre><pre>  &quot;@emotion&quot;,<br>  &quot;@babel/plugin-syntax-dynamic-import&quot;,<br>  &quot;@loadable/babel-plugin&quot;,<br>  &quot;@babel/plugin-proposal-class-properties&quot;,<br>  &quot;@babel/plugin-proposal-numeric-separator&quot;<br>] </pre><p>Mission #6 Complete ✅. Right now I’m feeling pretty good about myself.</p><p><em>💬 Narrator: Mandy’s confidence is being restored.</em></p><p>Now we are getting somewhere. At this point, Playroom is now compiling. Unfortunately, I’m getting some console errors.</p><h4>Issue #7 — Styling 🤔</h4><p>Our components have themes for three different products, as a result our styling makes heavy use of theming. To get this moving I set up a simplified use case of setting up the ThemeProvider with a preset theme for one of our products.</p><p>You might recall that earlier I commented out some code in the playroom.config.js file — specifically the frameComponent property. Now it’s time to set that up to pass through our themes.</p><p>I basically copied the one that Playroom has up on Github, mine looks like this.</p><pre>import React <em>from</em> &#39;react&#39;<br>import { ThemeProvider } <em>from</em> &#39;@emotion/react&#39;<br>import { thewest } <em>from</em> &#39;component-library/__styling/themes&#39;</pre><pre>export default ({ theme, children }) =&gt; (<br>   &lt;ThemeProvider <em>theme</em>={thewest}&gt;<br>      &lt;React.Fragment&gt;{children}&lt;/React.Fragment&gt;<br>   &lt;/ThemeProvider&gt;<br>)</pre><p>Then I had to set the path in the playroom.config.js file</p><pre>frameComponent: &#39;./src/playroom/FrameComponent.js&#39;,</pre><p>🙈<em> Mandy’s Note</em>: Friends, I spent an uncomfortable amount of time wondering why this wasn’t working before I realised that I still had the property commented out in the playroom config file. 😅 Don’t make the same mistake.</p><p><em>💬 Narrator</em>: This was when Mandy had regrets on her previous choices.</p><p>So with the Frame Component set up, I start getting some new errors. My current loader in webpack was set up only for tsxso it started throwing an error about missing loaders. As a result, I had to update this to work with js as well. Inside my playroom.config.js file so I just set it up for js as well</p><pre>{</pre><pre>test: /\.js$/,<br>include: __dirname,<br>exclude: /node_modules/,<br>  use: {<br>      loader: &#39;babel-loader&#39;,<br>      options: {<br>          presets: [&#39;@babel/preset-env&#39;, &#39;@babel/preset-react&#39;],<br>      },<br>   },<br>}</pre><p>Mission #7 Complete ✅</p><p><em>💬 Narrator</em>: At this point a component rendered and Mandy cheered and messaged some people on slack to let them know of her accomplishment. She also tweeted, knowing that it was just into the void.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lwVBctugG0EEahlIbd6fXw.png" /><figcaption>Success with a simple component rendering in Playroom</figcaption></figure><h4>Issue #8 — Adding the other Themes 😎</h4><p>Once I’d confirmed that my component was loading and rendering the correct styles I wanted to include the other themes we had set up in our component library. I honestly thought this would be a pain in the bumbag, but in reality, it was very straightforward for our codebase.</p><p>To do this I went back into the playroom config file and updated the theme property to reference our component library themes which we already had setup. ✨ Spectactular.</p><p>themes: ‘./src/component-library/__styling/themes.ts’,</p><p>Everything worked 🎉. Mission #8 Complete ✅</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6TBagjTkJrO7VkBhrBaJGA.png" /><figcaption>Themes for the Headline component</figcaption></figure><p><em>💬 Narrator: At this moment Mandy made videos of playroom in action to send the team. It’s unknown if they were as enthusiastic as she was, but Mandy liked to think they were.</em></p><h4>Issue #9 — Complicated Components 😫</h4><p>After successfully rendering a simple Headline component I took the next steps to render some more complicated ones.</p><p>🧐<em> Mandy’s Note</em>: While setting this up I noticed a bunch of flaws in the way some of our components, particularly our older ones from about 4 years ago were setup. So it was a nice exercise in flagging areas of improvement.</p><p><strong>Step 1</strong></p><p>I hit a few issues with this, mostly around wiring up data. This was thankfully fairly straightforward for me to set up given that we already have code in our codebase that handles this for our tests and rendering out components in the style guide.</p><p>This is pretty specific to our codebase so there isn’t much to show but what I did was set up our Provider and the test redux store— if you have a custom component library you probably have something similar setup already.</p><p>My FrameComponent.js file is starting to look like this</p><pre>&lt;ThemeProvider <em>theme</em>={theme}&gt;<br>   &lt;Provider <em>store</em>={store}&gt;<br>      &lt;React.Fragment&gt;<br>         &lt;style&gt;{`html, body { margin: 0; }`}&lt;/style&gt;<br>           {children}<br>      &lt;React.Fragment&gt;   <br>   &lt;/Provider&gt;<br>&lt;/ThemeProvider&gt;</pre><p><strong>Step 2 — Location</strong></p><p>Some of our components have this custom web link that requires access to Location. I added a StaticRouter from react-router-dom to resolve this — using the defaults worked fine.</p><pre>&lt;ThemeProvider <em>theme</em>={theme}&gt;<br>  &lt;StaticRouter&gt;<br>      &lt;Provider <em>store</em>={store}&gt;<br>        &lt;React.Fragment&gt;<br>           &lt;style&gt;{`html, body { margin: 0; }`}&lt;/style&gt;<br>             {children}<br>        &lt;React.Fragment&gt;   <br>     &lt;/Provider&gt;<br>  &lt;/StaticRouter<br>&lt;/ThemeProvider&gt;</pre><p><strong>Step 3 — Fallback Images</strong></p><p>Some of our components have fallback images that render when no image is provided by our content API. I needed to make these available to the ThemeProvider. I ended up hacking this but I figure that’s later Mandy’s problem.</p><p><em>💬 Narrator: At this point, Mandy is getting impatient again</em></p><h4>Issue #10 — too much data 🤦‍♀️</h4><p>Some of our components have an unnecessary amount of data and this caused some problems with rendering. Clearing the cache fixes temporarily but eventually, Chrome gets pretty sad again.. I didn&#39;t really resolve this, but it did flag some areas we could simplify some of our APIs.</p><h4><strong>Bonus: Issue #11 — </strong><strong>Uncaught ReferenceError: Card is not defined 💜</strong></h4><p>If you hit something like this, you probably forgot to add the component into your index file where you define all your components 😄</p><p>It’s easy to forget this stuff when you have been trawling through errors for a while. So don’t sweat it.</p><h4>In Conclusion</h4><p>It’s working, mostly, there are still some components that aren’t super happy but we’ll add those and fix over time.</p><p>In review, Playroom is mostly a step by step process to set up. A lot of the time is spent getting the Webpack config right and setting up the FrameComponent. If you aren’t super familiar with Webpack you might have some trouble here, so don’t be afraid to ask some folks for help. Otherwise, if your components aren’t overly complex I think you will have a pretty good time.</p><p>If your component library is doing a lot of stuff with data, locations, paths etc you might have a tougher road. It’s not that it’s impossible, it’s just more effort than a plug and play type situation. It becomes a little tedious as you step through each error — thankfully most of the errors are pretty helpful so it’s not like you are doing a lot of wild guessing.</p><p>This was my experience, it might not cover all your errors but I hope it helps some people get playroom into their component libraries, it really is a great tool. ☺️</p><p>Thanks for playing ✨💜</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8f83e113be41" width="1" height="1" alt=""><hr><p><a href="https://medium.com/pixel-and-ink/setting-up-playroom-in-a-custom-component-library-8f83e113be41">Setting up Playroom in a custom Component Library</a> was originally published in <a href="https://medium.com/pixel-and-ink">Pixel and Ink</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Generating CSS breakpoints from props with CSS-in-JS and TypeScript]]></title>
            <link>https://medium.com/pixel-and-ink/generating-css-breakpoints-from-props-with-css-in-js-and-typescript-50665291589b?source=rss-eb5fea6e7083------2</link>
            <guid isPermaLink="false">https://medium.com/p/50665291589b</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[css-in-js]]></category>
            <category><![CDATA[components]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[front-end-development]]></category>
            <dc:creator><![CDATA[Mandy Michael]]></dc:creator>
            <pubDate>Fri, 10 Apr 2020 00:28:23 GMT</pubDate>
            <atom:updated>2020-04-10T02:24:21.129Z</atom:updated>
            <content:encoded><![CDATA[<p>One of the things I love about CSS is how easy it is to change things at different breakpoints. Maybe you want to drop text, images, or even change the layout.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1007/1*Bs63bJNxO20kJjGpWiQrsQ.png" /></figure><p>You might do this for a number of reasons, maybe it’s to simplify a design on a smaller screen, or in the case I hit recently, to make things look more consistent when it’s stacked in a list. This should be pretty straightforward, but, when you are building components that can be shared reused and put together in a number of ways this can become more difficult.</p><p>What we wanted to do in our product was to define what we wanted to show at our pre-defined breakpoints. There are a few ways you could accomplish this, but this is the solution we came up with for our codebase.</p><p>I’m going to use a teaser or summary text as an example — on mobile we might hide the teaser and on desktop, we will show it, or vice versa. Our product has a lot of different variations on layout, an example is an image below, the teaser is the text “Jello likes to eat marshmallows…”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/470/1*YmngT6b9NSNFGS55V9Hlsg.png" /><figcaption>Horizontal card layout with image, headline, teaser text and byline with timestamp</figcaption></figure><h4>The setup with TypeScript</h4><p>First, the types, you don’t need TypeScript to make this work, but this section does outline all the different states, so it’s good to read through regardless.</p><p>When it comes to hiding and showing things <em>in components</em> there are often a few scenarios we are trying to create.</p><ol><li>In this instance <em>never</em> <em>show</em> the thing</li><li>In this instance <em>always</em> <em>show</em> the thing</li><li>In this instance <em>sometimes show</em> the thing (e.g. at x breakpoint show the thing, but hide at y breakpoint</li></ol><pre>type TeaserState = &#39;hidden&#39; | &#39;visible&#39;</pre><pre>type TeaserMode = <br>   TeaserState | Record&lt;&#39;initial&#39; | &#39;xs&#39; | &#39;sm&#39; | &#39;md&#39;, TeaserState&gt;</pre><p>I’ve set up two types, a TeaserState Union type that will set the teaser to be hidden or visible. This ensures that we can’t have something that is both hidden and visible at the same time (For more info you can read <a href="https://medium.com/pixel-and-ink/a-quick-tip-for-props-types-in-reusable-components-11b7a21e296e">Props and Types in reusable components</a>). This takes care of points 1 and 2 above.</p><p>In order to deal with option 3 (sometimes show the thing), we have the second type TeaserMode — teaser mode is also a Union, specifically a union of TeaserStateand a Record (the values in the Union are basically used as attributes of the new type).</p><p>Our record lets us set breakpoints to apply TeaserState to (these align to the breakpoints we have set in our codebase). initial in this instance represents 0px to xs — so mobile devices. The usage might look something like</p><pre><strong>teaserMode</strong>: { <br>  <strong>initial</strong>: &#39;visible&#39;, <strong>xs</strong>: &#39;hidden&#39;, <strong>sm</strong>: &#39;visible&#39;, <strong>md</strong>: &#39;hidden&#39; <br>},</pre><p>TeaserMode is what we will use for our actual component prop.</p><h4>The Component</h4><p>Using our TeaserMode prop if we pass the string &#39;hidden&#39; we have some code in the component itself that prevents the component from rendering at all. If it’s set to visible then we just render the component and move on. That’s the easy part.</p><p>When it comes to showing or hiding the component at different breakpoints this is when we jump into the styles. I mentioned earlier we used EmotionJS for styling so we make the TeaserMode prop available to Emotion.</p><p>Inside Emotion we have a JS function that looks like the following (I changed some names so that it would format easier, they are a bit more verbose in our actual code):</p><pre>function teaserStyles({ teaserMode }: TeaserProps): CSSObject {</pre><pre>// If there is no teaserMode do nothing basically<br>if (!teaserMode) {<br>   return {}<br>}</pre><pre>// If it&#39;s visible set to display block otherwise no styles please because we aren&#39;t rendering the component anyway<br>if (typeof teaserMode === &#39;string&#39;) {<br>   return <br>    { display: teaserMode === &#39;visible&#39; ? &#39;block&#39; : undefined  }<br>}</pre><pre>return (</pre><pre>  // Generate all the breakpoints except for initial<br>  teaserMode &amp;&amp;<br>    Object.entries(teaserMode).slice(1).reduce&lt;CSSObject&gt;(<br>     (styles, [breakpointVal, teaserModeBP]) =&gt; {</pre><pre>      styles[breakpoint(breakpointVal as BreakpointKey)] = {        </pre><pre>        display: teaserModeBP === &#39;hidden&#39; ? &#39;none&#39; : &#39;block&#39;,</pre><pre>      }</pre><pre>      return styles</pre><pre>}, {})</pre><pre>)}</pre><p>Depending on how you set things up you may not need the first two parts, but I’ve included it for demonstration purposes in case you get stuck.</p><p>The core part is how we generate the breakpoints — the code takes each of our breakpoints in our Record (skipping initial using slice) and generates the styles that will set the teaser to either display: block; or display: none;</p><p>For our actual component styles, we add in the styles generated by our function teaserStyles, and additionally, add in a breakpoint from 0-xs that sets the initial state for the teaser.</p><pre>export const StyledTeaser = styled(&#39;p&#39;)&lt;TeaserProps&gt;({ <br>   margin: 0,<br>   color: black,<br>   //..other styles<br>},<br>teaserStyles,</pre><pre>({teaserMode }) =&gt; {<br>   const smBpVal = teaserMode &amp;&amp; Object.entries(teaserMode)[0][0]  <br>   <br>   return {<br>      [breakpointMax(&#39;xs&#39;)]: {<br>      display: smBpVal === &#39;hidden&#39; ? &#39;none&#39; : &#39;block&#39;,</pre><pre>   },</pre><pre>)</pre><p>Finally, the last step — when using our component we can set the value we want as one of the following:</p><pre>teaserMode: &#39;hidden&#39; // will not render the teaser at all<br>teaserMode: &#39;visible&#39; // will always render the teaser<br>teaserMode: { <br>  initial: &#39;visible&#39;, xs: &#39;visible&#39;, sm: &#39;visible&#39;, md: &#39;hidden&#39; <br>}, // will render the teaser from 0 - md breakpoint and then not display from md and above.</pre><p>This is obviously only one way to accomplish this, you might solve the problem differently, you can also include reasonable default states if you don’t want to set this all the time, but you can get a general gist of how to accomplish a similar strategy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/903/1*wiVygTcfHiGarnR-f7axaA.jpeg" /><figcaption>Example layout changes between breakpoints</figcaption></figure><p>This approach can work for all sorts of things. We can also use it to change other styles of a component at different breakpoints, perhaps the orientation of a card from landscape to stacked, or different margin or padding sizes. It opens up a lot of opportunities and helps to create more flexible components within your system.</p><p>Enjoy</p><p>Mandy</p><p>*Normally I’d have better names for variables but I shortened them so they’d sit nicer in the page. Personally I prefer something a bit more verbose, but you do you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=50665291589b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/pixel-and-ink/generating-css-breakpoints-from-props-with-css-in-js-and-typescript-50665291589b">Generating CSS breakpoints from props with CSS-in-JS and TypeScript</a> was originally published in <a href="https://medium.com/pixel-and-ink">Pixel and Ink</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The performance benefits of Variable Fonts]]></title>
            <link>https://uxdesign.cc/the-performance-benefits-of-variable-fonts-79af8c4ff56c?source=rss-eb5fea6e7083------2</link>
            <guid isPermaLink="false">https://medium.com/p/79af8c4ff56c</guid>
            <category><![CDATA[css]]></category>
            <category><![CDATA[ux]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[visual-design]]></category>
            <category><![CDATA[typography]]></category>
            <dc:creator><![CDATA[Mandy Michael]]></dc:creator>
            <pubDate>Mon, 09 Mar 2020 04:42:00 GMT</pubDate>
            <atom:updated>2020-03-13T00:17:02.556Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8IgFKQkPc19d_SkmFiVfbw.png" /></figure><p>When we think about web fonts and their impact on the performance on our websites we often focus on three main areas:</p><ul><li>The number of font requests</li><li>Font file size</li><li>Time to first render</li></ul><p>I wanted to see how variable fonts faired in these situations and did a review comparing with standard fonts. Here are my results.</p><h3>Reducing the number of requests</h3><p>This can be accomplished several ways including caching, CDNs and reducing the number of style variations. I’m not going to get into the use of CDN’s or caching because it’s essentially the same process for standard fonts as it is for variable fonts. Instead, I will focus on reducing style variations.</p><p>In a world of standard fonts, reducing the number of styles reduces the number of requests because it results in fewer files and therefore fewer requests. Typically this meant that we’d have to plan our typography choices and weigh up the cost of design over the cost of performance and decide whether the cost of additional styles is worth the impact to performance.</p><p>With variable fonts, because they can contain multiple variations in the one file — this means we have immediately reduced the number of requests without having to question our designers about their typography choices.</p><p>Variable fonts, in essence, reduce the number of requests simply by being a variable font. But if the font has all the information in it, what does that do to file size?</p><h3>Reducing the font file size</h3><p>This can be achieved several ways, the first step is usually choosing the most efficient Webfont format like WOFF2 for example.</p><h4>Setting a baseline</h4><p>I conducted a review of different font file sizes specifically using <a href="https://github.com/adobe-fonts/source-sans-pro">Source Sans Pro</a> by Adobe because it’s open source and on Github.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hvqTCYeYNHyqp3JR-XoKpg.png" /><figcaption>Source Sans Pro OTF Comparison — Single Weight: 243kb, Variable Font 405kb</figcaption></figure><p>As a baseline, a single weight of the standard version of the font Source Sans Pro is approximately 243kb in OTF format and the size of the variable font in OTF format is 405kb. This makes the variable font 73% larger than a single weight of the standard Source Sans Pro font.</p><p>But given that the variable font contains all the information for all the font weights the resulting combined file size of all the standard Source Sans Pro weights is approximately 1170kb.</p><p>That is nearly 3 times the size of the variable font.</p><p>Even if you just wanted the bold and regular versions of the font, two versions are still larger than the single variable font.</p><h4>OTF vs WOFF2</h4><p>OTF file sizes, however, are pretty large in comparison to the font compression you get from formats like WOFF and WOFF2.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T-_qxbXPOdXsXoA084ERvA.png" /><figcaption>Single Weight: OTF: 234kb, WOFF2: 111kb Variable Font: OTF: 405kb, WOFF2: 112kb</figcaption></figure><p>So in comparison, we can gain significant reductions in file size by simply using WOFF2 versions of the fonts.</p><p>What I did find interesting was how significant the savings were in the variable font. Dropping from 405kb down to 112kb, making it almost the same size as a single weight of Source Sans Pro (standard font).</p><p>This took me a bit by surprise and I’m pretty confident saying this won’t be the case in all scenarios. But it’s pretty great to see how effective the WOFF2 compression can be on a variable font.</p><h4>Reducing file size by subsetting</h4><p>With standard fonts, another way to reduce file size is by subsetting the font to remove unnecessary characters or reducing it to a specific language set like only Latin characters.</p><p>This comes with some risks and can result in parts of your typography rendering as your fallback and not your font if you accidentally remove characters you need.</p><p>You can subset fonts with tools like <a href="https://github.com/filamentgroup/glyphhanger">Glyphanger, by filament group</a>, they have a great readme on the Github page and it works with both standard fonts and variable fonts.</p><p>I ran a Glyphhanger over the standard and variable versions of Source Sans variable and subset it to uppercase and lowercase English characters, numbers and special characters like exclamation marks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z-mwoeiLR2cR2zQKk4zPbA.png" /></figure><p>This reduced the file size of the Single weight from 111kb down to 16kb (85% savings, nice). The variable font dropped from 112kb down to 27kb (75% savings, acceptable!).</p><p>Again, I was pretty surprised by this. I was expecting Source Sans Variable to be larger than this. Keeping in mind we typically use both a bold and regular version of a font a single variable font at 27kb is still smaller than two weights in the standard font. So that is a pretty great saving.</p><p>It’s important to note at this point though that this is just my experience with Source Sans, it will vary between fonts and you may find your outcome is worse than using standard fonts. So don’t just jump in blindly, make sure you test and compare and do what is best for your project.</p><h4>Additional file size considerations</h4><p>Some additional things to consider about file size — a single larger font file will take longer to load than multiple smaller font files.<br> <br>With standard fonts because individually they are <em>typically </em>a<em> </em>smaller file size you might have your body text render quicker and then the bold text load, and so on. The benefit here is that because, individually, the files are smaller you may get your content sooner.</p><p>With variable fonts you have to wait for the single file to load before any text is rendered — this can result in a longer delay. However, having to wait for all the font data to download before rendering the text avoids the problem where part of our text might load and affect the message while we wait for other font versions to load in. Also, because we only load the fonts in once, we are not forcing the page to re-redraw every time a new font is loaded.</p><p>So when it comes to file size, the verdict on variable fonts is, “it depends”, because it is going to depend on your site, your requirements and the fonts you are using.</p><h4>Reducing time to first render</h4><p>So finally let’s look at reducing the time to first render. This has an obvious performance benefit because it’s in the name, and as I just explained the larger single file can take slightly longer to load than an individual standard font. So even a short delay with a Flash of Invisible Text can make the user <em>feel</em> like a page is loading slower than it is. As a result, and in my opinion, we should aim for a Flash of Unstyled Text instead of a Flash of Invisible Text.</p><h4>Flash of Invisible Text (FOIT)</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/884/1*55rmVeIzERBSKlNpg9mb_A.png" /><figcaption>Example image demonstrating a flash of invisible text (FOIT)</figcaption></figure><p>The “Flash of Invisible Text” is when we block or delay the font from loading until it’s available. So our page can look very empty until the fonts have loaded in.</p><h4>Flash of Unstyled Text (FOUT)</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/596/1*RUzEsLex0fwVRPvmO32U_g.png" /></figure><p>Flash of Unstyled Text (FOUT) is when we load a fallback font and switch or swap to our custom fonts when they are ready.</p><p>In my opinion, a flash of unstyled text is a better experience than not being able to read your content at all — so what we want to be able to do is embrace FOUT but try and limit the impacts as much as we can.</p><p>A simple way to embrace FOUT is by using the font-display property with the value of “swap” — this will render our fallback font defined in our font stack and then swap in the custom font when it has loaded. There are other options for font-display, which I recommend you investigate, but for FOUT, swap is a good place to start.</p><p>font-display: swap;</p><p>One of the issues with FOUT is that as the fonts swap, we often see the layout shifts to accommodate for the different “sized” fonts.</p><p>With Standard Fonts we can modify the line-height, size and letter-spacing to try and match our system and custom fonts to reduce that layout shifting. We can do this with a fantastic tool called <a href="https://meowni.ca/font-style-matcher/">Font Style Matcher</a>, built by <a href="https://twitter.com/notwaldorf">Monica Dinculescu</a>, inspired by a fantastic blog post by Helen Holmes called <a href="https://helenvholmes.com/writing/type-is-your-right/">Type is Your Right</a> (seriously great article go read it).</p><p>What I’m hoping to see is as variable fonts become more widely supported across Operating Systems we can reduce this layout shifting by using a variable <em>system</em> font as a fallback in our font stack.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QCgTSwkPYV3dl4lxK7qYog.png" /></figure><p>Imagine if we had system fonts with the ability to control for weight, width and optical size — we would be able to modify the font itself to match the size, and the space it takes up, much more closely with our custom fonts. Combining with the existing techniques of line-height, font size etc, we could create an incredibly smooth transition between the two fonts meaning less noticeable FOUT and less redraw due to less layout shifting.</p><p>This would be incredible, and I hope we get to this at some point.</p><h4>TL;DR Variable Font Performance</h4><p>Variable fonts reduce the overall combined file size and automatically reduce the number of network requests by simply being a variable font.</p><p>Even if you consider the slightly larger file sizes, when combined with improved font compression formats like WOFF2, font subsetting and font loading techniques like font-display: swap; we end up in a situation where we <em>can</em> still get smaller overall font file sizes as well as a significant increase in stylistic opportunity.</p><p>If we can improve some of our pre-existing technical problems around performance we can start to shift our focus. We no longer need to trade-off design for performance.</p><p>It becomes an opportunity to figure out how we can use this technology to create better experiences for our users. Variable fonts offer so much variation, this means we can create experiences which better suit our devices, and environments, and adjust our fonts to create more accessible and legible text, without being concerned about how the increase in the number of styles is going to blow out our page size.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=79af8c4ff56c" width="1" height="1" alt=""><hr><p><a href="https://uxdesign.cc/the-performance-benefits-of-variable-fonts-79af8c4ff56c">The performance benefits of Variable Fonts</a> was originally published in <a href="https://uxdesign.cc/">UX Collective</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Resize text to fit the parent with variable font width axis]]></title>
            <link>https://medium.com/@mandy.michael/resize-text-to-fit-the-parent-with-variable-font-width-axis-16921b6687ae?source=rss-eb5fea6e7083------2</link>
            <guid isPermaLink="false">https://medium.com/p/16921b6687ae</guid>
            <category><![CDATA[responsive-design]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[variable-fonts]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Mandy Michael]]></dc:creator>
            <pubDate>Fri, 06 Mar 2020 14:05:05 GMT</pubDate>
            <atom:updated>2020-03-09T06:30:12.531Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Nj8X6X0jAqXp_JzFGZ8DNA.gif" /></figure><h4>Adjust the width of your text to fit its parent container using a variable font width axis</h4><p>One of the most exciting things for me about variable fonts is that their flexibility opens up an opportunity to create more responsive designs and components.</p><p>There are a number of ways you can have text resize to fit its parent container, but it’s been largely limited to adjusting the font size. The problem with this approach is that making the font smaller is not always the best option for our designs.</p><p>With variable fonts that contain a width axis, we can adjust the font-stretch property with CSS to condense the font. When we combine this with font-size as well we can create more flexible response text on the web. For our example, we are using <a href="http://localhost:8080/posts/resize-to-fit/Barlow">Barlow</a> which has a width axis with a range of 300% to 500%.</p><h3>The Code</h3><p>You can either check out the Codepen, or you can read on to get a breakdown.</p><p><em>Note: This is an experiment, meaning I have in no way optimised this for performance. If you plan on using this for anything in prod, please make sure you think about the performance impacts.</em></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fmandymichael%2Fembed%2Fpreview%2FNWqaNJL%3Fheight%3D600%26slug-hash%3DNWqaNJL%26default-tabs%3Djs%2Cresult%26host%3Dhttps%3A%2F%2Fcodepen.io&amp;display_name=CodePen&amp;url=https%3A%2F%2Fcodepen.io%2Fmandymichael%2Fpen%2FNWqaNJL&amp;image=https%3A%2F%2Fscreenshot.codepen.io%2F209981.NWqaNJL.small.aac90236-ed13-49e5-90c0-2cd550fb7ff2.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/0b030106fd82073e698bbcdb7d20602d/href">https://medium.com/media/0b030106fd82073e698bbcdb7d20602d/href</a></iframe><p>To accomplish this we need a few things, firstly the width of the parent container and secondly, we will use scrollWidth to measure the width of our text.</p><pre>const parentContainerWidth = text.parentNode.clientWidth;<br>const currentTextWidth = text.scrollWidth;</pre><p>Once we have these we also need to determine what the current font-stretch value is so we can update it as the parent changes. One way to do this is to use getComputedStyle.</p><pre>const currentFontStretch = <strong>parseInt</strong>(window.<strong>getComputedStyle</strong>(text).fontStretch);</pre><p>Finally, we can use these values to determine the new font-stretch value. Basically what we are doing here is working out a percentage value to assign to our font-stretch property. Math.min and Math.max are really useful in this case because I don&#39;t want to extend past the available axis range for the font.</p><pre>const newValue = Math.<strong>min</strong>(Math.<strong>max</strong>(300, (parentContainerWidth / currentTextWidth) * currentFontStretch), 500)</pre><p>If we break this down, let&#39;s say our parent container is 300px wide, our text is 150px wide and out current font-stretch value is at the starting value of 300%. If we divide the parent by the child we’d have a value of 2, which we then multiply by the current font-stretch of 300, giving us a value of 600 e.g. Math.max(300, 600). Because Math.max will return the highest value we’ll take 600, leaving us with Math.min(600, 500) . In this case, we want the minimum value (our maximum font-stretch) so the final value will be 500.</p><p>This will ensure that our font-stretch value matches the width of our container, within the constraints of the available values.</p><p>Finally, we can use CSS custom properties to update our font-stretch value in our CSS leaving us with the final effect.</p><pre>text.style.<strong>setProperty</strong>(&#39;--fontStretch&#39;, newValue + &#39;%&#39;);</pre><h3>Bonus</h3><p>While I was working on this I wanted a quick way to resize a div for the demo, I procrastinated a lot on it because I thought I’d have to write a bunch of code. Turns out, Chris Coyier had a great CSS only suggestion! resize. This property accepts a number of options and sets whether an element is resizable, and in which directions you can resize it! It only works on elements that don&#39;t have an overflow of hidden though. Check it out on <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/resize">MDN</a>. (Or have a play with the bottom right corner on the header box).</p><p>You can see the full implementation in the <a href="https://codepen.io/mandymichael/pen/NWqaNJL">Codepen</a> example.</p><p>Have fun and make cool things.</p><p>Mandy</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=16921b6687ae" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>