Tab.vue 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <template>
  2. <div v-show="active" class="flex flex-col flex-1">
  3. <slot></slot>
  4. </div>
  5. </template>
  6. <script setup lang="ts">
  7. import {
  8. onMounted,
  9. onBeforeUnmount,
  10. inject,
  11. computed,
  12. watch,
  13. } from "@nuxtjs/composition-api"
  14. import { TabMeta, TabProvider } from "./Tabs.vue"
  15. const props = defineProps({
  16. label: { type: String, default: null },
  17. info: { type: String, default: null },
  18. indicator: { type: Boolean, default: false },
  19. icon: { type: String, default: null },
  20. id: { type: String, default: null, required: true },
  21. selected: {
  22. type: Boolean,
  23. default: false,
  24. },
  25. })
  26. const tabMeta = computed<TabMeta>(() => ({
  27. icon: props.icon,
  28. indicator: props.indicator,
  29. info: props.info,
  30. label: props.label,
  31. }))
  32. const { activeTabID, addTabEntry, updateTabEntry, removeTabEntry } =
  33. inject<TabProvider>("tabs-system")!
  34. const active = computed(() => activeTabID.value === props.id)
  35. onMounted(() => {
  36. addTabEntry(props.id, tabMeta.value)
  37. })
  38. watch(tabMeta, (newMeta) => {
  39. updateTabEntry(props.id, newMeta)
  40. })
  41. onBeforeUnmount(() => {
  42. removeTabEntry(props.id)
  43. })
  44. </script>