ll-package
Version:
2 lines (1 loc) • 3.8 kB
JavaScript
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const F=require("../../../@babel/runtime/helpers/esm/objectSpread2.js"),r=require("vue"),A=require("../_util/props-util/index.js"),G=require("../_util/type.js"),X=require("./util.js"),_=require("../_util/classNames.js"),h=require("../_util/vue-types/index.js"),C=require("../_util/KeyCode.js"),U=require("../../../@ant-design/icons-vue/es/icons/StarFilled.js"),W=require("../tooltip/index.js"),z=require("../config-provider/hooks/useConfigInject.js"),J=require("./Star.js"),Q=require("../_util/hooks/useRefs.js"),Y=require("../form/FormItemContext.js"),Z=require("./style/index.js"),ee=require("../_util/props-util/initDefaultProps.js"),R=()=>({prefixCls:String,count:Number,value:Number,allowHalf:{type:Boolean,default:void 0},allowClear:{type:Boolean,default:void 0},tooltips:Array,disabled:{type:Boolean,default:void 0},character:h.default.any,autofocus:{type:Boolean,default:void 0},tabindex:h.default.oneOfType([h.default.number,h.default.string]),direction:String,id:String,onChange:Function,onHoverChange:Function,"onUpdate:value":Function,onFocus:Function,onBlur:Function,onKeydown:Function}),te=r.defineComponent({compatConfig:{MODE:3},name:"ARate",inheritAttrs:!1,props:ee.default(R(),{value:0,count:5,allowHalf:!1,allowClear:!0,tabindex:0,direction:"ltr"}),setup(u,S){let{slots:H,attrs:y,emit:s,expose:D}=S;const{prefixCls:c,direction:b}=z.default("rate",u),[N,I]=Z.default(c),g=Y.useInjectFormItemContext(),w=r.ref(),[B,M]=Q.default(),e=r.reactive({value:u.value,focused:!1,cleanedValue:null,hoverValue:void 0});r.watch(()=>u.value,()=>{e.value=u.value});const p=t=>A.findDOMNode(M.value.get(t)),V=(t,a)=>{const l=b.value==="rtl";let n=t+1;if(u.allowHalf){const o=p(t),f=X.getOffsetLeft(o),v=o.clientWidth;(l&&a-f>v/2||!l&&a-f<v/2)&&(n-=.5)}return n},i=t=>{u.value===void 0&&(e.value=t),s("update:value",t),s("change",t),g.onFieldChange()},$=(t,a)=>{const l=V(a,t.pageX);l!==e.cleanedValue&&(e.hoverValue=l,e.cleanedValue=null),s("hoverChange",l)},m=()=>{e.hoverValue=void 0,e.cleanedValue=null,s("hoverChange",void 0)},O=(t,a)=>{const{allowClear:l}=u,n=V(a,t.pageX);let o=!1;l&&(o=n===e.value),m(),i(o?0:n),e.cleanedValue=o?n:null},T=t=>{e.focused=!0,s("focus",t)},k=t=>{e.focused=!1,s("blur",t),g.onFieldBlur()},j=t=>{const{keyCode:a}=t,{count:l,allowHalf:n}=u,o=b.value==="rtl";a===C.default.RIGHT&&e.value<l&&!o?(n?e.value+=.5:e.value+=1,i(e.value),t.preventDefault()):a===C.default.LEFT&&e.value>0&&!o||a===C.default.RIGHT&&e.value>0&&o?(n?e.value-=.5:e.value-=1,i(e.value),t.preventDefault()):a===C.default.LEFT&&e.value<l&&o&&(n?e.value+=.5:e.value+=1,i(e.value),t.preventDefault()),s("keydown",t)},q=()=>{u.disabled||w.value.focus()};D({focus:q,blur:()=>{u.disabled||w.value.blur()}}),r.onMounted(()=>{const{autofocus:t,disabled:a}=u;t&&!a&&q()});const E=(t,a)=>{let{index:l}=a;const{tooltips:n}=u;return n?r.createVNode(W.default,{title:n[l]},{default:()=>[t]}):t};return()=>{const{count:t,allowHalf:a,disabled:l,tabindex:n,id:o=g.id.value}=u,{class:f,style:v}=y,x=[],K=l?`${c.value}-disabled`:"",L=u.character||H.character||(()=>r.createVNode(U.default,null,null));for(let d=0;d<t;d++)x.push(r.createVNode(J.default,{ref:B(d),key:d,index:d,count:t,disabled:l,prefixCls:`${c.value}-star`,allowHalf:a,value:e.hoverValue===void 0?e.value:e.hoverValue,onClick:O,onHover:$,character:L,characterRender:E,focused:e.focused},null));const P=_.default(c.value,K,f,{[I.value]:!0,[`${c.value}-rtl`]:b.value==="rtl"});return N(r.createVNode("ul",F.default(F.default({},y),{},{id:o,class:P,style:v,onMouseleave:l?null:m,tabindex:l?-1:n,onFocus:l?null:T,onBlur:l?null:k,onKeydown:l?null:j,ref:w,role:"radiogroup"}),[x]))}}}),le=G.withInstall(te);exports.default=le;exports.rateProps=R;
;