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.
96 lines
2.3 KiB
96 lines
2.3 KiB
import { ButtonGroup } from "@/base"; |
|
import { SegmentButton } from "./button.segment"; |
|
import { |
|
TableLayout, |
|
shortcut, |
|
Widget, |
|
extend, |
|
toPix, |
|
Controller, |
|
createWidget, |
|
createItems, |
|
makeArrayByArray |
|
} from "@/core"; |
|
|
|
/** |
|
* 单选按钮组 |
|
* |
|
* 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: ButtonGroup.xtype, |
|
value: o.value, |
|
items: [ |
|
createItems(o.items, { |
|
type: SegmentButton.xtype, |
|
height: toPix(o.height, 2), |
|
whiteSpace: o.whiteSpace, |
|
}) |
|
], |
|
layouts: [ |
|
{ |
|
type: TableLayout.xtype, |
|
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: SegmentButton.xtype, |
|
height: toPix(o.height, 2), |
|
whiteSpace: o.whiteSpace, |
|
}) |
|
]); |
|
} |
|
}
|
|
|