Skip to content

Commit 6c7a102

Browse files
authored
Merge pull request #11 from DenisaCG/all_themes
added personalized JupyterLab theme
2 parents 0696926 + 3862159 commit 6c7a102

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

src/layout.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { IIterator, ArrayIterator } from '@lumino/algorithm';
99
import * as Blockly from 'blockly';
1010

1111
import { BlocklyManager } from './manager';
12+
import { THEME } from './utils';
1213

1314
/**
1415
* A blockly layout to host the Blockly editor.
@@ -113,13 +114,16 @@ export class BlocklyLayout extends PanelLayout {
113114
/**
114115
* Handle `after-attach` messages sent to the widget.
115116
*/
116-
protected onAfterAttach(msg: Message): void {
117+
protected onAfterAttach(msg: Message): void {
118+
//inject Blockly with appropiate JupyterLab theme.
117119
this._workspace = Blockly.inject(this._host, {
118-
toolbox: this._manager.toolbox
120+
toolbox: this._manager.toolbox,
121+
theme: THEME
119122
});
120123
}
121124

122125
private _resizeWorkspace(): void {
126+
//Resize logic.
123127
const rect = this.parent.node.getBoundingClientRect();
124128
const { height } = this._outputArea.node.getBoundingClientRect();
125129
this._host.style.width = rect.width + 'px';

src/utils.ts

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
1+
import * as Blockly from 'blockly';
2+
3+
// Creating a toolbox containing all the main (default) blocks.
14
export const TOOLBOX = {
2-
//kind: 'flyoutToolbox',
3-
// contents: [
4-
// {
5-
// kind: 'block',
6-
// type: 'controls_if'
7-
// },
8-
// {
9-
// kind: 'block',
10-
// type: 'controls_whileUntil'
11-
// }
12-
// ]
13-
//{
145
kind: 'categoryToolbox',
156
contents: [
167
{
@@ -360,3 +351,22 @@ export const TOOLBOX = {
360351
}
361352
]
362353
};
354+
355+
// Defining a Blockly Theme in accordance with the current JupyterLab Theme.
356+
const jupyterlab_theme = Blockly.Theme.defineTheme('jupyterlab', {
357+
'base': Blockly.Themes.Classic,
358+
'componentStyles': {
359+
'workspaceBackgroundColour': 'var(--jp-layout-color0)',
360+
'toolboxBackgroundColour': 'var(--jp-layout-color2)',
361+
'toolboxForegroundColour': 'var(--jp-ui-font-color0)',
362+
'flyoutBackgroundColour': 'var(--jp-border-color2)',
363+
'flyoutForegroundColour': 'var(--jp-layout-color3)',
364+
'flyoutOpacity': 1,
365+
'scrollbarColour': 'var(--jp-border-color0)',
366+
'insertionMarkerOpacity': 0.3,
367+
'scrollbarOpacity': 0.4,
368+
'cursorColour': 'var(--jp-scrollbar-background-color)',
369+
}
370+
});
371+
372+
export const THEME: Blockly.Theme = jupyterlab_theme;

0 commit comments

Comments
 (0)