47 lines
1.1 KiB
JavaScript
47 lines
1.1 KiB
JavaScript
let register = Toolkit => Toolkit.Label =
|
|
|
|
// Presentational text
|
|
class Label extends Toolkit.Component {
|
|
|
|
///////////////////////// Initialization Methods //////////////////////////
|
|
|
|
constructor(app, options = {}, autoId = false) {
|
|
super(app, Object.assign({
|
|
class: "tk label"
|
|
}, options, { style: Object.assign({
|
|
cursor : "default",
|
|
userSelect: "none",
|
|
whiteSpace: "nowrap"
|
|
}, options.style || {}) }));
|
|
|
|
// Configure instance fields
|
|
if (autoId)
|
|
this.id = Toolkit.id();
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////// Public Methods //////////////////////////////
|
|
|
|
// Specify the display text
|
|
setText(text, localize) {
|
|
this.setString("text", text, localize);
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////// Package Methods /////////////////////////////
|
|
|
|
// Update localization strings
|
|
localize() {
|
|
if (this.text != null) {
|
|
let text = this.text;
|
|
this.element.innerText = !text[1] ? text[0] :
|
|
this.app.localize(text[0], this.substitutions);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
export { register };
|