UNPKG

primevue

Version:

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![npm version](https://badge.fury.io/js/primevue.svg)](https://badge.fury.io/js/primevue) [![Discord Chat](https://img.shields.io/discord/55794023

2 lines (1 loc) 2.72 kB
import e from"primevue/basecomponent";import l from"primevue/icons/check";import{ObjectUtils as t}from"primevue/utils";import{openBlock as i,createElementBlock as a,mergeProps as u,createElementVNode as n,renderSlot as d,createBlock as s,resolveDynamicComponent as c}from"vue";var o={name:"Checkbox",extends:e,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 l;l=this.binary?this.checked?this.falseValue:this.trueValue:this.checked?this.modelValue.filter((e=>!t.equals(e,this.value))):this.modelValue?[...this.modelValue,this.value]:[this.value],this.$emit("click",e),this.$emit("update:modelValue",l),this.$emit("change",e),this.$emit("input",l),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:t.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:l}};const r=["id","value","name","checked","tabindex","disabled","readonly","required","aria-labelledby","aria-label"];o.render=function(e,l,t,o,p,h){return i(),a("div",u({class:h.containerClass,onClick:l[2]||(l[2]=e=>h.onClick(e))},e.ptm("root")),[n("div",u({class:"p-hidden-accessible"},e.ptm("hiddenInputWrapper")),[n("input",u({ref:"input",id:t.inputId,type:"checkbox",value:t.value,name:t.name,checked:h.checked,tabindex:t.tabindex,disabled:t.disabled,readonly:t.readonly,required:t.required,"aria-labelledby":e.ariaLabelledby,"aria-label":e.ariaLabel,onFocus:l[0]||(l[0]=e=>h.onFocus(e)),onBlur:l[1]||(l[1]=e=>h.onBlur(e))},e.ptm("hiddenInput")),null,16,r)],16),n("div",u({ref:"box",class:["p-checkbox-box",t.inputClass,{"p-highlight":h.checked,"p-disabled":t.disabled,"p-focus":p.focused}],style:t.inputStyle},{...t.inputProps,...e.ptm("input")}),[d(e.$slots,"icon",{checked:h.checked},(()=>[(i(),s(c(h.checked?"CheckIcon":null),u({class:"p-checkbox-icon"},e.ptm("icon")),null,16))]))],16)],16)};export{o as default};