npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@react-email/tailwind

v1.0.4

Published

A React component to wrap emails with Tailwind CSS

Downloads

1,782,506

Readme

React Email Tailwind cover

Install

Install component from your command line.

With yarn

yarn add @react-email/tailwind -E

With npm

npm install @react-email/tailwind -E

Getting started

Add the component around your email body content.

import { Button } from "@react-email/button";
import { Tailwind } from "@react-email/tailwind";

const Email = () => {
  return (
    <Tailwind
      config={{
        theme: {
          extend: {
            colors: {
              "custom-color": "#ff0000",
            },
          },
        },
      }}
    >
      <Button
        href="https://example.com"
        className="text-custom-color bg-white mx-auto"
      >
        Click me
      </Button>
    </Tailwind>
  );
};

Contributing notes

These are some things you will need to keep in mind if you are improving the Tailwind component with things that might influence certain decisions we have made for better email client support that have been made also in the past by other contributors but not documented which ended up causing us to have these problems and need to rediscover the best decisions again.

The inlining of all styles

This is one of the most important because this is not one of the use cases this is the main focus point of using the Tailwind component. The support for defining styles with tags and using classes is not the best.

This though can't be used the same for media queries so we do append the media queries and the class names associated with them on a <style> tag on the <head> element.

The treatment for Tailwind's CSS variables

Emails don't really have great support for CSS variables, so we needed to use a custom postcss plugin alongisde Tailwind to resolve all of these variables. When the plugin finds a CSS Variable that it cannot resolve, it leaves it without any changes.

The treatment for media query class names

For media queries we have made more than one decision that are for the better. The first one and most important is sanitizing the media query class names on the <style> tag to avoid needing to escape the class names which does cause problems.

RGB syntax color changes

For the best support two things were taken into account here. First thing is that the syntax using spaces, which Tailwind generally uses, is not really supported, neither for rgb nor for rgba, so we do a pass through Tailwind's generated styles to change the syntax into using commas instead of spaces.

Second thing is that both rgba and using / for defining the color's opacity are not very well supported, but passing in the opacity as a fourth parameter of rgb() is what is mostly supported so we also account for that.

This has an effect like the following:

rgb(255 255 255 / 1) -> rgb(255,255,255)
rgb(212 213 102 / 0.2) -> rgb(212,213,102,0.2)

Defining the styles on the React style prop

This is something that comes a bit at the risk of performance but it is a safer way of doing this. The reason this is safer is because certain components of ours or even custom ones may modify the way styles are applied and defining it directly on the rendered HTML would cause unexpected behavior on that.

Support

This component was tested using the most popular email clients.

| | | | | | | | -------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ | | Gmail ✔ | Apple Mail ✔ | Outlook ✔ | Yahoo! Mail ✔ | HEY ✔ | Superhuman ✔ |

License

MIT License