<?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: Juan David García Rincón</title>
    <description>The latest articles on DEV Community by Juan David García Rincón (@juandagarcia).</description>
    <link>https://dev.to/juandagarcia</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F591665%2F0ec7fb29-4cad-42e2-b4d1-c1e95a0ca8e1.png</url>
      <title>DEV Community: Juan David García Rincón</title>
      <link>https://dev.to/juandagarcia</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/juandagarcia"/>
    <language>en</language>
    <item>
      <title>I shipped a themeable component. It ignored every theme.</title>
      <dc:creator>Juan David García Rincón</dc:creator>
      <pubDate>Mon, 28 Sep 2026 21:35:21 +0000</pubDate>
      <link>https://dev.to/juandagarcia/i-shipped-a-themeable-component-it-ignored-every-theme-5doh</link>
      <guid>https://dev.to/juandagarcia/i-shipped-a-themeable-component-it-ignored-every-theme-5doh</guid>
      <description>&lt;p&gt;I spent a while building a credit card component with what I thought was a clean theming story: a handful of CSS custom properties, documented, override whatever you like.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.crd&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;--crd-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;340px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;--crd-bg&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;linear-gradient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;135deg&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;#111&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;#333&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;Then I actually tested it from the outside, the way a consumer would. Three separate bugs, none of which produced an error, all of which ended the same way: &lt;strong&gt;the library quietly won and the user's value did nothing.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Every one comes from a cascade rule that's easy to forget. If you publish components, you probably have at least one of these.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. A declared value always beats an inherited one
&lt;/h2&gt;

&lt;p&gt;The intent was that you could set a knob anywhere above the card and it would inherit down:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.checkout&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="py"&gt;--crd-bg&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;rebeccapurple&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;Nothing happened.&lt;/p&gt;

&lt;p&gt;Custom properties do inherit — that part is true. But inheritance only fills in where the element &lt;strong&gt;declares nothing itself&lt;/strong&gt;. My stylesheet declared &lt;code&gt;--crd-bg&lt;/code&gt; right on &lt;code&gt;.crd&lt;/code&gt;, so the card's own value shadowed anything coming from above. The ancestor was setting a variable that the card immediately overwrote with its default.&lt;/p&gt;

&lt;p&gt;I confirmed it by reading the computed value on both elements:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Where &lt;code&gt;--crd-bg: red&lt;/code&gt; was set&lt;/th&gt;
&lt;th&gt;What the card resolved to&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;on an ancestor&lt;/td&gt;
&lt;td&gt;the library's gradient ❌&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;on &lt;code&gt;.crd&lt;/code&gt; itself&lt;/td&gt;
&lt;td&gt;red ✅&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The docs said "on &lt;code&gt;.crd&lt;/code&gt; or any ancestor". Half of that sentence was fiction, and it had been fiction since the first release.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Unlayered CSS beats &lt;code&gt;@layer&lt;/code&gt;, whatever the specificity
&lt;/h2&gt;

&lt;p&gt;The same design was supposed to make Tailwind work for free. Every knob is a custom property, so an arbitrary-property utility should just set it:&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="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Card&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"[--crd-radius:1.25rem] [--crd-bg:var(--color-indigo-600)]"&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It didn't. Not "sometimes" — never.&lt;/p&gt;

&lt;p&gt;Tailwind v4 emits its utilities inside &lt;code&gt;@layer utilities&lt;/code&gt;. My stylesheet was unlayered. And in the cascade, &lt;strong&gt;layer order is compared before specificity&lt;/strong&gt;, with unlayered normal declarations treated as the highest-priority layer. So a plain &lt;code&gt;.crd { … }&lt;/code&gt; outranks every utility Tailwind can generate, no matter how specific the utility looks.&lt;/p&gt;

&lt;p&gt;Tested against real Tailwind (v4.3.3), not from memory:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Utility on the card&lt;/th&gt;
&lt;th&gt;Result&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;[--crd-bg:…]&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;library gradient wins ❌&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;[--crd-radius:1.25rem]&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;stays &lt;code&gt;14px&lt;/code&gt; ❌&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;This one is nastier than the first, because &lt;code&gt;!important&lt;/code&gt; and higher specificity don't help. Layers sit above both.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Your &lt;code&gt;className&lt;/code&gt; may not be reaching the element you think
&lt;/h2&gt;

&lt;p&gt;Then a third one, and this is the one I'd bet is most common.&lt;/p&gt;

&lt;p&gt;The React wrapper rendered a container div and mounted the card inside it:&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;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;containerRef&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Reasonable-looking. But the card is the &lt;em&gt;child&lt;/em&gt; of that div, so &lt;code&gt;className&lt;/code&gt; landed on the wrapper — and thanks to bug #1, a custom property on the wrapper never reached the card anyway. Two bugs stacking into one silent failure.&lt;/p&gt;

&lt;p&gt;Measured on a real rendered component:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Where the class went&lt;/th&gt;
&lt;th&gt;Card's &lt;code&gt;--crd-radius&lt;/code&gt;
&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;the mount container (what &lt;code&gt;className&lt;/code&gt; did)&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;14px&lt;/code&gt; ❌&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;the card element itself&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;99px&lt;/code&gt; ✅&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Worth checking in your own library: &lt;code&gt;className&lt;/code&gt; landing on a wrapper instead of the component root is invisible until someone tries to theme through it. Every mainstream library — Mantine, HeroUI, Radix — puts it on the root, and users assume that.&lt;/p&gt;

&lt;h2&gt;
  
  
  The fix: never declare, always fall back
&lt;/h2&gt;

&lt;p&gt;The repair for the first two is one idea. &lt;strong&gt;Don't declare your knobs anywhere.&lt;/strong&gt; Read them, and put the default in the &lt;code&gt;var()&lt;/code&gt; fallback at the point of use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="c"&gt;/* before — the default is a declaration, so it shadows everything */&lt;/span&gt;
&lt;span class="nc"&gt;.crd&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="py"&gt;--crd-bg&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;linear-gradient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;…&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;.crd__front&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--crd-bg&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;/* after — the default is a fallback, so any value the user sets wins */&lt;/span&gt;
&lt;span class="nc"&gt;.crd__front&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--crd-bg&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;linear-gradient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&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;p&gt;Now a value set on an ancestor, by a utility class, or inline all reach the card, because the card no longer declares anything to shadow them.&lt;/p&gt;

&lt;p&gt;There's a wrinkle if you ship themes of your own. My per-brand styles also set &lt;code&gt;--crd-bg&lt;/code&gt;, which would recreate the same shadowing. So the themes feed a &lt;em&gt;private&lt;/em&gt; slot instead, and the public knob outranks it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.crd--brand-visa&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="py"&gt;--_crd-bg-theme&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;linear-gradient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;…&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;.crd__front&lt;/span&gt;      &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--crd-bg&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--_crd-bg-theme&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="err"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;default&lt;/span&gt;&lt;span class="err"&gt;&amp;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;p&gt;Read outward-in: the user's value, else the brand theme, else the base default.&lt;/p&gt;

&lt;p&gt;For the third bug the fix is just as small — merge &lt;code&gt;className&lt;/code&gt; into the classes applied to the component's root element rather than putting it on the mount container.&lt;/p&gt;

&lt;p&gt;The result is that Tailwind now works with no plugin, no config, and no cascade layer:&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="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Card&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"[--crd-radius:1.25rem] [--crd-bg:var(--color-indigo-600)]"&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The one case that still needs a layer
&lt;/h2&gt;

&lt;p&gt;Being precise, because this took me a while to separate: the fallback trick fixes &lt;strong&gt;custom properties&lt;/strong&gt;. It does nothing for regular ones.&lt;/p&gt;

&lt;p&gt;If a user writes &lt;code&gt;text-2xl&lt;/code&gt; on a slot and your stylesheet sets &lt;code&gt;font-size&lt;/code&gt; on that slot, you're back to unlayered-beats-layered and the library still wins. The only real fix there is to ship your CSS wrapped in a cascade layer the consumer can order:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="k"&gt;@layer&lt;/span&gt; &lt;span class="n"&gt;crd-ui&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;theme&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;base&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;components&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;utilities&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Mantine does this (&lt;code&gt;styles.layer.css&lt;/code&gt;), PrimeReact has a &lt;code&gt;cssLayer&lt;/code&gt; option. I copied the pattern — a second stylesheet entry point, wrapped, so the consumer opts in.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I was building
&lt;/h2&gt;

&lt;p&gt;All of this came out of &lt;a href="https://github.com/JuandaGarcia/crd-ui" rel="noopener noreferrer"&gt;crd-ui&lt;/a&gt; — a credit and debit card component for payment forms and saved-card views. Live brand detection, formatting, a flip when the CVC is focused, and a display layout for cards a user already owns. Zero runtime dependencies, MIT, and the same component ships for React, Vue, Svelte and vanilla JS from one package.&lt;/p&gt;

&lt;p&gt;It's display-only on purpose: it never handles real card data, so it composes with providers that keep the number inside their own iframes.&lt;/p&gt;

&lt;p&gt;If you're on &lt;code&gt;react-credit-cards&lt;/code&gt; — unmaintained since 2020 — the prop names line up closely enough that migrating is mostly the import and the stylesheet. There's a &lt;a href="https://crd-ui.juanda.co/migrate/react-credit-cards/" rel="noopener noreferrer"&gt;prop-by-prop guide&lt;/a&gt;, including the two props that genuinely don't map.&lt;/p&gt;

&lt;p&gt;Mostly, though: go check whether your own component actually honours the theme someone sets on it. Mine didn't, for three releases, and nothing ever threw an error.&lt;/p&gt;

</description>
      <category>css</category>
      <category>webdev</category>
      <category>javascript</category>
      <category>frontend</category>
    </item>
  </channel>
</rss>
