UNPKG

3.81 kBJavaScriptView Raw
1/* -----------------------------------------------------------------------------
2| Copyright (c) Jupyter Development Team.
3| Distributed under the terms of the Modified BSD License.
4|----------------------------------------------------------------------------*/
5import { ellipsesIcon } from '@jupyterlab/ui-components';
6import { Widget } from '@lumino/widgets';
7import { nullTranslator } from '@jupyterlab/translation';
8/**
9 * The CSS class added to placeholders.
10 */
11const PLACEHOLDER_CLASS = 'jp-Placeholder';
12/**
13 * The CSS classes added to input placeholder prompts.
14 */
15const INPUT_PROMPT_CLASS = 'jp-Placeholder-prompt jp-InputPrompt';
16/**
17 * The CSS classes added to output placeholder prompts.
18 */
19const OUTPUT_PROMPT_CLASS = 'jp-Placeholder-prompt jp-OutputPrompt';
20/**
21 * The CSS class added to placeholder content.
22 */
23const CONTENT_CLASS = 'jp-Placeholder-content';
24/**
25 * The CSS class added to input placeholders.
26 */
27const INPUT_PLACEHOLDER_CLASS = 'jp-InputPlaceholder';
28/**
29 * The CSS class added to output placeholders.
30 */
31const OUTPUT_PLACEHOLDER_CLASS = 'jp-OutputPlaceholder';
32/**
33 * An base class for placeholders
34 *
35 * ### Notes
36 * A placeholder is the element that is shown when input/output
37 * is hidden.
38 */
39export class Placeholder extends Widget {
40 /**
41 * Construct a new placeholder.
42 */
43 constructor(options) {
44 var _a, _b, _c;
45 const node = document.createElement('div');
46 super({ node });
47 const trans = ((_a = options.translator) !== null && _a !== void 0 ? _a : nullTranslator).load('jupyterlab');
48 const innerNode = document.createElement('div');
49 innerNode.className = (_b = options.promptClass) !== null && _b !== void 0 ? _b : '';
50 node.insertAdjacentHTML('afterbegin', innerNode.outerHTML);
51 this._cell = document.createElement('div');
52 this._cell.classList.add(CONTENT_CLASS);
53 this._cell.title = trans.__('Click to expand');
54 const container = this._cell.appendChild(document.createElement('div'));
55 container.classList.add('jp-Placeholder-contentContainer');
56 this._textContent = container.appendChild(document.createElement('span'));
57 this._textContent.className = 'jp-PlaceholderText';
58 this._textContent.innerText = (_c = options.text) !== null && _c !== void 0 ? _c : '';
59 node.appendChild(this._cell);
60 ellipsesIcon.element({
61 container: container.appendChild(document.createElement('span')),
62 className: 'jp-MoreHorizIcon',
63 elementPosition: 'center',
64 height: 'auto',
65 width: '32px'
66 });
67 this.addClass(PLACEHOLDER_CLASS);
68 this._callback = options.callback;
69 }
70 /**
71 * The text displayed in the placeholder.
72 */
73 set text(t) {
74 this._textContent.innerText = t;
75 }
76 get text() {
77 return this._textContent.innerText;
78 }
79 onAfterAttach(msg) {
80 super.onAfterAttach(msg);
81 this.node.addEventListener('click', this._callback);
82 }
83 onBeforeDetach(msg) {
84 this.node.removeEventListener('click', this._callback);
85 super.onBeforeDetach(msg);
86 }
87}
88/**
89 * The input placeholder class.
90 */
91export class InputPlaceholder extends Placeholder {
92 /**
93 * Construct a new input placeholder.
94 */
95 constructor(options) {
96 super({ ...options, promptClass: INPUT_PROMPT_CLASS });
97 this.addClass(INPUT_PLACEHOLDER_CLASS);
98 }
99}
100/**
101 * The output placeholder class.
102 */
103export class OutputPlaceholder extends Placeholder {
104 /**
105 * Construct a new output placeholder.
106 */
107 constructor(options) {
108 super({ ...options, promptClass: OUTPUT_PROMPT_CLASS });
109 this.addClass(OUTPUT_PLACEHOLDER_CLASS);
110 }
111}
112//# sourceMappingURL=placeholder.js.map
\No newline at end of file