index-ab43c325.js 3.5 KB

12
  1. import{j as $,v as y,t as T,ao as N,n as H,d as A,aG as j,i as D,ac as B,aD as K,E as z,ay as M,u as Y,ak as q,g as r,Y as F,ar as G,as as L,O as U,ae as Z,aH as J,q as Q,x as E,aI as X,az as ee,aA as te,P as oe,m as ae,ap as ne,I as se,D as V}from"./index-1d4a9afa.js";import{C as le}from"./index-a27d7671.js";const[W,h]=$("dropdown-menu"),re={overlay:y,zIndex:T,duration:N(.2),direction:H("down"),activeColor:String,closeOnClickOutside:y,closeOnClickOverlay:y},R=Symbol(W);var ie=A({name:W,props:re,setup(t,{slots:i}){const c=j(),u=D(),a=D(),l=D(0),{children:d,linkChildren:p}=B(R),g=K(u),f=z(()=>d.some(o=>o.state.showWrapper)),O=z(()=>{if(f.value&&M(t.zIndex))return{zIndex:+t.zIndex+1}}),k=()=>{t.closeOnClickOutside&&d.forEach(o=>{o.toggle(!1)})},w=()=>{if(a.value){const o=F(a);t.direction==="down"?l.value=o.bottom:l.value=G.value-o.top}},b=()=>{f.value&&w()},I=o=>{d.forEach((e,n)=>{n===o?e.toggle():e.state.showPopup&&e.toggle(!1,{immediate:!0})})},x=(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:[h("item",{disabled:s}),{[L]:!s}],onClick:()=>{s||I(e)}},[r("span",{class:[h("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}),Y(u,k),q("scroll",b,{target:g,passive:!0}),()=>{var o;return r("div",{ref:u,class:h()},[r("div",{ref:a,style:O.value,class:h("bar",{opened:f.value})},[d.map(x)]),(o=i.default)==null?void 0:o.call(i)])}}});const[ce,P]=$("dropdown-item"),de={title:String,options:Q(),disabled:Boolean,teleport:[String,Object],lazyRender:y,modelValue:E,titleClass:E};var ue=A({name:ce,inheritAttrs:!1,props:de,emits:["open","opened","close","closed","change","update:modelValue"],setup(t,{emit:i,slots:c,attrs:u}){const a=U({showPopup:!1,transition:!0,showWrapper:!1}),{parent:l,index:d}=Z(R);if(!l)return;const p=e=>()=>i(e),g=p("open"),f=p("close"),O=p("opened"),k=()=>{a.showWrapper=!1,i("closed")},w=e=>{t.teleport&&e.stopPropagation()},b=(e=!a.showPopup,n={})=>{e!==a.showPopup&&(a.showPopup=e,a.transition=!n.immediate,e&&(l.updateOffset(),a.showWrapper=!0))},I=()=>{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:""},x=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":C=>a.showPopup=C,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:k},{default:()=>{var C;return[t.options.map(x),(C=c.default)==null?void 0:C.call(c)]}})]),[[te,a.showWrapper]])};return ne({state:a,toggle:b,renderTitle:I}),()=>t.teleport?r(J,{to:t.teleport},{default:()=>[o()]}):o()}});const ve=V(ue),me=V(ie);export{me as D,ve as a};