Search
Loading...
Skip to content

Add a New Button

Add custom buttons to the CE.SDK editor to trigger actions, control panels, or implement custom workflows.

Add a New Button example showing theme and favorite toggle buttons in navigation bar

5 mins
estimated time
Download
StackBlitz
GitHub

CE.SDK provides a component registration system for adding custom UI elements. The builder API ensures buttons match the editor’s look and feel while giving full control over behavior.

This guide demonstrates adding custom buttons to the navigation bar: a theme toggle, a favorite button with local state, and an export button that triggers a built-in action.

Register a Button Component#

Use cesdk.ui.registerComponent() to create the theme toggle button. The render function receives a builder object for creating UI elements. Use cesdk.ui.getTheme() to read the current theme and cesdk.ui.setTheme() to change it.

cesdk.ui.registerComponent('theme.toggle', ({ builder }) => {
const isDark = cesdk.ui.getTheme() === 'dark';
builder.Button('toggle-theme', {
label: 'Dark Mode',
icon: isDark ? '@imgly/ToggleIconOn' : '@imgly/ToggleIconOff',
variant: 'regular',
isActive: isDark,
onClick: () => {
cesdk.ui.setTheme(isDark ? 'light' : 'dark');
}
});
});

The render function re-runs when relevant state changes. Calling cesdk.ui.getTheme() tracks the theme state, so the component automatically re-renders when setTheme() is called.

Use Component State#

For buttons that need to maintain their own state, use the state() function provided in the render context. This creates reactive state that persists across re-renders and automatically triggers updates when changed.

cesdk.ui.registerComponent('favorite.toggle', ({ builder, state }) => {
const { value: isFavorite, setValue: setIsFavorite } = state(
'isFavorite',
false
);
builder.Button('toggle-favorite', {
label: 'Favorite',
icon: '@imgly/ShapeStar',
variant: 'regular',
isActive: isFavorite,
onClick: () => {
setIsFavorite(!isFavorite);
}
});
});

The state() function returns an object with value (the current state) and setValue (a function to update it). When setValue is called, the component re-renders with the new value. The isActive property provides visual feedback when the button state is active.

Trigger Built-in Actions#

Combine custom buttons with built-in actions to create streamlined workflows. Use cesdk.actions.run() to execute registered actions like export, save, or zoom operations.

cesdk.ui.registerComponent('quick.export', ({ builder }) => {
builder.Button('quick-export', {
label: 'Export',
icon: '@imgly/Download',
variant: 'regular',
onClick: () => {
cesdk.actions.run('exportDesign');
}
});
});

The Actions API provides access to built-in operations (exportDesign, saveScene, zoom.in, etc.) and supports custom actions you register yourself.

Add to the Navigation Bar#

Use insertNavigationBarOrderComponent() to add buttons to the navigation bar. The first argument is a matcher ('first', 'last', a number, component ID, or function), and the second is your component ID.

cesdk.ui.insertNavigationBarOrderComponent('last', 'theme.toggle');

You can add buttons to other UI locations using similar APIs:

LocationInsert APISet Order API
Navigation BarinsertNavigationBarOrderComponent()setNavigationBarOrder()
DockinsertDockOrderComponent()setDockOrder()
Canvas MenuinsertCanvasMenuOrderComponent()setCanvasMenuOrder()
Inspector BarinsertInspectorBarOrderComponent()setInspectorBarOrder()
Canvas BarinsertCanvasBarOrderComponent()setCanvasBarOrder()

Button Properties#

The builder’s Button method accepts these configuration options:

PropertyTypeDescription
labelstring | string[]Button text, supports i18n keys
iconCustomIconIcon from the icon set
onClick() => voidClick handler function
isSelectedbooleanHighlight as selected
isActivebooleanShow active state styling
isDisabledbooleanDisable interaction
isLoadingbooleanShow loading indicator
loadingProgressnumberLoading progress (0-1)
color'accent' | 'danger'Color variant
variant'regular' | 'plain'Style variant
tooltipstring | string[]Hover tooltip text
shortcutstringKeyboard shortcut display

API Reference#

APIDescription
registerComponent()Register a custom component with a render function
state()Create reactive component state that persists across re-renders
insertNavigationBarOrderComponent()Insert a component into the navigation bar
getTheme()Get the current editor theme ('light' or 'dark')
setTheme()Set the editor theme
actions.run()Execute a registered action by ID
actions.list()List all available action IDs

Next Steps#