Skip to content

Inputs ​

Change local block state. Bind a control with value={$name}; see state and inputs.

tsx
import { useState } from 'react';
import { bound, ui } from '../shared/intelligent-ui-tree.ts';
import { DemoBlock } from '../shared/intelligent-ui.tsx';

export default function InputsDemo() {
    const [selected, setSelected] = useState<unknown>(['links']);
    const [notify, setNotify] = useState<unknown>(false);
    const [limit, setLimit] = useState<unknown>(20);
    const [scope, setScope] = useState<unknown>('failed');
    const [name, setName] = useState<unknown>('Ada');
    const [kind, setKind] = useState<unknown>('bug');
    const [note, setNote] = useState<unknown>('');

    // A Button's action runs on the block's state; here it puts the demo's values back.
    const reset = {
        ...ui('Button', {}, 'Reset'),
        onAction: () => {
            setSelected(['links']);
            setNotify(false);
            setLimit(20);
            setScope('failed');
            setName('Ada');
            setKind('bug');
            setNote('');
        }
    };

    return (
        <DemoBlock
            nodes={[
                bound(
                    ui(
                        'Checklist',
                        {},
                        ui('Item', { value: 'links' }, 'Fix the link parser'),
                        ui('Item', { value: 'preload' }, 'Make the bridge method optional')
                    ),
                    selected,
                    setSelected
                ),
                bound(ui('Switch', {}, 'Notify me when it lands'), notify, setNotify),
                bound(ui('Slider', { min: 10, max: 100, step: 10, unit: 'runs' }, 'Runs to compare'), limit, setLimit),
                bound(
                    ui('Segmented', { label: 'Tests to run' }, ui('Option', { value: 'failed' }, 'Failed'), ui('Option', { value: 'all' }, 'All')),
                    scope,
                    setScope
                ),
                bound(ui('TextField', { maxLength: 40, placeholder: 'Your name' }, 'Name'), name, setName),
                bound(ui('TextField', { maxLength: 200, placeholder: 'What should change', multiline: true }, 'Note'), note, setNote),
                bound(
                    ui(
                        'Select',
                        {},
                        ui('Option', { value: 'bug' }, 'Bug'),
                        ui('Option', { value: 'idea' }, 'Idea'),
                        ui('Option', { value: 'question' }, 'Question')
                    ),
                    kind,
                    setKind
                ),
                reset
            ]}
        />
    );
}
ui
$selected = ["links"]
$notify = false
$limit = 20
$scope = "failed"
$name = "Ada"
$kind = "bug"
$note = ""
<Checklist value={$selected}>
<Item value="links">Fix the link parser</Item>
<Item value="preload">Make the bridge method optional</Item>
</Checklist>
<Switch value={$notify}>Notify me when it lands</Switch>
<Slider value={$limit} min={10} max={100} step={10} unit="runs">Runs to compare</Slider>
<Segmented value={$scope} label="Tests to run">
<Option value="failed">Failed</Option>
<Option value="all">All</Option>
</Segmented>
<TextField value={$name} maxLength={40} placeholder="Your name">Name</TextField>
<TextField value={$note} maxLength={200} placeholder="What should change" multiline>Note</TextField>
<Select value={$kind}>
<Option value="bug">Bug</Option>
<Option value="idea">Idea</Option>
<Option value="question">Question</Option>
</Select>
<Button action={@Reset()}>Reset</Button>

A control is disabled until its tag closes, and when its value is not a bare reference to a declared variable.

Checklist and Item ​

Select values in a list. Checklist holds only Item, and binds the list of checked values. An Item stands only inside Checklist; its children are the label and may hold a link.

PropTypeRequiredNotes
valuearray of scalarsYesAt most 1,000; bindable
Item propTypeRequiredNotes
valuescalarYesA string, number, boolean or null
detailstringNoA faint line under the label

Switch ​

A local boolean. Its children are the label.

PropTypeRequiredNotes
valuebooleanYesBindable

Slider ​

A local number in a range. Its children are the label.

PropTypeRequiredNotes
valuenumberYesBindable; from min to max
minnumberYesBelow max
maxnumberYes
stepnumberNoAbove zero
unitstringNoWritten after the value

Segmented and Option ​

Choose one value. Segmented holds only Option, and binds the chosen option's value. An Option stands inside Segmented, Select or Radio; its children are its label. Keep labels to a few words. Longer ones make the renderer stack the options in a column.

PropTypeRequiredNotes
valuescalarYesBindable
labelstringNoA line above the options, and the group's name for a screen reader
Option propTypeRequiredNotes
valuescalarYes
detailstringNoA line under the label in a Radio; Segmented and Select have no room for it

Radio ​

One value out of a list, for options that each need a line of explanation. Radio holds only Option and binds the chosen option's value.

PropTypeRequiredNotes
valuescalarYesBindable
labelstringNoA line above the options, and the group's name for a screen reader
ui
$scope = "fast"
<Radio value={$scope} label="Tests to run">
<Option value="fast" detail="Only the changed files, about a minute">Fast</Option>
<Option value="full" detail="Every suite, about twenty minutes">Full</Option>
</Radio>

Each option is a tile with its label and, under it, its detail. The group is one tab stop, and the arrow keys move the choice, as in any radio group. Without a label, the group's accessible name is Options.

Select ​

A dropdown, for more or longer options than a Segmented holds. Select holds only Option and binds the chosen option's value. A Choice refuses a value no option offers. Text beside the options is the label, drawn above the dropdown and used as its accessible name, as in <Select value={$kind}>Kind of report<Option ...>. Without it, the accessible name is Options.

PropTypeRequiredNotes
valuescalarYesBindable

TextField ​

A line of text, up to maxLength characters, or with multiline a field that grows to a few lines and scrolls after that. Its children are the label. It does not submit; the text reaches the agent only through a Choice.

PropTypeRequiredNotes
valuestringYesBindable; at most maxLength characters, or the field fails
maxLengthnumberNoA whole number from 1 to 1,024; 256 without it
placeholderstringNoAt most 128 characters; shown while the field is empty
multilinebooleanNoTakes more than one line of text

A count (7 of 8 characters) appears once the field is 80% full. A default over the limit makes the TextField fail alone and draw as its label.

NumberField ​

A number a person types. Its children are the label. Like a TextField it does not submit; the number reaches the agent only through a Choice.

PropTypeRequiredNotes
valuenumberYesBindable; within min and max, or the field fails
minnumberNoThe smallest number the field takes
maxnumberNoThe largest number the field takes
stepnumberNoAbove zero; what an arrow key adds or takes
unitstringNoWritten inside the field, after the number
ui
$runs = 50
<NumberField value={$runs} min={1} max={500} unit="runs">Number of runs</NumberField>

The variable changes only while the field holds a number inside the range. Text that is no number, or a number outside the range, stays in the field with a line that names the range, and leaving the field puts the last good number back. For a number a person picks by feel, use a Slider.

Button ​

Runs one action on local state when pressed. Its children are the label, on one line; a label that does not fit is truncated and shown whole in a tooltip.

PropTypeRequiredNotes
actionactionYes@Set($name, constant), @Reset($name) or @Reset()
disabledbooleanNo

action runs only when pressed; see the rules for buttons.

Show ​

Shows its children while when is true. Show may stand inside any container, and its children follow that container's rule.

PropTypeRequiredNotes
whenbooleanYes
ui
$details = false
<Switch value={$details}>Show details</Switch>
<Show when={$details}><Callout tone="info">The cache missed on every cold start.</Callout></Show>

Each ​

Repeats its children for every item. Each may stand inside any container, and its children follow that container's rule.

PropTypeRequiredNotes
itemsarrayYesAt most 1,000
asstringYesThe item's name, a letter or _ then letters, digits, _
ui
$checks = ["lint", "types", "tests"]
$done = ["lint"]
<Checklist value={$done}>
<Each items={$checks} as="check"><Item value={check}>{check}</Item></Each>
</Checklist>

Licenses and third-party notices are listed in each package.