Skip to content

Commit aa2fde7

Browse files
krassowskigithub-actions[bot]agriyakhetarpal
authored
Quick styling pass (#45)
* Quick styling pass * Fix filename typo * Update Playwright Snapshots * Switch to notebook sidebar on start * Revert snapshot * Add one second timeout * Update Playwright Snapshots * Ensure the logo is above notebook * Update Playwright Snapshots * Try the suggestion Co-authored-by: Agriya Khetarpal <[email protected]> * Update Playwright Snapshots --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Agriya Khetarpal <[email protected]>
1 parent c0555e1 commit aa2fde7

File tree

14 files changed

+201
-18
lines changed

14 files changed

+201
-18
lines changed

src/icons.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import {
44
folderIcon,
55
addIcon,
66
LabIcon,
7-
linkIcon
7+
linkIcon,
8+
runIcon,
9+
refreshIcon,
10+
stopIcon,
11+
fastForwardIcon
812
} from '@jupyterlab/ui-components';
913

1014
import saveSvg from '../style/icons/save.svg';
@@ -15,6 +19,11 @@ import addSvg from '../style/icons/add.svg';
1519
import linkSvg from '../style/icons/link.svg';
1620
import competitionSvg from '../style/icons/competition.svg';
1721
import notebookSvg from '../style/icons/notebook.svg';
22+
import logoSvg from '../style/icons/logo.svg';
23+
import runSvg from '../style/icons/run.svg';
24+
import refreshSvg from '../style/icons/refresh.svg';
25+
import stopSvg from '../style/icons/stop.svg';
26+
import fastForwardSvg from '../style/icons/fast-forward.svg';
1827

1928
export namespace EverywhereIcons {
2029
// Overwrite Jupyter default icons
@@ -38,7 +47,22 @@ export namespace EverywhereIcons {
3847
name: notebookIcon.name,
3948
svgstr: notebookSvg
4049
});
41-
notebookIcon;
50+
export const run = new LabIcon({
51+
name: runIcon.name,
52+
svgstr: runSvg
53+
});
54+
export const refresh = new LabIcon({
55+
name: refreshIcon.name,
56+
svgstr: refreshSvg
57+
});
58+
export const stop = new LabIcon({
59+
name: stopIcon.name,
60+
svgstr: stopSvg
61+
});
62+
export const fastForward = new LabIcon({
63+
name: fastForwardIcon.name,
64+
svgstr: fastForwardSvg
65+
});
4266
// Addd custom icons
4367
export const folderSidebar = new LabIcon({
4468
name: 'everywhere:folder-sidebar',
@@ -52,4 +76,8 @@ export namespace EverywhereIcons {
5276
name: 'everywhere:competition',
5377
svgstr: competitionSvg
5478
});
79+
export const logo = new LabIcon({
80+
name: 'everywhere:logo',
81+
svgstr: logoSvg
82+
});
5583
}

src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Dialog, showDialog, ReactWidget } from '@jupyterlab/apputils';
55
import { PageConfig } from '@jupyterlab/coreutils';
66
import { INotebookContent } from '@jupyterlab/nbformat';
77

8+
import { customSidebar } from './sidebar';
89
import { SharingService } from './sharing-service';
910

1011
import {
@@ -218,4 +219,4 @@ const plugin: JupyterFrontEndPlugin<void> = {
218219
}
219220
};
220221

221-
export default [plugin, notebookPlugin, files, competitions];
222+
export default [plugin, notebookPlugin, files, competitions, customSidebar];

src/pages/notebook.tsx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,19 @@ export const notebookPlugin: JupyterFrontEndPlugin<void> = {
6868
});
6969
}
7070

71-
shell.add(
72-
new SidebarIcon({
73-
label: 'Notebook',
74-
icon: EverywhereIcons.notebook,
75-
execute: () => {
76-
if (tracker.currentWidget) {
77-
shell.activateById(tracker.currentWidget.id);
78-
}
71+
const sidebarItem = new SidebarIcon({
72+
label: 'Notebook',
73+
icon: EverywhereIcons.notebook,
74+
execute: () => {
75+
if (tracker.currentWidget) {
76+
shell.activateById(tracker.currentWidget.id);
7977
}
80-
}),
81-
'left',
82-
{ rank: 100 }
83-
);
78+
}
79+
});
80+
shell.add(sidebarItem, 'left', { rank: 100 });
81+
82+
app.shell.activateById(sidebarItem.id);
83+
app.restored.then(() => app.shell.activateById(sidebarItem.id));
8484

8585
/**
8686
* Create a "Share" button

src/sidebar.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { TabBar, Widget } from '@lumino/widgets';
2+
import { ILabShell, JupyterFrontEnd, JupyterFrontEndPlugin } from '@jupyterlab/application';
3+
import { SidebarIcon } from './ui-components/SidebarIcon';
4+
import { EverywhereIcons } from './icons';
5+
6+
export const customSidebar: JupyterFrontEndPlugin<void> = {
7+
id: 'jupytereverywhere:sidebar',
8+
autoStart: true,
9+
requires: [ILabShell],
10+
activate: (app: JupyterFrontEnd, shell: ILabShell) => {
11+
// Overwrite behaviour of the sidebar panel
12+
const leftHandler = shell['_leftHandler'];
13+
const sidebar: TabBar<Widget> = leftHandler._sideBar;
14+
leftHandler._refreshVisibility = () => {
15+
sidebar.setHidden(false);
16+
leftHandler._stackedPanel.setHidden(true);
17+
leftHandler._updated.emit();
18+
};
19+
sidebar.currentChanged.connect(
20+
(_sender: TabBar<Widget>, args: TabBar.ICurrentChangedArgs<Widget>) => {
21+
const oldWidget = args.previousTitle
22+
? leftHandler._findWidgetByTitle(args.previousTitle)
23+
: null;
24+
const newWidget = args.currentTitle
25+
? leftHandler._findWidgetByTitle(args.currentTitle)
26+
: null;
27+
console.log(newWidget);
28+
if (newWidget && newWidget instanceof SidebarIcon) {
29+
const cancel = newWidget.execute();
30+
if (cancel) {
31+
console.log('Attempting to revert to:', oldWidget.label);
32+
if (args.previousTitle) {
33+
const previousIndex = sidebar.titles.indexOf(oldWidget);
34+
if (previousIndex >= 0) {
35+
sidebar.currentIndex = previousIndex;
36+
} else {
37+
sidebar.currentIndex = -1;
38+
}
39+
} else {
40+
sidebar.currentIndex = -1;
41+
}
42+
}
43+
}
44+
},
45+
this
46+
);
47+
// Add Jupyter Everywhere icon
48+
shell.add(
49+
new SidebarIcon({
50+
label: 'Jupyter Everywhere',
51+
icon: EverywhereIcons.logo,
52+
execute: () => {
53+
console.log('TODO');
54+
return true;
55+
}
56+
}),
57+
'left',
58+
{ rank: 0 }
59+
);
60+
}
61+
};

src/ui-components/SidebarIcon.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import { StackedPanel } from '@lumino/widgets';
44

55
// it could extend Widget, StackedPanel is just temporary as it gives 0-width layout
66
export class SidebarIcon extends StackedPanel {
7-
constructor(private _options: { label: string; icon: LabIcon; execute: () => void }) {
7+
constructor(private _options: { label: string; icon: LabIcon; execute: () => boolean | void }) {
88
super();
99
this.title.caption = _options.label;
1010
this.title.icon = _options.icon;
1111
this.id = UUID.uuid4();
1212
}
13-
protected onBeforeShow() {
14-
this._options.execute();
13+
execute() {
14+
return this._options.execute();
1515
}
1616
}

style/base.css

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,19 @@
3535
background: #e8e3e3;
3636
cursor: pointer;
3737
}
38+
39+
#jp-main-dock-panel[data-mode='single-document'] {
40+
padding: 25px !important;
41+
background: #d8b8dc;
42+
}
43+
44+
#jp-main-dock-panel[data-mode='single-document'] .jp-MainAreaWidget {
45+
border-radius: 15px;
46+
}
47+
48+
.jp-SideBar {
49+
/* Override colors in sidebar */
50+
--jp-layout-color1: #e6e6e6;
51+
--jp-layout-color2: #fff;
52+
--jp-border-width: 0px;
53+
}

style/icons/fast-forward.svg

Lines changed: 24 additions & 0 deletions
Loading

style/icons/refresh.svg

Lines changed: 26 additions & 0 deletions
Loading

style/icons/run.svg

Lines changed: 13 additions & 0 deletions
Loading

style/icons/stop.svg

Lines changed: 13 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)