Debian Codegraph @

examples/example-accordionpanel/src/index.ts

raw
1 // Copyright (c) Jupyter Development Team.
2 // Distributed under the terms of the Modified BSD License.
3
4 import { Message } from '@lumino/messaging';
5
6 import { AccordionPanel, BoxPanel, Widget } from '@lumino/widgets';
7
8 import '../style/index.css';
9
10 class ContentWidget extends Widget {
11 static createNode(): HTMLElement {
12 let node = document.createElement('div');
13 let content = document.createElement('div');
14 let input = document.createElement('input');
15 input.placeholder = 'Placeholder...';
16 content.appendChild(input);
17 node.appendChild(content);
18 return node;
19 }
20
21 constructor(name: string) {
22 super({ node: ContentWidget.createNode() });
23 this.setFlag(Widget.Flag.DisallowLayout);
24 this.addClass('content');
25 this.addClass(name.toLowerCase());
26 this.title.label = name;
27 this.title.closable = true;
28 this.title.caption = `Long description for: ${name}`;
29 }
30
31 get inputNode(): HTMLInputElement {
32 return this.node.getElementsByTagName('input')[0] as HTMLInputElement;
33 }
34
35 protected onActivateRequest(msg: Message): void {
36 if (this.isAttached) {
37 this.inputNode.focus();
38 }
39 }
40 }
41
42 function main(): void {
43 const accordion = new AccordionPanel();
44 accordion.id = 'accordion';
45
46 const r1 = new ContentWidget('Red');
47 const b1 = new ContentWidget('Blue');
48 const g1 = new ContentWidget('Green');
49
50 accordion.addWidget(r1);
51 accordion.addWidget(b1);
52 accordion.addWidget(g1);
53
54 BoxPanel.setStretch(accordion, 1);
55
56 const main = new BoxPanel({ direction: 'left-to-right', spacing: 0 });
57 main.id = 'main';
58 main.addWidget(accordion);
59
60 window.onresize = () => {
61 main.update();
62 };
63
64 Widget.attach(main, document.body);
65 }
66
67 window.onload = main;