Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add settings to override theme font sizes #6926

Merged
merged 24 commits into from Aug 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
16eb75a
adding overrides for all of the theme font sizes
telamonian Jul 31, 2019
f64325f
the font size settings now work
telamonian Jul 31, 2019
9f32ff4
setting font size to empty now correctly restores original theme size
telamonian Jul 31, 2019
a00df0b
added arbitrary theme CSS overrides to settings
telamonian Aug 3, 2019
b6291f1
simplified syntax of theme override settings
telamonian Aug 3, 2019
c39a4ce
default theme override settings
telamonian Aug 3, 2019
b1d4db7
added theme font size incr/decr items to settings menu
telamonian Aug 7, 2019
c118399
theme palette items now have parity with theme settings menu items
telamonian Aug 7, 2019
9ef802f
cleanup
telamonian Aug 7, 2019
2488d07
improved unsettinng of CSS overrides
telamonian Aug 13, 2019
fc40623
added `"additionalProperties": false` to CSS overrides schema
telamonian Aug 13, 2019
c2db5bd
ran `jlpm run lint`, fixed complaints
telamonian Aug 13, 2019
b87c4d0
cleanup/simplification
telamonian Aug 14, 2019
8065460
improved incrFontSize to work with non-default font sizes in themes
telamonian Aug 14, 2019
92e8093
cleanup
telamonian Aug 14, 2019
d40dddf
more cleanup
telamonian Aug 14, 2019
b3f36ad
added validation of CSS override values
telamonian Aug 14, 2019
45bca49
simplified some code
telamonian Aug 14, 2019
8cb3108
improved validation of CSS override values
telamonian Aug 15, 2019
d6c2bfc
had to rearrange some json in order to get the defaults to display co…
telamonian Aug 15, 2019
6bf371e
added docstring
telamonian Aug 15, 2019
54b9fc0
fix for CSS font size validation in Firefox
telamonian Aug 22, 2019
6e9dfd7
partial fix for scrollbar theming toggle
telamonian Aug 22, 2019
997b4fe
fixed `isToggled` param of 'apputils:theme-scrollbars' command
telamonian Aug 22, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/application/style/scrollbar.css
Expand Up @@ -8,12 +8,13 @@
*/

/* use standard opaque scrollbars for most nodes */
div.jp-LabShell[data-jp-theme-scrollbars='true'] {
[data-jp-theme-scrollbars='true'] {
scrollbar-color: rgb(var(--jp-scrollbar-thumb-color))
var(--jp-scrollbar-background-color);
}

/* for code nodes, use a transparent style of scrollbar */
/* for code nodes, use a transparent style of scrollbar. These selectors
* will match lower in the tree, and so will override the above */
[data-jp-theme-scrollbars='true'] .CodeMirror-hscrollbar,
[data-jp-theme-scrollbars='true'] .CodeMirror-vscrollbar {
scrollbar-color: rgba(var(--jp-scrollbar-thumb-color), 0.5) transparent;
Expand Down
35 changes: 33 additions & 2 deletions packages/apputils-extension/schema/themes.json
Expand Up @@ -2,7 +2,29 @@
"title": "Theme",
"jupyter.lab.setting-icon-label": "Theme Manager",
"description": "Theme manager settings.",
"type": "object",
"additionalProperties": false,
"definitions": {
"cssOverrides": {
"type": "object",
"additionalProperties": false,
"description": "The description field of each item is the CSS property that will be used to validate an override's value",
"properties": {
"code-font-size": {
"type": ["string", "null"],
"description": "font-size"
},
"content-font-size1": {
"type": ["string", "null"],
"description": "font-size"
},
"ui-font-size1": {
"type": ["string", "null"],
"description": "font-size"
}
}
}
},
"properties": {
"theme": {
"type": "string",
Expand All @@ -15,7 +37,16 @@
"title": "Scrollbar Theming",
"description": "Enable/disable styling of the application scrollbars",
"default": false
},
"overrides": {
"title": "Theme CSS Overrides",
"description": "Override theme CSS variables by setting key-value pairs here",
"$ref": "#/definitions/cssOverrides",
"default": {
"code-font-size": null,
"content-font-size1": null,
"ui-font-size1": null
}
}
},
"type": "object"
}
}
136 changes: 4 additions & 132 deletions packages/apputils-extension/src/index.ts
Expand Up @@ -14,9 +14,7 @@ import {
Dialog,
ICommandPalette,
ISplashScreen,
IThemeManager,
IWindowResolver,
ThemeManager,
WindowResolver,
Printing
} from '@jupyterlab/apputils';
Expand All @@ -32,18 +30,16 @@ import {
URLExt
} from '@jupyterlab/coreutils';

import { IMainMenu } from '@jupyterlab/mainmenu';

import { defaultIconRegistry } from '@jupyterlab/ui-components';

import { PromiseDelegate } from '@phosphor/coreutils';

import { DisposableDelegate } from '@phosphor/disposable';

import { Menu } from '@phosphor/widgets';

import { Palette } from './palette';

import { themesPlugin, themesPaletteMenuPlugin } from './themeplugins';

/**
* The interval in milliseconds before recover options appear during splash.
*/
Expand All @@ -53,8 +49,6 @@ const SPLASH_RECOVER_TIMEOUT = 12000;
* The command IDs used by the apputils plugin.
*/
namespace CommandIDs {
export const changeTheme = 'apputils:change-theme';

export const loadState = 'apputils:load-statedb';

export const print = 'apputils:print';
Expand Down Expand Up @@ -105,128 +99,6 @@ const settings: JupyterFrontEndPlugin<ISettingRegistry> = {
provides: ISettingRegistry
};

/**
* The default theme manager provider.
*/
const themes: JupyterFrontEndPlugin<IThemeManager> = {
id: '@jupyterlab/apputils-extension:themes',
requires: [ISettingRegistry, JupyterFrontEnd.IPaths],
optional: [ISplashScreen],
activate: (
app: JupyterFrontEnd,
settings: ISettingRegistry,
paths: JupyterFrontEnd.IPaths,
splash: ISplashScreen | null
): IThemeManager => {
const host = app.shell;
const commands = app.commands;
const url = URLExt.join(paths.urls.base, paths.urls.themes);
const key = themes.id;
const manager = new ThemeManager({ key, host, settings, splash, url });

// Keep a synchronously set reference to the current theme,
// since the asynchronous setting of the theme in `changeTheme`
// can lead to an incorrect toggle on the currently used theme.
let currentTheme: string;

// Set data attributes on the application shell for the current theme.
manager.themeChanged.connect((sender, args) => {
currentTheme = args.newValue;
document.body.dataset.jpThemeLight = String(
manager.isLight(currentTheme)
);
document.body.dataset.jpThemeName = currentTheme;
if (
document.body.dataset.jpThemeScrollbars !==
String(manager.themeScrollbars(currentTheme))
) {
document.body.dataset.jpThemeScrollbars = String(
manager.themeScrollbars(currentTheme)
);
}
commands.notifyCommandChanged(CommandIDs.changeTheme);
});

commands.addCommand(CommandIDs.changeTheme, {
label: args => {
const theme = args['theme'] as string;
return args['isPalette'] ? `Use ${theme} Theme` : theme;
},
isToggled: args => args['theme'] === currentTheme,
execute: args => {
const theme = args['theme'] as string;
if (theme === manager.theme) {
return;
}
return manager.setTheme(theme);
}
});

return manager;
},
autoStart: true,
provides: IThemeManager
};

/**
* The default theme manager's UI command palette and main menu functionality.
*
* #### Notes
* This plugin loads separately from the theme manager plugin in order to
* prevent blocking of the theme manager while it waits for the command palette
* and main menu to become available.
*/
const themesPaletteMenu: JupyterFrontEndPlugin<void> = {
id: '@jupyterlab/apputils-extension:themes-palette-menu',
requires: [IThemeManager],
optional: [ICommandPalette, IMainMenu],
activate: (
app: JupyterFrontEnd,
manager: IThemeManager,
palette: ICommandPalette | null,
mainMenu: IMainMenu | null
): void => {
const commands = app.commands;

// If we have a main menu, add the theme manager to the settings menu.
if (mainMenu) {
const themeMenu = new Menu({ commands });
themeMenu.title.label = 'JupyterLab Theme';
void app.restored.then(() => {
const command = CommandIDs.changeTheme;
const isPalette = false;

manager.themes.forEach(theme => {
themeMenu.addItem({ command, args: { isPalette, theme } });
});
});
mainMenu.settingsMenu.addGroup(
[
{
type: 'submenu' as Menu.ItemType,
submenu: themeMenu
}
],
0
);
}

// If we have a command palette, add theme switching options to it.
if (palette) {
void app.restored.then(() => {
const category = 'Settings';
const command = CommandIDs.changeTheme;
const isPalette = true;

manager.themes.forEach(theme => {
palette.addItem({ command, args: { isPalette, theme }, category });
});
});
}
},
autoStart: true
};

/**
* The default window name resolver provider.
*/
Expand Down Expand Up @@ -594,8 +466,8 @@ const plugins: JupyterFrontEndPlugin<any>[] = [
settings,
state,
splash,
themes,
themesPaletteMenu,
themesPlugin,
themesPaletteMenuPlugin,
print
];
export default plugins;
Expand Down