<?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 Sasha Koss on Medium]]></title>
        <description><![CDATA[Stories by Sasha Koss on Medium]]></description>
        <link>https://medium.com/@kossnocorp?source=rss-bfbde86be02a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Vul3HV5dO8uW0RI4dizP3A.jpeg</url>
            <title>Stories by Sasha Koss on Medium</title>
            <link>https://medium.com/@kossnocorp?source=rss-bfbde86be02a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 01:11:52 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kossnocorp/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[Write plain CSS while reaping the benefits of CSS-in-JS]]></title>
            <link>https://medium.com/@kossnocorp/write-plain-css-while-reaping-the-benefits-of-css-in-js-d33435d6b5ff?source=rss-bfbde86be02a------2</link>
            <guid isPermaLink="false">https://medium.com/p/d33435d6b5ff</guid>
            <category><![CDATA[preact]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[styled-components]]></category>
            <dc:creator><![CDATA[Sasha Koss]]></dc:creator>
            <pubDate>Fri, 09 Aug 2019 10:00:53 GMT</pubDate>
            <atom:updated>2019-08-09T10:00:53.835Z</atom:updated>
            <content:encoded><![CDATA[<p>Modern CSS land is divided into CSS-in-JS followers and plain CSS adherents with an ongoing controversy about which approach is superior. Despite the fight, it benefits us by advancing the ecosystem and making it more vibrant.</p><p>While plain CSS users get established tooling, simplicity, performance, and portability, the CSS-in-JS users enjoy the reliability and tight integration with the app code.</p><h3>Why don’t we have both?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tPUZR67LskNHkK0ffgpStQ.png" /></figure><p><a href="https://github.com/nyancss/nyancss">Nyan CSS</a> is a convention that allows to write good ol’ CSS and import the styles as components (React/Preact/Vue.js).</p><p><strong>Here’s how it works</strong>. First, you define CSS:</p><pre>.Header,<br>.Text {<br>  font-family: monospace;<br>}<br><br>.Header {<br>  font-size: 2rem;<br>}<br><br>.Header-size-large {<br>  font-size: 2.2rem;<br>}<br><br>.Text-italic {<br>  font-style: italic;<br>}</pre><p>Then you import it as components:</p><pre>import React from &#39;react&#39;<br>import { Header, Text } from &#39;./style.css&#39;<br><br>function Announcement() {<br>  return (<br>    &lt;&gt;<br>      &lt;Header tag=&quot;h1&quot; size=&quot;large&quot;&gt;<br>        Welcome Nyan CSS!<br>      &lt;/Header&gt;<br>      &lt;Text tag=&quot;marquee&quot; italic&gt;<br>        Please, welcome Nyan CSS!<br>      &lt;/Text&gt;<br>    &lt;/&gt;<br>  )<br>}</pre><p>And so you get:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/0*V1whm-SNJnJGSh3p.gif" /></figure><p>Essentially Nyan CSS is a convention plus family of libraries that provides tight integration with frameworks (React, Preact, Vue.js, class names). You don’t need to install anything to use Nyan CSS with HTML.</p><h3>The convention</h3><p>The convention is simplistic and consists just of three rules:</p><ol><li>.Button is a CSS class which represents a component (other examples are .ListItem , .UI , etc.) and can be used as &lt;Button&gt;Content&lt;/Button&gt;.</li><li>.Button-disabled generates a component with a boolean prop (e.g. .Button-fullWidth, .Window-inactive) and can be used as &lt;Button disabled /&gt;.</li><li>.Button-color-red represents a component with an enum prop (e.g. .Spacing-direction-column, .Window-mode-alert) and can be used as &lt;Button color=&#39;red&#39; /&gt;.</li></ol><h3>Why?</h3><h4>Universal design system</h4><p>Because Nyan CSS is just CSS, it can be used across different projects built using different technologies with no code changes. Use the same styles for a static landing page with no JS as for React SPA.</p><p>Web technologies envolve, fashion and passion changes, and just a few things remain HTML, CSS, and JS. CoffeeScript made our lives better with its legacy, but the language itself became history.</p><h4>Zero overhead</h4><p>With no runtime that manipulates CSS in a browser, Nyan CSS ensures maximum performance by reducing JavaScript build size and leaving CSS management to the browser.</p><p>I was inspired by Styled Components myself, but I was working on a widget and didn’t want to add extra 15Kb, so I created Nyan CSS that is not 5x size of <a href="https://preactjs.com/">the framework I use</a>.</p><p>You don’t need to install plugins for your editor, transpile before use or parse it anyhow. It’s just CSS.</p><h4>Battle-tested</h4><p>I incrementally improve the approach for the <a href="https://medium.com/dailyjs/js-in-css-df4cf8b9b96c">last two years</a>. I <a href="https://gist.github.com/kossnocorp/653f032f4a7cf469c982aa06c290d559">developed 6 different applications</a> (demo: <a href="https://diaryemail.com/">Diary Email</a>) using Nyan CSS and I’m confident that <strong>it just works</strong>.</p><h3>Let’s talk</h3><p>What do you think? <a href="https://github.com/nyancss/nyancss">Give it a try</a>. And then you can tell me if it’s good or not ;-)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d33435d6b5ff" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Please welcome Cultural Fit!]]></title>
            <link>https://medium.com/@kossnocorp/please-welcome-cultural-fit-f17b3644c55f?source=rss-bfbde86be02a------2</link>
            <guid isPermaLink="false">https://medium.com/p/f17b3644c55f</guid>
            <category><![CDATA[product-hunt]]></category>
            <category><![CDATA[startup]]></category>
            <category><![CDATA[corporate-culture]]></category>
            <dc:creator><![CDATA[Sasha Koss]]></dc:creator>
            <pubDate>Fri, 23 Nov 2018 13:54:02 GMT</pubDate>
            <atom:updated>2018-11-23T13:54:02.238Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U_aoiEkk_j5lJe0cy4CZcQ.png" /></figure><p>To succeed nowadays, companies must attract and keep the top talent. The best way to do so is to provide a working environment where they will be able to realize themselves maintaining a healthy work-life balance.</p><p>The days when it was enough to bring XBox to the office are long gone. Nobody buys these so-called perks that only exist to tie people to the workplaces. Top talent doesn’t care if you have ping pong in the office or if you provide free dinners. Damn, they might even prefer to not go to the office at all. They want balanced lives so that they could be productive in the workplace.</p><p>I’ve made Cultural Fit to collect corporate culture traits that matter. It’s a collaborative list that everyone can contribute to.</p><p>My goal is to demonstrate what employees care about and what they consider bullshit. I believe that it will help companies better understand prospects’ needs and build cultures that will attract the best talent like a magnet. I also hope it will spark healthy discussions about the topic and contribute to a better future</p><p>I made it as a submission for the <a href="https://blog.producthunt.com/youre-invited-to-the-product-hunt-makers-festival-a3ac1ff8250f">Product Hunt Makers Festival</a>, but I plan to support and evolve it. Besides filling it with more data, I’m going to add profiles so people would be able to showcase their favorite culture traits. I will also add an ability to create company profiles with the list of their perks.</p><p>Please feel free to <a href="https://twitter.com/kossnocorp">contact me</a> if you have any feedback and don’t hesitate to contribute to <a href="https://cultural.fit/">Cultural Fit</a>: vote for your favorites, downvote that you don’t like, leave your opinion and add more traits.</p><p>Thank you!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f17b3644c55f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to speed up the code review process and prevent pull request from piling up]]></title>
            <link>https://medium.com/@kossnocorp/how-to-speed-up-the-code-review-process-and-prevent-pull-request-from-piling-up-f6f80140ef75?source=rss-bfbde86be02a------2</link>
            <guid isPermaLink="false">https://medium.com/p/f6f80140ef75</guid>
            <category><![CDATA[agile]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Sasha Koss]]></dc:creator>
            <pubDate>Mon, 16 Oct 2017 12:29:49 GMT</pubDate>
            <atom:updated>2017-10-16T12:34:33.413Z</atom:updated>
            <content:encoded><![CDATA[<p>This week, <a href="https://twitter.com/mpjme">MPJ</a> addressed a question from one of his patrons:</p><blockquote>How to manage pull requests in a team?<br>How to maintain the pull requests pile as low as possible while keeping the team focus high?</blockquote><blockquote>From one hand you want it to be reviewed as quickly as possible from the other hand you don’t want to create too many context switches to your team members…</blockquote><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fvideoseries%3Flist%3DPL0zVEGEvSaeH21VDycWYNWU7VKUA-xLzg&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DiGBWyhiqBsk&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FiGBWyhiqBsk%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/2585f4c1f6a9853489b32ddf46633452/href">https://medium.com/media/2585f4c1f6a9853489b32ddf46633452/href</a></iframe><p><a href="https://www.atlassian.com/agile/code-reviews">Code reviews</a> are a vital practice that helps to improve code quality, prevent bugs and share knowledge, however, it also could be an annoying bottleneck. In this post, I share my experience addressing this problem.</p><h4>Is it worth it?</h4><p>Once on a retrospective, a member of the team where I was the team lead, raised a concern: “<em>pull-request reviews take time and slow down the process, maybe we should make it optional</em>?”.</p><p>You probably had this problem too: once a ticket is “done”, an engineer sends a pull-request to review and immediately switches to another ticket in the backlog. Other team members are also busy: they’re working on they own issues, so review doesn’t happen immediately. When someone finally submits a review, the pull request author is already busy on the new task, so they postpone addressing the review. In the worst case, the author will have a question to the reviewer. The reviewer is also busy or already left his workplace. The conversation takes days, pull-requests pile-up, engineers have to switch contexts back and forth which breaks the flow. So it’s valid to ask: is it really worth it?</p><h4>Limit work in progress</h4><p>Instead of agreeing on the most obvious solution I’ve proposed to introduce <a href="https://www.atlassian.com/agile/wip-limits">the work in progress limit</a>. That is a technique that limits the number of issues the team can work simultaneously. To encourage collaboration and pair programming, the limit is usually less than the number of team members. Once an engineer sent a PR they have to review open pull-requests, help someone to finish their work or ask them to review the pull-request instead of switching to another task.</p><p>Despite the doubts, it helped to make not only a habit of reviewing pull-requests but also brought pair-programming into our day-to-day lives. My team was spread across a wide range of time zones, from Brazil to Indonesia. If someone submitted a pull request at the evening, there would be a great chance that it’d be reviewed when they wake up. Another side effect of the limit in progress was shared ownership. It was a common practice to address review comments to another team member’s pull request when they were away or busy.</p><p>Once pairing became a standard practice for us, we also adopted the pair reviews technique: the pull request author creates an ad-hoc call and invites other team members to it. One of the team members shares the screen, and they read the diff all together, ask questions and raise concerns to the author. It improved the quality and dramatically speeded up the process.</p><h4>The actual problem</h4><p>So that slow code reviews highlighted a bigger problem: we didn’t collaborate and did focus on our own piece of work, not project as a whole. Once we changed the mindset the problem disappeared and we have become better as a team.</p><p>If you want to see more stuff like that, <a href="https://twitter.com/kossnocorp">follow me at Twitter</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f6f80140ef75" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Solving the Unsolvable: SVG Icons With React/Preact & Webpack]]></title>
            <link>https://medium.com/@kossnocorp/solving-the-unsolvable-svg-icons-with-react-preact-webpack-4185032f2601?source=rss-bfbde86be02a------2</link>
            <guid isPermaLink="false">https://medium.com/p/4185032f2601</guid>
            <category><![CDATA[desvg]]></category>
            <category><![CDATA[svg]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[webpack]]></category>
            <category><![CDATA[preact]]></category>
            <dc:creator><![CDATA[Sasha Koss]]></dc:creator>
            <pubDate>Mon, 24 Jul 2017 16:51:07 GMT</pubDate>
            <atom:updated>2017-07-25T07:33:54.400Z</atom:updated>
            <content:encoded><![CDATA[<p>Icons always been an issue in front-end world. Every time we think that the problem is finally solved, the industry makes another swing. Requirements and possibilities change, so yet another superior solution appears. Image sprites, fonts, SVG sprites… you name it.</p><p>Recently I’ve published stories were I’ve shown how to import <a href="https://medium.com/@kossnocorp/js-in-css-df4cf8b9b96c">CSS</a> and <a href="https://medium.com/@kossnocorp/importing-anything-as-react-preact-components-with-webpack-d00c38d92e4a">any asset</a> as React/Preact component. It inspired me to explore the topic even further and find a way efficiently yet concise import SVG as components.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k1azXwlU2QAlSmKKSiBSkg.png" /></figure><h4>🥇 Inline SVG</h4><p>At the moment, inline SVG is the best approach to icons in the web. It does not only solve the problem with HiDPI displays but unlike SVG-as-img allows to control the image with JavaScript: change colors, animate, etc. For more details about that, I recommend to watch a video by <a href="https://frontend.center/">Front End Center</a> “<a href="https://www.youtube.com/watch?v=af4ZQJ14yu8">Why Inline SVG is Best SVG</a>”.</p><h4>Loading SVG with Webpack</h4><p>The approach is quite labor-intensive as you need to insert the SVG source manually, but thankfully, with webpack, it’s as easy as import a file:</p><pre>import svgSource from ‘./image.svg’</pre><p>There are few solutions for that:</p><ul><li>Popular <a href="https://github.com/webpack-contrib/svg-inline-loader">svg-inline-loader</a> maintained by the webpack team.</li><li>Unheard <a href="https://github.com/dolbyzerr/svg-loader">svg-loader</a> built by my friend (who just got married, congratulations, Andrei!).</li></ul><p>I’ve decided to stick to the latter as I already had experience with it and also due to the fact that it’s built with dangerouslySetInnerHTML in mind, so the exported object doesn’t contain the root svg element.</p><h4>The Dilemma</h4><p>Initially, I’ve simply wrapped imported SVGs into a component and passed the icon name as a prop, but the solution has an obvious downside: the build size grows with the number of icons regardless of whether you use them all or not:</p><pre>import Icon from &#39;app/UI/_lib/Icon&#39;</pre><pre>&lt;Icon type=&#39;danger&#39; size=&#39;big&#39; color=&#39;small&#39; /&gt;</pre><p>For instance Font Awesome 5 SVG collection weights 6.3 Mb that is clearly not an option.</p><p>The solution for that is to import the component and icon file separately and combine them manually:</p><pre>import Icon from &#39;app/UI/_lib/Icon&#39;<br>import dangerIcon from &#39;app/UI/_lib/danger.svg&#39;</pre><pre>&lt;Icon source={dangerIcon} size=&#39;big&#39; color=&#39;small&#39; /&gt;</pre><p>Some would end the story right here, but not me. We can do better!</p><h4>Importing SVG as React/Preact Component</h4><p>To achieve my goal, first I’ve built <a href="https://github.com/kossnocorp/desvg">a loader that converts SVGs to React/Preact components</a>:</p><pre>import DangerIcon from &#39;app/UI/_lib/danger.svg&#39;</pre><pre>&lt;DangerIcon fill=&#39;#f00&#39; width=&#39;1rem&#39; /&gt;</pre><h4>Wrapping Icons Into HoC</h4><p>In the real world, the icon would have more props (e.g. style — light/regular/solid), and as we want to not repeat ourselves and keep UI consistent, we have to limit the color and size to the predefined set.</p><p>The solution for that would be <a href="https://facebook.github.io/react/docs/higher-order-components.html">a high-order component</a>, that returns us back to the initial solution 🤦‍:</p><pre>import Icon from &#39;app/UI/_lib/Icon&#39;<br>import DangerIcon from &#39;app/UI/_lib/danger.svg&#39;</pre><pre>&lt;Icon component={DangerIcon} size=&#39;big&#39; color=&#39;red&#39; /&gt;</pre><p>I started to wonder, what if we can automate it using the power of webpack loaders? After a while, I found a way and built <a href="https://github.com/kossnocorp/hoc-loader">hoc-loader</a> that allowed me to ditch the glue code:</p><pre>import DangerIcon from &#39;app/UI/_lib/danger.svg&#39;</pre><pre>&lt;DangerIcon size=&#39;big&#39; color=&#39;red&#39; /&gt;<br>//=&gt; &lt;svg fill=&#39;#f00&#39; width=&#39;1rem&#39;&gt;...&lt;/svg&gt;</pre><p>Here is sample configuration that I’ve extracted from my project:</p><pre>const iconsPath = path.resolve(process.cwd(), &#39;app/UI/_lib/Icon&#39;)<br>...<br>{<br>  test: /\.svg$/,<br>  use: [<br>    {<br>      loader: &#39;hoc&#39;,<br>      options: {<br>        useDefault: true,<br>        path: path.join(iconsPath, &#39;index.jsx&#39;) // 👈 Path to HoC<br>      }<br>    },<br>    &#39;desvg/react&#39;, // 👈 Convert SVG to components<br>    &#39;svg&#39;<br>  ],<br>  include: iconsPath<br>},<br>...</pre><p>And finally, the HoC:</p><pre>import React from &#39;react&#39;<br>import classNames from &#39;classnames&#39;</pre><pre>export default function (Svg) {<br>  return function Icon ({<br>    size = &#39;medium&#39;,<br>    color = &#39;black&#39;,<br>    style = &#39;solid&#39;<br>  }) {<br>    return (<br>      &lt;div<br>        className={classNames(<br>          &#39;Icon&#39;,<br>          `is-${size}`,<br>          `is-${color}`,<br>          `is-${style}`<br>        )}<br>      &gt;<br>        &lt;Svg fill=&#39;currentColor&#39; /&gt;<br>      &lt;/div&gt;<br>    )<br>  }<br>}</pre><p>This way I’ve got simple and concise way to deal with icons that allow to make the build as small as possible and keep code clean and tidy.</p><p>For more info about usage and configuration see <a href="https://github.com/kossnocorp/desvg">desvg</a> and <a href="https://github.com/kossnocorp/hoc-loader">hoc-loader</a> READMEs.</p><p>If you have any questions or need help, don’t hesitate to reach me!</p><h4>Thank You for Reading!</h4><p><em>If you like the story, please recommend it, it means a lot to me!</em></p><p><em>If you like the libraries, </em><a href="https://github.com/kossnocorp/desvg"><em>please star it</em></a><em>.</em></p><p><em>And finally, if you want to see more stories like that, </em><a href="https://twitter.com/kossnocorp"><em>follow me at Twitter</em></a><em> and </em><a href="https://medium.com/@kossnocorp"><em>Medium</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4185032f2601" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Importing anything as React/Preact components with webpack]]></title>
            <link>https://medium.com/@kossnocorp/importing-anything-as-react-preact-components-with-webpack-d00c38d92e4a?source=rss-bfbde86be02a------2</link>
            <guid isPermaLink="false">https://medium.com/p/d00c38d92e4a</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[defile]]></category>
            <category><![CDATA[webpack]]></category>
            <category><![CDATA[preact]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Sasha Koss]]></dc:creator>
            <pubDate>Wed, 19 Jul 2017 16:00:19 GMT</pubDate>
            <atom:updated>2017-07-19T16:30:30.636Z</atom:updated>
            <content:encoded><![CDATA[<p><em>In this short story, I’ll demonstrate how to import assets (images, videos, etc.) as React/Preact components and make your code clean and neat.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AaFoeG7N61CRMHHabD5Jyw.png" /></figure><p>In <a href="https://medium.com/@kossnocorp/js-in-css-df4cf8b9b96c">my previous story</a>, I was importing CSS as components. After using <a href="https://github.com/kossnocorp/decss">decss</a> for a while, I’ve realized that the underlying concept is applicable not only to CSS but any assets!</p><p>This idea inspired me, so I’ve built <a href="https://github.com/kossnocorp/defile"><strong>defile</strong></a>. It might look like magic, but in fact, the <a href="https://github.com/kossnocorp/defile-loader/blob/master/preact.js">implementation is trivial</a>. It simply wraps the output of <a href="https://github.com/webpack-contrib/file-loader">file-loader</a> into a component constructor. Despite the simplicity, it allows making the code more expressive and neat.</p><p>By default, <a href="https://github.com/kossnocorp/defile-loader">defile-loader</a> generates a link component with predefined href prop:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hD6MUZmU5VPeuq4yh3tj9A.png" /></figure><p>defile allows to redefine the tag and the prop name so that you can import images as img components (loader: &#39;defile/react?tag=img&amp;prop=src!file&#39;):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*alKvLEBb4cbrQ7P4OTD2SA.png" /></figure><p>It also allows to redefine the default props so that you can set the meaningful defaults (loader: &#39;defile/react?{tag: &quot;kind&quot;, prop: &quot;src&quot;, defaultProps: {kind: &quot;subtitles&quot;}}!file&#39;):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1_aYtZI_Qq6THDIra2Ks3A.png" /></figure><p>If you want to give it a try, see <a href="https://github.com/kossnocorp/defile#readme">defile docs</a>.</p><p>If you like it, star the <a href="https://github.com/kossnocorp/defile">repo</a> and share the post and also <a href="https://twitter.com/kossnocorp">follow me on Twitter</a>.</p><p>Thank you for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d00c38d92e4a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Importing CSS as React/Preact components with webpack and unicorns]]></title>
            <link>https://medium.com/dailyjs/js-in-css-df4cf8b9b96c?source=rss-bfbde86be02a------2</link>
            <guid isPermaLink="false">https://medium.com/p/df4cf8b9b96c</guid>
            <category><![CDATA[decss]]></category>
            <category><![CDATA[styled-components]]></category>
            <category><![CDATA[webpack]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Sasha Koss]]></dc:creator>
            <pubDate>Tue, 11 Jul 2017 12:54:36 GMT</pubDate>
            <atom:updated>2019-08-08T12:28:00.825Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cU24xnt7_lDbdIgvU62U3Q.png" /></figure><h3>🦄 Keep It Simple, Stupid!</h3><p>I’m building an app that is supposed to be embedded on 3rd party websites and for such kind of applications the build size is very important.</p><p>I was amused by <a href="https://www.styled-components.com/">styled-components</a> and had wanted to give it a try for a long time, but I found that it requires a 12kB runtime, which is 4x more than size of the <a href="https://preactjs.com/">framework I use</a>! Any other CSS-in-JS solution also has an unavoidable overhead, so I decided to stay lean and use plain CSS.</p><p>I’ve opted to use <a href="https://github.com/css-modules/css-modules">CSS Modules</a>, which came with <a href="https://github.com/alexkuz/create-preact-app">create-preact-app</a>. The approach solves many classic CSS problems but has practically no footprint. With rich <a href="http://postcss.org/">PostCSS</a> ecosystem, you can write modern CSS, with variables, nested selectors, extend and <a href="http://cssnext.io/features/">many more great features</a>, so it’s a pleasure to use it nowadays.</p><h3>🦄 Don’t Repeat Yourself?</h3><p>After a few days I’ve found that I am repeating myself writing the same glue code again and again:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pp7H2i31DaAOWoegGEqDvw.png" /><figcaption>It’s the same enum and boolean props processing code all over the codebase!</figcaption></figure><p>I’ve realized that I had been writing such components for years! At the first glance, those have a value. They map props to class names, and also wrap children in divs. But at the end, they all look the same.</p><p>Also, I recall a lot of dummy components with the only purpose to wrap children within a div with a particular className.</p><p>The problem is that it’s not easy to refactor those, so the best you can do is to let them be.</p><h3>🦄 Convention Over Configuration!</h3><p>Ruby on Rails taught me that <a href="https://en.wikipedia.org/wiki/Convention_over_configuration">convention over configuration</a> efficiently ditches tons of glue code. So I thought if I can come up with a convention similar to <a href="https://en.bem.info/">BEM</a> which would allow to define boolean and enum props so I can stop writing such code and automate its generation instead!</p><p>After a few iterations <a href="https://github.com/kossnocorp/decss">I’ve come up with a short list of rules</a>:</p><ol><li><strong>.Button</strong> is a CSS class which represents a <strong>component</strong> (other examples are .ListItem , .UI , etc.) and can be used as &lt;Button&gt;Content&lt;/Button&gt; .</li><li><strong>.Button-disabled</strong> generates a component with a <strong>boolean prop</strong> (e.g. .Button-fullWidth, .Window-inactive ) and can be used as &lt;Button disabled /&gt; .</li><li><strong>.Button-color-red</strong> represents a component with an <strong>enum prop</strong> (e.g. .Spacing-direction-column, .Window-mode-alert ) and can be used as &lt;Button color=&#39;red&#39; /&gt; .</li></ol><p>As it turns out, boolean and enum props cover most of the props use-cases for styling purposes. Having just 2 types inspired me to simplify my code and replace many components with plain styles.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G8NpGH51-iaSUX3Xddl1YQ.png" /></figure><h3>Nyan CSS</h3><p>I’ve open-sourced the runtime that parses CSS Modules output and builds React or Preact components and the webpack loader that allows importing components right from CSS files, so grab while it’s 🔥: <a href="https://github.com/kossnocorp/decss">https://github.com/</a>nyancss/nyancss</p><p>I don’t want to claim that this is a superior CSS solution in any sense. There are <a href="https://medium.com/@tkh44/emotion-ad1c45c6d28b">too</a> <a href="https://m.alphasights.com/css-evolution-from-css-sass-bem-css-modules-to-styled-components-d4c1da3a659b">many</a> <a href="https://hackernoon.com/introducing-glamorous-fb3c9f4ed20e">fantastic</a> CSS-in-JS libraries that push the boundaries of what’s possible with CSS, although I believe that Nyan CSS <a href="https://medium.com/@gajus/stop-using-css-in-javascript-for-web-development-fa32fb873dcc">may be relevant</a> in some cases and it’s up to the engineers to make a choice.</p><p>If you want to give it a try, see Nyan CSS<a href="https://github.com/kossnocorp/decss"> docs</a>.</p><p>If you like it, star the <a href="https://github.com/kossnocorp/decss">repo</a> and share the post and also <a href="https://twitter.com/kossnocorp">follow me on Twitter</a>.</p><p><em>Thank you for reading!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=df4cf8b9b96c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/dailyjs/js-in-css-df4cf8b9b96c">Importing CSS as React/Preact components with webpack and unicorns</a> was originally published in <a href="https://medium.com/dailyjs">DailyJS</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>