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

className matching #282

Merged
merged 2 commits into from Jan 20, 2021
Merged

className matching #282

merged 2 commits into from Jan 20, 2021

Conversation

ben-rogerson
Copy link
Owner

@ben-rogerson ben-rogerson commented Jan 9, 2021

This PR adds a includeClassNames flag that allows twin to check className props for tailwind classes:

<button className="rounded some-other-class" />

When a tailwind class is matched, it's converted to a css object and delivered to the css prop:

<button className="some-other-class" css={{ "borderRadius": "0.25rem" }} />
  • Unmatched classes are skipped and preserved within the className
  • Suggestions aren’t shown for unmatched classes like they are for the tw prop
  • The tw/css props can be used on the same jsx element
  • Limitation: classNames with conditional props or variables aren’t touched, eg: <div className={isBlock && "block"} />

How to enable the feature

// babel-plugin-macros.config.js
module.exports = {
  twin: {
    // ...
    includeClassNames: true,
  },
}

// or

// package.json
"babelMacros": {
    "twin": 
      // ...
      "includeClassNames": true
    },
},

Thanks to @mxstbr for the idea in this discussion.

src/getStyles.js Outdated Show resolved Hide resolved
src/macro/className.js Outdated Show resolved Hide resolved
src/macro/tw.js Outdated Show resolved Hide resolved
@ben-rogerson ben-rogerson merged commit 2d92fd3 into master Jan 20, 2021
@ben-rogerson ben-rogerson deleted the feature/className-matching branch January 20, 2021 06:08
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

Successfully merging this pull request may close these issues.

None yet

1 participant