Skip to content

Commit 371d5fb

Browse files
committed
Lint and make it more homogeneous
1 parent d2cb020 commit 371d5fb

File tree

7 files changed

+78
-64
lines changed

7 files changed

+78
-64
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ jobs:
1313
fail-fast: false
1414
matrix:
1515
example:
16-
- clear-cell-outputs
1716
- kernel-messaging
1817
- kernel-output
1918
- datagrid
@@ -29,6 +28,7 @@ jobs:
2928
- react-widget
3029
- settings
3130
- state
31+
- toolbar-button
3232
- widgets
3333
os: [ubuntu-latest, macos-latest, windows-latest]
3434
steps:

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ You may find it easier to learn how to create extensions _by examples_, instead
5252

5353
Start with the [Hello World](hello-world) and then jump to the topic you are interested in.
5454

55-
- [Clear Cell Outputs](clear_cell_outputs)
5655
- [Commands](commands)
5756
- [Command Palette](command-palette)
5857
- [Context Menu](context-menu)
@@ -69,6 +68,7 @@ Start with the [Hello World](hello-world) and then jump to the topic you are int
6968
- [Settings](settings)
7069
- [Signals](signals)
7170
- [State](state)
71+
- [Toolbar item](toolbar-button)
7272
- [Widgets](widgets)
7373

7474
You can expect from each example:
@@ -178,6 +178,12 @@ Use State persistence in an extension.
178178

179179
[![State](state/preview.gif)](state)
180180

181+
### [Toolbar item](toolbar-button)
182+
183+
Add a new button to the notebook toolbar.
184+
185+
[![Toolbar button](toolbar-button/Preview.gif)](toolbar-button)
186+
181187
### [Widgets](widgets)
182188

183189
Add a new Widget element to the main window.

kernel-messaging/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,5 +284,5 @@ example, you will explore how you can reuse some Jupyter components to have a ni
284284
This example uses React to define UI elements. You can
285285
learn more about React in JupyterLab in [that example](../react-widget/README.md).
286286

287-
The UI refresh is triggered by signal emitions. To know more about it,
287+
The UI refresh is triggered by signal emissions. To know more about it,
288288
you can have a look at the [signal example](../signals/README.md).

toolbar-button/.eslintrc.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ module.exports = {
1515
'@typescript-eslint/naming-convention': [
1616
'error',
1717
{
18-
'selector': 'interface',
19-
'format': ['PascalCase'],
20-
'custom': {
21-
'regex': '^I[A-Z]',
22-
'match': true
18+
selector: 'interface',
19+
format: ['PascalCase'],
20+
custom: {
21+
regex: '^I[A-Z]',
22+
match: true
2323
}
2424
}
2525
],

toolbar-button/README.md

Lines changed: 45 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,61 @@
1-
# clear cell outputs
1+
# Toolbar Item
22

3-
This example shows how to clear all cell outputs at once by clicking on the button.
3+
This example shows how to add a button to the notebook toolbar.
44

5-
![Github Actions Status](https://github.com/yash112-lang/extension-examples/blob/master/toolbar-button/Preview.gif)
5+
![Toolbar button](Preview.gif)
6+
7+
In this particular example, the button will clear all cell outputs
8+
9+
To use it first you need to import the following packages:
610

7-
To use it first we need to import the packages
811
```ts
9-
// src/index.ts#L1-L19
12+
// src/index.ts#L1-L16
1013

11-
import {
12-
IDisposable, DisposableDelegate
13-
} from '@lumino/disposable';
14+
import { IDisposable, DisposableDelegate } from '@lumino/disposable';
1415

1516
import {
16-
JupyterFrontEnd, JupyterFrontEndPlugin
17+
JupyterFrontEnd,
18+
JupyterFrontEndPlugin
1719
} from '@jupyterlab/application';
1820

19-
import {
20-
ToolbarButton
21-
} from '@jupyterlab/apputils';
21+
import { ToolbarButton } from '@jupyterlab/apputils';
2222

23-
import {
24-
DocumentRegistry
25-
} from '@jupyterlab/docregistry';
23+
import { DocumentRegistry } from '@jupyterlab/docregistry';
2624

2725
import {
28-
NotebookActions, NotebookPanel, INotebookModel
26+
NotebookActions,
27+
NotebookPanel,
28+
INotebookModel
2929
} from '@jupyterlab/notebook';
3030
```
3131

32-
Firstly we have to register the plugin information. In this we have to pass a activate **function** & the plugin **id**.
32+
Firstly you have to register the plugin information. For that you have to pass a activate **function** and the plugin **id**.
3333

3434
```ts
35-
// src/index.ts#L25-L29
35+
// src/index.ts#L21-L25
36+
3637
const plugin: JupyterFrontEndPlugin<void> = {
3738
activate,
38-
id: 'clear-cell-outputs:buttonPlugin',
39+
id: 'toolbar-button',
3940
autoStart: true
4041
};
4142
```
42-
Now creating a notebook widget extension that adds a button to the toolbar. For more info [IWidgetExtension](https://jupyterlab.readthedocs.io/en/latest/api/interfaces/docregistry.documentregistry.iwidgetextension.html)
43+
44+
New widgets can be added to a document widget by implementing the interface [DocumentRegistry.IWidgetExtension](https://jupyterlab.readthedocs.io/en/latest/api/interfaces/docregistry.documentregistry.iwidgetextension.html). In particular, you need to add your widget in the `createNew` method that is called when creating a new
45+
document widget; in this case a notebook panel.
4346

4447
```ts
45-
// src/index.ts#L35-L56
46-
export
47-
class ButtonExtension implements DocumentRegistry.IWidgetExtension<NotebookPanel, INotebookModel> {
48-
49-
// Create a new extension object.
50-
51-
createNew(panel: NotebookPanel, context: DocumentRegistry.IContext<INotebookModel>): IDisposable {
48+
// src/index.ts#L30-L54
49+
50+
export class ButtonExtension
51+
implements DocumentRegistry.IWidgetExtension<NotebookPanel, INotebookModel> {
52+
/**
53+
* Create a new extension for the notebook panel widget.
54+
*/
55+
createNew(
56+
panel: NotebookPanel,
57+
context: DocumentRegistry.IContext<INotebookModel>
58+
): IDisposable {
5259
let clearOutput = () => {
5360
NotebookActions.clearAllOutputs(panel.content);
5461
};
@@ -66,15 +73,18 @@ export
6673
}
6774
}
6875
```
69-
Now activating the extension
76+
77+
Finally you need to tell the document registry about your widget extension:
78+
7079
```ts
71-
// src/index.ts#L61-L63
80+
// src/index.ts#L59-L61
81+
7282
function activate(app: JupyterFrontEnd) {
7383
app.docRegistry.addWidgetExtension('Notebook', new ButtonExtension());
74-
};
75-
```
76-
Finally exporting the plugin
77-
```ts
78-
// src/index.ts#L69-L69
79-
export default plugin;
84+
}
8085
```
86+
87+
## Where to Go Next
88+
89+
This example uses a command to display the widget. Have a look a the
90+
[commands example](../commands/README.md) for more information about it.

toolbar-button/src/index.ts

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,41 @@
1-
import {
2-
IDisposable, DisposableDelegate
3-
} from '@lumino/disposable';
1+
import { IDisposable, DisposableDelegate } from '@lumino/disposable';
42

53
import {
6-
JupyterFrontEnd, JupyterFrontEndPlugin
4+
JupyterFrontEnd,
5+
JupyterFrontEndPlugin
76
} from '@jupyterlab/application';
87

9-
import {
10-
ToolbarButton
11-
} from '@jupyterlab/apputils';
8+
import { ToolbarButton } from '@jupyterlab/apputils';
129

13-
import {
14-
DocumentRegistry
15-
} from '@jupyterlab/docregistry';
10+
import { DocumentRegistry } from '@jupyterlab/docregistry';
1611

1712
import {
18-
NotebookActions, NotebookPanel, INotebookModel
13+
NotebookActions,
14+
NotebookPanel,
15+
INotebookModel
1916
} from '@jupyterlab/notebook';
2017

21-
2218
/**
2319
* The plugin registration information.
2420
*/
2521
const plugin: JupyterFrontEndPlugin<void> = {
2622
activate,
27-
id: 'clear-cell-outputs:buttonPlugin',
23+
id: 'toolbar-button',
2824
autoStart: true
2925
};
3026

31-
3227
/**
3328
* A notebook widget extension that adds a button to the toolbar.
3429
*/
35-
export
36-
class ButtonExtension implements DocumentRegistry.IWidgetExtension<NotebookPanel, INotebookModel> {
30+
export class ButtonExtension
31+
implements DocumentRegistry.IWidgetExtension<NotebookPanel, INotebookModel> {
3732
/**
38-
* Create a new extension object.
33+
* Create a new extension for the notebook panel widget.
3934
*/
40-
createNew(panel: NotebookPanel, context: DocumentRegistry.IContext<INotebookModel>): IDisposable {
35+
createNew(
36+
panel: NotebookPanel,
37+
context: DocumentRegistry.IContext<INotebookModel>
38+
): IDisposable {
4139
let clearOutput = () => {
4240
NotebookActions.clearAllOutputs(panel.content);
4341
};
@@ -60,10 +58,9 @@ export
6058
*/
6159
function activate(app: JupyterFrontEnd) {
6260
app.docRegistry.addWidgetExtension('Notebook', new ButtonExtension());
63-
};
64-
61+
}
6562

6663
/**
6764
* Export the plugin as default.
6865
*/
69-
export default plugin;
66+
export default plugin;

widgets/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,4 @@ widgets in the following examples:
9898
- Widget showing a [Datagrid](../datagrid/README.md)
9999
- Widget integrating [React components](../react-widget/README.md)
100100
- Widget interacting with a [Kernel](../kernel-messaging/README.md)
101+
- Extending document widget (like the notebook panel) with a new [Toolbar Button](../toolbar-button/README.md)

0 commit comments

Comments
 (0)