Files
mixtape/zero.Backoffice.UI/app/components/ui-tabs.vue
T

235 lines
4.6 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">
2021-12-21 13:58:48 +01:00
<button type="button" v-for="(tab, index) in tabs" class="ui-tabs-list-item" :key="index"
:class="{ 'is-active': tab.active, 'has-errors': tab.hasErrors }"
:disabled="tab.disabled"
2021-12-23 14:39:00 +01:00
:aria-selected="tab.active ? true : null"
2021-12-21 13:58:48 +01:00
role="tab"
@click="select(index)">
<ui-icon v-if="tab.hasErrors" class="ui-tabs-list-item-error" :size="16" symbol="fth-alert-circle"></ui-icon>
2021-03-23 10:30:14 +01:00
<span v-localize="tab.label"></span>
2020-10-01 16:06:44 +02:00
<i v-if="tab.countOutput > 0" class="ui-tabs-list-item-count">{{tab.countOutput}}</i>
2020-04-08 13:52:45 +02:00
</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-10-18 23:47:59 +02:00
mounted()
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
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: {
2021-12-07 01:11:18 +01:00
register(tab)
{
this.tabs.push(tab);
},
unregister(tab)
{
this.tabs = this.tabs.splice(this.tabs.indexOf(tab), 1);
},
2020-04-08 13:52:45 +02:00
select(index, ev)
{
if (ev)
{
ev.preventDefault();
}
const currentTab = this.tabs[index];
2021-03-23 10:30:14 +01:00
if (!currentTab || currentTab.disabled)
2020-04-08 13:52:45 +02:00
{
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-06-23 16:08:26 +02:00
}
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
}
2020-05-06 15:49:21 +02:00
.ui-header-bar + .ui-tabs > .ui-tabs-list
{
padding-top: 0;
}
2020-04-08 13:52:45 +02:00
.ui-tabs-list
{
padding: var(--padding) var(--padding) 0;
margin-bottom: calc(var(--padding) * -1);
height: 58px;
display: flex;
2020-04-08 13:52:45 +02:00
}
2020-09-05 17:35:47 +02:00
/*.ui-tabs-items > .ui-tab:first-child.ui-box:not(.is-blank)
{
border-top-left-radius: 0;
2020-09-05 17:35:47 +02:00
}*/
2021-09-16 10:25:56 +02:00
.ui-tabs-items
{
position: relative;
z-index: 1;
}
2020-04-08 13:52:45 +02:00
.ui-tabs-list-item
{
display: inline-flex;
align-items: center;
2021-04-22 16:04:05 +02:00
height: 58px;
2021-04-22 14:48:10 +02:00
padding: 0 var(--padding);
2020-04-08 13:52:45 +02:00
font-size: var(--font-size);
color: var(--color-text);
2020-04-08 13:07:15 +02:00
position: relative;
2020-04-08 13:52:45 +02:00
transition: color 0.2s ease;
2021-10-11 13:58:14 +02:00
border-radius: var(--radius-inner) var(--radius-inner) 0 0;
background: var(--color-box-light);
& + .ui-tabs-list-item
{
margin-left: 4px;
}
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
{
color: var(--color-text);
2020-04-08 13:07:15 +02:00
}
2020-04-08 13:52:45 +02:00
&[disabled]
{
cursor: default;
color: var(--color-text-dim);
2020-04-08 13:52:45 +02:00
}
2020-04-08 13:07:15 +02:00
2020-04-08 13:52:45 +02:00
&.is-active
{
font-weight: 700;
color: var(--color-text);
background: var(--color-box);
2020-09-09 19:06:37 +02:00
box-shadow: var(--shadow-short);
.ui-tabs-list-item-count
{
background: var(--color-box-light);
}
2020-04-08 13:52:45 +02:00
}
2020-06-23 16:08:26 +02:00
&.has-errors
{
color: var(--color-accent-error);
&.is-active
{
color: var(--color-accent-error);
2020-09-05 17:35:47 +02:00
&:before
2020-06-23 16:08:26 +02:00
{
background: var(--color-accent-error);
}
}
}
2020-09-05 17:35:47 +02:00
2021-09-16 10:25:56 +02:00
&:first-child:after
2020-09-05 17:35:47 +02:00
{
content: '';
position: absolute;
left: 0;
2021-09-16 10:25:56 +02:00
width: 30px;
bottom: -30px;
height: 30px;
background: var(--color-box-light);
z-index: 0;
2020-09-05 17:35:47 +02:00
}
2020-04-08 13:07:15 +02:00
}
.ui-tabs-list-item-count
{
font-style: normal;
font-size: 12px;
overflow: hidden;
float: right;
padding: 2px 6px;
background: var(--color-box);
border-radius: 10px;
margin-left: 8px;
margin-right: -4px;
margin-top: -1px;
font-weight: bold;
color: var(--color-text);
}
2020-06-23 16:08:26 +02:00
.ui-tabs-list-item-error
{
display: inline-block;
float: left;
margin-right: 6px;
margin-left: -4px;
position: relative;
margin-top: -4px;
top: 1px;
}
2021-09-16 10:25:56 +02:00
.ui-tab.ui-box:first-child
{
border-top-left-radius: 0;
}
2020-04-08 13:07:15 +02:00
</style>