api-client/components/smart/Tabs.vue

137 lines
2.5 KiB
Vue
Raw Normal View History

2020-03-07 13:10:37 +00:00
<template>
2021-07-08 07:30:41 +00:00
<div class="flex flex-col flex-nowrap flex-1">
<div class="tabs hide-scrollbar relative" :class="styles">
2021-07-03 13:14:58 +00:00
<div class="flex w-0">
<div class="inline-flex">
<button
v-for="(tab, index) in tabs"
2021-07-13 23:49:08 +00:00
:key="`tab-${index}`"
2021-07-03 13:14:58 +00:00
class="tab"
2021-07-07 23:28:42 +00:00
:class="{ active: tab.active }"
2021-07-03 13:14:58 +00:00
:tabindex="0"
@keyup.enter="selectTab(tab)"
@click="selectTab(tab)"
>
2020-03-08 16:22:04 +00:00
<i v-if="tab.icon" class="material-icons">
{{ tab.icon }}
</i>
<span v-if="tab.label">{{ tab.label }}</span>
2021-07-13 05:37:29 +00:00
<span v-if="tab.info" class="tab-info">
{{ tab.info }}
</span>
2021-07-03 13:14:58 +00:00
</button>
</div>
</div>
2020-03-07 13:10:37 +00:00
</div>
2021-07-30 19:21:41 +00:00
<slot></slot>
2021-07-03 13:14:58 +00:00
</div>
2020-03-07 13:10:37 +00:00
</template>
2021-05-18 09:27:29 +00:00
<script>
export default {
props: {
styles: {
type: String,
default: "",
},
},
data() {
return {
tabs: [],
}
},
created() {
this.tabs = this.$children
},
methods: {
selectTab({ id }) {
this.tabs.forEach((tab) => {
2021-07-07 23:28:42 +00:00
tab.active = tab.id === id
2021-05-18 09:27:29 +00:00
})
this.$emit("tab-changed", id)
},
},
}
</script>
2020-03-07 13:10:37 +00:00
<style scoped lang="scss">
2021-07-07 23:28:42 +00:00
.tabs {
2021-07-03 13:14:58 +00:00
@apply flex;
2021-07-07 23:28:42 +00:00
@apply whitespace-nowrap;
@apply overflow-auto;
@apply bg-primary;
2020-03-07 13:10:37 +00:00
2021-07-07 23:28:42 +00:00
&::after {
@apply absolute;
@apply inset-x-0;
@apply bottom-0;
@apply bg-dividerLight;
@apply z-1;
@apply h-0.5;
content: "";
}
.tab {
2021-07-20 10:29:30 +00:00
@apply relative;
2020-09-22 17:06:37 +00:00
@apply flex;
2021-07-07 23:28:42 +00:00
@apply items-center;
@apply justify-center;
@apply px-4 py-2;
2021-07-07 23:28:42 +00:00
@apply text-secondary;
@apply font-semibold;
@apply cursor-pointer;
@apply transition;
@apply hover:text-secondaryDark;
@apply focus:text-secondaryDark;
@apply focus:outline-none;
2020-03-07 13:10:37 +00:00
2021-07-13 05:37:29 +00:00
.tab-info {
@apply inline-flex;
@apply items-center;
@apply justify-center;
@apply w-5;
@apply h-4;
@apply ml-2;
@apply text-8px;
@apply border border-divider;
@apply font-mono;
@apply rounded;
@apply text-secondaryLight;
}
2021-07-07 23:28:42 +00:00
&::after {
@apply absolute;
@apply inset-x-0;
@apply bottom-0;
@apply bg-dividerLight;
@apply z-2;
@apply h-0.5;
2020-03-07 13:10:37 +00:00
2021-07-07 23:28:42 +00:00
content: "";
}
2020-03-07 13:10:37 +00:00
2021-07-07 23:28:42 +00:00
.material-icons {
@apply mr-4;
}
&.active {
@apply text-accent;
@apply border-accent;
2021-07-13 05:37:29 +00:00
.tab-info {
@apply text-secondary;
@apply border-dividerDark;
}
2021-07-07 23:28:42 +00:00
&::after {
@apply bg-accent;
2020-03-07 13:10:37 +00:00
}
}
}
}
</style>