Extension of styled-components
with
essential features for building email components.
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
nessecary features to build mail-first components.
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
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;
`;
// That works ๐ฑ
console.assert(
renderToStaticMarkup(<Link href="https://example.com">Hey</Link>),
'<a href="https://example.com" style="font-family:sans-serif;background-color:blue;color:white;">Hey</a>',
);
This module sets list of XHTML 1.0 Transitional element aliases instead of original HTML5 set, which is widely used doctype in mails.
In addition to XHTML elements, styled.vml.*
, styled.wml.*
and
styled.office.*
aliases are available. These are simple proxies and passes tag
names as-is with v:
, w:
and o:
prefixes respectevly.
Original APIs are mirrored without
any modifications from styled-components
. Make sure to check
server-side rendering
for rendering final email.
MIT ยฉ Sergey Bekrin