You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
93 lines
2.3 KiB
93 lines
2.3 KiB
/** |
|
* title提示 |
|
* |
|
* Created by GUY on 2015/9/7. |
|
* @class BI.Tooltip |
|
* @extends BI.Tip |
|
*/ |
|
|
|
import { shortcut } from "../../../core"; |
|
import Tip from "./0.tip"; |
|
@shortcut() |
|
export default class Tooltip extends Tip { |
|
_const = { |
|
hgap: 8, |
|
vgap: 4, |
|
} |
|
static xtype = "bi.tooltip"; |
|
|
|
_defaultConfig() { |
|
return BI.extend(super._defaultConfig(arguments), { |
|
extraCls: "bi-tooltip", |
|
text: "", |
|
level: "success", // success或warning |
|
stopEvent: false, |
|
stopPropagation: false, |
|
textAlign: "left", |
|
}); |
|
} |
|
|
|
render () { |
|
const { level, stopPropagation, stopEvent, text, textAlign } = this.options; |
|
this.element.addClass("tooltip-" + level); |
|
function fn(e) { |
|
stopPropagation && e.stopPropagation(); |
|
stopEvent && e.stopEvent(); |
|
} |
|
this.element.bind({ |
|
click: fn, |
|
mousedown: fn, |
|
mouseup: fn, |
|
mouseover: fn, |
|
mouseenter: fn, |
|
mouseleave: fn, |
|
mousemove: fn, |
|
}); |
|
|
|
const texts = (text + "").split("\n"); |
|
if (texts.length > 1) { |
|
BI.createWidget({ |
|
type: "bi.vertical", |
|
element: this, |
|
hgap: this._const.hgap, |
|
innerVgap: this._const.vgap, |
|
items: BI.map(texts, (i, text) => { |
|
return { |
|
type: "bi.label", |
|
textAlign: textAlign, |
|
whiteSpace: "normal", |
|
text: text, |
|
textHeight: 18, |
|
title: null, |
|
}; |
|
}), |
|
}); |
|
} else { |
|
this.text = BI.createWidget({ |
|
type: "bi.label", |
|
element: this, |
|
textAlign: textAlign, |
|
whiteSpace: "normal", |
|
text: text, |
|
title: null, |
|
textHeight: 18, |
|
hgap: this._const.hgap, |
|
vgap: this._const.vgap, |
|
}); |
|
} |
|
} |
|
|
|
setWidth(width) { |
|
this.element.width(BI.pixFormat(width - 2 * this._const.hgap)); |
|
} |
|
|
|
setText(text) { |
|
this.text && this.text.setText(text); |
|
} |
|
|
|
setLevel(level) { |
|
this.element.removeClass("tooltip-success").removeClass("tooltip-warning"); |
|
this.element.addClass("tooltip-" + level); |
|
} |
|
|
|
}
|
|
|