Use Tailwind in React Native
// In
import tw from '@ecreeth/tw.macro'
const buttonStyles = tw`bg-transparent text-sm text-blue-500`
// Out
const buttonStyles = {
backgroundColor: 'transparent',
fontSize: 14,
color: '#4299e1'
}
npm install -D @ecreeth/tw.macro babel-plugin-macros
# or
yarn add @ecreeth/tw.macro babel-plugin-macros -D
Enable Babel macros by adding "macros" to the plugin configuration:
{
"plugins": ["macros"]
}
You can customize the default styles and even add your own. There are two ways to do:
"babelMacros": {
"tailwind": {
"file": "./my_personal_styles.json"
}
},
{
"bg-black": {
"backgroundColor": "black"
},
"bg-personal": {
"backgroundColor": "coral"
}
}
This configuration file can be any of the following:
- .babel-plugin-macrosrc
- .babel-plugin-macrosrc.json
- .babel-plugin-macrosrc.yaml
- .babel-plugin-macrosrc.yml
- .babel-plugin-macrosrc.js
- babel-plugin-macros.config.js
Go to codesandbox for see this example
This project stemmed from tailwind-rn and twin.macro