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.9 kB
"use strict";var e=require("primevue/basecomponent"),l=require("primevue/icons/check"),t=require("primevue/utils"),i=require("vue");function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var u=a(e),n=a(l),c={name:"Checkbox",extends:u.default,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.ObjectUtils.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.ObjectUtils.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:n.default}};const d=["id","value","name","checked","tabindex","disabled","readonly","required","aria-labelledby","aria-label"];c.render=function(e,l,t,a,u,n){return i.openBlock(),i.createElementBlock("div",i.mergeProps({class:n.containerClass,onClick:l[2]||(l[2]=e=>n.onClick(e))},e.ptm("root")),[i.createElementVNode("div",i.mergeProps({class:"p-hidden-accessible"},e.ptm("hiddenInputWrapper")),[i.createElementVNode("input",i.mergeProps({ref:"input",id:t.inputId,type:"checkbox",value:t.value,name:t.name,checked:n.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=>n.onFocus(e)),onBlur:l[1]||(l[1]=e=>n.onBlur(e))},e.ptm("hiddenInput")),null,16,d)],16),i.createElementVNode("div",i.mergeProps({ref:"box",class:["p-checkbox-box",t.inputClass,{"p-highlight":n.checked,"p-disabled":t.disabled,"p-focus":u.focused}],style:t.inputStyle},{...t.inputProps,...e.ptm("input")}),[i.renderSlot(e.$slots,"icon",{checked:n.checked},(()=>[(i.openBlock(),i.createBlock(i.resolveDynamicComponent(n.checked?"CheckIcon":null),i.mergeProps({class:"p-checkbox-icon"},e.ptm("icon")),null,16))]))],16)],16)},module.exports=c;