@duetds/components
Version:
This package includes Duet Components and related tools.
60 lines (55 loc) • 2.04 kB
JavaScript
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
const __chunk_1 = require('./chunk-7888512a.js');
class DuetRadioGroup {
constructor(hostRef) {
__chunk_1.registerInstance(this, hostRef);
this.radioButtons = [];
/**
* Direction of the radio group. Can be one of: vertical, horizontal.
*/
this.direction = "vertical";
this.valueChanged = __chunk_1.createEvent(this, "valueChanged", 7);
}
nameChanged() {
this.updateButtons();
}
handleValueChange() {
this.updateButtons();
}
disabledChanged() {
this.updateButtons();
}
componentWillLoad() {
// Grab radio buttons from this component
this.radioButtons = Array.from(this.element.querySelectorAll("duet-radio"));
this.updateButtons();
this.radioButtons.forEach(radioButton => {
radioButton.addEventListener("changed", e => this.selectedRadioButtonChanged(e));
});
}
selectedRadioButtonChanged(event) {
this.value = event.target.value;
this.valueChanged.emit(this.value);
event.cancelBubble = true;
}
updateButtons() {
this.radioButtons.forEach(button => {
button.name = this.name;
button.groupDisabled = this.disabled;
button.checked = button.value === this.value;
button.groupDirection = this.direction;
});
}
render() {
return __chunk_1.h("slot", null);
}
get element() { return __chunk_1.getElement(this); }
static get watchers() { return {
"name": ["nameChanged"],
"value": ["handleValueChange"],
"disabled": ["disabledChanged"]
}; }
static get style() { return ":host{-webkit-appearance:none;-moz-appearance:none;appearance:none;-webkit-box-sizing:border-box;box-sizing:border-box;background:transparent;border:0;padding:0;margin:0;margin-bottom:12px;display:block;width:100%}"; }
}
exports.duet_radio_group = DuetRadioGroup;