77

GitHub - sergeybekrin/styled-email-components: ? styled-components for emails

 5 years ago
source link: https://github.com/sergeybekrin/styled-email-components
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

readme.md

? styled-email-components

npm Version Build Status dependencies Status devDependencies Status Greenkeeper badge

Extension of styled-components with essential features for building email components.

Important: due to dependencies on styled-components internals, latest compatible version of styled-components is 3.4.1. We'll re-evaluate design of this module after stable v4 release of styled-components. Thanks!

Features

Motivation

styled-components is a universal styling solution with great developer experience and low learning curve. Unfortunately, there's no native support for inline styling which is essential for building emails. This module adds all necessary features to build mail-first components.

Installation

Don't forget to install styled-components itself as a peer dependency.

yarn:

yarn add styled-email-components styled-components

npm:

npm install --save styled-email-components styled-components

Getting Started

Check original Gettings Started for more examples.

import React from 'react';
import { renderToStaticMarkup } from 'react-dom/server';
import styled from 'styled-email-components';

const Link = styled.a`
  font-family: sans-serif;
  background: blue;
  color: white;
`;

renderToStaticMarkup(<Link href="https://example.com">Hey</Link>),
// ? output
// <a href="https://example.com" style="font-family:sans-serif;background-color:blue;color:white;">Hey</a>

API

styled.*

This module sets list of XHTML 1.0 Transitional element aliases instead of original HTML5 set, which is a widely used doctype in mails.

styled.vml.*

In addition to XHTML elements, styled.vml.*, styled.wml.* and styled.office.* aliases are available. These are simple proxies and pass tag names as-is with v:, w: and o: prefixes respectevly.

Other APIs

Original APIs are mirrored without any modifications from styled-components. Make sure to check server-side rendering guide for rendering the final email.

License

MIT © Sergey Bekrin


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK