Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
babel-plugin-namespace-styled-components
Advanced tools
Keep styles generated by styled-components in their own CSS namespace
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.
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.
.bMqNs {
color: tomato;
}
.my-namespace .bMqNs {
color: tomato;
}
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.
Thanks to QuickBase’s babel-plugin-styled-components-css-namespace for inspiring this project!
FAQs
Keep styles generated by styled-components in their own CSS namespace
The npm package babel-plugin-namespace-styled-components receives a total of 0 weekly downloads. As such, babel-plugin-namespace-styled-components popularity was classified as not popular.
We found that babel-plugin-namespace-styled-components demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.