Skip to content

Extending Tailwind in Twin.Macro #517

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

You must be logged in to vote

There's a few ways you could add this (not in order):

  1. Add the classes in a global provider
    The global provider can be imported from your css-in-js library. `className="..." is used to add the styles to JSX elements
  2. Convert the styles to variables and import them into your components, eg:
    const snapCss = tw`scroll-snap-type[var(--scroll-snap-direction) var(--scroll-snap-constraint)]`
    
    const Component = styled.div([
        snapCss,
        tw`block ...`
    ])
  3. Convert the classes to a tailwind plugin:
    function snapPlugin({ addComponents }) {
      const classes = {
        ".snap": {
          "scrollSnapType": "var(--scroll-snap-direction) var(--scroll-snap-constraint)",
        },
        // ...
      };
      addComponents(c…

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by ben-rogerson
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@ben-rogerson
Comment options

@jmichel17
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants