Toolbar API Documentation¶
The Toolbar API allows modules and pages to dynamically inject buttons and actions into the global Top Toolbar of the AgentUI application. This ensures that context-specific actions are readily available to the user without cluttering the main content area.
Usage¶
Importing the Store¶
To use the Toolbar API, import the toolbarStore from $lib/stores/toolbar.svelte.
Adding a Button¶
Use the addButton method to register a new button. It is recommended to do this within an $effect block (in Svelte 5) or onMount (in Svelte 4) to ensure the button is added when the component mounts.
$effect(() => {
const buttonId = 'my-unique-button-id';
toolbarStore.addButton({
id: buttonId,
label: 'My Action', // Used for tooltip
icon: 'mdi:rocket', // Icon name (mapped in icon utility) or SVG path
variant: 'ghost', // 'ghost' (default/recommended), 'primary', 'secondary', 'accent'
position: 'right', // Optional: 'left' (default) or 'right'
onClick: () => {
console.log('Button clicked!');
// Perform your action here
}
});
// Cleanup: Remove button when component unmounts
return () => {
toolbarStore.removeButton(buttonId);
};
});
Button Interface¶
interface ToolbarButton {
id: string; // Unique identifier for the button
label: string; // Text label, used for the tooltip
icon: string; // Icon identifier (e.g., 'mdi:home') or SVG path
onClick?: () => void; // Callback function when clicked
variant?: 'ghost' | 'primary' | 'secondary' | 'accent'; // Button style variant. 'ghost' is circular icon-only.
position?: 'left' | 'right'; // Position in the toolbar relative to the center spacer. Default is left (center-left).
}
Best Practices¶
- Unique IDs: Always use a unique
idfor your buttons to prevent collisions with other modules. - Cleanup: Always return a cleanup function that calls
removeButtonto ensure buttons are removed when the user navigates away from your module. - Icons: Use clear, recognizable icons. The toolbar buttons are designed to be icon-only with tooltips.
- Tooltips: Provide meaningful
labels as they appear as tooltips on hover. - Placement: Use
position: 'right'for secondary or system-like actions, and default (left) for primary module actions.