forked from fanruan/fineui
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.
79 lines
2.1 KiB
79 lines
2.1 KiB
import { shortcut, Widget, extend, toPix, Controller, createWidget, createItems, makeArrayByArray } from "@/core"; |
|
import { ButtonGroup } from "@/base"; |
|
|
|
/** |
|
* 单选按钮组 |
|
* |
|
* Created by GUY on 2015/9/7. |
|
* @class Segment |
|
* @extends Widget |
|
*/ |
|
@shortcut() |
|
export class Segment extends Widget { |
|
static xtype = "bi.segment" |
|
|
|
static EVENT_CHANGE = "EVENT_CHANGE" |
|
|
|
_defaultConfig() { |
|
return extend(super._defaultConfig(...arguments), { |
|
baseCls: "bi-segment", |
|
items: [], |
|
height: 24, |
|
}); |
|
} |
|
|
|
_init() { |
|
super._init(...arguments); |
|
const o = this.options; |
|
this.buttonGroup = createWidget({ |
|
element: this, |
|
type: "bi.button_group", |
|
value: o.value, |
|
items: [createItems(o.items, { |
|
type: "bi.segment_button", |
|
height: toPix(o.height, 2), |
|
whiteSpace: o.whiteSpace, |
|
})], |
|
layouts: [{ |
|
type: "bi.table", |
|
columnSize: makeArrayByArray(o.items, "fill"), |
|
}], |
|
}); |
|
this.buttonGroup.on(Controller.EVENT_CHANGE, (...args) => { |
|
this.fireEvent(Controller.EVENT_CHANGE, ...args); |
|
}); |
|
this.buttonGroup.on(ButtonGroup.EVENT_CHANGE, (value, obj) => { |
|
this.fireEvent(Segment.EVENT_CHANGE, value, obj); |
|
}); |
|
} |
|
|
|
_setEnable(enable) { |
|
super._setEnable(...arguments); |
|
if (enable === true) { |
|
this.element.removeClass("base-disabled disabled"); |
|
} else if (enable === false) { |
|
this.element.addClass("base-disabled disabled"); |
|
} |
|
} |
|
|
|
setValue(v) { |
|
this.buttonGroup.setValue(v); |
|
} |
|
|
|
setEnabledValue(v) { |
|
this.buttonGroup.setEnabledValue(v); |
|
} |
|
|
|
getValue() { |
|
return this.buttonGroup.getValue(); |
|
} |
|
|
|
populate(buttons) { |
|
const o = this.options; |
|
this.buttonGroup.populate([createItems(buttons, { |
|
type: "bi.segment_button", |
|
height: toPix(o.height, 2), |
|
whiteSpace: o.whiteSpace, |
|
})]); |
|
} |
|
}
|
|
|