index.63a4a300.js 3.7 KB

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