Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Expand css variables when setting blockly theme #104

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"prettier": "jlpm prettier:base --write --list-different",
"prettier:base": "prettier \"**/*{.ts,.tsx,.js,.jsx,.css}\"",
"prettier:check": "jlpm prettier:base --check",
"watch": "lerna run --stream watch"
"watch": "lerna run --stream --parallel watch"
},
"dependencies": {
"@typescript-eslint/eslint-plugin": "^5.12.1",
Expand Down
3 changes: 2 additions & 1 deletion packages/blockly/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"clean": "jlpm clean:lib",
"clean:lib": "rimraf lib tsconfig.tsbuildinfo",
"clean:all": "jlpm clean:lib",
"install:extension": "jlpm build"
"install:extension": "jlpm build",
"watch": "tsc -w --sourceMap"
},
"dependencies": {
"@blockly/field-colour": "5.0.6",
Expand Down
6 changes: 4 additions & 2 deletions packages/blockly/src/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Signal } from '@lumino/signaling';
import * as Blockly from 'blockly';

import { BlocklyManager } from './manager';
import { THEME } from './utils';
import { getTheme } from './utils';

/**
* A blockly layout to host the Blockly editor.
Expand Down Expand Up @@ -207,6 +207,8 @@ export class BlocklyLayout extends SplitLayout {
*/
protected onFitRequest(msg: Message): void {
super.onFitRequest(msg);
// Can be a result of a theme change
this._workspace.setTheme(getTheme());
this._resizeWorkspace();
}

Expand All @@ -218,7 +220,7 @@ export class BlocklyLayout extends SplitLayout {
//inject Blockly with appropiate JupyterLab theme.
this._workspace = Blockly.inject(this._host.node, {
toolbox: this._manager.toolbox,
theme: THEME
theme: getTheme()
});

this._workspace.addChangeListener(() => {
Expand Down
47 changes: 26 additions & 21 deletions packages/blockly/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,25 +352,30 @@ export const TOOLBOX = {
]
};

// Defining a Blockly Theme in accordance with the current JupyterLab Theme.
const jupyterlab_theme = Blockly.Theme.defineTheme('jupyterlab', {
name: 'JupyterLab Blockly',
base: Blockly.Themes.Classic,
componentStyles: {
workspaceBackgroundColour: 'var(--jp-layout-color0)',
toolboxBackgroundColour: 'var(--jp-layout-color2)',
toolboxForegroundColour: 'var(--jp-ui-font-color0)',
flyoutBackgroundColour: 'var(--jp-border-color2)',
flyoutForegroundColour: 'var(--jp-layout-color3)',
flyoutOpacity: 1,
scrollbarColour: 'var(--jp-border-color0)',
insertionMarkerOpacity: 0.3,
scrollbarOpacity: 0.4,
cursorColour: 'var(--jp-scrollbar-background-color)'
},
fontStyle: {
family: 'var(--jp-ui-font-family)'
}
});
const getJupyterLabTheme = (): Blockly.Theme => {
const rootStyles = getComputedStyle(document.documentElement);

export const THEME: Blockly.Theme = jupyterlab_theme;
const getStyle = (style: string) => rootStyles.getPropertyValue(style);

return Blockly.Theme.defineTheme('jupyterLab', {
name: 'JupyterLab',
base: Blockly.Themes.Classic,
componentStyles: {
workspaceBackgroundColour: getStyle('--jp-layout-color0'),
toolboxBackgroundColour: getStyle('--jp-layout-color2'),
toolboxForegroundColour: getStyle('--jp-ui-font-color0'),
flyoutBackgroundColour: getStyle('--jp-border-color2'),
flyoutForegroundColour: getStyle('--jp-layout-color3'),
flyoutOpacity: 1,
scrollbarColour: getStyle('--jp-border-color0'),
insertionMarkerOpacity: 0.3,
scrollbarOpacity: 0.4,
cursorColour: getStyle('--jp-scrollbar-background-color')
},
fontStyle: {
family: getStyle('--jp-ui-font-family')
}
});
};

export const getTheme = getJupyterLabTheme;
Loading