| 1 |
- import{G as $,I as P,H as T,ac as _,a1 as N,d as z,V as S,ak as H,ad as M,X as D,N as Z,bz as j,ag as B,j as s,aV as G,Z as K,an as U,aZ as F,J as V,U as J,au as L,al as X,bA as Y,af as q,a7 as Q,aG as ee,aT as oe,O as te,P as E}from"./ResizeObserver.es.62ab429c.js";import{C as ne}from"./index.d7a13e47.js";import{u as ae}from"./use-id.1bbe472d.js";const[W,C]=$("dropdown-menu"),se={overlay:P,zIndex:T,duration:_(.2),direction:N("down"),activeColor:String,closeOnClickOutside:P,closeOnClickOverlay:P},A=Symbol(W);var le=z({name:W,props:se,setup(o,{slots:c}){const d=ae(),t=S(),l=S(),p=S(0),{children:r,linkChildren:y}=H(A),b=M(t),f=D(()=>r.some(e=>e.state.showWrapper)),g=D(()=>{if(f.value&&Z(o.zIndex))return{zIndex:+o.zIndex+1}}),k=()=>{o.closeOnClickOutside&&r.forEach(e=>{e.toggle(!1)})},v=()=>{if(l.value){const e=K(l);o.direction==="down"?p.value=e.bottom:p.value=U.value-e.top}},O=()=>{f.value&&v()},x=e=>{r.forEach((n,a)=>{a===e?(v(),n.toggle()):n.state.showPopup&&n.toggle(!1,{immediate:!0})})},m=(e,n)=>{const{showPopup:a}=e.state,{disabled:i,titleClass:u}=e;return s("div",{id:`${d}-${n}`,role:"button",tabindex:i?void 0:0,class:[C("item",{disabled:i}),{[G]:!i}],onClick:()=>{i||x(n)}},[s("span",{class:[C("title",{down:a===(o.direction==="down"),active:a}),u],style:{color:a?o.activeColor:""}},[s("div",{class:"van-ellipsis"},[e.renderTitle()])])])};return y({id:d,props:o,offset:p}),j(t,k),B("scroll",O,{target:b}),()=>{var e;return s("div",{ref:t,class:C()},[s("div",{ref:l,style:g.value,class:C("bar",{opened:f.value})},[r.map(m)]),(e=c.default)==null?void 0:e.call(c)])}}});const[re,h]=$("dropdown-item"),ie={title:String,options:F(),disabled:Boolean,teleport:[String,Object],lazyRender:P,modelValue:V,titleClass:V};var ce=z({name:re,props:ie,emits:["open","opened","close","closed","change","update:modelValue"],setup(o,{emit:c,slots:d}){const t=J({showPopup:!1,transition:!0,showWrapper:!1}),{parent:l,index:p}=L(A);if(!l){console.error("[Vant] <DropdownItem> must be a child component of <DropdownMenu>.");return}const r=e=>()=>c(e),y=r("open"),b=r("close"),f=r("opened"),g=()=>{t.showWrapper=!1,c("closed")},k=e=>{o.teleport&&e.stopPropagation()},v=(e=!t.showPopup,n={})=>{e!==t.showPopup&&(t.showPopup=e,t.transition=!n.immediate,e&&(t.showWrapper=!0))},O=()=>{if(d.title)return d.title();if(o.title)return o.title;const e=o.options.find(n=>n.value===o.modelValue);return e?e.text:""},x=e=>{const{activeColor:n}=l.props,a=e.value===o.modelValue,i=()=>{t.showPopup=!1,e.value!==o.modelValue&&(c("update:modelValue",e.value),c("change",e.value))},u=()=>{if(a)return s(te,{class:h("icon"),color:n,name:"success"},null)};return s(ne,{role:"menuitem",key:e.value,icon:e.icon,title:e.text,class:h("option",{active:a}),style:{color:a?n:""},tabindex:a?0:-1,clickable:!0,onClick:i},{value:u})},m=()=>{const{offset:e}=l,{zIndex:n,overlay:a,duration:i,direction:u,closeOnClickOverlay:R}=l.props,I=q(n);return u==="down"?I.top=`${e.value}px`:I.bottom=`${e.value}px`,Q(s("div",{style:I,class:h([u]),onClick:k},[s(oe,{show:t.showPopup,"onUpdate:show":w=>t.showPopup=w,role:"menu",class:h("content"),overlay:a,position:u==="down"?"top":"bottom",duration:t.transition?i:0,lazyRender:o.lazyRender,overlayStyle:{position:"absolute"},"aria-labelledby":`${l.id}-${p.value}`,closeOnClickOverlay:R,onOpen:y,onClose:b,onOpened:f,onClosed:g},{default:()=>{var w;return[o.options.map(x),(w=d.default)==null?void 0:w.call(d)]}})]),[[ee,t.showWrapper]])};return X({state:t,toggle:v,renderTitle:O}),()=>o.teleport?s(Y,{to:o.teleport},{default:()=>[m()]}):m()}});const fe=E(ce),ve=E(le);export{ve as D,fe as a};
|