question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom properties (a.k.a CSS Variables)

See original GitHub issue

One (relatively) popular pattern for allowing for a little bit of runtime configuration of tailwind based apps is to use css vars in conjunction with the theme config.

tailwind.config.js

module.exports = {
  theme: {
    extend: {
      colors: {
        primary: "var(--primary)",
        secondary: "var(--secondary)",
        main: "var(--main)",
        background: "var(--background)",
        header: "var(--header)",
        accent: "var(--accent)",
      },
    },
  },
};

Then, at runtime we can set those variables and allow the user to pick a primary color for example. This pattern doesn’t translate well to RN for the simple reason that we don’t have css variables. However, we do have the stylesheet, and that is injected into the TailwindProvider at runtime.

What could be interesting is to allow for a way to intercept the stylesheet before it’s injected into the TailwindProvider by babel, transform it (replace colors for example), and then pass it through to the TailwindProvider.

I think this might be possible right now using the Tailwind CLI approach, but I’d love to be able to do it using Babel too.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
marklawlorcommented, Jun 24, 2022

I’m going to close this issue and track it via the Feature Request Project.

I like to keep the repo’s issues focusing on bugs/problems.

Your welcome to still comment/ask questions. I’ll reopen the issue when development has started.

0reactions
dohomicommented, Sep 2, 2022

@winterscar how did you solve CSS Vars support with the CLI? In the output of npx tailwindcss -i global.css --postcss postcss.config.js the css vars and @media queries are not part of the output.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom properties (--*): CSS variables - MDN Web Docs
Custom properties are scoped to the element(s) they are declared on, and participate in the cascade: the value of such a custom property...
Read more >
A Complete Guide to Custom Properties | CSS-Tricks
Everything important and useful to know about CSS Custom Properties. Like that they are often referred to as “CSS Variables” but that's not ......
Read more >
How to use CSS custom properties (a.k.a. variables)
CSS variables allow an author to assign arbitrary values to a property with an author-chosen name. This custom property must start with --...
Read more >
Dynamic CSS with Custom Properties (aka CSS Variables)
Modern browsers ship with CSS Custom Properties, also known as “CSS variables”, a superpower that enables us to create reusable components ...
Read more >
CSS Custom Properties for Cascading Variables Module Level 1
This module introduces cascading variables as a new primitive value type that is accepted by all CSS properties, and custom properties for ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found