Elian Doran 26c060bd22
chore(ckeditor5/plugins): add file-upload
Original commit: a440988df452ab4367f5288269ba3c05aa5e6b8e
2025-05-03 23:13:01 +03:00

69 lines
1.5 KiB
JavaScript

import View from "@ckeditor/ckeditor5-ui/src/view";
import toUnit from '@ckeditor/ckeditor5-utils/src/dom/tounit';
import ButtonView from "@ckeditor/ckeditor5-ui/src/button/buttonview";
import cancelIcon from '@ckeditor/ckeditor5-core/theme/icons/cancel.svg';
const toPx = toUnit('%');
export default class ProgressBarView extends View {
constructor(locale) {
super(locale);
const bind = this.bindTemplate;
this.cancelButton = this._createCancelButton(locale);
// Views define their interface (state) using observable attributes.
this.set('width', 100);
this.set('customWidth', 0);
this.setTemplate({
tag: 'div',
// The element of the view can be defined with its children.
children: [
{
tag: 'div',
children: ['Uploading...'],
attributes: {
class: ['ck-uploading-progress'],
style: {
width: bind.to('customWidth', toPx),
}
}
},
this.cancelButton,
],
attributes: {
class: [
'ck-progress-bar',
// Observable attributes control the state of the view in DOM.
bind.to('elementClass')
],
style: {
width: bind.to('width', toPx),
}
}
});
}
_createCancelButton(locale) {
const view = new ButtonView(locale);
view.set({
icon: cancelIcon,
tooltip: true,
label: 'Cancel',
attributes: {
class: ['ck', 'ck-button', 'ck-off', 'ck-button-cancel', 'ck-uploading-cancel']
}
});
view.on('execute', () => {
this.fire('cancel')
});
return view;
}
}