UNPKG

@progress/kendo-vue-inputs

Version:
9 lines (8 loc) 6.58 kB
/** * @license *------------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the package root for more information *------------------------------------------------------------------------------------------- */ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("vue"),t=require("@progress/kendo-vue-common"),S=require("../package-metadata.js"),x=require("@progress/kendo-vue-intl"),d=require("../messages/main.js"),B=n.defineComponent({name:"KendoCheckbox",emits:{changemodel:null,"update:modelValue":null,change:null,focus:null,blur:null},model:{event:"changemodel"},inject:{kendoLocalizationService:{default:null}},props:{checked:{type:Boolean,default:void 0},defaultChecked:{type:Boolean,default:void 0},defaultValue:{type:[String,Boolean],default:void 0},modelValue:{type:[String,Boolean],default:void 0},dir:String,disabled:Boolean,id:String,ariaLabelledBy:String,ariaDescribedBy:String,label:String,labelRender:[String,Number,Boolean,Object],labelPlacement:String,labelOptional:Boolean,labelClass:String,name:String,size:{type:String,default:"medium",validator:function(e){return[null,"small","medium","large"].includes(e)}},rounded:{type:String,default:"medium",validator:function(e){return[null,"small","medium","large"].includes(e)}},tabIndex:Number,value:{type:[String,Boolean],default:void 0},validationMessage:String,required:Boolean,valid:{type:Boolean,default:void 0},validityStyles:{type:Boolean,default:!0}},data(){return{valueDuringOnChange:void 0,currentDir:"ltr",currentChecked:void 0,currentValue:void 0}},created(){t.validatePackage(S.packageMetadata),this.calculatedId=t.guid(),this.$props.defaultChecked!==void 0&&(this.currentChecked=this.$props.defaultChecked),this.$props.defaultValue!==void 0&&(this.currentValue=this.$props.defaultValue),this.currentDir=this.$props.dir},computed:{valueIsBooleanOrNull(){const e=this.$props.value;return typeof e=="boolean"||e===null},isCheckedControlled(){return this.$props.checked!==void 0},isValueControlled(){return this.$props.value!==void 0&&this.valueIsBooleanOrNull},computedValue(){return this.$data.valueDuringOnChange!==void 0?this.$data.valueDuringOnChange:this.$props.value!==void 0?this.$props.value:this.$props.modelValue!==void 0?this.$props.modelValue:this.$data.currentValue},computedChecked(){return this.$data.valueDuringOnChange!==void 0?this.$data.valueDuringOnChange:this.$props.checked!==void 0?this.$props.checked:this.$props.modelValue!==void 0?this.$props.modelValue:this.$data.currentChecked},useValueAsChecked(){return this.computedChecked===void 0&&this.computedValue},checkedProp(){return this.useValueAsChecked?this.computedValue:this.computedChecked},valueProp(){const e=this.$props.value;return this.useValueAsChecked||this.isValueControlled?e===null?e:void 0:e||this.computedValue},indeterminateProp(){return this.checkedProp===null||this.valueProp===null},isValid(){const e=this.$props.valid;return e!==void 0?e:this.$props.required?!!this.computedChecked:!0},labelComputedClass(){return{"k-checkbox-label":!0,[this.$props.labelClass]:this.$props.labelClass}}},mounted(){if(this.input=t.getRef(this,"input"),!this.currentDir&&window&&this.$el){const e=window.getComputedStyle(this.$el).direction;e&&(this.currentDir=e)}this.setValidity()},updated(){this.input||(this.input=t.getRef(this,"input")),this.setValidity()},setup(){const e=n.ref(null),i=n.inject("kendoLocalizationService",{});return{inputRef:e,kendoLocalizationService:i}},render(){const{ariaDescribedBy:e,ariaLabelledBy:i,disabled:a,id:r,label:g,labelRender:l,labelPlacement:k,name:b,labelOptional:C,tabIndex:$,required:u,validityStyles:V,size:o,rounded:c}=this.$props,h=t.getDefaultSlots(this);let s=g;this.localizationService=x.provideLocalizationService(this),this.defaultValidationMessage=this.localizeMessage(d.checkboxValidation),this.optionalMessage=this.localizeMessage(d.checkboxOptionalText);const p=t.classNames({"k-checkbox-wrap":!0,"k-disabled":a}),v=t.classNames({"k-checkbox":!0,[`k-checkbox-${t.kendoThemeMaps.sizeMap[o]}`]:o,[`k-rounded-${t.kendoThemeMaps.roundedMap[c]}`]:c,"k-indeterminate":this.indeterminateProp,"k-disabled":a,"k-invalid":!this.isValid&&V!==!1}),f=function(){return n.createVNode("input",{type:"checkbox",class:v,name:b,id:r||this.calculatedId,ref:t.setRef(this,"input"),"aria-labelledby":i,"aria-describedby":e,checked:!!this.checkedProp,disabled:a,tabindex:t.getTabIndex($,a),role:"checkbox",required:u!==void 0?u:!1,"aria-checked":this.computedChecked||this.checkedProp?!0:this.indeterminateProp?"mixed":!1,"aria-disabled":a||void 0,onChange:this.onChangeHandler,onKeydown:this.onKeyDownHandler,onFocus:this.onFocusHandler,onBlur:this.onBlurHandler},null)};if(l){const y=l?t.templateRendering.call(this,l,t.getListeners.call(this)):null;s=t.getTemplate.call(this,{h:n.h,template:y})}const m=function(){return s!==void 0?n.createVNode("label",{class:this.labelComputedClass,for:r||this.calculatedId,style:{userSelect:"none"}},[s,C&&n.createVNode("span",{class:"k-label-optional"},[this.optionalMessage])]):null};return k==="before"?n.createVNode("span",{class:p,dir:"rtl"},[f.call(this),m.call(this),h]):n.createVNode("span",{class:p,dir:this.currentDir},[f.call(this),m.call(this),h])},methods:{setValidity(){const e=this.$props.valid!==void 0?this.$props.valid:this.$props.required?!!this.computedChecked:!0;this.input&&this.input.setCustomValidity&&this.input.setCustomValidity(e?"":this.$props.validationMessage||this.defaultValidationMessage)},localizeMessage(e){return this.localizationService.toLanguageString(e,d.messages[e])},focusElement(){this.input&&this.input.focus()},setValue(e,i){this.$data.valueDuringOnChange=i,this.$nextTick(()=>{if(!this.isCheckedControlled&&!this.isValueControlled&&!this.$props.disabled&&(this.currentValue=i,this.currentChecked=i),!this.$props.disabled){const a={element:this.$el,focus:null};this.$emit("changemodel",i),this.$emit("update:modelValue",i),this.$emit("change",{e,handle:a,value:i})}this.$data.valueDuringOnChange=void 0})},onChangeHandler(e){let i=e.target.checked;this.setValue(e,i)},onKeyDownHandler(e){if(this.$props.disabled)return;const{keyCode:i}=e;let a=e.currentTarget.checked;i===t.Keys.space&&(e.preventDefault(),e.stopPropagation(),this.setValue(e,!a))},onBlurHandler(e){this.$props.disabled||this.$emit("blur",e)},onFocusHandler(e){this.$props.disabled||this.$emit("focus",e)}}});exports.Checkbox=B;