hongluan-ui
Version:
Hongluan Component Library for Vue 3
62 lines (59 loc) • 1.99 kB
JavaScript
import { defineComponent, ref, getCurrentInstance, onMounted, inject, h, renderSlot } from 'vue';
import '../../../hooks/index.mjs';
import '../../../tokens/index.mjs';
import { breadcrumbItemProps } from './breadcrumb-item2.mjs';
import { useNamespace } from '../../../hooks/use-namespace/index.mjs';
import { BreadcrumbKey } from '../../../tokens/breadcrumb.mjs';
const _sfc_main = defineComponent({
name: "BreadcrumbItem",
props: breadcrumbItemProps,
setup(props) {
const { namespace } = useNamespace("breadcrumb-item");
const link = ref();
const instance = getCurrentInstance();
const router = instance.appContext.config.globalProperties.$router;
onMounted(() => {
var _a, _b;
(_a = link.value) == null ? void 0 : _a.setAttribute("role", "link");
(_b = link.value) == null ? void 0 : _b.addEventListener("click", () => {
if (!props.to || !router)
return;
props.replace ? router.replace(props.to) : router.push(props.to);
});
});
return {
namespace,
link
};
},
render() {
var _a;
const {
$slots,
namespace,
to
} = this;
const parent = inject(BreadcrumbKey);
const separator = parent == null ? void 0 : parent.separator;
return h("span", {
class: [namespace]
}, [
((_a = parent == null ? void 0 : parent.slots) == null ? void 0 : _a.icon) || $slots.icon ? h("span", {
class: "breadcrumb-separator"
}, [
$slots.icon ? renderSlot($slots, "icon", {}) : renderSlot(parent == null ? void 0 : parent.slots, "icon", {})
]) : h("span", {
class: "breadcrumb-separator",
role: "presentation",
innerHTML: separator
}, []),
h("span", {
ref: "link",
class: ["breadcrumb-inner", to ? "is-link" : ""],
role: "link"
}, [renderSlot($slots, "default", {})])
]);
}
});
export { _sfc_main as default };
//# sourceMappingURL=breadcrumb-item.mjs.map