Controls#
Controls are the parts a view is built from. They come from the core catalog, which the definition names under uses.catalogs (alias core), and a node names one as core:button. This topic says which control to reach for, then lists every control with its props, events and slots.
Which control#
| You want to | Use |
|---|---|
| Lay parts out one after another, or side by side | core:stack with direction |
| Lay out equal columns, such as figures or cards | core:grid with columns |
| Gather related parts under a title | core:group |
| Show one of several panels | core:tabs, each child a core:group whose title names its tab |
| Ask something on top of the view | core:dialog, with open bound to view state |
| Show words | core:text, core:heading |
| Show one key figure | core:stat |
| Show progress toward a target | core:progress |
| Mark a status or a count | core:badge with a tone |
| Say that something failed, needs attention, or worked | core:alert with a tone |
| Show a simple list | core:list with an item slot |
| Show records to compare, sort and pick | core:table with columns |
| Show how numbers compare or change | core:chart |
| Explain how parts connect: an architecture, a flow, a process | core:diagram: give boxes and connections, never positions; the host lays them out |
| Let a person type text, a number or a date | core:textInput, core:numberInput, core:dateInput |
| Let a person pick | core:toggle (on or off), core:choice (one option), core:multiChoice (several), core:slider (a number in a range) |
| Let a person pick a color or a tool | core:choice with a swatch or an icon on every option |
| Let a person attach a file or take a photo | core:fileInput (needs no permission) |
| Gather inputs that are sent together | core:form, with submit and cancel |
| Start something | core:button |
| Go to another view, or to a web address | core:link |
| Draw a game or a custom picture that is not boxes and connections | core:canvas |
Things to know:
- Inputs. Every input control has a bindable
valueand raiseschangewithevent.value. Bindvalueto view state inside a form, or handlechangewith arun. - Labels. Inputs, tables, charts and buttons need a
label: it is what the person reads and what assistive technology announces. - Numbers.
stat,progress,numberInput,sliderand table columns take aformat(plain,currency,percent). Percent values are fractions:0.25shows as 25%. - Money. Give
"format": "currency"and leavecurrencyout: the host uses the person's currency,env.currency, and shows a plain number when it knows none (the reference host never guesses one). Name a code only when the person named their currency, and never write"=env.currency"in a table column (seemistakes). - Choices.
optionsis a list of maps withvalueandlabel. The bound value is the picked option'svalue, with its own type. Make the options from a list withmap:
JSON
{ "control": "core:choice", "props": { "label": "Item", "options": "=state.items.map(i, {value: i.id, label: i.name})" } }
- Colors and tools. A choice of colors or of tools is a
core:choicewhose options all carryswatch(a color name, as a canvas shape'sfilltakes) oricon: the host draws up to 12 as small color dots or tool buttons, one picked. A look says "color palette" or "symbol palette" with each option's color or symbol in parentheses, or "not a palette" and why. Never draw a picker on a canvas (seemistakes). A canvas's own tools go in itstoolsslot, in a vertical stack: such choices and icon-only buttons are drawn in a strip beside the surface, and a slider or another input placed there (a pen size) in a bar under it.
JSON
{ "control": "core:choice", "props": { "label": "Pen", "options": [ { "value": "black", "label": "Black", "swatch": "text" }, { "value": "teal", "label": "Teal", "swatch": "accent" } ] } }
- Drawing along a drag. A canvas's
pointerevent has aphase:downat the press,movefor each move while pressed, thenup, orcancelwhen the gesture is lost. A pen stroke is onepathshape. Atdownstart a stroke in view state with anid(uuid()) and one point,{x: event.x, y: event.y}; at eachmoveappend the point to it; atuporcanceladd the stroke to the list and clear it. Let the scene draw each stroke, and the one in progress, as one path, so the line shows while it is drawn and a press alone leaves a dot. An eraser takes away the stroke whoseidisevent.target, the named shape under the pointer. Never build a stroke from onelineper move: a canvas draws at most 5000 shapes and 50000 path points and an expression has a budget, and such a stroke meets them within a minute of drawing.
(state.ink + (view.stroke == null ? [] : [view.stroke])).map(s, {kind: 'path', id: s.id, points: s.points, stroke: s.color, strokeWidth: 0.006})
- Keys for a game. A canvas hears the keys in its
keysonce the person presses it or tabs to it, and when it gives way to another canvas withkeys(bywhen, as a part's view or in the next view) the keys follow, so a game needs no "click to continue" between its screens. - Round and curved shapes. Draw a shape as what it is: a tile with rounded corners is a
rectwithradius, a stretched circle anellipse, a gauge or a ring of progress anarc(fromandtoin degrees clockwise from pointing right, so a ring of progress runs from-90to-90 + 360times the share done), and a piece of a pie anarcwith afill. A smooth line or outline is apathwhose points carry control points:cxandcyfor a gentle bend,c1x,c1y,c2xandc2yfor an S or a precise curve. Every line takesdash(dashed,dotted),capandjoin; a text takes"weight": "emphasis"to stand out. - Colors on a canvas. A color is named by its role, such as
textfor ink: the host draws it in the page's light or dark mode. A color is a name of the design's (surface, surfaceRaised, surfaceSunken, text, textMuted, border, outline, accent, onAccent, focus, neutral, info, success, warning, danger, category1 to category8); a hex value or a CSS name such as "red" or "none" is not one: the host paints another color in its place, and the look names it. No fill or no stroke is afillorstrokeleft out. Give the canvas amodeonly when its colors must never change, as in a drawing that is printed. - Symbols and motion. A figure a scene shows many times (a block of a game with its light and shade, a playing piece, a marker) is a symbol: write it once in the canvas's
symbols, around its origin, in units of the width, with"fill": "given"on the part that takes a color, and place it with auseof its ownx,y,scale,rotationandcolor. Agroupmoves, turns and scales shapes as one: a board of cells is a group scaled to one cell, its blocks placed at their column and row. For motion, give the canvas"motion": "standard"and each shape that moves anid: when the state changes, the host glides it to its new place. A piece a rule moves step by step keeps an even pace with{ "over": "PT0.3S", "ease": "linear" }at the rule's interval. A scene paints in order, so draw a label after the piece it stands on: the look names texts later shapes may cut.
{kind: 'group', x: 0.3, y: 0.05, scale: 0.04, shapes: state.cells.map(c, {kind: 'use', symbol: 'block', x: c.col, y: c.row, color: c.color})}
- Gradients and shadows. A
fillmay run between colors,{gradient: 'linear', stops: ['category1', 'accent']}(top to bottom;angle0 runs left to right) orradialfrom the middle out, and a stop{color: 'surface', opacity: 0}fades to nothing, so a shine is a second shape over a plain one. Ashadowof'low','medium'or'high'lifts a shape, a group or a placement. They serve the few things a person picks up or that catch the light, one level for things of one kind; on every shape, or between unrelated colors, they spoil a drawing. A host that draws neither shows the first stop and no shadow, so put the main color first. - Charts. Say what the numbers are:
unitfor what they count ("hours","kg"; money and percentages takeformatinstead) andvalueLabelfor what they are, withcategoryLabelfor the categories. For a ranking or long category names, lay bars on their side with"orientation": "horizontal". Show a target on a bar, line or area chart with"goal": { "value": 40, "label": "Weekly target" }. A pressed bar, point or slice is kept inselectedas{ "item": "Mar", "series": "hours" }, the record named by itscategoryor byitemKey: bind it to view state, and set that tonullwhen the app forgets the pick, so the outline goes with the words. In aselecthandlerevent.selectedisnullwhen the press or Escape cleared the selection, so words about the pick check it first. - Tables. With
completetrue (the default) the host sorts and pagesitemsitself.selectedholds theitemKeyvalues of picked rows. A column shows its field as it is. For a stored code in words, give each element the words in a field of their own (seeflows), or draw them in thecellslot of a"format": "custom"column, as the reading list does. - Items that move between lists. When a person moves items from list to list, such as the cards of a board between its columns, give the lists one
moveGroupand each alabel, and handlemoveon each by changing the field the lists filter on to that list's own (made witheach, the column's). When a person keeps items in an order of their own, such as priorities or the cards of a column, make the listreorderableand keep the ordermovegives:{ "set": "state.books", "to": "=state.books.sortBy(b, indexOf(event.order, b.id))" }. Shared state is set in an action passedevent.order. Such a list shows its items in the order the app keeps them, so sort them by nothing else. The host gives every item its own Move control, so draw no buttons that move an item between those lists or up and down. - Images.
core:imagesourceand a canvasimageshape are remote props. A picture that is part of the app (a header photo, a logo, the sprites of a game) is added first with the tool add_asset, then named as"asset:<name>"(an asset nothing names yet is only a warning): the app carries it, so it shows in the chat too and asks nothing. A picture that differs for each record stays a web address, which needs a grant (seecapabilities) and does not show in a chat. At most 64 pictures, each a PNG, JPEG, WebP or GIF of at most 768 KB and 4096 pixels a side, 1.875 MB in all; a picture from the web is not shrunk, so where a library's page offers smaller sizes (Wikimedia Commons, Unsplash, Pexels, Pixabay), take one, and givecreditwhen the license asks. A person's own photo given by path that is too large, or a HEIC, is made smaller on a Mac; elsewhere, ask the person to save it at 2048 pixels on its longer side first. add_asset removes the place where a photo was taken. - Formatted text. Text that arrives formatted, such as a model's reply, notes people write or a description from a service, often uses Markdown. Give its
core:text"format": "markdown": the host draws its headings, lists, tables, code and links, the same on every host, and shows anything else, HTML included, as its characters. Keep the app's own labels and sentences plain, and never join strings to put marks such as two asterisks or a hash around your own words:style,core:heading,core:badgeandcore:groupdo that. A link in it is followed as acore:linkwith aurlis.
JSON
{ "control": "core:text", "props": { "value": "=item.summary", "format": "markdown" } }
- Variants.
variantnames a preset of props from the design system. You can always set the props themselves instead, which works with every design system.
Icon names every host knows (for icon props, meta.icon and a main section's icon): add, remove, edit, delete, close, check, search, filter, sort, menu, more, back, forward, up, down, home, settings, user, users, calendar, clock, location, camera, image, file, attach, download, upload, share, copy, link, mail, phone, chat, notification, star, heart, info, help, warning, error, success, lock, play, pause, stop, refresh, chart, dashboard, list, table, folder, tag, inbox, money, undo, redo, eraser, line, rectangle, ellipse, text, pointer, hand, fill. A name the host does not know shows no symbol, and the check warns about it (value.notKnown).
Every control#
Every control also takes variant, hidden and disabled. "Required" props must be set in props or bound in bind. A bindable prop can be bound; a remote prop can make the host fetch from the network, unless it is "asset:<name>".
Types the props use:
Spacing: "small" | "medium" | "large"Emphasis: "high" | "medium" | "low"Tone: "neutral" | "info" | "success" | "warning" | "danger"NumberFormat: "plain" | "currency" | "percent"ChoiceValue: string | number | booleanChoiceOption:valueChoiceValue,labelstring,description? string,icon? IconName,swatch? stringTrend:direction"up" | "down" | "flat",label? string,sentiment? "positive" | "negative" | "neutral"TableColumn:fieldstring,labelstring,format? "text" | "number" | "currency" | "percent" | "date" | "datetime" | "boolean" | "custom",currency? string,sortable? booleanSortKey:fieldstring,direction"asc" | "desc"ChartSeries:fieldstring,labelstring,color? string,format? NumberFormat,unit? stringChartGoal:valuenumber,label? stringChartValue:itemstring | number | boolean,seriesstringShape: one of these, told apart bykind: "rect" (id? string,xnumber,ynumber,widthnumber from 0,heightnumber from 0,radius? number from 0,fill? Fill,stroke? string,strokeWidth? number from 0,dash? "solid" | "dashed" | "dotted",cap? "round" | "flat" | "square",join? "round" | "sharp" | "bevel",rotation? number,opacity? number 0 to 1,motion? Motion,shadow? Shadow); "circle" (id? string,xnumber,ynumber,rnumber from 0,fill? Fill,stroke? string,strokeWidth? number from 0,dash? "solid" | "dashed" | "dotted",cap? "round" | "flat" | "square",opacity? number 0 to 1,motion? Motion,shadow? Shadow); "ellipse" (id? string,xnumber,ynumber,radiusXnumber from 0,radiusYnumber from 0,fill? Fill,stroke? string,strokeWidth? number from 0,dash? "solid" | "dashed" | "dotted",cap? "round" | "flat" | "square",rotation? number,opacity? number 0 to 1,motion? Motion,shadow? Shadow); "arc" (id? string,xnumber,ynumber,radiusnumber from 0,fromnumber,tonumber,stroke? string,strokeWidth? number from 0,fill? Fill,dash? "solid" | "dashed" | "dotted",cap? "round" | "flat" | "square",join? "round" | "sharp" | "bevel",opacity? number 0 to 1,motion? Motion,shadow? Shadow); "line" (id? string,xnumber,ynumber,x2number,y2number,stroke? string,strokeWidth? number from 0,dash? "solid" | "dashed" | "dotted",cap? "round" | "flat" | "square",opacity? number 0 to 1,motion? Motion,shadow? Shadow); "path" (id? string,pointslist,stroke? string,strokeWidth? number from 0,fill? Fill,closed? boolean,dash? "solid" | "dashed" | "dotted",cap? "round" | "flat" | "square",join? "round" | "sharp" | "bevel",opacity? number 0 to 1,motion? Motion,shadow? Shadow); "text" (id? string,xnumber,ynumber,textstring,size? number from 0,align? "start" | "center" | "end",weight? "body" | "emphasis",fill? Fill,rotation? number,opacity? number 0 to 1,motion? Motion,shadow? Shadow); "image" (id? string,xnumber,ynumber,widthnumber from 0,heightnumber from 0,sourcestring,rotation? number,opacity? number 0 to 1,motion? Motion,shadow? Shadow); "group" (id? string,x? number,y? number,scale? number from 0,rotation? number,opacity? number 0 to 1,motion? Motion,shadow? Shadow,shapesShape[]); "use" (symbolstring,id? string,color? string,x? number,y? number,scale? number from 0,rotation? number,opacity? number 0 to 1,motion? Motion,shadow? Shadow)PathPoint:xnumber,ynumber,cx? number,cy? number,c1x? number,c1y? number,c2x? number,c2y? numberFill: string (A color token name, such as accent or category2), or {gradient"linear" | "radial",angle? number,stopsGradientStop[] }GradientStop: string (A color token name, fully opaque), or {colorstring,opacity? number 0 to 1,at? number 0 to 1 }Shadow: "low" | "medium" | "high"Motion: string (none, or the name of a motion token of the design system: quick, standard or slow in the default one), or {overstring,ease? "smooth" | "linear" }FileKind: "image" | "video" | "audio" | "document" | "spreadsheet" | "text" | "any"FileRef:idstring,namestring,mediaTypestring,size? integer from 0,uri? string
core:stack#
Arrange parts one after another, down the view or across it.
- Props:
direction"vertical" | "horizontal" (default "vertical");gapSpacing (default "medium");align"start" | "center" | "end" | "stretch" (default "stretch"). - Children: many.
core:grid#
Arrange parts in equal columns, filling row by row.
- Props:
columnsinteger 1 to 6 (default 2);gapSpacing (default "medium"). - Children: many.
core:group#
A titled section that gathers related parts, such as the fields of an address or the figures for one month.
- Props:
titlestring (required);descriptionstring;emphasisEmphasis (default "medium"). - Slots:
actions, one node drawn once, which reads the names around the control. - Children: many.
core:tabs#
Show one of several panels at a time, with a tab for each that its panel names, so each child is usually a group whose title names its tab.
- Props:
selectedinteger (bindable, default 0);labelstring. - Events:
changewitheventholdingvalueinteger. - Children: many.
core:dialog#
Ask for a person's attention or a short decision on top of the current view, without leaving it.
- Props:
openboolean (bindable, default false);titlestring (required);dismissibleboolean (default true). - Events:
dismisswith no payload. - Children: many.
core:divider#
Separate groups of content with a visible break.
- Props:
labelstring.
core:text#
Show a piece of text, such as a sentence, a value or a note.
- Props:
valuestring (required);style"body" | "caption" | "emphasis" (default "body");format"plain" | "markdown" (default "plain").
core:heading#
Title a view or a section of one, so people can scan and navigate by headings.
- Props:
valuestring (required);levelinteger 1 to 3 (default 2).
core:image#
Show a picture, such as a photo, an illustration or a picked image file.
- Props:
sourcestring (remote, required);altstring (required);fit"contain" | "cover" (default "contain");size"small" | "medium" | "large" | "fill" (default "fill").
core:icon#
Show a small symbol named by meaning, such as add, delete, warning or search.
- Props:
nameIconName (required);labelstring.
core:badge#
Mark something with a short status or count, such as New, Overdue or 3.
- Props:
labelstring (required);toneTone (default "neutral").
core:stat#
Show one key figure with its name and, optionally, which way it is moving.
- Props:
labelstring (required);valuenumber | string (required);formatNumberFormat (default "plain");currencystring;trendTrend.
core:progress#
Show progress toward a numeric target, or that work is under way when the amount is unknown.
- Props:
valuenumber?;maxnumber (default 100);labelstring (required);formatNumberFormat (default "plain");currencystring.
core:alert#
Tell a person something important in place: that an action failed, that something needs attention, or that something worked.
- Props:
titlestring (required);messagestring;toneTone (default "info");dismissibleboolean (default false). - Events:
dismisswith no payload. - Slots:
actions, one node drawn once, which reads the names around the control.
core:textInput#
Let a person enter text: a name, an email address, a note or a longer description.
- Props:
valuestring? (bindable);labelstring (required);hintstring;multilineboolean (default false);kind"text" | "email" | "phone" | "url" | "secret" (default "text");requiredboolean (default false);maxLengthinteger from 1;errorstring?. - Events:
changewitheventholdingvaluestring?.
core:numberInput#
Let a person enter a number, such as an amount of money, a quantity or a percentage.
- Props:
valuenumber? (bindable);labelstring (required);hintstring;minnumber;maxnumber;stepnumber from 0;formatNumberFormat (default "plain");currencystring;requiredboolean (default false);errorstring?. - Events:
changewitheventholdingvaluenumber?.
core:dateInput#
Let a person choose a calendar date, a date and time, or a time of day, such as a due date, an appointment or an alarm.
- Props:
valuestring? (bindable);mode"date" | "datetime" | "time" (default "date");labelstring (required);hintstring;minstring;maxstring;requiredboolean (default false);errorstring?. - Events:
changewitheventholdingvaluestring?.
core:toggle#
Let a person turn one setting on or off.
- Props:
valueboolean (bindable, default false);labelstring (required);hintstring. - Events:
changewitheventholdingvalueboolean.
core:choice#
Let a person pick exactly one option from a list.
- Props:
valueChoiceValue? (bindable);optionsChoiceOption[] (required);labelstring (required);hintstring;requiredboolean (default false);errorstring?. - Events:
changewitheventholdingvalueChoiceValue?.
core:multiChoice#
Let a person pick any number of options from a list, such as tags or days of the week.
- Props:
valueChoiceValue[] (bindable, default []);optionsChoiceOption[] (required);labelstring (required);hintstring;requiredboolean (default false);errorstring?. - Events:
changewitheventholdingvalueChoiceValue[].
core:slider#
Let a person set a number within a fixed range by feel, such as volume, a rating or a budget split.
- Props:
valuenumber (bindable, default 0);labelstring (required);minnumber (default 0);maxnumber (default 100);stepnumber from 0 (default 1);formatNumberFormat (default "plain");currencystring. - Events:
changewitheventholdingvaluenumber.
core:fileInput#
Let a person attach files, or take a photo or recording with the device, for example to add a receipt to an expense.
- Props:
valueFileRef[] (bindable, default []);labelstring (required);acceptFileKind[] (default ["any"]);multipleboolean (default false);capture"none" | "camera" | "microphone" (default "none");requiredboolean (default false);errorstring?. - Events:
changewitheventholdingvalueFileRef[].
core:form#
Gather related inputs into one unit that is submitted together, and report whether every input is acceptable.
- Props:
labelstring;submitLabelstring;cancelLabelstring. - Events:
submitwith no payload;cancelwith no payload. - Outputs (bind them to read them):
validboolean. - Children: many.
core:button#
Let a person start something: save, send, add, delete, start a game.
- Props:
labelstring (required);emphasisEmphasis (default "medium");iconIconName;destructiveboolean (default false);iconOnlyboolean (default false). - Events:
presswith no payload.
core:link#
Take a person somewhere: another view of this app, or a web address outside it.
- Props:
labelstring (required);viewstring;inputany;urlstring. - Events:
activatewith no payload.
core:list#
Show a collection of items one after another, each drawn by the item template, and let a person pick one, move one to another list, or put one at a place of their choosing.
- Props:
itemsany[] (required);itemKeystring (default "id");labelstring;emptystring;moveGroupstring;reorderableboolean (default false). - Events:
selectwitheventholdingitemany,indexinteger;movewitheventholdingitemany,indexinteger?,orderany[]?. - Slots:
item(required), whose node readsitem,index;actions, one node drawn once, which reads the names around the control.
core:table#
Show records as rows with named columns so people can compare, sort, select and page through them.
- Props:
itemsany[] (required);columnsTableColumn[] (required);labelstring (required);itemKeystring (default "id");completeboolean (default true);sortSortKey? (bindable);pageSizeinteger from 1;pageinteger from 1 (bindable, default 1);totalinteger from 0;selection"single" | "multiple" (default "single");selectedany[] (bindable, default []);emptystring. - Events:
selectwitheventholdingitemany,indexinteger,selectedany[];sortwitheventholdingfieldstring,direction"asc" | "desc";pagewitheventholdingpageinteger. - Slots:
cell, whose node readsitem,index,column,value;actions, one node drawn once, which reads the names around the control.
core:chart#
Show how numbers compare or change, drawn from a list of records.
- Props:
kind"bar" | "line" | "area" | "pie" | "scatter" (required);itemsany[] (required);categorystring (required);seriesChartSeries[] (required);labelstring (required);stackedboolean (default false);formatNumberFormat (default "plain");currencystring;unitstring;categoryLabelstring;valueLabelstring;orientation"vertical" | "horizontal" (default "vertical");goalChartGoal;selectedChartValue? (bindable, default null);itemKeystring. - Events:
selectwitheventholdingitemany,seriesstring,selectedChartValue?. - Slots:
actions, one node drawn once, which reads the names around the control.
core:canvas#
A drawing surface for casual games and custom visuals.
- Props:
sceneShape[] (remote, required);labelstring (required);summarystring;aspectnumber 0.1 to 10 (default 1);backgroundstring;mode"light" | "dark";keysstring[] (default []);symbolsobject (remote);motionMotion (default "none"). - Events:
pointerwitheventholdingphase"down" | "move" | "up" | "cancel",xnumber,ynumber,targetstring?;keywitheventholdingkeystring,phase"down" | "up",repeatboolean. - Slots:
actions, one node drawn once, which reads the names around the control;tools, one node drawn once, which reads the names around the control.
core:diagram#
Explain how parts connect: an architecture, a flow or a process.
- Props:
boxesDiagramBox[] (required);connectionsDiagramConnection[] (default []);groupsDiagramGroup[];selectedstring? (bindable, default null);highlightstring[] (default []);labelstring (required);summarystring. - Events:
selectwitheventholdingboxDiagramBox?,selectedstring?. - Slots:
actions, one node drawn once, which reads the names around the control.
Next#
viewsfor nodes, bindings and handlers.capabilitiesfor what the app uses outside the screen.