Skip to content

Commit abd2c65

Browse files
committed
Toggle full width
1 parent 676a0fe commit abd2c65

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"title": "Jupyter Notebook Full Width Notebook",
3+
"description": "Jupyter Notebook Full Width Notebook",
4+
"jupyter.lab.menus": {
5+
"main": [
6+
{
7+
"id": "jp-mainmenu-view",
8+
"items": [
9+
{
10+
"command": "notebook:toggle-full-width",
11+
"rank": 4
12+
}
13+
]
14+
}
15+
]
16+
},
17+
"properties": {
18+
"fullWidthNotebook": {
19+
"type": "boolean",
20+
"title": "Full Width Notebook",
21+
"description": "Whether to the notebook should take up the full width of the application",
22+
"default": false
23+
}
24+
},
25+
"additionalProperties": false,
26+
"type": "object"
27+
}

packages/notebook-extension/src/index.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ const KERNEL_STATUS_FADE_OUT_CLASS = 'jp-NotebookKernelStatus-fade';
6464
*/
6565
const SCROLLED_OUTPUTS_CLASS = 'jp-mod-outputsScrolled';
6666

67+
/**
68+
* The class for the full width notebook
69+
*/
70+
const FULL_WIDTH_NOTEBOOK_CLASS = 'jp-mod-fullwidth';
71+
6772
/**
6873
* The command IDs used by the notebook plugins.
6974
*/
@@ -72,6 +77,11 @@ namespace CommandIDs {
7277
* A command to open right sidebar for Editing Notebook Metadata
7378
*/
7479
export const openEditNotebookMetadata = 'notebook:edit-metadata';
80+
81+
/**
82+
* A command to toggle full width of the notebook
83+
*/
84+
export const toggleFullWidth = 'notebook:toggle-full-width';
7585
}
7686

7787
/**
@@ -202,6 +212,47 @@ const openTreeTab: JupyterFrontEndPlugin<void> = {
202212
},
203213
};
204214

215+
/**
216+
* A plugin to set the notebook to full width.
217+
*/
218+
const fullWidthNotebook: JupyterFrontEndPlugin<void> = {
219+
id: '@jupyter-notebook/notebook-extension:full-width-notebook',
220+
description: 'A plugin to set the notebook to full width.',
221+
autoStart: true,
222+
requires: [INotebookTracker],
223+
optional: [ICommandPalette, ISettingRegistry, ITranslator],
224+
activate: (
225+
app: JupyterFrontEnd,
226+
tracker: INotebookTracker,
227+
palette: ICommandPalette | null,
228+
settingRegistry: ISettingRegistry | null,
229+
translator: ITranslator | null
230+
) => {
231+
const trans = (translator ?? nullTranslator).load('notebook');
232+
233+
const toggleFullWidth = () => {
234+
const current = tracker.currentWidget;
235+
if (!current) {
236+
return;
237+
}
238+
current.content.toggleClass(FULL_WIDTH_NOTEBOOK_CLASS);
239+
};
240+
241+
// add a command to toggle full width
242+
app.commands.addCommand(CommandIDs.toggleFullWidth, {
243+
label: trans.__('Toggle Full Width'),
244+
execute: toggleFullWidth,
245+
});
246+
247+
if (palette) {
248+
palette.addItem({
249+
command: CommandIDs.toggleFullWidth,
250+
category: 'Notebook Operations',
251+
});
252+
}
253+
},
254+
};
255+
205256
/**
206257
* The kernel logo plugin.
207258
*/
@@ -597,6 +648,7 @@ const plugins: JupyterFrontEndPlugin<any>[] = [
597648
closeTab,
598649
openTreeTab,
599650
editNotebookMetadata,
651+
fullWidthNotebook,
600652
kernelLogo,
601653
kernelStatus,
602654
notebookToolsWidget,

packages/notebook-extension/style/base.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,20 @@
1818

1919
/* Keep the notebook centered on the page */
2020

21+
2122
body[data-notebook='notebooks'] .jp-NotebookPanel-toolbar {
2223
padding-left: calc(calc(100% - var(--jp-notebook-max-width)) * 0.5);
2324
padding-right: calc(calc(100% - var(--jp-notebook-max-width)) * 0.5);
2425
}
2526

27+
/* Make the notebook take up the full width of the page when jp-mod-fullwidth is set */
28+
body[data-notebook='notebooks'] .jp-Notebook.jp-mod-fullwidth .jp-WindowedPanel-outer {
29+
padding-left: unset;
30+
padding-right: unset !important;
31+
width: unset;
32+
}
33+
34+
/* Default notebook layout with a max-width */
2635
body[data-notebook='notebooks'] .jp-WindowedPanel-outer {
2736
width: unset !important;
2837
padding-top: unset;

0 commit comments

Comments
 (0)