1 |
|
2 |
|
3 | import { caretDownEmptyIcon } from '@jupyterlab/ui-components';
|
4 |
|
5 |
|
6 |
|
7 | export var Styling;
|
8 | (function (Styling) {
|
9 | |
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | function styleNode(node, className = '') {
|
17 | styleNodeByTag(node, 'select', className);
|
18 | styleNodeByTag(node, 'textarea', className);
|
19 | styleNodeByTag(node, 'input', className);
|
20 | styleNodeByTag(node, 'button', className);
|
21 | }
|
22 | Styling.styleNode = styleNode;
|
23 | |
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | function styleNodeByTag(node, tagName, className = '') {
|
33 | if (node.localName === tagName) {
|
34 | node.classList.add('jp-mod-styled');
|
35 | }
|
36 | if (node.localName === 'select') {
|
37 | wrapSelect(node);
|
38 | }
|
39 | const nodes = node.getElementsByTagName(tagName);
|
40 | for (let i = 0; i < nodes.length; i++) {
|
41 | const child = nodes[i];
|
42 | child.classList.add('jp-mod-styled');
|
43 | if (className) {
|
44 | child.classList.add(className);
|
45 | }
|
46 | if (tagName === 'select') {
|
47 | wrapSelect(child);
|
48 | }
|
49 | }
|
50 | }
|
51 | Styling.styleNodeByTag = styleNodeByTag;
|
52 | |
53 |
|
54 |
|
55 | function wrapSelect(node) {
|
56 | const wrapper = document.createElement('div');
|
57 | wrapper.classList.add('jp-select-wrapper');
|
58 | node.addEventListener('focus', Private.onFocus);
|
59 | node.addEventListener('blur', Private.onFocus);
|
60 | node.classList.add('jp-mod-styled');
|
61 | if (node.parentElement) {
|
62 | node.parentElement.replaceChild(wrapper, node);
|
63 | }
|
64 | wrapper.appendChild(node);
|
65 |
|
66 | wrapper.appendChild(caretDownEmptyIcon.element({
|
67 | tag: 'span',
|
68 | stylesheet: 'select',
|
69 | right: '8px',
|
70 | top: '5px',
|
71 | width: '18px'
|
72 | }));
|
73 | return wrapper;
|
74 | }
|
75 | Styling.wrapSelect = wrapSelect;
|
76 | })(Styling || (Styling = {}));
|
77 |
|
78 |
|
79 |
|
80 | var Private;
|
81 | (function (Private) {
|
82 | |
83 |
|
84 |
|
85 | function onFocus(event) {
|
86 | const target = event.target;
|
87 | const parent = target.parentElement;
|
88 | if (!parent) {
|
89 | return;
|
90 | }
|
91 | if (event.type === 'focus') {
|
92 | parent.classList.add('jp-mod-focused');
|
93 | }
|
94 | else {
|
95 | parent.classList.remove('jp-mod-focused');
|
96 | }
|
97 | }
|
98 | Private.onFocus = onFocus;
|
99 | })(Private || (Private = {}));
|
100 |
|
\ | No newline at end of file |