UNPKG

vexip-ui

Version:

A Vue 3 UI library, Highly customizability, full TypeScript, performance pretty good

3 lines (2 loc) 1.82 kB
"use strict";const e=require("vue"),v=require("@vexip-ui/config"),C=require("./props.cjs"),c=require("./symbol.cjs"),y=["href","title"],A=e.defineComponent({name:"AnchorLink",__name:"anchor-link",props:C.anchorLinkProps,setup(m){const s=m,t=e.inject(c.ANCHOR_STATE,null),o=e.inject(c.LINK_STATE,null),l=v.useNameHelper("anchor"),a=e.ref(o!=null&&o.indent?(o==null?void 0:o.indent)+1:1),u=e.ref(!1),d=e.ref(),i=e.reactive({el:d,to:e.toRef(s,"to"),active:u,indent:a}),h=e.computed(()=>({[l.be("link")]:!0,[l.bem("link","active")]:i.active})),k=e.computed(()=>({paddingInlineStart:`${c.baseIndentWidth*a.value}px`}));e.provide(c.LINK_STATE,i),t&&(e.watch(()=>t.currentActive,n=>{u.value=n===s.to}),e.onMounted(()=>{t.increaseLink(i)}),e.onBeforeUnmount(()=>{t.decreaseLink(i)}));function p(){return t&&t.handleActive(s.to),!1}return(n,B)=>{const f=e.resolveComponent("AnchorLink",!0);return e.openBlock(),e.createElementBlock("li",{class:e.normalizeClass(e.unref(l).be("item"))},[e.createElementVNode("a",{ref_key:"link",ref:d,class:e.normalizeClass(h.value),href:n.to,style:e.normalizeStyle(k.value),title:n.title,onClick:e.withModifiers(p,["prevent"])},[e.renderSlot(n.$slots,"default")],14,y),n.$slots.group||n.children&&n.children.length?(e.openBlock(),e.createElementBlock("ul",{key:0,class:e.normalizeClass(e.unref(l).be("list"))},[e.renderSlot(n.$slots,"group",{},()=>[n.children&&n.children.length?(e.openBlock(!0),e.createElementBlock(e.Fragment,{key:0},e.renderList(n.children,r=>(e.openBlock(),e.createBlock(f,{key:r.to,to:r.to,title:r.title,children:r.children},{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(r.label),1)]),_:2},1032,["to","title","children"]))),128)):e.createCommentVNode("",!0)])],2)):e.createCommentVNode("",!0)],2)}}});module.exports=A; //# sourceMappingURL=anchor-link.vue2.cjs.map