Visual Studio Refactor: fixed the items which use their label as content
Former-commit-id: 48d50e90bd581312b39a90b12c5fe50e03c8730a
This commit is contained in:
parent
92428f3731
commit
d94ed7e4f3
|
@ -212,7 +212,7 @@
|
||||||
// Generic props.
|
// Generic props.
|
||||||
id: 9,
|
id: 9,
|
||||||
type: 2, // Simple value = 2
|
type: 2, // Simple value = 2
|
||||||
label: '<h3 style="color: #FDFD96;">Simple Value: 10</h3>',
|
label: '<h3 style="color: #FDFD96;">Simple Value: (_VALUE_)</h3>',
|
||||||
isLinkEnabled: false,
|
isLinkEnabled: false,
|
||||||
isOnTop: false,
|
isOnTop: false,
|
||||||
parentId: null,
|
parentId: null,
|
||||||
|
|
|
@ -132,8 +132,7 @@ abstract class VisualConsoleItem<Props extends ItemProps> {
|
||||||
* when hovered, etc.
|
* when hovered, etc.
|
||||||
*/
|
*/
|
||||||
this.elementRef = this.createContainerDomElement();
|
this.elementRef = this.createContainerDomElement();
|
||||||
this.labelElementRef = document.createElement("div");
|
this.labelElementRef = this.createLabelDomElement();
|
||||||
this.labelElementRef.className = "visual-console-item-label";
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get a HTMLElement which represents the custom view
|
* Get a HTMLElement which represents the custom view
|
||||||
|
@ -142,11 +141,6 @@ abstract class VisualConsoleItem<Props extends ItemProps> {
|
||||||
*/
|
*/
|
||||||
this.childElementRef = this.createDomElement();
|
this.childElementRef = this.createDomElement();
|
||||||
|
|
||||||
// Add the label if it exists.
|
|
||||||
if (this.props.label && this.props.label.length) {
|
|
||||||
this.labelElementRef.innerHTML = this.props.label;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Insert the elements into the container.
|
// Insert the elements into the container.
|
||||||
this.elementRef.append(this.childElementRef, this.labelElementRef);
|
this.elementRef.append(this.childElementRef, this.labelElementRef);
|
||||||
|
|
||||||
|
@ -172,6 +166,21 @@ abstract class VisualConsoleItem<Props extends ItemProps> {
|
||||||
return box;
|
return box;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To create a new label for the visual console item.
|
||||||
|
* @return Item label.
|
||||||
|
*/
|
||||||
|
protected createLabelDomElement(): HTMLElement {
|
||||||
|
const element = document.createElement("div");
|
||||||
|
element.className = "visual-console-item-label";
|
||||||
|
// Add the label if it exists.
|
||||||
|
if (this.props.label && this.props.label.length) {
|
||||||
|
element.innerHTML = this.props.label;
|
||||||
|
}
|
||||||
|
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Public accessor of the `props` property.
|
* Public accessor of the `props` property.
|
||||||
* @return Properties.
|
* @return Properties.
|
||||||
|
@ -230,8 +239,7 @@ abstract class VisualConsoleItem<Props extends ItemProps> {
|
||||||
}
|
}
|
||||||
// Change label.
|
// Change label.
|
||||||
if (!prevProps || prevProps.label !== this.props.label) {
|
if (!prevProps || prevProps.label !== this.props.label) {
|
||||||
this.labelElementRef.innerHTML =
|
this.labelElementRef.innerHTML = this.createLabelDomElement().innerHTML;
|
||||||
this.props.label != null ? this.props.label : "";
|
|
||||||
}
|
}
|
||||||
// Change label position.
|
// Change label position.
|
||||||
if (!prevProps || prevProps.labelPosition !== this.props.labelPosition) {
|
if (!prevProps || prevProps.labelPosition !== this.props.labelPosition) {
|
||||||
|
|
|
@ -28,22 +28,20 @@ export default class Label extends Item<LabelProps> {
|
||||||
public createDomElement(): HTMLElement {
|
public createDomElement(): HTMLElement {
|
||||||
const element = document.createElement("div");
|
const element = document.createElement("div");
|
||||||
element.className = "label";
|
element.className = "label";
|
||||||
// Size to 0, as the item content is managed using the label.
|
element.innerHTML = this.props.label || "";
|
||||||
element.style.width = "0";
|
|
||||||
element.style.height = "0";
|
|
||||||
// The content of this item is already shown into the label container.
|
|
||||||
// element.innerHTML = this.props.label || "";
|
|
||||||
|
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @override Item.resize
|
* @override Item.createLabelDomElement
|
||||||
* To resize the item.
|
* Create a new label for the visual console item.
|
||||||
|
* @return Item label.
|
||||||
*/
|
*/
|
||||||
public resizeElement(): void {
|
public createLabelDomElement(): HTMLElement {
|
||||||
// Size to 0, as the item content is managed using the label.
|
const element = document.createElement("div");
|
||||||
this.childElementRef.style.width = `0`;
|
element.className = "visual-console-item-label";
|
||||||
this.childElementRef.style.height = `0`;
|
// Always return an empty label.
|
||||||
|
return element;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,23 +97,27 @@ export default class SimpleValue extends Item<SimpleValueProps> {
|
||||||
img.src = this.props.value;
|
img.src = this.props.value;
|
||||||
element.append(img);
|
element.append(img);
|
||||||
} else {
|
} else {
|
||||||
// Size to 0, as the item content is managed using the label.
|
// Add the value to the label and show it.
|
||||||
element.style.width = "0";
|
let text = this.props.value;
|
||||||
element.style.height = "0";
|
if (this.props.label) {
|
||||||
// The content of this item is already shown into the label container.
|
text = this.props.label.replace(/\(?_VALUE_\)?/i, text);
|
||||||
// element.innerHTML = this.props.label || "";
|
}
|
||||||
|
|
||||||
|
element.innerHTML = text;
|
||||||
}
|
}
|
||||||
|
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @override Item.resize
|
* @override Item.createLabelDomElement
|
||||||
* To resize the item.
|
* Create a new label for the visual console item.
|
||||||
|
* @return Item label.
|
||||||
*/
|
*/
|
||||||
public resizeElement(): void {
|
public createLabelDomElement(): HTMLElement {
|
||||||
// Size to 0, as the item content is managed using the label.
|
const element = document.createElement("div");
|
||||||
this.childElementRef.style.width = `0`;
|
element.className = "visual-console-item-label";
|
||||||
this.childElementRef.style.height = `0`;
|
// Always return an empty label.
|
||||||
|
return element;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue