Panel Field Types

When registering a control panel, define fields that streamers can adjust from the dashboard without editing widget code.

Available Types

TypeRenders AsKey Properties
sliderRange slidermin, max, step, default
dropdownSelect menuoptions: string[], default
textText inputplaceholder, maxLength, default
numberNumeric inputmin, max, default
toggleBoolean switchdefault: boolean
colorColor pickerdefault: '#hex'

Registration Example

SBCanvas.panel.register({
  fields: [
    { key: 'speed', type: 'slider', label: 'Animation Speed', min: 1, max: 10, step: 1, default: 5 },
    { key: 'theme', type: 'dropdown', label: 'Theme', options: ['dark', 'light', 'neon'], default: 'dark' },
    { key: 'title', type: 'text', label: 'Widget Title', placeholder: 'Enter title...', maxLength: 50 },
    { key: 'alertCount', type: 'number', label: 'Max Alerts', min: 1, max: 100, default: 10 },
    { key: 'sounds', type: 'toggle', label: 'Enable Sounds', default: true },
    { key: 'accentColor', type: 'color', label: 'Accent Color', default: '#8B5CF6' }
  ]
});

Receiving Field Changes

When a streamer adjusts a field in the dashboard, your widget receives the change via the event bus:
SBCanvas.on('panel:field_change', ({ key, value }) => {
  if (key === 'speed') {
    updateAnimationSpeed(value);
  }
  if (key === 'theme') {
    document.body.className = value;
  }
  if (key === 'sounds') {
    SBCanvas.vars.set('soundsEnabled', value);
  }
});

Conditional Fields

Show or hide fields based on other field values using conditions:
SBCanvas.panel.register({
  fields: [
    { key: 'mode', type: 'dropdown', label: 'Mode', options: ['simple', 'advanced'] },
    { key: 'speed', type: 'slider', label: 'Speed', min: 1, max: 10,
      conditions: { mode: 'advanced' } },
    { key: 'particles', type: 'toggle', label: 'Particles',
      conditions: { mode: 'advanced' } }
  ]
});
The speed and particles fields only appear when mode is set to 'advanced'.

Field Groups

Organize fields into visual groups:
SBCanvas.panel.register({
  fields: [
    { key: 'title', type: 'text', label: 'Title', group: 'Content' },
    { key: 'subtitle', type: 'text', label: 'Subtitle', group: 'Content' },
    { key: 'bgColor', type: 'color', label: 'Background', group: 'Appearance' },
    { key: 'fontSize', type: 'slider', label: 'Font Size', min: 12, max: 48, group: 'Appearance' }
  ]
});

Full Example: Configurable Alert Widget

SBCanvas.ready(() => {
  SBCanvas.panel.register({
    fields: [
      { key: 'duration', type: 'slider', label: 'Alert Duration (s)', min: 3, max: 15, default: 5 },
      { key: 'sound', type: 'toggle', label: 'Play Sound', default: true },
      { key: 'volume', type: 'slider', label: 'Volume', min: 0, max: 100, step: 10, default: 80,
        conditions: { sound: true } },
      { key: 'position', type: 'dropdown', label: 'Position', options: ['top', 'center', 'bottom'], default: 'top' }
    ]
  });

  let config = { duration: 5, sound: true, volume: 80, position: 'top' };

  SBCanvas.on('panel:field_change', ({ key, value }) => {
    config[key] = value;
  });

  SBCanvas.activities.on('follow', (activity) => {
    showAlert(activity.username, config);
  });
});