Skip to content

Inputs ​

Change local block state. Bind a control with value={$name}; see State and inputs. State stays in the block until a Choice sends visible context.

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

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');
    // 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');
        }
    };
    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', {}, ui('Option', { value: 'failed' }, 'Failed'), ui('Option', { value: 'all' }, 'All')), scope, setScope),
                reset
            ]}
        />
    );
}
ui
$selected = ["links"]
$notify = false
$limit = 20
$scope = "failed"
<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}>
<Option value="failed">Failed</Option>
<Option value="all">All</Option>
</Segmented>
<Button action={@Reset()}>Reset</Button>

A control is disabled until its tag closed, and when its value is anything but 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

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 only inside Segmented; its children are its label. Option draws nothing itself: Segmented reads its options.

PropTypeRequiredNotes
valuescalarYesBindable
Option propTypeRequiredNotes
valuescalarYes

Button ​

Runs one action on local state when pressed. Its children are the label.

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

action is kept as written and runs only when pressed. Buttons gives the rules.

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.