UNPKG

primevue

Version:

PrimeVue is an open source UI library for Vue featuring a rich set of 80+ components, a theme designer, various theme alternatives such as Material, Bootstrap, Tailwind, premium templates and professional support. In addition, it integrates with PrimeBloc

2 lines (1 loc) 6.49 kB
import e from"primevue/ripple";import{DomHandler as t,ObjectUtils as n}from"primevue/utils";import i from"primevue/basecomponent";import o from"primevue/selectbutton/style";import{resolveDirective as r,openBlock as l,createElementBlock as a,mergeProps as u,Fragment as s,renderList as d,withDirectives as c,renderSlot as f,normalizeClass as p,createElementVNode as h,toDisplayString as b}from"vue";function m(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=g(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var i=0,o=function(){};return{s:o,n:function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var r,l=!0,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,r=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw r}}}}function y(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function g(e,t){if(e){if("string"==typeof e)return S(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?S(e,t):void 0}}function v(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function x(e){if(Array.isArray(e))return S(e)}function S(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,i=new Array(t);n<t;n++)i[n]=e[n];return i}var A={name:"SelectButton",extends:{name:"BaseSelectButton",extends:i,props:{modelValue:null,options:Array,optionLabel:null,optionValue:null,optionDisabled:null,multiple:Boolean,unselectable:{type:Boolean,default:!0},allowEmpty:{type:Boolean,default:!0},invalid:{type:Boolean,default:!1},disabled:Boolean,dataKey:null,ariaLabelledby:{type:String,default:null}},style:o,provide:function(){return{$parentInstance:this}}},inheritAttrs:!1,emits:["update:modelValue","focus","blur","change"],data:function(){return{focusedIndex:0}},mounted:function(){this.defaultTabIndexes()},methods:{defaultTabIndexes:function(){for(var e=t.find(this.$refs.container,'[data-pc-section="button"]'),i=t.findSingle(this.$refs.container,'[data-p-highlight="true"]'),o=0;o<e.length;o++)(!0===t.getAttribute(e[o],"data-p-highlight")&&n.equals(e[o],i)||null===i&&0==o)&&(this.focusedIndex=o)},getOptionLabel:function(e){return this.optionLabel?n.resolveFieldData(e,this.optionLabel):e},getOptionValue:function(e){return this.optionValue?n.resolveFieldData(e,this.optionValue):e},getOptionRenderKey:function(e){return this.dataKey?n.resolveFieldData(e,this.dataKey):this.getOptionLabel(e)},getPTOptions:function(e,t){return this.ptm(t,{context:{active:this.isSelected(e),disabled:this.isOptionDisabled(e),option:e}})},isOptionDisabled:function(e){return!!this.optionDisabled&&n.resolveFieldData(e,this.optionDisabled)},onOptionSelect:function(e,t,i){var o=this;if(!this.disabled&&!this.isOptionDisabled(t)){var r=this.isSelected(t);if(!r||this.unselectable&&this.allowEmpty){var l,a,u=this.getOptionValue(t);l=this.multiple?r?this.modelValue.filter((function(e){return!n.equals(e,u,o.equalityKey)})):this.modelValue?[].concat(x(a=this.modelValue)||v(a)||g(a)||y(),[u]):[u]:r?null:u,this.focusedIndex=i,this.$emit("update:modelValue",l),this.$emit("change",{event:e,value:l})}}},isSelected:function(e){var t=!1,i=this.getOptionValue(e);if(this.multiple){if(this.modelValue){var o,r=m(this.modelValue);try{for(r.s();!(o=r.n()).done;){if(n.equals(o.value,i,this.equalityKey)){t=!0;break}}}catch(e){r.e(e)}finally{r.f()}}}else t=n.equals(this.modelValue,i,this.equalityKey);return t},onKeydown:function(e,t,n){switch(e.code){case"Space":this.onOptionSelect(e,t,n),e.preventDefault();break;case"ArrowDown":case"ArrowRight":this.onArrowRightKey(e.target),e.preventDefault();break;case"ArrowUp":case"ArrowLeft":this.onArrowLeftKey(e.target),e.preventDefault()}},onArrowRightKey:function(e){var i=this.findNextElement(e);i&&(this.focusedIndex=n.findIndexInList(i,this.findAllElements()),t.focus(i))},onArrowLeftKey:function(e){var i=this.findPrevElement(e);i&&(this.focusedIndex=n.findIndexInList(i,this.findAllElements()),t.focus(i))},findAllElements:function(){return t.find(this.$refs.container,'[data-pc-section="button"]')},findNextElement:function(e){return e.nextElementSibling?t.getAttribute(e.nextElementSibling,"data-p-disabled")?this.findNextElement(e.nextElementSibling):e.nextElementSibling:null},findPrevElement:function(e){return e.previousElementSibling?t.getAttribute(e.previousElementSibling,"data-p-disabled")?this.findPrevElement(e.previousElementSibling):e.previousElementSibling:null},onFocus:function(e){this.$emit("focus",e)},onBlur:function(e,t){e.target&&e.relatedTarget&&e.target.parentElement!==e.relatedTarget.parentElement&&this.defaultTabIndexes(),this.$emit("blur",e,t)},findTabindex:function(e,t){return this.disabled||this.isOptionDisabled(e)||t!==this.focusedIndex?"-1":"0"}},computed:{equalityKey:function(){return this.optionValue?null:this.dataKey}},directives:{ripple:e}},w=["aria-labelledby"],E=["tabindex","aria-label","role","aria-checked","aria-disabled","onClick","onKeydown","onBlur","data-p-highlight","data-p-disabled"];A.render=function(e,t,n,i,o,m){var y=r("ripple");return l(),a("div",u({ref:"container",class:e.cx("root"),role:"group","aria-labelledby":e.ariaLabelledby},e.ptmi("root")),[(l(!0),a(s,null,d(e.options,(function(n,i){return c((l(),a("div",u({key:m.getOptionRenderKey(n),tabindex:m.findTabindex(n,i),"aria-label":m.getOptionLabel(n),role:e.multiple?"checkbox":"radio","aria-checked":m.isSelected(n),"aria-disabled":m.isOptionDisabled(n),class:e.cx("button",{option:n}),onClick:function(e){return m.onOptionSelect(e,n,i)},onKeydown:function(e){return m.onKeydown(e,n,i)},onFocus:t[0]||(t[0]=function(e){return m.onFocus(e)}),onBlur:function(e){return m.onBlur(e,n)}},m.getPTOptions(n,"button"),{"data-p-highlight":m.isSelected(n),"data-p-disabled":m.isOptionDisabled(n)}),[f(e.$slots,"option",{option:n,index:i,class:p(e.cx("label"))},(function(){return[h("span",u({class:e.cx("label")},m.getPTOptions(n,"label")),b(m.getOptionLabel(n)),17)]}))],16,E)),[[y]])})),128))],16,w)};export{A as default};