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.

Support for twin.macro

See original GitHub issue

Hey there,

I keen on getting my package twin.macro working with compiled-css-in-js. Twin converts tailwind classes to css objects with a babel macro and then allows css props and styled imports (from libraries like yours) to take care of the rest.

Right now I’m hitting issues when I introduce the tw block within the styled import and css prop.

Here’s the error I’m seeing:

@compiled/css-in-js => unsupported node

I’ve tried switching the orders of imports and babel plugin registrations but no dice.

Here’s the code I’ve been testing and I’ve also made a code sandbox:

import React from 'react'
import { styled } from '@compiled/css-in-js'
import tw from 'twin.macro'

const Button = styled.button`
  ${tw`p-10`}
`

const App = () => (
  <div
    css={`
      ${tw`text-red-500`}
    `}
  >
    <Button>Test</Button>
  </div>
)

export default App

Twin’s output would normally look something like this before the css-in-js library does its thing:

// ...

const Button = styled.button`
  ${{
    "padding": "2.5rem"
  }}
`

const App = () => (
  <div
    css={`
      ${{
          "--text-opacity": "1",
            "color": "rgba(245, 101, 101, var(--text-opacity))"
          }}
    `}
  >
    <Button>Test</Button>
  </div>
)

// ...

It would be sweet if we could get the two packages co-operating, would you be able to check out how much work would be required your side?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:12

github_iconTop GitHub Comments

1reaction
itsdougescommented, Nov 8, 2020

good suggestions, when we start looking at https://github.com/atlassian-labs/compiled/issues/278 they should open doors for the above

currently conditional rules aren’t supported - but they are on the roadmap

1reaction
ben-rogersoncommented, Nov 8, 2020

Looking pretty good!

Here’s a few features I’d really like to see.

I like that you’re supporting array styling (much cleaner than template strings) 👍

const Button = styled.button([`background-color: black;`, `color: white;`])

So it would be sweet to see support for:

  1. Sending your props through via an ArrowFunctionExpression:
const Button = styled.button(({ isPrimary }) => [
  { 'background-color': 'black' },
  isPrimary && { color: 'white' }
])
  1. Sending props to each item in the array:
const Button = styled.button([
  { 'background-color': 'black' },
  ({ isPrimary }) => isPrimary && { color: 'white' }
])
Read more comments on GitHub >

github_iconTop Results From Across the Web

ben-rogerson/twin.macro - GitHub
GitHub - ben-rogerson/twin.macro: ‍♂️ Twin blends the magic of Tailwind with the ... New: Twin v3 now includes full Tailwind plugin support and...
Read more >
twin.macro - npm
Start using twin.macro in your project by running `npm i twin.macro`. There are 123 other projects in the npm registry using twin.macro.
Read more >
twin.macro examples - CodeSandbox
Learn how to use twin.macro by viewing and forking example apps that make use of twin.macro on CodeSandbox.
Read more >
Twin.macro Tutorial for Beginners: Styling with Tailwind CSS ...
Both string and object styles are supported. Tailwind is a utility-first CSS framework packed with classes like that can be composed to build ......
Read more >
Tailwind CSS with document colors & twin.macro support
Tailwind CSS with document colors & twin.macro support ... It's easier than ever nowadays with neovim treesitter and lsp support, but it may...
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