Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
babel-plugin-tailwind-components
Advanced tools
Use Tailwind with any CSS-in-JS library
Before you start using babel-plugin-tailwind-components you will need to ensure that you have a Tailwind config file. You can grab the default config from the Tailwind repo.
Place the config file in your project root as tailwind.js
. Alternatively you can specify a different filename in the plugin options.
There are two ways to use babel-plugin-tailwind-components. The recommended way is via babel-plugin-macros:
npm install --save-dev babel-plugin-macros tailwind.macro
Note: tailwind.macro is merely an alias for babel-plugin-tailwind-components/macro
Then add babel-plugin-macros to your babel config:
{
"plugins": ["macros"]
}
You can now use Tailwind classes with your preferred CSS-in-JS library by importing tailwind.macro
:
import styled from 'styled-components'
import tw from 'tailwind.macro'
const Button = styled('button')`
${tw`font-mono text-sm text-red hover:text-blue`};
`
Alternatively, you can use the plugin without babel-plugin-macros:
npm install --save-dev babel-plugin-tailwind-components
// .babelrc
{
"plugins": ["tailwind-components"]
}
When using this method the tw
tag is available anywhere without an explicit import:
import styled from 'styled-components'
const Button = styled('button')`
${tw`font-mono text-sm text-red hover:text-blue`};
`
The babel plugin transforms the tagged template literal into a style object:
In
const foo = tw`text-red hover:text-green sm:text-blue`
Out
const foo = {
color: '#e3342f',
':hover': {
color: '#38c172'
},
'@media (min-width: 576px)': {
color: '#3490dc'
}
}
This style object format is compatible with most CSS-in-JS libraries, including styled-components.
Some libraries such as styled-jsx do not support this format, so when used inside a <style>
element the tagged template literal is transformed into a CSS string instead:
In
<style jsx>{`
.foo {
${tw`text-red hover:text-green sm:text-blue`};
}
`}</style>
Out
<style jsx>{`
.foo {
color: #e3342f;
&:hover {
color: #38c172;
}
@media (min-width: 576px) {
color: #3490dc;
}
}
`}</style>
Note: when using hover:*
, focus:*
, or media query (e.g. sm:*
) class names the output is nested like above. You will need to use styled-jsx-plugin-postcss and postcss-nested to get this to work.
config
: path to your Tailwind config file. Defaults to "./tailwind.js"
format
: CSS output format. "object"
, "string"
, or "auto"
(default) – "auto"
will cause the output to be an object except when inside a <style>
element. See how it works for more info.
// babel-plugin-macros.config.js
module.exports = {
tailwind: {
config: './tailwind.js',
format: 'auto'
}
}
// or .babelrc
{
"plugins": [
[
"tailwind-components", {
"config": "./tailwind.js",
"format": "auto"
}
]
]
}
import styled from 'styled-components'
import tw from 'tailwind.macro'
const Button = styled('button')`
${tw`font-mono text-sm text-red hover:text-blue`};
`
import styled from 'preact-emotion'
import { css } from 'emotion'
import tw from 'tailwind.macro'
const green = css(tw`text-green`)
const Button = styled('button')`
${tw`font-mono text-sm text-red hover:text-blue`};
`
const App = () => (
<Button className={green} css={tw`uppercase`}>
hello, world
</Button>
)
Note: the css
prop requires the use of babel-plugin-emotion
import { css } from 'glamor'
import tw from 'tailwind.macro'
const style = css(tw`font-mono text-sm text-red hover:text-blue`)
const App = () => <div {...style}>hello, world</div>
import tw from 'tailwind.macro'
const App = () => (
<div>
<div className="foo">hello, world</div>
<style jsx>{`
.foo {
${tw`font-mono text-sm text-red hover:text-blue`};
}
`}</style>
</div>
)
Note: when using hover:*
, focus:*
, or media query (e.g. sm:*
) class names the output is nested. You will need to use styled-jsx-plugin-postcss and postcss-nested to get this to work.
sm:hover:*
rounded
should be an alias for rounded-default
FAQs
Use Tailwind with any CSS-in-JS library
The npm package babel-plugin-tailwind-components receives a total of 249 weekly downloads. As such, babel-plugin-tailwind-components popularity was classified as not popular.
We found that babel-plugin-tailwind-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
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.