UNPKG

@vuesax-alpha/nightly

Version:
67 lines (64 loc) 2.48 kB
import { defineComponent, inject, onBeforeUnmount, openBlock, createElementBlock, normalizeClass, unref, renderSlot, createTextVNode, toDisplayString } from 'vue'; import '../../../utils/index.mjs'; import '../../../hooks/index.mjs'; import { navbarRegisterContextKey, navbarGroupRegisterContextKey } from '../../../tokens/navbar.mjs'; import { navbarItemProps } from './navbar-item.mjs'; import _export_sfc from '../../../_virtual/plugin-vue_export-helper.mjs'; import { throwError } from '../../../utils/error.mjs'; import { useNamespace } from '../../../hooks/use-namespace/index.mjs'; const __default__ = defineComponent({ name: "VsNavbarItem" }); const _sfc_main = defineComponent({ ...__default__, props: navbarItemProps, setup(__props) { const props = __props; const navbarRegister = inject(navbarRegisterContextKey, void 0); const navbarGroupRegister = inject(navbarGroupRegisterContextKey, void 0); if (!navbarRegister) { throwError("navbar-item", "need to call inside navbar component"); } const { unregister, onClick, isActive } = navbarRegister(props.id); const navbarGroup = navbarGroupRegister == null ? void 0 : navbarGroupRegister(props.id); const ns = useNamespace("navbar-item"); const handleClickItem = (router) => { onClick(); if (props.to) { router.push(props.to); } else { if (props.link) { window.open(props.link.path, props.link.target); } } }; onBeforeUnmount(() => { unregister(); navbarGroup == null ? void 0 : navbarGroup.unregister(); }); return (_ctx, _cache) => { return openBlock(), createElementBlock( "button", { class: normalizeClass([unref(ns).b(), unref(ns).is("active", _ctx.active || unref(isActive))]), onClick: _cache[0] || (_cache[0] = ($event) => handleClickItem(_ctx.$router)) }, [ renderSlot(_ctx.$slots, "default", {}, () => { var _a; return [ createTextVNode( toDisplayString((_a = _ctx.link) == null ? void 0 : _a.text), 1 ) ]; }) ], 2 ); }; } }); var NavbarItem = /* @__PURE__ */ _export_sfc(_sfc_main, [["__file", "/home/runner/work/vuesax-alpha/vuesax-alpha/packages/components/navbar/src/navbar-item.vue"]]); export { NavbarItem as default }; //# sourceMappingURL=navbar-item2.mjs.map