Tailwind-Styled-Component
Create tailwind css react components like styled components with classes name on multiple lines
Before ?
<div className=`flex ${primary ? "bg-indigo-600" : "bg-indigo-300"} inline-flex items-center border border-transparent text-xs font-medium rounded shadow-sm text-white hover:bg-indigo-700 focus:outline-none`>
After ?
<Button $primary={false}>
Features
♻️ Reusable
? Extendable
? Compatible with Styled Components
⚡️ Use props like every React Component
? Stop editing 400+ characters lines
? Cleaner code in the render function
Install
Using npm
Using yarn
yarn add -D tailwind-styled-components
⚠️ This extension requires TailwindCSS to be installed and configured on your project too. Install TailwindCSS
[Optional] Configure IntelliSense autocomplete on VSCode
First, install Tailwind CSS IntelliSense VSCode extension
https://marketplace.visualstudio.com/items?itemName=bradlc.vscode-tailwindcss
Then add these user settings (How to edit VSCode settings?)
Usage
Import
Basic
Create a Tailwind Styled Component with Tailwind rules that you can render directly
Will be rendered as
Conditional class names
Set tailwind class conditionally with the same syntax as styled components
Tailwind Styled Components supports Transient Props
Prefix the props name with a dollar sign ($) to prevent forwarding them to the DOM element
Will be rendered as
and
Will be rendered as
Be sure to set the entire class name
✅ Do ${p => p.$primary ? "bg-indigo-600" : "bg-indigo-300"}
❌ Don't bg-indigo-${p => p.$primary ? "600" : "300"}
Extends
Will be rendered as
Careful it does not overrides parent classes
Extends Styled Component
Extend styled components
Css rule filter
is not supported by default on TailwindCSS
Will be rendered as