Skip to content

Can twin.macro using with the custom class #538

Answered by ben-rogerson
hoangddt asked this question in Q&A
Discussion options

You must be logged in to vote

We can't write css like that for twin (or use @apply) but you can create a reusable component like this instead:

import tw, { styled, theme } from 'twin.macro';

export const Button = styled.button({
  ...tw`px-3 py-2 rounded font-semibold inline-flex text-sm items-center hover:decoration-none`,
  variants: {
    variant: {
      primary: tw`bg-primary text-white`,
      secondary: tw`btn-secondary`,
    }
  }
});

Usage:

<Button variant="primary">Submit</Button>

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by hoangddt
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants