The page
Markup
Tags, values, styles, colour roles, conditional styles, control, routes, binding, components. Events are in events.md; the kit's components are in kit.md. Back to the map.
Examplea whole program
state n = 0 persistderive double = n * 2row gap=12 padding=24 align-items=center button "−" press={n -= 1} disabled=(n <= 0) text `${n}` font-size=24 button "+" press={n += 1} if n > 0 text `doubled: ${double}` color=dimMental model#
Tags#
Text#
Values#
Styles#
Colour roles#
Animation#
glass#
Conditional styles#
Examplea whole program
state items = ["One", "Two"]column gap=8 padding=16 button "Save" background=accent color=#ffffff hover opacity=0.8 active scale=0.98 focus outline="2px solid" disabled opacity=0.5 for t in items row group gap=8 padding=8 text t button "Delete" opacity=0 in hover opacity=1 row gap=24 phone flex-direction=column gap=12 dark background=#111111 text "Side by side, or stacked on a phone"Examplea whole program
state skin = {hover: "#2b6cb0", on: "#1a4971"}state busy = falsecolumn gap=8 padding=16 button "Blue" press={skin = {hover: "#2b6cb0", on: "#1a4971"}} button "Plum" press={skin = {hover: "#7b3f8c", on: "#4a2355"}} row padding=12 background=card hover background=skin.hover color=#ffffff active background=skin.on scale=(busy ? 1 : 0.98) phone padding=(busy ? 4 : 8) text "A row whose hover colour follows the theme"Values of the whole page#
Examplea whole program
state density = "cozy" persiststate zoom = 1 persiststate brand = "#0a84ff" persiststate calm = false persistroot density=density zoom=zoom var-brand=brand motion=(calm ? "less" : "system")column gap=8 padding=16 in root[density=compact] gap=2 padding=4 row gap=8 button "Compact" press={density = "compact"} button "Cozy" press={density = "cozy"} button "Larger" press={zoom = 1.25} button "Pink" press={brand = "#ff0066"} button "Less motion" press={calm = true} link "A link in the theme's colour" href="https://example.com" color="var(--brand)" text "This eases in" transition="opacity 300ms" still transition=noneExamplea whole program
app "Inbox"state unread = 0root title=(unread > 0 ? `(${unread}) Inbox` : "") badge=unreadaction signOut unread = 0 title("Signed out") badge(0)row gap=8 padding=16 button "One more" press={unread = unread + 1} button "Read them" press={unread = 0} button "Sign out" press=signOutDrawn before it arrives#
The screen's edges#
Examplea whole program
app "Shop" edges=covercolumn min-height=100vh padding="max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 96px max(16px, env(safe-area-inset-left))" text "Cabinets"row position=fixed left=0 right=0 bottom=0 padding=12 padding-bottom="max(12px, env(safe-area-inset-bottom))" background=card button "Save"A shared link#
Examplea whole program
app "Shop" "Cabinets drawn by you, cut by shops near you."text "Welcome"Examplea whole program
app "Shop" "Cabinets drawn by you."server fn price(sheets: number): number = sheets * 42column gap=8 padding=16 row gap=8 link "Home" href="/" link "Pricing" href="/pricing" route "/" text "Welcome" route "/pricing" title="Pricing · Shop" description="What a cut costs, by the sheet." image="pricing.png" text "Pricing" button "Share" press=share()In front, and at it#
Examplea whole program
state unread = 0server fn here(state: string): number return 1// Presence: "active" while the page is in front and somebody is at it.derive presence = screen.visible && !screen.idle(120000) ? "active" : "away"watch presence here(presence) else 0column gap=8 padding=16 text `You are ${presence}` text (screen.focused ? "This window has the keyboard" : "Another window has the keyboard") text `${unread} unread` font-weight=(screen.visible ? 400 : 700)Keeping the screen on#
Examplea whole program
state said = ""action work screen.awake(true) else none said = "working, with the screen kept on"action done screen.awake(false)? said = "done"button "Begin" press=workbutton "Done" press=donetext saidPrint and the whole screen#
Examplea whole program
state sheet: element? = nonecolumn gap=8 padding=16 row gap=8 print display=none button "Print" press={screen.print()} button "Print the invoice only" press={screen.print(sheet)} button (screen.full ? "Leave full screen" : "Fill the screen") press={screen.fullscreen(!screen.full)} column ref=sheet padding=24 background=card print width=190mm background=#ffffff text "Invoice 42" font-size=24 text "Two doors, hung"HTML attributes#
Examplea whole program
state preview = "<h1>Hello</h1>"column iframe sandbox srcdoc=preview width=320 height=200 iframe src="https://example.com/" sandbox="allow-scripts" allow="fullscreen" allowfullscreen width=320 height=200Binding#
Examplea whole program
shape Note id: string title: stringstate notes: Note[] = [{id: "a", title: "One"}, {id: "b", title: "Two"}]state sel = "a"state volume = 5derive open = notes.find(n => n.id == sel)column gap=8 padding=16 select value=sel for n in notes key=n.id option n.title value=n.id if open input value=open.title input type=range min=0 max=10 value=volume text `${volume * 10}%`Control#
Examplea whole program
shape Planet id: string name: string moons: numberstate planets: Planet[] = [{id: "e", name: "Earth", moons: 1}, {id: "m", name: "Mars", moons: 2}]state id = "e"state tab = "list"column gap=8 padding=16 row gap=8 button "List" press={tab = "list"} button "One" press={tab = "one"} match tab "list" for p, i in planets key=p.id row gap=8 text `${i + 1}.` button p.name press={id = p.id} else let p = planets.find(x => x.id == id) if p text `${p.name} has ${p.moons} moons` else text "No such planet" color=dangertry#
Examplea whole program
state rows: json = [3, 1, 2]fn biggest(rows: json): number return rows.reduce((a, b) => a > b ? a : b)component Chart(rows: json) text `${rows.length} rows, the biggest ${biggest(rows)}`column gap=8 padding=16 try Chart rows=rows else err text `This chart could not be drawn: ${err.words}` color=danger button "Try again" press={rows = [1]; again()} button "Break it" press={rows = none}Long lists#
Examplea whole program
shape Post id: string words: stringstate posts: Post[] = Array.from({length: 100000}, (x, i) => ({id: `p${i}`, words: "word ".repeat(1 + i % 40)}))column height=480 overflow-y=auto for p, i in posts key=p.id virtual column padding=8 gap=4 border-bottom="1px solid" border-bottom-color=line text `${i + 1}` font-weight=600 text p.wordsGroups and their heads#
Examplea whole program
shape Contact id: string name: string head: boolfn contacts(): Contact[] let out: Contact[] = [] for c in "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split("") out.push({id: c, name: c, head: true}) for n in ["Ada", "Ben", "Cy", "Di", "Ed", "Flo", "Gus", "Hal", "Ivy", "Jo"] out.push({id: `${c}-${n}`, name: `${c}. ${n}`, head: false}) return outstate people = contacts()column height=400 overflow-y=auto for c in people key=c.id virtual sticky=c.head if c.head text c.name position=sticky top=0 z-index=1 background=card padding="4px 12px" font-weight=600 else text c.name padding="8px 12px" border-bottom="1px solid" border-bottom-color=lineTables and wide grids#
Examplea whole program
state cols = Array.from({length: 300}, (x, i) => `c${i}`)state rows = Array.from({length: 5000}, (x, i) => i)state edits: json = {}view height=480 overflow=auto table border-collapse=separate border-spacing=0 table-layout=fixed thead tr th "#" position=sticky top=0 left=0 z-index=3 background=bg width=60 for c in cols key=c virtual=100 th c position=sticky top=0 z-index=2 background=bg width=100 tbody for r in rows key=r virtual=32 tr height=32 td `${r}` position=sticky left=0 z-index=1 background=bg width=60 for c in cols key=c virtual=100 td width=100 input value=(edits[`${r}.${c}`] ?? "") input={edits[`${r}.${c}`] = it} width=96 border=noneData that comes a page at a time#
Examplea whole program
model Order number: int customer: string total: number index numbershape Line number: int customer: string total: numberstate total = 0state rows: json[] = []state asked: json = {}server fn orderCount(): int return Order.count({})?// A hundred orders from a place, in the order of `number` (its index makes the offset a walk along it).server fn ordersFrom(from: int): Line[] return sql.run(sql.open("app")?, "select number, customer, total from \"Order\" order by number limit 100 offset ?", [from])?task total = orderCount()? rows = Array.from({length: total}, x => none)action want(i: number) let from = i - i % 100 if asked[from] return asked[from] = true let got = ordersFrom(from)? let j = 0 while j < got.length rows[from + j] = got[j] j += 1column height=480 overflow-y=auto for o, i in rows virtual=36 if o row height=36 gap=12 align-items=center padding="0 12px" text `#${o.number}` width=80 text o.customer flex=1 text `${o.total}` else row height=36 align-items=center padding="0 12px" color=dim seen={if it.visible want(i)} text "…"Routes#
Examplea whole program
state visits = 0column gap=12 padding=16 row gap=12 link "Home" href="/" link "Mars" href="/planet/mars" button "Venus" press={go("/planet/venus")} button "Back" press={back()} route "/" text "Home" route "/planet/:id" text `Planet ${id}` task visits += 1 route "*" text `Nothing at ${route.path}` text `${visits} planets visited` color=dimRoutes as paths#
Examplea whole program
app "Shop" routes=pathscolumn gap=12 padding=16 row gap=12 link "Home" href="/" link "Mars" href="/planet/mars" link "Plans" href="#plans" button "Venus" press={go("/planet/venus")} route "/" text "Home" text "Plans" id="plans" margin-top=1200 route "/planet/:id" text `Planet ${id}`The fragment#
Examplea whole program
app "Vault" routes=paths// Held by the page, in memory, and nowhere else.state key = ""task key = route.takeFragment()column gap=8 padding=16 text (key == "" ? "Open your link to unlock" : "Unlocked") button "Send it on" press={go(`https://mail.example.com/#${key}`)}Unsaved work#
Examplea whole program
state draft = ""state saved = ""root unsaved=(draft != saved)column gap=8 padding=16 textarea value=draft button "Save" press={saved = draft} link "Elsewhere" href="/elsewhere" route "/elsewhere" text "Elsewhere"Components#
Examplea whole program
component Badge(label: string, tone: string?) text label color=(tone ?? "fg") border="1px solid" padding="2px 8px" border-radius=999component Go(press: () => none) button press=press slotcomponent Switch(on: bool) button (on ? "on" : "off") press={on = !on}component Card(title: string) column gap=8 padding=16 background=card border-radius=12 text title font-weight=600 slotstate dark = falsestate saved = 0action save saved += 1column gap=8 padding=16 Badge label="New" tone="danger" Badge label="plain" Go "Save" press=save Switch on=dark Card title="Names" width=100% id="names" text "inside" text `${dark} ${saved}`Popover and tip#
Examplea whole program
state open = falseaction rename toast("Renamed")button "Options" popover placement="bottom-start" open=open button "Rename" press=rename data-close="" tip "More to do with this"Icons#
Examplea whole program
shape Tab name: string glyph: stringcomponent HeadLink(label: string, glyph: string) row gap=6 icon glyph size=16 text labelstate tabs: Tab[] = [{name: "Files", glyph: icon("file")}, {name: "People", glyph: icon("users")}]state lock = falsecolumn gap=4 for t in tabs HeadLink label=t.name glyph=t.glyph HeadLink label="Door" glyph=(lock ? icon("lock") : icon("lock-open")) button "Lock" press={lock = !lock}Pictures and assets#
Refused#
Pitfalls#
In the source#
Edit this page:
docs/markup.md