<?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 Danny Merry on Medium]]></title>
        <description><![CDATA[Stories by Danny Merry on Medium]]></description>
        <link>https://medium.com/@dannymerry?source=rss-ca3d2b90eaaa------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*KXGcsgfKRKk4wHI5wtm-xQ.png</url>
            <title>Stories by Danny Merry on Medium</title>
            <link>https://medium.com/@dannymerry?source=rss-ca3d2b90eaaa------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 02:34:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dannymerry/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[Building a Trusted Design System With Storybook]]></title>
            <link>https://blog.enable.engineering/building-a-trusted-design-system-with-storybook-d8f8c8741901?source=rss-ca3d2b90eaaa------2</link>
            <guid isPermaLink="false">https://medium.com/p/d8f8c8741901</guid>
            <category><![CDATA[design-systems]]></category>
            <dc:creator><![CDATA[Danny Merry]]></dc:creator>
            <pubDate>Tue, 25 Jun 2024 14:48:02 GMT</pubDate>
            <atom:updated>2024-06-26T10:52:30.334Z</atom:updated>
            <content:encoded><![CDATA[<p>At Enable, ensuring that our software is well-tested and trustworthy is a fundamental tenet of our engineering practices. This was also the case when we set out to build a component library to form our new Design System. Our plan was to build a library of framework-agnostic components that would serve as the basis of all of our user interfaces so it was imperative that these components were built with rigorous testing in mind.</p><p>We quickly decided to use Storybook to help develop our design system. This industry-standard tool enables testing and documenting components in isolation, and in their own words “Storybook brings together UI, examples, and documentation in one place.”</p><p>Storybook is built in React, however it supports a number of different frameworks — for us, that’s JavaScript native Web Components.</p><p>Each component and its variations are contained within a “Story” which can be written in either MDX or JavaScript, allowing you to combine documentation with live code examples.</p><p>Here is an example of a Story for our Information Message component. The table of properties is both used to document the components API and allows you to update the live example. The code for implementing the component can also be copied directly from the Story.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*_Y7A1m-CPcHfjJYnrJ5sww.gif" /></figure><p>This tool allowed us to create a central source for engineers to discover components and get detailed information on their APIs and implementation, forming the backbone of our Design System.</p><h3>Interaction testing</h3><p>Storybook offers a number of add-ons that enable building tests alongside your documentation. The first add-on we’ll look at is @storybook/addon-interactionswhich provides visual debugging of interaction tests. For the tests themselves we use a combination of Jest and Testing Library. These tools have their own Storybook add-ons to help with integration.</p><p>We install all of these tools via NPM:</p><pre>npm install @storybook/testing-library @storybook/jest @storybook/addon-interactions --save-dev</pre><p>We also declare the addons used in Storybooks main.ts:</p><pre>import type { StorybookConfig } from &#39;@storybook/core-common&#39;;<br>const storybookConfig: StorybookConfig = {<br>  stories: [&#39;./stories/**/*.stories.mdx&#39;,<br>  &#39;./stories/**/*.stories.@(js|jsx|ts|tsx)&#39;],<br> addons: [<br>  &#39;@storybook/addon-interactions&#39;<br> ]<br>};<br>module.exports = storybookConfig;</pre><h4>Writing tests</h4><p>Interaction tests can then be added to a Story by writing a Play function. This will run immediately after the Story is finished rendering. The interactions can be seen running live in Storybook.</p><pre>import { userEvent, waitFor } from &#39;@storybook/testing-library&#39;;<br>import { expect } from &#39;@storybook/jest&#39;;<br><br>export class ModalTests {<br> public openCloseTest = async (): Promise&lt;void&gt; =&gt; {<br>  await waitFor(() =&gt; {<br>   // The waitFor method is used to run setup code before running the actual interactions<br>   const modalScript = document.getElementById(&#39;#primary-modal-script&#39;);<br>   expect(modalScript).toBeInTheDocument();<br>  }).then(() =&gt; {<br>   // Create reference to an element in the Story<br>   const openModalButton = document.getElementById(&#39;primary-button&#39;) as HTMLElement;<br>   // userEvent functions allow you to trigger interactions<br>   userEvent.click(openModalButton);<br>  });<br> };<br>}</pre><p>Assertions can be added to confirm the state of the component after a series of interactions.</p><pre>import { userEvent, waitFor } from &#39;@storybook/testing-library&#39;;<br>import { expect } from &#39;@storybook/jest&#39;;<br><br>export class ModalTests {<br> public openCloseTest = async (): Promise&lt;void&gt; =&gt; {<br>  await waitFor(() =&gt; {<br>   const modalScript = document.getElementById(&#39;#primary-modal-script&#39;);<br>   const modal = document.getElementById(&#39;primary-modal&#39;) as any;<br>   <br>   expect(modalScript).toBeInTheDocument();<br>  }).then(() =&gt; {<br>   const openModalButton = document.getElementById(&#39;primary-button&#39;) as HTMLElement;<br>   userEvent.click(openModalButton);<br>   // Confirm that after the open button has been clicked that the modal panel&#39;s open state is True<br>   expect(modal.open).toBeTruthy();<br>   const closeButton = document.getElementById(&#39;primary-modal--close-button&#39;) as HTMLElement;<br>   userEvent.click(closeButton);<br>   // After clicking the close button with the modal panel, we expect the modal&#39;s open state to be false.<br>   expect(modal.open).not.toBeTruthy();<br>  });<br> };<br>}</pre><p>The interactions and assertions can be seen in a tab along side the Story, highlighting where the component may be failing tests.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l1pW9Uk_slI-3ZBXybCZVQ.png" /></figure><p>A11y testing</p><p>We can take this further with Accessibility tests using the @storybook/addon-a11y. This functions similarly to the interaction testing add-on in that it runs a test suite on a per Story basis, testing the story against WCAGs standard. Any aspects of the component that do not comply with those standard are raised in the UI.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y-em15cDzwY_uLllCVIUJA.png" /></figure><p>The impact of this is quite clear: we can be certain that every single component we provide to our engineers meets a rigorous accessibility standard, catering to all users, whether they use screen readers or use keyboard only. While this doesn’t ensure that our products are fully accessible themselves, it allows Engineers to focus on orchestrating their user experiences in an accessible manner, rather than worrying about if they remembered to add the correct Aria label to their dropdown.</p><h3>CI/CD Integration</h3><p>The above examples show how you can test a single component at a time. While this is useful during the development of a component, the real value comes from integrating these testing tools with a CI/CD pipeline.</p><p>We’ll need one more add-on from Storybook to help us here: @storybook/test-runner.</p><p>This uses Jest and Playwright to run through the play Function on all of your Stories in your StoryBook instance, providing a detailed report. For Stories that do not have a Play function, the utility will still check if the Story renders successfully.</p><p>The tests can run via NPM using the test-storybook command.</p><p>Our accessibility tests can also be included in the test runner by adding a small out of custom config to test-runner.ts. This config also allows to add any extra rules that we might need to the tests.</p><pre>import { injectAxe, checkA11y, configureAxe } from &#39;axe-playwright&#39;;<br>import { getStoryContext } from &#39;@storybook/test-runner&#39;;<br>import type { TestRunnerConfig } from &#39;@storybook/test-runner&#39;;<br><br>const a11yConfig: TestRunnerConfig = {<br> async preRender(page) {<br>  await injectAxe(page);<br> },<br> async postRender(page, context) {<br>  const storyContext = await getStoryContext(page, context);<br> <br>  // Apply story-level a11y rules<br>  await configureAxe(page, {<br>   rules: storyContext.parameters?.a11y?.config?.rules,<br>  });<br> <br>  await checkA11y(page, &#39;#root&#39;, {<br>   detailedReport: true,<br>   detailedReportOptions: {<br>    html: true,<br>   },<br>  });<br> },<br>};<br><br>module.exports = a11yConfig;</pre><p>We now have a full accessibility audit along with every test run.</p><p>The only thing left to do is to configure our interaction tests to only run during development and not in our live instance of Storybook. We handle this quite simply by checking the current config type for Storybook, if it’s Development instead of Production, we add the Play function to the stories. This property is added by Storybook at compile time. If we build it as a static web app then it’s set to Production, if we use the development run command then it is set to Development.</p><pre>if ((window as any).CONFIG_TYPE === &#39;DEVELOPMENT&#39;) {<br> const modalPanelTests = new ModalPanelTests();<br> ModalPanelStory.play = modalPanelTests;<br>}</pre><p>Adding the test-runner npm command to our CI pipeline ensures that every pull request triggers the tests, blocking merges if there are any failures. This process prevents the release of components with interaction or accessibility issues.</p><p>By integrating Storybook’s test-runner into our CI pipeline, we ensure that every component is rigorously tested and validated before being merged into the main codebase. This automated testing framework not only prevents the introduction of bugs and accessibility issues but also facilitates safer refactoring and easier maintenance of the component library. Ultimately, it allows our engineers to focus on building robust, high-quality user interfaces without worrying about underlying component reliability.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d8f8c8741901" width="1" height="1" alt=""><hr><p><a href="https://blog.enable.engineering/building-a-trusted-design-system-with-storybook-d8f8c8741901">Building a Trusted Design System With Storybook</a> was originally published in <a href="https://blog.enable.engineering/">Enable Engineering Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building Better Design Systems: Stencil.js vs React vs Custom Elements]]></title>
            <link>https://blog.enable.engineering/building-better-design-systems-stencil-js-vs-react-vs-custom-elements-b3ef41b66885?source=rss-ca3d2b90eaaa------2</link>
            <guid isPermaLink="false">https://medium.com/p/b3ef41b66885</guid>
            <category><![CDATA[ux]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Danny Merry]]></dc:creator>
            <pubDate>Wed, 28 Feb 2024 08:36:31 GMT</pubDate>
            <atom:updated>2024-02-28T08:36:31.912Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ImKrS7HQS5BValiqqBopNw.png" /></figure><p>When we began building the Enable Design System, we made the decision to create a framework agnostic component library to support all of Enable’s products. Here at Enable we are always looking for ways to push our engineering practices forward, therefore we work with a diverse tech stack. If we wanted to support all of our engineers, our component library needed to be compatible with all of the JS frameworks that we currently use, while also supporting potential tools we may use in the future.</p><p>We initially opted for Web Components, leveraging native JavaScript and the Custom Elements API, to ensure compatibility across any JavaScript-based environment. However, we soon encountered several drawbacks, including a less-than-ideal developer experience. This led us to seek a tool that not only supported our engineers better but also simplified our development process.</p><p>After reviewing a few different tools, we landed on stencil.js, a powerful tool that generates native web components while vastly improving the developer experience.</p><h3>The Problems with Web Components</h3><p>After building a handful of components and extending existing ones to cover more use cases, we quickly found developing web components using native JS to be tedious, verbose and brittle.</p><h4>Boiler plate code</h4><p>While the Custom Elements API provides support for observing attributes, the code is cumbersome and doesn’t extend to properties — these need to manually set up.<br>For every attribute, property and event added to the component, the size of the file significantly increases with methods being added to keep track of their state and their side effects.</p><h4>Javascript DOM manipulation</h4><p>Pretty much all components will require some level of conditional markup. Handling this in native JS, using DOM selectors and setting inner HTML is extremely easy to break. As variations are added to a component, more and more of the HTML needs to be provided by JS which makes it even harder to maintain.</p><h4>Working directly with the Custom Elements API</h4><p>The Custom Elements API, while fairly feature rich and well documented, needs to be well understood to work with effectively. There are very few safeguards to prevent developers from creating ill performant components with poor state management. For example, we found that it was common for our components to be triggering multiple renders on changing a single seemingly unimportant attribute.<br>Common sensible patterns such as not changing the state of public properties and providing properties for each attribute must be manually enforced.</p><h4>Slots and shadow DOM</h4><p>A very useful feature of the Custom Elements API is Slots. These allow the developers using the components to inject arbitrary HTML into the web component. However this requires the component is built using Shadow DOM which we have opted not to use as it leads to less flexibility when our engineers are creating features. This means for components that require slots we are forced to use Shadow DOM.</p><h3>Picking a Framework</h3><p>To overcome these issues we began looking at alternative ways to build components. We were particularly interested in React due to its component based structure and its incredible popularity. React is a JavaScript library used for building user interfaces and is particularly suited for developing encapsulated components, each managing its own state, which allows for efficient updates and rendering. This modular approach streamlines the development of complex applications by organizing UIs into smaller, manageable pieces. This, along with it’s strong community support and ecosystem, makes it quite clear why React is the go-to choice for design systems.</p><p>However, components built using React can only be used within apps that have also been built with React. An important requirement of our Design System is compatibility across all of Enable’s tech stack.</p><p>This is when we tried stencil.js. Stencil.js is a library built by the Ionic framework team, that uses a React like syntax to generate Javascript native Web Components using the Custom Elements API.</p><p>In other words, we get to build with a modern and enjoyable developer experience while delivering framework-agnostic components that can work with Angular, Razor, React — anything!</p><p>Stencil.js uses JSX along with its own API that abstracts away the Custom Elements API, providing an easier experience and enforcing sensible patterns. The library also includes some other handy developer tools such a dev server with hot reloading and a CLI for setting up components.</p><h3>Show Me Some Code</h3><p>Let’s walk through one of the Enable Design System components to demonstrate how we build using stencil.js.</p><p>We’ll use the file upload component which provides a drag and drop area along with a file input. It can be set to either accept single or multiple files and has configurable validation for file types and file size.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EJvOoqJqHtjt6coPlrLCvg.png" /></figure><p>The markup and and typescript/javascript is kept within a single TSX file. To define a component, we create a class with the Component decorator.</p><pre>@Component({<br>  tag: &#39;eds-file-upload&#39;,<br>  styleUrl: &#39;/styles/eds-file-upload.scss&#39;<br>})<br>export class EdsFileUpload {<br>  ...<br>}</pre><p>Within the decorator we can define the name of the web component and also link a CSS/SASS file for styling. This is also where we would set additional options such as using shadow DOM but we’ll keep it simple for now.</p><h4>Component API</h4><p>Now that we have a component, we will first define the API for interacting with it.</p><p>Within the defined class we can setup our web component’s properties using the Prop decorator. These are publicly accessible properties that define the inputs of our component.</p><pre>@Prop()<br>maxFileSize: number;<br>  <br>@Prop()<br>fileTypes: string[];<br><br>@Prop({reflect: true})<br>allowMultiple: boolean;</pre><p>In stencil.js, each primitively typed property (e.g., string, number, boolean) is automatically paired with a corresponding attribute, using kebab case for the attribute name. This is good practice as it provides more flexibility when being used. By setting the reflect option in the decorator we can tell stencil.js to automatically keep the generated attribute and property in sync.</p><p>It is recommended to avoid modifying the state of the properties from within the component as this can result in additional rerenders and render loops. Stencil.js will actually throw a warning at runtime if the properties are updated by any internal code.</p><p>We can setup custom events that our component will output using the Event binding. This allows us to define the list of possible outputs at the start of the component - rather than having arbitrary events being raised throughout.</p><pre>@Event({eventName: &#39;eds-file-upload__files-uploaded&#39;})<br>fileUploaded: EventEmitter&lt;FileList&gt;</pre><p>The event can be triggered at any point in the component by calling fileUploaded.emit(fileList).</p><p>Public methods can be defined using the Method decorator. Methods defined this way are intended to be used externally.</p><pre>@Method()<br>public async resetValidation(): Promise&lt;void&gt; {<br> this.isInvalid = false;<br>}</pre><h4>Interactions and state</h4><p>That’s our public API defined, but there are a few more decorators that we can use to add more interactivity to our component.</p><p>This Listen decorator is a quick and easy way to set up event listeners on the host element.</p><pre>@Listen(&#39;keyup&#39;)<br>handleKeyUp(e: KeyboardEvent) {<br> if (e.key === &#39;Enter&#39;) {<br>  this.dragArea.click();<br> }<br>}</pre><p>Our internal state properties are given the State decorator. These function similarly to our Props, triggering a re-render whenever they are updated. However, states are for internal use only.</p><pre>@State()<br>isInvalid = false;<br><br>@State()<br>validationError: string;</pre><h4>Rendering the component</h4><p>So we’ve set up our API and our internal state but what about building the actual component?</p><p>We need to define a render method that returns JSX (TSX in our case). This method will be called when the Custom Element is added to the DOM and then again whenever our Props or States are updated. This makes it very clear what your render triggers and what markup will be updated.</p><pre>render() {<br> return (<br>  &lt;Host&gt;<br>   &lt;div class=&quot;eds-file-upload__container&quot;&gt;<br>   ...<br>   &lt;/div&gt;<br>  &lt;/Host&gt;<br> )<br>}</pre><p>Now that we have our render method, let’s actually start putting together our component.</p><pre>render() {<br> return (<br> &lt;Host&gt;<br>  &lt;div<br>   class=&quot;eds-file-upload__container&quot;<br>   ref={el =&gt; this.dragArea = el}<br>   onDragEnter={e =&gt; this.handleDragEnter(e)}<br>   onDragLeave={e =&gt; this.handleDragLeave(e)}<br>   onDragOver={e =&gt; this.handleDragOver(e)}<br>   onDrop={e =&gt; this.handleDrop(e)}<br>   onClick={_ =&gt; fileInput.click()}&gt;  <br>   &lt;div class=&quot;eds-file-upload__text-container&quot;&gt;<br>    &lt;div class=&quot;eds-file-upload__upload-icon&quot;&gt;&lt;/div&gt;<br>    &lt;input<br>     name=&quot;file-upload&quot;<br>     type=&quot;file&quot;<br>     onChange={e =&gt; this.handleInput(e)}<br>     multiple={this.allowMultiple}<br>     hidden&gt;&lt;/input&gt;<br>     &lt;label htmlFor=&quot;file-upload&quot;&gt;Drag and drop here or click to browse files&lt;/label&gt;<br>   &lt;/div&gt;<br>   {this.isInvalid ? &lt;this.ValidationMessage validationError={this.validationError}&gt;&lt;/this.ValidationMessage&gt; : &#39;&#39;}<br>  &lt;/div&gt;<br>  &lt;this.FileDetails<br>   maxFileSize={this.maxFileSize}<br>   fileTypes={this.fileTypes}&gt;&lt;/this.FileDetails&gt;<br> &lt;/Host&gt;<br> );<br>}</pre><p>There’s a lot going on here, especially if you’re not used to JSX syntax, but what we essentially have is our component’s markup with bindings to our component’s properties and methods. The braces {} allow us to reference our component&#39;s data using regular Javascript.</p><p>For example, multiple={this.allowMultiple} will set the multiple attribute on our file input element to our public property allowMultiple and will be updated whenever the prop changes.</p><p>Towards the end of the render function we can see how we can add conditional markup, as well as how to reference child components.</p><pre>{this.isInvalid ? &lt;this.ValidationMessage validationError={this.validationError}&gt;&lt;/this.ValidationMessage&gt; : &#39;&#39;}</pre><p>Here we are conditionally showing a validation message child component based on our isInvalid prop. If this is true we render out locally defined ValidationMessage method.</p><pre>private ValidationMessage(props) {<br> return (<br>  &lt;div style={{ &#39;max-width&#39;: &#39;100%&#39;}}&gt;<br>   &lt;eds-info-message status=&quot;error&quot; display=&quot;inline&quot; message={props.validationError}&gt;<br>   &lt;/eds-info-message&gt;<br>  &lt;/div&gt;<br> )<br>}</pre><p>Along with the render method, we can also include as many component functions as we want. This is useful for breaking up larger components or using repeated markup. Note that we pass in a props object to the function - this is the current state that our render function is currently using and must be passed down to the child components.</p><h4>Packaging and use</h4><p>When creating a Stencil component with the CLI, a function is created for registering the component with the Custom Elements registry. We simply add this function to our NPM package and the component is ready to go. This means that components built in Stencil sit next to our natively built components in the same package. Developers using our component library don’t need to have any knowledge of stencil.js.</p><p>To use the web component, the developer just needs to install the NPM package, import compiled script which registers the component and then it is ready to be used in the HTML. The following is an example of file upload component being used in one of our Angular projects.</p><pre>import &#39;@enable/eds/register-components.js&#39;;</pre><pre>&lt;eds-file-upload<br>  [maxFileSize]=&quot;100&quot;<br>  [allowMultiple]=&quot;false&quot;<br>  [fileTypes]=&quot;fileTypes&quot;<br>  (eds-file-upload__files-uploaded)=&quot;handleFileUpload($event)&quot;<br>&gt;&lt;/eds-file-upload&gt;</pre><h3>Choosing stencil.js</h3><p>Stencil.js resolves almost all of the issues we found working directly with the Custom Elements API.</p><ul><li>The use of decorators makes it very clear at a quick glance what your Inputs, Outputs, State and Effects are.</li><li>Significantly less boiler plate code for setting up Attributes and Properties as well as less code to handle their side effects.</li><li>The React like syntax with template functions lends itself well to dynamic HTML and creating variations compared to handling this in native JS.</li><li>React like syntax is easy to pick up for anyone who has worked with React.</li><li>The Stencil’s API is much simpler to learn compared to Custom Elements (which unless you’ve worked on a JS native web component library before, you’ll probably have never encountered before).</li><li>Support for Slots without Shadow DOM! Stencil provides polyfills for using Slots in your components without need to encapsulate with Shadow DOM.</li></ul><p>While we still support our natively built Web Components, every single new component that we have built since finding stencil.js has been a Stencil component. They’re faster to build, easier to read and write, plus, they can be used with any framework.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b3ef41b66885" width="1" height="1" alt=""><hr><p><a href="https://blog.enable.engineering/building-better-design-systems-stencil-js-vs-react-vs-custom-elements-b3ef41b66885">Building Better Design Systems: Stencil.js vs React vs Custom Elements</a> was originally published in <a href="https://blog.enable.engineering/">Enable Engineering Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Enable Design System Deep Dive — Web components vs Frameworks]]></title>
            <link>https://blog.enable.engineering/enable-design-system-deep-dive-web-components-vs-frameworks-bc50ee976f95?source=rss-ca3d2b90eaaa------2</link>
            <guid isPermaLink="false">https://medium.com/p/bc50ee976f95</guid>
            <category><![CDATA[ux-design]]></category>
            <category><![CDATA[design-systems]]></category>
            <dc:creator><![CDATA[Danny Merry]]></dc:creator>
            <pubDate>Fri, 19 Jan 2024 11:28:29 GMT</pubDate>
            <atom:updated>2024-01-19T11:28:29.381Z</atom:updated>
            <content:encoded><![CDATA[<h3>Enable Design System Deep Dive — Web components vs Frameworks</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ss-rtTdr3773rvs_mo5sIA.png" /></figure><p>When we began creating the <a href="https://blog.enable.engineering/introducing-the-enable-design-system-69b1acc8eaeb">Enable Design System</a> within the UX team at Enable, we encountered a difficult decision: choosing the framework to serve as the foundation for our UI component library. This decision carries significant weight, having lasting effects on both the design system team and the engineers utilizing the components.</p><p>Component libraries are the primary tool for translating design into application features, ensuring consistency and quality throughout the product, while increasing productivity of engineers. Engineers can leverage the fully tested and ratified components rather than reinventing the wheel for each project. Updates or improvements to components can be applied universally, eliminating the need for redundant fixes across various projects.</p><h3>Choosing a framework</h3><p>In today’s rapidly evolving landscape of web development, characterized by the frequent release of new JavaScript frameworks, it’s not surprising to encounter a plethora of tools for building components. React, in particular, stands out as a prevalent choice for design systems due to:</p><ol><li>Its component driven design lends itself well to component libraries</li><li>It’s <strong>the most</strong> popular JS framework <a href="https://insights.stackoverflow.com/trends?tags=reactjs%2Cvue.js%2Cangular%2Csvelte%2Cangularjs%2Cvuejs3.">Stack Overflow</a></li></ol><p>However, using React, (as with many other frameworks), ties your team’s developments to that framework, taking away engineer’s autonomy and flexibility when choosing the best tool for the job. Other component tools can be very bulky, requiring a large JS bundle and providing poor performance (looking at you Angular Elements 👀).</p><p>Locking your component library into a framework from the start can lead to substantial reworks later down the line if your requirements change, as we discovered from <a href="https://2022.uxlondon.com/speakers/amir-ansari/#talk">UX London 2022</a>. We learned from design teams who had to completely overhaul their design systems for their v2 <em>and</em> v3 due to switching frameworks. So, what should we use if framework-based components are not viable?</p><h3>Introducing web components</h3><p>Web Components is a native JavaScript feature which allows for creating custom reusable HTML elements. It requires no additional JS libraries and is completely framework agnostic 🙌. As Web Component are supported by all modern browsers, the bundle size is only as large as the JavaScript that you write for the component (think very small).</p><h3>Enable’s choice</h3><p>At Enable, we actively support a diverse tech-stack across our platform, including Angular, Blazor and KnockoutJS. As our platform continuously evolves, so do our engineering practices. For this reason we opted to build the Enable Design System and its component library using Web Components. It allows us to establish consistency and well tested code across our products, even when they use entirely different frameworks. Embracing native JavaScript future proofs the design system, allowing our engineers to pick up new tools and write code according to their needs and preferences while still getting all the benefits of our component library.</p><p>Our design system is now incorporated into all of our applications, with minimal friction in implementing Web Components across different frameworks.</p><h4>Angular</h4><p>While Web Components works straight out of the box with Angular, we made some small adjustments to better take advantage of Angular’s change detection. By providing getters and setters for all of the attributes in a component, the Angular [input] binding can be used on the custom element, eliminating the need to pass around element references.</p><h4>Blazor</h4><p>We’ve recently begun supporting Blazor WASM (or Blazor WebAssembly). As this uses web assembly, Blazor cannot access the DOM which makes the use of custom HTML elements challenging. To address this we built a Blazor wrapper for each component to carry out <a href="https://learn.microsoft.com/en-us/aspnet/core/blazor/javascript-interoperability/call-javascript-from-dotnet?view=aspnetcore-8.0">JavaScript Interop</a>. This is a fairly trivial task of mapping the attributes and properties of the component, to Blazor equivalents.</p><h3>Developer experience</h3><p>Web Components indeed offer the advantages of being small, fast, and universally applicable (🎉). However, when it comes to building them, the process has both its merits and drawbacks. Direct DOM manipulation is fiddly and as a component inevitably grows and features are added, conditional HTML becomes hard to maintain. There are some lightweight JS libraries that can help with this such as lit-html, but they still lack the robustness, simplicity, and safety of frameworks like React.</p><p>Shadow DOM is recommended for strict encapsulation of components, safeguarding their behaviors and styles from the consuming web app; however, this comes with it’s own problems such as making it difficult to reuse shared styles and lack of flexibility. We decided against using Shadow DOM for our component library to give our engineers the flexibility to make tweaks where needed. However, creating Web Components with Slots for customizable content requires the use of Shadow DOM 😟.</p><p>Despite these issues, we are still happy with our decision to pick the framework-agnostic approach to build components and highly recommend this to anyone building a design system for a evolving and growing SaaS platform.</p><p>P.S. We have an upcoming article to share how we tackled some of the challenges in building Web Components by using StencilJS. Stay tuned for more details!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bc50ee976f95" width="1" height="1" alt=""><hr><p><a href="https://blog.enable.engineering/enable-design-system-deep-dive-web-components-vs-frameworks-bc50ee976f95">Enable Design System Deep Dive — Web components vs Frameworks</a> was originally published in <a href="https://blog.enable.engineering/">Enable Engineering Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>