maille
Version:
Component library for MithrilJS
48 lines (47 loc) • 1.75 kB
JavaScript
;
// THIS FILE WAS AUTO-GENERATED FOR PACKAGING, DO NOT MODIFY
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const button_1 = __importDefault(require("../button"));
const button_group_1 = __importDefault(require("../button-group"));
const radio_input_group_1 = __importDefault(require("../radio-input-group"));
const types_1 = require("../../types");
class RadioInputButtonGroup extends radio_input_group_1.default {
constructor() {
super(...arguments);
this.selectedIdx = -1;
this.valuesByIdx = {};
}
buildChild(option, checked, idx) {
let buttonType = types_1.ButtonType.Info;
if (this.selectedIdx === -1 && checked) {
buttonType = types_1.ButtonType.Primary;
}
if (this.selectedIdx === idx) {
buttonType = types_1.ButtonType.Primary;
}
this.valuesByIdx[idx] = option.value;
return m(button_1.default, {
type: buttonType,
rounded: this.rounded,
disabled: this.disabled,
// When any radio input we assume it's when it's checked
onclick: (event) => {
this.selectedIdx = idx;
this.onchange(event, option.value);
},
}, option.label);
}
buildContainer(classes, vnode) {
return m(button_group_1.default, {
id: vnode.attrs.id,
className: classes.join(" "),
}, this.children);
}
getSelectedValue(e) {
return this.valuesByIdx[this.selectedIdx];
}
}
exports.default = RadioInputButtonGroup;