api-client/components/ui/tabs.vue

112 lines
1.9 KiB
Vue
Raw Normal View History

2020-03-07 13:10:37 +00:00
<template>
<div class="tabs-wrapper">
<div class="tabs">
<ul>
<li
v-for="(tab, index) in tabs"
:class="{ 'is-active': tab.isActive }"
:key="index"
:tabindex="0"
@keyup.enter="selectTab(tab)"
>
2020-03-08 16:22:04 +00:00
<a :href="tab.href" @click="selectTab(tab)">
<i v-if="tab.icon" class="material-icons">
{{ tab.icon }}
</i>
<span v-if="tab.label">{{ tab.label }}</span>
</a>
2020-03-07 13:10:37 +00:00
</li>
</ul>
</div>
<div class="tabs-details">
<slot></slot>
</div>
</div>
</template>
<style scoped lang="scss">
.tabs-wrapper {
2020-09-22 17:06:37 +00:00
@apply flex;
@apply flex-col;
@apply flex-no-wrap;
@apply flex-1;
2020-03-07 13:10:37 +00:00
.tabs {
2020-09-22 17:06:37 +00:00
@apply scrolling-touch;
@apply flex;
@apply whitespace-no-wrap;
@apply overflow-auto;
2020-03-07 13:10:37 +00:00
ul {
2020-09-22 17:06:37 +00:00
@apply flex;
@apply w-0;
2020-03-07 13:10:37 +00:00
}
li {
2020-09-22 17:06:37 +00:00
@apply inline-flex;
@apply outline-none;
@apply border-none;
2020-03-07 13:10:37 +00:00
a {
2020-09-22 17:06:37 +00:00
@apply flex;
@apply items-center;
@apply justify-center;
@apply py-2;
@apply px-4;
@apply text-fgLightColor;
@apply text-sm;
@apply rounded-lg;
@apply cursor-pointer;
2020-03-07 13:10:37 +00:00
2020-03-08 16:22:04 +00:00
.material-icons {
2020-09-22 17:06:37 +00:00
@apply m-4;
2020-03-08 16:22:04 +00:00
}
2020-03-07 13:10:37 +00:00
&:hover {
2020-09-22 17:06:37 +00:00
@apply text-fgColor;
2020-03-07 13:10:37 +00:00
}
}
&:focus a {
2020-09-22 17:06:37 +00:00
@apply text-fgColor;
}
2020-03-07 13:10:37 +00:00
&.is-active a {
2020-09-22 17:06:37 +00:00
@apply bg-brdColor;
@apply text-fgColor;
2020-03-07 13:10:37 +00:00
}
}
}
}
@media (max-width: 768px) {
ul,
ol {
2020-09-22 17:06:37 +00:00
@apply flex-row;
@apply flex-no-wrap;
2020-03-07 13:10:37 +00:00
}
}
</style>
<script>
export default {
data() {
return {
tabs: [],
}
},
created() {
this.tabs = this.$children
},
methods: {
2020-03-08 16:22:04 +00:00
selectTab({ id }) {
2020-06-19 06:56:04 +00:00
this.tabs.forEach((tab) => {
2020-03-08 16:22:04 +00:00
tab.isActive = tab.id == id
2020-03-07 13:10:37 +00:00
})
},
},
}
</script>