New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-namespace-styled-components

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-namespace-styled-components

Keep styles generated by styled-components in their own CSS namespace

  • 0.4.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

babel-plugin-namespace-styled-components

Use a namespace to increase the CSS specificity of your styled-components, preventing them from being overwritten by overly broad rules from the page’s stylesheets.

Usage

Add the plugin to your Babel configuration before the styled-components plugin, and specify a CSS selector as its namespace:

"plugins": [
  [
    "babel-plugin-namespace-styled-components",
    { "namespace": ".my-namespace" }
  ],
  "styled-components
]

Then render your app’s content within that namespace:

MyApp = () => <div className="my-namespace">{appContent}</div>;

Now all styled() blocks will emit selectors that use that namespace.

Before

.bMqNs {
  color: tomato;
}

After

.my-namespace .bMqNs {
  color: tomato;
}

Compatibility with mixins

If you use multiple ampersands (&&) in a selector in a mixin (that is, a style block inserted into a styled() template with ${}), that selector will not match anything. This is a fundamental problem with namespacing at build time: styled-components resolves & to

.namespace .c0

which means that && will resolve to

.namespace .c0.namespace .c0

When the plugin detects an invalid selector like this in a styled-components css() block, it’ll throw an error at build time. Be careful to wrap mixins in css() rather than using raw strings, which are ignored by the plugin and therefore potentially unsafe.

Acknowledgments

Thanks to QuickBase’s babel-plugin-styled-components-css-namespace for inspiring this project!

Keywords

FAQs

Package last updated on 27 May 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc