|
@@ -1,16 +1,14 @@
|
|
|
// Copyright (c) Jupyter Development Team.
|
|
|
// Distributed under the terms of the Modified BSD License.
|
|
|
|
|
|
-import { Message } from '@lumino/messaging';
|
|
|
-import { h, VirtualElement } from '@lumino/virtualdom';
|
|
|
+import { hpass, VirtualElement } from '@lumino/virtualdom';
|
|
|
import { DockPanel, TabBar, Widget } from '@lumino/widgets';
|
|
|
|
|
|
-import { defaultIconRegistry } from './iconregistry';
|
|
|
-import { IconKindType } from '../style/icon';
|
|
|
+import { closeIcon } from './iconimports';
|
|
|
|
|
|
/**
|
|
|
- * A widget which displays titles as a single row or column of tabs. Tweaked
|
|
|
- * to enable the use of inline svgs as tab icons.
|
|
|
+ * a widget which displays titles as a single row or column of tabs.
|
|
|
+ * Tweaked to use an inline svg as the close icon
|
|
|
*/
|
|
|
export class TabBarSvg<T> extends TabBar<T> {
|
|
|
/**
|
|
@@ -19,66 +17,37 @@ export class TabBarSvg<T> extends TabBar<T> {
|
|
|
*
|
|
|
* @param options - The options for initializing the tab bar.
|
|
|
*/
|
|
|
- constructor(options: TabBarSvg.IOptions<T>) {
|
|
|
+ constructor(options: TabBar.IOptions<T> = {}) {
|
|
|
options.renderer = options.renderer || TabBarSvg.defaultRenderer;
|
|
|
super(options);
|
|
|
-
|
|
|
- this._kind = options.kind;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * A message handler invoked on an `'update-request'` message. Adds svg
|
|
|
- * nodes to icon nodes as appropriate
|
|
|
- */
|
|
|
- protected onUpdateRequest(msg: Message): void {
|
|
|
- super.onUpdateRequest(msg);
|
|
|
-
|
|
|
- for (let itab in this.contentNode.children) {
|
|
|
- let tab = this.contentNode.children[itab];
|
|
|
- let title = this.titles[itab];
|
|
|
- let iconNode = tab.children ? (tab.children[0] as HTMLElement) : null;
|
|
|
-
|
|
|
- if (iconNode) {
|
|
|
- // add the svg node, if not already present
|
|
|
- defaultIconRegistry.icon({
|
|
|
- name: title.iconClass,
|
|
|
- className: '',
|
|
|
- title: title.iconLabel,
|
|
|
- container: iconNode,
|
|
|
- justify: 'center',
|
|
|
- kind: this._kind
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
}
|
|
|
-
|
|
|
- protected _kind: IconKindType | undefined;
|
|
|
}
|
|
|
|
|
|
export namespace TabBarSvg {
|
|
|
- export interface IOptions<T> extends TabBar.IOptions<T> {
|
|
|
- /**
|
|
|
- * The kind of icon this tab bar widget should render.
|
|
|
- * Adds preset styling to the icons.
|
|
|
- */
|
|
|
- kind?: IconKindType;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* A modified implementation of the TabBar Renderer.
|
|
|
*/
|
|
|
export class Renderer extends TabBar.Renderer {
|
|
|
/**
|
|
|
- * Render the icon element for a tab. This version avoids clobbering
|
|
|
- * the icon node's children.
|
|
|
+ * Render the close icon element for a tab.
|
|
|
*
|
|
|
* @param data - The data to use for rendering the tab.
|
|
|
*
|
|
|
- * @returns A virtual element representing the tab icon.
|
|
|
+ * @returns A virtual element representing the tab close icon.
|
|
|
*/
|
|
|
- renderIcon(data: TabBar.IRenderData<any>): VirtualElement {
|
|
|
- let className = this.createIconClass(data);
|
|
|
- return h.div({ className });
|
|
|
+ renderCloseIcon(data: TabBar.IRenderData<any>): VirtualElement {
|
|
|
+ const className = closeIcon.class({
|
|
|
+ className: 'jp-icon-hover p-TabBar-tabCloseIcon',
|
|
|
+ justify: 'center',
|
|
|
+ height: '16px',
|
|
|
+ width: '16px'
|
|
|
+ });
|
|
|
+
|
|
|
+ return (hpass(
|
|
|
+ 'div',
|
|
|
+ { className },
|
|
|
+ closeIcon
|
|
|
+ ) as unknown) as VirtualElement;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -86,43 +55,26 @@ export namespace TabBarSvg {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * A widget which provides a flexible docking area for widgets.Tweaked
|
|
|
- * to enable the use of inline svgs as tab icons.
|
|
|
+ * a widget which provides a flexible docking area for widgets.
|
|
|
+ * Tweaked to use an inline svg as the close icon
|
|
|
*/
|
|
|
export class DockPanelSvg extends DockPanel {
|
|
|
/**
|
|
|
- * Construct a new dock panel. Overrides the default renderer
|
|
|
- * and sets the (icon) kind
|
|
|
+ * Construct a new dock panel.
|
|
|
*
|
|
|
* @param options - The options for initializing the panel.
|
|
|
*/
|
|
|
- constructor(options: DockPanelSvg.IOptions) {
|
|
|
- if (!options.renderer) {
|
|
|
- options.renderer = new DockPanelSvg.Renderer(options.kind);
|
|
|
- }
|
|
|
-
|
|
|
+ constructor(options: DockPanel.IOptions = {}) {
|
|
|
+ options.renderer = options.renderer || DockPanelSvg.defaultRenderer;
|
|
|
super(options);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export namespace DockPanelSvg {
|
|
|
- export interface IOptions extends DockPanel.IOptions {
|
|
|
- /**
|
|
|
- * The kind of icon this dock panel widget should render.
|
|
|
- * Adds preset styling to the icons.
|
|
|
- */
|
|
|
- kind?: IconKindType;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* A modified implementation of the DockPanel Renderer.
|
|
|
*/
|
|
|
export class Renderer extends DockPanel.Renderer {
|
|
|
- constructor(kind?: IconKindType) {
|
|
|
- super();
|
|
|
- this._kind = kind;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* Create a new tab bar (with inline svg icons enabled
|
|
|
* for use with a dock panel.
|
|
@@ -130,13 +82,11 @@ export namespace DockPanelSvg {
|
|
|
* @returns A new tab bar for a dock panel.
|
|
|
*/
|
|
|
createTabBar(): TabBarSvg<Widget> {
|
|
|
- let bar = new TabBarSvg<Widget>({
|
|
|
- kind: this._kind
|
|
|
- });
|
|
|
+ let bar = new TabBarSvg<Widget>();
|
|
|
bar.addClass('p-DockPanel-tabBar');
|
|
|
return bar;
|
|
|
}
|
|
|
-
|
|
|
- _kind: IconKindType | undefined;
|
|
|
}
|
|
|
+
|
|
|
+ export const defaultRenderer = new Renderer();
|
|
|
}
|