forked from jupyterlab/extension-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modify Signals to render a HTML button without React. (jupyterlab#148)
- Loading branch information
Showing
7 changed files
with
104 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Widget } from '@lumino/widgets'; | ||
import { ISignal, Signal } from '@lumino/signaling'; | ||
|
||
export interface ICount { | ||
clickCount: number; | ||
} | ||
|
||
const BUTTON_WIDGET_CLASS = 'jp-ButtonWidget'; | ||
|
||
export class ButtonWidget extends Widget { | ||
constructor(options = { node: document.createElement('button') }) { | ||
super(options); | ||
|
||
this.node.textContent = 'Click me'; | ||
|
||
/** | ||
* The class name, jp-ButtonWidget, follows the CSS class naming | ||
* convention for classes that extend lumino.Widget. | ||
*/ | ||
this.addClass(BUTTON_WIDGET_CLASS); | ||
|
||
this.node.addEventListener('click', () => { | ||
this._count.clickCount = this._count.clickCount + 1; | ||
this._stateChanged.emit(this._count); | ||
}); | ||
} | ||
|
||
private _count: ICount = { | ||
clickCount: 0 | ||
}; | ||
|
||
private _stateChanged = new Signal<ButtonWidget, ICount>(this); | ||
|
||
public get stateChanged(): ISignal<ButtonWidget, ICount> { | ||
return this._stateChanged; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.