Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Tabs.vue « Components « vue « src - github.com/marius-wieschollek/passwords-webextension.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 797b10023362e02167b1ba061df2b2d08b60d4b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<template>
    <div class="tab-container">
        <div class="tabs">
            <div :key="name"
                 v-for="(tab, name) in tabs"
                 @click="setActive(name)"
                 :class="{ active: isActive(name) }"
                 class="tab">
                <div>
                    <icon :icon="tab.icon" class="icon" v-if="tab.icon" font="solid"/>
                    <translate :say="tab.label" class="label" v-if="tab.label"/>
                </div>
            </div>
        </div>
        <div class="tab-content">
            <div v-for="(meta, name) in tabs"
                 :key="name"
                 :class="`tab-content-${name}`"
                 :style="{display: name===tab ? 'block':'none'}">
                <keep-alive>
                    <slot :name="name"/>
                </keep-alive>
            </div>
        </div>
    </div>
</template>

<script>
    import Icon from '@vue/Components/Icon';
    import Translate from '@vue/Components/Translate';

    export default {
        components: {Icon, Translate},

        props: {
            tabs      : {
                type: Object
            },
            initialTab: {
                type   : String,
                default: null
            }
        },

        data() {
            let tab = this.initialTab === null ? Object.keys(this.tabs)[0]:this.initialTab;

            return {tab};
        },

        methods: {
            isActive(tab) {
                return tab === this.tab;
            },
            setActive(tab) {
                if(typeof this.tabs[tab] !== 'string' && this.tabs[tab].action) {
                    this.tabs[tab].action();
                    return;
                }
                this.tab = tab;
                this.$emit('switch', {tab});
            }
        },

        watch: {
            tabs(value) {
                if(!value.hasOwnProperty(this.tab)) {
                    this.tab = Object.keys(value)[0];
                }
            }
        }
    };
</script>

<style lang="scss">
    .tab-container {
        .tabs {
            display  : flex;
            overflow : hidden;
        }

        .tab {
            padding          : 1rem;
            cursor           : pointer;
            flex             : 1 1 auto;
            text-align       : center;
            display          : flex;
            background-color : var(--element-bg-color);
            color            : var(--element-fg-color);
            box-shadow       : var(--tab-border);
            white-space      : nowrap;
            transition       : var(--element-transition);

            &:hover {
                background-color : var(--element-hover-bg-color);
                color            : var(--element-hover-fg-color);
                box-shadow       : var(--tab-border);
                transition       : var(--element-transition);
            }

            .icon {
                width        : 1rem;
                height       : 1rem;
                margin-right : .5rem;
            }

            &.active {
                background-color : var(--element-active-bg-color);
                color            : var(--element-active-fg-color);
                box-shadow       : var(--tab-active-border);

                &:hover {
                    background-color : var(--element-active-hover-bg-color);
                    color            : var(--element-active-hover-fg-color);
                }
            }
        }
    }
</style>