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.
94 lines
2.7 KiB
94 lines
2.7 KiB
import { IconButton, Single } from "@/base"; |
|
import { shortcut, extend, emptyFn, isFunction, createWidget, Controller } from "@/core"; |
|
|
|
/** |
|
* 可以改变图标的button |
|
* |
|
* Created by GUY on 2016/2/2. |
|
* |
|
* @class IconChangeButton |
|
* @extends Single |
|
*/ |
|
@shortcut() |
|
export class IconChangeButton extends Single { |
|
static xtype = "bi.icon_change_button"; |
|
static EVENT_CHANGE = "EVENT_CHANGE"; |
|
|
|
_defaultConfig() { |
|
const conf = super._defaultConfig(...arguments); |
|
|
|
return extend(conf, { |
|
baseCls: "bi-icon-change-button", |
|
iconCls: "", |
|
iconWidth: null, |
|
iconHeight: null, |
|
|
|
stopEvent: false, |
|
stopPropagation: false, |
|
selected: false, |
|
once: false, // 点击一次选中有效,再点无效 |
|
forceSelected: false, // 点击即选中, 选中了就不会被取消 |
|
forceNotSelected: false, // 无论怎么点击都不会被选中 |
|
disableSelected: false, // 使能选中 |
|
|
|
shadow: false, |
|
isShadowShowingOnSelected: false, // 选中状态下是否显示阴影 |
|
trigger: null, |
|
handler: emptyFn, |
|
}); |
|
} |
|
|
|
_init() { |
|
const o = this.options; |
|
o.iconCls = isFunction(o.iconCls) |
|
? this.__watch(o.iconCls, (context, newValue) => { |
|
this.setIcon(newValue); |
|
}) |
|
: o.iconCls; |
|
super._init(...arguments); |
|
this.button = createWidget({ |
|
type: IconButton.xtype, |
|
element: this, |
|
cls: o.iconCls, |
|
height: o.height, |
|
iconWidth: o.iconWidth, |
|
iconHeight: o.iconHeight, |
|
|
|
stopEvent: o.stopEvent, |
|
stopPropagation: o.stopPropagation, |
|
selected: o.selected, |
|
once: o.once, |
|
forceSelected: o.forceSelected, |
|
forceNotSelected: o.forceNotSelected, |
|
disableSelected: o.disableSelected, |
|
|
|
shadow: o.shadow, |
|
isShadowShowingOnSelected: o.isShadowShowingOnSelected, |
|
trigger: o.trigger, |
|
handler: o.handler, |
|
}); |
|
|
|
this.button.on(Controller.EVENT_CHANGE, (...args) => { |
|
this.fireEvent(Controller.EVENT_CHANGE, ...args); |
|
}); |
|
this.button.on(IconButton.EVENT_CHANGE, (...args) => { |
|
this.fireEvent(IconChangeButton.EVENT_CHANGE, ...args); |
|
}); |
|
} |
|
|
|
isSelected() { |
|
return this.button.isSelected(); |
|
} |
|
|
|
setSelected(b) { |
|
this.button.setSelected(b); |
|
} |
|
|
|
setIcon(cls) { |
|
const o = this.options; |
|
if (o.iconCls !== cls) { |
|
this.element.removeClass(o.iconCls).addClass(cls); |
|
o.iconCls = cls; |
|
} |
|
} |
|
}
|
|
|