Skip to main content

Build your first widget

Build a small banner widget with configurable text, colour and size, then place it on an overlay. You'll use every part of the Widget Creator: the code editor, properties, the preview and the Build step.

1. Create the widget​

  1. Open Widget Creator from the sidebar.
  2. Create a new widget named My First Banner.

2. Write the core​

The core is the code that runs when your widget loads. Open the core file (a .ts file) and show your main template:

// main.ts
import { onLoad, showTemplate, setCrashTemplate, Template } from '@widget';

onLoad(() => {
setCrashTemplate(Template.Crash); // fallback if something throws
showTemplate(Template.Main); // draw the Main template
});

3. Draw something​

Open the main.tsx template, a React component that draws your widget:

// main.tsx
export default function Main() {
return <h1>Hello, stream!</h1>;
}

The preview updates as you type.

4. Make it configurable​

Add properties so the message, colour and size can be set without editing code. On the Properties surface, add three:

KeyTypeLabelDefault
messagetextMessageHello, stream!
accent-colourcolorColour#9146FF
font-sizenumberFont size48

Read them with the useProp hook. A property's key becomes a camelCase name: accent-colour → accentColour, font-size → fontSize.

// main.tsx
import { useProp } from '@widget';

export default function Main() {
const message = useProp('message');
const colour = useProp('accentColour');
const fontSize = useProp('fontSize');

return (
<div
style={{
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
width: '100%',
height: '100%',
color: colour,
fontSize: `${fontSize}px`,
fontWeight: 800,
}}
>
{message}
</div>
);
}

5. Try your controls​

On the Simulate surface, change the property test values. The preview reacts as it will for whoever configures the widget on their overlay.

6. Add a crash fallback​

Open crash.tsx and make it return something harmless. It shows if your main template throws:

// crash.tsx
export default function Crash() {
return null;
}

7. Build it and put it on an overlay​

  1. Click Build. The widget becomes available on your own overlays.
  2. Open an overlay in the Overlay Editor.
  3. Click Add Widget, open the Custom widgets tab, and add My First Banner.
  4. Set its message, colour and size in the properties panel.

Where to go next​