Newer
Older
vmk-ui-kit / src / vue / components / GnTabPanel.js
@Eugene Sukhodolskiy Eugene Sukhodolskiy 2 days ago 691 bytes Add Tabs, Avatar, Chip, and Progress components
/**
 * GnTabPanel - Panel container for a tab. Must be used inside GnTabs slots.panels.
 */

import { defineComponent, h, inject, onMounted } from "vue";
import { tabsKey } from "./GnTabs.js";

export default defineComponent({
	name: "GnTabPanel",
	props: {
		name: { type: [String, Number], required: true }
	},
	setup(props, { slots }) {
		const tabs = inject(tabsKey, null);

		onMounted(() => {
			tabs?.registerPanel(props.name);
		});

		return () => {
			if (!tabs) return null;
			const active = tabs.isActive(props.name);

			return h("div", {
				class: ["tab-panel", { "tab-panel-active": active }],
				role: "tabpanel",
				hidden: !active
			}, slots.default?.());
		};
	}
});