Inputs
bind: $name ties a TextBox, CheckBox, Select or Slider to a state variable. When the person changes the input, the variable changes and the window is drawn again. In on_change, $event.value holds the new value:
<KScript.Window title="Settings">
<let name="name" value="''" />
<let name="dark" value="false" />
<let name="size" value="14" />
<let name="theme" value="'teal'" />
<Column gap="8">
<TextBox bind="$name" placeholder="Your name" />
<CheckBox bind="$dark">Dark mode</CheckBox>
<Slider bind="$size" min="10" max="24" step="1" />
<Select bind="$theme" options="['teal', 'orange', 'purple']" />
</Column>
</KScript.Window>import KScript.UI
Window(title: 'Settings') {
$name = ''
$dark = false
$size = 14
$theme = 'teal'
Column(gap: 8) {
TextBox(bind: $name, placeholder: 'Your name')
CheckBox(bind: $dark) "Dark mode"
Slider(bind: $size, min: 10, max: 24, step: 1)
Select(bind: $theme, options: ['teal', 'orange', 'purple'])
}
}Select takes its options as a list, a list of { label, value } maps, or a map from label to value.
A TextBox takes the same binding options as @bind on a page. on: is input (as you type, the default), change or blur (when focus leaves or Enter is pressed). trim: true trims spaces, and as: (string, int, number or bool) reads the value as that type and shows an error for one that isn't:
<KScript.Window title="Age">
<let name="age" value="0" />
<TextBox bind="$age" on="blur" trim="true" as="int" />
<Text>Next year you'll be {$age + 1}</Text>
</KScript.Window>import KScript.UI
Window(title: 'Age') {
$age = 0
TextBox(bind: $age, on: blur, trim: true, as: int)
Text "Next year you'll be {$age + 1}"
}multiline: true makes a TextBox hold several lines, and on_enter runs when Enter is pressed.