<?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>Forem: Vlad Shilov</title>
    <description>The latest articles on Forem by Vlad Shilov (@omgovich).</description>
    <link>https://forem.com/omgovich</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%2F487032%2F6ce969d0-67a5-4c18-a0f8-1754cf13dade.jpeg</url>
      <title>Forem: Vlad Shilov</title>
      <link>https://forem.com/omgovich</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/omgovich"/>
    <language>en</language>
    <item>
      <title>👑 Colord — tiny yet powerful tool for high-performance color manipulations and conversions</title>
      <dc:creator>Vlad Shilov</dc:creator>
      <pubDate>Wed, 12 May 2021 15:33:58 +0000</pubDate>
      <link>https://forem.com/omgovich/colord-tiny-yet-powerful-tool-for-high-performance-color-manipulations-and-conversions-4f76</link>
      <guid>https://forem.com/omgovich/colord-tiny-yet-powerful-tool-for-high-performance-color-manipulations-and-conversions-4f76</guid>
      <description>&lt;h1&gt;
  
  
  The Story
&lt;/h1&gt;

&lt;p&gt;It's been a year since &lt;a href="https://dev.to/omgovich/react-colorful-1-8-kb-color-picker-for-react-fast-dependency-free-customizable-and-accessible-8le"&gt;we introduced &lt;strong&gt;react-colorful&lt;/strong&gt;&lt;/a&gt;, the fastest and smallest color picker component for React and Preact apps. Developers love how fast it works and how small its bundle is, so the package has become quite popular (about 1 million downloads weekly).&lt;/p&gt;

&lt;p&gt;During the maintenance of react-colorful, we examined the color processing and discovered that all popular color manipulation libraries (such as &lt;strong&gt;&lt;a href="https://www.npmjs.com/package/color" rel="noopener noreferrer"&gt;color&lt;/a&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;a href="https://www.npmjs.com/package/tinycolor2" rel="noopener noreferrer"&gt;tinycolor2&lt;/a&gt;&lt;/strong&gt;) are quite heavy and slow. For instance, importing all 14 components &lt;strong&gt;including their styles&lt;/strong&gt; from the react-colorful package would be less expensive than importing a constructor from tinycolor2.&lt;/p&gt;

&lt;p&gt;That is why react-colorful is not dependent on any of these libraries and has its own color conversion logic built from scratch.&lt;/p&gt;

&lt;p&gt;A couple of months ago we noticed that the color conversion code we wrote appeared to be quite performant, so we decided to reuse our experience and created a new modern color manipulation library called &lt;a href="https://github.com/omgovich/colord" rel="noopener noreferrer"&gt;&lt;strong&gt;Colord&lt;/strong&gt;&lt;/a&gt; 👑&lt;/p&gt;

&lt;h1&gt;
  
  
  Meet &lt;a href="https://github.com/omgovich/colord" rel="noopener noreferrer"&gt;&lt;strong&gt;Colord&lt;/strong&gt;&lt;/a&gt; 👑
&lt;/h1&gt;

&lt;p&gt;A tiny yet powerful tool for high-performance color manipulations and conversions.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;📦 &lt;strong&gt;Small&lt;/strong&gt;: Just &lt;strong&gt;1.5 KB&lt;/strong&gt; gzipped (&lt;a href="https://github.com/omgovich/colord#benchmarks" rel="noopener noreferrer"&gt;3x+ lighter&lt;/a&gt; than &lt;strong&gt;color&lt;/strong&gt; and &lt;strong&gt;tinycolor2&lt;/strong&gt;)&lt;/li&gt;
&lt;li&gt;🚀 &lt;strong&gt;Fast&lt;/strong&gt;: &lt;a href="https://github.com/omgovich/colord#benchmarks" rel="noopener noreferrer"&gt;3x+ faster&lt;/a&gt; than &lt;strong&gt;color&lt;/strong&gt; and &lt;strong&gt;tinycolor2&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;😍 &lt;strong&gt;Simple&lt;/strong&gt;: Chainable API and familiar patterns&lt;/li&gt;
&lt;li&gt;💪 &lt;strong&gt;Immutable&lt;/strong&gt;: No need to worry about data mutations&lt;/li&gt;
&lt;li&gt;🛡 &lt;strong&gt;Bulletproof&lt;/strong&gt;: Written in strict TypeScript and has 100% test coverage&lt;/li&gt;
&lt;li&gt;🗂 &lt;strong&gt;Typed&lt;/strong&gt;: Ships with &lt;a href="https://github.com/omgovich/colord#types" rel="noopener noreferrer"&gt;types included&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;🏗 &lt;strong&gt;Extendable&lt;/strong&gt;: Built-in &lt;a href="https://github.com/omgovich/colord#plugins" rel="noopener noreferrer"&gt;plugin system&lt;/a&gt; to add new functionality&lt;/li&gt;
&lt;li&gt;👫 &lt;strong&gt;Works everywhere&lt;/strong&gt;: Supports all browsers and Node.js&lt;/li&gt;
&lt;li&gt;💨 &lt;strong&gt;Dependency-free&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Benchmarks
&lt;/h2&gt;

&lt;p&gt;We have performed a bunch of benchmarks against popular color manipulation libraries, and Colord currently beats them all.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fie5bd84yi4f7pvjy5ddw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fie5bd84yi4f7pvjy5ddw.png" alt="Benchmarks"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  API
&lt;/h2&gt;

&lt;p&gt;Colord has an immutable chainable API and follows familiar patterns.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;colord&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;colord&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;colord&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#ff0000&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;grayscale&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;alpha&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.25&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;toRgbString&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// "rgba(128, 128, 128, 0.25)"&lt;/span&gt;
&lt;span class="nf"&gt;colord&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;rgb(200, 200, 200)&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;isLight&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;span class="nf"&gt;colord&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hsl(0deg, 50%, 50%)&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;darken&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.25&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;toHex&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// "#602020"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Supported Color Models&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Hexadecimal strings (including 3, 4 and 8 digit notations)&lt;/li&gt;
&lt;li&gt;RGB strings and objects&lt;/li&gt;
&lt;li&gt;HSL strings and objects&lt;/li&gt;
&lt;li&gt;HSV objects&lt;/li&gt;
&lt;li&gt;Color names (&lt;a href="https://github.com/omgovich/colord#plugins" rel="noopener noreferrer"&gt;via plugin&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;HWB objects and strings (&lt;a href="https://github.com/omgovich/colord#plugins" rel="noopener noreferrer"&gt;via plugin&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;LCH objects and strings (&lt;a href="https://github.com/omgovich/colord#plugins" rel="noopener noreferrer"&gt;via plugin&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;LAB objects (&lt;a href="https://github.com/omgovich/colord#plugins" rel="noopener noreferrer"&gt;via plugin&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;XYZ objects (&lt;a href="https://github.com/omgovich/colord#plugins" rel="noopener noreferrer"&gt;via plugin&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;CMYK and more are coming...&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Plugin System
&lt;/h2&gt;

&lt;p&gt;You probably noticed we used the word "plugin" in the section above. That is actually one of the best things about Colord that other libraries don't have.&lt;/p&gt;

&lt;p&gt;By default, Colord includes the most popular color models and functions. The library doesn't add unnecessary expensive features to keep your bundle lightweight, but ships with a powerful plugin system that enables developers to add the methods and color models their applications might require.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;colord&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;extend&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;colord&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// 1. import plugins&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;a11yPlugin&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;colord/plugins/a11y&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;lchPlugin&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;colord/plugins/lch&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// 2. enable them&lt;/span&gt;
&lt;span class="nf"&gt;extend&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nx"&gt;a11yPlugin&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;lchPlugin&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;

&lt;span class="c1"&gt;// 3. use new methods and parsers&lt;/span&gt;
&lt;span class="nf"&gt;colord&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#FFF&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;isReadable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;#DDD&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// false&lt;/span&gt;
&lt;span class="nf"&gt;colord&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;lch(48.25% 30.07 196.38)&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;toHex&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// "#008080"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;a href="https://github.com/omgovich/colord#plugins" rel="noopener noreferrer"&gt;Official plugins&lt;/a&gt; are continually being added. These are the ones available right now:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;a11y&lt;/strong&gt; (Accessibility tools)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;hwb&lt;/strong&gt; (HWB color model)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;lab&lt;/strong&gt; (CIE LAB color space)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;lch&lt;/strong&gt; (CIE LCH color space)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;mix&lt;/strong&gt; (Color mixing)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;names&lt;/strong&gt; (CSS color keywords)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;xyz&lt;/strong&gt; (CIE XYZ color space)&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  ❤️ Thanks for reading
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/omgovich/colord" rel="noopener noreferrer"&gt;&lt;strong&gt;Colord&lt;/strong&gt;&lt;/a&gt; cares about bundle size, application performance, and interface accessibility. I hope that the community shares our values and will find the library useful for further projects.&lt;/p&gt;

&lt;p&gt;It will help us a lot if you star the repo on GitHub or share the link to this article with your friends 🙏&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/omgovich" rel="noopener noreferrer"&gt;
        omgovich
      &lt;/a&gt; / &lt;a href="https://github.com/omgovich/colord" rel="noopener noreferrer"&gt;
        colord
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      👑 A tiny yet powerful tool for high-performance color manipulations and conversions
    &lt;/h3&gt;
  &lt;/div&gt;
&lt;/div&gt;



</description>
      <category>showdev</category>
      <category>javascript</category>
      <category>node</category>
      <category>typescript</category>
    </item>
    <item>
      <title>The tiniest CSS-in-JS solution for your open-source React components</title>
      <dc:creator>Vlad Shilov</dc:creator>
      <pubDate>Thu, 18 Feb 2021 08:29:34 +0000</pubDate>
      <link>https://forem.com/omgovich/the-tiniest-css-in-js-solution-for-your-open-source-react-components-1o94</link>
      <guid>https://forem.com/omgovich/the-tiniest-css-in-js-solution-for-your-open-source-react-components-1o94</guid>
      <description>&lt;p&gt;Hey there! My name is Vlad and I'm fascinated by the development of JavaScript micro-libraries. My primary projects at the moment are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://omgovich.github.io/react-colorful" rel="noopener noreferrer"&gt;&lt;strong&gt;react-colorful&lt;/strong&gt;&lt;/a&gt; — the tiniest and fastest color picker component for React and Preact apps (14 times lighter than react-color)&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/molefrog/wouter" rel="noopener noreferrer"&gt;&lt;strong&gt;wouter&lt;/strong&gt;&lt;/a&gt; — a minimalist-friendly 1.3KB routing solution for React and Preact&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/omgovich/omgopass" rel="noopener noreferrer"&gt;&lt;strong&gt;omgopass&lt;/strong&gt;&lt;/a&gt; — a tiny 0.3 KB and ultra-fast memorable password generator (600 times faster than password-generator)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;react-colorful&lt;/strong&gt; is the only project that ships both JS and CSS. I want to share with you the challenges we encountered while developing it. You might find our experience useful in making your open-source React components lighter.&lt;/p&gt;

&lt;h2&gt;
  
  
  📦 Problem
&lt;/h2&gt;

&lt;p&gt;Since its first release, &lt;strong&gt;react-colorful&lt;/strong&gt; has included a CSS file that developers have to import:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;HexColorPicker&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react-colorful&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react-colorful/dist/index.css&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// 👈 this one&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;In terms of bundle size, everything was super cool because we wrote all styles as CSS files that were then compressed and minified by a bundling tool. &lt;/p&gt;

&lt;p&gt;It seemed like a good solution, but we've started receiving complaints from many developers that were unable to use the styles. It is quite common in the React ecosystem to use libraries like &lt;a href="https://emotion.sh/" rel="noopener noreferrer"&gt;Emotion&lt;/a&gt;, &lt;a href="https://styled-components.com/" rel="noopener noreferrer"&gt;Styled-Components&lt;/a&gt;, or other CSS-in-JS libraries exclusively and to entirely forgo the inclusion of a style loader. As such, usage of &lt;strong&gt;react-colorful&lt;/strong&gt; would necessitate the alteration of build configurations for these users to be able to access the default styling.&lt;/p&gt;

&lt;p&gt;Moreover, many component libraries and UI kits are CSS-in-JS exclusive, so the CSS-only approach makes it difficult for the picker to be compatible.&lt;/p&gt;
&lt;h2&gt;
  
  
  👩‍🎤 Why not just use an existing CSS-in-JS solution?
&lt;/h2&gt;

&lt;p&gt;In &lt;a href="https://dev.to/omgovich/react-colorful-1-8-kb-color-picker-for-react-fast-dependency-free-customizable-and-accessible-8le"&gt;my last post&lt;/a&gt;, I mentioned that &lt;strong&gt;react-colorful&lt;/strong&gt; aims to be a zero-dependency package and we didn't want to change that by adding a CSS-in-JS framework, such as Emotion.&lt;/p&gt;

&lt;p&gt;The entirety of &lt;strong&gt;react-colorful&lt;/strong&gt; costs about 2 KB, but installing emotion would make the size of the package almost 7 times bigger. Of course, there are tiny CSS-in-JS libraries like &lt;a href="https://github.com/cristianbote/goober" rel="noopener noreferrer"&gt;goober&lt;/a&gt; that cost about 1KB, but we didn't feel like we need the entire library since our styles are not dynamic.&lt;/p&gt;

&lt;p&gt;Installing an extra dependency on other developers' projects does not seem justified to us.&lt;/p&gt;
&lt;h2&gt;
  
  
  🗜 The tiniest solution
&lt;/h2&gt;

&lt;p&gt;In order to achieve our goals, we decided to find a simple way of injecting styles into the page just like how CSS-in-JS libraries do that.&lt;/p&gt;

&lt;p&gt;I use &lt;a href="https://github.com/developit/microbundle" rel="noopener noreferrer"&gt;Microbundle&lt;/a&gt; to build my open-source projects and love it a lot. It's a zero-configuration bundler for tiny modules, powered by Rollup. &lt;/p&gt;

&lt;p&gt;Most bundlers, Microbundle included, save processed styles to the disk as a CSS file. Because we wanted to have the styles in JS, &lt;a href="https://github.com/developit/microbundle/issues/744" rel="noopener noreferrer"&gt;we asked&lt;/a&gt; Jason Miller, the author of Microbundle (amongst many other notable projects), to provide us with a way to import processed CSS as a string into JavaScript and he generously added a &lt;a href="https://github.com/developit/microbundle#css-and-css-modules" rel="noopener noreferrer"&gt;new option&lt;/a&gt; to Microbundle:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// with the default external CSS:&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./foo.css&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;// generates a minified .css file in the output directory&lt;/span&gt;

&lt;span class="c1"&gt;// with `microbundle --css inline`:&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;css&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./foo.css&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;css&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;// the generated minified stylesheet string&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;em&gt;It is not necessary to use Microbundle; you can use any build tool that you'd like, just make sure to read up on the docs to configure it properly.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Then we created a &lt;a href="https://github.com/omgovich/react-colorful/blob/master/src/hooks/useStyleSheet.ts" rel="noopener noreferrer"&gt;simple hook&lt;/a&gt; that creates a &lt;code&gt;&amp;lt;style&amp;gt;&lt;/code&gt; tag containing the styles for our component. As soon as the component renders the first time, this hook appends the tag to &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useLayoutEffect&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;styles&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;../css/styles.css&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;styleElement&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;useStyleSheet&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;useLayoutEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;undefined&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;styleElement&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;styleElement&lt;/span&gt; &lt;span class="o"&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;head&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;appendChild&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="nf"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;style&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
      &lt;span class="nx"&gt;styleElement&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerHTML&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;styles&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[]);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  👍 Results
&lt;/h2&gt;

&lt;p&gt;Since it no longer requires importing CSS separately, the usage of the &lt;a href="https://github.com/omgovich/react-colorful" rel="noopener noreferrer"&gt;&lt;strong&gt;react-colorful&lt;/strong&gt;&lt;/a&gt; became much simpler. Now the component can be used with any CSS-in-JS project or component library.&lt;/p&gt;

&lt;p&gt;The hook's gzipped size is about 150 bytes, and I suspect it's one of the smallest ways of shipping CSS for a React component.&lt;/p&gt;
&lt;h2&gt;
  
  
  ❤️ Thanks for reading
&lt;/h2&gt;

&lt;p&gt;We care about size, performance, and accessibility. I hope that the React community shares our values and will find &lt;a href="https://omgovich.github.io/react-colorful/" rel="noopener noreferrer"&gt;&lt;strong&gt;react-colorful&lt;/strong&gt;&lt;/a&gt; useful for further projects.&lt;/p&gt;

&lt;p&gt;It will help us a lot if you star the repo on GitHub or share the link to this article with your friends 🙏&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/omgovich" rel="noopener noreferrer"&gt;
        omgovich
      &lt;/a&gt; / &lt;a href="https://github.com/omgovich/react-colorful" rel="noopener noreferrer"&gt;
        react-colorful
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      🎨 A tiny (2,8 KB) color picker component for React and Preact apps
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;div&gt;
  &lt;a href="https://omgovich.github.io/react-colorful" rel="nofollow noopener noreferrer"&gt;
    &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fomgovich%2Freact-colorfuldemo%2Fsrc%2Fassets%2Fdesign.png" width="229" height="233" alt="react-colorful"&gt;
  &lt;/a&gt;
&lt;/div&gt;

&lt;div&gt;
  &lt;a href="https://npmjs.org/package/react-colorful" rel="nofollow noopener noreferrer"&gt;
    &lt;img alt="npm" src="https://camo.githubusercontent.com/ec5179c970397f913cb756c2763359b4e4000ccbecae8c2995cba642ba83ad7d/68747470733a2f2f696d672e736869656c64732e696f2f6e706d2f762f72656163742d636f6c6f7266756c2e7376673f6c6162656c436f6c6f723d64613234386426636f6c6f723d366561643061"&gt;
  &lt;/a&gt;
  &lt;a href="https://github.com/omgovich/react-colorful/actions" rel="noopener noreferrer"&gt;
    &lt;img alt="build" src="https://camo.githubusercontent.com/50d41da2568f7ffb10d3519513f86e8a6e080e6fcda1975b8ccda832c9f4fe5c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6f6d676f766963682f72656163742d636f6c6f7266756c2f4e6f64652e6a7325323043492f6d61737465722e7376673f6c6162656c436f6c6f723d64613234386426636f6c6f723d366561643061"&gt;
  &lt;/a&gt;
  &lt;a href="https://codecov.io/gh/omgovich/react-colorful" rel="nofollow noopener noreferrer"&gt;
    &lt;img alt="coverage" src="https://camo.githubusercontent.com/36f5f094f8ab58c29ec9c9ceba34662fd2d80d04fc5b1ce417eb0a80b44228e8/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f6f6d676f766963682f72656163742d636f6c6f7266756c2e7376673f6c6162656c436f6c6f723d64613234386426636f6c6f723d366561643061"&gt;
  &lt;/a&gt;
  &lt;a href="https://npmjs.org/package/react-colorful" rel="nofollow noopener noreferrer"&gt;
    &lt;img alt="no dependencies" src="https://camo.githubusercontent.com/a34c66c7c03a54a9bde18609ab60ebdde682e40a289b2251520d659e8314dc63/68747470733a2f2f62616467656e2e6e65742f62756e646c6570686f6269612f646570656e64656e63792d636f756e742f72656163742d636f6c6f7266756c3f6c6162656c436f6c6f723d64613234386426636f6c6f723d366561643061"&gt;
  &lt;/a&gt;
  &lt;a href="https://bundlephobia.com/result?p=react-colorful" rel="nofollow noopener noreferrer"&gt;
    &lt;img alt="tree-shakeable" src="https://camo.githubusercontent.com/57cefbfb4e12d33acb2f4e5b1340d0d6a8f02134c0605f357c5456ee8e4c1ce6/68747470733a2f2f62616467656e2e6e65742f62756e646c6570686f6269612f747265652d7368616b696e672f72656163742d636f6c6f7266756c3f6c6162656c436f6c6f723d64613234386426636f6c6f723d366561643061"&gt;
  &lt;/a&gt;
  &lt;a href="https://npmjs.org/package/react-colorful" rel="nofollow noopener noreferrer"&gt;
    &lt;img alt="types included" src="https://camo.githubusercontent.com/d0612eeffbab3a562e975b07759d858d3e2fa84ab5e2ae5ae066f5d83076adba/68747470733a2f2f62616467656e2e6e65742f6e706d2f74797065732f72656163742d636f6c6f7266756c3f6c6162656c436f6c6f723d64613234386426636f6c6f723d366561643061"&gt;
  &lt;/a&gt;
&lt;/div&gt;

&lt;div&gt;
  &lt;strong&gt;react-colorful&lt;/strong&gt; is a tiny color picker component for React and Preact apps
&lt;/div&gt;

&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Features&lt;/h2&gt;
&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;🗜 &lt;strong&gt;Small&lt;/strong&gt;: Just 2,8 KB gzipped (&lt;a href="https://github.com/omgovich/react-colorful#why-react-colorful" rel="noopener noreferrer"&gt;13x lighter&lt;/a&gt; than &lt;strong&gt;react-color&lt;/strong&gt;).&lt;/li&gt;
&lt;li&gt;🌳 &lt;strong&gt;Tree-shakeable&lt;/strong&gt;: Only the parts you use will be imported into your app's bundle.&lt;/li&gt;
&lt;li&gt;🚀 &lt;strong&gt;Fast&lt;/strong&gt;: Built with hooks and functional components only.&lt;/li&gt;
&lt;li&gt;🛡 &lt;strong&gt;Bulletproof&lt;/strong&gt;: Written in strict TypeScript and has 100% test coverage.&lt;/li&gt;
&lt;li&gt;🗂 &lt;strong&gt;Typed&lt;/strong&gt;: Ships with &lt;a href="https://github.com/omgovich/react-colorful#typescript-support" rel="noopener noreferrer"&gt;types included&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;😍 &lt;strong&gt;Simple&lt;/strong&gt;: The interface is straightforward and easy to use.&lt;/li&gt;
&lt;li&gt;👫 &lt;strong&gt;Cross-browser&lt;/strong&gt;: Works out-of-the-box for most browsers, regardless of version.&lt;/li&gt;
&lt;li&gt;📲 &lt;strong&gt;Mobile-friendly&lt;/strong&gt;: Supports mobile devices and touch screens.&lt;/li&gt;
&lt;li&gt;💬 &lt;strong&gt;Accessible&lt;/strong&gt;: Follows the &lt;a href="https://www.w3.org/WAI/standards-guidelines/aria/" rel="nofollow noopener noreferrer"&gt;WAI-ARIA&lt;/a&gt; guidelines to support users of assistive technologies.&lt;/li&gt;
&lt;li&gt;💨 &lt;strong&gt;No dependencies&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Live demos&lt;/h2&gt;
&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://omgovich.github.io/react-colorful" rel="nofollow noopener noreferrer"&gt;Website&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://codesandbox.io/s/react-colorful-demo-u5vwp" rel="nofollow noopener noreferrer"&gt;HEX Color Picker (CodeSandbox)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://codesandbox.io/s/react-colorful-rgb-o9q0t" rel="nofollow noopener noreferrer"&gt;RGBA Color Picker (CodeSandbox)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Table of Contents&lt;/h2&gt;

&lt;/div&gt;


&lt;ul&gt;

&lt;li&gt;&lt;a href="https://github.com/omgovich/react-colorful#getting-started" rel="noopener noreferrer"&gt;Getting Started&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href="https://github.com/omgovich/react-colorful#supported-color-models" rel="noopener noreferrer"&gt;Supported Color Models&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href="https://github.com/omgovich/react-colorful#customization" rel="noopener noreferrer"&gt;Customization&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href="https://github.com/omgovich/react-colorful#how-to-paste-or-type-a-color" rel="noopener noreferrer"&gt;How to paste or type a color?&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href="https://github.com/omgovich/react-colorful#code-recipes" rel="noopener noreferrer"&gt;Code Recipes&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href="https://github.com/omgovich/react-colorful#typescript-support" rel="noopener noreferrer"&gt;TypeScript Support&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;

&lt;a href="https://github.com/omgovich/react-colorful#usage-with-preact" rel="noopener noreferrer"&gt;Usage with&lt;/a&gt;…&lt;/li&gt;

&lt;/ul&gt;
&lt;/div&gt;
&lt;br&gt;
  &lt;/div&gt;
&lt;br&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/omgovich/react-colorful" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;br&gt;


</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>opensource</category>
    </item>
    <item>
      <title>🎨 react-colorful — 1,8 KB color picker for React. Fast, dependency-free, customizable, and accessible</title>
      <dc:creator>Vlad Shilov</dc:creator>
      <pubDate>Tue, 13 Oct 2020 08:27:09 +0000</pubDate>
      <link>https://forem.com/omgovich/react-colorful-1-8-kb-color-picker-for-react-fast-dependency-free-customizable-and-accessible-8le</link>
      <guid>https://forem.com/omgovich/react-colorful-1-8-kb-color-picker-for-react-fast-dependency-free-customizable-and-accessible-8le</guid>
      <description>&lt;h2&gt;
  
  
  📆 The Story
&lt;/h2&gt;

&lt;p&gt;Several months ago I was searching for an open-source color picker component to use in my React project.&lt;/p&gt;

&lt;p&gt;I spent a lot of time looking for a good package and noticed that the most popular React color picker, &lt;code&gt;react-color&lt;/code&gt;, is 140 KB (far larger than the entirety of &lt;code&gt;react-dom&lt;/code&gt;), is not tree-shakeable, is not accessible, does not support keyboard navigation, pulls in 11 dependencies, and is not as fast as it could be.&lt;/p&gt;

&lt;p&gt;Despite this, &lt;code&gt;react-color&lt;/code&gt; is super popular and has 1,7 million downloads weekly. One of the largest reasons for this is there were no lighter alternatives aligned with modern requirements.&lt;/p&gt;

&lt;p&gt;So we decided to create one. The primary goal was to create a modern color picker component that would be 10+ times lighter than &lt;code&gt;react-color&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/rschristian" rel="noopener noreferrer"&gt;Ryan Christian&lt;/a&gt;, &lt;a href="https://github.com/molefrog" rel="noopener noreferrer"&gt;Alex Taktarov&lt;/a&gt;, and I had been working hard since July to create the tiniest and fastest color picker for the React community.&lt;/p&gt;

&lt;h2&gt;
  
  
  🎉 That's how &lt;a href="https://omgovich.github.io/react-colorful" rel="noopener noreferrer"&gt;&lt;code&gt;react-colorful&lt;/code&gt;&lt;/a&gt; was born!
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Demo:&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://omgovich.github.io/react-colorful" rel="noopener noreferrer"&gt;https://omgovich.github.io/react-colorful&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Docs:&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://github.com/omgovich/react-colorful" rel="noopener noreferrer"&gt;https://github.com/omgovich/react-colorful&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The current version of &lt;code&gt;react-colorful&lt;/code&gt; (v4.1) is 18 times lighter than &lt;code&gt;react-color&lt;/code&gt;. &lt;strong&gt;It's just 1,8 KB!&lt;/strong&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  🗜 How is &lt;code&gt;react-colorful&lt;/code&gt; so small and fast?
&lt;/h2&gt;
&lt;h3&gt;
  
  
  1. No dependencies
&lt;/h3&gt;

&lt;p&gt;While most of the popular pickers import entire color manipulation libraries that cost more than 10 KB, &lt;code&gt;react-colorful&lt;/code&gt; ships only a minimal amount of manually optimized color conversion algorithms.&lt;/p&gt;

&lt;p&gt;For example, &lt;code&gt;react-color&lt;/code&gt; pulls in 11 dependencies including &lt;code&gt;tinycolor2&lt;/code&gt; that costs 14,4 KB and doesn't support tree-shaking at all.&lt;/p&gt;

&lt;p&gt;We have spent a lot of time making &lt;code&gt;react-colorful&lt;/code&gt; dependency-free to ensure it is the lightest of the competition. Not to mention that this thoroughly reduces the surface for vulnerability issues to arise.&lt;/p&gt;
&lt;h3&gt;
  
  
  2. No classes
&lt;/h3&gt;

&lt;p&gt;ES6 classes are good when you need to encapsulate something, but if you want to create a tiny JS library then class declarations will be one of your worst enemies. Current minifiers cannot minify ES6 class fields and member functions because they are not able to track the class when a method is called on an object.&lt;/p&gt;

&lt;p&gt;That's why &lt;code&gt;react-colorful&lt;/code&gt; is built with functions, functional components, and hooks only.&lt;/p&gt;

&lt;p&gt;It's also one of the reasons why our picker is so fast.&lt;/p&gt;
&lt;h3&gt;
  
  
  3. No polyfills and extra code transforms
&lt;/h3&gt;

&lt;p&gt;We aim to support not only modern browsers but legacy ones as well. So we have Babel configured to make our code compatible even with IE11.&lt;/p&gt;

&lt;p&gt;Writing a library using modern language features such as &lt;code&gt;async/await&lt;/code&gt; often trades end user experience for source developer experience. While these modern features may be nicer and more terse to write, they often result in much larger statements when transpiled for use in older browsers.&lt;/p&gt;

&lt;p&gt;That's why our source code is so humble in terms of modern ECMAScript features. For example, we use &lt;code&gt;Object.assign({}, color, { alpha })&lt;/code&gt; instead of &lt;code&gt;{ ...color, alpha }&lt;/code&gt;. While yes, the source uses the older and more verbose API, this results in the bundle size being ~150 bytes lighter due to the lack of the polyfill.&lt;/p&gt;
&lt;h3&gt;
  
  
  4. Manually optimized
&lt;/h3&gt;

&lt;p&gt;We have installed &lt;a href="https://github.com/ai/size-limit" rel="noopener noreferrer"&gt;size-limit&lt;/a&gt; and tried many, many different things to find the smallest (in terms of bundle size) variation for each part of the library.&lt;/p&gt;

&lt;p&gt;It's pretty hard to put into words, so I just share an example with you:&lt;/p&gt;

&lt;p&gt;We have a simple function that clamps a value between an upper and lower bound. That's the first version of this function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;clamp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;min&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;max&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;min&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nx"&gt;max&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;But after a few experiments we have replaced it with:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;clamp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;min&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;max&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;max&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;max&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;min&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;min&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Your eyes do not deceive you: we chose the option that is longer. Why? Because the minification makes the second code almost 2 times shorter. See:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;?&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;?&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  ❤️ Thanks for reading
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;react-colorful&lt;/strong&gt; cares about size, performance, and accessibility. I hope that the React community shares our values and will find it useful for further projects.&lt;/p&gt;

&lt;p&gt;It will help us a lot if you star the repo on GitHub or share the link to this article with your friends 🙏&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/omgovich" rel="noopener noreferrer"&gt;
        omgovich
      &lt;/a&gt; / &lt;a href="https://github.com/omgovich/react-colorful" rel="noopener noreferrer"&gt;
        react-colorful
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      🎨 A tiny (2,8 KB) color picker component for React and Preact apps
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;div&gt;
  &lt;a href="https://omgovich.github.io/react-colorful" rel="nofollow noopener noreferrer"&gt;
    &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fomgovich%2Freact-colorfuldemo%2Fsrc%2Fassets%2Fdesign.png" width="229" height="233" alt="react-colorful"&gt;
  &lt;/a&gt;
&lt;/div&gt;

&lt;div&gt;
  &lt;a href="https://npmjs.org/package/react-colorful" rel="nofollow noopener noreferrer"&gt;
    &lt;img alt="npm" src="https://camo.githubusercontent.com/ec5179c970397f913cb756c2763359b4e4000ccbecae8c2995cba642ba83ad7d/68747470733a2f2f696d672e736869656c64732e696f2f6e706d2f762f72656163742d636f6c6f7266756c2e7376673f6c6162656c436f6c6f723d64613234386426636f6c6f723d366561643061"&gt;
  &lt;/a&gt;
  &lt;a href="https://github.com/omgovich/react-colorful/actions" rel="noopener noreferrer"&gt;
    &lt;img alt="build" src="https://camo.githubusercontent.com/50d41da2568f7ffb10d3519513f86e8a6e080e6fcda1975b8ccda832c9f4fe5c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6f6d676f766963682f72656163742d636f6c6f7266756c2f4e6f64652e6a7325323043492f6d61737465722e7376673f6c6162656c436f6c6f723d64613234386426636f6c6f723d366561643061"&gt;
  &lt;/a&gt;
  &lt;a href="https://codecov.io/gh/omgovich/react-colorful" rel="nofollow noopener noreferrer"&gt;
    &lt;img alt="coverage" src="https://camo.githubusercontent.com/36f5f094f8ab58c29ec9c9ceba34662fd2d80d04fc5b1ce417eb0a80b44228e8/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f6f6d676f766963682f72656163742d636f6c6f7266756c2e7376673f6c6162656c436f6c6f723d64613234386426636f6c6f723d366561643061"&gt;
  &lt;/a&gt;
  &lt;a href="https://npmjs.org/package/react-colorful" rel="nofollow noopener noreferrer"&gt;
    &lt;img alt="no dependencies" src="https://camo.githubusercontent.com/a34c66c7c03a54a9bde18609ab60ebdde682e40a289b2251520d659e8314dc63/68747470733a2f2f62616467656e2e6e65742f62756e646c6570686f6269612f646570656e64656e63792d636f756e742f72656163742d636f6c6f7266756c3f6c6162656c436f6c6f723d64613234386426636f6c6f723d366561643061"&gt;
  &lt;/a&gt;
  &lt;a href="https://bundlephobia.com/result?p=react-colorful" rel="nofollow noopener noreferrer"&gt;
    &lt;img alt="tree-shakeable" src="https://camo.githubusercontent.com/57cefbfb4e12d33acb2f4e5b1340d0d6a8f02134c0605f357c5456ee8e4c1ce6/68747470733a2f2f62616467656e2e6e65742f62756e646c6570686f6269612f747265652d7368616b696e672f72656163742d636f6c6f7266756c3f6c6162656c436f6c6f723d64613234386426636f6c6f723d366561643061"&gt;
  &lt;/a&gt;
  &lt;a href="https://npmjs.org/package/react-colorful" rel="nofollow noopener noreferrer"&gt;
    &lt;img alt="types included" src="https://camo.githubusercontent.com/d0612eeffbab3a562e975b07759d858d3e2fa84ab5e2ae5ae066f5d83076adba/68747470733a2f2f62616467656e2e6e65742f6e706d2f74797065732f72656163742d636f6c6f7266756c3f6c6162656c436f6c6f723d64613234386426636f6c6f723d366561643061"&gt;
  &lt;/a&gt;
&lt;/div&gt;

&lt;div&gt;
  &lt;strong&gt;react-colorful&lt;/strong&gt; is a tiny color picker component for React and Preact apps
&lt;/div&gt;

&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Features&lt;/h2&gt;
&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;🗜 &lt;strong&gt;Small&lt;/strong&gt;: Just 2,8 KB gzipped (&lt;a href="https://github.com/omgovich/react-colorful#why-react-colorful" rel="noopener noreferrer"&gt;13x lighter&lt;/a&gt; than &lt;strong&gt;react-color&lt;/strong&gt;).&lt;/li&gt;
&lt;li&gt;🌳 &lt;strong&gt;Tree-shakeable&lt;/strong&gt;: Only the parts you use will be imported into your app's bundle.&lt;/li&gt;
&lt;li&gt;🚀 &lt;strong&gt;Fast&lt;/strong&gt;: Built with hooks and functional components only.&lt;/li&gt;
&lt;li&gt;🛡 &lt;strong&gt;Bulletproof&lt;/strong&gt;: Written in strict TypeScript and has 100% test coverage.&lt;/li&gt;
&lt;li&gt;🗂 &lt;strong&gt;Typed&lt;/strong&gt;: Ships with &lt;a href="https://github.com/omgovich/react-colorful#typescript-support" rel="noopener noreferrer"&gt;types included&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;😍 &lt;strong&gt;Simple&lt;/strong&gt;: The interface is straightforward and easy to use.&lt;/li&gt;
&lt;li&gt;👫 &lt;strong&gt;Cross-browser&lt;/strong&gt;: Works out-of-the-box for most browsers, regardless of version.&lt;/li&gt;
&lt;li&gt;📲 &lt;strong&gt;Mobile-friendly&lt;/strong&gt;: Supports mobile devices and touch screens.&lt;/li&gt;
&lt;li&gt;💬 &lt;strong&gt;Accessible&lt;/strong&gt;: Follows the &lt;a href="https://www.w3.org/WAI/standards-guidelines/aria/" rel="nofollow noopener noreferrer"&gt;WAI-ARIA&lt;/a&gt; guidelines to support users of assistive technologies.&lt;/li&gt;
&lt;li&gt;💨 &lt;strong&gt;No dependencies&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Live demos&lt;/h2&gt;
&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://omgovich.github.io/react-colorful" rel="nofollow noopener noreferrer"&gt;Website&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://codesandbox.io/s/react-colorful-demo-u5vwp" rel="nofollow noopener noreferrer"&gt;HEX Color Picker (CodeSandbox)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://codesandbox.io/s/react-colorful-rgb-o9q0t" rel="nofollow noopener noreferrer"&gt;RGBA Color Picker (CodeSandbox)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Table of Contents&lt;/h2&gt;

&lt;/div&gt;


&lt;ul&gt;

&lt;li&gt;&lt;a href="https://github.com/omgovich/react-colorful#getting-started" rel="noopener noreferrer"&gt;Getting Started&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href="https://github.com/omgovich/react-colorful#supported-color-models" rel="noopener noreferrer"&gt;Supported Color Models&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href="https://github.com/omgovich/react-colorful#customization" rel="noopener noreferrer"&gt;Customization&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href="https://github.com/omgovich/react-colorful#how-to-paste-or-type-a-color" rel="noopener noreferrer"&gt;How to paste or type a color?&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href="https://github.com/omgovich/react-colorful#code-recipes" rel="noopener noreferrer"&gt;Code Recipes&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href="https://github.com/omgovich/react-colorful#typescript-support" rel="noopener noreferrer"&gt;TypeScript Support&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;

&lt;a href="https://github.com/omgovich/react-colorful#usage-with-preact" rel="noopener noreferrer"&gt;Usage with&lt;/a&gt;…&lt;/li&gt;

&lt;/ul&gt;
&lt;/div&gt;
&lt;br&gt;
  &lt;/div&gt;
&lt;br&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/omgovich/react-colorful" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;br&gt;


</description>
      <category>showdev</category>
      <category>react</category>
      <category>javascript</category>
      <category>a11y</category>
    </item>
  </channel>
</rss>
