ant-design-x-vue-next
Version:
Ant Design X for Vue — community continuation aligned with @ant-design/x
2 lines (1 loc) • 3.89 kB
JavaScript
;Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const s=require("vue"),Q=require("../chunks/helper-chunk.js"),i=require("../chunks/module-chunk.js");require("../x-provider/index.js");const U=require("../_util/hooks/use-x-component-config.js"),Y=require("./style/index.js"),V=require("../_util/hooks/use-state.js"),q=require("ant-design-vue"),Z=require("./useActive.js"),_=require("../x-provider/hooks/use-x-provider-context.js"),ee=s.defineComponent({name:"AXSuggestion",inheritAttrs:!1,__name:"Suggestion",props:s.mergeDefaults({prefixCls:null,className:null,rootClassName:null,style:null,children:{type:Function},open:{type:Boolean},onOpenChange:{type:Function},items:{type:Function},onSelect:{type:Function},block:{type:Boolean},styles:null,classNames:null,getPopupContainer:{type:Function}},{open:!1,styles:()=>({}),classNames:()=>({})}),setup(t){const w=Q.createPropsRestProxy(t,["prefixCls","className","rootClassName","style","children","open","onOpenChange","items","onSelect","block","styles","classNames","getPopupContainer"]);s.toRef(t,"prefixCls");const D=s.useAttrs(),g=s.useSlots(),{direction:A,getPrefixCls:F}=_.default(),l=s.computed(()=>F("suggestion",t.prefixCls)),r=`${l.value}-item`,m=s.computed(()=>A.value==="rtl"),o=U.default("suggestion"),p=s.ref(),[R,h,C]=Y.default(l),{width:y}=i.useElementSize(p),$=s.computed(()=>{var n;const e={...((n=o.value.styles)==null?void 0:n.popup)||{},...t.styles.popup||{}};return t.block&&y.value?{...e,width:`${y.value}px`}:Object.keys(e).length?e:void 0}),N=s.computed(()=>{var e;return i.classnames(t.rootClassName,t.className,(e=o.value.classNames)==null?void 0:e.root,t.classNames.root,l.value,h.value,C,{[`${l.value}-block`]:t.block})}),L=s.computed(()=>{var e;return i.classnames(l.value,t.rootClassName,(e=o.value.classNames)==null?void 0:e.content,t.classNames.content,`${l.value}-content`,h.value,C)}),T=s.computed(()=>{var e;return{...((e=o.value.styles)==null?void 0:e.content)||{},...t.styles.content}}),X=s.computed(()=>{var e;return i.classnames(N.value,(e=o.value.classNames)==null?void 0:e.popup,t.classNames.popup)}),j=s.computed(()=>{var e;return{...o.value.style,...((e=o.value.styles)==null?void 0:e.root)||{},...t.styles.root,...t.style}}),[d,S]=V.default(t.open);s.watch(()=>t.open,e=>{S(e)});const[B,I]=V.default(),u=e=>{var n;S(e),(n=t.onOpenChange)==null||n.call(t,e)},M=e=>{e===!1?u(!1):(I(e),u(!0))},P=()=>{u(!1)},v=s.computed(()=>typeof t.items=="function"?t.items(B.value):t.items);function z(e,n){const a=[];let f=e;for(const k of n){const c=f.find(O=>O.value===k);if(!c)break;a.push(c),f=c.children||[]}return a}function x(e){return e.map(n=>{var a;return{value:n.value,icon:n.icon,extra:n.extra,label:s.createVNode(q.Flex,{class:r},{default:()=>[n.icon?s.createVNode("div",{class:`${r}-icon`},[n.icon]):null,n.label,n.extra?s.createVNode("div",{class:`${r}-extra`},[n.extra]):null]}),children:(a=n.children)!=null&&a.length?x(n.children):void 0}})}const E=s.computed(()=>x(v.value||[])),b=e=>{const n=e||[];t.onSelect&&t.onSelect(n[n.length-1],z(v.value||[],n)),u(!1)},[K,W]=Z.default(v,d,m,b,P),G=s.computed(()=>{var n;const e={onTrigger:M,onKeyDown:W,open:d.value};return g.default?g.default(e):(n=t.children)==null?void 0:n.call(t,e)}),H=s.computed(()=>{const e=D,{class:n,style:a,open:f,options:k,value:c,multiple:O,onChange:te,onDropdownVisibleChange:ne,onOpenChange:se,placement:oe,getPopupContainer:le,...J}=e;return{...J,...w}});return()=>R(s.createVNode(q.Cascader,s.mergeProps(H.value,{options:E.value,open:d.value,value:K.value,placement:m.value?"topRight":"topLeft",onDropdownVisibleChange:e=>{e||P()},popupClassName:X.value,onChange:b,dropdownStyle:$.value,getPopupContainer:t.getPopupContainer,class:N.value,style:j.value}),{default:()=>s.createVNode("div",{ref:p,class:L.value,style:T.value},[G.value])}))}});exports.default=ee;