index.b1f8d369.js 3.4 KB

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