import Vue from 'vue' import { VNode } from 'vue/types/umd' import './tabs.scss' import './tabs-standard.scss' import './tabs-rounded.scss' interface Tab { title: string active: boolean index: number keep: boolean } export default Vue.extend({ name: 'rd-tabs', props: { type: {type: String, default: 'standard'}, active: {type: Number, default: 0}, label: {type: String, default: 'Tabs'}, }, created() { this.activeTab = this.active }, data: () => ({ activeTab: 0 }), methods: { handleSelect(tab: Tab) { this.activeTab = tab.index }, handleKeypress(ev: KeyboardEvent, tab: Tab) { if (ev.code == 'Space') this.handleSelect(tab) }, tabs(): Array { const tabs = (this.$slots.default?.filter(s => s.componentOptions) || []) return tabs } }, render(h) { // TODO refactor const activeNode = this.tabs()[this.activeTab] this.tabs().forEach((t, i) => t.key = i.toString()) const activeTab = activeNode.componentOptions?.propsData as any as Tab return (
{this.tabs().map( (node, i) => { const tab = node.componentOptions?.propsData as any as Tab return ( ) })}
{ activeTab.keep != false ? {activeNode} : activeNode }
) } })