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

fix(tailwind): className manipulation for component props #1556

Merged
merged 8 commits into from
Jul 31, 2024

Conversation

gabrielmfern
Copy link
Collaborator

This is meant so that it allows users to use twMerge with respective
components without it having any issues.

For background, we inline all styles from Tailwind classes and then remove the
classes. This is done on the props of all React elements inside of the Tailwind
component's children. This means that classNames are removed before the user
can deal with them to merge or manipulate in general.

The reason we can't just direclty not run Tailwind on the components and just
leave the classNames be, is because our components specifically do manipulation
on the styles. Meaning that, if only the classNames come in to be manipulated,
the components won't do what they would normally do.

The way this PR goes around that issue is then, by still running Tailwind on
the component, thus adding the proper style properties to the component, but
without removing the respective classNames. This still allows us to do style
manipulation while allowing users to do className manipulation in the same way.

There is still one issue that might arise from this, though. When using the
<Button> component, for example, we do some transformations to the padding
before actually applying it to the underlying <a> element while still adding
the needed classNames to the same element. Since, the current behavior of the
component is to give priority to the new styles from Tailwind classNames over
the already inlined styles, it means that these transformations will be ignored
in our component making it not work the same way as before. The only to fix
this, is to do the opposite of what we already do — we need to give priority to
the already inlined styles on elements.

This last change is still a trade-off though, and might be a bit unintuitive to
users. So, something to lookout for.

Copy link

changeset-bot bot commented Jul 23, 2024

🦋 Changeset detected

Latest commit: 9302024

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@react-email/tailwind Minor
@react-email/components Patch
react-email-starter Patch
create-email Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Jul 23, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-email ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 31, 2024 5:30pm
react-email-demo ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 31, 2024 5:30pm

@gabrielmfern gabrielmfern force-pushed the fix/class-name-manipulation-tailwind branch from 0609302 to ef821fc Compare July 25, 2024 16:16
@gabrielmfern gabrielmfern force-pushed the fix/class-name-manipulation-tailwind branch from 76800b3 to 5a3f129 Compare July 29, 2024 16:16
@gabrielmfern gabrielmfern force-pushed the fix/class-name-manipulation-tailwind branch from 5a3f129 to a643e48 Compare July 29, 2024 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants