primevue
Version:
[](https://opensource.org/licenses/MIT) [](https://badge.fury.io/js/primevue) [ • 5.09 kB
JavaScript
import e from"primevue/icons/check";import t from"primevue/icons/times";import n from"primevue/basecomponent";import{openBlock as c,createElementBlock as o,mergeProps as i,createElementVNode as l,toDisplayString as a,renderSlot as r,normalizeClass as u,createBlock as s,resolveDynamicComponent as d}from"vue";var p={name:"TriStateCheckbox",extends:{name:"BaseTriStateCheckbox",extends:n,props:{modelValue:null,inputId:{type:String,default:null},inputProps:{type:null,default:null},disabled:{type:Boolean,default:!1},tabindex:{type:Number,default:0},"aria-labelledby":{type:String,default:null},"aria-label":{type:String,default:null}},css:{classes:{root:function(e){var t=e.props;return["p-checkbox p-component",{"p-checkbox-checked":!0===t.modelValue,"p-checkbox-disabled":t.disabled,"p-checkbox-focused":e.instance.focused}]},checkbox:function(e){var t=e.props;return["p-checkbox-box",{"p-highlight":null!=t.modelValue,"p-disabled":t.disabled,"p-focus":e.instance.focused}]},checkIcon:"p-checkbox-icon",uncheckIcon:"p-checkbox-icon",nullableIcon:"p-checkbox-icon"}},provide:function(){return{$parentInstance:this}}},emits:["click","update:modelValue","change","keydown","focus","blur"],data:function(){return{focused:!1}},methods:{getPTOptions:function(e){return this.ptm(e,{context:{active:null!==this.modelValue,focused:this.focused,disabled:this.disabled}})},updateModel:function(){if(!this.disabled){var e;switch(this.modelValue){case!0:e=!1;break;case!1:e=null;break;default:e=!0}this.$emit("update:modelValue",e)}},onClick:function(e){this.updateModel(),this.$emit("click",e),this.$emit("change",e),this.$refs.input.focus()},onKeyDown:function(e){"Enter"===e.code&&(this.updateModel(),this.$emit("keydown",e),e.preventDefault())},onFocus:function(e){this.focused=!0,this.$emit("focus",e)},onBlur:function(e){this.focused=!1,this.$emit("blur",e)}},computed:{ariaValueLabel:function(){return this.modelValue?this.$primevue.config.locale.aria.trueLabel:!1===this.modelValue?this.$primevue.config.locale.aria.falseLabel:this.$primevue.config.locale.aria.nullLabel}},components:{CheckIcon:e,TimesIcon:t}};function b(e){return b="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},b(e)}function f(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var c=Object.getOwnPropertySymbols(e);t&&(c=c.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,c)}return n}function h(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?f(Object(n),!0).forEach((function(t){m(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):f(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function m(e,t,n){return(t=y(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function y(e){var t=k(e,"string");return"symbol"===b(t)?t:String(t)}function k(e,t){if("object"!==b(e)||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var c=n.call(e,t||"default");if("object"!==b(c))return c;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}var x=["id","checked","tabindex","disabled","aria-labelledby","aria-label"],v=["data-p-highlight","data-p-disabled","data-p-focused"];p.render=function(e,t,n,p,b,f){return c(),o("div",i({class:e.cx("root"),onClick:t[3]||(t[3]=function(e){return f.onClick(e)})},e.ptm("root"),{"data-pc-name":"tristatecheckbox"}),[l("div",i({class:"p-hidden-accessible"},e.ptm("hiddenInputWrapper"),{"data-p-hidden-accessible":!0}),[l("input",i({ref:"input",id:e.inputId,type:"checkbox",checked:!0===e.modelValue,tabindex:e.tabindex,disabled:e.disabled,"aria-labelledby":e.ariaLabelledby,"aria-label":e.ariaLabel,onKeydown:t[0]||(t[0]=function(e){return f.onKeyDown(e)}),onFocus:t[1]||(t[1]=function(e){return f.onFocus(e)}),onBlur:t[2]||(t[2]=function(e){return f.onBlur(e)})},h(h({},e.inputProps),e.ptm("hiddenInput"))),null,16,x)],16),l("span",i({role:"status",class:"p-hidden-accessible","aria-live":"polite"},e.ptm("hiddenValueLabel"),{"data-p-hidden-accessible":!0}),a(f.ariaValueLabel),17),l("div",i({ref:"box",class:e.cx("checkbox")},f.getPTOptions("checkbox"),{"data-p-highlight":null!=e.modelValue,"data-p-disabled":e.disabled,"data-p-focused":b.focused}),[!0===e.modelValue?r(e.$slots,"checkicon",{key:0,class:u(e.cx("checkIcon"))},(function(){return[(c(),s(d("CheckIcon"),i({class:e.cx("checkIcon")},e.ptm("checkIcon")),null,16,["class"]))]})):!1===e.modelValue?r(e.$slots,"uncheckicon",{key:1,class:u(e.cx("uncheckIcon"))},(function(){return[(c(),s(d("TimesIcon"),i({class:e.cx("uncheckIcon")},e.ptm("uncheckIcon")),null,16,["class"]))]})):r(e.$slots,"nullableicon",{key:2,class:u(e.cx("nullableIcon"))},(function(){return[l("span",i({class:e.cx("nullableIcon")},e.ptm("nullableIcon")),null,16)]}))],16,v)],16)};export{p as default};