@dialpad/dialtone
Version:
Dialpad's Dialtone design system monorepo
113 lines (112 loc) • 2.66 kB
JavaScript
import { warn } from "vue";
import DtInputGroup from "../input_group/input_group.vue.js";
const _sfc_main = {
compatConfig: { MODE: 3 },
name: "DtCheckboxGroup",
extends: DtInputGroup,
model: {
prop: "selectedValues"
},
props: {
/**
* Not supported by this component, please use selectedValues
*/
value: {
type: [],
default: null,
validator: (value) => {
if (!value) {
return true;
}
warn(
"Component uses selectedValues to initialize the model, value is not supported by this component",
void 0
);
return false;
}
},
/**
* A provided list of selected values(s) for the checkbox group
* @model selectedValues
*/
selectedValues: {
type: Array,
default() {
return [];
}
},
/**
* A data qa tag for the radio group
*/
dataQaGroup: {
type: String,
default: "checkbox-group"
},
/**
* A data qa tag for the radio group legend
*/
dataQaGroupLegend: {
type: String,
default: "checkbox-group-legend"
},
/**
* A data qa tag for the radio group messages
*/
dataQaGroupMessages: {
type: String,
default: "checkbox-group-messages"
}
},
emits: [
/**
* Native input event
*
* @event input
* @type {Array}
*/
"input"
],
data() {
return {
internalValue: this.selectedValues
};
},
watch: {
selectedValues(newSelectedValues) {
this.internalValue = newSelectedValues;
},
/*
* watching value to support 2 way binding for slotted checkboxes.
* need this to pass value to slotted checkboxes if modified outside
* checkbox group.
*/
internalValue: {
immediate: true,
handler(newInternalValue) {
this.provideObj.selectedValues = newInternalValue;
}
}
},
methods: {
/*
* provided value to support 2 way binding for slotted checkboxes.
* slotted checkbox will change this value and need to emit new value up.
*/
setGroupValue(value, checked) {
if (!checked) {
this.internalValue = this.internalValue.filter((checkedValue) => checkedValue !== value);
} else if (!this.internalValue.includes(value)) {
this.internalValue.push(value);
}
this.$emit("input", this.internalValue);
},
getMessageKey(type, index) {
return `checkbox-group-message-${type}-${index}-${this.id}`;
}
}
};
const _sfc_main$1 = _sfc_main;
export {
_sfc_main$1 as default
};
//# sourceMappingURL=checkbox_group.vue.js.map