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.

I am really excited about this project. One thing I haven’t wrapped my head around is how one could use these values to create “theme-able” components. Let’s say there are some variables that allow customization of a component - things like colors and fonts. Since the component’s css module has to import its values from some concrete file, I see no way how one could switch between two css files defining different values.

One could create two css modules that differ only in values, but then I would have to duplicate all the rules.

Basically, I wonder what would be the counterpart of the following SASS code:

// component.scss
.my-component {
   background-color: $my-component-background-color;
}

// theme-a.scss
$my-component-background-color: green;
@import "my-component"

// theme-b.scss
$my-component-background-color: red;
@import "my-component"

Or is this simply something css module values are not supposed to solve?

Issue Analytics

  • State:open
  • Created 8 years ago
  • Reactions:8
  • Comments:34 (18 by maintainers)

github_iconTop GitHub Comments

4reactions
markdalgleishcommented, Nov 10, 2015

I’m thinking that variables could become another first class, local-by-default feature of CSS Modules.

Values do a good job of allowing you to be explicit about variable dependencies between modules, but it certainly doesn’t enforce it. I really like the guarantees that locally scoped classes and animations currently provide, and I think that variables are another candidate for this.

I propose that the following:

:root { --color-primary: blue; }

…would be compiled to this:

:root { --HASH: blue; }

Then if you want to override this variable, you explicitly need to import it. Importing and overriding a variable could look something like this, perhaps:

@value --color-primary from './variables.css`;

.table { --color-primary: green; }

Which, of course, is also compiled into this:

.table { --HASH: green; }

Thoughts?

2reactions
andywercommented, Apr 9, 2016

Hey there! Even though that issue seems to approach its end of life… I just published a plugin to address this problem: https://github.com/andywer/postcss-theme

Maybe that’s some help for you, @SpencerCDixon?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Use themes - Knowledge Base - HubSpot
A theme is a set of templates, modules, global content, and style settings that can be used to create a website. Themes can...
Read more >
Using Themes
A WordPress Theme is a collection of files that work together to produce a graphical interface with an underlying unifying design for a...
Read more >
Theme Definition & Meaning
The meaning of THEME is a subject or topic of discourse or of artistic representation. How to use theme in a sentence.
Read more >
How to use themes on WordPress.com - YouTube
Welcome to WordPress.com! In this video, Mike Bal will discuss thow to use different themes on WordPress.com.Need more help?
Read more >
What Are WordPress Themes - And How To Use Them?
One of the many reasons WordPress is so popular is the vast array of different themes you can choose for your site. But...
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