UNPKG

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