@nextcloud/vue
Version:
Nextcloud vue components
2 lines (1 loc) • 4.2 kB
JavaScript
var v=require("../assets/index41.css");const s=require("./NcLoadingIcon.cjs"),o=require("../chunks/GenRandomId-67df40eb.cjs"),c=require("../chunks/l10n-dacb6440.cjs"),h=require("vue-material-design-icons/CheckboxBlankOutline.vue"),d=require("vue-material-design-icons/MinusBox.vue"),u=require("vue-material-design-icons/CheckboxMarked.vue"),l=require("vue-material-design-icons/RadioboxMarked.vue"),p=require("vue-material-design-icons/RadioboxBlank.vue"),b=require("vue-material-design-icons/ToggleSwitchOff.vue"),k=require("vue-material-design-icons/ToggleSwitch.vue"),y=require("../chunks/_plugin-vue2_normalizer-764a4c12.cjs");const a="checkbox",r="radio",i="switch",n="button",m={name:"NcCheckboxRadioSwitch",components:{NcLoadingIcon:s},mixins:[c.l10n],props:{id:{type:String,default:()=>"checkbox-radio-switch-"+o.GenRandomId(),validator:e=>e.trim()!==""},name:{type:String,default:null},type:{type:String,default:"checkbox",validator:e=>[a,r,i,n].includes(e)},buttonVariant:{type:Boolean,default:!1},buttonVariantGrouped:{type:String,default:"no",validator:e=>["no","vertical","horizontal"].includes(e)},checked:{type:[Boolean,Array,String],default:!1},value:{type:String,default:null},disabled:{type:Boolean,default:!1},indeterminate:{type:Boolean,default:!1},required:{type:Boolean,default:!1},loading:{type:Boolean,default:!1},wrapperElement:{type:String,default:"span"}},emits:["update:checked"],computed:{inputProps(){return this.type===n?null:{checked:this.isChecked,indeterminate:this.indeterminate,required:this.required,name:this.name}},inputListeners(){return this.type===n?{click:this.onToggle}:{change:this.onToggle}},size(){return this.type===i?36:24},cssVars(){return{"--icon-size":this.size+"px"}},inputType(){return[a,r,n].includes(this.type)?this.type:a},isChecked(){return this.value!==null?Array.isArray(this.checked)?[...this.checked].indexOf(this.value)>-1:this.checked===this.value:this.checked===!0},checkboxRadioIconElement(){return this.type===r?this.isChecked?l:p:this.type===i?this.isChecked?k:b:this.indeterminate?d:this.isChecked?u:h}},mounted(){if(this.name&&this.type===a&&!Array.isArray(this.checked))throw new Error("When using groups of checkboxes, the updated value will be an array.");if(this.name&&this.type===i)throw new Error("Switches are not made to be used for data sets. Please use checkboxes instead.");if(typeof this.checked!="boolean"&&this.type===i)throw new Error("Switches can only be used with boolean as checked prop.")},methods:{onToggle(){if(this.disabled)return;if(this.type===r){this.$emit("update:checked",this.value);return}if(this.type===i){this.$emit("update:checked",!this.isChecked);return}if(typeof this.checked=="boolean"){this.$emit("update:checked",!this.isChecked);return}const e=this.getInputsSet().filter(t=>t.checked).map(t=>t.value);this.$emit("update:checked",e)},getInputsSet(){return[...document.getElementsByName(this.name)]}}};var f=function(){var e=this,t=e._self._c;return t(e.wrapperElement,{tag:"component",staticClass:"checkbox-radio-switch",class:{["checkbox-radio-switch-"+e.type]:e.type,"checkbox-radio-switch--checked":e.isChecked,"checkbox-radio-switch--disabled":e.disabled,"checkbox-radio-switch--indeterminate":e.indeterminate,"checkbox-radio-switch--button-variant":e.buttonVariant,"checkbox-radio-switch--button-variant-v-grouped":e.buttonVariant&&e.buttonVariantGrouped==="vertical","checkbox-radio-switch--button-variant-h-grouped":e.buttonVariant&&e.buttonVariantGrouped==="horizontal"},style:e.cssVars},[t("input",e._g(e._b({staticClass:"checkbox-radio-switch__input",attrs:{id:e.id,disabled:e.disabled,type:e.inputType},domProps:{value:e.value}},"input",e.inputProps,!1),e.inputListeners)),t("label",{staticClass:"checkbox-radio-switch__label",attrs:{for:e.id}},[t("div",{staticClass:"checkbox-radio-switch__icon"},[e._t("icon",function(){return[e.loading?t("NcLoadingIcon"):e.buttonVariant?e._e():t(e.checkboxRadioIconElement,{tag:"component",attrs:{size:e.size}})]},{checked:e.isChecked,loading:e.loading})],2),t("span",{staticClass:"checkbox-radio-switch__label-text"},[e._t("default")],2)])])},g=[],w=y.normalizeComponent(m,f,g,!1,null,"a6f82e18",null,null);const x=w.exports;module.exports=x;