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

Theming.vue « Options « Components « vue « src - github.com/marius-wieschollek/passwords-webextension.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4477459af617b79efd444c3ed4727fe60fbf1fae (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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<template>
    <div class="theming" v-if="theme">
        <div class="theme-settings">
            <div class="setting">
                <translate tag="label" for="theme-current" say="SettingsThemeId"/>
                <select-field id="theme-current" :options="list" v-model="themeId"/>
            </div>
            <custom-theme :theme="customTheme" v-if="customTheme && themeId === 'custom'"/>
        </div>
        <preview-theme :theme="theme"/>
    </div>
</template>

<script>
    import SelectField from '@vue/Components/Form/SelectField';
    import MessageService from '@js/Services/MessageService';
    import Translate from '@vue/Components/Translate';
    import ToastService from '@js/Services/ToastService';
    import PreviewTheme from '@vue/Components/Theming/PreviewTheme';
    import CustomTheme from '@vue/Components/Theming/CustomTheme';
    import ErrorManager from '@js/Manager/ErrorManager';

    export default {
        components: {CustomTheme, PreviewTheme, Translate, SelectField},

        data() {
            return {
                themeId: null,
                theme  : null,
                themes : []
            };
        },

        computed: {
            list() {
                let list = {};

                for(let theme of this.themes) list[theme.getId()] = theme.getLabel();

                return list;
            },
            customTheme() {
                for(let theme of this.themes) {
                    if(theme.getId() === 'custom') return theme;
                }
            }
        },

        async mounted() {
            let reply = await MessageService.send({type: 'theme.list'});
            this.themes = reply.getPayload();

            reply = await MessageService.send({type: 'setting.get', payload: 'theme.current'});
            this.themeId = reply.getPayload();

            this.setCurrentTheme(this.themeId);
        },

        methods: {
            setCurrentTheme(themeId) {
                for(let theme of this.themes) {
                    if(theme.getId() === themeId) {
                        this.theme = theme;
                        return;
                    }
                }
            }
        },

        watch: {
            themeId(value) {
                MessageService.send({type: 'setting.set', payload: {setting: 'theme.current', value}})
                    .catch((e) => { ToastService.error(e.message); });

                this.setCurrentTheme(this.themeId);
                MessageService.send(
                    {
                        type    : 'theme.preview',
                        payload : this.theme,
                        receiver: 'popup'
                    }
                ).catch(ErrorManager.catch);
            }
        }
    };
</script>

<style lang="scss">
    .theming {
        display               : grid;
        grid-template-columns : 3fr 4fr;
        grid-column-gap       : 1rem;
        padding               : 1rem;

        .theme-settings {
            .setting {
                display               : grid;
                grid-template-areas   : "label input";
                grid-template-columns : 3fr 2fr;
                margin-bottom         : .25rem;

                label {
                    grid-area : label;
                }

                select,
                input {
                    grid-area : input;
                    width     : 100%;
                }
            }
        }

        .theme-colors {
            .color-setting {
                display               : grid;
                grid-template-columns : 1fr 1.5rem 1.5rem;
                grid-column-gap       : .2rem;
                margin-bottom         : .2rem;

                input {
                    padding    : 0;
                    margin     : 0;
                    border     : 0;
                    outline    : 0;
                    box-shadow : 0 0 0 1px var(--element-hover-bg-color);
                    width      : 1.5rem;
                    cursor     : pointer;

                    &[disabled] {
                        opacity : .25;
                    }
                }
            }
        }
    }
</style>