Giter Site home page Giter Site logo

react-email's Introduction

React Email

Emails are a different kind of beast. Not every fancy CSS trick you put in works. We built this components' library depending on how Email clients want it. For a start, all the styles are compiled into inline styles. But you do not have to worry about putting styles inline. Our library provides great Developer Experience with easy-to-use mechanisms to let you define the styles as usual but turned to inlined styles at the end of the day when you send the emails. Also, you don't need to worry about the styling and HTML tags guidelines for different email clients, use our components and leave the handling of compatibility to us.

Check out the documentation for more information.

React Email Docs

Find the npm package here

npm version CI/CD

Join the Gitter channel here for discussions and support.

Gitter channel

Star us on GitHub — it helps!

GitHub GitHub stars GitHub forks GitHub license Twitter

Installation

Using npm

npm i @leopardslab/react-email

or

npm install --save @leopardslab/react-email

Using Yarn

yarn add @leopardslab/react-email

Glimpses of usage

import { Email, Section, Column, Typography } from '@leopardslab/react-email';

export const HelloEmail = ({ name }) => {
  return (
    <Email>
      <Section>
        <Column>
          <Typography variant="h2">Hello {name}</Typography>
        </Column>
      </Section>
    </Email>
  );
};

Want to add some custom styles?

Here we go:

import { Divider, Email, Section, Column, Typography } from '@leopardslab/react-email';

const styles = {
  greyBackground: {
    backgroud: 'grey',
  },
};

export const HelloEmail = ({ name }) => {
  return (
    <Email>
      <Section>
        <Column>
          <Typography variant="h2">Hello {name}</Typography>
        </Column>
        <Divider />
        <Column classes={{ root: styles.greyBackground }}>
          <Typography variant="h2">Hello {name}</Typography>
        </Column>
      </Section>
    </Email>
  );
};

You can also define and load a fully custom theme! 🤯

import { Email, Section, Column, Typography } from '@leopardslab/react-email';
import darkTheme from './theme';

export const HelloEmail = ({ name }) => {
  return (
    <Email theme={darkTheme}>
      <Section>
        <Column>
          <Typography variant="h2">Hello {name}</Typography>
        </Column>
      </Section>
    </Email>
  );
};

Create your own component like this:

// InfoPanel.jsx
const useStyles = makeStyles({
  root: { padding: '10px' },
  info: { border: '1px solid #DD5353' },
  warn: { border: '1px solid #FF731D' },
});

export const InfoPanel = ({
  children,
  variant = 'info',
  classes, // if you want to override some styles when you are using the component
}) => {
  const styles = useStyles({ classes });
  const infoPanelStyle = sx(styles.root, styles[variant]); // combines root and variant specific styles

  return <div style={infoPanelStyle}>{children}</div>;
};

// HelloWorld.jsx
import { InfoPanel } from './InfoPanel';

const styles = {
  greyBackground: {
    backgroud: 'grey',
  },
};

export const HelloEmail = ({ name }) => {
  return (
    <Email theme={darkTheme}>
      <Section>
        <Column>
          <InfoPanel variant="info">Hello {name}!!!!</InfoPanel>
          <InfoPanel variant="warn" classes={{ root: styles.greyBackground }}>
            Be prepared!
          </InfoPanel>
        </Column>
      </Section>
    </Email>
  );
};

Inspiration

The idea of a React Component Library for Emails is not novel. There have been other implementations around for a while and we were inspired a lot by these solutions and many other generic Component Libraries. Following are a few of the amazing other implementations.

We try to be the community backed up-to-date solution one can depend on and contribute back, request features & seek help.

react-email's People

Contributors

agentmilindu avatar charithccmc avatar niloysikdar avatar sakkshm26 avatar semantic-release-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-email's Issues

Implement text email generation utility based on Email templates

Description:

  • We need to generate the plaintext version of the email template from the HTML or React.

Outcome:

  • We need to create the “generateTextEmail” utility function which will do this conversion.

References:

  • This package can help us to implement this method

  • A working POC: link

image

Sample output:

Hello World
![Image] (https://images.unsplash.com/photo-1453728013993-6d66e9c9123a)
Hello World 1

Add snapshot testing using storybookjs/test-runner

Problem:

Previously, as per issue #19 , we tried to use @storybook/addon-storyshots to generate snapshots of our components and utils methods from our storybook stories. But unfortunately, that wasn't working as per PR #29 . I dropped this issue to the official discord server of Storybook and also opened this as a question in Stack Overflow.

Solution:

I didn't receive any answer or solution in Stack Overflow. But however, I got a reply from one of the Storybook's admins (@kylegach) in Discord.

Storyshots is being replaced by the test-runner, with which you can use the test hook API to take snapshots: https://github.com/storybookjs/test-runner#experimental-test-hook-api.
Once that API is proven to be stable, we'll update the docs to make this clear.

Also, I asked

Thanks a lot for the info, so can't we use storyshots for our new projects for now?

And the answer was

It may work for some setups, but I wouldn't advise it.

Description:

So now, we're moving forward with storybookjs/test-runner with their Experimental test hook API to generate snapshots based on our Storybook stories.

Outcome:

Well configured storybookjs/test-runner for the snapshot testing and snapshots for all of the Storybook stories.

Reference issue and closes #19

CODE_OF_CONDUCT.md file

Currently, there is no CODE_OF_CONDUCT.md file, which is present in other projects of SCoReLab.

Add component: Quote

Description:

  • Add component - Quote

  • Example:

    <Quote>I am Hello</Quote>
  • HTML:

    <div styles={{...}}>I am Hello</div>
  • Text:

    > I am Hello

Outcome:

  • New Quote component
  • Add PropTypes for the components
  • Add Storybook story

Feat: Regarding initiliazation of the project

Currently, this is an empty repo we can make and initialize a node project using TypeScript, based on Rollup as bundler as mentioned in docs. This would give a head start to the project
[X] would like to work on this issue

add component: Button

Description:

  • Add component - Button
  • Variation: primary | secondary
  • Use a tag under the hood

Outcome:

  • New Button component
  • Add PropTypes for the components
  • Add Storybook story

Add Storybook for the Example app

Description:

  • Add Storybook and stories for the email layouts inside the example app for visualization.

Outcome:

  • Storybook init and configured for the Example app
  • Stories for the Email Layouts

Add deploy config and scripts

Description:

As discussed here in issue #74 , we need to add the configurations and all the scripts to deploy our Storybook, TSDoc, and Docusaurus docs.

Outcome:

A general script to deploy all of our sites from a single folder.

[Epic] Implement default styles for styled components

Description:

Since we have implemented our styled-components and themeprovider, we also need to implement some default stylings for our components (Button, Link, Divider, Quote, etc.).
We need to update the styles inside the defaultTheme object.

Outcome:

Default styles for our styled components.

Add Storybook to the project

Description:

  1. Add React Storybook to the project
  2. Add a sample story for the Email component

Outcome:

  1. Working story for the Email component

Add example for ESM

Description:

  • Add an example inside the example directory to show the example of how to use the package with the ECMAScript modules standard for the Node.js environment (i.e. import/export syntax)

Outcome:

  • Working example for ESM

Research into the usage of Docusaurus

Description:

  • Learn about Docusaurus and how it works
  • Pros and cons for using it in our project to generate docs

Outcome:

  • A detailed breakdown of the above-mentioned points which need to be explained during weekly standup
  • A POC that can show the usage of Docusaurus

Hosting Storybook

Hosting the storybook on GitHub pages using CI/CD

Description:

  • Hosting the Storybook static site with already added stories using GitHub pages
  • Deploy the storybook with GitHub Actions to trigger auto-deploy when pushed to the main branch

Outcome:

  • GitHub page link of the hosted Storybook with stories

Initialize storybook and create test themes

What is React Storybook?

Storybook is a development environment tool that is used as a playground for UI components. It allows us, the developers, to create and test components in isolation. It runs outside of the app, too, so project dependencies won't affect the behaviour of components.

add component: Divider

Description:

  • Add component - Divider

Outcome:

  • New Divider component
  • Add PropTypes for the components
  • Add Storybook story

Support for ESM

Description:

  • Currently, our package isn't compatible with the ECMAScript modules standard for the Node.js environment. That means, we can't use the import/export syntax for Node.js.

Outcome:

  • Fixing bugs and adding support for ESM inside Node.js

Create example application

Description:

  • Add one example application to show how to use our package with the already existing components and methods

Outcome:

  • A working application using our package
  • Email layout using different components
  • Using generateEmail method to generate plain HTML from the react layout

Converting React components to HTML

Description:

  1. After creating react components, we need to convert the react code to plain HTML code which users can send through email.

  2. However, we also need to add the option to configure the base HTML and base CSS styles. Both of them should be added to the separate files and then should be imported. Users can also customize the base code as per their needs.

Outcome:

  1. We need to create the “generateEmail” utility function which will do this conversion.
  2. Add stories on how to use the generateEmail utility.

Initialise the project

Description:

  1. Initialize the project with a basic TypeScript compiler to compile the TypeScript code to JavaScript.
  2. Should maintain proper folder structure and package.json for the package.
  3. Use yarn for dependency management.

Outcome:

  1. Successful initialization of the project.

Add component: Typography

Description:

  • Add component - Typography
  • variants:
    • h1, h2, h3, h4, h5, h6, subtitle1, subtitle2, body1, body2, caption

Outcome:

  • New Typography component
  • Add PropTypes for the components
  • Add Storybook story

ESM & CJS compatibility issues

Description:

  • Currently, we're just converting our TypeScript code to JavaScript code into ES Modules (ESM). We need to add support for both ESM and CJS modules while compilation in order to make our package a hybrid package that can run both on React (browser) and Node.js environments.
  • If we try to import some method from our package inside our Node.js environment, we're getting some issues like
    export * from "./Components"
    
    export isn't defined and can't be used here
    
    like this

References:

CC @agentmilindu

Add component: Preheader

Description:

  • Email Preheader text is a small line of text that appears after the subject line in an email inbox. Email preheaders give a short summary of the contents of an email, and may appear differently on mobile and web email clients.

  • Adding Preheader:

    • Add text as the first text within the body tag of your email
    • Put the text in a div style
    • Use the div style to hide the text from the actual email
  • To email clients, the preheader text will show up as the first text in the email. When someone opens the email, that text will be hidden (because of the hidden div style).

  • https://www.activecampaign.com/blog/email-preheader

Outcome:

  • Working Preheader component.

Reference/Example Code to add Preheader:

image

Add CI-CD

Description:

  1. Adding the CI-CD pipeline using GitHub Actions

Outcome:

  1. Release the beta version of the package (v0.0.1) on npm

add component: Column and Section

Description:

  • Add components - Column & Section

Outcome:

  • New Column and Section component
  • Add PropTypes for the components
  • Add Storybook story

Adding styling methods

Description:

  1. We can implement a utility method to combine styles, and a hook for exposing styles to components with style overrides.

Outcome:

  1. “sx” method will be implemented
  2. A makeStyles() util which gives useStyles() hook will be implemented
  3. Add a separate section for Utils in Storybook
  4. Add stories for styling like stylx, makeStyles and useStyles.
    • Use the Email component to override style.

add component: Row

Description:

  • Add component - Row
  • It will be used to align items in a horizontal way

Outcome:

  • New Row component
  • Add PropTypes for the components
  • Add Storybook story

Add component: Image

Description:

  • Add component - Image
  • Props:
    • src, alt, height, width

Outcome:

  • New Image component
  • Add PropTypes for the components
  • Add Storybook story

add component: Link

Description:

  • Add component - Link
  • Props:
    • href

Outcome:

  • New Link component
  • Add PropTypes for the components
  • Add Storybook story

The automated release is failing 🚨

🚨 The automated release from the main branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you can benefit from your bug fixes and new features again.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can fix this 💪.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the main branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here are some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


No npm token specified.

An npm token must be created and set in the NPM_TOKEN environment variable on your CI environment.

Please make sure to create an npm token and to set it in the NPM_TOKEN environment variable on your CI environment. The token must allow to publish to the registry https://registry.npmjs.org/.


Good luck with your project ✨

Your semantic-release bot 📦🚀

Setup Theme

Description:

  • Explore and implement a setup to add a theme to the styled components and also add support to add custom themes by the users

Optimize the exported packages

Description:

  • Currently, our package also contains a few tests and storybook stories for the components and methods after the build process.
  • We can remove those files from the final production package as there are just for testing and they are of no use, and these are only increasing the size of the package.

Outcome:

  • Removing all tests and stories from the final package.

Proposed Solution:

  • We can add this config inside our tsconfig.json to exclude those files while building the package

    "exclude": ["node_modules", "**/*.test.ts", "**/*.test.tsx", "**/*.stories.ts", "**/*.stories.tsx"]

Adding Git hooks, linter, code formatter

Description:

  1. Adding pre-commit hooks with husky, ESLint for linting and prettier configurations for formatting, and conventional changelog for proper commit messages.

Outcome:

  1. ESLint set up
    • yarn lint
    • yarn lint:fix
  2. Prettier configured
    • yarn pretty
    • yarn pretty:fix - optional
  3. Pre-commit hook to maintain proper code style
    • Lint checks, prettier checks, and commit style checks

Adding Semantic Release

Description:

  1. Adding Semantic release to the project

Outcome:

  1. Manual release of the package

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.