@jupyterlab/ui-components 4.0.0-alpha.33 → 4.0.0-alpha.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/components/form.d.ts +17 -2
- package/lib/components/form.js +52 -11
- package/lib/components/form.js.map +1 -1
- package/lib/components/vdom.d.ts +1 -1
- package/lib/components/windowedlist.d.ts +1 -1
- package/lib/components/windowedlist.js +2 -1
- package/lib/components/windowedlist.js.map +1 -1
- package/lib/hoverbox.d.ts +1 -1
- package/lib/icon/labicon.js +49 -48
- package/lib/icon/labicon.js.map +1 -1
- package/lib/icon/widgets/tabbarsvg.js +2 -1
- package/lib/icon/widgets/tabbarsvg.js.map +1 -1
- package/lib/tokens.d.ts +1 -1
- package/package.json +22 -20
- package/src/FormRendererRegistry.tsx +60 -0
- package/src/components/accordiontoolbar.ts +252 -0
- package/src/components/button.tsx +45 -0
- package/src/components/collapser.ts +176 -0
- package/src/components/form.tsx +678 -0
- package/src/components/htmlselect.tsx +99 -0
- package/src/components/iframe.ts +153 -0
- package/src/components/index.ts +20 -0
- package/src/components/inputgroup.tsx +51 -0
- package/src/components/interface.ts +9 -0
- package/src/components/menu.ts +442 -0
- package/src/components/panelwithtoolbar.ts +41 -0
- package/src/components/search.tsx +216 -0
- package/src/components/sidepanel.ts +168 -0
- package/src/components/spinner.ts +31 -0
- package/src/components/styling.ts +114 -0
- package/src/components/switch.ts +103 -0
- package/src/components/toolbar.tsx +1119 -0
- package/src/components/vdom.ts +324 -0
- package/src/components/windowedlist.ts +1422 -0
- package/src/hoverbox.ts +401 -0
- package/src/icon/iconimports.ts +206 -0
- package/src/icon/index.ts +6 -0
- package/src/icon/labicon.tsx +955 -0
- package/src/icon/widgets/commandpalettesvg.ts +78 -0
- package/src/icon/widgets/index.ts +6 -0
- package/src/icon/widgets/menusvg.ts +218 -0
- package/src/icon/widgets/tabbarsvg.ts +122 -0
- package/src/index.ts +13 -0
- package/src/style/icon.ts +581 -0
- package/src/style/index.ts +4 -0
- package/src/svg.d.ts +58 -0
- package/src/tokens.ts +68 -0
- package/src/utils.ts +90 -0
- package/style/rjsfTemplates.css +0 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jupyterlab/ui-components",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.35",
|
|
4
4
|
"description": "JupyterLab - UI components written in React",
|
|
5
5
|
"homepage": "https://github.com/jupyterlab/jupyterlab",
|
|
6
6
|
"bugs": {
|
|
@@ -24,7 +24,8 @@
|
|
|
24
24
|
"files": [
|
|
25
25
|
"lib/**/*.{d.ts,eot,gif,html,jpg,js,js.map,json,png,svg,woff2,ttf}",
|
|
26
26
|
"style/**/*.{css,eot,gif,html,jpg,json,png,svg,woff2,ttf}",
|
|
27
|
-
"style/index.js"
|
|
27
|
+
"style/index.js",
|
|
28
|
+
"src/**/*.{ts,tsx}"
|
|
28
29
|
],
|
|
29
30
|
"scripts": {
|
|
30
31
|
"build": "tsc -b",
|
|
@@ -40,33 +41,34 @@
|
|
|
40
41
|
"watch": "tsc -b --watch"
|
|
41
42
|
},
|
|
42
43
|
"dependencies": {
|
|
43
|
-
"@jupyterlab/coreutils": "^6.0.0-alpha.
|
|
44
|
-
"@jupyterlab/observables": "^5.0.0-alpha.
|
|
45
|
-
"@jupyterlab/rendermime-interfaces": "^3.8.0-alpha.
|
|
46
|
-
"@jupyterlab/translation": "^4.0.0-alpha.
|
|
47
|
-
"@lumino/algorithm": "^2.0.0-
|
|
48
|
-
"@lumino/commands": "^2.0.0-
|
|
49
|
-
"@lumino/coreutils": "^2.0.0-
|
|
50
|
-
"@lumino/disposable": "^2.0.0-
|
|
51
|
-
"@lumino/messaging": "^2.0.0-
|
|
52
|
-
"@lumino/polling": "^2.0.0-
|
|
53
|
-
"@lumino/properties": "^2.0.0-
|
|
54
|
-
"@lumino/signaling": "^2.0.0-
|
|
55
|
-
"@lumino/virtualdom": "^2.0.0-
|
|
56
|
-
"@lumino/widgets": "^2.0.0-
|
|
57
|
-
"@rjsf/core": "^
|
|
44
|
+
"@jupyterlab/coreutils": "^6.0.0-alpha.20",
|
|
45
|
+
"@jupyterlab/observables": "^5.0.0-alpha.20",
|
|
46
|
+
"@jupyterlab/rendermime-interfaces": "^3.8.0-alpha.20",
|
|
47
|
+
"@jupyterlab/translation": "^4.0.0-alpha.20",
|
|
48
|
+
"@lumino/algorithm": "^2.0.0-rc.0",
|
|
49
|
+
"@lumino/commands": "^2.0.0-rc.0",
|
|
50
|
+
"@lumino/coreutils": "^2.0.0-rc.0",
|
|
51
|
+
"@lumino/disposable": "^2.0.0-rc.0",
|
|
52
|
+
"@lumino/messaging": "^2.0.0-rc.0",
|
|
53
|
+
"@lumino/polling": "^2.0.0-rc.0",
|
|
54
|
+
"@lumino/properties": "^2.0.0-rc.0",
|
|
55
|
+
"@lumino/signaling": "^2.0.0-rc.0",
|
|
56
|
+
"@lumino/virtualdom": "^2.0.0-rc.0",
|
|
57
|
+
"@lumino/widgets": "^2.0.0-rc.0",
|
|
58
|
+
"@rjsf/core": "^5.1.0",
|
|
59
|
+
"@rjsf/utils": "^5.1.0",
|
|
58
60
|
"react": "^18.2.0",
|
|
59
61
|
"react-dom": "^18.2.0",
|
|
60
62
|
"typestyle": "^2.0.4"
|
|
61
63
|
},
|
|
62
64
|
"devDependencies": {
|
|
63
|
-
"@jupyterlab/testing": "^4.0.0-alpha.
|
|
65
|
+
"@jupyterlab/testing": "^4.0.0-alpha.20",
|
|
64
66
|
"@types/jest": "^29.2.0",
|
|
65
67
|
"@types/react": "^18.0.26",
|
|
66
68
|
"rimraf": "~3.0.0",
|
|
67
69
|
"svgo": "^3.0.1",
|
|
68
|
-
"typedoc": "~0.
|
|
69
|
-
"typescript": "~
|
|
70
|
+
"typedoc": "~0.23.25",
|
|
71
|
+
"typescript": "~5.0.0-beta"
|
|
70
72
|
},
|
|
71
73
|
"peerDependencies": {
|
|
72
74
|
"react": "^18.2.0"
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/* -----------------------------------------------------------------------------
|
|
2
|
+
| Copyright (c) Jupyter Development Team.
|
|
3
|
+
| Distributed under the terms of the Modified BSD License.
|
|
4
|
+
|----------------------------------------------------------------------------*/
|
|
5
|
+
|
|
6
|
+
import { IFormRenderer, IFormRendererRegistry } from './tokens';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A registry for property renderers used in the FormEditor component.
|
|
10
|
+
*/
|
|
11
|
+
export class FormRendererRegistry implements IFormRendererRegistry {
|
|
12
|
+
/**
|
|
13
|
+
* Adds a renderer for a given property of a given settings plugin.
|
|
14
|
+
*
|
|
15
|
+
* The id must follow that structure `<ISettingRegistry.IPlugin.id>.<propertyName>`
|
|
16
|
+
*
|
|
17
|
+
* @param id - Unique ID for the given renderer.
|
|
18
|
+
* @param renderer - A renderer interfacing IFormRenderer.
|
|
19
|
+
*/
|
|
20
|
+
addRenderer(id: string, renderer: IFormRenderer): void {
|
|
21
|
+
if (this._renderers[id]) {
|
|
22
|
+
throw new Error(`A renderer with id '${id}' is already registered.`);
|
|
23
|
+
}
|
|
24
|
+
if (!renderer.fieldRenderer && !renderer.widgetRenderer) {
|
|
25
|
+
throw new Error(
|
|
26
|
+
`The component for '${id}' cannot be registered as it does not define 'fieldRenderer' nor 'widgetRenderer'.`
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const splitPosition = id.lastIndexOf('.');
|
|
31
|
+
const pluginId = id.substring(0, splitPosition);
|
|
32
|
+
const propertyName = id.substring(splitPosition + 1);
|
|
33
|
+
if (pluginId.length == 0 || propertyName.length == 0) {
|
|
34
|
+
throw new Error(
|
|
35
|
+
`Form renderer id must follows the structure '<ISettingRegistry.IPlugin.id>.<propertyName>'; got ${id}.`
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
this._renderers[id] = renderer;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Returns all registered renderers in dictionary form.
|
|
44
|
+
* @returns - A dictionary that maps an id to a renderer.
|
|
45
|
+
*/
|
|
46
|
+
get renderers(): { [id: string]: IFormRenderer } {
|
|
47
|
+
return this._renderers;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Returns the renderer for the given id
|
|
52
|
+
* @param id - The unique id for the renderer.
|
|
53
|
+
* @returns - A renderer interfacing IFormRenderer.
|
|
54
|
+
*/
|
|
55
|
+
getRenderer(id: string): IFormRenderer {
|
|
56
|
+
return this._renderers[id];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
private _renderers: { [id: string]: IFormRenderer } = {};
|
|
60
|
+
}
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
// Copyright (c) Jupyter Development Team.
|
|
2
|
+
// Distributed under the terms of the Modified BSD License.
|
|
3
|
+
|
|
4
|
+
import { Message, MessageLoop } from '@lumino/messaging';
|
|
5
|
+
import {
|
|
6
|
+
AccordionLayout,
|
|
7
|
+
AccordionPanel,
|
|
8
|
+
Title,
|
|
9
|
+
Widget
|
|
10
|
+
} from '@lumino/widgets';
|
|
11
|
+
import { caretDownIcon } from '../icon';
|
|
12
|
+
import { Toolbar } from './toolbar';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Accordion panel layout that adds a toolbar in widget title if present.
|
|
16
|
+
*/
|
|
17
|
+
class AccordionToolbarLayout extends AccordionLayout {
|
|
18
|
+
/**
|
|
19
|
+
* Insert a widget into the layout at the specified index.
|
|
20
|
+
*
|
|
21
|
+
* @param index - The index at which to insert the widget.
|
|
22
|
+
*
|
|
23
|
+
* @param widget - The widget to insert into the layout.
|
|
24
|
+
*
|
|
25
|
+
* #### Notes
|
|
26
|
+
* The index will be clamped to the bounds of the widgets.
|
|
27
|
+
*
|
|
28
|
+
* If the widget is already added to the layout, it will be moved.
|
|
29
|
+
*
|
|
30
|
+
* #### Undefined Behavior
|
|
31
|
+
* An `index` which is non-integral.
|
|
32
|
+
*/
|
|
33
|
+
insertWidget(index: number, widget: Toolbar.IWidgetToolbar): void {
|
|
34
|
+
if (widget.toolbar) {
|
|
35
|
+
this._toolbars.set(widget, widget.toolbar);
|
|
36
|
+
widget.toolbar.addClass('jp-AccordionPanel-toolbar');
|
|
37
|
+
}
|
|
38
|
+
super.insertWidget(index, widget);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Remove the widget at a given index from the layout.
|
|
43
|
+
*
|
|
44
|
+
* @param index - The index of the widget to remove.
|
|
45
|
+
*
|
|
46
|
+
* #### Notes
|
|
47
|
+
* A widget is automatically removed from the layout when its `parent`
|
|
48
|
+
* is set to `null`. This method should only be invoked directly when
|
|
49
|
+
* removing a widget from a layout which has yet to be installed on a
|
|
50
|
+
* parent widget.
|
|
51
|
+
*
|
|
52
|
+
* This method does *not* modify the widget's `parent`.
|
|
53
|
+
*
|
|
54
|
+
* #### Undefined Behavior
|
|
55
|
+
* An `index` which is non-integral.
|
|
56
|
+
*/
|
|
57
|
+
removeWidgetAt(index: number): void {
|
|
58
|
+
const widget = this.widgets[index];
|
|
59
|
+
super.removeWidgetAt(index);
|
|
60
|
+
// Remove the toolbar after the widget has `removeWidgetAt` will call `detachWidget`
|
|
61
|
+
if (widget && this._toolbars.has(widget)) {
|
|
62
|
+
this._toolbars.delete(widget);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Attach a widget to the parent's DOM node.
|
|
68
|
+
*
|
|
69
|
+
* @param index - The current index of the widget in the layout.
|
|
70
|
+
*
|
|
71
|
+
* @param widget - The widget to attach to the parent.
|
|
72
|
+
*/
|
|
73
|
+
protected attachWidget(index: number, widget: Widget): void {
|
|
74
|
+
super.attachWidget(index, widget);
|
|
75
|
+
|
|
76
|
+
const toolbar = this._toolbars.get(widget);
|
|
77
|
+
if (toolbar) {
|
|
78
|
+
// Send a `'before-attach'` message if the parent is attached.
|
|
79
|
+
if (this.parent!.isAttached) {
|
|
80
|
+
MessageLoop.sendMessage(toolbar, Widget.Msg.BeforeAttach);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Insert the toolbar in the title node.
|
|
84
|
+
this.titles[index].appendChild(toolbar.node);
|
|
85
|
+
|
|
86
|
+
// Send an `'after-attach'` message if the parent is attached.
|
|
87
|
+
if (this.parent!.isAttached) {
|
|
88
|
+
MessageLoop.sendMessage(toolbar, Widget.Msg.AfterAttach);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Detach a widget from the parent's DOM node.
|
|
95
|
+
*
|
|
96
|
+
* @param index - The previous index of the widget in the layout.
|
|
97
|
+
*
|
|
98
|
+
* @param widget - The widget to detach from the parent.
|
|
99
|
+
*/
|
|
100
|
+
protected detachWidget(index: number, widget: Widget): void {
|
|
101
|
+
const toolbar = this._toolbars.get(widget);
|
|
102
|
+
if (toolbar) {
|
|
103
|
+
// Send a `'before-detach'` message if the parent is attached.
|
|
104
|
+
if (this.parent!.isAttached) {
|
|
105
|
+
MessageLoop.sendMessage(toolbar, Widget.Msg.BeforeDetach);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Remove the toolbar in the title node.
|
|
109
|
+
this.titles[index].removeChild(toolbar.node);
|
|
110
|
+
|
|
111
|
+
// Send an `'after-detach'` message if the parent is attached.
|
|
112
|
+
if (this.parent!.isAttached) {
|
|
113
|
+
MessageLoop.sendMessage(toolbar, Widget.Msg.AfterDetach);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
super.detachWidget(index, widget);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* A message handler invoked on a `'before-attach'` message.
|
|
122
|
+
*
|
|
123
|
+
* #### Notes
|
|
124
|
+
* The default implementation of this method forwards the message
|
|
125
|
+
* to all widgets. It assumes all widget nodes are attached to the
|
|
126
|
+
* parent widget node.
|
|
127
|
+
*
|
|
128
|
+
* This may be reimplemented by subclasses as needed.
|
|
129
|
+
*/
|
|
130
|
+
protected onBeforeAttach(msg: Message): void {
|
|
131
|
+
this.notifyToolbars(msg);
|
|
132
|
+
super.onBeforeAttach(msg);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* A message handler invoked on an `'after-attach'` message.
|
|
137
|
+
*
|
|
138
|
+
* #### Notes
|
|
139
|
+
* The default implementation of this method forwards the message
|
|
140
|
+
* to all widgets. It assumes all widget nodes are attached to the
|
|
141
|
+
* parent widget node.
|
|
142
|
+
*
|
|
143
|
+
* This may be reimplemented by subclasses as needed.
|
|
144
|
+
*/
|
|
145
|
+
protected onAfterAttach(msg: Message): void {
|
|
146
|
+
super.onAfterAttach(msg);
|
|
147
|
+
this.notifyToolbars(msg);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* A message handler invoked on a `'before-detach'` message.
|
|
152
|
+
*
|
|
153
|
+
* #### Notes
|
|
154
|
+
* The default implementation of this method forwards the message
|
|
155
|
+
* to all widgets. It assumes all widget nodes are attached to the
|
|
156
|
+
* parent widget node.
|
|
157
|
+
*
|
|
158
|
+
* This may be reimplemented by subclasses as needed.
|
|
159
|
+
*/
|
|
160
|
+
protected onBeforeDetach(msg: Message): void {
|
|
161
|
+
this.notifyToolbars(msg);
|
|
162
|
+
super.onBeforeDetach(msg);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* A message handler invoked on an `'after-detach'` message.
|
|
167
|
+
*
|
|
168
|
+
* #### Notes
|
|
169
|
+
* The default implementation of this method forwards the message
|
|
170
|
+
* to all widgets. It assumes all widget nodes are attached to the
|
|
171
|
+
* parent widget node.
|
|
172
|
+
*
|
|
173
|
+
* This may be reimplemented by subclasses as needed.
|
|
174
|
+
*/
|
|
175
|
+
protected onAfterDetach(msg: Message): void {
|
|
176
|
+
super.onAfterDetach(msg);
|
|
177
|
+
this.notifyToolbars(msg);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
private notifyToolbars(msg: Message): void {
|
|
181
|
+
this.widgets.forEach(widget => {
|
|
182
|
+
const toolbar = this._toolbars.get(widget);
|
|
183
|
+
if (toolbar) {
|
|
184
|
+
toolbar.processMessage(msg);
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
protected _toolbars = new WeakMap<Widget, Toolbar>();
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export namespace AccordionToolbar {
|
|
193
|
+
/**
|
|
194
|
+
* Custom renderer for the SidePanel
|
|
195
|
+
*/
|
|
196
|
+
export class Renderer extends AccordionPanel.Renderer {
|
|
197
|
+
/**
|
|
198
|
+
* Render the collapse indicator for a section title.
|
|
199
|
+
*
|
|
200
|
+
* @param data - The data to use for rendering the section title.
|
|
201
|
+
*
|
|
202
|
+
* @returns A element representing the collapse indicator.
|
|
203
|
+
*/
|
|
204
|
+
createCollapseIcon(data: Title<Widget>): HTMLElement {
|
|
205
|
+
const iconDiv = document.createElement('div');
|
|
206
|
+
caretDownIcon.element({
|
|
207
|
+
container: iconDiv
|
|
208
|
+
});
|
|
209
|
+
return iconDiv;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Render the element for a section title.
|
|
214
|
+
*
|
|
215
|
+
* @param data - The data to use for rendering the section title.
|
|
216
|
+
*
|
|
217
|
+
* @returns A element representing the section title.
|
|
218
|
+
*/
|
|
219
|
+
createSectionTitle(data: Title<Widget>): HTMLElement {
|
|
220
|
+
const handle = super.createSectionTitle(data);
|
|
221
|
+
handle.classList.add('jp-AccordionPanel-title');
|
|
222
|
+
return handle;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export const defaultRenderer = new Renderer();
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Create an accordion layout for accordion panel with toolbar in the title.
|
|
230
|
+
*
|
|
231
|
+
* @param options Panel options
|
|
232
|
+
* @returns Panel layout
|
|
233
|
+
*
|
|
234
|
+
* #### Note
|
|
235
|
+
*
|
|
236
|
+
* Default titleSpace is 29 px (default var(--jp-private-toolbar-height) - but not styled)
|
|
237
|
+
*/
|
|
238
|
+
export function createLayout(
|
|
239
|
+
options: AccordionPanel.IOptions
|
|
240
|
+
): AccordionLayout {
|
|
241
|
+
return (
|
|
242
|
+
options.layout ||
|
|
243
|
+
new AccordionToolbarLayout({
|
|
244
|
+
renderer: options.renderer || defaultRenderer,
|
|
245
|
+
orientation: options.orientation,
|
|
246
|
+
alignment: options.alignment,
|
|
247
|
+
spacing: options.spacing,
|
|
248
|
+
titleSpace: options.titleSpace ?? 29
|
|
249
|
+
})
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Jupyter Development Team.
|
|
3
|
+
* Distributed under the terms of the Modified BSD License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import React from 'react';
|
|
7
|
+
import { classes } from '../utils';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Button component property
|
|
11
|
+
*/
|
|
12
|
+
export interface IButtonProps
|
|
13
|
+
extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
14
|
+
/**
|
|
15
|
+
* Whether this button should use minimal styles.
|
|
16
|
+
*/
|
|
17
|
+
minimal?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Whether this button should use small styles.
|
|
20
|
+
*/
|
|
21
|
+
small?: boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Button component
|
|
26
|
+
*
|
|
27
|
+
* @param props Component properties
|
|
28
|
+
* @returns Component
|
|
29
|
+
*/
|
|
30
|
+
export function Button(props: IButtonProps): JSX.Element {
|
|
31
|
+
const { minimal, small, children, ...others } = props;
|
|
32
|
+
return (
|
|
33
|
+
<button
|
|
34
|
+
{...others}
|
|
35
|
+
className={classes(
|
|
36
|
+
props.className,
|
|
37
|
+
minimal ? 'jp-mod-minimal' : '',
|
|
38
|
+
small ? 'jp-mod-small' : '',
|
|
39
|
+
'jp-Button'
|
|
40
|
+
)}
|
|
41
|
+
>
|
|
42
|
+
{children}
|
|
43
|
+
</button>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
// Copyright (c) Jupyter Development Team.
|
|
2
|
+
// Distributed under the terms of the Modified BSD License.
|
|
3
|
+
|
|
4
|
+
import { Message } from '@lumino/messaging';
|
|
5
|
+
import { ISignal, Signal } from '@lumino/signaling';
|
|
6
|
+
import { Panel, PanelLayout, Title, Widget } from '@lumino/widgets';
|
|
7
|
+
import { caretDownIcon, caretUpIcon } from '../icon';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* A panel that supports a collapsible header made from the widget's title.
|
|
11
|
+
* Clicking on the title expands or contracts the widget.
|
|
12
|
+
*/
|
|
13
|
+
export class Collapser<T extends Widget = Widget> extends Widget {
|
|
14
|
+
constructor(options: Collapser.IOptions<T>) {
|
|
15
|
+
super(options);
|
|
16
|
+
const { widget, collapsed = true } = options;
|
|
17
|
+
|
|
18
|
+
this.addClass('jp-Collapse');
|
|
19
|
+
this._header = new Widget();
|
|
20
|
+
this._header.addClass('jp-Collapse-header');
|
|
21
|
+
this._content = new Panel();
|
|
22
|
+
this._content.addClass('jp-Collapse-contents');
|
|
23
|
+
|
|
24
|
+
const layout = new PanelLayout();
|
|
25
|
+
this.layout = layout;
|
|
26
|
+
layout.addWidget(this._header);
|
|
27
|
+
layout.addWidget(this._content);
|
|
28
|
+
|
|
29
|
+
this.widget = widget;
|
|
30
|
+
this.collapsed = collapsed;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The widget inside the collapse panel.
|
|
35
|
+
*/
|
|
36
|
+
get widget(): T {
|
|
37
|
+
return this._widget;
|
|
38
|
+
}
|
|
39
|
+
set widget(widget: T) {
|
|
40
|
+
const oldWidget = this._widget;
|
|
41
|
+
if (oldWidget) {
|
|
42
|
+
oldWidget.title.changed.disconnect(this._onTitleChanged, this);
|
|
43
|
+
oldWidget.parent = null;
|
|
44
|
+
}
|
|
45
|
+
this._widget = widget;
|
|
46
|
+
widget.title.changed.connect(this._onTitleChanged, this);
|
|
47
|
+
this._onTitleChanged(widget.title);
|
|
48
|
+
this._content.addWidget(widget);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The collapsed state of the panel.
|
|
53
|
+
*/
|
|
54
|
+
get collapsed(): boolean {
|
|
55
|
+
return this._collapsed;
|
|
56
|
+
}
|
|
57
|
+
set collapsed(value: boolean) {
|
|
58
|
+
if (value === this._collapsed) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (value) {
|
|
62
|
+
this._collapse();
|
|
63
|
+
} else {
|
|
64
|
+
this._uncollapse();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* A signal for when the widget collapse state changes.
|
|
70
|
+
*/
|
|
71
|
+
get collapseChanged(): ISignal<Collapser, void> {
|
|
72
|
+
return this._collapseChanged;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Toggle the collapse state of the panel.
|
|
77
|
+
*/
|
|
78
|
+
toggle(): void {
|
|
79
|
+
this.collapsed = !this.collapsed;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Dispose the widget.
|
|
84
|
+
*/
|
|
85
|
+
dispose(): void {
|
|
86
|
+
if (this.isDisposed) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Delete references we explicitly hold to other widgets.
|
|
91
|
+
this._header = null!;
|
|
92
|
+
this._widget = null!;
|
|
93
|
+
this._content = null!;
|
|
94
|
+
|
|
95
|
+
super.dispose();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Handle the DOM events for the Collapser widget.
|
|
100
|
+
*
|
|
101
|
+
* @param event - The DOM event sent to the panel.
|
|
102
|
+
*
|
|
103
|
+
* #### Notes
|
|
104
|
+
* This method implements the DOM `EventListener` interface and is
|
|
105
|
+
* called in response to events on the panel's DOM node. It should
|
|
106
|
+
* not be called directly by user code.
|
|
107
|
+
*/
|
|
108
|
+
handleEvent(event: Event): void {
|
|
109
|
+
switch (event.type) {
|
|
110
|
+
case 'click':
|
|
111
|
+
this._evtClick(event as MouseEvent);
|
|
112
|
+
break;
|
|
113
|
+
default:
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
protected onAfterAttach(msg: Message): void {
|
|
119
|
+
this._header.node.addEventListener('click', this);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
protected onBeforeDetach(msg: Message): void {
|
|
123
|
+
this._header.node.removeEventListener('click', this);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
private _collapse() {
|
|
127
|
+
this._collapsed = true;
|
|
128
|
+
if (this._content) {
|
|
129
|
+
this._content.hide();
|
|
130
|
+
}
|
|
131
|
+
this._setHeader();
|
|
132
|
+
this._collapseChanged.emit(void 0);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
private _uncollapse() {
|
|
136
|
+
this._collapsed = false;
|
|
137
|
+
if (this._content) {
|
|
138
|
+
this._content.show();
|
|
139
|
+
}
|
|
140
|
+
this._setHeader();
|
|
141
|
+
this._collapseChanged.emit(void 0);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
private _evtClick(event: MouseEvent) {
|
|
145
|
+
this.toggle();
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Handle the `changed` signal of a title object.
|
|
150
|
+
*/
|
|
151
|
+
private _onTitleChanged(sender: Title<Widget>): void {
|
|
152
|
+
this._setHeader();
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
private _setHeader(): void {
|
|
156
|
+
(this._collapsed ? caretUpIcon : caretDownIcon).element({
|
|
157
|
+
container: this._header.node,
|
|
158
|
+
label: this._widget.title.label,
|
|
159
|
+
elementPosition: 'right',
|
|
160
|
+
height: '28px'
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
private _collapseChanged = new Signal<this, void>(this);
|
|
165
|
+
private _collapsed: boolean;
|
|
166
|
+
private _content: Panel;
|
|
167
|
+
private _header: Widget;
|
|
168
|
+
private _widget: T;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export namespace Collapser {
|
|
172
|
+
export interface IOptions<T extends Widget = Widget> extends Widget.IOptions {
|
|
173
|
+
widget: T;
|
|
174
|
+
collapsed?: boolean;
|
|
175
|
+
}
|
|
176
|
+
}
|