@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.
Files changed (49) hide show
  1. package/lib/components/form.d.ts +17 -2
  2. package/lib/components/form.js +52 -11
  3. package/lib/components/form.js.map +1 -1
  4. package/lib/components/vdom.d.ts +1 -1
  5. package/lib/components/windowedlist.d.ts +1 -1
  6. package/lib/components/windowedlist.js +2 -1
  7. package/lib/components/windowedlist.js.map +1 -1
  8. package/lib/hoverbox.d.ts +1 -1
  9. package/lib/icon/labicon.js +49 -48
  10. package/lib/icon/labicon.js.map +1 -1
  11. package/lib/icon/widgets/tabbarsvg.js +2 -1
  12. package/lib/icon/widgets/tabbarsvg.js.map +1 -1
  13. package/lib/tokens.d.ts +1 -1
  14. package/package.json +22 -20
  15. package/src/FormRendererRegistry.tsx +60 -0
  16. package/src/components/accordiontoolbar.ts +252 -0
  17. package/src/components/button.tsx +45 -0
  18. package/src/components/collapser.ts +176 -0
  19. package/src/components/form.tsx +678 -0
  20. package/src/components/htmlselect.tsx +99 -0
  21. package/src/components/iframe.ts +153 -0
  22. package/src/components/index.ts +20 -0
  23. package/src/components/inputgroup.tsx +51 -0
  24. package/src/components/interface.ts +9 -0
  25. package/src/components/menu.ts +442 -0
  26. package/src/components/panelwithtoolbar.ts +41 -0
  27. package/src/components/search.tsx +216 -0
  28. package/src/components/sidepanel.ts +168 -0
  29. package/src/components/spinner.ts +31 -0
  30. package/src/components/styling.ts +114 -0
  31. package/src/components/switch.ts +103 -0
  32. package/src/components/toolbar.tsx +1119 -0
  33. package/src/components/vdom.ts +324 -0
  34. package/src/components/windowedlist.ts +1422 -0
  35. package/src/hoverbox.ts +401 -0
  36. package/src/icon/iconimports.ts +206 -0
  37. package/src/icon/index.ts +6 -0
  38. package/src/icon/labicon.tsx +955 -0
  39. package/src/icon/widgets/commandpalettesvg.ts +78 -0
  40. package/src/icon/widgets/index.ts +6 -0
  41. package/src/icon/widgets/menusvg.ts +218 -0
  42. package/src/icon/widgets/tabbarsvg.ts +122 -0
  43. package/src/index.ts +13 -0
  44. package/src/style/icon.ts +581 -0
  45. package/src/style/index.ts +4 -0
  46. package/src/svg.d.ts +58 -0
  47. package/src/tokens.ts +68 -0
  48. package/src/utils.ts +90 -0
  49. package/style/rjsfTemplates.css +0 -4
@@ -0,0 +1,168 @@
1
+ // Copyright (c) Jupyter Development Team.
2
+ // Distributed under the terms of the Modified BSD License.
3
+
4
+ import {
5
+ ITranslator,
6
+ nullTranslator,
7
+ TranslationBundle
8
+ } from '@jupyterlab/translation';
9
+ import { AccordionPanel, Panel, PanelLayout, Widget } from '@lumino/widgets';
10
+ import { AccordionToolbar } from './accordiontoolbar';
11
+ import { Toolbar } from './toolbar';
12
+
13
+ /**
14
+ * A widget meant to be contained in sidebars.
15
+ *
16
+ * #### Note
17
+ * By default the content widget is an accordion panel that supports widget with
18
+ * associated toolbar to be displayed in the widget title.
19
+ */
20
+ export class SidePanel extends Widget {
21
+ constructor(options: SidePanel.IOptions = {}) {
22
+ super();
23
+ const layout = (this.layout = new PanelLayout());
24
+ this.addClass('jp-SidePanel');
25
+
26
+ const trans = (this._trans = (options.translator || nullTranslator).load(
27
+ 'jupyterlab'
28
+ ));
29
+
30
+ if (options.header) {
31
+ this.addHeader(options.header);
32
+ }
33
+
34
+ const content = (this._content =
35
+ options.content ??
36
+ new AccordionPanel({
37
+ ...options,
38
+ layout: AccordionToolbar.createLayout(options)
39
+ }));
40
+ content.node.setAttribute('role', 'region');
41
+ content.node.setAttribute('aria-label', trans.__('side panel content'));
42
+ content.addClass('jp-SidePanel-content');
43
+ layout.addWidget(content);
44
+
45
+ if (options.toolbar) {
46
+ this.addToolbar(options.toolbar);
47
+ }
48
+ }
49
+
50
+ /**
51
+ * The content hosted by the widget.
52
+ */
53
+ get content(): Panel {
54
+ return this._content;
55
+ }
56
+
57
+ /**
58
+ * A panel for widgets that sit on top of the widget.
59
+ */
60
+ get header(): Panel {
61
+ if (!this._header) {
62
+ this.addHeader();
63
+ }
64
+ return this._header;
65
+ }
66
+
67
+ /**
68
+ * The toolbar hosted by the widget.
69
+ *
70
+ * It sits between the header and the content
71
+ */
72
+ get toolbar(): Toolbar {
73
+ if (!this._toolbar) {
74
+ this.addToolbar();
75
+ }
76
+ return this._toolbar;
77
+ }
78
+
79
+ /**
80
+ * A read-only array of the widgets in the content panel.
81
+ */
82
+ get widgets(): ReadonlyArray<Widget> {
83
+ return this.content.widgets;
84
+ }
85
+
86
+ /**
87
+ * Add a widget to the content panel bottom.
88
+ *
89
+ * @param widget Widget to add
90
+ */
91
+ addWidget(widget: Toolbar.IWidgetToolbar): void {
92
+ this.content.addWidget(widget);
93
+ }
94
+
95
+ /**
96
+ * Insert a widget at the given position in the content panel.
97
+ *
98
+ * @param index Position
99
+ * @param widget Widget to insert
100
+ */
101
+ insertWidget(index: number, widget: Toolbar.IWidgetToolbar): void {
102
+ this.content.insertWidget(index, widget);
103
+ }
104
+
105
+ private addHeader(header?: Panel) {
106
+ const theHeader = (this._header = header || new Panel());
107
+ theHeader.addClass('jp-SidePanel-header');
108
+
109
+ (this.layout as PanelLayout).insertWidget(0, theHeader);
110
+ }
111
+
112
+ private addToolbar(toolbar?: Toolbar) {
113
+ const theToolbar = (this._toolbar = toolbar ?? new Toolbar());
114
+ theToolbar.addClass('jp-SidePanel-toolbar');
115
+ theToolbar.node.setAttribute('role', 'navigation');
116
+ theToolbar.node.setAttribute(
117
+ 'aria-label',
118
+ this._trans.__('side panel actions')
119
+ );
120
+ (this.layout as PanelLayout).insertWidget(
121
+ (this.layout as PanelLayout).widgets.length - 1,
122
+ theToolbar
123
+ );
124
+ }
125
+
126
+ protected _content: Panel;
127
+ protected _header: Panel;
128
+ protected _toolbar: Toolbar;
129
+ protected _trans: TranslationBundle;
130
+ }
131
+
132
+ /**
133
+ * The namespace for the `SidePanel` class statics.
134
+ */
135
+ export namespace SidePanel {
136
+ /**
137
+ * An options object for creating a side panel widget.
138
+ */
139
+ export interface IOptions extends AccordionPanel.IOptions {
140
+ /**
141
+ * The main child of the side panel
142
+ *
143
+ * If nothing is provided it fallback to an AccordionToolbar panel.
144
+ */
145
+ content?: Panel;
146
+
147
+ /**
148
+ * The header is at the top of the SidePanel,
149
+ * and that extensions can populate.
150
+ *
151
+ * Defaults to an empty Panel if requested otherwise it won't be created.
152
+ */
153
+ header?: Panel;
154
+
155
+ /**
156
+ * The toolbar to use for the widget.
157
+ * It sits between the header and the content
158
+ *
159
+ * Defaults to an empty toolbar if requested otherwise it won't be created.
160
+ */
161
+ toolbar?: Toolbar;
162
+
163
+ /**
164
+ * The application language translator.
165
+ */
166
+ translator?: ITranslator;
167
+ }
168
+ }
@@ -0,0 +1,31 @@
1
+ /* -----------------------------------------------------------------------------
2
+ | Copyright (c) Jupyter Development Team.
3
+ | Distributed under the terms of the Modified BSD License.
4
+ |----------------------------------------------------------------------------*/
5
+
6
+ import { Message } from '@lumino/messaging';
7
+ import { Widget } from '@lumino/widgets';
8
+
9
+ /**
10
+ * The spinner class.
11
+ */
12
+ export class Spinner extends Widget {
13
+ /**
14
+ * Construct a spinner widget.
15
+ */
16
+ constructor() {
17
+ super();
18
+ this.addClass('jp-Spinner');
19
+ this.node.tabIndex = -1;
20
+ const content = document.createElement('div');
21
+ content.className = 'jp-SpinnerContent';
22
+ this.node.appendChild(content);
23
+ }
24
+
25
+ /**
26
+ * Handle `'activate-request'` messages.
27
+ */
28
+ protected onActivateRequest(msg: Message): void {
29
+ this.node.focus();
30
+ }
31
+ }
@@ -0,0 +1,114 @@
1
+ // Copyright (c) Jupyter Development Team.
2
+ // Distributed under the terms of the Modified BSD License.
3
+
4
+ import { caretDownEmptyIcon } from '../icon';
5
+
6
+ /**
7
+ * A namespace for node styling.
8
+ */
9
+ export namespace Styling {
10
+ /**
11
+ * Style a node and its child elements with the default tag names.
12
+ *
13
+ * @param node - The base node.
14
+ *
15
+ * @param className - The optional CSS class to add to styled nodes.
16
+ */
17
+ export function styleNode(node: HTMLElement, className = ''): void {
18
+ styleNodeByTag(node, 'select', className);
19
+ styleNodeByTag(node, 'textarea', className);
20
+ styleNodeByTag(node, 'input', className);
21
+ styleNodeByTag(node, 'button', className);
22
+ }
23
+
24
+ /**
25
+ * Style a node and its elements that have a given tag name.
26
+ *
27
+ * @param node - The base node.
28
+ *
29
+ * @param tagName - The html tag name to style.
30
+ *
31
+ * @param className - The optional CSS class to add to styled nodes.
32
+ */
33
+ export function styleNodeByTag(
34
+ node: HTMLElement,
35
+ tagName: string,
36
+ className = ''
37
+ ): void {
38
+ if (node.localName === tagName) {
39
+ node.classList.add('jp-mod-styled');
40
+ }
41
+ if (node.localName === 'select') {
42
+ const multiple = node.hasAttribute('multiple');
43
+ wrapSelect(node as HTMLSelectElement, multiple);
44
+ }
45
+ const nodes = node.getElementsByTagName(tagName);
46
+ for (let i = 0; i < nodes.length; i++) {
47
+ const child = nodes[i];
48
+ child.classList.add('jp-mod-styled');
49
+ if (className) {
50
+ child.classList.add(className);
51
+ }
52
+ if (tagName === 'select') {
53
+ const multiple = child.hasAttribute('multiple');
54
+ wrapSelect(child as HTMLSelectElement, multiple);
55
+ }
56
+ }
57
+ }
58
+
59
+ /**
60
+ * Wrap a select node.
61
+ */
62
+ export function wrapSelect(
63
+ node: HTMLSelectElement,
64
+ multiple?: boolean
65
+ ): HTMLElement {
66
+ const wrapper = document.createElement('div');
67
+ wrapper.classList.add('jp-select-wrapper');
68
+ node.addEventListener('focus', Private.onFocus);
69
+ node.addEventListener('blur', Private.onFocus);
70
+ node.classList.add('jp-mod-styled');
71
+ if (node.parentElement) {
72
+ node.parentElement.replaceChild(wrapper, node);
73
+ }
74
+ wrapper.appendChild(node);
75
+
76
+ if (multiple) {
77
+ wrapper.classList.add('multiple');
78
+ } else {
79
+ // add the icon node
80
+ wrapper.appendChild(
81
+ caretDownEmptyIcon.element({
82
+ tag: 'span',
83
+ stylesheet: 'select',
84
+ right: '8px',
85
+ top: '5px',
86
+ width: '18px'
87
+ })
88
+ );
89
+ }
90
+
91
+ return wrapper;
92
+ }
93
+ }
94
+
95
+ /**
96
+ * The namespace for module private data.
97
+ */
98
+ namespace Private {
99
+ /**
100
+ * Handle a focus event on a styled select.
101
+ */
102
+ export function onFocus(event: FocusEvent): void {
103
+ const target = event.target as Element;
104
+ const parent = target.parentElement;
105
+ if (!parent) {
106
+ return;
107
+ }
108
+ if (event.type === 'focus') {
109
+ parent.classList.add('jp-mod-focused');
110
+ } else {
111
+ parent.classList.remove('jp-mod-focused');
112
+ }
113
+ }
114
+ }
@@ -0,0 +1,103 @@
1
+ // Copyright (c) Jupyter Development Team.
2
+ // Distributed under the terms of the Modified BSD License.
3
+
4
+ import { IChangedArgs } from '@jupyterlab/coreutils';
5
+ import { ISignal, Signal } from '@lumino/signaling';
6
+ import { Widget } from '@lumino/widgets';
7
+
8
+ /**
9
+ * A Switch widget
10
+ */
11
+ export class Switch extends Widget {
12
+ constructor() {
13
+ super();
14
+
15
+ // switch accessibility refs:
16
+ // https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/Switch_role
17
+ // https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Accessibility_concerns
18
+
19
+ this._button.className = 'jp-switch';
20
+ this._button.setAttribute('role', 'switch');
21
+
22
+ this._label.className = 'jp-switch-label';
23
+
24
+ const track = document.createElement('div');
25
+ track.className = 'jp-switch-track';
26
+ track.setAttribute('aria-hidden', 'true');
27
+
28
+ this._button.appendChild(this._label);
29
+ this._button.appendChild(track);
30
+ this.node.appendChild(this._button);
31
+ }
32
+
33
+ /**
34
+ * The value of the switch.
35
+ */
36
+ get value(): boolean {
37
+ return this._value;
38
+ }
39
+ set value(newValue: boolean) {
40
+ const oldValue = this._value;
41
+ if (oldValue === newValue) {
42
+ return;
43
+ }
44
+ this._button.setAttribute('aria-checked', newValue.toString());
45
+ this._value = newValue;
46
+ this._valueChanged.emit({ name: 'value', oldValue, newValue });
47
+ }
48
+
49
+ /**
50
+ * A signal emitted when the value changes.
51
+ */
52
+ get valueChanged(): ISignal<this, IChangedArgs<boolean, boolean, 'value'>> {
53
+ return this._valueChanged;
54
+ }
55
+
56
+ /**
57
+ * The visible label of the switch.
58
+ */
59
+ get label(): string {
60
+ return this._label.textContent ?? '';
61
+ }
62
+ set label(x: string) {
63
+ this._label.textContent = x;
64
+ }
65
+
66
+ /**
67
+ * The caption (title) of the switch.
68
+ */
69
+ get caption(): string {
70
+ return this._button.title;
71
+ }
72
+ set caption(x: string) {
73
+ this._button.title = x;
74
+ this._label.title = x;
75
+ }
76
+
77
+ handleEvent(event: Event): void {
78
+ switch (event.type) {
79
+ case 'click':
80
+ this.value = !this.value;
81
+ break;
82
+ default:
83
+ break;
84
+ }
85
+ }
86
+
87
+ protected onAfterAttach(): void {
88
+ this._button.addEventListener('click', this);
89
+ }
90
+
91
+ protected onBeforeDetach(): void {
92
+ this._button.removeEventListener('click', this);
93
+ }
94
+
95
+ private _button = document.createElement('button');
96
+ private _label = document.createElement('label');
97
+
98
+ private _value: boolean;
99
+ private _valueChanged = new Signal<
100
+ this,
101
+ IChangedArgs<boolean, boolean, 'value'>
102
+ >(this);
103
+ }