Tailwind-Styled-Component
Create tailwind css react components like styled components with classes name on multiple lines
Install
npm i -D tailwind-styled-components
yarn add -D tailwind-styled-components
Usage
Import
import tw from "tailwind-styled-components"
Basic
You can use tailwind-styled-components without using styled components
const Container = tw.div`
flex
items-center
justify-center
flex-col
w-full
bg-indigo-600
`
Will be rendered as
<div class="flex items-center justify-center flex-col w-full bg-indigo-600">
</div>
Extends
const RedContainer = tw(Container)`
bg-red-600
`
Will be rendered as
<div class="flex items-center justify-center flex-col w-full bg-red-600">
</div>
Overrides the parent background color class
Extends Styled Component
Extend styled components
const StyledComponentWithCustomJs = styled.div`
filter: blur(1px)
`
const = tw(StyledComponentWithCustomJs)`
flex
`
Will be rendered as
<div class="flex" style="filter: blur(1px);">
</div>
Example
import React from "react"
import tw from "tailwind-styled-components"
import styled from "styled-components"
const Container = tw.div`
flex
items-center
justify-center
`
const Title = tw.h1`
text-lg
text-indigo-500
`
const Container = styled.section`
background-color: #0366d6;
`
const Container = tw(SpecialBlueContainer)`
flex
items-center
justify-center
w-full
`
<Container>
<Title>Hello World, this is my first tailwind styled component!</Title>
</Container>