@vuesax-alpha/nightly
Version:
A Component Library for Vue 3
101 lines (98 loc) • 3.28 kB
JavaScript
import { defineComponent, useSlots, inject, computed, openBlock, createElementBlock, normalizeClass, unref, renderSlot, createCommentVNode, createElementVNode, createVNode } from 'vue';
import '../../../hooks/index.mjs';
import '../../../tokens/index.mjs';
import '../../../utils/index.mjs';
import { IconArrow } from '../../icon/index.mjs';
import { sidebarItemProps } from './sidebar-item.mjs';
import _export_sfc from '../../../_virtual/plugin-vue_export-helper.mjs';
import { useNamespace } from '../../../hooks/use-namespace/index.mjs';
import { sidebarContextKey } from '../../../tokens/sidebar.mjs';
import { throwError } from '../../../utils/error.mjs';
const __default__ = defineComponent({
name: "VsSidebarItem"
});
const _sfc_main = defineComponent({
...__default__,
props: sidebarItemProps,
setup(__props) {
const props = __props;
const slots = useSlots();
const ns = useNamespace("sidebar-item");
const sidebar = inject(sidebarContextKey);
if (!sidebar) {
throwError("sidebar-item", "need to call inside the sidebar component");
}
const handleClickItem = (router) => {
if (props.id) {
sidebar.handleClickItem(props.id);
}
if (props.to) {
router.push(props.to);
} else if (props.href) {
window.open(props.href, props.target);
}
};
const itemKls = computed(() => [
ns.b(),
ns.is("active", props.active || sidebar.modelValue.value == props.id),
ns.is("has-icon", Boolean(slots.icon))
]);
return (_ctx, _cache) => {
return openBlock(), createElementBlock(
"button",
{
class: normalizeClass(itemKls.value),
onClick: _cache[0] || (_cache[0] = ($event) => handleClickItem(_ctx.$router))
},
[
_ctx.$slots.icon ? (openBlock(), createElementBlock(
"div",
{
key: 0,
class: normalizeClass(unref(ns).e("icon"))
},
[
renderSlot(_ctx.$slots, "icon")
],
2
)) : createCommentVNode("v-if", true),
createElementVNode(
"div",
{
class: normalizeClass(unref(ns).e("text"))
},
[
renderSlot(_ctx.$slots, "default")
],
2
),
createElementVNode(
"div",
{
class: normalizeClass(unref(ns).e("text-tooltip"))
},
[
renderSlot(_ctx.$slots, "default")
],
2
),
_ctx.$slots.arrow ? renderSlot(_ctx.$slots, "arrow", { key: 1 }) : _ctx.arrow ? (openBlock(), createElementBlock(
"div",
{
key: 2,
class: normalizeClass(unref(ns).e("arrow"))
},
[
createVNode(unref(IconArrow))
],
2
)) : createCommentVNode("v-if", true)
],
2
);
};
}
});
var SidebarItem = /* @__PURE__ */ _export_sfc(_sfc_main, [["__file", "/home/runner/work/vuesax-alpha/vuesax-alpha/packages/components/sidebar/src/sidebar-item.vue"]]);
export { SidebarItem as default };
//# sourceMappingURL=sidebar-item2.mjs.map