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) • 5 kB
JavaScript
"use strict";var e=require("primevue/icons/ban"),n=require("primevue/icons/star"),o=require("primevue/icons/starfill"),t=require("primevue/utils"),a=require("primevue/basecomponent"),c=require("primevue/rating/style"),l=require("vue");function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=i(e),s=i(n),u=i(o),d={name:"Rating",extends:{name:"BaseRating",extends:i(a).default,props:{modelValue:{type:Number,default:null},disabled:{type:Boolean,default:!1},readonly:{type:Boolean,default:!1},stars:{type:Number,default:5},cancel:{type:Boolean,default:!0},onIcon:{type:String,default:void 0},offIcon:{type:String,default:void 0},cancelIcon:{type:String,default:void 0}},style:i(c).default,provide:function(){return{$parentInstance:this}}},emits:["update:modelValue","change","focus","blur"],data:function(){return{name:this.$attrs.name,focusedOptionIndex:-1,isFocusVisibleItem:!0}},watch:{"$attrs.name":function(e){this.name=e||t.UniqueComponentId()}},mounted:function(){this.name=this.name||t.UniqueComponentId()},methods:{getPTOptions:function(e,n){return this.ptm(e,{context:{active:n<=this.modelValue,focused:n===this.focusedOptionIndex}})},onOptionClick:function(e,n){if(!this.readonly&&!this.disabled){this.onOptionSelect(e,n),this.isFocusVisibleItem=!1;var o=t.DomHandler.getFirstFocusableElement(e.currentTarget);o&&t.DomHandler.focus(o)}},onFocus:function(e,n){this.focusedOptionIndex=n,this.$emit("focus",e)},onBlur:function(e){this.focusedOptionIndex=-1,this.$emit("blur",e)},onChange:function(e,n){this.onOptionSelect(e,n),this.isFocusVisibleItem=!0},onOptionSelect:function(e,n){this.focusedOptionIndex=n,this.updateModel(e,n||null)},updateModel:function(e,n){this.$emit("update:modelValue",n),this.$emit("change",{originalEvent:e,value:n})},cancelAriaLabel:function(){return this.$primevue.config.locale.clear},starAriaLabel:function(e){return 1===e?this.$primevue.config.locale.aria.star:this.$primevue.config.locale.aria.stars.replace(/{star}/g,e)}},components:{StarFillIcon:u.default,StarIcon:s.default,BanIcon:r.default}},p=["data-p-focused"],m=["name","checked","disabled","readonly","aria-label"],f=["onClick","data-p-active","data-p-focused"],h=["value","name","checked","disabled","readonly","aria-label","onFocus","onChange"];d.render=function(e,n,o,t,a,c){return l.openBlock(),l.createElementBlock("div",l.mergeProps({class:e.cx("root")},e.ptm("root"),{"data-pc-name":"rating"}),[e.cancel?(l.openBlock(),l.createElementBlock("div",l.mergeProps({key:0,class:e.cx("cancelItem"),onClick:n[3]||(n[3]=function(e){return c.onOptionClick(e,0)})},c.getPTOptions("cancelItem",0),{"data-p-focused":0===a.focusedOptionIndex}),[l.createElementVNode("span",l.mergeProps({class:"p-hidden-accessible"},e.ptm("hiddenCancelInputWrapper"),{"data-p-hidden-accessible":!0}),[l.createElementVNode("input",l.mergeProps({type:"radio",value:"0",name:a.name,checked:0===e.modelValue,disabled:e.disabled,readonly:e.readonly,"aria-label":c.cancelAriaLabel(),onFocus:n[0]||(n[0]=function(e){return c.onFocus(e,0)}),onBlur:n[1]||(n[1]=function(){return c.onBlur&&c.onBlur.apply(c,arguments)}),onChange:n[2]||(n[2]=function(e){return c.onChange(e,0)})},e.ptm("hiddenCancelInput")),null,16,m)],16),l.renderSlot(e.$slots,"cancelicon",{class:l.normalizeClass(e.cx("cancelIcon"))},(function(){return[(l.openBlock(),l.createBlock(l.resolveDynamicComponent(e.cancelIcon?"span":"BanIcon"),l.mergeProps({class:[e.cx("cancelIcon"),e.cancelIcon]},e.ptm("cancelIcon")),null,16,["class"]))]}))],16,p)):l.createCommentVNode("",!0),(l.openBlock(!0),l.createElementBlock(l.Fragment,null,l.renderList(e.stars,(function(o){return l.openBlock(),l.createElementBlock("div",l.mergeProps({key:o,class:e.cx("item",{value:o}),onClick:function(e){return c.onOptionClick(e,o)}},c.getPTOptions("item",o),{"data-p-active":o<=e.modelValue,"data-p-focused":o===a.focusedOptionIndex}),[l.createElementVNode("span",l.mergeProps({class:"p-hidden-accessible"},e.ptm("hiddenItemInputWrapper"),{"data-p-hidden-accessible":!0}),[l.createElementVNode("input",l.mergeProps({type:"radio",value:o,name:a.name,checked:e.modelValue===o,disabled:e.disabled,readonly:e.readonly,"aria-label":c.starAriaLabel(o),onFocus:function(e){return c.onFocus(e,o)},onBlur:n[4]||(n[4]=function(){return c.onBlur&&c.onBlur.apply(c,arguments)}),onChange:function(e){return c.onChange(e,o)}},e.ptm("hiddenItemInput")),null,16,h)],16),o<=e.modelValue?l.renderSlot(e.$slots,"onicon",{key:0,value:o,class:l.normalizeClass(e.cx("onIcon"))},(function(){return[(l.openBlock(),l.createBlock(l.resolveDynamicComponent(e.onIcon?"span":"StarFillIcon"),l.mergeProps({class:[e.cx("onIcon"),e.onIcon]},e.ptm("onIcon")),null,16,["class"]))]})):l.renderSlot(e.$slots,"officon",{key:1,value:o,class:l.normalizeClass(e.cx("offIcon"))},(function(){return[(l.openBlock(),l.createBlock(l.resolveDynamicComponent(e.offIcon?"span":"StarIcon"),l.mergeProps({class:[e.cx("offIcon"),e.offIcon]},e.ptm("offIcon")),null,16,["class"]))]}))],16,f)})),128))],16)},module.exports=d;