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.
76 lines
2.1 KiB
76 lines
2.1 KiB
import { Icon } from "../../icon/icon"; |
|
import { DefaultLayout, CenterAdaptLayout, shortcut, extend, isNumber, createWidget, isNull } from "@/core"; |
|
import { BasicButton } from "../button.basic"; |
|
|
|
/** |
|
* @class IconButton |
|
* @extends BasicButton |
|
* 图标的button |
|
*/ |
|
@shortcut() |
|
export class IconButton extends BasicButton { |
|
static EVENT_CHANGE = "EVENT_CHANGE"; |
|
static xtype = "bi.icon_button"; |
|
|
|
_defaultConfig() { |
|
const conf = super._defaultConfig(...arguments); |
|
|
|
return extend(conf, { |
|
_baseCls: `${conf._baseCls || ""} bi-icon-button horizon-center`, |
|
hgap: 0, |
|
vgap: 0, |
|
tgap: 0, |
|
bgap: 0, |
|
lgap: 0, |
|
rgap: 0, |
|
iconWidth: null, |
|
iconHeight: null, |
|
}); |
|
} |
|
|
|
render() { |
|
const o = this.options; |
|
this.element.css({ |
|
textAlign: "center", |
|
}); |
|
this.icon = createWidget({ |
|
type: Icon.xtype, |
|
width: o.iconWidth, |
|
height: o.iconHeight, |
|
}); |
|
if (isNumber(o.height) && o.height > 0 && isNull(o.iconWidth) && isNull(o.iconHeight)) { |
|
this.element.css("lineHeight", BI.pixFormat(o.height)); |
|
createWidget({ |
|
type: DefaultLayout.xtype, |
|
element: this, |
|
hgap: o.hgap, |
|
vgap: o.vgap, |
|
lgap: o.lgap, |
|
rgap: o.rgap, |
|
tgap: o.tgap, |
|
bgap: o.bgap, |
|
items: [this.icon], |
|
}); |
|
} else { |
|
this.element.css("lineHeight", "1"); |
|
createWidget({ |
|
element: this, |
|
type: CenterAdaptLayout.xtype, |
|
hgap: o.hgap, |
|
vgap: o.vgap, |
|
lgap: o.lgap, |
|
rgap: o.rgap, |
|
tgap: o.tgap, |
|
bgap: o.bgap, |
|
items: [this.icon], |
|
}); |
|
} |
|
} |
|
|
|
doClick() { |
|
super.doClick(...arguments); |
|
if (this.isValid()) { |
|
this.fireEvent(IconButton.EVENT_CHANGE, this); |
|
} |
|
} |
|
}
|
|
|