@nswds/email
v6.2.0
Published
React/react-email foundation for NSW Government email.
Readme
@nswds/email
The React + react-email foundation for NSW Government
email: the Nsw* components, and renderEmail, which turns them into the HTML
you send. Every component, its props and the templates built from them are
documented at email.design.nsw.gov.au.
Install
npm install @nswds/email react react-domIt needs Node 22 or later and React 19, from 19.2 (react at ^19.2.0 and
react-dom at ^19.2.0), and is ESM only.
Use
import { NswColumn, NswColumns, NswLayout, NswText, renderEmail } from '@nswds/email'
const html = await renderEmail(
<NswLayout title='Welcome'>
<NswColumns>
<NswColumn>
<NswText>Hello from the NSW Design System.</NswText>
</NswColumn>
</NswColumns>
</NswLayout>,
)renderEmail is pure JS (no native binary), so it runs on any route or worker.
Use it rather than react-email's own render: it adds Windows Outlook's handling,
and it writes the email's language (<NswLayout lang='fr'>, English by default)
on every cell of words, whichever component drew them.
@nswds/email exports the Nsw* components and their props, renderEmail and
render, and the names a template in the docs is written with. That is what a
release keeps: a change that breaks any of it is a major version.
@nswds/email/internal is everything else the library is built from. It is for
this repository's own apps, and a name in it can change or go in any release.
Import from it only if you accept that.
Developing this package
The rest of this page is for people working on the package in its repository.
None of what it describes (emails/, scripts/, tests/) is in the published
package, which carries the built library alone.
It replaced the earlier Vue + Maizzle implementation (the migration is complete: the apps consume this package and the Vue one is gone).
Why react-email
The decision and its cost are in the migration design doc. The short version:
Maizzle's Vue-SSR render path pulled a native binary (Tailwind v4's oxide, and
Maizzle's own toolchain) that would not load in a stateless serverless function,
which is what broke the render-route spike. @react-email/render is pure JS, so
the builder can render an email on any route or edge worker.
Native-free is a rule here, not an accident. The one thing that would drag
a native binary back in is <Tailwind> at render time, so we do not use it.
scripts/tokens.ts precompiles what Tailwind would have generated live — the
palette hex from @nswds/tokens and the mobile/font rules from the layout — into
plain static source (src/tokens/*.generated.ts, derived and gitignored) that
the components import. No Tailwind, no oxide, no var() to flatten.
Parity is the standard
The reference emails in tests/reference/ are proven across every client,
Outlook included. The React output must draw the same boxes, verified by
measurement at a desktop and a phone width (tests/visual/reference-parity.spec.ts,
1px per box), never by diffing markup. The grid math
(src/lib/grid.ts) is ported verbatim from the legacy Vue implementation and
pinned by tests/unit/grid.test.ts.
Layout
emails/<family>/<slug> email entrypoints — previewed by `email dev`, built, and measured
scripts/tokens.ts precompiles @nswds/tokens + layout/typography -> src/tokens/*.generated.ts
scripts/render.ts renders the emails to dist/html + writes dist/docs/manifest.json
scripts/props.ts writes dist/docs/props.json (the prop tables the docs read)
src/lib/ grid.ts, primitives.ts, vml.ts, manifest.ts, props.ts, typography.ts, devices.ts — pure logic
src/tokens/ generated palette + theme <style> (derived, gitignored)
src/components/ NswLayout, NswColumns, NswColumn, NswSpacer, NswDivider, NswText, NswLink, NswImg, NswButton, NswButtonSquare, NswVml (react-email components)
tests/ reference emails, the unit gate, the visual parity gateA file in emails/ is one email: its default export is what the preview lists
and what the build renders, so the preview and the shipped output are the same
component. Every entrypoint lives under emails/.
A demo whose page is not itself the email a team sends (a template, generic base
or transactional service, shown in the grey, blue and red families) also exports
that one email as
Email. The build renders it beside the page, to
dist/html/<family>/<slug>.email.html, and the docs show its code and link to
it. The local preview lists only the default export, so open the built
.email.html (after npm run build) or the docs' Open the email it sends link
to see it.
Local preview
react-email's own preview server lists every email in emails/, renders it, and
hot-reloads on save.
npm run dev:email # from the repo root
# or: npm run dev -w @nswds/emailIt serves at http://localhost:3031, regenerating the tokens first, then running
email dev.
One thing to keep straight: the preview CLI (react-email) bundles Tailwind and
its native oxide binary. That is the local viewer only. The shipped render path
is @react-email/render, pure JS, and stays native-free — the whole point. The
preview tool being native does not change that.
Commands
| Task | Command |
| ----------------- | ---------------------------------------------------------------------------------- |
| Local preview | npm run dev:email (from root) — serves at localhost:3031 |
| Regenerate tokens | npm run generate -w @nswds/email |
| Build + render | npm run build -w @nswds/email |
| Unit (grid math) | npm run test -w @nswds/email |
| Visual parity | npm run test:visual -w @nswds/email (needs a browser + network for the web font) |
| Typecheck / lint | npm run typecheck / lint -w @nswds/email |
Scope
The grid, section, spacer and divider primitives and their devices prop
(desktop or mobile shows a block on that kind of device only, with the
Windows Outlook half handled in src/lib/devices.ts), the text primitive and
the NSW type scale, and its heading treatments, a highlight behind the words or a thick bar under them (NswText, typescale, treatments), the text link (NswLink), the bulleted and numbered list (NswList), the data table built from rows and cells (NswTable, NswTableRow, NswTableCell), the image (NswImg), the NSW Government logo (NswLogo, logo), the social links (NswSocial, social), the icon cloud, a row of small images such as partners' logos (NswIconCloud, iconCloud), the menu of text links (NswMenu, menu), the callout (NswCallout, callout), the header at the top of an email, the logo alone or beside a descriptor, with a divider above, below or down the descriptor's side (NswHeader, header), the header bar, a line of small words above the header (view in a browser, security advice, a date, links to manage preferences), alone or beside a column of words or social icons (NswHeaderBar, headerBar), the hero, the top of an email under its header, a heading with a label, intro, date, button, rules or bands of colour around it, or beside a picture or columns of colour, or over a picture with the email's header, in one of the legacy's layouts (variant) or composed of its parts (NswHero, NswHeroLabel, NswHeroHeading, NswHeroIntro, NswHeroDate, NswHeroButton, NswHeroButtons, NswHeroRule, NswHeroSpace, NswHeroBand, NswHeroImage, NswHeroColumns, NswHeroColumn, NswHeroBackdrop, hero), the call to action, a heading beside or above its button, or with an intro and two buttons side by side, in one of the legacy's layouts on the hero's frame (NswCta, cta), the footer, the logo, social icons, address, copyright, links in a line or a column, the menu and a notice or compliance words, in one of the legacy's layouts (variant) or composed of its parts (NswFooter, NswFooterAddress, NswFooterCopyright, NswFooterText, NswFooterLinks, NswFooterRule, NswFooterSpace, NswFooterColumns, NswFooterColumn, footer), the Acknowledgement of Country, under First Nations artwork or with the Aboriginal and Torres Strait Islander flags (NswAcknowledgement, acknowledgement), the statement, a privacy notice or disclaimer under its heading on a fill of the theme, or words to stand out in a panel with a line down its left, beside the flags if asked (NswStatement, statement), the blockquote, words quoted under a quote mark, beside a line or over a bar (NswBlockquote, blockquote), the card, a picture, heading, words and link, alone in a column or in rows of them (NswCard, NswCards, card), the feature, a picture flush to one edge of the row beside a heading, words and a link (NswFeature, feature), the gallery, a row of two to four pictures, each with a caption under it if given, or as masonry, two pictures stacked beside one as tall as both (NswGallery, gallery), the infographic, figures drawn large with a pictogram above or beside them, a line of pictograms each over a short figure, or headings, figures and words between lines (NswInfographic, infographic, infographicPictogram), the feedback block, a question and a row of answers the reader clicks, each linking to the sender's feedback address with the answer added, as a 1 to 10 scale, five stars, thumbs up or down, or five faces (NswFeedback, feedback, feedbackPictogram, feedbackColourFaces), the social block, a heading over links to the sender's social accounts, as tiles filled or outlined, square or round, bare glyphs, or glyphs beside the networks' names (NswSocialBlock, socialBlock), the link list, announcements beside their heading, each a heading, a line in bold, words and a link, ruled apart and closed by a button if given, or a column of plain links (NswLinkList, linkList), the date list, each date in a card outlined in the words' colour, its day over its month or its month, day and year, beside what happens, ruled apart (NswDateList, dateList), the line list, lines ruled apart: a summary of labels and values such as a payment's, the total larger, words with a date or figure pushed to the right, or headings with words and a link beside them (NswLineList, lineList), the icon list, items each beside a pictogram, a label, heading and words or any of them (NswIconList, iconList), the pill, a short label for a status, category or count in the web design system's badge tones and variants (NswPill, pill), the button and its tones
(NswButton, buttonTones), the square button (NswButtonSquare), the VML shape Windows Outlook draws backgrounds, gradients and rounded panels with (NswVml, the base for primitives that need one), the native-free token precompile, and the docs'
props/manifest machinery all ship here. Still to come: per-theme token
generation. A real Outlook render stays a manual
verification step (testi.at); the Outlook handling lives in the components and
is documented in each.
No AI attribution anywhere in this repo.
