2023-11-15 15:57:04 +08:00

2 lines
5.1 KiB
JavaScript

import{C as me,U as C,v as $}from"./event-f85d77b0.js";import{b as pe,d as I,au as V,m as L,av as he,_ as ye,a as R,ab as be,H as Ve,v as we,a6 as xe,E as W,a3 as q}from"./index-cf9a2dd7.js";import{m as G}from"./index-e27c3bb0.js";import{d as ae,I as U,b as Ce,r as S,c as u,G as E,q as X,ay as T,m as J,w as _e,e as c,f as h,F as Q,z as ge,n as y,u as o,y as Ie,x as Y,M as Z,v as w,S as D,H,j as ee,B as Se,_ as Ee,l as Te}from"./plugin-vue_export-helper-85a4d40b.js";import{E as x}from"./index-1ad115d7.js";const De=pe({modelValue:{type:Number,default:0},id:{type:String,default:void 0},lowThreshold:{type:Number,default:2},highThreshold:{type:Number,default:4},max:{type:Number,default:5},colors:{type:I([Array,Object]),default:()=>G(["","",""])},voidColor:{type:String,default:""},disabledVoidColor:{type:String,default:""},icons:{type:I([Array,Object]),default:()=>[V,V,V]},voidIcon:{type:L,default:()=>he},disabledVoidIcon:{type:L,default:()=>V},disabled:Boolean,allowHalf:Boolean,showText:Boolean,showScore:Boolean,textColor:{type:String,default:""},texts:{type:I(Array),default:()=>G(["Extremely bad","Disappointed","Fair","Satisfied","Surprise"])},scoreTemplate:{type:String,default:"{value}"},size:ye,label:{type:String,default:void 0},clearable:{type:Boolean,default:!1}}),He={[me]:v=>R(v),[C]:v=>R(v)},Ne=["id","aria-label","aria-labelledby","aria-valuenow","aria-valuetext","aria-valuemax"],Me=["onMousemove","onClick"],ke=ae({name:"ElRate"}),Be=ae({...ke,props:De,emits:He,setup(v,{expose:le,emit:m}){const e=v;function _(a,l){const t=n=>X(n),i=Object.keys(l).map(n=>+n).filter(n=>{const b=l[n];return(t(b)?b.excluded:!1)?a<n:a<=n}).sort((n,b)=>n-b),p=l[i[0]];return t(p)&&p.value||p}const N=U(be,void 0),M=U(Ve,void 0),oe=we(),r=Ce("rate"),{inputId:te,isLabeledByFormItem:k}=xe(e,{formItemContext:M}),s=S(e.modelValue),g=S(-1),f=S(!0),se=u(()=>[r.b(),r.m(oe.value)]),d=u(()=>e.disabled||(N==null?void 0:N.disabled)),re=u(()=>r.cssVarBlock({"void-color":e.voidColor,"disabled-void-color":e.disabledVoidColor,"fill-color":P.value})),B=u(()=>{let a="";return e.showScore?a=e.scoreTemplate.replace(/\{\s*value\s*\}/,d.value?`${e.modelValue}`:`${s.value}`):e.showText&&(a=e.texts[Math.ceil(s.value)-1]),a}),A=u(()=>e.modelValue*100-Math.floor(e.modelValue)*100),ne=u(()=>E(e.colors)?{[e.lowThreshold]:e.colors[0],[e.highThreshold]:{value:e.colors[1],excluded:!0},[e.max]:e.colors[2]}:e.colors),P=u(()=>{const a=_(s.value,ne.value);return X(a)?"":a}),ue=u(()=>{let a="";return d.value?a=`${A.value}%`:e.allowHalf&&(a="50%"),{color:P.value,width:a}}),j=u(()=>{let a=E(e.icons)?[...e.icons]:{...e.icons};return a=T(a),E(a)?{[e.lowThreshold]:a[0],[e.highThreshold]:{value:a[1],excluded:!0},[e.max]:a[2]}:a}),ie=u(()=>_(e.modelValue,j.value)),de=u(()=>d.value?J(e.disabledVoidIcon)?e.disabledVoidIcon:T(e.disabledVoidIcon):J(e.voidIcon)?e.voidIcon:T(e.voidIcon)),ce=u(()=>_(s.value,j.value));function z(a){const l=d.value&&A.value>0&&a-1<e.modelValue&&a>e.modelValue,t=e.allowHalf&&f.value&&a-.5<=s.value&&a>s.value;return l||t}function O(a){e.clearable&&a===e.modelValue&&(a=0),m(C,a),e.modelValue!==a&&m("change",a)}function fe(a){d.value||(e.allowHalf&&f.value?O(s.value):O(a))}function ve(a){if(d.value)return;let l=s.value;const t=a.code;return t===x.up||t===x.right?(e.allowHalf?l+=.5:l+=1,a.stopPropagation(),a.preventDefault()):(t===x.left||t===x.down)&&(e.allowHalf?l-=.5:l-=1,a.stopPropagation(),a.preventDefault()),l=l<0?0:l,l=l>e.max?e.max:l,m(C,l),m("change",l),l}function F(a,l){if(!d.value){if(e.allowHalf&&l){let t=l.target;q(t,r.e("item"))&&(t=t.querySelector(`.${r.e("icon")}`)),(t.clientWidth===0||q(t,r.e("decimal")))&&(t=t.parentNode),f.value=l.offsetX*2<=t.clientWidth,s.value=f.value?a-.5:a}else s.value=a;g.value=a}}function K(){d.value||(e.allowHalf&&(f.value=e.modelValue!==Math.floor(e.modelValue)),s.value=e.modelValue,g.value=-1)}return _e(()=>e.modelValue,a=>{s.value=a,f.value=e.modelValue!==Math.floor(e.modelValue)}),e.modelValue||m(C,0),le({setCurrentValue:F,resetCurrentValue:K}),(a,l)=>{var t;return c(),h("div",{id:o(te),class:y([o(se),o(r).is("disabled",o(d))]),role:"slider","aria-label":o(k)?void 0:a.label||"rating","aria-labelledby":o(k)?(t=o(M))==null?void 0:t.labelId:void 0,"aria-valuenow":s.value,"aria-valuetext":o(B)||void 0,"aria-valuemin":"0","aria-valuemax":a.max,tabindex:"0",style:ee(o(re)),onKeydown:ve},[(c(!0),h(Q,null,ge(a.max,(i,p)=>(c(),h("span",{key:p,class:y(o(r).e("item")),onMousemove:n=>F(i,n),onMouseleave:K,onClick:n=>fe(i)},[Ie(o(W),{class:y([o(r).e("icon"),{hover:g.value===i},o(r).is("active",i<=s.value)])},{default:Y(()=>[z(i)?H("v-if",!0):(c(),h(Q,{key:0},[Z((c(),w(D(o(ce)),null,null,512)),[[$,i<=s.value]]),Z((c(),w(D(o(de)),null,null,512)),[[$,!(i<=s.value)]])],64)),z(i)?(c(),w(o(W),{key:1,style:ee(o(ue)),class:y([o(r).e("icon"),o(r).e("decimal")])},{default:Y(()=>[(c(),w(D(o(ie))))]),_:1},8,["style","class"])):H("v-if",!0)]),_:2},1032,["class"])],42,Me))),128)),a.showText||a.showScore?(c(),h("span",{key:0,class:y(o(r).e("text"))},Se(o(B)),3)):H("v-if",!0)],46,Ne)}}});var Ae=Ee(Be,[["__file","/home/runner/work/element-plus/element-plus/packages/components/rate/src/rate.vue"]]);const $e=Te(Ae);export{$e as E};