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

@tellimer/mailable

v1.0.4

Published

Allows you to create React components that render to email HTML

Downloads

65

Readme

@tellimer/mailable

Allows you to create React components that render to email HTML

Example mailable

import React from 'react'
import { Components, Mailable } from '@tellimer/mailable'

export class ExampleMailable extends Mailable {
  // This is required
  subject = 'Test'

  // This is required, can be just a string (containing email)
  from = {
    name: 'Tellimer Test',
    email: '[email protected]',
  }
  // OR from = '[email protected]'

  // Does not have to return a promise, but allows for it
  async view () {
    const somethingElse = await new Promise((resolve) => setTimeout(() => resolve('hello'), 500))

    return <div>This is an email!</div>
  }
}

// .........

const mailable = new ExampleMailable()
mailable.render().then(html => console.log(html))

Would output the following HTML

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:o="urn:schemas-microsoft-com:office:office" style="margin: 0; padding: 0; font-size: 16px; color: #242424; font-family: Arial, Helvetica, Verdana, Tahoma, sans-serif;">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <meta name="x-apple-disable-message-reformatting">
    <title>Test</title>
    <!--[if mso]>
    <noscript>
        <xml>
            <o:OfficeDocumentSettings>
                <o:PixelsPerInch>96</o:PixelsPerInch>
            </o:OfficeDocumentSettings>
        </xml>
    </noscript>
    <![endif]-->
</head>
<body style="background: #eaeaea; margin: 0; padding: 0; font-size: 16px; color: #242424; font-family: Arial, Helvetica, Verdana, Tahoma, sans-serif;">
  <div data-reactroot>This is an email!</div>
</body>
</html>

Versioned example

First, you must create some versions of the email. These versions must be MailableVersion, which extends the Mailable class. The only new property in this class, is the version property, which is required.

Then, you must create a class that extends MailableVersionFactory. This will contain a method version that returns the correct MailableVersion to send to a person.

import React from 'react'
import {
  Components,
  Mailable,
  MailableVersion,
  MailableVersionFactory,
  Personalization
} from '@tellimer/mailable';

const { Email } = Components

export class Versioned extends MailableVersionFactory {
  version(personalization: Personalization) {
    return parseInt(personalization.customArgs?.userId, 10) % 2 === 0 ? new VersionA() : new VersionB()
  }
}

class VersionA extends MailableVersion {
  version = 'A'
  subject = 'this is a subject for A'
  from = {email: '[email protected]'}

  view() {
    return (
      <Email>
        <div>
          for version B
        </div>
      </Email>
    )
  }
}

class VersionB extends MailableVersion {
  version = 'B'
  subject = 'this is a subject for B'
  from = {email: '[email protected]'}

  view() {
    return (
      <Email>
        <div>
          for version B
        </div>
      </Email>
    )
  }
}

Components

Run storybook to see more information!

yarn storybook

<Email header?={React.ReactComponent} footer?={React.ReactComponent}>
<EmailRow>
<EmailCol>