From 476bf0afe1c890b0f08587b3942981c8c591c7be Mon Sep 17 00:00:00 2001 From: shpuld Date: Thu, 31 Jan 2019 17:00:31 +0200 Subject: Fix media timeline attachments being small by adding an option to not render background tabs in tab switcher --- src/components/tab_switcher/tab_switcher.js | 67 +++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/components/tab_switcher/tab_switcher.js (limited to 'src/components/tab_switcher/tab_switcher.js') diff --git a/src/components/tab_switcher/tab_switcher.js b/src/components/tab_switcher/tab_switcher.js new file mode 100644 index 00000000..f9c3f927 --- /dev/null +++ b/src/components/tab_switcher/tab_switcher.js @@ -0,0 +1,67 @@ +import Vue from 'vue' + +import './tab_switcher.scss' + +export default Vue.component('tab-switcher', { + name: 'TabSwitcher', + props: ['renderOnlyFocused'], + data () { + return { + active: this.$slots.default.findIndex(_ => _.tag) + } + }, + methods: { + activateTab (index) { + return () => { + this.active = index + } + } + }, + beforeUpdate () { + const currentSlot = this.$slots.default[this.active] + if (!currentSlot.tag) { + this.active = this.$slots.default.findIndex(_ => _.tag) + } + }, + render (h) { + const tabs = this.$slots.default + .map((slot, index) => { + if (!slot.tag) return + const classesTab = ['tab'] + const classesWrapper = ['tab-wrapper'] + + if (index === this.active) { + classesTab.push('active') + classesWrapper.push('active') + } + + return ( +
+ +
+ ) + }) + + const contents = this.$slots.default.map((slot, index) => { + if (!slot.tag) return + const active = index === this.active + if (this.renderOnlyFocused) { + return active + ?
{slot}
+ : + } + return
{slot}
+ }) + + return ( +
+
+ {tabs} +
+
+ {contents} +
+
+ ) + } +}) -- cgit v1.2.3-70-g09d2