Gathering detailed insights and metrics for @quickbaseoss/babel-plugin-styled-components-css-namespace
Gathering detailed insights and metrics for @quickbaseoss/babel-plugin-styled-components-css-namespace
Gathering detailed insights and metrics for @quickbaseoss/babel-plugin-styled-components-css-namespace
Gathering detailed insights and metrics for @quickbaseoss/babel-plugin-styled-components-css-namespace
styled-jsx
Full CSS support for JSX without compromises
babel-plugin-styled-components
Improve the debugging experience and add server-side rendering support to styled-components
@emotion/babel-plugin
A recommended babel preprocessing plugin for emotion, The Next Generation of CSS-in-JS.
@babel/plugin-transform-export-namespace-from
Compile export namespace to ES2015
npm install @quickbaseoss/babel-plugin-styled-components-css-namespace
57
Supply Chain
88.2
Quality
74.6
Maintenance
50
Vulnerability
99.6
License
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
118 Stars
58 Commits
32 Forks
28 Watching
17 Branches
14 Contributors
Updated on 04 Jul 2024
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
10.3%
962
Compared to previous day
Last week
4.3%
5,477
Compared to previous week
Last month
-4.1%
22,445
Compared to previous month
Last year
2.4%
508,422
Compared to previous year
6
yarn add @quickbaseoss/babel-plugin-styled-components-css-namespace
or npm install @quickbaseoss/babel-plugin-styled-components-css-namespace
1"babel": { 2 "plugins": [ 3 "@quickbaseoss/babel-plugin-styled-components-css-namespace" 4 ] 5}
If you are also using babel-plugin-styled-components, you must place styled-components-css-namespace
before babel-plugin-styled-components
.
1"babel": { 2 "plugins": [ 3 "@quickbaseoss/babel-plugin-styled-components-css-namespace", 4 "babel-plugin-styled-components" 5 ] 6}
Without adding options, this plugin will duplicate the class name generated by styled-components
as suggested in this issue.
1/* output */ 2.c0.c0 { 3 background-color: blue; 4}
A common scenario when integrating styled-components into existing projects is fighting against extremely specific legacy CSS selectors such as #someId .grossly .nested section input {/* styles */}
.
To increase the specificity that this plugin adds, you can leverage the recommended approach from the styled-components docs. Add the appropriate number of &
selectors equal to the desired selector duplication as the cssNamespace
option (the default behavior is x2 {"cssNamespace": "&&"}
).
1{ 2 "plugins": [ 3 [ 4 "@quickbaseoss/babel-plugin-styled-components-css-namespace", 5 {"cssNamespace": "&&&"} 6 ], 7 "babel-plugin-styled-components" 8 ] 9}
1/* output */ 2.c0.c0.c0 { 3 background-color: blue; 4}
You can provide a cssNamespace
to use instead of duplicating the class name. Remember to include a DOM element with that class that wraps the styled-component. The cssNamespace
takes the form of the selector you want to use to wrap all of your styles with.
1"babel": { 2 "plugins": [ 3 ["@quickbaseoss/babel-plugin-styled-components-css-namespace", {"cssNamespace": ".specific .moreSpecific .reallySpecific"}], 4 "styled-components" 5 ] 6}
1/* output */ 2.specific .moreSpecific .reallySpecific .c0 { 3 background-color: blue; 4}
where .c0 is the class added by styled-components to the element
While an uncommon use-case, it can often be useful to interpolate media query at-rules in your css
template string. Compared to the method for creating media queries from the
styled-component docs, this
method reduces the overhead of multiple calls of css
while still allowing queries to be
constructed without requiring nested template literals.
1const mediaQuery = '@media only screen and (min-width: 426px)' 2 3const StyledComponent = styled.div` 4 background-color: red; 5 ${mediaQuery} { 6 background-color: blue; 7 } 8`
Unfortunately, this syntax is identical to the syntax used to refer to other components and this
plugin cannot distinguish between the two and will produce broken CSS rules. Since referring to
other components is more common, the below method of formatting @media
inline can be
used as a workaround.
1const mediaQuery = 'only screen and (min-width: 426px)'; 2 3const StyledComponent = styled.div` 4 background-color: red; 5 @media ${mediaQuery} { 6 background-color: blue; 7 } 8`;
Note that rawCssNamespace
was dropped in favor of the single cssNamespace
option. Additionally, support for an array of selectors was dropped as well. Update any references to rawCssNamespace
with cssNamespace
.
If you were already using cssNamespace
, update your configuration to use a css selector rather than an array of classes. E.g., cssNamespace: 'moreSpecific'
should be cssNamespace: '.moreSpecific'
and cssNamespace: ['specific', 'verySpecific']
should be cssNamespace: '.specific .verySpecific'
.
styled-components is an awesome library for css-in-js and feels like a natural combination of React and CSS. It is easy to use and produces css instead of inline styles.
However, if you are trying to gradually introduce styled-components into a legacy website that might not have the best CSS, the legacy styles may bleed into your styled-components because they have more specificity than the single class styled-components.
This plugin will automatically add additional css namespaces or duplicated classes to the selectors produced by styled components effectively creating a wall between the legacy css code and your new shiny styled components.
This plugin was built for Styled Components; however, since initially creating it, we at Quick Base have switched to Emotion. It works as an alternative to the stylis extra scope plugin which requires creating your own instance of stylis.
git clone https://github.com/QuickBase/babel-plugin-styled-components-css-namespace.git
yarn install
(prefer yarn
although npm
should work as well)yarn test
to run the testsWhen we are ready to release a new version, one of the admins needs to run the following commands to publish the new version to npm. We probably need to invest in a better deploy and semver management system. Interested? See this issue.
git tag -a {version} {commit_hash}
. For example: git tag -a 0.0.9 abf3123
git push --follow-tags
Open source software is a group effort. This version of the plugin was heavily inspired by a fork of the original plugin from @TrevorBurnham.
We also would like to thank some of our contributors who helped solve some tough issues with the previous iteration of this plugin:
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 23/28 approved changesets -- score normalized to 8
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
55 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More