<?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 Andrico Karoulla on Medium]]></title>
        <description><![CDATA[Stories by Andrico Karoulla on Medium]]></description>
        <link>https://medium.com/@andricokaroulla?source=rss-e274c246e46d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*S5DtvoPsU-V_sM8fSvhAvA.jpeg</url>
            <title>Stories by Andrico Karoulla on Medium</title>
            <link>https://medium.com/@andricokaroulla?source=rss-e274c246e46d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 16:23:34 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@andricokaroulla/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[What is a component library and should you build your own?]]></title>
            <link>https://medium.com/@andricokaroulla/what-is-a-component-library-and-should-you-build-your-own-d42a0d2dc73a?source=rss-e274c246e46d------2</link>
            <guid isPermaLink="false">https://medium.com/p/d42a0d2dc73a</guid>
            <category><![CDATA[css]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Andrico Karoulla]]></dc:creator>
            <pubDate>Tue, 06 Aug 2024 23:19:26 GMT</pubDate>
            <atom:updated>2024-08-06T23:19:26.039Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ins1t_zY5TgP03NJYmdLRw.png" /></figure><blockquote><em>💡 I want to give a special shoutout to stephband (</em><a href="https://front-end.social/@stephband"><em>Mastodon</em></a><em>, </em><a href="https://bsky.app/profile/stephen.band"><em>Bluesky</em></a><em>) for proofreading and providing feedback.</em></blockquote><blockquote><em>Please note that this is a X-Post from my </em><a href="https://component-odyssey.com/articles/10-what-is-a-library-should-you-build-your-own"><em>site</em></a><em>. The content is largely the same, but the original post has interactive snippets and videos that are omitted in this article.</em></blockquote><h3>What if there were no music albums?</h3><p>I’m a huge music fan. One of my favourite pastimes is to put on a record and listen to it front to back. A music album is simple in concept, it’s a suite of recorded tracks by an artist and is considered a complete and coherent set of songs.</p><p>But what if recorded music didn’t exist? Instead of putting songs to tape, CD, or mp3 (or FLAC if you’re that way inclined), you could only listen to an album if the artist played it live for you. You’d need to go to the band, ask them to set up their equipment and get them to play the album front-to-back. They’d need to play it the same way every time to ensure that everyone had the exact same experience.</p><p>The cracks would start to show. It’s not an efficient way to ensure that anyone interested in the band’s music can listen to it. If Taylor Swift were to play her song Fortnight personally for every person who listened to it on Spotify, it would take her 3,179 years. And that doesn’t account for any <a href="https://www.threads.net/@adhd.international/post/C6ugTXAPt71?hl=en-gb">plane travel</a>. Artists would get bored, maybe even careless, leading to a lesser experience for their listeners.</p><p>So how does this relate to web development? Every time you build a UI control, you have to ensure it’s functioning, robust, and accessible. You’ll get bored if you keep rewriting the same UI every time. Mistakes will slip through, leading to a worse experience for your end users.</p><h3>A little about me</h3><p>I’ve been a web developer for nearly 10 years, and I’ve written hundreds of components myself, often the same UI pattern many times. I’ve used dozens of component libraries, and have built admin dashboards, component libraries, mobile applications, blogs, figma plugins, VSCode extensions, and more. This article will be a distillation about where I see the role of components, libraries, and whether developers should write their own.</p><h3>What is a component?</h3><p>When building user interfaces, we don’t write all the HTML markup from scratch every single time. We write our UIs using components — reusable building blocks that encapsulate common UI patterns. Writing a component lets you use it multiple times in a single project or even in independent projects.</p><p>Here I’ve written a counter component, I’ve written it once and used it in multiple places on the page.</p><pre>&lt;body&gt;<br>  &lt;div class=&quot;wrapper&quot;&gt;<br>    &lt;counter-button&gt;&lt;/counter-button&gt;<br>    &lt;counter-button&gt;&lt;/counter-button&gt;<br>    &lt;counter-button&gt;&lt;/counter-button&gt;<br>  &lt;/div&gt;<br><br>  &lt;script type=&quot;module&quot;&gt;<br>    import { LitElement, html } from &#39;lit&#39;;<br>    class CounterButton extends LitElement {<br>      constructor() {<br>        super();<br>        this.count = 0;<br>      }<br>      static properties = {<br>        count: { type: Number }<br>      };<br>      _increment() {<br>        this.count++;<br>      }<br>      render() {<br>        return html`<br>          &lt;button @click=${this._increment}&gt;Count: ${this.count}&lt;/button&gt;<br>        `;<br>      }<br>    }<br>    customElements.define(&#39;counter-button&#39;, CounterButton);<br>  &lt;/script&gt;<br>&lt;/body&gt;</pre><p>Us tutorial creators like to demo counters like they’re going out of style, but a real-world application will contain dozens of different UI patterns written as components.</p><p>In this article, I’ll group CSS rules that provide styling for certain UI patterns under the components umbrella. The definition can get murky depending on who you ask.</p><h3>What is a component library?</h3><p>Not all components are standalone. It makes sense for many components to be grouped within a single package, called a component library.</p><p>If you want your site to have a specific look or feel, you can use a <em>component library</em>. There are component libraries that:</p><ul><li>offer components that adhere to a design specification.</li><li>offer multiple solutions for a specific UI pattern.</li><li>work with specific toolchain</li></ul><p>But they come in different shapes and sizes. The definition I’ve come to use when defining a component library is the following:</p><p><em>A component library is a set of reusable components that are cohesive in their utility, or appearance (or both). A great component library will help developers achieve their UI needs efficiently, while offering an exemplary experience for the end user.</em></p><h3>What’s the difference between a component library and a design system</h3><p>I talk about guidelines and design systems later in this article, so I’ll take a moment to disambiguate them. It can be difficult to see where one ends, one begins, or one subsumes the other.</p><p><strong>Design Systems</strong></p><p>I see a design system as a specification for how things should look, feel, and behave. A design system can encompass a product, a brand, or a company to ensure consistency across the suite of experiences. A comprehensive design system will dictate everything from font families, font sizes, spacing sizes, UI patterns, and copy guidelines.</p><p>A few of the most well-known design systems include:</p><ul><li><a href="https://m3.material.io/foundations/layout/understanding-layout/overview">Material Design</a> (Google)</li><li><a href="https://base.uber.com/6d2425e9f/p/294ab4-base-design-system">Base Design</a> (Uber)</li><li><a href="https://www.lightningdesignsystem.com/getting-started/">Lightning Design System</a> (Salesforce)</li></ul><p>While many design systems are specific to companies, there are design systems, like Material Design, that teams across the globe use to shortcut their way to building familiar feeling products. You’ve probably used a handful of products that use Material Design principles but they’re <a href="https://www.smashingmagazine.com/2021/02/material-design-text-fields/">certainly not free from basic usability issues</a>.</p><p><strong>Component Libraries</strong></p><p>As for component libraries, they may or may not be the code implementation of a design system. If you work for a company with a design system, it’s likely that the corresponding component library (if one exists), is tightly integrated with it.</p><p>For instance, Google’s <a href="https://material-web.dev/">Material Web</a> is a web component implementation of Material Design. <a href="https://baseweb.design/components/button/">Base Web</a> and <a href="https://lwc.dev/guide/introduction">Lightning Web Components</a> are also open source too.</p><h3>A brief history of component libraries</h3><p>The concept of UI components (or widgets) has been around for a long time. If you want to see a museum’s worth of retro user interfaces, grab some popcorn and watch this <a href="https://vimeo.com/61556918">2+ hour video of “all the widgets” from 1974–1990</a>.</p><p>From the early 2000s, we’d start seeing component libraries made to help developers build for the web. The web browser landscape back then was unrecognisable from what we see now. Versions of Internet Explorer deviated away from the spec entirely, which was particularly problematic given the <a href="https://en.wikipedia.org/wiki/Usage_share_of_web_browsers#TheCounter.com_(2000_to_2009)">huge market share that IE had back in the day</a>. <a href="https://www.quora.com/Why-do-people-hate-IE6-so-much-and-want-it-to-die#:~:text=IE6%20doesn&#39;t%20support%20web,PNGs%20to%20natively%20support%20IE6">Internet Explorer 6 was famously known for being a pain to develop for</a>. Mainly due to its incorrect implementation of the <a href="https://www.webfx.com/blog/web-design/definitive-guide-to-taming-the-ie6-beast/#616723179a361-3">box model</a>, and lack of CSS2 support.</p><blockquote><em>💡 TIL, Internet Explorer supported a “</em><a href="https://www.notion.so/Complete-written-content-806882f918204715a6e45df68f492bdd?pvs=21"><em>quirks mode</em></a><em>” that let developers write non-standard HTML and CSS to appease older browsers that didn’t support the standards.</em></blockquote><p>Fortunately, when I started web development in earnest, many of these issues were ironed out. By this point, there were still a handful of libraries that made writing complex interfaces with cross-browser support a little easier. <a href="https://jqueryui.com/">jQuery UI</a>, the first component library I used, supported accordions and other widgets. But the browser is constantly evolving, and we now have a native way of implementing this accordion pattern using the details and summary elements, available in all browsers in 2020. With these elements, you can get pretty far along creating interactive accordions without JavaScript.</p><p>Contrast this with 2009, and these elements haven’t been implemented in any browser. It required a fair bit of JS to get working. Have a look at the <a href="https://code.jquery.com/ui/1.7.0/jquery-ui.js">jQuery UI v1.7 source code</a>, and CTRL+F “accordion” if you want to see how web devs were implementing accordions 15 years ago.</p><p>Over the next couple of decades, the capabilities of the web grew. More powerful devices meant more powerful browsers. More powerful browsers meant web applications became more ambitious. Developers responded by creating the tools to help us build these applications by allowing us to create UIs using <em>building blocks</em>, i.e., a component model. We saw a proliferation of these component-based frameworks. I’m talking Angular, React, and Vue. Each with its own rich ecosystem of component libraries.</p><p>There’s a reasonable argument to be made that there has been an over-correction and that the frontend landscape is now oversaturated with tools that are <em>too</em> powerful for most people’s needs, but let’s not go there.</p><blockquote><em>This section is extended with interactive snippets on the </em><a href="https://component-odyssey.com/articles/10-what-is-a-library-should-you-build-your-own"><em>original post</em></a></blockquote><h3>What makes a good component library?</h3><p>The challenge with building a component library is that they’re not a <em>one-and-done</em> deal. Many of the most popular libraries have been around for years and have had heaps of research, usage feedback, and contributions to get them to where they are now.</p><p>I’ve found that a good component library often has the following traits:</p><ul><li>It understands the problems of its target developers and solves those problem well</li><li>It has great documentation</li><li>It ensures a good experience for the end-user</li><li>It’s robust and caters for appropriate input modes and devices.</li></ul><p>On the flip side, a way to discern if a component library <em>isn’t good</em> is if it doesn’t consider accessibility, has an inconsistent API, has little to no project stewardship, or has no clear and consistent documentation.</p><h3>What are the benefits of using a component library?</h3><p>We know what a good component library looks like, so let’s see how one can make your life, and the lives of your users a little better.</p><h3>Component libraries save you time</h3><p>If you’re on a project with a tight deadline, it’s important to be efficient. But efficiency shouldn’t come at the cost of crafting a robust web experience. Using a component library lets you spend less time reinventing the wheel and more time focusing on the finer details.</p><h3>Component libraries make you and your users happier</h3><p>We’re not motivated by repetitive work. We enjoy technical challenges, and writing the same components over again is not a fun challenge. We’ve already spoken about what happens when we get bored and let mistakes slip through.</p><p>If you wanted to implement a dialog component from scratch, you’d need to:</p><ul><li>Handle focus trapping correctly</li><li>Make the rest of the page inert</li><li>Position the dialog correctly</li><li>Ensure that it works with assistive technologies</li></ul><p>It takes work to remember and implement the above, but the consequence of getting it wrong can render your interface literally unusable, such is the case if you <a href="https://www.w3.org/WAI/WCAG21/Understanding/no-keyboard-trap.html">incorrectly handle focus</a>.</p><p>By using a component library that’s been built with the end users in mind, you can prevent the risk of introducing broken experiences, while spending less time rebuilding the same components.</p><h3>Component libraries lead to consistent experiences</h3><p>If you work for a company with several different web applications, they’ll generally follow a set of guidelines. These guidelines might dictate the colour palette to use, the size of your typography, or how UI elements should look and behave.</p><p>But you increase the likelihood of your application deviating from the style guide if you’re re-writing components. By having a component library, you can more easily audit your component’s UI against the brand guidelines so they look great, wherever they’re used.</p><p>Uber has several different apps that share the same user interface elements. I’m almost certain that they use the same component library across these apps. That way each new app is virtually guaranteed to adhere to the brand’s guidelines.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*mhHzNHt11nuCpjgJ.png" /></figure><h3>What are the drawbacks of using a third-party component library?</h3><p>The benefits I’ve mentioned above are irrespective of whether you’re using your own component library or a third party. If you or your team has decided that they don’t want to build a library, and instead lean on a third-party, then it’s worth considering the following.</p><h3>Vendor lock-in</h3><p>By choosing a component library, you’re picking a partner who will greatly impact how you write your frontend code and how your interfaces will look and behave.</p><p>The former will have a big impact on you, and the latter will have a big impact on your end users. Using a component library is locking you into the standards of that component library.</p><p>The library could introduce massive breaking changes in a major version that could require dedicated development time, and a lot of testing to ensure that no serious regressions were introduced.</p><p>A few years back I used React Admin to build a complex admin dashboard to an internal division. The library offered a suite of components specifically dedicate for fetching and displaying complex data. Because our application at the time relied heavily on React Admin, upgrading between major versions was challenging, especially as many of the internal tools used by React Admin had been swapped out for others. The change surface was huge, and we spent a good deal of time upgrading and flagging the issues that we spotted.</p><p>I don’t believe that building our own solution would have saved us any time in the long term, but this kind of vender lock-in is worth considering, especially before going all in on a tool.</p><h3>Code bloat</h3><p>Shocking as it is, libraries with a lot of components tend to be written using lots of code. Code that you download when installing dependencies, and code you sending over to your end users.</p><p>Modern tooling makes it easier to perform bundle optimisations like tree-shaking to remove unused code, but there’s no guarantee that you’re removing all of the code that your users won’t need.</p><p>Unless you dig deep into the libraries that you’re using, you may not be aware of all the separate packages they’re importing. You could end up with hundreds of unnecessary dependencies. The folks in the <a href="https://e18e.dev/">e18e</a> community have been working hard at bringing this problem to light, <a href="https://x.com/DanaWoodman/status/1819084012729798833">while also fixing it too</a>.</p><p>Many of these problems could also be said about rolling your own component library. The biggest difference is that you have stewardship over your component library. You’re able to define how it solves your specific problems, and you have control over improving its shortcomings.</p><h3>The different shapes a component library can take</h3><p>The <a href="https://cds.cern.ch/record/369245/files/dd-89-001.pdf">initial proposal</a> for the World Wide Web was a tool to improve communication between researchers at CERN. The proposal outlined how documents could be shared, and linked to one another through the use of hypertext. This is the fundamental cornerstone of the web, and we still use the humble &lt;a&gt; tag to link between other HTML documents across the web.</p><p>But the web has grown in scope over the last few decades, and the browsers we use to navigate the web have become beasts of their own. The browsers today can enable <a href="https://plumegame.com/">powerful forms of creative expression</a>, and the <a href="https://medium.com/@addyosmani/photoshop-is-now-on-the-web-38d70954365a">running of native-like software</a>.</p><p>There are hundreds of different solutions out there, some general purpose, others hyper-niche, but finding the right tool for your next project requires a complex decision process that might look like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*sI2nYzUefkg_rwgK.png" /></figure><p>This isn’t a comprehensive list of ALL use cases or component library types, but it illustrates how component libraries differ in terms of:</p><ul><li>the technologies involved.</li><li>the levels of abstraction they offer.</li><li>the problems they solve.</li></ul><p>Let’s take a look at some of the most common component library types</p><blockquote><em>💡 A quick side note: If you’re interested in building your own web component library, then consider checking out my course </em><a href="https://component-odyssey.com/"><em>Component Odyssey</em></a><em>. You’ll learn how to build and publish a component library that works in any frontend framework.</em></blockquote><h3>Utility classes libraries / CSS Style Guides</h3><p>For me, <a href="https://getbootstrap.com/">Bootstrap</a> is the first that comes to mind. Back in the day, if you wanted to give your site a quick lick of paint, you’d drop the CDN link to the bootstrap CSS file and immediately get that Bootstrap look. It was everywhere in the mid-2010s.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*xK9ABwJyhhebH2lU.png" /></figure><p>The technical scope of these kind of tools range from</p><ul><li>A single CSS file (<a href="https://picocss.com/">Pico</a>)</li></ul><p>to</p><ul><li>A toolchain to generate CSS classes based on your configuration (<a href="https://tailwindcss.com/">Tailwind</a>)</li></ul><p>Dozens of other tools, like <a href="https://open-props.style/">Open Props</a>, fit somewhere in between.</p><h3>Off-the-shelf component libraries</h3><p>If you’re building an interactive web application, you might just want to grab a suite of components that look great and function well. There are many of these off-the-shelf component libraries that give you everything you need and more.</p><p>Regardless of which framework you’re writing your app with, there’s likely to be a set of great looking components for you to use.</p><p>Another great component library is <a href="https://shoelace.style/">Shoelace</a>, which provides dozens of fully interactive and fully-styled components.</p><p>What makes libraries like Shoelace particularly interestingly is that it’s built using web components, the browser’s built-in way of writing components. Building your UIs with tools like Shoelace, give you the added benefit of being able to use them across different frontend frameworks. <a href="https://component-odyssey.com/articles/01-writing-components-that-work-in-any-framework">Which is something I’ve spoken a little about in the past.</a></p><p>Here’s the same Shoelace component being used in Vue and React.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*sol9JfdNxwDjeSRY.gif" /></figure><h3>Unstyled components</h3><p>Depending on your project’s specs, you might not have the luxury of using an off-the-shelf tool. Your design specs might be very specific.</p><p>I’ve seen teams roll components at the first sign of friction. And in one case of a hand-rolled data picker, led to a way worse user experience. In retrospect, using an unstyled component library would have given the team flexibility with appearance, while ensuring that the time</p><p>That’s why you can reach for a library out there that offers completely unstyled components with flexible styling hooks. If it’s a good library, it’ll also take care of all those complex interactions. It’s a best of both worlds situation.</p><p>It’s easy to mess up a checkbox if you want to push beyond the styling hooks that the browser provides, unless you test with a wide-range of devices and input modes.</p><blockquote><em>The </em><a href="https://component-odyssey.com/articles/10-what-is-a-library-should-you-build-your-own"><em>original article</em></a><em> has a video showing me interact with different checkbox implementations using a screen reader</em></blockquote><p><a href="https://www.radix-ui.com/">Radix</a> is a popular example of a library, but it’s built using React.</p><p>Other examples of component libraries like this are <a href="https://lion-web.netlify.app/">Lion</a> and <a href="https://headlessui.com/">HeadlessUI</a>.</p><h3>Copy Pastable Component Libraries</h3><p>Some developers might want the best of both worlds. They might want a component built by a trusted third-party library, while also having full control over the markup, styles, and functionality. Libraries like <a href="https://ui.shadcn.com/">ShadCN</a> allow for this kind of work flow, by allowing developers to copy and paste the component definition into their own projects, effectively letting them <em>own</em> the component.</p><h3>Why isn’t there one component library to rule them all?</h3><p>At this point, it’s probably clear why no such single component library exists. We’ve looked at a non-exhaustive look at different groups of component libraries.</p><p>There is, however, a movement to introduce a “<a href="https://bradfrost.com/blog/post/a-global-design-system/">Global Design System</a>”, a concept spearheaded by Brad Frost.</p><p>In the announcement, Brad outlines that in the hundreds of projects he’s been a part of, many of the UI controls behave (or should behave) similarly across these various projects, yet developers reimplement the same thing in every single project. This has lead to lots of wasted time and effort, and inconsistencies between projects. This also expands to the existing component libraries out there. You’ll see that the keyboard behaviour for a combobox in React Aria, is different to that of the combobox in ShadCN.</p><blockquote><em>The </em><a href="https://component-odyssey.com/articles/10-what-is-a-library-should-you-build-your-own"><em>original article</em></a><em> has a video showing me interact with different combobox implementations using a keyboard</em></blockquote><p>Brad Frost is proposing a Global Design System as a set of web components that should be adoptable by almost any frontend project to ensure a baseline of functionality for the controls that are not yet available in HTML.</p><p>There are <a href="https://github.com/openui/open-ui/issues/1066">discussions going on within the Open UI</a> to see how this could start taking shape within the next few years.</p><h3>Should you build your own component library?</h3><p>This article has been a wide dive into component libraries, and with all that context, you’ll inevitably ask yourself, when staring at the empty HTML page for your next big project, whether to build your own component library or use an existing one.</p><p>My first thought is: <em>I don’t think you should build your library.</em></p><p>I generally favour picking a battle-tested library. Particularly one that has:</p><ul><li>Been used across thousands of projects</li><li>A strong community, in Discord, or GitHub</li><li>Great documentation</li><li>A strong focus on accessibility</li><li>Worked with the strengths of the chosen framework</li></ul><p>Most importantly out of all of these is to use a component library puts care into building accessible components.</p><p>Take a combobox for instance. It’s a search input and a select menu mixed into one. If you’ve built your own, you may get it looking good, and working with your mouse. But you’ll also need to consider:</p><ul><li>Cross browser support</li><li>Tab and focus behaviour</li><li>Screen reader support</li><li>Handle states for async loading of search results</li></ul><p>Konnor Rogers, who does excellent work in the web + web component space, has shared countless frustrations with his experiences building an accessible combobox. Here’s one such <a href="https://x.com/RogersKonnor/status/1797529313279140294">tweet he shared</a>.</p><p>Screen reader support is particularly complex, and is worth of its own bullet-point list. To support screen readers, you’ll also need to handle:</p><ul><li>live regions</li><li>interactive controls</li><li>selected items</li><li>support between different screen readers</li></ul><p>As a side note, I only have access to Voiceover, meaning it’s difficult for me to test these complex UI patterns using different screen readers. Like browsers, there are differences between screen readers. In this article, <a href="https://www.scottohara.me/blog/2022/02/05/are-we-live.html">Are We Live?</a>, Scott O’Hara describes how there’s variance among the difference with how they treat the live regions.</p><p>This means it’s also up to you, the developer to pick a component library that you can trust has been developed with accessibility in mind. This is why it’s also important to pick a component library that has a strong community. It’s important to be able to:</p><ul><li>See the bugs and issues others have flagged for a given library</li><li>Suggest (or even contribute) improvements and changes to such library</li><li>Discuss ideas with members of the community and build working relationships with active members of the community or even maintainers themselves</li></ul><p>Finally, and not least, a great component library will consider much more than the aesthetics of their components. For a component library designed for the web, it should try it’s best to:</p><ul><li>adhere to the <a href="https://www.w3.org/TR/WCAG21/">Web Content Accessibility Guidelines (WCAG)</a></li><li>ensure that the components work across different input modalities (touch, keyboard, screen reader)</li><li>ensure that the components are usable for folks with additional requirements, like those living with vestibular disorders, vision impairments, or a broken hand.</li></ul><h3>Building your own component library can be a good thing, actually</h3><p>If I haven’t scared you off from building a component library, then let me contradict myself and explain why it can be a really good thing to build your own.</p><p>If you take the time to put care and attention into building a component library, then you’ll find yourself a developer who better understands the browser platform, accessibility best practices, testing practices, and more.</p><p>But it doesn’t just stop there, there are some excellent reasons to build your own library.</p><p>For starters, you can build something tailored to your needs, and avoid some of the bloat you might get form an off-the-shelf component library. It’s up to you and your team to understand your end users, and you can build something specifically for them.</p><p>You also have the opportunity to experiment with novel approaches. If you have a hyper-niche problem, there might not be a component library out there to solves that need. It could be a component library that:</p><ul><li>Visualises data in specific way</li><li>Has a distinct and unique visual identity</li><li>Is built on a new framework</li></ul><p>That gives you the opportunity to build something tailored to your needs. You then have the opportunity to change and fix things as your needs change, or as you understand the problem space better.</p><p>Importantly, you’ll learn more about the web by doing so. If it’s your first time building a component library, it can be an opportunity to dive deeper into the <a href="https://html.spec.whatwg.org/multipage/">HTML browser specs</a>, or brush up on your <a href="https://www.w3.org/TR/WCAG21/">web accessibility knowledge</a>. This will improve your abilities as a web developer, which will serve you well in any frontend project in the future. It could even help you land your next job.</p><p>So whether you should build a component library depends on your end goals. Consider questions like:</p><ul><li>Do I want to better under stand the browser?</li><li>Do I want to build something quickly?</li><li>Do I want to make it usable for as many users as possible?</li><li>Do libraries exist that solve my current problem?</li></ul><p>Depending on what your answers are, you can make the right call for your project.</p><p>Thanks for reading! If you’re interested in building your own web component library, then consider checking out my course <a href="https://component-odyssey.com/">Component Odyssey</a>. You’ll learn how to build and publish a component library that works in any frontend framework.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d42a0d2dc73a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Heaps of Cutting Edge CSS Features to Build a Progress Indicator]]></title>
            <link>https://medium.com/@andricokaroulla/using-heaps-of-cutting-edge-css-features-to-build-a-progress-indicator-b89eeedc8fed?source=rss-e274c246e46d------2</link>
            <guid isPermaLink="false">https://medium.com/p/b89eeedc8fed</guid>
            <category><![CDATA[css]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Andrico Karoulla]]></dc:creator>
            <pubDate>Tue, 06 Aug 2024 08:49:03 GMT</pubDate>
            <atom:updated>2024-08-06T08:49:03.561Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A2cnhma4k24Yd4c6n6-1Tw.png" /></figure><p>For the last 7 months, I’ve had my head down building <a href="https://component-odyssey.com/">Component Odyssey</a>. It’s been a richly fulfilling project and I’m eager for people to take the course and learn heaps about building component libraries using web components.</p><p>I’ve seen some incredible demos over the past year and wanted to bite my teeth into some of these cool new features. So I used some downtime over the Christmas period to cram tons of new CSS features into a lesson progress indicator for the Component Odyssey platform. The result is the following progress indicator that shows how much of the page the user has scrolled:</p><figure><img alt="the fully completed progress indicator as it exists on Component Odyssey" src="https://cdn-images-1.medium.com/max/720/0*m-a2Fedn5OQNS-7M.gif" /></figure><p>Building it gave me some exposure to some of the latest CSS features like:</p><ul><li>animation-timeline: scroll()</li><li>CSS trig functions, sin() and cos()</li><li>color-mix()</li><li>the @property at-rule</li></ul><p>I know the risks of building something with a particular tool in mind. As the saying goes “When all you have is a hammer, then something something nails”</p><p>Yes, I have a hammer, and I’m going to smash the walls down with it</p><p>In this article, I’ll run through how to create a pared-down version of this swanky progress animation while still using all of the CSS features mentioned above. I’ll also show you how to gracefully handle browsers that don’t support these features through <strong>progressive enhancement</strong>.</p><p>If you want to follow along, then it’s best to use the latest versions of Chrome or Safari, currently Firefox doesn’t have general support for properties like animation-timeline. Get started by jumping into the <a href="https://codepen.io/andrico1234/pen/WNmQrGK">starter Codepen</a>.</p><p>If you want to peruse the finished code, you can <a href="https://codepen.io/andrico1234/pen/qBvdjLd">check it out here.</a></p><h3>Creating the markup</h3><p>I’ve already provided a little markup to simulate a page with enough content that you need to scroll to get to the bottom. To get started creating the progress indicator, you’ll need to add some more markup.</p><p>The markup itself is really simple, we’ll only need to create 3 div elements.</p><p>The outer element is responsible for the positioning and layout of the loader. We’ll give this a class of wrapper.</p><p>The middle element is responsible for rendering the track to the screen. We’ll give this element a class of progress. We’ll later use a ::after pseudo-element to create the thumb.</p><p>The innermost element will be used to create the circular hole in the middle, making the indicator look like a low-calorie doughnut. This will have a class of inner.</p><p>Take a look at the following if you need a hand visualising the structure:</p><figure><img alt="A visual representation of the information outlined above" src="https://cdn-images-1.medium.com/max/800/0*yKfdeFy3NXs7rMLp.png" /></figure><p>Provide the following markup as the first child of the main element create the following markup:</p><pre>&lt;div class=&quot;wrapper&quot;&gt;<br>    &lt;div class=&quot;progress&quot;&gt;<br>        &lt;div class=&quot;inner&quot;&gt;&lt;/div&gt;<br>    &lt;/div&gt;<br>&lt;/div&gt;</pre><p>You’ll also need to apply the following styles to give the markup a base visual experience:</p><pre>.wrapper {<br>    --size: 80px;<br><br>    position: fixed;<br>    width: var(--size);<br>    aspect-ratio: 1/1;<br>    top: 24px;<br>    left: 24px;<br>    display: flex;<br>    align-items: center;<br>    justify-content: center;<br>}<br><br>.progress {<br>    --track-size: 16px;<br><br>    width: var(--size);<br>    aspect-ratio: 1/1;<br>    border-radius: 50%;<br>}<br><br>.inner {<br>    position: absolute;<br>    width: calc(100% - var(--track-size));<br>    aspect-ratio: 1/1;<br>    background: var(--background-color);<br>    border-radius: 50%;<br>    top: 0;<br>    left: 0;<br>    right: 0;<br>    bottom: 0;<br>    margin: auto;<br>}</pre><p>Most of the CSS here shouldn’t come as a shock to you, so I won’t go over it line by line, but I will touch on some of the more interesting bits.</p><p>In .wrapper we’re fixing the element to the top left of the screen, and using flexbox to center the children horizontally and vertically.</p><p>💡 I learnt that if you want an element to share the same value for both its width and height, you just set the width and use aspect-ratio: 1/1. The browser will implicitly set the height. This is a neat trick because you won’t have to define the same value twice, and it makes it easier to guarantee that the width and the height share the same value.</p><p>As for the .inner element, I’ve used a mix of absolute positioning and the margin: auto to center it in the middle of the .progress element. We’ve also deducted the --track-size from the full width of the container, to ensure that it’s correctly positioned over the .progress element.</p><p>You won’t be able to see anything just yet, but if you add a temporary background-color: red to the .progress element, it should render as follows:</p><figure><img alt="a basic doughnut shaped indicator without any animation" src="https://cdn-images-1.medium.com/max/228/0*ya6vuYdeSl4mdp8N.png" /></figure><h3>Creating an animated progress indicator</h3><p>Creating a scroll-driven animation of this kind requires a lot of new CSS features that you may have not used before. Instead of learning everything all at once, we’ll start by decoupling the animation from the scrolling mechanics.</p><p>That way, by the end of this section, you should have the following animation that plays automatically:</p><figure><img alt="A progress indicator playing automatically in an infinite loop" src="https://cdn-images-1.medium.com/max/720/0*o_yF78z00JAJJcJN.gif" /></figure><p>We’ll start by creating a new animation called load:</p><pre>@keyframes load {<br>    0% {<br>        --progress: 0%;<br>    }<br><br>    100% {<br>        --progress: 100%;<br>    }<br>}</pre><p>All this does is move the progress along from 0 to 100 over the course of the animation. In your .progress rule, add the following CSS properties:</p><pre>.progress {<br>    # Existing rules<br>    animation: load linear 1s infinite;<br>    background: conic-gradient(<br>        from 0deg at 50% 50%,<br>        var(--red) var(--progress),<br>        var(--black) var(--progress)<br>    )<br>}</pre><p>The animation property should be pretty straightforward, but there’s a lot going on with the background rule, so let’s step through it.</p><p>For starters, we’re using a conic-gradient as it makes it easy for us to animate the background over 360 degrees, in the way shown in the animation above. We’re starting from the 0deg position, which is top and center. We’re describing where we want the center of the gradient to be using at 50% 50%.</p><p>conic-gradient(from 0deg at 50% 50%) alone would render something like the following:</p><figure><img alt="A visualisation of a radial gradient starting from the center, like a sonar radar" src="https://cdn-images-1.medium.com/max/800/0*BLOLftPIjLKvOYAq.png" /></figure><p>Hopefully I’ve made it clear why that’s the case.</p><p>As for the the second and third arguments of the conic-gradient function, we’re linking the --progress variable (which is being calculated via the load animation) to the two colors. The --red is used to denote the completed progress, while the --black is used to denote the remaining position. It might be confusing why they share the same --progress value. The --progress value for the --red value denotes where the gradient stop ends, while the --progress value for the --black denotes where the gradient stop begins. Because it’s the last stop on the gradient, it’s implied that it ends at 100%. By setting the same --progress value to both stops in the gradient, we create a hard transition between the two colors. Without doing so, our progress indicator (with a --progress value set to 16%) would look like this:</p><figure><img alt="The progress indicator where the color gradient goes slowly from red to black" src="https://cdn-images-1.medium.com/max/278/0*yaVPHwpAvcmnJiyM.png" /></figure><p>Now, something strange is probably happening. Instead of your progress indicator transitioning gracefully across the entire perimeter of the circle, it’s instead flashing between the black and red.</p><p>Why is this happening?</p><p>This is because we’re making the browser interpolate between percentage values, which is something it can’t do automatically. Even though we’ve given the --progress variable a percentage value, the browser doesn’t assume that it’s always going to be a percentage value.</p><p>We can solve this by telling the browser that --progress will always be a percentage value. We can do this by explicitly defining the --progress property using the @property CSS rule. Just add the following to the top-level of your CSS:</p><pre>@property --progress {<br>    syntax: &#39;&lt;percentage&gt;&#39;;<br>    inherits: false;<br>    initial-value: 0%;<br>}</pre><p>We’re telling the browser that --progress should only support percentage values and that the initial value is 0%. We’re also not interested in having the custom element inherit its value.</p><p>Finally, I don’t quite like the use of the --black variable to signify empty progress. It looks too stark. I’d like to create a lighter shade created from the black to ensure a more homogenous visual palette. This is something we can easily achieve using the color-mix() CSS function.</p><p>Jump back up to the :root CSS rule and add the following variable:</p><pre>:root {<br>    # your other CSS variables<br>    <br>    --grey: color-mix(in srgb, var(--black), transparent 60%);<br>}</pre><p>The color-mix function lets us mix two colors together. In this case, we’re mixing the color stored in our black variable with some transparency, which will result in a partially see-through grey color. You’ll need to replace the reference to the --black variable in the conic-gradient function with --grey to see the color change in effect.</p><p>Now that we’ve defined our custom property, the browser will be able to interpolate the correct values during the entire animation, so it should now transition smoothly from start to finish.</p><p>GIF</p><figure><img alt="A progress indicator playing automatically in an infinite loop" src="https://cdn-images-1.medium.com/max/720/0*3doz2ZsWIEWYUoQy.gif" /></figure><h3>Scroll driven animations</h3><p>The next stage of our animation journey is to tie our animation to the scrolling of the page.</p><p>This should only take us a couple of lines of CSS.</p><p>You’ll need to do two things. First adjust the animation property in your .progress class to remove the infinite value, and to change the duration from 1s to 1ms. We can’t remove the value altogether because Firefox needs it for scroll animations to work.</p><p>Next update your .progress class to include the following</p><pre>.progress {<br>  # other CSS properties<br>  <br>  animation-timeline: scroll(nearest block);<br>}</pre><p>The animation-timeline property tells the browser to tie the progress of the animation with a specific timeline. In this case it’s the scroll timeline, which we specify using the scroll function.</p><p>You can see I’m providing two arguments to scroll(), nearest and block.</p><p>The nearest value is used to tie the animation to the nearest ancestor that has a scrollbar, in this case it’s the document. If you’re certain that you only ever want to tie the animation to the document’s scrollbar, then you can use swap out nearest for root instead.</p><p>The block property denotes the axis that we want to tie our animation to. For most cases this will be the vertical scrollbar, but for vertical writing modes, this will be the horizontal scrollbar.</p><p>Now that you’ve hooked up the animation to your page’s scroll, you should be able to scroll up and down the page and watch how your animation changes accordingly</p><figure><img alt="The basic progress indicator whose animation is tied to the progress of the page scroll" src="https://cdn-images-1.medium.com/max/800/0*jr0W34UBiThpc0no.gif" /></figure><h3>Progressively enhancing your scroll animation</h3><p>While it’s exciting to use these new features in the browser, the animation-timeline property doesn’t have universal support across browsers yet. It’s still very new in Chrome, and it’s only available in Firefox behind a feature flag. If you try opening the code in Firefox, you’ll notice that the progress ring just appears with a finished animation.</p><p>In cases like this, it’s important to set up a solid base experience for all browsers, and then <em>progressively enhance</em> your webpage with the newer features on compatible browsers. Because the progress indicator isn’t critical for the application to function, we can just hide it away if the browser doesn’t support the animation-timeline property.</p><p>We can do this by moving our .wrapper, .progress, and .inner classes within CSS’s @supports at-rule, like so:</p><pre>@supports (animation-timeline: scroll()) {<br>    .wrapper {}<br><br>    .progress {}<br><br>    .inner {}<br>}</pre><p>Doing so ensures that if the browser doesn’t support scroll(), then it will ignore all of the styles contained within the rule.</p><h3>Adding the indicator thumb</h3><p>The final thing for us to add is a cool little indicator thumb, to both give our progress indicator a little more visual interest and to also let us play with the swanky CSS trigonometric functions.</p><p>To create the indicator thumb, start by writing the following CSS inside of the @supports block:</p><pre>.progress::after {<br>    --radius: calc(var(--size) / 2);<br>    --track-offset: calc(var(--track-size) / 4);<br><br>    content: &#39;&#39;;<br>    position: absolute;<br>    aspect-ratio: 1/1;<br>    width: calc(var(--track-size) / 2);<br>    background: var(--red-dark);<br>    border-radius: 50%;<br>    left: calc(50% - var(--track-offset));<br>    top: calc(50% - var(--track-offset));<br>    transform: scale(1.5);<br>}</pre><p>This creates a new pseudo-element off of the .progress class, and gives it it’s visual appearance. Once added, the indicator thumb should live in the center progress element. We’re using the --track-offset variable to position the thumb correctly by taking into consideration the dimensions of the track.</p><p>⚠️ I’m also increasing the size of the thumb to using scale() so that its size in the DOM is still relative to the --size variable. This just means a little less maths for us to worry about when setting the value for --track-offset. Using scale() makes it easy to change the size of the element without causing a shift in the DOM.</p><p>The next step is to use the color-mix() function again to create a dark red from the base red color. Add the following to your :root rule.</p><pre>:root {<br>    # your other CSS variables<br><br>    --red-dark: color-mix(in srgb, var(--red), var(--black) 60%);<br>}</pre><p>Your progress indicator should look less like a UI widget and more like a dartboard:</p><figure><img alt="the thumb is in the center of the progress indicator" src="https://cdn-images-1.medium.com/max/268/0*-KGep2hTnUM825UC.png" /></figure><p>Let’s position the thumb on to the track.</p><pre>.progress::before {<br>  # rest of properties<br><br>  translate: calc((var(--radius) - var(--track-offset)) * cos(var(--angle)))<br>      calc((var(--radius) - var(--track-offset)) * sin(var(--angle)));<br>}</pre><p>This is probably the gnarliest piece of CSS in this entire article. It isn’t anywhere near as complex if we break it down in half. Here’s the first half:</p><pre>calc((var(--radius) - var(--track-offset)) * cos(var(--angle)))</pre><p>This uses a little trigonometry to calculate the position of the thumb based on the current angle (which will be tied to the scroll progress) and the radius of the circle. The cos() function is used to determine the horizontal value of the position.</p><p>The second half of the value is identical, except we’re using the sin() function to determine the vertical position of the indicator:</p><pre>calc((var(--radius) - var(--track-offset)) * sin(var(--angle)))</pre><p>⚠️ I’m not going to use this article as an introduction into trigonometry, but I can point you in the direction of some amazing resources:</p><ul><li><a href="https://web.dev/articles/css-trig-functions">Trigonometric functions in CSS</a></li><li><a href="https://tympanus.net/codrops/2021/06/04/trigonometry-in-css-and-javascript-beyond-triangles/">Trigonometric functions in CSS and JavaScript: Beyond Triangles</a></li></ul><p>You may have noticed that I’ve specified a variable, --angle that I haven’t yet defined. Because we’ll be animating the --angle we need to explicitly define it using the @property rule, much like we did for the --progress property. The only difference is that we’ll need to specify a different syntax value. Instead of &lt;percentage&gt; the value will need to be &lt;angle&gt; .</p><pre>@property --angle {<br>    syntax: &#39;&lt;angle&gt;&#39;;<br>    inherits: false;<br>    initial-value: -90deg;<br>}</pre><p>By setting the initial value to -90deg we ensure that thumb is placed at the 12 o’clock position on the progress indicator.</p><p>Your indicator should now look like this:</p><figure><img alt="The thumb is positioned at the top center of the progress indicator" src="https://cdn-images-1.medium.com/max/266/0*9Q9HGYRUk00H28K8.png" /></figure><p>The next step is to create the animation for the thumb and then bind the animation timeline to the scroll position of the page.</p><p>Let’s start by creating a new animation:</p><pre>@keyframes rotate {<br>    0% {<br>        --angle: -90deg;<br>    }<br><br>    100% {<br>        --angle: 270deg;<br>    }<br>}</pre><p>Over the course of the entire animation, the thumb will rotate 360 degrees, performing a full revolution over the progress element.</p><p>Finally we need to add the following two properties to the thumb:</p><pre>.progress::after {<br>    # other CSS properties<br><br>    animation: rotate linear 1ms;<br>    animation-timeline: scroll(nearest block);<br>}</pre><p>Doing so applies the rotate animation to our thumb and binds it to the scroll position.</p><p>Everything should now work flawlessly:</p><figure><img alt="The completed progress indicator UI" src="https://cdn-images-1.medium.com/max/800/0*BClwdMP4xV6VPl-A.gif" /></figure><h3>Wrapping up</h3><p>I created this progress indicator specifically to become more familiar with the amazing tools that CSS has shipped in the last couple years. Hopefully you learnt just as much from this lesson as I did making it.</p><p>There were other CSS features I wanted to explore, like popover and :has but I couldn’t find a way to fit them in with this animation. If people find this article interesting, I might try and create more little changes to the Component Odyssey platform, using cutting-edge CSS features.</p><p>By wary, that because a lot of the CSS features I’ve covered are still very new, check the browser support before using them in production. If they’re not supported in one or more browsers, but you’re desperate to use them, then use a <strong>progressive enhancement</strong> strategy to ensure that those with compatible browsers get the full experience, while still offering users of unsupported browsers a solid baseline experience.</p><p>If you enjoyed this article, and would love to learn more about Component Odyssey or other cool web development tips, then consider <a href="https://component-odyssey.com/subscribe">subscribing to the newsletter</a>.</p><h3>Resources</h3><p><a href="https://developer.chrome.com/docs/css-ui/scroll-driven-animations#getting_practical_with_scroll_progress_timelines">Getting practical with scroll progress timelines</a></p><p><a href="https://dev.to/afif/we-can-finally-animate-css-gradient-kdk">We can finally animate css gradients</a></p><p><a href="https://codepen.io/LukyVj/pen/rNqvowZ">Fitness inspired loaders</a></p><p><a href="https://drafts.css-houdini.org/css-properties-values-api-1/#at-property-rule">MDN: @property at-rule</a></p><p><a href="https://developer.mozilla.org/en-US/docs/Web/CSS/animation-timeline">MDN: Animation Timeline</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b89eeedc8fed" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Navigating Your Component Journey with Component Odyssey]]></title>
            <link>https://itnext.io/navigating-your-component-journey-with-component-odyssey-d9bcf8caa5c1?source=rss-e274c246e46d------2</link>
            <guid isPermaLink="false">https://medium.com/p/d9bcf8caa5c1</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[components]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Andrico Karoulla]]></dc:creator>
            <pubDate>Mon, 27 Nov 2023 07:54:17 GMT</pubDate>
            <atom:updated>2023-11-27T07:54:17.715Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Complexities of Building Your Own Component Library</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H6VPmDYRV2mjYA1mu3zXnQ.png" /></figure><p>At some point, every web developer has thought about creating their own component library, and for good reason.</p><p>Building a library is an opportunity to express your creativity, learn to develop more accessible web experiences, contribute to the open source community, upskill yourself for a better-paid role, or simply become a more well-rounded web developer.</p><p>A component library is also a valuable tool to have in your team, as reusing the same components over several projects is a great way of saving your team lots of time and effort.</p><p>But building a component library is no easy task in part due to how complex the web development landscape has gotten over the years. With so many frameworks and runtimes to choose from, how do you know which is the best to pick for your component library? Picking one may very well lock your components out from being used with others.</p><p>Ultimately, you want your end-users to have enjoyable web experiences, you want your library consumers to easily build interfaces with your library, and you want a smooth development experience to build, test, and publish your library.</p><p>That’s what Component Odyssey will teach you to do.</p><h3>Introducing Component Odyssey</h3><p>Component Odyssey will help you navigate your component library journey.</p><p>In Component Odyssey, I’ll be teaching you how to build a component library with a minimal tech stack. You’ll learn how to avoid locking yourself into the shiny framework of the month, and you’ll write components that work across any JavaScript framework.</p><p>So why should you embark on your Component Odyssey?</p><h3>You’ll become a more future-proof web developer</h3><p>The core technologies introduced in Component Odyssey are baked into the browser, meaning that as you become more familiar with these tools, you’ll also become more familiar with building for the browser as a whole. The skills you learn in this course will serve you in almost any front-end project you work on in the future.</p><h3>You’ll build components that your users will love</h3><p>You won’t just be writing components in Component Odyssey, you’ll learn how to style, test, type, and publish them. These are all important in ensuring that the components you ship are robust and user-friendly.</p><h3>You’ll boost your career opportunities</h3><p>Building a component library is an excellent way to contribute to the open-source community, which improves your chances of working on other cool projects, or landing some wonderful job roles. Just sharing the library you’ve built from scratch with a prospective job employer will help you stand out from the crowd of applicants.</p><p>I did just this when I interviewed for my current job, and the interviewers loved my component library:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*1VRiGVZJoApl4fBb.png" /></figure><h3>You’ll learn to do more with less</h3><p>The components you’ll be building in Component Odyssey are built using web components, the browser’s built-in way to create reusable components. You don’t need a framework to write and publish them, and as a result, you’ll be able to deliver components that work across the web.</p><p>Web components aren’t new or radical, loads of large companies use web components to power their web experiences, like Microsoft, Adobe, and NASA.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*78-aColv5baG3cL-.png" /></figure><p>You’ll also be introduced to other tools and technologies that lean into the browser’s built-in capabilities, which means that you, and your library consumers, can avoid complex build systems to run your code.</p><h3>The Component Odyssey platform</h3><p>Component Odyssey is a self-paced and highly interactive course, so there’ll be plenty of hands-on coding for you to do. There are also no deadlines, so you can go through the entire course on your own time.</p><p>Every lesson is accompanied by written content and a video, and the course is jam-packed with code examples, exercises, and projects.</p><p>Most lessons contain some interactive runnable code like the one below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*NXaEpOdV0M7Z8AB8.png" /></figure><p>Other lessons contain in-depth exercises for you to download and run locally on your computers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*Rw1jvRR4jO8H3H3e.png" /></figure><p>Most importantly, throughout the entire course, you’ll be slowly building out a functioning component library, with multiple components, a testing strategy, and some handy workflow automation.</p><p>You won’t be alone either, starting Component Odyssey will also give you access to a Discord community. You’ll be able to share the amazing things you’ve built, get help on any tough challenges you’re facing, and meet other developers on their journeys.</p><h3>Who should take Component Odyssey?</h3><p>You don’t need to be an expert web developer to take this course, it’s designed for anyone with some working HTML, CSS, and JavaScript experience. If you’ve built a few interactive websites and have a few months of web development experience, then you’re golden.</p><p>Component Odyssey doesn’t cover the absolute basics of HTML, CSS, and JavaScript, but it does build on top of those browser fundamentals, so you can build great components without a framework.</p><p>Is Component Odyssey worth taking if you’re a seasoned developer? Absolutely, there’ll still be so much for you to gain, as you’ll be diving deep into web components, and you’ll learn how to style, test, and publish them.</p><h3>About me</h3><p>As for me, I’m Andrico, a web developer based in London. I’ve been a professional web developer for the last 7 years and have worked across a bunch of startups. I’m currently building design-to-code automation and design system automation at Anima.</p><p>In previous roles, I was a front-end champion, where I ran workshops about front-end development, web accessibility, and front-end testing.</p><p>I’ve also built a few personal projects on the side like Cali Skills, a bodyweight fitness tracker, and Handstand Journey, a popular mobile application designed as a fun introduction to the exciting world of arm balances.</p><p>I’m also the creator of a2k, the Windows 2000-inspired web component library. I’ve also contributed to several open-source projects, most notably the Open UI, where I led the site rewrite from Gatsby to Astro.</p><p>Component Odyssey is everything I’ve learnt about web development and component library development condensed down into a fun and highly interactive course.</p><p>Fun fact: Before starting my career as a web developer, I worked in the family chip shop in South-East London (it’s still going strong, so stop by for some fish and chips!).</p><h3>Register your interest</h3><p>Component Odyssey is still in development, with more release details coming out in the following months. If you’d like to be notified about Component Odyssey news, including beta testing details + launch discounts, then please <a href="https://component-odyssey.com/subscribe">register your interest</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d9bcf8caa5c1" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/navigating-your-component-journey-with-component-odyssey-d9bcf8caa5c1">Navigating Your Component Journey with Component Odyssey</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Gather User Feedback On Any Website with Hermes WC]]></title>
            <link>https://itnext.io/gather-user-feedback-on-any-website-with-hermes-wc-70383423f836?source=rss-e274c246e46d------2</link>
            <guid isPermaLink="false">https://medium.com/p/70383423f836</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[front-end-development]]></category>
            <dc:creator><![CDATA[Andrico Karoulla]]></dc:creator>
            <pubDate>Tue, 14 Nov 2023 08:26:32 GMT</pubDate>
            <atom:updated>2023-11-14T08:26:32.416Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zW6ZoRa5gGTeRvU1xmdUMg.png" /></figure><p>Nothing’s more important for indie developers than gathering user feedback, especially for early-stage projects that are likely to undergo massive changes regularly. At the same time, many developers don’t need the kind of enterprise-level feature set that many of the most well-known customer platforms offer.</p><p>For the last few months, I’ve been creating <a href="https://component-odyssey.com/">Component Odyssey</a>, a course designed to help developers build and publish components that work everywhere. As I’m gearing up to open my platform to beta testers I need a free, quick, and easy mechanism to gather user feedback.</p><p>I want an unintrusive widget that I could drop into my page which students could use to send feedback at any point during the course to flag bugs and unclear course content. Given that the Component Odyssey platform is built on top of SvelteKit, it would be easy for me to create a Svelte component that fires data to an endpoint.</p><p>But I wanted to practice what I teach, and a form widget feels like a great candidate for a web component as the browser already has great support for building forms. On top of that, a form widget isn’t a novel piece of functionality and certainly shouldn’t rely on a specific framework to work. The idea of writing a simple, but very useful component, that I can’t then use in my React and VanillaJS projects feels like a waste of energy.</p><p>That’s what led me to build <a href="https://github.com/andrico1234/hermes-wc">Hermes WC</a>. With Hermes WC, you can easily add an interactive form that dispatches the form data to a location of your choice.</p><p>Here’s a demo of Hermes WC in action, sending feedback to Discord, Slack, and an HTTP endpoint.</p><p>GIF</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*eV1BSaWhRAs9StzD.gif" /></figure><p>So let’s see how you can add Hermes WC to your own projects</p><h3>Step 1: Installing Hermes WC</h3><p>Begin by installing Hermes WC:</p><pre>npm install hermes-wc</pre><h3>Step 2: Adding the Hermes WC markup</h3><p>Once you’ve done that, you can update your webpage with the following markup:</p><pre>&lt;hermes-wrapper&gt;<br>    &lt;form class=&quot;hermes-stack&quot; data-hermes=&quot;form&quot;&gt;<br>        &lt;sl-input name=&quot;feedback&quot; label=&quot;Feedback&quot; placeholder=&quot;e.g., Not clear enough&quot;&gt;&lt;/sl-input&gt;<br>        &lt;hermes-score-input<br>            name=&quot;score&quot;<br>            label=&quot;Score&quot;<br>            score-count=&quot;5&quot;<br>            start-helper-text=&quot;Low Score&quot;<br>            end-helper-text=&quot;High score&quot;<br>        &gt;&lt;/hermes-score-input&gt;<br>        &lt;div class=&quot;hermes-row&quot;&gt;<br>            &lt;sl-button data-hermes=&quot;close&quot;&gt;Close&lt;/sl-button&gt;<br>            &lt;sl-button variant=&quot;primary&quot; type=&quot;submit&quot;&gt;Submit&lt;/sl-button&gt;<br>        &lt;/div&gt;<br>        &lt;p data-hermes=&quot;helper-text&quot; /&gt;<br>    &lt;/form&gt;<br>&lt;/hermes-wrapper&gt;</pre><p>There’s heaps of stuff going on here, so let’s break it down, element by element.</p><p><strong>Hermes Wrapper</strong></p><p>This is the component that’s responsible for handling the layout of the Hermes form. It mainly handles the form’s open and close states, while also placing a button on the right hand side of the page.</p><p><strong>Form</strong></p><p>This is the form element that’s in charge of listening and reacting to the submit event. A form element with the attribute data-hermes=&quot;form&quot; is required.</p><p><strong>SL Input</strong></p><p>Because Hermes WC uses a standard HTML form element, we can use any old HTML form controls as children and their values will be captured in the submit event. As a result, I’m using the Shoelace library to render some pre-styled and accessible components.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/586/0*eiAkDOAJa-TqmGfD.png" /></figure><p><strong>Hermes Score Input</strong></p><p>This is an additional web component that Hermes WC provides. It renders a horizontal radio button group with some attributes for helper text.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/591/0*wytwTPN3SSi0NhXW.png" /></figure><p><strong>SL Button</strong></p><p>This is a button provided to us by Shoelace. The button on the left has a data-hermes=&quot;close&quot; attribute, which is used to close the feedback widget.</p><p>The button on the right has an attribute type=&quot;submit&quot; and is used to submit the form when it’s clicked.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/586/0*bC8X8UKd-N4gVC5x.png" /></figure><p><strong>Whatever else you want…</strong></p><p>Like I mentioned earlier, because Hermes WC works with HTML forms, you can use any HTML form control to build your form.</p><h3>Step 3: Import the styles into your page</h3><p>To apply the default styles to Hermes WC, go ahead and import the styles into your project:</p><pre>&lt;link rel=&quot;stylesheet&quot; href=&quot;path/to/node_modules/hermes-wc/src/style.css&quot; /&gt;</pre><h3>Step 4: Initializing the Hermes WC form</h3><p>With the markup written, you’ll need to add a small splash of JavaScript to initialize the form.</p><pre>import { DiscordSubmissionAdapter } from &#39;hermes-wc/src/submission-adapters/discord.js&#39;<br>import { initializeHermesForm } from &#39;hermes-wc/src/index.js&#39;<br><br>initializeHermesForm({<br>  submissionAdapters: [new DiscordSubmissionAdapter({<br>    webhookUrl: &#39;your webhook url&#39;<br>  })],<br>  submissionCompleteCallback: (response) =&gt; { // handle the response }<br>});</pre><p>Running initializeHermesForm will do a few things under-the-hood, like set up event listeners and register the web components.</p><p>You can then provide one or more <strong><em>submission adapters</em></strong> which send your data to a destination of your choice. As of now, Hermes WC supports sending feedback to Slack, Discord, or an HTTP GET endpoint. You can even create your own adapters.</p><p>You can also pass a function through to the submissionCompleteCallback option, which gets fired when all of the submission requests are settled. You’ll be given the response of all the promises, which you can use to display a success or error message to your users.</p><h3>Wrapping Up</h3><p>I hope you find a tool like Hermes WC useful. I plan to open source a bunch of the tools I create for Component Odyssey. Other tools include <a href="https://github.com/andrico1234/sandpack-lit">Sandpack Lit</a>.</p><p>If you’d like to learn how to build your own components that work anywhere, regardless of framework, then please register your interest for my course, <a href="https://component-odyssey.com/">Component Odyssey</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=70383423f836" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/gather-user-feedback-on-any-website-with-hermes-wc-70383423f836">Gather User Feedback On Any Website with Hermes WC</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Writing Components That Work In Any Frontend Framework]]></title>
            <link>https://itnext.io/writing-components-that-work-in-any-frontend-framework-1356b1ad7b83?source=rss-e274c246e46d------2</link>
            <guid isPermaLink="false">https://medium.com/p/1356b1ad7b83</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[frontend-development]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[components]]></category>
            <dc:creator><![CDATA[Andrico Karoulla]]></dc:creator>
            <pubDate>Sun, 05 Nov 2023 16:56:08 GMT</pubDate>
            <atom:updated>2023-11-05T16:56:08.416Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZOZBH9yn824Fl6wsGEBl_g.png" /><figcaption>Write components that work in Svelte, Vue, React, and other frameworks, with minimal boilerplate</figcaption></figure><p>The browser has a built-in way of writing reusable components in the form of <strong>web components</strong>. They’re an excellent choice for building interactive, and reusable components that work in any frontend framework. With that said, writing highly interactive and robust web components isn’t simple. They require a lot of boilerplate and feel much less intuitive than the components you may have written in frameworks like React, Svelte, and Vue.</p><p>In this article, I’ll give you an example of an interactive component written as a web component, and then refactor it using a library that softens the edges and removes heaps of boilerplate.</p><p>Don’t sweat if you’re not familiar with web components. In the next section, I’ll do a (very brief and limited) overview of what web components are, and what they’re made out of. If you have some basic experience with them, you can skip the next section.</p><h3>What are web components?</h3><p>Before web components, the browser didn’t have a standard way of writing reusable components. Many libraries solve this problem, but they often run into limitations like performance, interoperability, and issues with web standards.</p><p>They’re a technology made up of 3 different browser features:</p><ul><li>Custom elements</li><li>Shadow DOM</li><li>HTML Templates</li></ul><p>We’ll do a quick crash course of these technologies, but it’s by no means a comprehensive breakdown.</p><h3>Custom Elements</h3><p>With Custom Elements you can author your own custom HTML elements that you can reuse across your site. They can be as simple as text, images, or visual decorations. You can push them further and build interactive components, complex widgets, or entire web applications.</p><p>You’re not just limited to using them in your projects, but you can publish them and allow other developers to use them on their sites.</p><p>Here are some of the reusable components from my library <a href="https://a2000-docs.netlify.app/">A2K</a>. You can see that they come in all shapes and sizes, and have a range of different functionalities. Using them in your projects is similar to using any old HTML element.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rUHrAGPMp-1MBBltC1wHxg.png" /><figcaption>A small collection of web components from the A2K library</figcaption></figure><p>Here’s how you’d use the progress element in your project:</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>    &lt;head&gt;<br>        &lt;title&gt;Quick Start&lt;/title&gt;<br>        &lt;meta charset=&quot;UTF-8&quot; /&gt;<br>    &lt;/head&gt;<br>    &lt;body&gt;<br>        &lt;!-- Use web components in your HTML like regular built-in elements. --&gt;<br>        &lt;a2k-progress progress=&quot;50&quot; /&gt;<br>        &lt;!-- a2k web components use standard JavaScript modules. --&gt;<br>        &lt;script type=&quot;module&quot;&gt;<br>            import &#39;https://cdn.jsdelivr.net/npm/@a2000/progress@0.0.5/lib/src/a2k-progress.js&#39;;<br>        &lt;/script&gt;<br>    &lt;/body&gt;<br>&lt;/html&gt;</pre><p>Once you’ve imported the third-party scripts, you can start using the component, a2k-progress in this case, just like any other HTML element.</p><p>If you’re building your own web components, there’s virtually no limit to how complex you can make your custom elements. I recently created a web component that renders a CodeSandbox code editor in the browser. And because it’s a web component, you can use it in any framework you like! If you’d like to learn a little more about that, <a href="https://component-odyssey.com/articles/00-sandpack-lit-universal">you can read more here</a>.</p><h3>Shadow DOM</h3><p>If you have a working knowledge of CSS, you’ll know that vanilla CSS is scoped globally. Writing something like this in your global.css:</p><pre>p {<br>    color: tomato;<br>}</pre><p>Will give all p elements a nice orange/red color, assuming that no other, more specific CSS selectors are applied to a p element.</p><p>Take this select menu for example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Uf6Iy4n01e97FD99fsOXyA.png" /><figcaption>A select menu component with a visual design reminiscent of the old Windows operating systems</figcaption></figure><p>It has a distinct character which is driven by the visual design. You might want to use this component, but if your global styles affect things like the font family, the color, or the font size, it could cause issues with the appearance of the component:</p><pre>&lt;head&gt;<br>    &lt;style&gt;<br>        body {<br>            color: blue;<br>            font-size: 12px;<br>            font-family: system-ui;<br>        }<br>    &lt;/style&gt;<br>&lt;/head&gt;<br><br>&lt;body&gt;<br>    &lt;a2k-select&gt;&lt;/a2k-select&gt;<br>&lt;/body&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jN1uJ-czJVY2htQ_GQLkpg.png" /><figcaption>The same select menu, but with a lot of its defining characteristics overridden by global CSS.</figcaption></figure><p>This is where the Shadow DOM comes in. The Shadow DOM is an encapsulation mechanism that prevents the rest of the DOM from interfering with your web component, this ensures that the global styles of the web application don’t interfere with any components that you consume. It also means that component library developers can author their components with the confidence that they’ll look and behave as expected across different web applications.</p><p>There’s a lot more nuance when it comes to the Shadow DOM, as well as other features that we’re not going to touch on in this article. If you’d like to learn more about web components though, I have an entire course (<a href="https://component-odyssey.com/">Component Odyssey</a>) dedicated to teaching you how to build reusable components that work in any framework.</p><h3>HTML Templates</h3><p>The last feature in our whistle-stop tour of web components features is HTML Templates.</p><p>What makes this HTML element different from other elements, is that the browser doesn’t render its content to the page. If you were to write the following HTML you wouldn’t see the text “I’m a header” displayed on the page:</p><pre>&lt;body&gt;<br>    &lt;template&gt;<br>        &lt;h1&gt;I&#39;m a header&lt;/h1&gt;<br>    &lt;/template&gt;<br>&lt;/body&gt;</pre><p>Instead of being used to render the content directly, the content of the template is designed to be copied. The copied template can then be used to render content to the page. You can think of the template element much like the template for a 3D print. The template isn’t a physical entity, but it’s used to create real-life clones.</p><p>You would then reference the template element in your web component, clone it, and render the clone as the markup for your component.</p><p>I won’t spend any more time on these web component features, but you’ve probably already noticed that to write vanilla web components, there are a lot of new browser features that you need to know and understand. You’ll see in the next section that the mental model for building web components doesn’t feel as streamlined as it does for other component frameworks.</p><h3>A Basic Web Component</h3><p>Now that we’ve briefly covered the fundamental technologies powering a web component, here’s how to build a <em>hello world</em> component:</p><pre>const template = document.createElement(&#39;template&#39;);<br>template.innerHTML = `&lt;p&gt;Hello World&lt;/p&gt;`;<br><br>class HelloWorld extends HTMLElement {<br>    constructor() {<br>        super();<br>        this.attachShadow({ mode: &#39;open&#39; });<br>        this.shadowRoot.append(template.content.cloneNode(true));<br>    }<br>}<br>customElements.define(&#39;hello-world&#39;, HelloWorld);</pre><p>This is the most simple component one could write, but there’s already so much going on. For someone completely new to web components, and without the background knowledge I provided above, they’re going to be left with a lot of questions, and a lot of confusion.</p><p>For me, there are at least two key reasons why web components can be challenging to write, at least within the context of the hello world examples.</p><h3>The markup is decoupled from the component logic</h3><p>In many frameworks, the markup of the component is often treated as a first-class citizen. It’s often the content that gets returned from the component function, or has direct access to the component’s state, or has built-in utilities to help manipulate markup (like loops, conditionals, etc).</p><p>This isn’t the case for web components. In fact, the markup is often defined outside of the component’s class. There’s also no built-in way for the template to reference the current state of the component. This becomes a cumbersome limitation as the complexity of a component grows.</p><p>In the world of frontend, components are designed to help developers reuse markup in several pages. As a result, the markup and the component logic are inextricably linked, and so they should be colocated with one another.</p><h3>Writing a web component requires understanding all of its underlying technologies</h3><p>As we saw above, web components are made up of three technologies. You can also see in the hello world code snippet, that we explicitly need to know and understand these three technologies.</p><ol><li>We’re creating a <strong>template element</strong> and setting its inner HTML</li><li>We’re creating a <strong>shadow root</strong>, and explicitly setting its mode to ‘open’.</li><li>We’re cloning our <strong>template</strong> and appending it to our <strong>shadow root</strong></li><li>We’re registering a new <strong>custom element</strong> to the document</li></ol><p>There’s nothing inherently wrong with this, since web components are supposed to be a “lower-level” browser API, making them prime for building abstractions on top of. But for a developer coming from a React or a Svelte background, having to understand these new browser features, and then having to write components with them can feel like too much friction.</p><h3>A more advanced web component</h3><p>Let’s take a look at a more advanced web component, a counter button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/388/1*xI-N6FwjeWnjJsmqyFmesw.png" /><figcaption>A simple counter button. There’s a clickable button, and some text showing how many times the button has been clicked</figcaption></figure><p>You click the button, and the counter increments.</p><p>The following example contains a few extra web component concepts, like lifecycle functions and observable attributes. You don’t need to understand everything going on in the code snippet. This example is really only used to illustrate how much boilerplate is required for the most basic of interactive interfaces, a counter button:</p><pre>const templateEl = document.createElement(&quot;template&quot;);<br><br>templateEl.innerHTML = `<br>&lt;button&gt;Press me!&lt;/button&gt;<br>&lt;p&gt;You pressed me 0 times.&lt;/p&gt;<br>`;<br>export class OdysseyButton extends HTMLElement {<br>  constructor() {<br>    super();<br>    this.attachShadow({ mode: &quot;open&quot; });<br>    this.shadowRoot.appendChild(templateEl.content.cloneNode(true));<br>    this.button = this.shadowRoot.querySelector(&quot;button&quot;);<br>    this.p = this.shadowRoot.querySelector(&quot;p&quot;);<br>    this.setAttribute(&quot;count&quot;, &quot;0&quot;);<br>  }<br>    // Note: Web components have lifecycle methods,<br>  // If we&#39;re setting event listeners when the component is added to the DOM, it&#39;s our job to clean<br>  // them up when it gets removed from the DOM<br>  connectedCallback() {<br>    this.button.addEventListener(&quot;click&quot;, this.handleClick);<br>  }<br>  disconnectedCallback() {<br>    this.button.removeEventListener(&quot;click&quot;, this.handleClick);<br>  }<br>  // Unlike frameworks like React, Web Components don&#39;t automatically rerender when a prop (or attribute)<br>  // changes. Instead, we need to explicitly define which attributes we want to observe.<br>  static get observedAttributes() {<br>    return [&quot;disabled&quot;, &quot;count&quot;];<br>  }<br>  // When one of the above attributes change, this lifecycle method runs, and we can<br>  // react to the new attribute&#39;s value accordingly.<br>  attributeChangedCallback(name, _, newVal) {<br>    if (name === &quot;count&quot;) {<br>      this.p.innerHTML = `You pressed me ${newVal} times.`;<br>    }<br>    if (name === &quot;disabled&quot;) {<br>      this.button.disabled = true;<br>    }<br>  }<br>  // In HTML, attribute values are always strings. This means that it&#39;s our job to<br>  // convert types. You can see below that we&#39;re converting a string -&gt; number, and then back to a string<br>  handleClick = () =&gt; {<br>    const counter = Number(this.getAttribute(&quot;count&quot;));<br>    this.setAttribute(&quot;count&quot;, `${counter + 1}`);<br>  };</pre><p>As web component authors, we need to consider a lot of things:</p><ul><li>Setting up the shadow DOM</li><li>Setting up the HTML templates</li><li>Cleaning up event listeners</li><li>Defining properties that we want to observe</li><li>Reacting to properties when they change</li><li>Handling type conversions for attributes</li></ul><p>And there are still so many other things to consider that I haven’t touched on in this article.</p><p>That isn’t to say that web components are bad and that you shouldn’t write them, in fact, I’d argue that you learn so much about the browser platform by building with them. However, I feel that there are better ways to write components if your priority is to write interoperable components in a much more streamlined and ergonomic way.</p><h3>Writing web components with less boilerplate</h3><p>As I mentioned earlier, there are a lot of tools out there to help make writing web components much easier. One such tool is called Lit, which is developed by a team at Google. <a href="https://lit.dev/">Lit</a> is a lightweight library designed to make writing web components simple, by removing the need for the boilerplate we’ve already seen above.</p><p>As we’ll see, Lit does a lot of heavy lifting under-the-hood to help cut down the total lines of code by nearly half! And because Lit is a wrapper around web components and other native browser features, all your existing knowledge about web components is transferable.</p><p>To start seeing how Lit simplifies your web components, here’s the <strong>hello world</strong> example from earlier, but refactored to use Lit instead of a vanilla web component:</p><pre>import { LitElement, html } from &quot;lit&quot;;<br><br>export class HelloWorld extends LitElement {<br>  render() {<br>    return html`&lt;p&gt;Hello World!&lt;/p&gt;`;<br>  }<br>}`<br>customElements.define(&#39;hello-world&#39;, HelloWorld);</pre><p>There’s a lot less boilerplate with the Lit component, and Lit handles the two problems I mentioned earlier, a little bit differently. Let’s see how:</p><ol><li>The markup is directly defined from within the component class. While you can define your templates outside of the class, it’s common practice to the template as the result of the render function. This is more in line with the mental model presented in other UI frameworks, where the UI is a function of the state.</li><li>Lit also doesn’t require developers to attach the shadow DOM, or create template and clone template elements. While having an understanding of the underlying web component features will help when developing Lit components, they’re not required for getting started, so the barrier for entry is much lower.</li></ol><p>So now for the big finale, what does the counter component look like once we’ve migrated it over to Lit?</p><pre>import { LitElement, html } from &quot;lit&quot;;<br><br>export class OdysseyCounter extends LitElement {<br>  static properties = {<br>        // We define the component&#39;s properties as well as their type.<br>        // These properties will trigger the component to re-render when their values change.<br>        // While they&#39;re not the same, you can think of these &quot;properties&quot; as being<br>        // Lit&#39;s alternatives to &quot;observed attributes&quot;<br>        // If the value is passed down as an attribute, Lit converts the value<br>        // to the correct type<br>    count: { type: Number },<br>    disabled: { type: Boolean },<br>  };<br>  constructor() {<br>    super();<br>        // There&#39;s no need to create a shadow DOM, clone the template,<br>        // or store references to our DOM nodes.<br>    this.count = 0;<br>  }<br>  onCount() {<br>    this.count = this.count + 1;<br>  }<br>  render() {<br>        // Instead of using the attributeChangedCallback lifecycle, the<br>        // render function has access to all of the component&#39;s properties,<br>        // which simplifies the process of manipulating our templates.<br>    return html`<br>      &lt;button ?disabled=${this.disabled} @click=${this.onCount}&gt;<br>        Press me!<br>      &lt;/button&gt;<br>      &lt;p&gt;You pressed me ${this.count} times.&lt;/p&gt;<br>    `;<br>  }<br>}`</pre><p>The amount of code we’re writing is cut down by almost half! And this difference becomes more noticeable when creating more complex user interfaces.</p><h3>Why am I going on about Lit?</h3><p>I’m a big believer in web components, but I recognise that the barrier of entry is high for many developers. Writing complex web components requires understanding heaps of browser features and the education around web components isn’t as comprehensive as other technologies, like React or Vue.</p><p>This is why I think it’s important to use tools like Lit can make writing performant and interoperable web components much easier. This is great if you want your components to work within any frontend framework.</p><p>If you’d like to learn even more, this is the approach I teach in my upcoming course <a href="https://component-odyssey.com/">Component Odyssey</a>. This course is excellent for anyone who wants to understand how to write components that work in any framework. I do this by covering the absolute basics of web components, before moving on to tools like Lit that simplify the process of writing web components without complicating your development environment. By the end, you’ll learn how to build and publish a component library that works across any frontend framework.</p><p>If you want early-bird discount codes for Component Odyssey, then head on <a href="https://component-odyssey.com/subscribe">over to the site to get notified</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1356b1ad7b83" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/writing-components-that-work-in-any-frontend-framework-1356b1ad7b83">Writing Components That Work In Any Frontend Framework</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introducing Sandpack Lit: The Universal CodeSandbox]]></title>
            <link>https://medium.com/@andricokaroulla/introducing-sandpack-lit-the-universal-codesandbox-67595fe6a45e?source=rss-e274c246e46d------2</link>
            <guid isPermaLink="false">https://medium.com/p/67595fe6a45e</guid>
            <category><![CDATA[vue]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[codesandbox]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[svelte]]></category>
            <dc:creator><![CDATA[Andrico Karoulla]]></dc:creator>
            <pubDate>Mon, 23 Oct 2023 15:08:07 GMT</pubDate>
            <atom:updated>2023-10-23T15:08:07.641Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vfJArMus73Ac3E2WPPIuNg.png" /><figcaption>Learn how to run entire web applications within you own web apps, regardless of which framework you’re using</figcaption></figure><p>Sandpack was a game-changer back when the team at CodeSandbox officially released it. Thanks to Sandpack, running a CodeSandbox in your browser-based projects was easier than ever. With it, you could open up a little window inside of your application that runs an entirely different application. And you weren’t limited to running simple sites, but entire web applications or Node servers.</p><p>If you haven’t directly used Sandpack yourself, you’ve probably been on a site that has for displaying runnable code snippets or code exercises. In fact, the React docs site uses Sandpack for its code exercises.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0SxfY_dyOf87Gk29kW7EpQ.gif" /><figcaption>Runnable code examples in the React docs site</figcaption></figure><p>However, there’s one major problem… CodeSandbox only officially provides a React wrapper for Sandpack. If you wanted to run a CodeSandox from within your project, you’d need to either:</p><ul><li>Create your project in React</li><li>Create your own wrapper around the sandpack-core library</li></ul><h3>Introducing Sandpack Lit</h3><p>With more frameworks than ever to build web applications, it makes sense to offer a drop-in Sandpack solution for frameworks that aren’t React.</p><p>Developers could build their own Sandpack wrapper around their favourite frameworks, or the team at CodeSandbox could release official wrappers around each framework, but that feels like a lot of work for a lot of developers.</p><p>That’s where Sandpack Lit comes in.</p><p>Sandpack Lit is a standalone web component that allows you to add a CodeSandbox to any client-side web application. Let’s see it in action!</p><h3>Sandpack Lit in action</h3><p>You’ll see just how easy it is to render a CodeSandbox inside of different projects using different frameworks. I’ll render the same interactive theme picker inside the sandbox</p><p>If you want to go ahead and use it yourself, you can begin by installing sandpack-lit:</p><pre>npm install sandpack-lit</pre><h3>Svelte</h3><p>If you’re using Svelte, create the following component:</p><pre>&lt;script&gt;<br>  import &quot;sandpack-lit/dist/presets/sandpack&quot;;<br>  import &quot;sandpack-lit/dist/themes/odyssey.css&quot;;<br>&lt;/script&gt;<br><br>&lt;main&gt;<br>  &lt;h1&gt;Svelte&lt;/h1&gt;<br>  &lt;div class=&quot;container&quot;&gt;<br>    &lt;sandpack-preset<br>      options={{<br>        closableTabs: false,<br>        files: { /** files go here */},<br>        customSetup: {<br>          &quot;dependencies&quot;: {<br>            &quot;lit&quot;: &quot;2.6.1&quot;<br>          }<br>        }<br>      }}<br>    /&gt;<br>  &lt;/div&gt;<br>&lt;/main&gt;<br>&lt;style&gt;<br>  .container {<br>    width: 900px;<br>  }<br>&lt;/style&gt;</pre><p>Run and open your development server, and you should see Sandpack working:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yH8qYtXXzl_J2qgcxrv4DQ.png" /><figcaption>Sandpack Lit running in Svelte</figcaption></figure><h3>Vue</h3><p>If you’re using Vue, create the following component:</p><pre>&lt;script setup&gt;<br>import &quot;sandpack-lit/dist/presets/sandpack&quot;;<br>import &quot;sandpack-lit/dist/themes/odyssey.css&quot;;</pre><pre>const files = { /** files go here */ }</pre><pre>const dependencies = {<br>  lit: &quot;2.6.1&quot;,<br>};</pre><pre>const options = {<br>  closableTabs: false,<br>  files,<br>  customSetup: {<br>    dependencies,<br>  },<br>};<br>&lt;/script&gt;</pre><pre>&lt;template&gt;<br>  &lt;h1&gt;Vue&lt;/h1&gt;<br>  &lt;div style=&quot;width: 900px&quot;&gt;<br>    &lt;sandpack-preset v-bind:options=options /&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;</pre><p>Kick off your dev server, and you should see Sandpack working:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TU8eSSPGUBM3QU1WofPAmg.png" /></figure><h3>React</h3><p>Consuming web components in a React project is a little different to the others, since React doesn’t offer out-of-the-box support for web components. Luckily Sandpack Lit offers a exports a React component that you can use instead:</p><pre>import { SandpackLitComponent } from &#39;sandpack-lit/dist/presets/sandpack-react&#39;;<br>import &quot;sandpack-lit/dist/themes/odyssey.css&quot;;</pre><pre>function App() {<br>  return (<br>    &lt;div style={{ width: &#39;900px&#39; }}&gt;<br>      &lt;h1 style={{ textAlign: &#39;center&#39; }}&gt;React&lt;/h1&gt;<br>      &lt;SandpackLitComponent<br>        options={{<br>          closableTabs: false,<br>          files: { /** files go here */ },<br>          customSetup: {<br>            &quot;dependencies&quot;: {<br>              &quot;lit&quot;: &quot;2.6.1&quot;<br>            }<br>          }<br>        }}<br>      /&gt;<br>    &lt;/div&gt;<br>  )<br>}</pre><pre>export default App</pre><p>Run and open your development server, and you should see Sandpack working:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hszw8yD2xfjCS1ErzyvhpQ.png" /></figure><h3>Vanilla</h3><p>If you’re opting to not use a framework at all, you can add Sandpack Lit to your project using the following:</p><pre>&lt;body&gt;<br>  &lt;div id=&quot;app&quot; style=&quot;width:900px&quot;&gt;<br>    &lt;h1 style=&quot;text-align: center; color: black;&quot;&gt;VanillaJS&lt;/h1&gt;<br>    &lt;sandpack-preset&gt;&lt;/sandpack-preset&gt;<br>  &lt;/div&gt;<br>  &lt;script type=&quot;module&quot;&gt;<br>    import &quot;sandpack-lit/dist/presets/sandpack&quot;;<br>    import &quot;sandpack-lit/dist/themes/odyssey.css&quot;;<br>    const files = /** your files here */</pre><pre>    const sandpackEl = document.querySelector(&#39;sandpack-preset&#39;);<br>    const options = {<br>      closableTabs: false,<br>      files,<br>      customSetup: {<br>        &quot;dependencies&quot;: {<br>          &quot;lit&quot;: &quot;2.6.1&quot;<br>        }<br>      }<br>    };</pre><pre>    sandpackEl.options = options<br>  &lt;/script&gt;<br>&lt;/body&gt;</pre><p>Run your local development server, and you can see Sandpack Lit working without a framework:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*maDUSqWS7EY9knN-E--CkQ.png" /></figure><p>So how does Sandpack Lit work across all frameworks? Instead of being built using a framework, I’ve instead opted to use a handy native browser feature called <strong>web components</strong>.</p><h3>What the Heck are Web Components?</h3><p>The browser offers developers a way to write reusable components without needing an external framework. They can create a custom element (with styles, attributes, and more), and use it like any other HTML element.</p><p>You can even import and use web components made by other developers!</p><p><a href="https://nolanlawson.com/2023/08/23/use-web-components-for-what-theyre-good-at/">Nolan Lawson recently wrote</a> about the use cases that web components are best for:</p><blockquote><em>You have some component at the leaf of the DOM tree, it doesn’t need to be rendered server-side, and it doesn’t </em><em>&lt;slot&gt; any content inside of it. Examples include: a rich text editor, a calendar widget, a color picker, etc. To me, this is the most unambiguously slam-dunk use case for web components.</em></blockquote><p>I feel that this applies perfectly to an embedded code editor, like Sandpack, since a code editor is a highly interactive client-side component that doesn’t rely on the consumer passing down child content.</p><h3>Real-world usages of Sandpack Lit (Component Odyssey)</h3><p>While Sandpack Lit is still new, I’ve been using it over the last few months to build the exercises and code examples in my web development course <a href="https://component-odyssey.com/">Component Odyssey</a>. Component Odyssey is dedicated to helping developers learn the ins-and-outs of component library development.</p><p>I’m using Sandpack Lit to run both browser-based code and Node projects in the browser:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TF7Df81MTtgybyFyvIJI4w.gif" /></figure><p>If you’d like to learn build, manage, and distribute your component library in an ever-increasingly complex web development landscape, then <a href="https://component-odyssey.com/subscribe">register your interest</a> to get an early-bird discount when Component Odyssey releases.</p><h3>Learn more about Sandpack Lit</h3><p>You may have noticed that I used the sandpack-preset web component. This is a component that renders a preset configuration of some additional components, ones that render the code editor, ones that render the preview, and one that sets up the shared context. Sandpack Lit also exports these components, so you can have more flexibility. If you’d like to learn more, you can check out the <a href="https://github.com/andrico1234/sandpack-lit">Sandpack Lit GitHub repo</a>.</p><h3>What’s next for Sandpack Lit?</h3><p>Sandpack Lit is still in early days, if there are features that you’d like to see added, please add an issue in the GitHub, or try your hand at implementing it yourself. If you like the look of Sandpack Lit, then please leave a GitHub star and share online!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=67595fe6a45e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[beautiful-skill-tree is officially v1! ]]></title>
            <link>https://codeburst.io/beautiful-skill-tree-is-officially-v1-60a0b14fd993?source=rss-e274c246e46d------2</link>
            <guid isPermaLink="false">https://medium.com/p/60a0b14fd993</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[ux]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Andrico Karoulla]]></dc:creator>
            <pubDate>Thu, 14 Nov 2019 16:10:07 GMT</pubDate>
            <atom:updated>2019-11-14T16:10:07.305Z</atom:updated>
            <content:encoded><![CDATA[<p>Visualise a satisfying feeling of progression in your app with the help of beautiful-skill-tree.</p><h3>What is beautiful-skill-tree? 🌳</h3><p><a href="https://github.com/andrico1234/beautiful-skill-tree">beautiful-skill-tree</a> came about as as result of my love for video games, web development and fitness. BST was never intended to be a standalone package, but a feature in a <a href="https://calisthenicsskills.com/">fitness progress app</a>. After discovering that there were no easy-to-use libraries that empower developers to create their own versatile skill trees, BST ended up manifesting as exactly that.</p><p>My key motivation for beautiful-skill-tree is to create a package that can be used across a series of browsers and devices, with interactions that feel intuitive, sleek, and gratifying. While developer experience is a major consideration when creating BST, I want usability to be BST’s key measurement for success. Thanks to tools like <a href="https://www.browserstack.com/">Browserstack</a>, BST has been tested and validated across a series of operating systems, browsers and devices. And thanks to my friends, family (incl. my grandmother), coworkers, and strangers in ensuring that it has been tested across a diverse range of people.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*oJXL9Ug-2hHOp9hr" /><figcaption>Photo by <a href="https://unsplash.com/@maritafox?utm_source=medium&amp;utm_medium=referral">Marita Kavelashvili</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>What can I do with beautiful-skill-tree?</h3><p>Currently, the most comprehensive use of beautiful-skill-tree in the wild is <a href="https://calisthenicsskills.com/">Calisthenics Skills</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/404/0*DxkLYX8YhCbXdx9Z.gif" /></figure><p>Setting up BST in your own application is straight forward, with the official <a href="https://github.com/andrico1234/beautiful-skill-tree/blob/master/README.md">README</a> guiding you through the key features in great detail.</p><p>Once you’ve imported the components and configured the SkillTree, all that&#39;s left is to supply your own data. For those, like myself, who are TypeScript nerds, BST exports types to ensure that your data adheres to the structure required. If usability is my bottom-line measure for success, developer experience places a close second.</p><p>Here’s what beautiful-skill-tree offers you:</p><ul><li>📈 A way to visualise user progression in your application</li><li>🖥️ Responsive, cross-browser compatible trees</li><li>🕸️ Silky smooth animations</li><li>⌨️ Keyboard navigable trees</li><li>🍂 Collapsible trees</li><li>🎨 Custom theming</li><li>💾 Saving to localstorage out-of-the-box</li><li>✍🏿 Option to implement custom saving</li><li>❓ Optional nodes</li><li>📊 Access to your tree’s data and methods</li></ul><h3>What can I expect beyond v1? 🎄</h3><ul><li>Custom pre-requisites to to unlock/select skills</li><li>Searching/Filtering through trees and skills</li><li>Features as a result of insight received from feedback</li></ul><p>In the future, I’ll talk about some of the challenges I’ve come across during the creation and development of BST, and the User Experience lessons I’ve learnt along the way. Stay tuned!</p><p>And a big thanks to everyone that has used beautiful-skill-tree in the past!</p><p>Have you used beautiful-skill-tree in your own project? You can leave anonymous feedback and feature suggestions <a href="https://docs.google.com/forms/d/e/1FAIpQLSfQ5cJSMt4nLTVsXP88_0EfPXbzSwHoJlzWRW5nBWKNMtKSHA/viewform?usp=sf_link">here</a>. You can try it out here</p><p>If you’re interested in keeping up-to-date with any of my projects you can find me in the following places:</p><ul><li><a href="https://www.instagram.com/andricokaroulla/?hl=en">Instagram</a></li><li><a href="https://github.com/andrico1234">Github</a></li><li><a href="https://twitter.com/andricokaroulla?lang=en">Twitter</a></li><li><a href="https://www.freecodecamp.org/news/author/andrico/">freeCodeCamp</a></li><li><a href="https://medium.com/@andricokaroulla">Medium</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=60a0b14fd993" width="1" height="1" alt=""><hr><p><a href="https://codeburst.io/beautiful-skill-tree-is-officially-v1-60a0b14fd993">beautiful-skill-tree is officially v1! 🌲</a> was originally published in <a href="https://codeburst.io/">codeburst</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create a Borderlands-style skill tree in 5 minutes]]></title>
            <link>https://codeburst.io/create-a-borderlands-style-skill-tree-in-5-minutes-71fc9a6ba19d?source=rss-e274c246e46d------2</link>
            <guid isPermaLink="false">https://medium.com/p/71fc9a6ba19d</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[videogames]]></category>
            <dc:creator><![CDATA[Andrico Karoulla]]></dc:creator>
            <pubDate>Wed, 21 Aug 2019 06:28:57 GMT</pubDate>
            <atom:updated>2019-08-21T15:01:55.304Z</atom:updated>
            <content:encoded><![CDATA[<p>Growing up, I spent my spare time doing what most programmers did; played video games every waking moment. I loved Adventure games and what a time sink they were; if time was the Mary Rose, and I was the French, my artillery were games like Kingdom Hearts, Ōkami, and Borderlands.</p><p>Why did I, and others, spend so much of our spare time exploring, surviving, dying, and (so, so much)grinding? Hundreds of factors contribute toward making an engaging experience, but the one I’m going to focus on is the notion of progression.</p><p>The idea of gamification isn’t new, with many popular applications (like <a href="https://todoist.com/?lang=en">todoist</a>, or <a href="https://productivitychallengetimer.com/">challenge timer</a>) incorporating some sort of progression scheme to make us, the consumer, use their app, give them money, and hand over our personal data. So I decided to go about my way of enabling others to do just that, through beautiful skill trees! Note: I expect neither money nor data from those using my skill trees.</p><p>The last few weeks have seen me toil away to create what I hope to be a pleasant plug’n’play React package to help you create exciting skill trees. You can test it yourself by following the tutorial. I hope it to be a frictionless experience.</p><p>We hope to have something resembling the skill tree below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SVmULmiah6yx-Hwhin94cw.png" /><figcaption>“A dying puppy. A baby in tears. If the previous statements elicited any emotional reaction report to your supervisor for summary destruction.”</figcaption></figure><h3>beautiful-skill-tree@0.7.5</h3><p>Grab the starter repo by using git clone git@github.com:andrico1234/borderlands-skill-tree.git</p><p>Move into the directory and run the starting script, yarn start. Give the site a whirl, you&#39;ll see nothing but the Borderlands logo and environment.</p><p>beautiful-skill-tree exposes three components: the SkillProvider, SkillTreeGroup, and the SkillTree components.</p><p>SkillProvider: This takes in no props and supplies the children with the skill tree&#39;s context. This puppy handles all of the global data related to the skill tree.</p><p>SkillTreeGroup: Is more involved in that it can take an optional theme property, where we can pass in some custom styling, to make our skill tree feel very Borderlands. The SkillTreeGroup also uses the children-as-a-function pattern to give us access to some imperative api functionality, such as skill tree reset, selected skills counter, etc. We don&#39;t need to worry about any of those for the scope of this article.</p><p>SkillTree: This is the most exciting of the package&#39;s exports, unless you&#39;re a sucker for typings (which are also exported, for all you TS fans). The SkillTree doesn&#39;t take any children but requires 3 props: treeId, title, and data. The treeId should be an id that&#39;s unique to each skill tree, but should be persistent across user sessions as this is used as the key for getting and setting the data to local storage. I&#39;m not going to explain what the title prop does, I&#39;ll leave you to experiment. The data is the mixing pot of the application. You&#39;ll pass in your skill tree data structure which the app will use to render a beautiful-skill-tree. Let&#39;s get a real basic tree going before we move on to our multi-tree, multi-branch Borderlands spectacular.</p><p>In App.tsx, import the 3 components like so:</p><pre>import { SkillProvider, SkillTreeGroup, SkillTree } from &#39;beautiful-skill-tree&#39;;</pre><p>Place it underneath your img tag, outside of the image&#39;s container div, but within the outer div. Add the SkillProvider, passing the SkillTreeGroup as a child. Before you do the same with the SkillTree, remember that as SkillTreeGroup uses function-as-a-child pattern, you&#39;ll need to render a function that returns the child components. Return a single SkillTree and give it a treeId and a title prop. Pass an empty array into the data prop so your App.tsx looks like this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9afaf909491da0fad201e1c91ab00eb9/href">https://medium.com/media/9afaf909491da0fad201e1c91ab00eb9/href</a></iframe><p>Go to <a href="http://localhost:3000/">localhost:3000</a> to see the application running. You should see the logo, background, and a grey rectangle. If you’re running into any errors, go through the introduction again and check to see if there any syntax error or incorrect imports.</p><p>Next, let’s create a real basic tree. Just 3 items that move in a linear line. The data structure for data looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d8e810ab9ee279cf406b618731c45a2d/href">https://medium.com/media/d8e810ab9ee279cf406b618731c45a2d/href</a></iframe><p>Each skill requires four properties, with one being optional. You should also notice that the children property is a recursive type, meaning that it takes an array of the same data structure, which it uses to render the children of the skill. This can go on infinitely, and make for some real complicated, winding trees. I&#39;ll create the first skill for you, and I&#39;ll trust you with carrying on for the next two items.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a05b619e49eba6e0154550ebfde13c5f/href">https://medium.com/media/a05b619e49eba6e0154550ebfde13c5f/href</a></iframe><p>Add the above snippet to the App.tsx file, and replace the empty array inside of the SkillTree&#39;s data property with our data definition. Load your page, and you should have an interactive node. Give it a hover and a click and it should be reacting to your actions. If things are working, then I&#39;ll task you with creating two (or more) child nodes. Experiment with children and sibling lengths, to see what you can come up with. (If you also happen to break my precious package, leave me a GitHub issue so I can patch things up).</p><p>Once you’re comfortable with creating a skill tree, let’s go ahead and create our Borderlands skill tree. Fortunately, I’ve done all of the tedious work for you and have already created the data structures and accumulated the images.</p><p>You’ll need to import the three trees from the data file, which can be done via</p><pre>import { motion, harmony, cataclysm } from &quot;./data/data&quot;;</pre><p>The next step is creating two additional SkillTrees alongside the current one. You&#39;ll need to wrap them in a React.Fragment as your SkillTreeGroup will now be trying to render 3 top level components. Pass in the data accordingly, and if you&#39;re unsure, I&#39;ve posted the code snippet below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dec647e1322b387d9015656cf5936375/href">https://medium.com/media/dec647e1322b387d9015656cf5936375/href</a></iframe><p>Go ahead and check your web browser, it should be <strong>aaallmoost</strong> ready. We’ve got the skills rendered, but the styling feels a little lackluster. It doesn’t feel very Borderlands. Fortunately for you, I’m a regular <a href="https://www.youtube.com/watch?v=0evlWSY8kTc">Neil Buchanan</a> and prepared a custom theme. Import the theme and pass it through to the SkillTreeGroup&#39;s theme prop. The theme object is export via import theme from &#39;./data/theme&#39;;. Easy!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rrCuBsiU2bdcIofhZyac3w.png" /><figcaption>“I HAVE ONE QUESTION FOR YOU. EXPLOSIONS?”</figcaption></figure><p>Once you’ve done the above, check out the finished product. If you’re still not satisfied with the styles, check out the theme object and customise it yourself, there are a bunch of additional attributes whose styles can be adjusted, so just peek into the typings of the package.</p><p>I mentioned earlier that there are a few additional properties and values that can be used to tweak the skill tree, so have a mess around yourself, and link me to any cool trees you create. I’d love to add it to the growing list of trees found <a href="https://github.com/andrico1234/beautiful-skill-tree#examples">here</a>. <a href="https://calisthenicsskills.com/">Here’s</a> an example of the skill tree that kickstarted this obsession.</p><p>I hope you’ve enjoyed tinkering with the beautiful-skill-tree package. I&#39;m always adding new features and updating, so give it a star on github! You can find an online demo of the borderlands skill tree <a href="http://borderlands-skill-tree.s3-website.eu-west-2.amazonaws.com/">here</a></p><p>You can find me on Instagram or GitHub if you want to chat code, music or fitness!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=71fc9a6ba19d" width="1" height="1" alt=""><hr><p><a href="https://codeburst.io/create-a-borderlands-style-skill-tree-in-5-minutes-71fc9a6ba19d">Create a Borderlands-style skill tree in 5 minutes</a> was originally published in <a href="https://codeburst.io/">codeburst</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My favorite way to keep programming when I’m traveling or don’t have internet]]></title>
            <link>https://medium.com/free-code-camp/my-favorite-way-to-keep-programming-when-im-traveling-or-don-t-have-internet-d1c2d26618b7?source=rss-e274c246e46d------2</link>
            <guid isPermaLink="false">https://medium.com/p/d1c2d26618b7</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[personal-development]]></category>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Andrico Karoulla]]></dc:creator>
            <pubDate>Wed, 14 Nov 2018 17:32:46 GMT</pubDate>
            <atom:updated>2018-11-16T17:29:16.969Z</atom:updated>
            <content:encoded><![CDATA[<p>This is a short guide on sharpening your skills and keeping productive when in transit. And it doesn’t involve burying your face in a book.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5djL-YOSdGd_rK_x" /><figcaption>Don’t let a few days without coding leave you feeling rusty. Stay sharp.</figcaption></figure><h3>Books can only get you so far</h3><p>Now don’t get me wrong, I love a good programming book. Jon Duckett’s series on HTML, CSS, and JavaScript were the guiding beacons during my formative years as a Web Developer. Robert C Martin’s seminal tome Clean Code has its pages bent. It is misshapen through years of being wrung dry for each drop of information. Even Simon Holmes’ Getting MEAN, while now dated, had its time by my side in the local café. It was my companion as I created my first full-stack application.</p><p>With a little preparation, most of these books could’ve been used with no, or much more frighteningly, slow internet. Download the packages in advance. Get your local environments working. If the book’s comprehensive enough, you’ll likely make solid progress without needing Google, GitHub or StackOverflow.</p><p>On the flip-side, we as programmers thrive best when tasked with a challenge. Having an author walk us through solutions is nice, but it’s not enough. The best way for us to improve our problem-solving skills is to solve problems.</p><p>If you’re a professional programmer then you’re likely to be solving your fair share of problems on a day-to-day basis. If you’re a hobbyist then you might find pleasure from creating your own <a href="http://www.jsfuck.com/">JSF**k</a> applications. Or even killing time by solving algorithm challenges online. It’s why sites like CodeWars or HackerRank are so popular.</p><p>The underlying problem with most of these, particularly the latter, is continuing when the internet breaks. Or without connection to begin with. Both are common scenarios as developers are becoming more nomadic. How do you kill time during your 12-hour flight from London to Shanghai, while still reaping the rewards gained from solving problems?</p><p>I have had the displeasure of being on such a long flight. There’s about enough space on said flight to prop your laptop on the foldout tray. Everything beyond that becomes a game of Tetris, trying to make your comfort and possessions fit in the limited space given to you on your budget flight. So you’ve got your laptop, headphones, jumper, snacks, and water all within arms reach? It’s starting to feel cramped, right? Try pulling out your 600 page 2-kilo programming book. Yeah, not gonna happen.</p><h3>The silver bullet</h3><p>So how did I overcome this impediment? Well, I reimplemented the Lodash library.</p><p>Why did I choose a such an arbitrary task? There are many key reasons. Some I rationalized before taking on the challenge and others I discovered along the way. Here are some of the most notable:</p><ul><li>Each function feels like a miniature code challenge</li><li>The documentation is on a single HTML page, easy to download and view offline</li><li>It encourages looking inside the source code when stuck</li><li>It allows you to build your own suite of utility functions</li><li>It’s a library with no dependencies, which keeps things simple</li><li>You will get more familiar with your programming language of choice</li></ul><p>Let’s dive a bit more into each of these points.</p><h4><strong>Each function feels like a code challenge</strong></h4><p>As I mentioned earlier on, Codewars and HackerRack are two very popular programming challenge sites. For those unfamiliar, you’re given a programming task to complete within the built-in text-editor. When completed, you run your finished code against the curated suite of tests. The aim of the challenge is to get all tests passing.</p><p>It’s not difficult emulating this yourself. If anything, it’s a great way of improving your approach to TDD (test driven development). My general approach to reimplementing a function would be to stub out the method:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/06edc2185e5c7b799860d6a6382bfb88/href">https://medium.com/media/06edc2185e5c7b799860d6a6382bfb88/href</a></iframe><p>The next step is to create my test suite with some assertions I’d expect my function to satisfy:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/38b6e02bc33d835cbdc0eda0e6def07b/href">https://medium.com/media/38b6e02bc33d835cbdc0eda0e6def07b/href</a></iframe><p>Then I’d implement the code so the tests run successfully:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/93101bd067dbae997380dbf50f3461be/href">https://medium.com/media/93101bd067dbae997380dbf50f3461be/href</a></iframe><p>Knocking out one of these functions will leave you with a sense pride and accomplishment.</p><h4><strong>Simple HTML documentation</strong></h4><p>Most libraries have a GitHub page with an API reference. These are usually a single page of Markdown that’s available for download. Take a snippet from the Recompose library:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/29321096438237979bf5cd56249e4a47/href">https://medium.com/media/29321096438237979bf5cd56249e4a47/href</a></iframe><p>There’s plenty of information here to get you on your way. If you’re learning React and want to get your head around HOCs (higher order components), then implementing this library might be a gratifying challenge to take on.</p><h4><strong>Reviewing the source code</strong></h4><p>Up until recently, I wouldn’t take much time to see how the packages I use most frequently work under the hood. Being without Google or StackOverflow made me desperate and so I started to look inside. I don’t know what I expected to see, but it wasn’t a minified, garbled mess.</p><p>Opening Pandora’s box didn’t send a swarm of scorn, hate and famine to taunt me and my family. Instead I was welcomed with cleanly written and well-documented code.</p><p>You can even take a peek to see how the people at Lodash write their solutions differently to yours:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f65e6e1b36f0afbdfba1eea6eb4242d3/href">https://medium.com/media/f65e6e1b36f0afbdfba1eea6eb4242d3/href</a></iframe><p>You’ll learn new ways of achieving the same goals. Maybe their solutions are more efficient, maybe yours are. It’s still a great way to open your eyes to new paradigms and patterns.</p><h4><strong>Developing your own utility functions</strong></h4><p>Lodash gets a bad rep as a library that has a large footprint. Projects may need a small number of the utilities. We will still import the whole library as a dependency.</p><p>You could download the couple of functions that you use. Why not use the methods you spent 8 hours writing whilst flying over the Pacific Ocean? It might not be quite as robust. But you’ll always be reminded of your journey to Angular Fest Hawaii ’19 whenever you whip out your implementation of _.memoize.</p><h4><strong>Keep things simple</strong></h4><p>Traveling’s draining and flying’s stressful. When feeling fatigued, any level of bureaucracy that sits in the way of any programming becomes a barrier. The idea is to choose a task that gets you coding with as little friction as possible.</p><p>I didn’t want to faff around with a bunch of random dependencies and messy vendor code when packed between two snorers on my overnight flight to Canada. It was a happy accident discovering that Lodash doesn’t rely on any external modules. The Lodash package itself is laid out simply. Each method has its own file, which may import a couple of base or utility methods.</p><h4><strong>Becoming familiar with your tools of choice</strong></h4><p>If you’re reading this article, chances are you’re familiar with JavaScript. Like most other modern programming languages, JavaScript receives semi-regular updates. These updates give you access to some new features. Implementing a library might take you to corners of your chosen language that you’ve never been before. It happened to me.</p><p>In fact, I recently came across some of JavaScript’s newer <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects#Keyed_collections">built-in objects</a>. I’d never used them in code before, so I made a conscious effort to integrate some of them into the utility methods I made:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d08f4b448e3f390c733204fb4bf8879f/href">https://medium.com/media/d08f4b448e3f390c733204fb4bf8879f/href</a></iframe><p>Using Set() makes a lot of sense here. What separates it from a normal array is that only unique values can be stored. This means you can’t have any duplicate values inside of your set. This works well when trying to create a function that removes duplicate values.</p><p>Whether you’re a guitarist, a painter, or a molecular physicist, you’re not going to get far without familiarizing yourself with your guitar, or your paints, or your … molecules?</p><p>The same goes with being a programmer. Master your tools and actively seek gaps in your knowledge. Make a conscious effort to implement features that you haven’t come across before. Or use ones that you find intimidating. It’s one of the strongest ways to learn.</p><h3><strong>Conclusion</strong></h3><p>This isn’t the only way to stay productive when without internet, but it’s worked well for me. In fact, it’s something I recommend people do in the early stages of their programming careers.</p><p>I’d love to know if you’ve done something similar, or if you have your own ways of staying sharp without the internet. Let me know below!</p><p>Do you know any other packages that would lend themselves well to being rewritten?</p><h4>Thanks for reading!</h4><p>Knowledge sharing is one of the cornerstones of what makes the development community so great. Please don’t hesitate to comment your solutions.</p><p>If you’re interested in hosting me at a conference, meetup, or as a speaking guest for any engagement, then you can DM me on <a href="https://twitter.com/andricokaroulla?lang=en">twitter</a>!</p><p>I hope this article taught you something new. I post regularly, so if you want to keep up to date with my latest releases then you can follow me. And remember, the longer you hold the clap button, the more claps you can give. 👏👏👏</p><h4>You can also check out my other articles below:</h4><p><a href="https://codeburst.io/add-a-touch-of-suspense-to-your-web-app-with-react-lazy-374e66ee05af"><em>Add a touch of Suspense to your web app with React.lazy()</em></a></p><p><a href="https://medium.com/@andricokaroulla/updated-for-apollo-v2-1-managing-local-state-with-apollo-d1882f2fbb7"><em>How to use Apollo’s brand new Query components to manage local state</em></a></p><p><a href="https://codeburst.io/no-need-to-wait-for-the-holidays-start-decorating-now-67b9dabd60d7"><em>No need to wait for the holidays, start Decorating now</em></a></p><p><a href="https://itnext.io/managing-local-state-with-apollo-client-3be522258645"><em>Managing local state with Apollo and Higher Order Components</em></a></p><p><a href="https://medium.com/@andricokaroulla/the-react-conference-drinking-game-7a996bfbef3"><em>The React Conference drinking game</em></a></p><p><a href="https://codeburst.io/develop-and-deploy-your-own-react-monorepo-app-in-under-2-hours-using-lerna-travis-and-now-2b140d647238"><em>Develop and Deploy your own React monorepo app in under 2 hours, using Lerna, Travis and Now</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d1c2d26618b7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/free-code-camp/my-favorite-way-to-keep-programming-when-im-traveling-or-don-t-have-internet-d1c2d26618b7">My favorite way to keep programming when I’m traveling or don’t have internet</a> was originally published in <a href="https://medium.com/free-code-camp">We’ve moved to freeCodeCamp.org/news</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Add a touch of Suspense to your web app with React.lazy()]]></title>
            <link>https://codeburst.io/add-a-touch-of-suspense-to-your-web-app-with-react-lazy-374e66ee05af?source=rss-e274c246e46d------2</link>
            <guid isPermaLink="false">https://medium.com/p/374e66ee05af</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[lazy-loading]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[suspense]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Andrico Karoulla]]></dc:creator>
            <pubDate>Thu, 25 Oct 2018 17:26:15 GMT</pubDate>
            <atom:updated>2018-10-31T22:07:14.726Z</atom:updated>
            <content:encoded><![CDATA[<p>We’re all eagerly awaiting the arrival of React 17, which promises the much-anticipated Suspense and Time Splitting features. In the meantime, the React team have been generous enough to give us a sample of what’s in store, in the latest ‘minor’ update.</p><p>There’s a small platter of features that accompany React.lazy in 16.6 but I won’t talk about them here. When you finish reading this, go to the official React blog and have a look to see what’s good to use.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*thAmeIskv9ruvyqU" /><figcaption>People like Sloths. Sloths are lazy. Therefore, use React.lazy and people will like you</figcaption></figure><p>Code splitting is generally regarded as a good thing. It’s why the import syntax has been pushed so heavily in the last few years. It’s also why <a href="https://webpack.js.org/guides/code-splitting/">Webpack</a> and <a href="https://nextjs.org/#automatic-code-splitting">Next.js</a> display it prominently on their home pages as a key feature. It’s compelling for good reason, why load all of the data in the webpage when the user might not need it? We want the perceived loading for our site to be consistently low and for users to only download the code that they need.</p><p>One way in which we can achieve this is through using dynamic imports. Unlike static imports, dynamic imports return a promise that gets resolved when necessary, allowing us to delay the loading of a module. A user’s journey may avoid using the aforementioned module entirely. Visually, dynamic imports vary from the more commonly seen static imports. The code snippet below highlights this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/63469718a67a12207026abdd78cc4bff/href">https://medium.com/media/63469718a67a12207026abdd78cc4bff/href</a></iframe><p>Line 1 shows the syntax for static import, while line 3 shows the syntax for a dynamic import. It’s a little more verbose, and that’s because a dynamic import returns a promise that resolves to a module. Let’s see dynamic imports in action.</p><p>Say your web app is an Event Planner. You’ve got your CMS that contains all of the event details in a nice JSON object. You:</p><ul><li>Request the data</li><li>Display a loading component</li></ul><p>and either:</p><ul><li>Receive the data</li><li>Render the event details</li></ul><p>or:</p><ul><li>Receive an error</li><li>Render an error component</li></ul><p>Before using React.lazy, your code might look a little like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7fc0496b34df56be08a7fc5f0b743358/href">https://medium.com/media/7fc0496b34df56be08a7fc5f0b743358/href</a></iframe><p>There’s nothing crazy going on here. We’re importing 3 components that get rendered under certain conditions. When our component mounts we make a request for our CMS data. Only when it returns successfully do we dynamically import our eventCards component. We save the module to the state and load it within our render method. The code on line 37 isn’t the clean React code we strive to achieve. We’re not using the declarative JSX syntax we know and love so much. Now imagine doing this with several components, it would make any sane JavaScript developer wince. We deserve better than that.</p><p>With React.lazy(), we can automatically load a given component’s code bundle only once we go to render the component:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/edcd1079164cb24944cb499098c631a3/href">https://medium.com/media/edcd1079164cb24944cb499098c631a3/href</a></iframe><p>Everything feels a little cleaner this time around. We’re returning normal looking JSX, and the React.lazy() on line 12 makes our import logic a lot more declarative.</p><p>We had to make few notable changes to our code to lazy load our modules. The most significant is the use of the new Suspense component that we’ve imported from React. The Suspense component needs to be placed anywhere above our lazily-loaded module. If the module hasn’t fully loaded the fallback component is rendered in its stead. If you move your eyes up to line 27 you’ll see that I’ve taken the liberty of wrapping our Suspense component in an ErrorBoundary. If our EventCards component fails or throws an error we let it propagate upwards and our ErrorBoundary handles it. You can read more about <a href="https://reactjs.org/docs/error-boundaries.html">ErrorBoundaries here</a>, I didn’t go into anymore detail as it’s out of the article’s scope.</p><p>I’ve also gotten the Loading component to render in two separate places. It’s included on line 24 as we wait for the data to come back from our request to the CMS. It is again included on line 28 as React goes to load the actual module.</p><p>Let me know in the comments about your thoughts new hese new features. Have you used it yourself in a different context? Then post a link of your repo, I’d love to check it out. React.lazy() has just been released at the time of writing this article, so I’m certain I’ve barely scratched the surface of when and where to use it.</p><h4>Thanks for reading!</h4><p>It’s always exciting when the React teams gives us some shiny toys to tinker with, and with React 17 just around the corner we’ve got a lot more Suspense related features coming our way very soon.</p><p>If you’re interested in hosting me at a conference, meetup or as a speaking guest for any engagement then you can DM me on <a href="https://twitter.com/andricokaroulla?lang=en">twitter</a>!</p><p>I hope this article taught you something new. I post regularly, so if you want to keep up to date with my latest releases then you can follow me. And remember, the longer you hold the clap button, the more claps you can give. 👏👏👏</p><h4>You an also check out my other articles below:</h4><p><a href="https://medium.com/@andricokaroulla/updated-for-apollo-v2-1-managing-local-state-with-apollo-d1882f2fbb7"><em>How to use Apollo’s brand new Query components to manage local state</em></a></p><p><a href="https://codeburst.io/no-need-to-wait-for-the-holidays-start-decorating-now-67b9dabd60d7"><em>No need to wait for the holidays, start Decorating now</em></a></p><p><a href="https://itnext.io/managing-local-state-with-apollo-client-3be522258645"><em>Managing local state with Apollo and Higher Order Components</em></a></p><p><a href="https://medium.com/@andricokaroulla/the-react-conference-drinking-game-7a996bfbef3"><em>The React Conference drinking game</em></a></p><p><a href="https://codeburst.io/develop-and-deploy-your-own-react-monorepo-app-in-under-2-hours-using-lerna-travis-and-now-2b140d647238"><em>Develop and Deploy your own React monorepo app in under 2 hours, using Lerna, Travis and Now</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=374e66ee05af" width="1" height="1" alt=""><hr><p><a href="https://codeburst.io/add-a-touch-of-suspense-to-your-web-app-with-react-lazy-374e66ee05af">Add a touch of Suspense to your web app with React.lazy()</a> was originally published in <a href="https://codeburst.io/">codeburst</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>