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) 3.83 kB
import{DomHandler as e,UniqueComponentId as n}from"primevue/utils";import{openBlock as a,createElementBlock as t,normalizeClass as l,createElementVNode as i,renderSlot as o,createCommentVNode as s,Fragment as c,renderList as r}from"vue";var d={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:()=>({focusedOptionIndex:-1}),methods:{onOptionClick(n,a){if(!this.readonly&&!this.disabled){this.onOptionSelect(n,a);const t=e.getFirstFocusableElement(n.currentTarget);t&&e.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]},name(){return this.$attrs.name||n()}}};const u={class:"p-hidden-accessible"},p=["name","checked","disabled","readonly","aria-label"],m=["onClick"],f={class:"p-hidden-accessible"},h=["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],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"),d.render=function(e,n,d,g,y,b){return a(),t("div",{class:l(b.containerClass)},[d.cancel?(a(),t("div",{key:0,class:l(["p-rating-item p-rating-cancel-item",{"p-focus":0===y.focusedOptionIndex}]),onClick:n[3]||(n[3]=e=>b.onOptionClick(e,0))},[i("span",u,[i("input",{type:"radio",value:"0",name:b.name,checked:0===d.modelValue,disabled:d.disabled,readonly:d.readonly,"aria-label":b.cancelAriaLabel(),onFocus:n[0]||(n[0]=e=>b.onFocus(e,0)),onBlur:n[1]||(n[1]=(...e)=>b.onBlur&&b.onBlur(...e)),onChange:n[2]||(n[2]=e=>b.onChange(e,0))},null,40,p)]),o(e.$slots,"cancelicon",{},(()=>[i("span",{class:l(b.cancelIconClass)},null,2)]))],2)):s("",!0),(a(!0),t(c,null,r(d.stars,(s=>(a(),t("div",{key:s,class:l(["p-rating-item",{"p-rating-item-active":s<=d.modelValue,"p-focus":s===y.focusedOptionIndex}]),onClick:e=>b.onOptionClick(e,s)},[i("span",f,[i("input",{type:"radio",value:s,name:b.name,checked:d.modelValue===s,disabled:d.disabled,readonly:d.readonly,"aria-label":b.starAriaLabel(s),onFocus:e=>b.onFocus(e,s),onBlur:n[4]||(n[4]=(...e)=>b.onBlur&&b.onBlur(...e)),onChange:e=>b.onChange(e,s)},null,40,h)]),s<=d.modelValue?o(e.$slots,"onicon",{key:0,value:s},(()=>[i("span",{class:l(b.onIconClass)},null,2)])):o(e.$slots,"officon",{key:1,value:s},(()=>[i("span",{class:l(b.offIconClass)},null,2)]))],10,m)))),128))],2)};export{d as default};