Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass variables to the tagged template literal #42

Open
markbrouch opened this issue Sep 29, 2019 · 3 comments
Open

Pass variables to the tagged template literal #42

markbrouch opened this issue Sep 29, 2019 · 3 comments

Comments

@markbrouch
Copy link

I'm trying to pass a variable from Styled Components to my tailwind tagged template literal, but can't figure out how to do it. This doesn't work:

const Button = styled.button`
  ${p => tw`bg-${p.color}`}
`
@eelkeh
Copy link

eelkeh commented Sep 30, 2019

Having the same issue with something like:

const StyledCard = tw.div`
  w-full
  flex-grow 
  lg:w-1/2 
  bg-pink-300
  ${props => (props.noPadding ? `p-0` : `p-8`)}
`

@NikkiJonesR
Copy link

NikkiJonesR commented Sep 30, 2019

I believe you need to use the css helper to do interpolations: https://www.styled-components.com/docs/api#css

So something like this ...

  const StyledLink = styled.a`
    ${tw`no-underline text-black-two`}
    ${({ navigation }) =>
      navigation &&
      css`
        &:hover,
        &:focus {
          ${tw`text-white-three`}
          transition: color 0.3s ease;
        }
      `}
  `

@pyrbin
Copy link

pyrbin commented Oct 8, 2019

Using typescript this doesnt seem to work:

const Button = tw.button<ButtonProps>`
  bg-${props => props.bg || "primary"} 
  hover:bg-${props => props.bg || "primary"}-dark
  text-${props => props.color || "white"} 
  border-none font-bold font-mono py-2 px-4 rounded
`;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants