refactor: revamped tab system

This commit is contained in:
Andrew Bastin
2022-03-24 18:41:44 +05:30
parent 29d3f3cbe3
commit f3f4420d6d
2 changed files with 133 additions and 77 deletions

View File

@@ -4,31 +4,49 @@
</div>
</template>
<script>
import { defineComponent } from "@nuxtjs/composition-api"
<script setup lang="ts">
import {
onMounted,
onBeforeUnmount,
inject,
computed,
watch,
} from "@nuxtjs/composition-api"
import { TabMeta, TabProvider } from "./Tabs.vue"
export default defineComponent({
name: "SmartTab",
props: {
label: { type: String, default: null },
info: { type: String, default: null },
indicator: { type: Boolean, default: false },
icon: { type: String, default: null },
id: { type: String, default: null, required: true },
selected: {
type: Boolean,
default: false,
},
},
data() {
return {
active: false,
}
},
mounted() {
this.active = this.selected
const props = defineProps({
label: { type: String, default: null },
info: { type: String, default: null },
indicator: { type: Boolean, default: false },
icon: { type: String, default: null },
id: { type: String, default: null, required: true },
selected: {
type: Boolean,
default: false,
},
})
const tabMeta = computed<TabMeta>(() => ({
icon: props.icon,
indicator: props.indicator,
info: props.info,
label: props.label,
}))
const { activeTabID, addTabEntry, updateTabEntry, removeTabEntry } =
inject<TabProvider>("tabs-system")!
const active = computed(() => activeTabID.value === props.id)
onMounted(() => {
addTabEntry(props.id, tabMeta.value)
})
watch(tabMeta, (newMeta) => {
updateTabEntry(props.id, newMeta)
})
onBeforeUnmount(() => {
removeTabEntry(props.id)
})
</script>