Checkbox
One checkbox in Stolon's look, with its text beside it. The box fills with the accent and shows a check while it is on, and shows a bar while it is partly on. Every box Stolon draws is built on the same checkbox core, so a checkbox here matches the boxes in the Checkbox List, the Filtered List, the Filter Panel, and the Tree View.
Decision
| When |
Use |
| Any yes or no setting you build in script |
Checkbox. |
| Almost every setting |
size: 'small', the default. |
| A checkbox beside medium buttons or larger text |
size: 'medium'. |
A few headline settings on their own row, each with a description |
size: 'large'. A large checkbox is a tile that fills the room its row has, and tiles in one row share it and wrap. |
| A small or medium box in a row of text boxes and selects |
field: true, so its box lines up with them. |
| A box that should also look like one of those fields |
boxed: true. The box and its text sit in a frame drawn like a text box, the same height, border, and corners. |
| A list of choices |
Checkbox List. |
| One choice of several |
A select, the Pill Group, or the Choice Group. |
| A checkbox written in a page's own markup |
The markup as written, which already takes this look. Build one in script only when you need its handle. |
Usage
import { createCheckbox } from './configurationpage?name=myplugin_stolon.js';
var box = createCheckbox({
label: 'Sync watched state',
checked: config.SyncWatched,
onChange: function (checked) { config.SyncWatched = checked; }
});
view.querySelector('#watchedHost').appendChild(box.element);
The handle is { element, input, getValue, setValue, setIndeterminate, setDisabled, setLabel, setDescription, destroy }.
var tile = createCheckbox({
size: 'large',
label: 'Sync watched state',
description: 'Played and resume points follow you between servers.',
checked: true
});
Sizes
The sizes follow the button scale, so a checkbox lines up with a button of its size.
| Size |
Look |
small (default) |
The plain box and text, the small button's height |
medium |
A larger box and text, the medium button's height |
large |
A bordered tile with a bold label and a dimmed description, filling the room its row has. While on, it is outlined and washed in the accent |
States and Modifiers
| State |
Look |
| Off |
An outlined box |
| On |
Filled with the accent, with a check |
| Partly on |
Filled with the accent, with a bar. setIndeterminate(true) shows it, and a click clears it |
| Disabled |
Dimmed, and takes no clicks |
field |
Stands a small or medium box a field tall, with the box centered on the line of the fields beside it |
boxed |
Frames a small or medium box and its text like a text box, a field tall, so it matches the fields beside it edge for edge. The frame turns the accent on hover |
Behavior
- A click on the box or its text turns it on or off, and so does Space while it has focus.
onChange reports the new state.
setValue changes it from code without calling onChange.
- With no
label, ariaLabel names the box for screen readers and is its tooltip.
- The Repeater, Matrix Grid, and Mapping Table draw their
toggle fields with it.
Reference
createCheckbox
function createCheckbox(options?: CheckboxOptions): CheckboxHandle
One checkbox in Stolon's own look, with its text beside it, built on the checkbox core every Stolon box shares. The box fills with the accent and a drawn check while on, and shows a bar while partly on. A click anywhere on its text toggles it. It comes in three sizes on the same scale as buttons: small, the plain box and text most pages use; medium, a size up; and large, a bordered tile that fills the room its row has, outlined and washed in the accent while on. With field, a small or medium box stands a field tall with the box centered, so it lines up beside text boxes and selects in a row. With boxed, it sits in a frame drawn like a text box, the same height, border, and corners, so it matches the fields beside it edge for edge. With no label, ariaLabel names it.
| Option |
Type |
What it does |
label |
string |
the text beside the box [optional] |
description |
string |
a dimmed line under the label [optional] |
size |
CheckboxSize |
'small', 'medium', or 'large' (default 'small') |
ariaLabel |
string |
the box's name when it has no label [optional] |
checked |
boolean |
whether it starts on (default false) |
indeterminate |
boolean |
whether it starts partly on (default false) |
disabled |
boolean |
whether it starts disabled (default false) |
field |
boolean |
true stands a small or medium box a field tall, to sit in a row of fields (default false) |
boxed |
boolean |
true frames a small or medium box and its text like a text box, a field tall (default false) |
id |
string |
the input's id [optional] |
name |
string |
the input's name [optional] |
value |
string |
the input's value [optional] |
className |
string |
extra classes for the row [optional] |
onChange |
(checked: boolean): void |
function(checked) after the reader turns it on or off [optional] |
| Handle member |
Type |
input |
HTMLInputElement |
getValue |
(): boolean |
setValue |
(checked: boolean): void |
setIndeterminate |
(on: boolean): void |
setDisabled |
(disabled: boolean): void |
setLabel |
(text: string): void |
setDescription |
(text: string): void |
destroy |
(): void |
| Type |
What it is |
CheckboxSize |
The three checkbox sizes. small is the plain box most pages use, and large is a tile that fills its row. |
| Class |
What it looks like |
stolon-check-row.stolon-checkbox |
One checkbox with its text beside it, the box and text centered on one line, with no row padding or hover wash. Small is the plain box most pages use |
stolon-check-row.stolon-checkbox.stolon-medium |
A medium checkbox, a size up: the medium button's height, the large box, and the large text |
stolon-check-row.stolon-checkbox.stolon-field-sized |
A checkbox a field tall, so it lines up with the text boxes and selects beside it |
stolon-check-row.stolon-checkbox.stolon-disabled |
A disabled checkbox, dimmed and taking no clicks |