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.09 kB
import e from"primevue/icons/ban";import n from"primevue/icons/star";import a from"primevue/icons/starfill";import{UniqueComponentId as t,DomHandler as o}from"primevue/utils";import{openBlock as l,createElementBlock as i,normalizeClass as s,createElementVNode as c,renderSlot as r,createBlock as d,resolveDynamicComponent as u,createCommentVNode as p,Fragment as m,renderList as f}from"vue";var h={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:void 0},offIcon:{type:String,default:void 0},cancelIcon:{type:String,default:void 0}},data(){return{name:this.$attrs.name,focusedOptionIndex:-1}},watch:{"$attrs.name":function(e){this.name=e||t()}},mounted(){this.name=this.name||t()},methods:{onOptionClick(e,n){if(!this.readonly&&!this.disabled){this.onOptionSelect(e,n);const a=o.getFirstFocusableElement(e.currentTarget);a&&o.focus(a)}},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}]}},components:{StarFillIcon:a,StarIcon:n,BanIcon:e}};const g={class:"p-hidden-accessible"},y=["name","checked","disabled","readonly","aria-label"],v=["onClick"],b={class:"p-hidden-accessible"},I=["value","name","checked","disabled","readonly","aria-label","onFocus","onChange"];!function(e,n){void 0===n&&(n={});var a=n.insertAt;if(e&&"undefined"!=typeof document){var t=document.head||document.getElementsByTagName("head")[0],o=document.createElement("style");o.type="text/css","top"===a&&t.firstChild?t.insertBefore(o,t.firstChild):t.appendChild(o),o.styleSheet?o.styleSheet.cssText=e:o.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"),h.render=function(e,n,a,t,o,h){return l(),i("div",{class:s(h.containerClass)},[a.cancel?(l(),i("div",{key:0,class:s(["p-rating-item p-rating-cancel-item",{"p-focus":0===o.focusedOptionIndex}]),onClick:n[3]||(n[3]=e=>h.onOptionClick(e,0))},[c("span",g,[c("input",{type:"radio",value:"0",name:o.name,checked:0===a.modelValue,disabled:a.disabled,readonly:a.readonly,"aria-label":h.cancelAriaLabel(),onFocus:n[0]||(n[0]=e=>h.onFocus(e,0)),onBlur:n[1]||(n[1]=(...e)=>h.onBlur&&h.onBlur(...e)),onChange:n[2]||(n[2]=e=>h.onChange(e,0))},null,40,y)]),r(e.$slots,"cancelicon",{},(()=>[(l(),d(u(a.cancelIcon?"span":"BanIcon"),{class:s(["p-rating-icon p-rating-cancel",a.cancelIcon])},null,8,["class"]))]))],2)):p("",!0),(l(!0),i(m,null,f(a.stars,(t=>(l(),i("div",{key:t,class:s(["p-rating-item",{"p-rating-item-active":t<=a.modelValue,"p-focus":t===o.focusedOptionIndex}]),onClick:e=>h.onOptionClick(e,t)},[c("span",b,[c("input",{type:"radio",value:t,name:o.name,checked:a.modelValue===t,disabled:a.disabled,readonly:a.readonly,"aria-label":h.starAriaLabel(t),onFocus:e=>h.onFocus(e,t),onBlur:n[4]||(n[4]=(...e)=>h.onBlur&&h.onBlur(...e)),onChange:e=>h.onChange(e,t)},null,40,I)]),t<=a.modelValue?r(e.$slots,"onicon",{key:0,value:t},(()=>[(l(),d(u(a.onIcon?"span":"StarFillIcon"),{class:s(["p-rating-icon",a.onIcon])},null,8,["class"]))])):r(e.$slots,"officon",{key:1,value:t},(()=>[(l(),d(u(a.onIcon?"span":"StarIcon"),{class:s(["p-rating-icon",a.offIcon])},null,8,["class"]))]))],10,v)))),128))],2)};export{h as default};