Skip to content

FieldList ​

FieldList draws the rows of settings from a list of field specs: a name and the control of its kind for each field.

When to use ​

Use it where the settings of a thing are known as data rather than written out: the style of a shape, whose fields depend on its kind, or the options of a tool. The application builds the specs for the thing selected and applies the changes; the list only draws and reports. Put it in an InspectorSection. For a setting that none of the kinds fits, use custom and draw the control in the field snippet. For settings written one by one, use InspectorRow.

When several things are selected, give each field the value they share, or mixed: true when they differ; the change the user makes then applies to all of them.

svelte
<FieldList
  fields={[
    { key: 'fill', kind: 'color', label: 'Fill', value: '#2F6FDE' },
    { key: 'width', kind: 'number', label: 'Width', value: 2, unit: 'px' },
  ]}
  onchange={(key, value) => apply(key, value)}
/>

Props ​

PropDefaultDescription
fieldsrequiredThe fields, FieldSpec[] (below)
onchangeCalled with the key and the value of a committed change
oninputCalled with the key and the value of a dragged slider
oncolorCalled with the key of a color field pressed; no picker opens
fieldDraws a custom field (a snippet that receives the spec)
endOne row after the fields, for an action on all of them (a snippet)

A FieldSpec has these keys.

KeyDescription
keyThe key the change is reported with
kindThe control, one of the kinds under Contract
labelThe name before the control
valueThe current value, as the application holds it
mixedThe things selected differ; no value shows
optionsThe choices of select and segmented, { value, label }[]
min, max, stepThe range of number and slider
digitsThe characters of the longest number; it keeps that width
unitText after the value (px, %, °)
placeholderA word shown while a text or a number is empty
disabledThe control cannot be changed
hintA caption under the control
topThe control has several lines; the name stays at the top

Contract ​

Each field is an InspectorRow, the rows gap-sm apart, with the control of its kind.

KindControlReported value
textTextInputThe text, on change
numberNumberInput; with digits, as wide as its value at the start of the value columnA number, or null when emptied
selectNativeSelectThe option's value
colorA button with a Swatch, as wide as the value column, that opens a ColorPicker#RRGGBB, at each pick
toggleToggle, at the end of the rowtrue or false
sliderSlider, with the value and the unitA number, when let go
segmentedSegmentedThe option's value
customThe field snippetWhat the snippet reports

The list does not convert the values: a unit is text after the value, and the application keeps the meaning of each number. A text or a number is reported when it is committed (Enter or leaving the input), not at each key; a number that cannot be read is not reported. A slider shows its value while it is dragged and reports it with onchange once, when let go; oninput receives each value while it is dragged, for a preview. With oncolor, the button of a color field shows its swatch and its value as before but opens no picker: it calls oncolor with the key, and the application opens its own picker where it wants and applies the color itself. end is one Row after the fields, gap-sm below the last one, for an action on the whole list, such as a reset as a LinkAction. A field with mixed shows no value (an empty input, no chosen option, a button without a swatch, the thumb at the start) and the mixed message as its hint. Without a field snippet, a custom field shows its value as text.

Example ​

FieldList

Released under the Apache-2.0 license.