index-94bf7631.js 3.5 KB

1
  1. import{j as z,v as y,t as T,al as N,n as H,d as V,aK as K,i as D,aa as M,aH as j,E,av as B,u as L,ah as Y,g as r,Y as q,ao as F,ap as U,O as Z,ac as G,aL as J,q as Q,x as $,aM as X,aw as ee,ax as te,P as oe,m as ae,am as ne,I as se,D as W}from"./index-e826bad6.js";import{C as le}from"./index-0e8cf742.js";const[A,C]=z("dropdown-menu"),re={overlay:y,zIndex:T,duration:N(.2),direction:H("down"),activeColor:String,closeOnClickOutside:y,closeOnClickOverlay:y},R=Symbol(A);var ie=V({name:A,props:re,setup(t,{slots:i}){const c=K(),u=D(),a=D(),l=D(0),{children:d,linkChildren:p}=M(R),g=j(u),f=E(()=>d.some(o=>o.state.showWrapper)),O=E(()=>{if(f.value&&B(t.zIndex))return{zIndex:+t.zIndex+1}}),b=()=>{t.closeOnClickOutside&&d.forEach(o=>{o.toggle(!1)})},w=()=>{if(a.value){const o=q(a);t.direction==="down"?l.value=o.bottom:l.value=F.value-o.top}},k=()=>{f.value&&w()},x=o=>{d.forEach((e,n)=>{n===o?e.toggle():e.state.showPopup&&e.toggle(!1,{immediate:!0})})},I=(o,e)=>{const{showPopup:n}=o.state,{disabled:s,titleClass:v}=o;return r("div",{id:`${c}-${e}`,role:"button",tabindex:s?void 0:0,class:[C("item",{disabled:s}),{[U]:!s}],onClick:()=>{s||x(e)}},[r("span",{class:[C("title",{down:n===(t.direction==="down"),active:n}),v],style:{color:n?t.activeColor:""}},[r("div",{class:"van-ellipsis"},[o.renderTitle()])])])};return p({id:c,props:t,offset:l,updateOffset:w}),L(u,b),Y("scroll",k,{target:g,passive:!0}),()=>{var o;return r("div",{ref:u,class:C()},[r("div",{ref:a,style:O.value,class:C("bar",{opened:f.value})},[d.map(I)]),(o=i.default)==null?void 0:o.call(i)])}}});const[ce,P]=z("dropdown-item"),de={title:String,options:Q(),disabled:Boolean,teleport:[String,Object],lazyRender:y,modelValue:$,titleClass:$};var ue=V({name:ce,inheritAttrs:!1,props:de,emits:["open","opened","close","closed","change","update:modelValue"],setup(t,{emit:i,slots:c,attrs:u}){const a=Z({showPopup:!1,transition:!0,showWrapper:!1}),{parent:l,index:d}=G(R);if(!l)return;const p=e=>()=>i(e),g=p("open"),f=p("close"),O=p("opened"),b=()=>{a.showWrapper=!1,i("closed")},w=e=>{t.teleport&&e.stopPropagation()},k=(e=!a.showPopup,n={})=>{e!==a.showPopup&&(a.showPopup=e,a.transition=!n.immediate,e&&(l.updateOffset(),a.showWrapper=!0))},x=()=>{if(c.title)return c.title();if(t.title)return t.title;const e=t.options.find(n=>n.value===t.modelValue);return e?e.text:""},I=e=>{const{activeColor:n}=l.props,s=e.value===t.modelValue,v=()=>{a.showPopup=!1,e.value!==t.modelValue&&(i("update:modelValue",e.value),i("change",e.value))},m=()=>{if(s)return r(se,{class:P("icon"),color:n,name:"success"},null)};return r(le,{role:"menuitem",key:e.value,icon:e.icon,title:e.text,class:P("option",{active:s}),style:{color:s?n:""},tabindex:s?0:-1,clickable:!0,onClick:v},{value:m})},o=()=>{const{offset:e}=l,{zIndex:n,overlay:s,duration:v,direction:m,closeOnClickOverlay:_}=l.props,S=X(n);return m==="down"?S.top=`${e.value}px`:S.bottom=`${e.value}px`,ee(r("div",ae({style:S,class:P([m]),onClick:w},u),[r(oe,{show:a.showPopup,"onUpdate:show":h=>a.showPopup=h,role:"menu",class:P("content"),overlay:s,position:m==="down"?"top":"bottom",duration:a.transition?v:0,lazyRender:t.lazyRender,overlayStyle:{position:"absolute"},"aria-labelledby":`${l.id}-${d.value}`,closeOnClickOverlay:_,onOpen:g,onClose:f,onOpened:O,onClosed:b},{default:()=>{var h;return[t.options.map(I),(h=c.default)==null?void 0:h.call(c)]}})]),[[te,a.showWrapper]])};return ne({state:a,toggle:k,renderTitle:x}),()=>t.teleport?r(J,{to:t.teleport},{default:()=>[o()]}):o()}});const ve=W(ue),me=W(ie);export{me as D,ve as a};