Views#
The visual surface is the app's screens. A view shows state through controls and starts actions from their events; it holds no logic of its own.
A view with a form#
JSON
{
"title": "Add a book",
"state": {
"title": { "type": "string?", "description": "The title being typed." },
"author": { "type": "string?", "description": "The author being typed." }
},
"body": {
"control": "core:form",
"props": { "submitLabel": "Add", "cancelLabel": "Cancel" },
"on": {
"submit": [
{ "run": "addBook", "with": { "title": "=default(view.title, '')", "author": "=default(view.author, '')" } },
{ "navigate": "back" }
],
"cancel": { "navigate": "back" }
},
"children": [
{ "control": "core:textInput", "props": { "label": "Title", "required": true }, "bind": { "value": "view.title" } },
{ "control": "core:textInput", "props": { "label": "Author" }, "bind": { "value": "view.author" } }
]
}
}
stateis view state: values that belong to this visit of the view, read and written asview.title. Each visit starts fresh, and the values are gone when the view closes. A view state entry hastype,descriptionand an optionalinitial, worked out as the view opens. Unlike a stored entry'sinitial, which reads onlyenv, it may readstate,user,envand the view's input, asview.id.bindties a control's value to a place: what the person types is written there, and the control shows what is there.on.submitruns the action, then goes back. The form raisessubmitonly when every input in it is acceptable (arequiredinput is filled, a number is withinminandmax).- When the action fails, the handler stops: it does not go back, and the form shows the action's message, such as a
requireentry's. No error plumbing is needed.
The surface#
surfaces.visual has start (the first view), views (by name) and, optionally, navigation: the app's main sections, in order.
JSON
[
{ "view": "mine", "label": "My time off", "icon": "calendar" },
{ "view": "decide", "label": "To decide", "icon": "check", "when": "'approver' in user.roles" }
]
A section's when decides whether it is offered, never what is allowed: guards on the actions decide that. with opens the section's view with input, as a navigate step's with does, and must give every required input. count shows a number beside the label and is hidden at 0. Without navigation the app has no main sections.
Sections can come from the app's own data. A section with each is offered once for every element of its list, named by as and told apart by key; its label, count and with read the element. A group stands its sections under a heading. The notes app offers one section for each notebook, under the heading Notebooks:
JSON
{
"group": "Notebooks",
"sections": [
{ "each": { "in": "state.notebooks", "as": "book", "key": "book.id" }, "view": "notebook", "with": { "id": "=book.id" }, "label": "=book.name", "icon": "file", "count": "=size(state.notes.filter(n, n.notebook == book.id))" },
{ "view": "newNotebook", "label": "New notebook", "icon": "add" }
]
}
Repeat sections for places a person goes to and stays in, such as notebooks, channels or projects, when there are few enough to scan, and always give each a key, so that the chosen section stays chosen when the list changes. Records a person searches, sorts or acts on, such as notes, orders or tickets, belong in a list inside a view. Give every section an icon: a host may show the navigation as icons alone, and a section without one is then the first letter of its label.
A view has title (text or = expression), input (a field map of what it is opened with, read as view.id), state and body. View state and input names must differ (name.collision). The host draws the title as the heading of the page or of the card, so the body does not begin with a core:heading that says it again (view.headingRepeatsTitle).
An app with one view and no navigation is drawn as one card, not as a page: give the view a title, which heads the card, and make the one thing the app shows its body. When the body is a canvas, chart, table, list or diagram with a label, or a group with a title, that control's own card is the app's card and its head shows the view's title. Without a view title the card is headed by the app's name.
Nodes#
The body is a tree of nodes. A node names a control from the catalog (see controls) and may have:
| Field | What it is |
|---|---|
props |
The control's props: a literal, or = and an expression. |
bind |
Props tied two-way to a path, or outputs written to one. |
on |
Event name to a step or a list of steps. event holds the event's payload. |
children |
Nodes inside, for controls that take children (stack, grid, group, tabs, dialog, form). |
slots |
A node used as a template, such as a list's item. |
when |
An expression: the node exists only while it is true. |
each |
An object with in (a list), as (a name) and key: the node repeats once per element. |
id |
A name for the node, unique in the view. |
fallback |
A node to draw instead when a host lacks the control. |
Use when to leave a node out; hidden keeps its place and what was typed in it; disabled shows it but takes no input.
A prop the control requires must be set or bound (prop.missing); a prop it does not have is prop.unknown.
Lists of things#
To show a list, give a core:list or core:table its items. A slot is the template for one element, with item the element, as in the groceries app in start.
A table shows columns of fields; a column with "format": "custom" is drawn by the table's cell slot, which reads value (the field's value), item and column.
One record opened from a list#
Most apps with records have a list of them and a view for one. Picking a row of the reading list's table raises select with event.item, the record, and opens the book view with its id:
JSON
{ "select": { "navigate": "book", "with": { "id": "=event.item.id" } } }
In a core:list, a button in the row does the same with item.id. The book view declares id under input and reads it as view.id. It shows the one record with a node's each over a list of one, which names it book for the nodes inside; when the book is removed, the list is empty and another node says so:
JSON
{ "in": "state.books.filter(b, b.id == view.id)", "as": "book", "key": "book.id" }
Its "Change" button opens the editBook view with the same id. There the form starts filled with the saved book, because each view state initial reads the record by the view's input:
JSON
{
"title": { "type": "string?", "initial": "=state.books.find(b, b.id == view.id).title", "description": "The title being typed." },
"author": { "type": "string?", "initial": "=state.books.find(b, b.id == view.id).author", "description": "The author being typed." }
}
Its form runs editBook, which patches the book, then goes back. A host may show the opened record beside the list on a wide screen; you write nothing for that.
When the rows of a table can be picked (selection), pressing a row picks it, so it cannot also open the record. Then open it from a core:link (or a button with "emphasis": "low") in the cell of the record's name: give that column "format": "custom", draw the link in the table's cell slot with its view and input, and leave the row's press to picking.
A form in steps#
Sign-up, checkout or a request with several parts reads best one step at a time. The booking app keeps the step in view state (view.step, from 1) and gives each step a core:form that is there only on its step (when). A form raises submit only when its own inputs are acceptable, so "Next" goes on only once the step is filled in, and its cancel is "Back":
JSON
{
"control": "core:form",
"when": "view.step == 2",
"props": { "submitLabel": "Next", "cancelLabel": "Back" },
"on": { "submit": { "set": "view.step", "to": 3 }, "cancel": { "set": "view.step", "to": 1 } },
"children": [
{ "control": "core:choice", "props": { "label": "Room", "required": true, "options": [ { "value": "Harbor", "label": "Harbor, 4 seats" }, { "value": "Garden", "label": "Garden, 8 seats" }, { "value": "Hall", "label": "Hall, 12 seats" } ] }, "bind": { "value": "view.room" } }
]
}
The first step's cancel goes back to the list, and the last step's form runs the action and then goes back. A line of text above the forms says "Step 2 of 3"; a core:progress would do as well. What was typed in an earlier step stays in view state while its form is not shown.
Handlers#
A handler is what an event does: one step, or a list. It may hold only steps that stay with the person and the view: set, append, remove, patch, let, if, each, navigate, refresh and run. Everything else (a call, send, emit, code or return) belongs in an action, which the handler runs (view.handlerStep).
A handler writes view state and the person's own state directly, never a shared entry (write.sharedDirect). Pass the action what it needs in with: an action cannot read view.
Bindings#
bind maps a prop the control marks bindable (usually value) to a path: view.<name> for view state, or state.<name> for a stored entry that is not shared. A path may pick a list element with a selector: state.books[id=view.id].status. Bind outputs the same way: a form's valid output tells whether every input is acceptable.
Bind to view state for a form whose result goes through an action. Bind to the person's own state for a setting that should take effect as soon as it changes, such as a toggle for a preference.
Navigation#
{ "navigate": "book", "with": { "id": "=event.item.id" } } opens a view with its input; { "navigate": "back" } closes the current one. A navigate or core:link to a main section, with the section's input, goes to that section as choosing it in the navigation does; any other view opens on top of the current one, with a way back.
Showing what can be done#
Show a button only to someone who can use it, with can or canSend (see expressions), so that the screen follows the guards instead of copying them:
JSON
{ "control": "core:button", "when": "canSend('approval', 'approve', request.id)", "props": { "label": "Approve", "emphasis": "high" }, "on": { "press": { "run": "approve", "with": { "id": "=request.id" } } } }
Use grants.<name>.held and grants.<name>.declined to show what depends on a permission, and sources.<name>.status to show loading and errors (see state).
Layout#
Lay out with core:stack (one after another, direction vertical or horizontal), core:grid (equal columns) and core:group (a titled section). Spacing, sizes and colors are the design system's: a definition names no pixels, fonts or colors. Give the one main action of a view "emphasis": "high".
In a horizontal stack the first child, when it is a core:text, a core:heading or a core:stack, takes the room the others leave, so what follows sits at the end of the row, such as a title with a button after it. Children that one each repeats are drawn alike.
core:tabs shows one child at a time and names each tab by that child's label. Make each child a core:group: its title is the tab's name, and it is not drawn again in the panel. A child with nothing to name it, such as a plain core:stack, is only "Tab 1" (view.tabUnnamed).
JSON
{
"control": "core:tabs",
"children": [
{ "control": "core:group", "props": { "title": "Coming up" }, "children": [ { "control": "core:table", "props": { "label": "Coming up", "items": "=state.bookings.filter(b, b.day >= env.today)", "columns": [ { "field": "day", "label": "Day", "format": "date", "sortable": true }, { "field": "room", "label": "Room" } ], "empty": "Nothing booked." } } ] },
{ "control": "core:group", "props": { "title": "Past" }, "children": [ { "control": "core:table", "props": { "label": "Past", "items": "=state.bookings.filter(b, b.day < env.today)", "columns": [ { "field": "day", "label": "Day", "format": "date", "sortable": true }, { "field": "room", "label": "Room" } ], "empty": "No past bookings." } } ] }
]
}
Actions of one control#
What a person does with one chart, table, list, group, canvas or diagram (edit it, export it, add to it, choose its period) goes in that control's actions slot, which the host draws at the end of the control's header. The slot is for buttons and a choice whose options say what they are: the host shows no label there, so an input that needs its label goes in the content, and a canvas's own settings in its tools slot. What a person does with the whole view stays a button of the view. The weather app refreshes its forecast from the header of the list of days:
JSON
{ "control": "core:button", "props": { "label": "Refresh the forecast", "icon": "refresh", "iconOnly": true, "emphasis": "low" }, "on": { "press": { "refresh": "state.forecast" } } }
The slot holds one node: a button, or a horizontal core:stack of a few, such as a core:choice and a button. It reads what a child at its place would: state, view state and the names of an each around the control. A table, list or canvas with actions shows its label as the header's title. An alert takes the same slot for what to do about what it says, such as "Retry", drawn after its message. "iconOnly": true draws a button as its icon alone; its label stays its name and is shown when the pointer rests on it.
Next#
controlsfor every control with its props and events.actionsfor what handlers run.expressionsfor props andwhen.agentsfor what the same app gives an agent.