Files
mixtape/zero.Web/App/Components/Tabs/tabs.vue
T

158 lines
2.9 KiB
Vue
Raw Normal View History

2020-04-08 13:07:15 +02:00
<template>
2020-04-08 13:52:45 +02:00
<div class="ui-tabs">
<div role="tablist" class="ui-tabs-list">
<button type="button" v-for="(tab, index) in tabs" class="ui-tabs-list-item" :key="index" :class="{ 'is-active': tab.active }" :disabled="tab.disabled"
:aria-selected="tab.active" role="tab" @click="select(index)">
{{ tab.label | localize }}
</button>
</div>
<div class="ui-tabs-items">
<slot />
2020-04-08 13:07:15 +02:00
</div>
</div>
</template>
<script>
export default {
2020-04-08 13:52:45 +02:00
name: 'uiTabs',
2020-04-08 13:07:15 +02:00
props: {
2020-04-08 15:16:05 +02:00
cache: {
type: String
},
active: {
type: Number,
default: 0
2020-04-08 13:52:45 +02:00
}
},
2020-04-08 15:16:05 +02:00
data: () => ({
storageKey: null,
tabs: []
}),
2020-04-08 13:52:45 +02:00
created()
2020-04-08 13:07:15 +02:00
{
2020-04-08 15:16:05 +02:00
this.cacheKey = this.cache ? `zero.ui-tabs.cache.${this.cache}` : null;
2020-04-08 13:52:45 +02:00
this.tabs = this.$children;
},
mounted()
{
2020-04-08 15:16:05 +02:00
if (this.cache)
{
const cachedActiveTab = localStorage.getItem(this.cacheKey);
if (cachedActiveTab !== null)
{
this.select(+cachedActiveTab);
return;
}
}
2020-04-08 13:52:45 +02:00
this.select(this.active);
2020-04-08 13:07:15 +02:00
},
methods: {
2020-04-08 13:52:45 +02:00
select(index, ev)
{
if (ev)
{
ev.preventDefault();
}
const currentTab = this.tabs[index];
if (currentTab.disabled)
{
return;
}
this.tabs.forEach((tab, tabIndex) =>
{
tab.active = index === tabIndex;
});
2020-04-08 15:16:05 +02:00
if (this.cache)
{
localStorage.setItem(this.cacheKey, index);
}
2020-04-08 13:52:45 +02:00
//this.$emit('changed', { tab: selectedTab });
//this.activeTabHash = selectedTab.hash;
//this.activeTabIndex = this.getTabIndex(selectedTabHash);
//this.lastActiveTabHash = this.activeTabHash = selectedTab.hash;
//expiringStorage.set(this.storageKey, selectedTab.hash, this.cacheLifetime);
},
2020-04-08 13:07:15 +02:00
}
}
</script>
2020-04-08 13:52:45 +02:00
<style lang="scss">
.ui-tabs
2020-04-08 13:07:15 +02:00
{
2020-04-08 13:52:45 +02:00
}
.ui-tabs-list
{
border-bottom: 1px solid var(--color-line);
padding: 0 10px;
}
.ui-tabs-list-item
{
display: inline-flex;
align-items: center;
height: 60px;
padding: 0 20px;
margin: 0;
font-size: var(--font-size);
color: var(--color-fg-light);
2020-04-08 13:07:15 +02:00
position: relative;
2020-04-08 13:52:45 +02:00
overflow: hidden;
transition: color 0.2s ease;
2020-04-08 13:07:15 +02:00
2020-04-08 13:52:45 +02:00
&:hover
2020-04-08 13:07:15 +02:00
{
2020-04-08 13:52:45 +02:00
color: var(--color-fg);
2020-04-08 13:07:15 +02:00
}
2020-04-08 13:52:45 +02:00
&:before
2020-04-08 13:07:15 +02:00
{
2020-04-08 13:52:45 +02:00
display: none;
2020-04-08 13:07:15 +02:00
}
2020-04-08 13:52:45 +02:00
&[disabled]
{
cursor: default;
color: var(--color-fg-light);
}
2020-04-08 13:07:15 +02:00
2020-04-08 13:52:45 +02:00
&:after
{
content: '';
height: 4px;
border-radius: 4px 4px 0 0;
background: var(--color-line);
position: absolute;
left: 18px;
right: 18px;
bottom: 0;
transform: translateY(5px) scaleX(0.5);
transition: transform 0.2s ease;
}
2020-04-08 13:07:15 +02:00
2020-04-08 13:52:45 +02:00
&.is-active
{
font-weight: 700;
color: var(--color-fg);
2020-04-08 13:07:15 +02:00
2020-04-08 13:52:45 +02:00
&:after
{
transform: translateY(0) scaleX(1);
}
}
2020-04-08 13:07:15 +02:00
}
</style>