toggle / toggle-group

Two related controls. `toggle` is an on/off switch storing a boolean. `toggle-group` is a single-select segmented control storing the chosen `value` as a string.

Stored value

boolean (`toggle`) or string (`toggle-group`)

Supports

  • Simple on/off boolean via `toggle`
  • Single-select segmented control via `toggle-group`
  • Pairs naturally with `conditionalLogic` to gate other fields

Config options

options{ value, label }[]
`toggle-group` only. The choices shown as segments. Required for `toggle-group`.
defaultboolean or string
For `toggle` a boolean; for `toggle-group` the pre-selected `value` (should match one of the options or no segment will be active).

Example

json
// toggle
{ "id": "ctrl_pinned",
  "type": "toggle",
  "label": "Pin to top",
  "attributeKey": "is_pinned",
  "default": false,
  "parentPanelId": "panel" }

// toggle-group
{ "id": "ctrl_source",
  "type": "toggle-group",
  "label": "Source",
  "attributeKey": "source",
  "default": "latest",
  "options": [
    { "value": "latest", "label": "Latest" },
    { "value": "manual", "label": "Pick" }
  ],
  "parentPanelId": "panel" }

Gotchas

Heads up
For multi-select use `checkbox-group` (alias: `button-group`). The two are picked by the SHAPE of the saved value, not by visual style.

Notes

Consume

export default function Collection({ attributes }) {
  const source = attributes.source === 'manual' ? 'manual' : 'latest';
  // ... branch on `source`
}