<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Max</title>
    <description>The latest articles on DEV Community by Max (@onmax).</description>
    <link>https://dev.to/onmax</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F747022%2F1a6cf34b-2916-4345-b2a0-a5fc58ea6875.png</url>
      <title>DEV Community: Max</title>
      <link>https://dev.to/onmax</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/onmax"/>
    <language>en</language>
    <item>
      <title>Some tips for your first WebComponent</title>
      <dc:creator>Max</dc:creator>
      <pubDate>Thu, 18 Nov 2021 15:26:02 +0000</pubDate>
      <link>https://dev.to/onmax/some-tips-for-your-first-webcomponent-3bgj</link>
      <guid>https://dev.to/onmax/some-tips-for-your-first-webcomponent-3bgj</guid>
      <description>&lt;p&gt;Over the last year I have been investigating various ways of making WebComponents. In this article I summarise what I have learnt in this process&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Attributes with basic types
&lt;/h2&gt;

&lt;p&gt;A prop is an input that can be added to WebComponents. Whenever possible, I recommend using a basic type: &lt;code&gt;number&lt;/code&gt;, &lt;code&gt;bool&lt;/code&gt;, &lt;code&gt;string&lt;/code&gt; or &lt;code&gt;number&lt;/code&gt; and avoiding &lt;code&gt;Array&lt;/code&gt; and &lt;code&gt;JSON&lt;/code&gt; types, although I understand that this may not be possible at times.&lt;/p&gt;

&lt;p&gt;The problem with using an &lt;code&gt;Array&lt;/code&gt; or &lt;code&gt;JSON&lt;/code&gt; is that native HTML elements only allow basic attributes and there is no possible way to put an &lt;code&gt;Array&lt;/code&gt; or &lt;code&gt;JSON&lt;/code&gt; into an HTML template. Therefore, the only way (that I have found) is to instantiate the WC in the HTML and then reference that element in JS and add the &lt;code&gt;Array&lt;/code&gt; or &lt;code&gt;JSON&lt;/code&gt; attribute:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- This won't work --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;my-element&lt;/span&gt; &lt;span class="na"&gt;my-prop-array=&lt;/span&gt;&lt;span class="s"&gt;"[1,2,3]"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/my-element&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;my-element&lt;/span&gt; &lt;span class="na"&gt;my-prop-json=&lt;/span&gt;&lt;span class="s"&gt;"{user: 'max'}"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/my-element&amp;gt;&lt;/span&gt;

&lt;span class="c"&gt;&amp;lt;!-- This will work --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;my-element&amp;gt;&amp;lt;/my-element&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
    &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;my-element&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;myPropArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;my-element&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;myPropJson&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;max&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also, it should be noted that I have found that with certain frameworks such as Angular, it is necessary to do a &lt;code&gt;JSON.stringify(myPropJson)&lt;/code&gt; and in the WC do a &lt;code&gt;JSON.parse(myPropJson)&lt;/code&gt;, which is not the best process in my opinion.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Reactive vs static
&lt;/h2&gt;

&lt;p&gt;You have to know the difference between a reactive and a static WC prop:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reactive: The value of the variable that is passed to the component and the value of the prop is always the same.&lt;/li&gt;
&lt;li&gt;Static: A copy of the value of the variable passed to the component is created in the prop.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Depending on the framework you want to use, you must indicate what you want.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Output with events
&lt;/h2&gt;

&lt;p&gt;The way to pass data from a WebComponent to the host is mainly through events. Note that these events may be encapsulated in a &lt;code&gt;CustomEvent&lt;/code&gt;, where the &lt;code&gt;detail&lt;/code&gt; attribute will have the value that has been emitted.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Working with styles
&lt;/h2&gt;

&lt;p&gt;One of the positive aspects that WebComponents bring is the use of the Shadow DOM. This is a big plus point, but on the other hand, being something relatively new, CSS development should be at its most basic. If you try to do something more complex, for example with PostCSS, you might not work or you might have a lot of difficulties.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Use a template
&lt;/h2&gt;

&lt;p&gt;It is better if you use a template when you start the development of a WebComponent, as these templates are usually configured to do the build as well. I have developed two templates with lit and vite:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/onmax/github-user-wc"&gt;Github User WC&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/onmax/lit-ts-vite-tailwindcss-template"&gt;Twind in Lit&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>webcomponents</category>
      <category>ts</category>
      <category>template</category>
      <category>lit</category>
    </item>
    <item>
      <title>Basic concepts about WebComponents</title>
      <dc:creator>Max</dc:creator>
      <pubDate>Mon, 15 Nov 2021 13:22:08 +0000</pubDate>
      <link>https://dev.to/onmax/basic-concepts-about-webcomponents-4ldg</link>
      <guid>https://dev.to/onmax/basic-concepts-about-webcomponents-4ldg</guid>
      <description>&lt;h2&gt;
  
  
  What is it?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;WebComponents (WC) is a technology that focuses on the development of native web components&lt;/strong&gt; so that they can be used by any page and any framework. To do this, an API has been developed in both JS and browsers to create these new non-native components.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;When we talk about a native component we are referring to HTML elements such as: div, p, main, article, button... A non-native WebComponent would be something like &lt;code&gt;&amp;lt;my-element&amp;gt;&amp;lt;/my-element&amp;gt;&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;WebComponents is a very basic API and does not have many common features for component development that we can expect from a normal framework such as: &lt;code&gt;Reactive lifecycle&lt;/code&gt;, &lt;code&gt;Reactive variables/props&lt;/code&gt; or &lt;code&gt;Declarative template&lt;/code&gt; among others. That is why it is recommended to use a framework like Lit, Svelte or Angular to create WebComponents and not to do it directly on the JS API. To do this, you must compile your component with your framework to generate a JS file with the &lt;code&gt;WebComponent&lt;/code&gt; definition. That file later you will be able to take it to any page and import the script in a similar way to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"module"&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"./simple-greeting.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;simple-greeting&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"World"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/simple-greeting&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="c"&gt;&amp;lt;!-- 
    Example from:
    https://lit.dev/playground/#sample=examples/hello-world
 --&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I recommend &lt;a href="https://youtu.be/4-dYhoZ1Ukw?t=1926"&gt;this video&lt;/a&gt; to learn more about the differences between developing directly with the WebComponents API and using a framework to generate WebComponents.&lt;/p&gt;

&lt;p&gt;I also recommend taking a look at the &lt;a href="https://open-wc.org/guides/"&gt;Open WC guidelines, recommendations and best practices&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to generate WebComponents
&lt;/h2&gt;

&lt;p&gt;As discussed above, there are two ways to create WebComponents:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Directly with the JS WebComponents API: It would be similar to building a web page only with vanilla JS and therefore I do not recommend it unless it is a very basic component.&lt;/li&gt;
&lt;li&gt;With the help of some framework. This is what I recommend.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Webcomponents technology is just starting to be created and new tools will surely appear in the near future.&lt;/p&gt;

&lt;h2&gt;
  
  
  Frameworks
&lt;/h2&gt;

&lt;p&gt;Good articles with more detail on this subject::&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://webcomponents.dev/blog/all-the-ways-to-make-a-web-component/"&gt;All the Ways to Make a Web Component - Nov 2021 Update&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://levelup.gitconnected.com/web-component-solutions-a-comparison-e2fa25c34730"&gt;Web Component Solutions: A Comparison&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Below is a comparative table based on my personal opinion based on different tests:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Framework&lt;/th&gt;
&lt;th&gt;Made for WC&lt;/th&gt;
&lt;th&gt;Small bundle&lt;/th&gt;
&lt;th&gt;External libreries^1&lt;/th&gt;
&lt;th&gt;Buildless&lt;/th&gt;
&lt;th&gt;FrameworkCSS&lt;/th&gt;
&lt;th&gt;With TS^2&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Lit&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Svelte&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;-&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;❓&lt;/td&gt;
&lt;td&gt;❓&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Stencil&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;❓&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Vue&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;❓&lt;/td&gt;
&lt;td&gt;❓&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Angular&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;❓&lt;/td&gt;
&lt;td&gt;❓&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;^1 You can always use vanilla JS libraries&lt;br&gt;
^2 With TS out-of-the-box&lt;/p&gt;

&lt;h3&gt;
  
  
  Lit
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://vite.new/lit-ts"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--oYPJfc6u--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://img.shields.io/badge/lit-demo_online-blue" alt="Lit online demo " width="98" height="20"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://lit.dev/playground/"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dZhppONY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://img.shields.io/badge/lit-playground-lightgrey" alt="Lit playground" width="92" height="20"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://lit.dev/docs/"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VlkxTmaN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://img.shields.io/badge/lit-docs-orange" alt="Lit docs" width="56" height="20"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://youtu.be/4-dYhoZ1Ukw?t=1926"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4hDVXJ6h--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://img.shields.io/badge/lit-video-yellow" alt="Video" width="60" height="20"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Positive facts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Super light and fast&lt;/li&gt;
&lt;li&gt;Well documented&lt;/li&gt;
&lt;li&gt;No build needed, can be a negative point&lt;/li&gt;
&lt;li&gt;Developed by Google&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Negative facts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Because it is buildless, you cannot use third party tools such as TailwindCSS with ShadowDOM.&lt;/li&gt;
&lt;li&gt;It is a very strict CSS framework, and works with ShadowDOM, therefore, CSS works only if it is parsed using "&lt;code&gt;css`h1 { color: red}&lt;/code&gt; ``" is allowed. &lt;a href="https://lit.dev/docs/components/styles/"&gt;More info&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Svelte
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://vite.new/svelte-ts"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mY-4IgS1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://img.shields.io/badge/svelte-demo_online-blue" alt="Svelte online demo " width="120" height="20"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://svelte.dev/tutorial/basics"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LGJAvxWv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://img.shields.io/badge/svelte-tutorial-lightgrey" alt="Svelte tutorial" width="92" height="20"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://svelte.dev/docs"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jSYe-61Q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://img.shields.io/badge/svelte-docs-orange" alt="Svelte docs" width="78" height="20"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Positive facts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Super light and fast&lt;/li&gt;
&lt;li&gt;Well loved by the community&lt;/li&gt;
&lt;li&gt;Well documented and lots of examples&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Negative facts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It is a framework that was intended for web development.&lt;/li&gt;
&lt;li&gt;Small community, and therefore, few libraries/plugins compared to React/Angular/Vue.&lt;/li&gt;
&lt;li&gt;There are certain restrictions on how Svelte is made and should be taken into account. &lt;a href="https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Client-side_JavaScript_frameworks/Svelte_reactivity_lifecycle_accessibility"&gt;More info&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Stencil
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://stenciljs.com/docs/introduction"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5VP2m71O--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://img.shields.io/badge/stencil-docs-orange" alt="Stencil docs" width="80" height="20"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Positive facts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Powered by Ionic&lt;/li&gt;
&lt;li&gt;Developed to create Design Systems.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Negative facts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Does not have a large community&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Angular/Vue
&lt;/h3&gt;

&lt;p&gt;Positive points:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Popular frameworks&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Negative facts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;They are not intended for developing WebComponents but web pages.&lt;/li&gt;
&lt;li&gt;WebComponents take up a lot of space&lt;/li&gt;
&lt;li&gt;Compared to the other frameworks in this article, both Angular and Vue are very slow to develop and build.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Storybook
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://storybook.js.org/docs/web-components/get-started/introduction"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_7F3mmSe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://img.shields.io/badge/storybook-docs-orange" alt="Storybook docs" width="100" height="20"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://next--storybookjs.netlify.app/official-storybook/"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZqeaZBqC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://img.shields.io/badge/stencil-example-orange" alt="Storybook example" width="102" height="20"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Storybook is an open source tool for building components in isolation. It streamlines development, testing and documentation of the user interface. In a "story", which is a web page where a WebComponent or CustomComponent (component developed by Vue, Angular, React...) that you have developed is shown, you can interact with it by changing the props, seeing the events it emits, reading the documentation you have written about the component... which allows you to show your components and do manual testing in a much more comfortable way. Storybook can be integrated with many well-known frameworks and WebComponents.&lt;/p&gt;

&lt;h2&gt;
  
  
  TS
&lt;/h2&gt;

&lt;p&gt;In 2021, most JS frameworks also support TS. The use of TS allows to add types to the JS. In addition, tools such as Lit or Stencil, when exporting the component, also export a document with the types of the WebComponent, indicating the props it can receive and the events it can emit and with what parameters.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bundler
&lt;/h2&gt;

&lt;p&gt;You can choose any bundler. Although &lt;code&gt;Open-WC&lt;/code&gt; recommends the use of &lt;code&gt;web-dev-server&lt;/code&gt;. But &lt;code&gt;rollup&lt;/code&gt; and &lt;code&gt;vite&lt;/code&gt; are much faster and also have a lot of plugins. The easiest is to download a &lt;code&gt;template&lt;/code&gt; from Github.&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding styles to WebComponents
&lt;/h2&gt;

&lt;p&gt;To talk about styling in WebComponents, you have to understand that it is the &lt;a href="https://developers.google.com/web/fundamentals/web-components/shadowdom?hl=en"&gt;Shadow DOM&lt;/a&gt; that allows CSS styles to be applied only to the elements of the subtree that generates your WebComponent and not to other elements of the web page that hosts the document.&lt;/p&gt;

&lt;p&gt;This is very problematic and in general, the only thing I recommend for styling is to use the most basic method: Add classes in the HTML template and then in the CSS of the Shadow DOM by hand, this way you can ease the development process and CI/CD if you add it to the project.&lt;/p&gt;

&lt;p&gt;Any other technique that you want to carry out in relation to the WebComponent styles can give problems:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://css-tricks.com/styling-web-components/"&gt;Attempting to pass styles from host to WebComponent&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.smashingmagazine.com/2016/12/styling-web-components-using-a-shared-style-sheet/"&gt;Sharing styles for WC and host&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Style inheritance
&lt;/h3&gt;

&lt;p&gt;Another option (and which is not recommended in my opinion) is to disable the ShadowDOM of your component and allow your component to inherit styles from the host and, therefore, the WC developer will have to generate the JS file (with the WC definition) and the CSS. Subsequently, the WC user would have to import both the JS file and the CSS file. These styles will also be applied to the host.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Svelte, for example, uses this technique with the difference that it hashes the CSS classes and in the end the expected result is achieved: That the CSS classes are only applied to the WebComponent. In this way, tools like PostCSS could be used for the development of the WebComponent and not only vanilla CSS.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Still, ShadowDOM is a very immature technology and it is possible that in the future they will improve this aspect.&lt;/p&gt;

&lt;h3&gt;
  
  
  Alternatives to TailwindCSS
&lt;/h3&gt;

&lt;p&gt;Alternatives to TailwindCSS can be investigated such as &lt;code&gt;twind&lt;/code&gt; and &lt;code&gt;WindiCSS&lt;/code&gt; which are based on &lt;code&gt;TailwindCSS&lt;/code&gt; but do not work as a PostCSS plugin.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;WC is something different from a web, and therefore, you should use a framework that is specialized in the development of WebComponents. Also, the good practice would be to use ShadowDOM but that as we have already seen can give many problems and it is necessary to use some better alternative.&lt;/p&gt;

</description>
      <category>webcomponents</category>
      <category>lit</category>
      <category>javascript</category>
      <category>typescript</category>
    </item>
  </channel>
</rss>
