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.

Add support for CSS Modules

See original GitHub issue

Proposal

I would like to propose support for CSS modules using the solution from reactstrap.

Meaning for Product

We are building a snippet, which can be integrated into any arbitrary website. This has often resulted in the css of the snippet overriding that of the enclosing site or vice versa. A solution for this would be support for CSS modules.

Solution and code

This could be done by globally setting the CSS Modules as follows:

let globalCssModule;

export function setGlobalCssModule(cssModule) {
  globalCssModule = cssModule;
}

We could optionally not set the CSS Module globally but rather make it an optional property in the components.

This globalCSSModule could then be used to update the Component classNames with the following function:

export function mapToCssModules(className = '', cssModule = globalCssModule) {
  if (!cssModule) return className;
  return className
    .split(' ')
    .map(c => cssModule[c] || c)
    .join(' ');
}

All of these methods were lifted off the reactstrap library. Sources:

Implementation

I am ready to create a pull request with the proposed implementation.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ericgiocommented, Jan 24, 2019

Hi @rawroland and thanks for the detailed proposal. I haven’t used CSS modules extensively, so I’m not totally sure how they’d integrate with this project and what implications that would have more broadly for consumers of the library. For example, would things continue to work correctly for those using the UMD builds or not using modules in their own projects? I understand that style conflicts can be a problem, though I’ve tried to address that by scoping the styles to the component. Can you explain more about the specific issues you’re running into?

0reactions
rawrolandcommented, May 25, 2020

@ericgio Sorry for not responding for so long. It is ok to close the issue, since we found a workaround for our problem which really does not belong in the base package. Looking forward to using a new version of the package.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Adding a CSS Modules Stylesheet - Create React App
This project supports CSS Modules alongside regular stylesheets using the [name].module.css file naming convention. CSS Modules allows the ...
Read more >
Basic Features: Built-in CSS Support - Next.js
Next.js supports including CSS files as Global CSS or CSS Modules, using `styled-jsx` for CSS-in-JS, or any other CSS-in-JS solution! Learn more here....
Read more >
Documentation about css-modules - GitHub
A CSS Module is a CSS file in which all class names and animation names are scoped locally by default. All URLs (...
Read more >
What are CSS Modules and why do we need them?
According to the repo, CSS modules are: CSS files in which all class names and animation names are scoped locally by default. So...
Read more >
A deep dive into CSS Module - LogRocket Blog
Next, we'll add CSS module support for our app by simply renaming the App.css file to App.module.css . Update the import statement in...
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