primevue
Version:
[](https://opensource.org/licenses/MIT) [](https://badge.fury.io/js/primevue) [ • 2.6 kB
JavaScript
import e from"primevue/icons/check";import{ObjectUtils as l}from"primevue/utils";import{openBlock as t,createElementBlock as a,normalizeClass as i,createElementVNode as u,mergeProps as d,normalizeStyle as n,renderSlot as s,createBlock as c,resolveDynamicComponent as o}from"vue";var r={name:"Checkbox",emits:["click","update:modelValue","change","input","focus","blur"],props:{value:null,modelValue:null,binary:Boolean,name:{type:String,default:null},trueValue:{type:null,default:!0},falseValue:{type:null,default:!1},disabled:{type:Boolean,default:!1},readonly:{type:Boolean,default:!1},required:{type:Boolean,default:!1},tabindex:{type:Number,default:null},inputId:{type:String,default:null},inputClass:{type:[String,Object],default:null},inputStyle:{type:Object,default:null},inputProps:{type:null,default:null},"aria-labelledby":{type:String,default:null},"aria-label":{type:String,default:null}},data:()=>({focused:!1}),methods:{onClick(e){if(!this.disabled&&!this.readonly){let t;t=this.binary?this.checked?this.falseValue:this.trueValue:this.checked?this.modelValue.filter((e=>!l.equals(e,this.value))):this.modelValue?[...this.modelValue,this.value]:[this.value],this.$emit("click",e),this.$emit("update:modelValue",t),this.$emit("change",e),this.$emit("input",t),this.$refs.input.focus()}},onFocus(e){this.focused=!0,this.$emit("focus",e)},onBlur(e){this.focused=!1,this.$emit("blur",e)}},computed:{checked(){return this.binary?this.modelValue===this.trueValue:l.contains(this.value,this.modelValue)},containerClass(){return["p-checkbox p-component",{"p-checkbox-checked":this.checked,"p-checkbox-disabled":this.disabled,"p-checkbox-focused":this.focused}]}},components:{CheckIcon:e}};const h={class:"p-hidden-accessible"},p=["id","value","name","checked","tabindex","disabled","readonly","required","aria-labelledby","aria-label"];r.render=function(e,l,r,b,f,m){return t(),a("div",{class:i(m.containerClass),onClick:l[2]||(l[2]=e=>m.onClick(e))},[u("div",h,[u("input",d({ref:"input",id:r.inputId,type:"checkbox",value:r.value,name:r.name,checked:m.checked,tabindex:r.tabindex,disabled:r.disabled,readonly:r.readonly,required:r.required,"aria-labelledby":e.ariaLabelledby,"aria-label":e.ariaLabel,onFocus:l[0]||(l[0]=e=>m.onFocus(e)),onBlur:l[1]||(l[1]=e=>m.onBlur(e))},r.inputProps),null,16,p)]),u("div",{ref:"box",class:i(["p-checkbox-box",r.inputClass,{"p-highlight":m.checked,"p-disabled":r.disabled,"p-focus":f.focused}]),style:n(r.inputStyle)},[s(e.$slots,"icon",{checked:m.checked},(()=>[(t(),c(o(m.checked?"CheckIcon":null),{class:"p-checkbox-icon"}))]))],6)],2)};export{r as default};