-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTitlebar.jsx
More file actions
139 lines (123 loc) · 4.95 KB
/
Titlebar.jsx
File metadata and controls
139 lines (123 loc) · 4.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import { createElement } from '@syncfusion/ej2-base';
import { Button } from '@syncfusion/ej2-buttons';
import { DropDownButton } from '@syncfusion/ej2-splitbuttons';
/**
* Represents the title bar of the document editor.
*/
class TitleBar {
constructor(element, docEditor, isShareNeeded, dialogComponent) {
// Initialize title bar elements.
this.tileBarDiv = element;
this.documentEditor = docEditor;
this.dialogComponent = dialogComponent;
this.initializeTitleBar(isShareNeeded);
this.wireEvents();
// Append document title after initialization
if (this.tileBarDiv && !this.tileBarDiv.contains(this.documentTitle)) {
this.tileBarDiv.prepend(this.documentTitle);
}
}
/**
* Initializes the title bar, setting up text and tooltips.
* @param {boolean} isShareNeeded - Flag to decide if sharing feature is needed.
*/
initializeTitleBar = (isShareNeeded) => {
const downloadText = 'Download';
const downloadToolTip = 'Download this document.';
const printText = 'Print';
const printToolTip = 'Print this document (Ctrl+P).';
// Create the document title element
this.documentTitle = createElement('label', {
id: 'documenteditor_title_name',
styles: 'font-weight:400;text-overflow:ellipsis;white-space:pre;overflow:hidden;user-select:none;cursor:text'
});
this.documentTitle.innerHTML = this.documentEditor.documentName;
const btnStyles = 'float:right;background: transparent;box-shadow:none; font-family: inherit;border-color: transparent;' +
'border-radius: 2px;color:inherit;font-size:12px;text-transform:capitalize;height:28px;font-weight:400;margin: 4px;';
// Initialize print button
this.print = this.addButton('e-icons e-print e-de-padding-right', printText, btnStyles, 'de-print', printToolTip, false);
// Initialize download drop-down button
const items = [
{ text: 'Syncfusion® Document Text (*.sfdt)', id: 'sfdt' },
{ text: 'Word Document (*.docx)', id: 'word' },
{ text: 'Word Template (*.dotx)', id: 'dotx' },
{ text: 'Plain Text (*.txt)', id: 'txt' },
];
this.download = this.addButton('e-icons e-download e-de-padding-right', downloadText, btnStyles, 'documenteditor-share', downloadToolTip, true, items);
// Hide download button if sharing is not needed
if (!isShareNeeded) {
this.download.element.style.display = 'none';
}
};
/**
* Wires events to the buttons.
*/
wireEvents = () => {
this.print.element.addEventListener('click', this.onPrint);
};
/**
* Updates the document title displayed in the title bar.
*/
updateDocumentTitle = () => {
if (this.documentEditor.documentName === '') {
this.documentEditor.documentName = 'Untitled';
}
this.documentTitle.textContent = this.documentEditor.documentName;
};
/**
* Adds a button to the title bar.
* @param {string} iconClass - Icon class for the button.
* @param {string} btnText - Button text.
* @param {string} styles - Button styles.
* @param {string} id - Button id.
* @param {string} tooltipText - Tooltip text for the button.
* @param {boolean} isDropDown - Whether the button is a dropdown.
* @param {Array} items - Items for dropdown, if applicable.
* @returns {Button|DropDownButton} - The created button instance.
*/
addButton(iconClass, btnText, styles, id, tooltipText, isDropDown, items) {
// Create button element
const button = createElement('button', { id, styles });
this.tileBarDiv.appendChild(button);
button.setAttribute('title', tooltipText);
// Return appropriate button based on isDropDown flag
if (isDropDown) {
return new DropDownButton({
select: this.onDownloadClick,
items,
iconCss: iconClass,
cssClass: 'e-caret-hide',
content: btnText,
}, button);
} else {
return new Button({ iconCss: iconClass, content: btnText }, button);
}
}
/**
* Handles print button click event.
*/
onPrint = () => {
this.documentEditor.print();
};
/**
* Handles download item selection.
* @param {Object} args - Event arguments.
*/
onDownloadClick = (args) => {
const formatMap = {
'word': 'Docx',
'sfdt': 'Sfdt',
'txt': 'Txt',
'dotx': 'Dotx'
};
this.save(formatMap[args.item.id]);
};
/**
* Saves the document in the specified format.
* @param {string} format - Format to save the document as.
*/
save = (format) => {
this.documentEditor.save(this.documentEditor.documentName || 'sample', format);
};
}
export default TitleBar;