hongluan-ui
Version:
Hongluan Component Library for Vue 3
61 lines (58 loc) • 2.01 kB
JavaScript
import { defineComponent, ref, inject, computed, onMounted, openBlock, createElementBlock, normalizeClass, createElementVNode, renderSlot, createTextVNode, toDisplayString, createCommentVNode } from 'vue';
import '../../../hooks/index.mjs';
import { anchorInjectionKey } from './types.mjs';
import _export_sfc from '../../../_virtual/plugin-vue_export-helper.mjs';
import { useNamespace } from '../../../hooks/use-namespace/index.mjs';
const _sfc_main = defineComponent({
name: "AnchorLink",
props: {
title: String,
href: String
},
setup(props) {
const { namespace } = useNamespace("anchor-link");
const linkRef = ref();
const context = inject(anchorInjectionKey, void 0);
const cls = computed(() => [
namespace.value,
{
[`is-active`]: (context == null ? void 0 : context.currentLink) === props.href
}
]);
const handleClick = (e) => context == null ? void 0 : context.handleClick(e, props.href);
onMounted(() => {
if (props.href && linkRef.value) {
context == null ? void 0 : context.addLink(props.href, linkRef.value);
}
});
return {
cls,
linkRef,
handleClick
};
}
});
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
return openBlock(), createElementBlock("div", {
ref: "linkRef",
class: normalizeClass(_ctx.cls)
}, [
createElementVNode("a", {
href: _ctx.href,
onClick: _ctx.handleClick
}, [
renderSlot(_ctx.$slots, "default", {}, () => [
createTextVNode(toDisplayString(_ctx.title), 1)
])
], 8, ["href", "onClick"]),
_ctx.$slots.sublist ? (openBlock(), createElementBlock("div", {
key: 0,
class: normalizeClass(`anchor-sublist`)
}, [
renderSlot(_ctx.$slots, "sublist")
])) : createCommentVNode("v-if", true)
], 2);
}
var AnchorLink = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]);
export { AnchorLink as default };
//# sourceMappingURL=anchor-link.mjs.map