Created
November 13, 2017 09:33
-
-
Save blocka/83637959e1303673dc0af9ae9129fcbb to your computer and use it in GitHub Desktop.
Simple, flexible tabs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<Tabs initialTab="login"> | |
<TabNav tabId="login"> | |
<template scope="{active, selectTab}"> | |
<a>Login</a> | |
</template> | |
</TabNav> | |
<TabNav tabId="register"> | |
<template scope="{active, selectTab}"> | |
<a>Registration</a> | |
</template> | |
</TabNav> | |
<TabNav tabId="forgot"> | |
<template scope="{active, selectTab}"> | |
<a>Forgot Password</a> | |
</template> | |
</TabNav> | |
<TabPanel tabId="login"> | |
Login Panel | |
</TabPanel> | |
<TabPanel tabId="register"> | |
Register Panel | |
</TabPanel> | |
<TabPanel tabId="forgot"> | |
Forgot Password panel | |
</TabPanel> | |
</Tabs> | |
</template> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Tabs from './Tabs'; | |
import TabNav from './TabNav'; | |
import TabPanel from './TabPanel'; | |
export { Tabs, TabNav, TabPanel }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default { | |
props: ['tabId'], | |
inject: ['tabs'], | |
render (h) { | |
if (this.tabId !== this.tabs.tabData.activeTab) { | |
return null; | |
} | |
const vnodes = this.$slots.default; | |
const vnode = vnodes.length > 1 | |
? h('div', [vnodes]) | |
: vnodes[0]; | |
return vnode; | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default { | |
props: ['initialTab'], | |
data () { | |
return { | |
tabData: { | |
activeTab: this.initialTab | |
} | |
}; | |
}, | |
provide () { | |
return { | |
tabs: { | |
selectTab: this.selectTab, | |
tabData: this.tabData | |
} | |
}; | |
}, | |
methods: { | |
selectTab (tab) { | |
this.tabData.activeTab = tab; | |
} | |
}, | |
render (h) { | |
return h('div', [this.$slots.default]); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment