Skip to content

Commit

Permalink
Add tippy.js based tooltip (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Jun 15, 2023
1 parent 17dc3d7 commit 3fdfa64
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
2 changes: 1 addition & 1 deletion conda.recipe/meta.yaml
Expand Up @@ -15,7 +15,7 @@ build:
requirements:
build:
- jupyter-packaging
- jupyterlab
- jupyterlab <4
- notebook
- python
- setuptools
Expand Down
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -54,7 +54,8 @@
"@jupyterlab/settingregistry": "^3.1.0",
"@jupyterlab/ui-components": "^3.1.0",
"@lumino/coreutils": "^1.5.3",
"@lumino/signaling": "^1.4.3"
"@lumino/signaling": "^1.4.3",
"tippy.js": "^6"
},
"resolutions": {
"@lumino/widgets": "^1.37.2",
Expand Down
37 changes: 34 additions & 3 deletions src/plugin.ts
Expand Up @@ -56,6 +56,9 @@ export type INBWidgetExtension = DocumentRegistry.IWidgetExtension<
INotebookModel
>;

import tippy from 'tippy.js';
import 'tippy.js/dist/tippy.css'; // optional for styling

let registerWidgetManager: any = null;
try {
const jlm = require('@jupyter-widgets/jupyterlab-manager');
Expand All @@ -77,6 +80,15 @@ export namespace CommandIDs {
export const lumenOpen = 'notebook:open-with-lumen';
}

const TOOLTIP_CONTENT = `
<span>Preview with Panel<span>
<br>
<br>
<span>
<b>Note:</b> Your notebook must publish Panel contents with .servable().
<span>
`;

/**
* A notebook widget extension that adds a panel preview button to the toolbar.
*/
Expand All @@ -96,13 +108,23 @@ class PanelRenderButton
createNew(panel: NotebookPanel): IDisposable {
const button = new ToolbarButton({
className: 'panelRender',
tooltip: 'Render with Panel',
icon: panelIcon,
onClick: (): void => {
this._commands.execute(CommandIDs.panelRender);
}
});

setTimeout(() => {
requestAnimationFrame(() => {
tippy(button.node, {
allowHTML: true,
arrow: true,
content: TOOLTIP_CONTENT,
placement: 'bottom'
});
});
}, 0);

panel.toolbar.insertAfter('cellType', 'panelRender', button);
return button;
}
Expand All @@ -129,13 +151,22 @@ class LumenRenderButton
createNew(panel: NotebookPanel): IDisposable {
const button = new ToolbarButton({
className: 'lumenRender',
tooltip: 'Render with Lumen',
icon: panelIcon,
onClick: () => {

Check warning on line 155 in src/plugin.ts

View workflow job for this annotation

GitHub Actions / test (3.7)

Missing return type on function

Check warning on line 155 in src/plugin.ts

View workflow job for this annotation

GitHub Actions / test (3.8)

Missing return type on function

Check warning on line 155 in src/plugin.ts

View workflow job for this annotation

GitHub Actions / test (3.9)

Missing return type on function

Check warning on line 155 in src/plugin.ts

View workflow job for this annotation

GitHub Actions / test (3.10)

Missing return type on function

Check warning on line 155 in src/plugin.ts

View workflow job for this annotation

GitHub Actions / test (3.11)

Missing return type on function
this._commands.execute(CommandIDs.lumenRender);
}
});

setTimeout(() => {
requestAnimationFrame(() => {
tippy(button.node, {
arrow: true,
content: 'Preview with Lumen',
placement: 'bottom'
});
});
}, 0);

panel.toolbar.addItem('lumenRender', button);
return button;
}
Expand Down Expand Up @@ -318,7 +349,7 @@ export const extension: JupyterFrontEndPlugin<IPanelPreviewTracker> = {
const { commands, docRegistry } = app;

commands.addCommand(CommandIDs.panelRender, {
label: 'Render Notebook with Panel',
label: 'Preview Notebook with Panel',
execute: async args => {
const current = getCurrent(args);
let context: DocumentRegistry.IContext<INotebookModel>;
Expand Down

0 comments on commit 3fdfa64

Please sign in to comment.