-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathapp.vue
More file actions
67 lines (55 loc) · 1.63 KB
/
app.vue
File metadata and controls
67 lines (55 loc) · 1.63 KB
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
<template lang="pug">
Toast
.flex.flex-row.min-h-screen.w-full.items-start
button.fixed.top-4.left-4.z-50.px-3.py-2.rounded-md(
class="md:border md:border-gray-200"
v-if="$route.name !== 'index'"
@click="toggleSidebar"
aria-label="Toggle sidebar"
style="background: var(--color-nav-bg); color: var(--color-nav-text);"
) ☰
Navbar(
v-if="$route.name !== 'index'"
:is-open="sidebarOpen"
@close="closeSidebar"
)
.centered-row.flex-auto.content-area(:class="['ml-0 md:border-l md:border-gray-200', $route.name !== 'index' && sidebarOpen ? 'xl:ml-64' : 'xl:ml-0']")
NuxtPage
</template>
<script setup lang="ts">
import { onBeforeUnmount, onMounted, ref } from 'vue';
const sidebarOpen = ref(true);
const MOBILE_SIDEBAR_BREAKPOINT = 1280;
let lastWindowWidth = MOBILE_SIDEBAR_BREAKPOINT;
const toggleSidebar = () => {
sidebarOpen.value = !sidebarOpen.value;
};
const closeSidebar = () => {
sidebarOpen.value = false;
};
const handleResize = () => {
const currentWidth = window.innerWidth;
const crossedToSmallScreen = lastWindowWidth >= MOBILE_SIDEBAR_BREAKPOINT && currentWidth < MOBILE_SIDEBAR_BREAKPOINT;
if (crossedToSmallScreen) {
closeSidebar();
}
lastWindowWidth = currentWidth;
};
onMounted(() => {
lastWindowWidth = window.innerWidth;
if (lastWindowWidth < MOBILE_SIDEBAR_BREAKPOINT) {
closeSidebar();
}
window.addEventListener('resize', handleResize);
});
onBeforeUnmount(() => {
window.removeEventListener('resize', handleResize);
});
</script>
<style>
@media (max-width: 767px) {
.flex-row {
flex-direction: column;
}
}
</style>