2 lines
3.1 KiB
JavaScript
2 lines
3.1 KiB
JavaScript
import{ak as F,al as N,ao as R,bN as $,bj as A,c as o,c5 as w,ck as T,bJ as j,c0 as D,at as H,g as s,bL as E,n as k,ay as J,az as q,dr as G,cP as K,aC as O,aD as _,i as t,F as C,av as Q,z as U,j as W}from"./main-BhFWIRV_.js";const X=N({name:String,itemAriaLabel:{type:String,default:"$vuetify.rating.ariaLabel.item"},activeColor:String,color:String,clearable:Boolean,disabled:Boolean,emptyIcon:{type:_,default:"$ratingEmpty"},fullIcon:{type:_,default:"$ratingFull"},halfIncrements:Boolean,hover:Boolean,length:{type:[Number,String],default:5},readonly:Boolean,modelValue:{type:[Number,String],default:0},itemLabels:Array,itemLabelPosition:{type:String,default:"top",validator:e=>["top","bottom"].includes(e)},ripple:Boolean,...O(),...K(),...G(),...q(),...J()},"VRating"),Z=F()({name:"VRating",props:X(),emits:{"update:modelValue":e=>!0},setup(e,P){let{slots:r}=P;const{t:f}=R(),{themeClasses:M}=$(e),h=A(e,"modelValue"),u=o(()=>w(parseFloat(h.value),0,Number(e.length))),y=o(()=>T(Number(e.length),1)),I=o(()=>y.value.flatMap(a=>e.halfIncrements?[a-.5,a]:[a])),c=j(-1),v=o(()=>I.value.map(a=>{const l=e.hover&&c.value>-1,n=u.value>=a,i=c.value>=a,g=(l?i:n)?e.fullIcon:e.emptyIcon,b=e.activeColor??e.color,m=n||i?b:e.color;return{isFilled:n,isHovered:i,icon:g,color:m}})),z=o(()=>[0,...I.value].map(a=>{function l(){c.value=a}function n(){c.value=-1}function i(){e.disabled||e.readonly||(h.value=u.value===a&&e.clearable?0:a)}return{onMouseenter:e.hover?l:void 0,onMouseleave:e.hover?n:void 0,onClick:i}})),B=D(),L=o(()=>e.name??`v-rating-${B}`);function d(a){let{value:l,index:n,showStar:i=!0}=a;const{onMouseenter:S,onMouseleave:g,onClick:b}=z.value[n+1],m=`${L.value}-${String(l).replace(".","-")}`,x={color:v.value[n]?.color,density:e.density,disabled:e.disabled,icon:v.value[n]?.icon,ripple:e.ripple,size:e.size,variant:"plain"};return t(C,null,[t("label",{for:m,class:k({"v-rating__item--half":e.halfIncrements&&l%1>0,"v-rating__item--full":e.halfIncrements&&l%1===0}),onMouseenter:S,onMouseleave:g,onClick:b},[t("span",{class:"v-rating__hidden"},[f(e.itemAriaLabel,l,e.length)]),i?r.item?r.item({...v.value[n],props:x,value:l,index:n,rating:u.value}):s(U,Q({"aria-label":f(e.itemAriaLabel,l,e.length)},x),null):void 0]),t("input",{class:"v-rating__hidden",name:L.value,id:m,type:"radio",value:l,checked:u.value===l,tabindex:-1,readonly:e.readonly,disabled:e.disabled},null)])}function V(a){return r["item-label"]?r["item-label"](a):a.label?t("span",null,[a.label]):t("span",null,[W(" ")])}return H(()=>{const a=!!e.itemLabels?.length||r["item-label"];return s(e.tag,{class:k(["v-rating",{"v-rating--hover":e.hover,"v-rating--readonly":e.readonly},M.value,e.class]),style:E(e.style)},{default:()=>[s(d,{value:0,index:-1,showStar:!1},null),y.value.map((l,n)=>t("div",{class:"v-rating__wrapper"},[a&&e.itemLabelPosition==="top"?V({value:l,index:n,label:e.itemLabels?.[n]}):void 0,t("div",{class:"v-rating__item"},[e.halfIncrements?t(C,null,[s(d,{value:l-.5,index:n*2},null),s(d,{value:l,index:n*2+1},null)]):s(d,{value:l,index:n},null)]),a&&e.itemLabelPosition==="bottom"?V({value:l,index:n,label:e.itemLabels?.[n]}):void 0]))]})}),{}}});export{Z as V};
|