question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add support for styled-components style API:

import tw from 'tailwind.macro'

let Header = tw.header`bg-red text-center`

Should we use the default export like above, or use a separate named export? For example:

import { styled } from 'tailwind.macro'

let Header = styled.header`bg-red text-center`

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
bradlccommented, Apr 13, 2019

It would be useful to use it to extend […]

You can do this already in pretty much the same way you would with standard emotion/styled-components:

import tw from 'tailwind.macro'

const Paragraph = tw.p`font-muli mb-8 text-gray-800 font-light`
const ParagraphLarge = tw(Paragraph)`text-lg text-gray-500`
1reaction
JaffParkercommented, May 13, 2019

Adding classes based on props doesn’t work when using tw.button syntax. I had to switch to styled-components to achieve that.

To illustrate, this won’t work:

import { ComponentType } from 'react'
import tw from 'tailwind.macro'

export const Button = tw.button`
  rounded
  py-2
  px-4
  m-1
  text-white
  uppercase

  focus:outline-none

  ${({ color }: ButtonProps) =>
    color === 'primary'
      ? `bg-red-500 hover:bg-red-700`
      : `bg-gray-500 hover:bg-gray-700`}
`

This will:

import { ComponentType } from 'react'
import styled from 'styled-components/macro'
import tw from 'tailwind.macro'

export const Button = styled.button`
  ${tw`
  rounded
  py-2
  px-4
  m-1
  text-white
  uppercase

  focus:outline-none
  `}

  ${({ color }: ButtonProps) =>
    color === 'primary'
      ? tw`bg-red-500 hover:bg-red-700`
      : `background-color: gray;`}
`
Read more comments on GitHub >

github_iconTop Results From Across the Web

styled() - MUI System
Utility for creating styled components. ... This example demonstrates how you can use the styled API to create custom components, with the same...
Read more >
API Reference
A function that receives the props that are passed into the component and computes a value, that is then going to be merged...
Read more >
API
The space utility converts shorthand margin and padding props to margin and padding CSS declarations. Numbers from 0 to the length of theme.space...
Read more >
The Essential Guide to MUI Styled Components
MUI Styled Import ... Most developers should use the MUI-recommended approach, which is the styled() API that wraps emotion. ... Here is the ......
Read more >
Using styled API in ReactJS
Styled components in ReactJS is a CSS-in-JS library that can be used for a better UI design. This API allows us to create...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found