/
AppBar.vue
194 lines (175 loc) · 7.01 KB
/
AppBar.vue
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
// Copyright (C) 2023 Storj Labs, Inc.
// See LICENSE for copying information.
<template>
<v-app-bar :elevation="0">
<v-app-bar-nav-icon
v-if="showNavDrawerButton"
variant="text"
color="default"
class="ml-1"
size="x-small"
density="comfortable"
@click.stop="appStore.toggleNavigationDrawer()"
/>
<v-app-bar-title class="mx-1 flex-initial" :class="{ 'ml-4': !showNavDrawerButton }">
<router-link to="/projects">
<v-img
v-if="theme.global.current.value.dark"
src="@poc/assets/logo-dark.svg"
width="120"
alt="Storj Logo"
/>
<v-img
v-else
src="@poc/assets/logo.svg"
width="120"
alt="Storj Logo"
/>
</router-link>
</v-app-bar-title>
<template #append>
<v-menu offset-y width="200" class="rounded-xl">
<template #activator="{ props: activatorProps }">
<!-- Theme Toggle Light/Dark Mode -->
<v-btn-toggle
v-model="activeTheme"
mandatory
border
inset
density="comfortable"
class="pa-1"
>
<v-tooltip text="Light Theme" location="bottom">
<template #activator="{ props: darkProps }">
<v-btn
v-bind="darkProps"
icon="mdi-weather-sunny"
size="small"
rounded="xl"
aria-label="Toggle Light Theme"
@click="toggleTheme('light')"
/>
</template>
</v-tooltip>
<v-tooltip text="Dark Theme" location="bottom">
<template #activator="{ props: lightProps }">
<v-btn
v-bind="lightProps"
icon="mdi-weather-night"
size="small"
rounded="xl"
aria-label="Toggle Dark Theme"
@click="toggleTheme('dark')"
/>
</template>
</v-tooltip>
</v-btn-toggle>
<!-- My Account Dropdown Button -->
<v-btn
v-bind="activatorProps"
variant="outlined"
color="default"
class="ml-4 font-weight-medium"
density="comfortable"
>
<template #append>
<img src="@poc/assets/icon-dropdown.svg" alt="Account Dropdown">
</template>
My Account
</v-btn>
</template>
<!-- My Account Menu -->
<v-list class="px-2">
<v-list-item class="py-2 rounded-lg">
<template #prepend>
<img src="@poc/assets/icon-satellite.svg" alt="Region">
</template>
<v-list-item-title class="text-body-2 ml-3">Region</v-list-item-title>
<v-list-item-subtitle class="ml-3">
North America 1
</v-list-item-subtitle>
</v-list-item>
<v-divider class="my-2" />
<v-list-item link class="my-1 rounded-lg">
<template #prepend>
<img src="@poc/assets/icon-upgrade.svg" alt="Upgrade">
</template>
<v-list-item-title class="text-body-2 ml-3">
Upgrade
</v-list-item-title>
</v-list-item>
<v-list-item link class="my-1 rounded-lg" router-link to="/account/billing">
<template #prepend>
<img src="@poc/assets/icon-card.svg" alt="Billing">
</template>
<v-list-item-title class="text-body-2 ml-3">
Billing
</v-list-item-title>
</v-list-item>
<v-list-item link class="my-1 rounded-lg" router-link to="/account/settings">
<template #prepend>
<img src="@poc/assets/icon-settings.svg" alt="Account Settings">
</template>
<v-list-item-title class="text-body-2 ml-3">
Settings
</v-list-item-title>
</v-list-item>
<v-list-item class="rounded-lg" link>
<template #prepend>
<img src="@poc/assets/icon-logout.svg" alt="Log Out">
</template>
<v-list-item-title class="text-body-2 ml-3">
Sign Out
</v-list-item-title>
</v-list-item>
</v-list>
</v-menu>
</template>
</v-app-bar>
</template>
<script setup lang="ts">
import { ref, watch } from 'vue';
import { useTheme } from 'vuetify';
import {
VAppBar,
VAppBarNavIcon,
VAppBarTitle,
VImg,
VMenu,
VBtnToggle,
VTooltip,
VBtn,
VList,
VListItem,
VListItemTitle,
VListItemSubtitle,
VDivider,
} from 'vuetify/components';
import { useAppStore } from '@poc/store/appStore';
const activeTheme = ref<number>(0);
const appStore = useAppStore();
const theme = useTheme();
const props = withDefaults(defineProps<{
showNavDrawerButton: boolean;
}>(), {
showNavDrawerButton: false,
});
function toggleTheme(newTheme: string): void {
if ((newTheme === 'dark' && theme.global.current.value.dark) || (newTheme === 'light' && !theme.global.current.value.dark)) {
return;
}
theme.global.name.value = newTheme;
localStorage.setItem('theme', newTheme); // Store the selected theme in localStorage
}
watch(() => theme.global.current.value.dark, (newVal: boolean) => {
activeTheme.value = newVal ? 1 : 0;
});
// Check for stored theme in localStorage. If none, default to 'light'
toggleTheme(localStorage.getItem('theme') || 'light');
activeTheme.value = theme.global.current.value.dark ? 1 : 0;
</script>
<style scoped lang="scss">
.flex-initial {
flex: initial;
}
</style>