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