Skip to main content

turn.healthpass.ds

The design system behind Turn's patient-facing pages, such as HealthPass, shipped as a platform library so every app that serves pages to patients looks and behaves the same. It covers cards for clinical records, buttons, badges, a drawer, a PIN input, headers, sections, rich text, date tiles, icons and illustrations.

Each component is a Lua function that takes a table of props and renders a Liquid template. Every component is on the components page, with a screenshot, the call that renders it and its props.

Rendering a component​

Require the component's module and call the function. It returns an html value, not a string. Turn it into a string with turn.healthpass.ds.html where it goes into a page:

local ds_html = require("turn.healthpass.ds.html")
local buttons = require("turn.healthpass.ds.components.buttons")
local cards = require("turn.healthpass.ds.components.cards")

local share = buttons.button({ variant = "secondary", label = "Share", icon = "share-05" })
local note = cards.text_card({ text = document.note })

response:html(turn.liquid.render("pages/document", {
share_button = ds_html.to_string(share),
note = ds_html.to_string(note),
}))

Components compose: a prop of type slot takes another component's output, such as a badge in a card's status:

local badges = require("turn.healthpass.ds.components.badges")

cards.base_card({
label = "Penicillin",
text = "Medication",
status = badges.badge({ state = "success", icon = "check-circle", text = "Done" }),
})

User data stays escaped​

Pages built with the design system show patients their own records, so text from a record must never be able to inject markup. The design system makes that structural rather than a matter of care:

  • String props are escaped by the component that renders them.
  • Slots accept only html values that a component produced. A plain string passed to a slot is refused with an error, so text from a record can't reach a slot unescaped by accident.
  • When you hold markup you trust, such as a literal in your own code, ds_html.html("...") declares that trust explicitly. It is the one place to look when reviewing what bypasses escaping.

turn.healthpass.ds.html is the html value's whole interface:

FunctionReturnsWhat it does
html(s)html valueDeclares the string s trusted markup. Raises when s is not a string.
is_html(v)booleanWhether v is an html value.
to_string(v)stringThe markup inside an html value. Raises for anything else, so a plain string can't pass as rendered output.
slots(vars)tableFor a page template's variables: a new table with every html value, or array of html values, turned into strings. Raises on any other value. Pass text the template escapes itself ({{ name | escape }}) next to it, not through it.

Styling: each app ships its own stylesheet​

Components emit Tailwind classes from the design system's own palette and type scale. The stylesheet and script that style them are not part of the library: an app ships them itself, as assets/public/ds/ds.css and ds.js, and loads them in its page layout:

<link rel="stylesheet" href="{{ "ds/ds.css" | versioned_static_url }}">
<script defer src="{{ "ds/ds.js" | versioned_static_url }}"></script>

The stylesheet is compiled from the classes the components use, and one built for only some components styles only those. When a component you start using renders unstyled, the stylesheet your app ships was built without it. ds.js makes the interactive components work, such as opening and closing a drawer, and the PIN input.

Icons and illustrations​

Icons are inline SVGs that take the colour of the text around them, so a text-* class paints them and a size class sizes them:

local icons = require("turn.healthpass.ds.components.icons")
icons.icon({ name = "chevron-right", class = "w-5 h-5" })

Illustrations are multi-colour artwork served as static files and rendered as an image; sizing is the only option:

local illustrations = require("turn.healthpass.ds.components.illustrations")
illustrations.illustration({ name = "timeline-empty", class = "w-32" })

The names each accepts are in icons.names and illustrations.names, and both sets are shown under Foundations on the components page.

Dates​

turn.healthpass.ds.date formats the ISO 8601 dates FHIR uses the way the components show them, so every page writes a date the same way:

CallResult
date.date_line("2026-07-15T10:00:00Z")15 Jul 2026
date.date_time_line("2026-07-15T09:30:00Z")15 Jul 2026, 09:30
date.month_line("2026-07-15T10:00:00Z")July 2026
date.parts("2026-05-12"){ month = "May", day = "12" }, for a date tile

The storybook​

The library includes a storybook viewer that lists every component and its stories, next to any components of your own, rendered with your app's stylesheet. One viewer serves every app, so a component looks the same in each app's storybook. Mount it on your app's router and decide when it is on:

local storybook = require("turn.healthpass.ds.storybook").new({
enabled = function(app) return app.config.storybook_enabled == true end,
title = "My app",
groups = { my_component_stories },
})

router:get("/storybook")(storybook.get)
router:get("/storybook/preview")(storybook.preview)

The routes show no patient data and are not authenticated, so enabled is required and checked on every request: the routes answer 404 whenever it returns false.

storybook.new(opts) returns { get, preview }, the two route handlers. Its options:

OptionType
enabledfunction(app) -> booleanRequired. Called with the app on every request; false answers 404.
titlestringThe heading over your own groups. Defaults to "HealthPass".
groupsarray of story groupsYour own components' stories, listed after the design system's.

A story group describes one module of components, the same way the library's own do:

local my_cards_stories = {
component = "my-cards", -- the group's URL slug; must not reuse a design system slug
module = require("my_app.components.cards"),
name = "My cards", -- optional; derived from the slug
stories = {
{ id = "summary_card", args = { title = "Blood test", details = "12 May 2026" } },
{ id = "summary_card_states", fn = "summary_card", variants = {
{ title = "Booked", details = "Tomorrow" },
{ title = "Cancelled", details = "Yesterday" },
} },
},
}

Each story renders module[fn or id] with args, or once for each entry of variants, stacked. name defaults to the id, humanised. The code snippet and the props table come from the module's props table, which declares each function's props:

M.props = {}
M.props.summary_card = {
{ name = "title", type = "string", required = true, description = "What the card is about." },
{ name = "details", type = "string", default = "", description = "A second line, such as a date." },
}

A prop's type is one of string, number, boolean, table, slot, enum (with a values array), date (ISO 8601) or digits, and every prop is either required or has a default. turn.healthpass.ds.props.normalize(M.props.summary_card, props) checks a call against the declaration, so the storybook and the component agree on the contract. storybook.new raises when enabled is missing or a group reuses a design system slug.

Testing​

turn.healthpass.ds.spec_html_helpers makes structural assertions over rendered markup in specs, so a test checks what a patient would see rather than matching substrings:

local h = require("turn.healthpass.ds.spec_html_helpers")

local html = buttons.button({ label = "Share" })
assert(h.text(html, "[data-testid=button-label]") == "Share")
h.find_none(html, "[data-testid=button-icon]")

Every helper takes either an html value or a plain html string as html, and a CSS selector. A found node is a table { html, text, attributes }. text, attribute, has_attribute and has_class also take a node from find or find_one in place of html and the selector, to check several things on one element.

FunctionReturnsRaises when
find(html, selector)array of nodesnothing matches, which also catches a mistyped selector
find_one(html, selector)nodethe selector matches none, or more than one
find_none(html, selector)nothinganything matches, naming the first match
text(html, selector) or text(node)string, whitespace normalisedthe selector doesn't match exactly one node
texts(html, selector)array of strings, in document order; empty when nothing matchesnever
assert_texts(html, selector, expected)nothingthe texts differ from the expected array, in content, order or count
attribute(html, selector, name) or attribute(node, name)string, or nil when absentthe selector doesn't match exactly one node
has_attribute(html, selector, name) or has_attribute(node, name)boolean, true even for an empty valuethe selector doesn't match exactly one node
has_class(html, selector, class) or has_class(node, class)booleanthe selector doesn't match exactly one node
r2s(value)stringvalue is not an html value
local card = cards.base_card({ label = "Penicillin", text = "Medication" })

local label = h.find_one(card, "[data-testid=card-label]")
assert(h.text(label) == "Penicillin")
assert(h.has_class(label, "text-gray-dark"))

h.assert_texts(card, "[data-testid=card-text]", { "Medication" })
assert(#h.find(card, "[data-testid=card-label]") == 1)

A selector with a typo matches nothing, so find_none only proves an absence for a selector another assertion has shown to match. A component that returns a plain string instead of an html value fails r2s, so the mistake shows up in the component's own spec.

Like the rest of the library, these helpers aren't in the Turn Lua SDK yet: see Testing on the overview.