Files
hoppscotch/components/smart/Tabs.vue
2021-07-06 18:00:39 +00:00

104 lines
1.9 KiB
Vue

<template>
<div class="tabs-wrapper">
<div class="tabs" :class="styles">
<div class="flex w-0">
<div class="inline-flex">
<button
v-for="(tab, index) in tabs"
:key="index"
class="tab"
:class="{ 'is-active': tab.isActive }"
:tabindex="0"
@keyup.enter="selectTab(tab)"
@click="selectTab(tab)"
>
<i v-if="tab.icon" class="material-icons">
{{ tab.icon }}
</i>
<span v-if="tab.label">{{ tab.label }}</span>
</button>
</div>
</div>
</div>
<div class="tabs-details">
<slot></slot>
</div>
</div>
</template>
<script>
export default {
props: {
styles: {
type: String,
default: "",
},
},
data() {
return {
tabs: [],
}
},
created() {
this.tabs = this.$children
},
methods: {
selectTab({ id }) {
this.tabs.forEach((tab) => {
tab.isActive = tab.id === id
})
this.$emit("tab-changed", id)
},
},
}
</script>
<style scoped lang="scss">
.tabs-wrapper {
@apply flex;
@apply flex-col;
@apply flex-nowrap;
@apply flex-1;
.tabs {
@apply flex;
@apply whitespace-nowrap;
@apply overflow-auto;
@apply mt-4;
.tab {
@apply flex;
@apply items-center;
@apply justify-center;
@apply p-3;
@apply text-secondaryLight;
@apply font-semibold;
@apply cursor-pointer;
@apply transition;
@apply border-b-2;
@apply border-transparent;
@apply rounded-t-lg;
.material-icons {
@apply mr-4;
}
&:hover {
@apply text-secondaryDark;
}
&:focus {
@apply text-secondaryDark;
@apply outline-none;
}
&.is-active {
@apply text-accent;
@apply border-accent;
}
}
}
}
</style>