AppBar.vue 2.66 KB
Newer Older
abergavenny's avatar
abergavenny committed
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
<script setup>
import { ref } from 'vue'

import { ROLE_OPTIONS } from '@/data/options'
import { useBuildingStore } from '@/stores/buildings'
import { useSessionStore } from '@/stores/session'

const openMenu = ref(false)

const buildings = useBuildingStore()
const session = useSessionStore()

function toggleMenu() {
  openMenu.value = !openMenu.value
}

function convertRole(value) {
  const role = ROLE_OPTIONS.find(element => element.value === value)

  return role ? role.name : null
}
</script>

<template>
  <div class="app-bar">
    <div class="app-bar__left">
      <slot />
    </div>
    <div class="app-bar__right">
      <div class="app-bar__role bar">Sie sind angemeldet als {{ convertRole(session.currentUser?.role) }}.</div>
      <router-link class="button secondary" to="/">
        <font-awesome-icon icon="fa-solid fa-arrow-right-from-bracket" />
      </router-link>
    </div>
    <div class="app-bar__mobile">
      <button class="button secondary" type="button" @click="toggleMenu">
        <font-awesome-icon v-if="!openMenu" icon="fa-solid fa-bars" />
        <font-awesome-icon v-else icon="fa-solid fa-xmark" />
      </button>
      <div class="app-bar__dropdown shadow" v-if="openMenu">
        <div v-if="session.currentUser?.role === 'user'">
          <span class="static-text">{{ buildings.single.name }}</span>
        </div>
        <div class="app-bar__role">Sie sind angemeldet als {{ convertRole(session.currentUser?.role) }}.</div>
        <router-link class="button primary" to="/">
          <font-awesome-icon icon="fa-solid fa-arrow-right-from-bracket" />
        </router-link>
      </div>
    </div>
  </div>
</template>

<style scoped>
.app-bar {
  position: relative;
  background-color: hsl(var(--clr-primary));
  padding: var(--spacing);
  display: flex;
  flex-direction: row-reverse;
  justify-content: space-between;
}

@media (min-width: 48em) {
  .app-bar {
    flex-direction: row;
  }
}

.app-bar__role {
  display: flex;
}

.app-bar__role.bar {
  color: var(--clr-white);
}

.app-bar__left,
.app-bar__right {
  height: var(--element-size);
  display: flex;
  gap: var(--spacing);
  align-items: center;
}

.app-bar__right {
  display: none;
}

.app-bar__mobile {
  position: relative;
  display: flex;
}

@media (min-width: 48em) {
  .app-bar__mobile {
    display: none;
  }

  .app-bar__right {
    display: flex;
  }
}

.app-bar__dropdown {
  background-color: hsl(var(--clr-content));
  z-index: 1;
  position: fixed;
  top: calc(var(--element-size) + var(--spacing) * 2);
  left: 0;
  right: 0;
  padding: var(--spacing);
  display: flex;
  flex-direction: column;
  gap: var(--spacing);
  border-bottom: var(--border) solid hsl(var(--clr-primary));
}
</style>