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) 4.23 kB
this.primevue=this.primevue||{},this.primevue.rating=function(e,n){"use strict";var a={name:"Rating",emits:["update:modelValue","change","focus","blur"],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:"pi pi-star-fill"},offIcon:{type:String,default:"pi pi-star"},cancelIcon:{type:String,default:"pi pi-ban"}},data(){return{name:this.$attrs.name,focusedOptionIndex:-1}},watch:{"$attrs.name":function(n){this.name=n||e.UniqueComponentId()}},mounted(){this.name=this.name||e.UniqueComponentId()},methods:{onOptionClick(n,a){if(!this.readonly&&!this.disabled){this.onOptionSelect(n,a);const t=e.DomHandler.getFirstFocusableElement(n.currentTarget);t&&e.DomHandler.focus(t)}},onFocus(e,n){this.focusedOptionIndex=n,this.$emit("focus",e)},onBlur(e){this.focusedOptionIndex=-1,this.$emit("blur",e)},onChange(e,n){this.onOptionSelect(e,n)},onOptionSelect(e,n){this.focusedOptionIndex=n,this.updateModel(e,n||null)},updateModel(e,n){this.$emit("update:modelValue",n),this.$emit("change",{originalEvent:e,value:n})},cancelAriaLabel(){return this.$primevue.config.locale.clear},starAriaLabel(e){return 1===e?this.$primevue.config.locale.aria.star:this.$primevue.config.locale.aria.stars.replace(/{star}/g,e)}},computed:{containerClass(){return["p-rating",{"p-readonly":this.readonly,"p-disabled":this.disabled}]},cancelIconClass(){return["p-rating-icon p-rating-cancel",this.cancelIcon]},onIconClass(){return["p-rating-icon",this.onIcon]},offIconClass(){return["p-rating-icon",this.offIcon]}}};const t={class:"p-hidden-accessible"},l=["name","checked","disabled","readonly","aria-label"],o=["onClick"],i={class:"p-hidden-accessible"},s=["value","name","checked","disabled","readonly","aria-label","onFocus","onChange"];return function(e,n){void 0===n&&(n={});var a=n.insertAt;if(e&&"undefined"!=typeof document){var t=document.head||document.getElementsByTagName("head")[0],l=document.createElement("style");l.type="text/css","top"===a&&t.firstChild?t.insertBefore(l,t.firstChild):t.appendChild(l),l.styleSheet?l.styleSheet.cssText=e:l.appendChild(document.createTextNode(e))}}("\n.p-rating {\n position: relative;\n display: flex;\n align-items: center;\n}\n.p-rating-item {\n display: inline-flex;\n align-items: center;\n cursor: pointer;\n}\n.p-rating.p-readonly .p-rating-item {\n cursor: default;\n}\n"),a.render=function(e,a,r,c,d,u){return n.openBlock(),n.createElementBlock("div",{class:n.normalizeClass(u.containerClass)},[r.cancel?(n.openBlock(),n.createElementBlock("div",{key:0,class:n.normalizeClass(["p-rating-item p-rating-cancel-item",{"p-focus":0===d.focusedOptionIndex}]),onClick:a[3]||(a[3]=e=>u.onOptionClick(e,0))},[n.createElementVNode("span",t,[n.createElementVNode("input",{type:"radio",value:"0",name:d.name,checked:0===r.modelValue,disabled:r.disabled,readonly:r.readonly,"aria-label":u.cancelAriaLabel(),onFocus:a[0]||(a[0]=e=>u.onFocus(e,0)),onBlur:a[1]||(a[1]=(...e)=>u.onBlur&&u.onBlur(...e)),onChange:a[2]||(a[2]=e=>u.onChange(e,0))},null,40,l)]),n.renderSlot(e.$slots,"cancelicon",{},(()=>[n.createElementVNode("span",{class:n.normalizeClass(u.cancelIconClass)},null,2)]))],2)):n.createCommentVNode("",!0),(n.openBlock(!0),n.createElementBlock(n.Fragment,null,n.renderList(r.stars,(t=>(n.openBlock(),n.createElementBlock("div",{key:t,class:n.normalizeClass(["p-rating-item",{"p-rating-item-active":t<=r.modelValue,"p-focus":t===d.focusedOptionIndex}]),onClick:e=>u.onOptionClick(e,t)},[n.createElementVNode("span",i,[n.createElementVNode("input",{type:"radio",value:t,name:d.name,checked:r.modelValue===t,disabled:r.disabled,readonly:r.readonly,"aria-label":u.starAriaLabel(t),onFocus:e=>u.onFocus(e,t),onBlur:a[4]||(a[4]=(...e)=>u.onBlur&&u.onBlur(...e)),onChange:e=>u.onChange(e,t)},null,40,s)]),t<=r.modelValue?n.renderSlot(e.$slots,"onicon",{key:0,value:t},(()=>[n.createElementVNode("span",{class:n.normalizeClass(u.onIconClass)},null,2)])):n.renderSlot(e.$slots,"officon",{key:1,value:t},(()=>[n.createElementVNode("span",{class:n.normalizeClass(u.offIconClass)},null,2)]))],10,o)))),128))],2)},a}(primevue.utils,Vue);