I am trying to create an extension that adds a custom button to the toolbar of an opened Jupyter Lab notebook, similar to the "Submit Notebook button ..." in this photo. How do I achieve this? I tried using the following code but it does not work:
import { ToolbarButton } from "@jupyterlab/apputils";
import { DocumentRegistry } from "@jupyterlab/docregistry";
import { INotebookModel, NotebookPanel } from "@jupyterlab/notebook";
import { IDisposable } from "@lumino/disposable";
export class ButtonExtension implements DocumentRegistry.IWidgetExtension<NotebookPanel, INotebookModel> {
createNew(panel: NotebookPanel, context: DocumentRegistry.IContext<INotebookModel>): IDisposable {
// Create the toolbar button
let mybutton = new ToolbarButton({
label: 'My Button',
onClick: () => alert('You did it!')
});
// Add the toolbar button to the notebook toolbar
panel.toolbar.insertItem(10, 'mybutton', mybutton);
// The ToolbarButton class implements `IDisposable`, so the
// button *is* the extension for the purposes of this method.
return mybutton;
}
}