forked from mviewer/mviewerstudio
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFreeComponent.js
49 lines (42 loc) · 1.23 KB
/
FreeComponent.js
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
import TemplateComponent from "./TemplateComponent.js";
import TextArea from "../forms/TextArea.js";
export const header = () => ({
icon: "bi bi-body-text",
id: mv.uuidv4(),
title: "template.free.title",
click: () => FreeComponent,
class: "FreeComponent",
});
const defaultTypeFields = [];
const attributes = ["data-value"];
export default class FreeComponent extends TemplateComponent {
constructor(customHeader, defaultAttrValues) {
let defaultValues = new Map();
if (defaultAttrValues) {
attributes.forEach((a) => {
defaultValues.set(a, defaultAttrValues[a]);
});
}
const textArea = new TextArea(defaultValues.get("data-value"), "template.free.label");
super(customHeader || header(), defaultTypeFields, [textArea], defaultValues);
this.textArea = textArea;
}
getAttributes = () => attributes;
render = () => {
let values = {
value: this.textArea.getValue(),
};
return this.template(values);
};
template = ({ value }) => {
return `
<div class="${header().class} template-component mb-2"
data-type-selector=""
data-value="${encodeURI(value)}"
data-component="${header().class}"
>
${value}
</div>
`;
};
}