UNPKG

3.42 kBJavaScriptView Raw
1// Copyright (c) Jupyter Development Team.
2// Distributed under the terms of the Modified BSD License.
3import { hpass } from '@lumino/virtualdom';
4import { DockPanel, TabBar, TabPanel } from '@lumino/widgets';
5import { LabIconStyle } from '../../style';
6import { classes } from '../../utils';
7import { addIcon, closeIcon } from '../iconimports';
8import { nullTranslator } from '@jupyterlab/translation';
9/**
10 * a widget which displays titles as a single row or column of tabs.
11 * Tweaked to use an inline svg as the close icon
12 */
13export class TabBarSvg extends TabBar {
14 /**
15 * Construct a new tab bar. Overrides the default renderer.
16 *
17 * @param options - The options for initializing the tab bar.
18 */
19 constructor(options = {}) {
20 options.renderer = options.renderer || TabBarSvg.defaultRenderer;
21 super(options);
22 const trans = ((options && options.translator) || nullTranslator).load('jupyterlab');
23 addIcon.element({
24 container: this.addButtonNode,
25 title: trans.__('New Launcher')
26 });
27 }
28}
29(function (TabBarSvg) {
30 /**
31 * A modified implementation of the TabBar Renderer.
32 */
33 class Renderer extends TabBar.Renderer {
34 /**
35 * Render the close icon element for a tab.
36 *
37 * @param data - The data to use for rendering the tab.
38 *
39 * @returns A virtual element representing the tab close icon.
40 */
41 renderCloseIcon(data) {
42 const className = classes('jp-icon-hover lm-TabBar-tabCloseIcon', LabIconStyle.styleClass({
43 elementPosition: 'center',
44 height: '16px',
45 width: '16px'
46 }));
47 return hpass('div', { className }, closeIcon);
48 }
49 }
50 TabBarSvg.Renderer = Renderer;
51 TabBarSvg.defaultRenderer = new Renderer();
52})(TabBarSvg || (TabBarSvg = {}));
53/**
54 * a widget which provides a flexible docking area for widgets.
55 * Tweaked to use an inline svg as the close icon
56 */
57export class DockPanelSvg extends DockPanel {
58 /**
59 * Construct a new dock panel.
60 *
61 * @param options - The options for initializing the panel.
62 */
63 constructor(options = {}) {
64 options.renderer = options.renderer || DockPanelSvg.defaultRenderer;
65 super(options);
66 }
67}
68(function (DockPanelSvg) {
69 /**
70 * A modified implementation of the DockPanel Renderer.
71 */
72 class Renderer extends DockPanel.Renderer {
73 /**
74 * Create a new tab bar (with inline svg icons enabled
75 * for use with a dock panel.
76 *
77 * @returns A new tab bar for a dock panel.
78 */
79 createTabBar() {
80 const bar = new TabBarSvg();
81 bar.addClass('lm-DockPanel-tabBar');
82 return bar;
83 }
84 }
85 DockPanelSvg.Renderer = Renderer;
86 DockPanelSvg.defaultRenderer = new Renderer();
87})(DockPanelSvg || (DockPanelSvg = {}));
88/**
89 * A widget which combines a `TabBar` and a `StackedPanel`.
90 * Tweaked to use an inline svg as the close icon
91 */
92export class TabPanelSvg extends TabPanel {
93 /**
94 * Construct a new tab panel.
95 *
96 * @param options - The options for initializing the tab panel.
97 */
98 constructor(options = {}) {
99 options.renderer = options.renderer || TabBarSvg.defaultRenderer;
100 super(options);
101 }
102}
103//# sourceMappingURL=tabbarsvg.js.map
\No newline at end of file